]>
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 LT |
28 | #include <linux/init.h> |
29 | #include <linux/ioport.h> | |
30 | #include <linux/pci.h> | |
31 | #include <linux/netdevice.h> | |
32 | #include <linux/etherdevice.h> | |
33 | #include <linux/skbuff.h> | |
34 | #include <linux/ethtool.h> | |
3110f5f5 | 35 | #include <linux/mdio.h> |
1da177e4 | 36 | #include <linux/mii.h> |
158d7abd | 37 | #include <linux/phy.h> |
a9daf367 | 38 | #include <linux/brcmphy.h> |
1da177e4 LT |
39 | #include <linux/if_vlan.h> |
40 | #include <linux/ip.h> | |
41 | #include <linux/tcp.h> | |
42 | #include <linux/workqueue.h> | |
61487480 | 43 | #include <linux/prefetch.h> |
f9a5f7d3 | 44 | #include <linux/dma-mapping.h> |
077f849d | 45 | #include <linux/firmware.h> |
1da177e4 LT |
46 | |
47 | #include <net/checksum.h> | |
c9bdd4b5 | 48 | #include <net/ip.h> |
1da177e4 LT |
49 | |
50 | #include <asm/system.h> | |
27fd9de8 | 51 | #include <linux/io.h> |
1da177e4 | 52 | #include <asm/byteorder.h> |
27fd9de8 | 53 | #include <linux/uaccess.h> |
1da177e4 | 54 | |
49b6e95f | 55 | #ifdef CONFIG_SPARC |
1da177e4 | 56 | #include <asm/idprom.h> |
49b6e95f | 57 | #include <asm/prom.h> |
1da177e4 LT |
58 | #endif |
59 | ||
63532394 MC |
60 | #define BAR_0 0 |
61 | #define BAR_2 2 | |
62 | ||
1da177e4 LT |
63 | #include "tg3.h" |
64 | ||
63c3a66f JP |
65 | /* Functions & macros to verify TG3_FLAGS types */ |
66 | ||
67 | static inline int _tg3_flag(enum TG3_FLAGS flag, unsigned long *bits) | |
68 | { | |
69 | return test_bit(flag, bits); | |
70 | } | |
71 | ||
72 | static inline void _tg3_flag_set(enum TG3_FLAGS flag, unsigned long *bits) | |
73 | { | |
74 | set_bit(flag, bits); | |
75 | } | |
76 | ||
77 | static inline void _tg3_flag_clear(enum TG3_FLAGS flag, unsigned long *bits) | |
78 | { | |
79 | clear_bit(flag, bits); | |
80 | } | |
81 | ||
82 | #define tg3_flag(tp, flag) \ | |
83 | _tg3_flag(TG3_FLAG_##flag, (tp)->tg3_flags) | |
84 | #define tg3_flag_set(tp, flag) \ | |
85 | _tg3_flag_set(TG3_FLAG_##flag, (tp)->tg3_flags) | |
86 | #define tg3_flag_clear(tp, flag) \ | |
87 | _tg3_flag_clear(TG3_FLAG_##flag, (tp)->tg3_flags) | |
88 | ||
1da177e4 | 89 | #define DRV_MODULE_NAME "tg3" |
6867c843 | 90 | #define TG3_MAJ_NUM 3 |
64cad2ad | 91 | #define TG3_MIN_NUM 118 |
6867c843 MC |
92 | #define DRV_MODULE_VERSION \ |
93 | __stringify(TG3_MAJ_NUM) "." __stringify(TG3_MIN_NUM) | |
64cad2ad | 94 | #define DRV_MODULE_RELDATE "April 22, 2011" |
1da177e4 LT |
95 | |
96 | #define TG3_DEF_MAC_MODE 0 | |
97 | #define TG3_DEF_RX_MODE 0 | |
98 | #define TG3_DEF_TX_MODE 0 | |
99 | #define TG3_DEF_MSG_ENABLE \ | |
100 | (NETIF_MSG_DRV | \ | |
101 | NETIF_MSG_PROBE | \ | |
102 | NETIF_MSG_LINK | \ | |
103 | NETIF_MSG_TIMER | \ | |
104 | NETIF_MSG_IFDOWN | \ | |
105 | NETIF_MSG_IFUP | \ | |
106 | NETIF_MSG_RX_ERR | \ | |
107 | NETIF_MSG_TX_ERR) | |
108 | ||
109 | /* length of time before we decide the hardware is borked, | |
110 | * and dev->tx_timeout() should be called to fix the problem | |
111 | */ | |
63c3a66f | 112 | |
1da177e4 LT |
113 | #define TG3_TX_TIMEOUT (5 * HZ) |
114 | ||
115 | /* hardware minimum and maximum for a single frame's data payload */ | |
116 | #define TG3_MIN_MTU 60 | |
117 | #define TG3_MAX_MTU(tp) \ | |
63c3a66f | 118 | (tg3_flag(tp, JUMBO_CAPABLE) ? 9000 : 1500) |
1da177e4 LT |
119 | |
120 | /* These numbers seem to be hard coded in the NIC firmware somehow. | |
121 | * You can't change the ring sizes, but you can change where you place | |
122 | * them in the NIC onboard memory. | |
123 | */ | |
7cb32cf2 | 124 | #define TG3_RX_STD_RING_SIZE(tp) \ |
63c3a66f | 125 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
de9f5230 | 126 | TG3_RX_STD_MAX_SIZE_5717 : TG3_RX_STD_MAX_SIZE_5700) |
1da177e4 | 127 | #define TG3_DEF_RX_RING_PENDING 200 |
7cb32cf2 | 128 | #define TG3_RX_JMB_RING_SIZE(tp) \ |
63c3a66f | 129 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
de9f5230 | 130 | TG3_RX_JMB_MAX_SIZE_5717 : TG3_RX_JMB_MAX_SIZE_5700) |
1da177e4 | 131 | #define TG3_DEF_RX_JUMBO_RING_PENDING 100 |
c6cdf436 | 132 | #define TG3_RSS_INDIR_TBL_SIZE 128 |
1da177e4 LT |
133 | |
134 | /* Do not place this n-ring entries value into the tp struct itself, | |
135 | * we really want to expose these constants to GCC so that modulo et | |
136 | * al. operations are done with shifts and masks instead of with | |
137 | * hw multiply/modulo instructions. Another solution would be to | |
138 | * replace things like '% foo' with '& (foo - 1)'. | |
139 | */ | |
1da177e4 LT |
140 | |
141 | #define TG3_TX_RING_SIZE 512 | |
142 | #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1) | |
143 | ||
2c49a44d MC |
144 | #define TG3_RX_STD_RING_BYTES(tp) \ |
145 | (sizeof(struct tg3_rx_buffer_desc) * TG3_RX_STD_RING_SIZE(tp)) | |
146 | #define TG3_RX_JMB_RING_BYTES(tp) \ | |
147 | (sizeof(struct tg3_ext_rx_buffer_desc) * TG3_RX_JMB_RING_SIZE(tp)) | |
148 | #define TG3_RX_RCB_RING_BYTES(tp) \ | |
7cb32cf2 | 149 | (sizeof(struct tg3_rx_buffer_desc) * (tp->rx_ret_ring_mask + 1)) |
1da177e4 LT |
150 | #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ |
151 | TG3_TX_RING_SIZE) | |
1da177e4 LT |
152 | #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) |
153 | ||
287be12e MC |
154 | #define TG3_DMA_BYTE_ENAB 64 |
155 | ||
156 | #define TG3_RX_STD_DMA_SZ 1536 | |
157 | #define TG3_RX_JMB_DMA_SZ 9046 | |
158 | ||
159 | #define TG3_RX_DMA_TO_MAP_SZ(x) ((x) + TG3_DMA_BYTE_ENAB) | |
160 | ||
161 | #define TG3_RX_STD_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_STD_DMA_SZ) | |
162 | #define TG3_RX_JMB_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_JMB_DMA_SZ) | |
1da177e4 | 163 | |
2c49a44d MC |
164 | #define TG3_RX_STD_BUFF_RING_SIZE(tp) \ |
165 | (sizeof(struct ring_info) * TG3_RX_STD_RING_SIZE(tp)) | |
2b2cdb65 | 166 | |
2c49a44d MC |
167 | #define TG3_RX_JMB_BUFF_RING_SIZE(tp) \ |
168 | (sizeof(struct ring_info) * TG3_RX_JMB_RING_SIZE(tp)) | |
2b2cdb65 | 169 | |
d2757fc4 MC |
170 | /* Due to a hardware bug, the 5701 can only DMA to memory addresses |
171 | * that are at least dword aligned when used in PCIX mode. The driver | |
172 | * works around this bug by double copying the packet. This workaround | |
173 | * is built into the normal double copy length check for efficiency. | |
174 | * | |
175 | * However, the double copy is only necessary on those architectures | |
176 | * where unaligned memory accesses are inefficient. For those architectures | |
177 | * where unaligned memory accesses incur little penalty, we can reintegrate | |
178 | * the 5701 in the normal rx path. Doing so saves a device structure | |
179 | * dereference by hardcoding the double copy threshold in place. | |
180 | */ | |
181 | #define TG3_RX_COPY_THRESHOLD 256 | |
182 | #if NET_IP_ALIGN == 0 || defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) | |
183 | #define TG3_RX_COPY_THRESH(tp) TG3_RX_COPY_THRESHOLD | |
184 | #else | |
185 | #define TG3_RX_COPY_THRESH(tp) ((tp)->rx_copy_thresh) | |
186 | #endif | |
187 | ||
1da177e4 | 188 | /* minimum number of free TX descriptors required to wake up TX process */ |
f3f3f27e | 189 | #define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4) |
1da177e4 | 190 | |
ad829268 MC |
191 | #define TG3_RAW_IP_ALIGN 2 |
192 | ||
c6cdf436 MC |
193 | #define TG3_FW_UPDATE_TIMEOUT_SEC 5 |
194 | ||
077f849d JSR |
195 | #define FIRMWARE_TG3 "tigon/tg3.bin" |
196 | #define FIRMWARE_TG3TSO "tigon/tg3_tso.bin" | |
197 | #define FIRMWARE_TG3TSO5 "tigon/tg3_tso5.bin" | |
198 | ||
1da177e4 | 199 | static char version[] __devinitdata = |
05dbe005 | 200 | DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")"; |
1da177e4 LT |
201 | |
202 | MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)"); | |
203 | MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver"); | |
204 | MODULE_LICENSE("GPL"); | |
205 | MODULE_VERSION(DRV_MODULE_VERSION); | |
077f849d JSR |
206 | MODULE_FIRMWARE(FIRMWARE_TG3); |
207 | MODULE_FIRMWARE(FIRMWARE_TG3TSO); | |
208 | MODULE_FIRMWARE(FIRMWARE_TG3TSO5); | |
209 | ||
1da177e4 LT |
210 | static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */ |
211 | module_param(tg3_debug, int, 0); | |
212 | MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value"); | |
213 | ||
a3aa1884 | 214 | static DEFINE_PCI_DEVICE_TABLE(tg3_pci_tbl) = { |
13185217 HK |
215 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)}, |
216 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)}, | |
217 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)}, | |
218 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)}, | |
219 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)}, | |
220 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)}, | |
221 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)}, | |
222 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)}, | |
223 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)}, | |
224 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)}, | |
225 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)}, | |
226 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)}, | |
227 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)}, | |
228 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)}, | |
229 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)}, | |
230 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)}, | |
231 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)}, | |
232 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)}, | |
233 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)}, | |
234 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)}, | |
235 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)}, | |
236 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)}, | |
13185217 | 237 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)}, |
126a3368 | 238 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)}, |
13185217 | 239 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)}, |
13185217 HK |
240 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)}, |
241 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)}, | |
242 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)}, | |
243 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)}, | |
244 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)}, | |
245 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)}, | |
246 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)}, | |
247 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)}, | |
248 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)}, | |
249 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)}, | |
250 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)}, | |
126a3368 | 251 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)}, |
13185217 HK |
252 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)}, |
253 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)}, | |
254 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)}, | |
676917d4 | 255 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F)}, |
13185217 HK |
256 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)}, |
257 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)}, | |
258 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)}, | |
259 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)}, | |
260 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)}, | |
261 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)}, | |
262 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)}, | |
b5d3772c MC |
263 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)}, |
264 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)}, | |
d30cdd28 MC |
265 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)}, |
266 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)}, | |
6c7af27c | 267 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)}, |
9936bcf6 MC |
268 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)}, |
269 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)}, | |
c88e668b MC |
270 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761S)}, |
271 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761SE)}, | |
2befdcea MC |
272 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_G)}, |
273 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_F)}, | |
321d32a0 MC |
274 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780)}, |
275 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57760)}, | |
276 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57790)}, | |
5e7ccf20 | 277 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57788)}, |
5001e2f6 MC |
278 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717)}, |
279 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5718)}, | |
b0f75221 MC |
280 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57781)}, |
281 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57785)}, | |
282 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57761)}, | |
283 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57765)}, | |
284 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57791)}, | |
285 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57795)}, | |
302b500b | 286 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5719)}, |
ba1f3c76 | 287 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5720)}, |
13185217 HK |
288 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, |
289 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)}, | |
290 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)}, | |
291 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)}, | |
292 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)}, | |
293 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)}, | |
294 | {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)}, | |
295 | {} | |
1da177e4 LT |
296 | }; |
297 | ||
298 | MODULE_DEVICE_TABLE(pci, tg3_pci_tbl); | |
299 | ||
50da859d | 300 | static const struct { |
1da177e4 | 301 | const char string[ETH_GSTRING_LEN]; |
48fa55a0 | 302 | } ethtool_stats_keys[] = { |
1da177e4 LT |
303 | { "rx_octets" }, |
304 | { "rx_fragments" }, | |
305 | { "rx_ucast_packets" }, | |
306 | { "rx_mcast_packets" }, | |
307 | { "rx_bcast_packets" }, | |
308 | { "rx_fcs_errors" }, | |
309 | { "rx_align_errors" }, | |
310 | { "rx_xon_pause_rcvd" }, | |
311 | { "rx_xoff_pause_rcvd" }, | |
312 | { "rx_mac_ctrl_rcvd" }, | |
313 | { "rx_xoff_entered" }, | |
314 | { "rx_frame_too_long_errors" }, | |
315 | { "rx_jabbers" }, | |
316 | { "rx_undersize_packets" }, | |
317 | { "rx_in_length_errors" }, | |
318 | { "rx_out_length_errors" }, | |
319 | { "rx_64_or_less_octet_packets" }, | |
320 | { "rx_65_to_127_octet_packets" }, | |
321 | { "rx_128_to_255_octet_packets" }, | |
322 | { "rx_256_to_511_octet_packets" }, | |
323 | { "rx_512_to_1023_octet_packets" }, | |
324 | { "rx_1024_to_1522_octet_packets" }, | |
325 | { "rx_1523_to_2047_octet_packets" }, | |
326 | { "rx_2048_to_4095_octet_packets" }, | |
327 | { "rx_4096_to_8191_octet_packets" }, | |
328 | { "rx_8192_to_9022_octet_packets" }, | |
329 | ||
330 | { "tx_octets" }, | |
331 | { "tx_collisions" }, | |
332 | ||
333 | { "tx_xon_sent" }, | |
334 | { "tx_xoff_sent" }, | |
335 | { "tx_flow_control" }, | |
336 | { "tx_mac_errors" }, | |
337 | { "tx_single_collisions" }, | |
338 | { "tx_mult_collisions" }, | |
339 | { "tx_deferred" }, | |
340 | { "tx_excessive_collisions" }, | |
341 | { "tx_late_collisions" }, | |
342 | { "tx_collide_2times" }, | |
343 | { "tx_collide_3times" }, | |
344 | { "tx_collide_4times" }, | |
345 | { "tx_collide_5times" }, | |
346 | { "tx_collide_6times" }, | |
347 | { "tx_collide_7times" }, | |
348 | { "tx_collide_8times" }, | |
349 | { "tx_collide_9times" }, | |
350 | { "tx_collide_10times" }, | |
351 | { "tx_collide_11times" }, | |
352 | { "tx_collide_12times" }, | |
353 | { "tx_collide_13times" }, | |
354 | { "tx_collide_14times" }, | |
355 | { "tx_collide_15times" }, | |
356 | { "tx_ucast_packets" }, | |
357 | { "tx_mcast_packets" }, | |
358 | { "tx_bcast_packets" }, | |
359 | { "tx_carrier_sense_errors" }, | |
360 | { "tx_discards" }, | |
361 | { "tx_errors" }, | |
362 | ||
363 | { "dma_writeq_full" }, | |
364 | { "dma_write_prioq_full" }, | |
365 | { "rxbds_empty" }, | |
366 | { "rx_discards" }, | |
4d958473 | 367 | { "mbuf_lwm_thresh_hit" }, |
1da177e4 LT |
368 | { "rx_errors" }, |
369 | { "rx_threshold_hit" }, | |
370 | ||
371 | { "dma_readq_full" }, | |
372 | { "dma_read_prioq_full" }, | |
373 | { "tx_comp_queue_full" }, | |
374 | ||
375 | { "ring_set_send_prod_index" }, | |
376 | { "ring_status_update" }, | |
377 | { "nic_irqs" }, | |
378 | { "nic_avoided_irqs" }, | |
379 | { "nic_tx_threshold_hit" } | |
380 | }; | |
381 | ||
48fa55a0 MC |
382 | #define TG3_NUM_STATS ARRAY_SIZE(ethtool_stats_keys) |
383 | ||
384 | ||
50da859d | 385 | static const struct { |
4cafd3f5 | 386 | const char string[ETH_GSTRING_LEN]; |
48fa55a0 | 387 | } ethtool_test_keys[] = { |
4cafd3f5 MC |
388 | { "nvram test (online) " }, |
389 | { "link test (online) " }, | |
390 | { "register test (offline)" }, | |
391 | { "memory test (offline)" }, | |
392 | { "loopback test (offline)" }, | |
393 | { "interrupt test (offline)" }, | |
394 | }; | |
395 | ||
48fa55a0 MC |
396 | #define TG3_NUM_TEST ARRAY_SIZE(ethtool_test_keys) |
397 | ||
398 | ||
b401e9e2 MC |
399 | static void tg3_write32(struct tg3 *tp, u32 off, u32 val) |
400 | { | |
401 | writel(val, tp->regs + off); | |
402 | } | |
403 | ||
404 | static u32 tg3_read32(struct tg3 *tp, u32 off) | |
405 | { | |
de6f31eb | 406 | return readl(tp->regs + off); |
b401e9e2 MC |
407 | } |
408 | ||
0d3031d9 MC |
409 | static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val) |
410 | { | |
411 | writel(val, tp->aperegs + off); | |
412 | } | |
413 | ||
414 | static u32 tg3_ape_read32(struct tg3 *tp, u32 off) | |
415 | { | |
de6f31eb | 416 | return readl(tp->aperegs + off); |
0d3031d9 MC |
417 | } |
418 | ||
1da177e4 LT |
419 | static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val) |
420 | { | |
6892914f MC |
421 | unsigned long flags; |
422 | ||
423 | spin_lock_irqsave(&tp->indirect_lock, flags); | |
1ee582d8 MC |
424 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
425 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); | |
6892914f | 426 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
1ee582d8 MC |
427 | } |
428 | ||
429 | static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val) | |
430 | { | |
431 | writel(val, tp->regs + off); | |
432 | readl(tp->regs + off); | |
1da177e4 LT |
433 | } |
434 | ||
6892914f | 435 | static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off) |
1da177e4 | 436 | { |
6892914f MC |
437 | unsigned long flags; |
438 | u32 val; | |
439 | ||
440 | spin_lock_irqsave(&tp->indirect_lock, flags); | |
441 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); | |
442 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); | |
443 | spin_unlock_irqrestore(&tp->indirect_lock, flags); | |
444 | return val; | |
445 | } | |
446 | ||
447 | static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val) | |
448 | { | |
449 | unsigned long flags; | |
450 | ||
451 | if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) { | |
452 | pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX + | |
453 | TG3_64BIT_REG_LOW, val); | |
454 | return; | |
455 | } | |
66711e66 | 456 | if (off == TG3_RX_STD_PROD_IDX_REG) { |
6892914f MC |
457 | pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX + |
458 | TG3_64BIT_REG_LOW, val); | |
459 | return; | |
1da177e4 | 460 | } |
6892914f MC |
461 | |
462 | spin_lock_irqsave(&tp->indirect_lock, flags); | |
463 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); | |
464 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); | |
465 | spin_unlock_irqrestore(&tp->indirect_lock, flags); | |
466 | ||
467 | /* In indirect mode when disabling interrupts, we also need | |
468 | * to clear the interrupt bit in the GRC local ctrl register. | |
469 | */ | |
470 | if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) && | |
471 | (val == 0x1)) { | |
472 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL, | |
473 | tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT); | |
474 | } | |
475 | } | |
476 | ||
477 | static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off) | |
478 | { | |
479 | unsigned long flags; | |
480 | u32 val; | |
481 | ||
482 | spin_lock_irqsave(&tp->indirect_lock, flags); | |
483 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); | |
484 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); | |
485 | spin_unlock_irqrestore(&tp->indirect_lock, flags); | |
486 | return val; | |
487 | } | |
488 | ||
b401e9e2 MC |
489 | /* usec_wait specifies the wait time in usec when writing to certain registers |
490 | * where it is unsafe to read back the register without some delay. | |
491 | * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power. | |
492 | * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed. | |
493 | */ | |
494 | static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait) | |
6892914f | 495 | { |
63c3a66f | 496 | if (tg3_flag(tp, PCIX_TARGET_HWBUG) || tg3_flag(tp, ICH_WORKAROUND)) |
b401e9e2 MC |
497 | /* Non-posted methods */ |
498 | tp->write32(tp, off, val); | |
499 | else { | |
500 | /* Posted method */ | |
501 | tg3_write32(tp, off, val); | |
502 | if (usec_wait) | |
503 | udelay(usec_wait); | |
504 | tp->read32(tp, off); | |
505 | } | |
506 | /* Wait again after the read for the posted method to guarantee that | |
507 | * the wait time is met. | |
508 | */ | |
509 | if (usec_wait) | |
510 | udelay(usec_wait); | |
1da177e4 LT |
511 | } |
512 | ||
09ee929c MC |
513 | static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val) |
514 | { | |
515 | tp->write32_mbox(tp, off, val); | |
63c3a66f | 516 | if (!tg3_flag(tp, MBOX_WRITE_REORDER) && !tg3_flag(tp, ICH_WORKAROUND)) |
6892914f | 517 | tp->read32_mbox(tp, off); |
09ee929c MC |
518 | } |
519 | ||
20094930 | 520 | static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val) |
1da177e4 LT |
521 | { |
522 | void __iomem *mbox = tp->regs + off; | |
523 | writel(val, mbox); | |
63c3a66f | 524 | if (tg3_flag(tp, TXD_MBOX_HWBUG)) |
1da177e4 | 525 | writel(val, mbox); |
63c3a66f | 526 | if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
1da177e4 LT |
527 | readl(mbox); |
528 | } | |
529 | ||
b5d3772c MC |
530 | static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off) |
531 | { | |
de6f31eb | 532 | return readl(tp->regs + off + GRCMBOX_BASE); |
b5d3772c MC |
533 | } |
534 | ||
535 | static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val) | |
536 | { | |
537 | writel(val, tp->regs + off + GRCMBOX_BASE); | |
538 | } | |
539 | ||
c6cdf436 | 540 | #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val) |
09ee929c | 541 | #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val)) |
c6cdf436 MC |
542 | #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val) |
543 | #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val) | |
544 | #define tr32_mailbox(reg) tp->read32_mbox(tp, reg) | |
20094930 | 545 | |
c6cdf436 MC |
546 | #define tw32(reg, val) tp->write32(tp, reg, val) |
547 | #define tw32_f(reg, val) _tw32_flush(tp, (reg), (val), 0) | |
548 | #define tw32_wait_f(reg, val, us) _tw32_flush(tp, (reg), (val), (us)) | |
549 | #define tr32(reg) tp->read32(tp, reg) | |
1da177e4 LT |
550 | |
551 | static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val) | |
552 | { | |
6892914f MC |
553 | unsigned long flags; |
554 | ||
b5d3772c MC |
555 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) && |
556 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) | |
557 | return; | |
558 | ||
6892914f | 559 | spin_lock_irqsave(&tp->indirect_lock, flags); |
63c3a66f | 560 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
bbadf503 MC |
561 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
562 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); | |
1da177e4 | 563 | |
bbadf503 MC |
564 | /* Always leave this as zero. */ |
565 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
566 | } else { | |
567 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); | |
568 | tw32_f(TG3PCI_MEM_WIN_DATA, val); | |
28fbef78 | 569 | |
bbadf503 MC |
570 | /* Always leave this as zero. */ |
571 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
572 | } | |
573 | spin_unlock_irqrestore(&tp->indirect_lock, flags); | |
758a6139 DM |
574 | } |
575 | ||
1da177e4 LT |
576 | static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val) |
577 | { | |
6892914f MC |
578 | unsigned long flags; |
579 | ||
b5d3772c MC |
580 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) && |
581 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) { | |
582 | *val = 0; | |
583 | return; | |
584 | } | |
585 | ||
6892914f | 586 | spin_lock_irqsave(&tp->indirect_lock, flags); |
63c3a66f | 587 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
bbadf503 MC |
588 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
589 | pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); | |
1da177e4 | 590 | |
bbadf503 MC |
591 | /* Always leave this as zero. */ |
592 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
593 | } else { | |
594 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); | |
595 | *val = tr32(TG3PCI_MEM_WIN_DATA); | |
596 | ||
597 | /* Always leave this as zero. */ | |
598 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
599 | } | |
6892914f | 600 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
1da177e4 LT |
601 | } |
602 | ||
0d3031d9 MC |
603 | static void tg3_ape_lock_init(struct tg3 *tp) |
604 | { | |
605 | int i; | |
f92d9dc1 MC |
606 | u32 regbase; |
607 | ||
608 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) | |
609 | regbase = TG3_APE_LOCK_GRANT; | |
610 | else | |
611 | regbase = TG3_APE_PER_LOCK_GRANT; | |
0d3031d9 MC |
612 | |
613 | /* Make sure the driver hasn't any stale locks. */ | |
614 | for (i = 0; i < 8; i++) | |
f92d9dc1 | 615 | tg3_ape_write32(tp, regbase + 4 * i, APE_LOCK_GRANT_DRIVER); |
0d3031d9 MC |
616 | } |
617 | ||
618 | static int tg3_ape_lock(struct tg3 *tp, int locknum) | |
619 | { | |
620 | int i, off; | |
621 | int ret = 0; | |
f92d9dc1 | 622 | u32 status, req, gnt; |
0d3031d9 | 623 | |
63c3a66f | 624 | if (!tg3_flag(tp, ENABLE_APE)) |
0d3031d9 MC |
625 | return 0; |
626 | ||
627 | switch (locknum) { | |
33f401ae MC |
628 | case TG3_APE_LOCK_GRC: |
629 | case TG3_APE_LOCK_MEM: | |
630 | break; | |
631 | default: | |
632 | return -EINVAL; | |
0d3031d9 MC |
633 | } |
634 | ||
f92d9dc1 MC |
635 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
636 | req = TG3_APE_LOCK_REQ; | |
637 | gnt = TG3_APE_LOCK_GRANT; | |
638 | } else { | |
639 | req = TG3_APE_PER_LOCK_REQ; | |
640 | gnt = TG3_APE_PER_LOCK_GRANT; | |
641 | } | |
642 | ||
0d3031d9 MC |
643 | off = 4 * locknum; |
644 | ||
f92d9dc1 | 645 | tg3_ape_write32(tp, req + off, APE_LOCK_REQ_DRIVER); |
0d3031d9 MC |
646 | |
647 | /* Wait for up to 1 millisecond to acquire lock. */ | |
648 | for (i = 0; i < 100; i++) { | |
f92d9dc1 | 649 | status = tg3_ape_read32(tp, gnt + off); |
0d3031d9 MC |
650 | if (status == APE_LOCK_GRANT_DRIVER) |
651 | break; | |
652 | udelay(10); | |
653 | } | |
654 | ||
655 | if (status != APE_LOCK_GRANT_DRIVER) { | |
656 | /* Revoke the lock request. */ | |
f92d9dc1 | 657 | tg3_ape_write32(tp, gnt + off, |
0d3031d9 MC |
658 | APE_LOCK_GRANT_DRIVER); |
659 | ||
660 | ret = -EBUSY; | |
661 | } | |
662 | ||
663 | return ret; | |
664 | } | |
665 | ||
666 | static void tg3_ape_unlock(struct tg3 *tp, int locknum) | |
667 | { | |
f92d9dc1 | 668 | u32 gnt; |
0d3031d9 | 669 | |
63c3a66f | 670 | if (!tg3_flag(tp, ENABLE_APE)) |
0d3031d9 MC |
671 | return; |
672 | ||
673 | switch (locknum) { | |
33f401ae MC |
674 | case TG3_APE_LOCK_GRC: |
675 | case TG3_APE_LOCK_MEM: | |
676 | break; | |
677 | default: | |
678 | return; | |
0d3031d9 MC |
679 | } |
680 | ||
f92d9dc1 MC |
681 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
682 | gnt = TG3_APE_LOCK_GRANT; | |
683 | else | |
684 | gnt = TG3_APE_PER_LOCK_GRANT; | |
685 | ||
686 | tg3_ape_write32(tp, gnt + 4 * locknum, APE_LOCK_GRANT_DRIVER); | |
0d3031d9 MC |
687 | } |
688 | ||
1da177e4 LT |
689 | static void tg3_disable_ints(struct tg3 *tp) |
690 | { | |
89aeb3bc MC |
691 | int i; |
692 | ||
1da177e4 LT |
693 | tw32(TG3PCI_MISC_HOST_CTRL, |
694 | (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT)); | |
89aeb3bc MC |
695 | for (i = 0; i < tp->irq_max; i++) |
696 | tw32_mailbox_f(tp->napi[i].int_mbox, 0x00000001); | |
1da177e4 LT |
697 | } |
698 | ||
1da177e4 LT |
699 | static void tg3_enable_ints(struct tg3 *tp) |
700 | { | |
89aeb3bc | 701 | int i; |
89aeb3bc | 702 | |
bbe832c0 MC |
703 | tp->irq_sync = 0; |
704 | wmb(); | |
705 | ||
1da177e4 LT |
706 | tw32(TG3PCI_MISC_HOST_CTRL, |
707 | (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT)); | |
89aeb3bc | 708 | |
f89f38b8 | 709 | tp->coal_now = tp->coalesce_mode | HOSTCC_MODE_ENABLE; |
89aeb3bc MC |
710 | for (i = 0; i < tp->irq_cnt; i++) { |
711 | struct tg3_napi *tnapi = &tp->napi[i]; | |
c6cdf436 | 712 | |
898a56f8 | 713 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
63c3a66f | 714 | if (tg3_flag(tp, 1SHOT_MSI)) |
89aeb3bc | 715 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
f19af9c2 | 716 | |
f89f38b8 | 717 | tp->coal_now |= tnapi->coal_now; |
89aeb3bc | 718 | } |
f19af9c2 MC |
719 | |
720 | /* Force an initial interrupt */ | |
63c3a66f | 721 | if (!tg3_flag(tp, TAGGED_STATUS) && |
f19af9c2 MC |
722 | (tp->napi[0].hw_status->status & SD_STATUS_UPDATED)) |
723 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); | |
724 | else | |
f89f38b8 MC |
725 | tw32(HOSTCC_MODE, tp->coal_now); |
726 | ||
727 | tp->coal_now &= ~(tp->napi[0].coal_now | tp->napi[1].coal_now); | |
1da177e4 LT |
728 | } |
729 | ||
17375d25 | 730 | static inline unsigned int tg3_has_work(struct tg3_napi *tnapi) |
04237ddd | 731 | { |
17375d25 | 732 | struct tg3 *tp = tnapi->tp; |
898a56f8 | 733 | struct tg3_hw_status *sblk = tnapi->hw_status; |
04237ddd MC |
734 | unsigned int work_exists = 0; |
735 | ||
736 | /* check for phy events */ | |
63c3a66f | 737 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
04237ddd MC |
738 | if (sblk->status & SD_STATUS_LINK_CHG) |
739 | work_exists = 1; | |
740 | } | |
741 | /* check for RX/TX work to do */ | |
f3f3f27e | 742 | if (sblk->idx[0].tx_consumer != tnapi->tx_cons || |
8d9d7cfc | 743 | *(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
04237ddd MC |
744 | work_exists = 1; |
745 | ||
746 | return work_exists; | |
747 | } | |
748 | ||
17375d25 | 749 | /* tg3_int_reenable |
04237ddd MC |
750 | * similar to tg3_enable_ints, but it accurately determines whether there |
751 | * is new work pending and can return without flushing the PIO write | |
6aa20a22 | 752 | * which reenables interrupts |
1da177e4 | 753 | */ |
17375d25 | 754 | static void tg3_int_reenable(struct tg3_napi *tnapi) |
1da177e4 | 755 | { |
17375d25 MC |
756 | struct tg3 *tp = tnapi->tp; |
757 | ||
898a56f8 | 758 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
1da177e4 LT |
759 | mmiowb(); |
760 | ||
fac9b83e DM |
761 | /* When doing tagged status, this work check is unnecessary. |
762 | * The last_tag we write above tells the chip which piece of | |
763 | * work we've completed. | |
764 | */ | |
63c3a66f | 765 | if (!tg3_flag(tp, TAGGED_STATUS) && tg3_has_work(tnapi)) |
04237ddd | 766 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
fd2ce37f | 767 | HOSTCC_MODE_ENABLE | tnapi->coal_now); |
1da177e4 LT |
768 | } |
769 | ||
1da177e4 LT |
770 | static void tg3_switch_clocks(struct tg3 *tp) |
771 | { | |
f6eb9b1f | 772 | u32 clock_ctrl; |
1da177e4 LT |
773 | u32 orig_clock_ctrl; |
774 | ||
63c3a66f | 775 | if (tg3_flag(tp, CPMU_PRESENT) || tg3_flag(tp, 5780_CLASS)) |
4cf78e4f MC |
776 | return; |
777 | ||
f6eb9b1f MC |
778 | clock_ctrl = tr32(TG3PCI_CLOCK_CTRL); |
779 | ||
1da177e4 LT |
780 | orig_clock_ctrl = clock_ctrl; |
781 | clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN | | |
782 | CLOCK_CTRL_CLKRUN_OENABLE | | |
783 | 0x1f); | |
784 | tp->pci_clock_ctrl = clock_ctrl; | |
785 | ||
63c3a66f | 786 | if (tg3_flag(tp, 5705_PLUS)) { |
1da177e4 | 787 | if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) { |
b401e9e2 MC |
788 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
789 | clock_ctrl | CLOCK_CTRL_625_CORE, 40); | |
1da177e4 LT |
790 | } |
791 | } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) { | |
b401e9e2 MC |
792 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
793 | clock_ctrl | | |
794 | (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK), | |
795 | 40); | |
796 | tw32_wait_f(TG3PCI_CLOCK_CTRL, | |
797 | clock_ctrl | (CLOCK_CTRL_ALTCLK), | |
798 | 40); | |
1da177e4 | 799 | } |
b401e9e2 | 800 | tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40); |
1da177e4 LT |
801 | } |
802 | ||
803 | #define PHY_BUSY_LOOPS 5000 | |
804 | ||
805 | static int tg3_readphy(struct tg3 *tp, int reg, u32 *val) | |
806 | { | |
807 | u32 frame_val; | |
808 | unsigned int loops; | |
809 | int ret; | |
810 | ||
811 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { | |
812 | tw32_f(MAC_MI_MODE, | |
813 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); | |
814 | udelay(80); | |
815 | } | |
816 | ||
817 | *val = 0x0; | |
818 | ||
882e9793 | 819 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
1da177e4 LT |
820 | MI_COM_PHY_ADDR_MASK); |
821 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & | |
822 | MI_COM_REG_ADDR_MASK); | |
823 | frame_val |= (MI_COM_CMD_READ | MI_COM_START); | |
6aa20a22 | 824 | |
1da177e4 LT |
825 | tw32_f(MAC_MI_COM, frame_val); |
826 | ||
827 | loops = PHY_BUSY_LOOPS; | |
828 | while (loops != 0) { | |
829 | udelay(10); | |
830 | frame_val = tr32(MAC_MI_COM); | |
831 | ||
832 | if ((frame_val & MI_COM_BUSY) == 0) { | |
833 | udelay(5); | |
834 | frame_val = tr32(MAC_MI_COM); | |
835 | break; | |
836 | } | |
837 | loops -= 1; | |
838 | } | |
839 | ||
840 | ret = -EBUSY; | |
841 | if (loops != 0) { | |
842 | *val = frame_val & MI_COM_DATA_MASK; | |
843 | ret = 0; | |
844 | } | |
845 | ||
846 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { | |
847 | tw32_f(MAC_MI_MODE, tp->mi_mode); | |
848 | udelay(80); | |
849 | } | |
850 | ||
851 | return ret; | |
852 | } | |
853 | ||
854 | static int tg3_writephy(struct tg3 *tp, int reg, u32 val) | |
855 | { | |
856 | u32 frame_val; | |
857 | unsigned int loops; | |
858 | int ret; | |
859 | ||
f07e9af3 | 860 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
b5d3772c MC |
861 | (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL)) |
862 | return 0; | |
863 | ||
1da177e4 LT |
864 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
865 | tw32_f(MAC_MI_MODE, | |
866 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); | |
867 | udelay(80); | |
868 | } | |
869 | ||
882e9793 | 870 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
1da177e4 LT |
871 | MI_COM_PHY_ADDR_MASK); |
872 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & | |
873 | MI_COM_REG_ADDR_MASK); | |
874 | frame_val |= (val & MI_COM_DATA_MASK); | |
875 | frame_val |= (MI_COM_CMD_WRITE | MI_COM_START); | |
6aa20a22 | 876 | |
1da177e4 LT |
877 | tw32_f(MAC_MI_COM, frame_val); |
878 | ||
879 | loops = PHY_BUSY_LOOPS; | |
880 | while (loops != 0) { | |
881 | udelay(10); | |
882 | frame_val = tr32(MAC_MI_COM); | |
883 | if ((frame_val & MI_COM_BUSY) == 0) { | |
884 | udelay(5); | |
885 | frame_val = tr32(MAC_MI_COM); | |
886 | break; | |
887 | } | |
888 | loops -= 1; | |
889 | } | |
890 | ||
891 | ret = -EBUSY; | |
892 | if (loops != 0) | |
893 | ret = 0; | |
894 | ||
895 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { | |
896 | tw32_f(MAC_MI_MODE, tp->mi_mode); | |
897 | udelay(80); | |
898 | } | |
899 | ||
900 | return ret; | |
901 | } | |
902 | ||
b0988c15 MC |
903 | static int tg3_phy_cl45_write(struct tg3 *tp, u32 devad, u32 addr, u32 val) |
904 | { | |
905 | int err; | |
906 | ||
907 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); | |
908 | if (err) | |
909 | goto done; | |
910 | ||
911 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); | |
912 | if (err) | |
913 | goto done; | |
914 | ||
915 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, | |
916 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); | |
917 | if (err) | |
918 | goto done; | |
919 | ||
920 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, val); | |
921 | ||
922 | done: | |
923 | return err; | |
924 | } | |
925 | ||
926 | static int tg3_phy_cl45_read(struct tg3 *tp, u32 devad, u32 addr, u32 *val) | |
927 | { | |
928 | int err; | |
929 | ||
930 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); | |
931 | if (err) | |
932 | goto done; | |
933 | ||
934 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); | |
935 | if (err) | |
936 | goto done; | |
937 | ||
938 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, | |
939 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); | |
940 | if (err) | |
941 | goto done; | |
942 | ||
943 | err = tg3_readphy(tp, MII_TG3_MMD_ADDRESS, val); | |
944 | ||
945 | done: | |
946 | return err; | |
947 | } | |
948 | ||
949 | static int tg3_phydsp_read(struct tg3 *tp, u32 reg, u32 *val) | |
950 | { | |
951 | int err; | |
952 | ||
953 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); | |
954 | if (!err) | |
955 | err = tg3_readphy(tp, MII_TG3_DSP_RW_PORT, val); | |
956 | ||
957 | return err; | |
958 | } | |
959 | ||
960 | static int tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val) | |
961 | { | |
962 | int err; | |
963 | ||
964 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); | |
965 | if (!err) | |
966 | err = tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val); | |
967 | ||
968 | return err; | |
969 | } | |
970 | ||
15ee95c3 MC |
971 | static int tg3_phy_auxctl_read(struct tg3 *tp, int reg, u32 *val) |
972 | { | |
973 | int err; | |
974 | ||
975 | err = tg3_writephy(tp, MII_TG3_AUX_CTRL, | |
976 | (reg << MII_TG3_AUXCTL_MISC_RDSEL_SHIFT) | | |
977 | MII_TG3_AUXCTL_SHDWSEL_MISC); | |
978 | if (!err) | |
979 | err = tg3_readphy(tp, MII_TG3_AUX_CTRL, val); | |
980 | ||
981 | return err; | |
982 | } | |
983 | ||
b4bd2929 MC |
984 | static int tg3_phy_auxctl_write(struct tg3 *tp, int reg, u32 set) |
985 | { | |
986 | if (reg == MII_TG3_AUXCTL_SHDWSEL_MISC) | |
987 | set |= MII_TG3_AUXCTL_MISC_WREN; | |
988 | ||
989 | return tg3_writephy(tp, MII_TG3_AUX_CTRL, set | reg); | |
990 | } | |
991 | ||
1d36ba45 MC |
992 | #define TG3_PHY_AUXCTL_SMDSP_ENABLE(tp) \ |
993 | tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, \ | |
994 | MII_TG3_AUXCTL_ACTL_SMDSP_ENA | \ | |
995 | MII_TG3_AUXCTL_ACTL_TX_6DB) | |
996 | ||
997 | #define TG3_PHY_AUXCTL_SMDSP_DISABLE(tp) \ | |
998 | tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, \ | |
999 | MII_TG3_AUXCTL_ACTL_TX_6DB); | |
1000 | ||
95e2869a MC |
1001 | static int tg3_bmcr_reset(struct tg3 *tp) |
1002 | { | |
1003 | u32 phy_control; | |
1004 | int limit, err; | |
1005 | ||
1006 | /* OK, reset it, and poll the BMCR_RESET bit until it | |
1007 | * clears or we time out. | |
1008 | */ | |
1009 | phy_control = BMCR_RESET; | |
1010 | err = tg3_writephy(tp, MII_BMCR, phy_control); | |
1011 | if (err != 0) | |
1012 | return -EBUSY; | |
1013 | ||
1014 | limit = 5000; | |
1015 | while (limit--) { | |
1016 | err = tg3_readphy(tp, MII_BMCR, &phy_control); | |
1017 | if (err != 0) | |
1018 | return -EBUSY; | |
1019 | ||
1020 | if ((phy_control & BMCR_RESET) == 0) { | |
1021 | udelay(40); | |
1022 | break; | |
1023 | } | |
1024 | udelay(10); | |
1025 | } | |
d4675b52 | 1026 | if (limit < 0) |
95e2869a MC |
1027 | return -EBUSY; |
1028 | ||
1029 | return 0; | |
1030 | } | |
1031 | ||
158d7abd MC |
1032 | static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg) |
1033 | { | |
3d16543d | 1034 | struct tg3 *tp = bp->priv; |
158d7abd MC |
1035 | u32 val; |
1036 | ||
24bb4fb6 | 1037 | spin_lock_bh(&tp->lock); |
158d7abd MC |
1038 | |
1039 | if (tg3_readphy(tp, reg, &val)) | |
24bb4fb6 MC |
1040 | val = -EIO; |
1041 | ||
1042 | spin_unlock_bh(&tp->lock); | |
158d7abd MC |
1043 | |
1044 | return val; | |
1045 | } | |
1046 | ||
1047 | static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val) | |
1048 | { | |
3d16543d | 1049 | struct tg3 *tp = bp->priv; |
24bb4fb6 | 1050 | u32 ret = 0; |
158d7abd | 1051 | |
24bb4fb6 | 1052 | spin_lock_bh(&tp->lock); |
158d7abd MC |
1053 | |
1054 | if (tg3_writephy(tp, reg, val)) | |
24bb4fb6 | 1055 | ret = -EIO; |
158d7abd | 1056 | |
24bb4fb6 MC |
1057 | spin_unlock_bh(&tp->lock); |
1058 | ||
1059 | return ret; | |
158d7abd MC |
1060 | } |
1061 | ||
1062 | static int tg3_mdio_reset(struct mii_bus *bp) | |
1063 | { | |
1064 | return 0; | |
1065 | } | |
1066 | ||
9c61d6bc | 1067 | static void tg3_mdio_config_5785(struct tg3 *tp) |
a9daf367 MC |
1068 | { |
1069 | u32 val; | |
fcb389df | 1070 | struct phy_device *phydev; |
a9daf367 | 1071 | |
3f0e3ad7 | 1072 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
fcb389df | 1073 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
6a443a0f MC |
1074 | case PHY_ID_BCM50610: |
1075 | case PHY_ID_BCM50610M: | |
fcb389df MC |
1076 | val = MAC_PHYCFG2_50610_LED_MODES; |
1077 | break; | |
6a443a0f | 1078 | case PHY_ID_BCMAC131: |
fcb389df MC |
1079 | val = MAC_PHYCFG2_AC131_LED_MODES; |
1080 | break; | |
6a443a0f | 1081 | case PHY_ID_RTL8211C: |
fcb389df MC |
1082 | val = MAC_PHYCFG2_RTL8211C_LED_MODES; |
1083 | break; | |
6a443a0f | 1084 | case PHY_ID_RTL8201E: |
fcb389df MC |
1085 | val = MAC_PHYCFG2_RTL8201E_LED_MODES; |
1086 | break; | |
1087 | default: | |
a9daf367 | 1088 | return; |
fcb389df MC |
1089 | } |
1090 | ||
1091 | if (phydev->interface != PHY_INTERFACE_MODE_RGMII) { | |
1092 | tw32(MAC_PHYCFG2, val); | |
1093 | ||
1094 | val = tr32(MAC_PHYCFG1); | |
bb85fbb6 MC |
1095 | val &= ~(MAC_PHYCFG1_RGMII_INT | |
1096 | MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK); | |
1097 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT; | |
fcb389df MC |
1098 | tw32(MAC_PHYCFG1, val); |
1099 | ||
1100 | return; | |
1101 | } | |
1102 | ||
63c3a66f | 1103 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) |
fcb389df MC |
1104 | val |= MAC_PHYCFG2_EMODE_MASK_MASK | |
1105 | MAC_PHYCFG2_FMODE_MASK_MASK | | |
1106 | MAC_PHYCFG2_GMODE_MASK_MASK | | |
1107 | MAC_PHYCFG2_ACT_MASK_MASK | | |
1108 | MAC_PHYCFG2_QUAL_MASK_MASK | | |
1109 | MAC_PHYCFG2_INBAND_ENABLE; | |
1110 | ||
1111 | tw32(MAC_PHYCFG2, val); | |
a9daf367 | 1112 | |
bb85fbb6 MC |
1113 | val = tr32(MAC_PHYCFG1); |
1114 | val &= ~(MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK | | |
1115 | MAC_PHYCFG1_RGMII_EXT_RX_DEC | MAC_PHYCFG1_RGMII_SND_STAT_EN); | |
63c3a66f JP |
1116 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
1117 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) | |
a9daf367 | 1118 | val |= MAC_PHYCFG1_RGMII_EXT_RX_DEC; |
63c3a66f | 1119 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
a9daf367 MC |
1120 | val |= MAC_PHYCFG1_RGMII_SND_STAT_EN; |
1121 | } | |
bb85fbb6 MC |
1122 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT | |
1123 | MAC_PHYCFG1_RGMII_INT | MAC_PHYCFG1_TXC_DRV; | |
1124 | tw32(MAC_PHYCFG1, val); | |
a9daf367 | 1125 | |
a9daf367 MC |
1126 | val = tr32(MAC_EXT_RGMII_MODE); |
1127 | val &= ~(MAC_RGMII_MODE_RX_INT_B | | |
1128 | MAC_RGMII_MODE_RX_QUALITY | | |
1129 | MAC_RGMII_MODE_RX_ACTIVITY | | |
1130 | MAC_RGMII_MODE_RX_ENG_DET | | |
1131 | MAC_RGMII_MODE_TX_ENABLE | | |
1132 | MAC_RGMII_MODE_TX_LOWPWR | | |
1133 | MAC_RGMII_MODE_TX_RESET); | |
63c3a66f JP |
1134 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
1135 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) | |
a9daf367 MC |
1136 | val |= MAC_RGMII_MODE_RX_INT_B | |
1137 | MAC_RGMII_MODE_RX_QUALITY | | |
1138 | MAC_RGMII_MODE_RX_ACTIVITY | | |
1139 | MAC_RGMII_MODE_RX_ENG_DET; | |
63c3a66f | 1140 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
a9daf367 MC |
1141 | val |= MAC_RGMII_MODE_TX_ENABLE | |
1142 | MAC_RGMII_MODE_TX_LOWPWR | | |
1143 | MAC_RGMII_MODE_TX_RESET; | |
1144 | } | |
1145 | tw32(MAC_EXT_RGMII_MODE, val); | |
1146 | } | |
1147 | ||
158d7abd MC |
1148 | static void tg3_mdio_start(struct tg3 *tp) |
1149 | { | |
158d7abd MC |
1150 | tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; |
1151 | tw32_f(MAC_MI_MODE, tp->mi_mode); | |
1152 | udelay(80); | |
a9daf367 | 1153 | |
63c3a66f | 1154 | if (tg3_flag(tp, MDIOBUS_INITED) && |
9ea4818d MC |
1155 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
1156 | tg3_mdio_config_5785(tp); | |
1157 | } | |
1158 | ||
1159 | static int tg3_mdio_init(struct tg3 *tp) | |
1160 | { | |
1161 | int i; | |
1162 | u32 reg; | |
1163 | struct phy_device *phydev; | |
1164 | ||
63c3a66f | 1165 | if (tg3_flag(tp, 5717_PLUS)) { |
9c7df915 | 1166 | u32 is_serdes; |
882e9793 | 1167 | |
9c7df915 | 1168 | tp->phy_addr = PCI_FUNC(tp->pdev->devfn) + 1; |
882e9793 | 1169 | |
d1ec96af MC |
1170 | if (tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) |
1171 | is_serdes = tr32(SG_DIG_STATUS) & SG_DIG_IS_SERDES; | |
1172 | else | |
1173 | is_serdes = tr32(TG3_CPMU_PHY_STRAP) & | |
1174 | TG3_CPMU_PHY_STRAP_IS_SERDES; | |
882e9793 MC |
1175 | if (is_serdes) |
1176 | tp->phy_addr += 7; | |
1177 | } else | |
3f0e3ad7 | 1178 | tp->phy_addr = TG3_PHY_MII_ADDR; |
882e9793 | 1179 | |
158d7abd MC |
1180 | tg3_mdio_start(tp); |
1181 | ||
63c3a66f | 1182 | if (!tg3_flag(tp, USE_PHYLIB) || tg3_flag(tp, MDIOBUS_INITED)) |
158d7abd MC |
1183 | return 0; |
1184 | ||
298cf9be LB |
1185 | tp->mdio_bus = mdiobus_alloc(); |
1186 | if (tp->mdio_bus == NULL) | |
1187 | return -ENOMEM; | |
158d7abd | 1188 | |
298cf9be LB |
1189 | tp->mdio_bus->name = "tg3 mdio bus"; |
1190 | snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x", | |
158d7abd | 1191 | (tp->pdev->bus->number << 8) | tp->pdev->devfn); |
298cf9be LB |
1192 | tp->mdio_bus->priv = tp; |
1193 | tp->mdio_bus->parent = &tp->pdev->dev; | |
1194 | tp->mdio_bus->read = &tg3_mdio_read; | |
1195 | tp->mdio_bus->write = &tg3_mdio_write; | |
1196 | tp->mdio_bus->reset = &tg3_mdio_reset; | |
3f0e3ad7 | 1197 | tp->mdio_bus->phy_mask = ~(1 << TG3_PHY_MII_ADDR); |
298cf9be | 1198 | tp->mdio_bus->irq = &tp->mdio_irq[0]; |
158d7abd MC |
1199 | |
1200 | for (i = 0; i < PHY_MAX_ADDR; i++) | |
298cf9be | 1201 | tp->mdio_bus->irq[i] = PHY_POLL; |
158d7abd MC |
1202 | |
1203 | /* The bus registration will look for all the PHYs on the mdio bus. | |
1204 | * Unfortunately, it does not ensure the PHY is powered up before | |
1205 | * accessing the PHY ID registers. A chip reset is the | |
1206 | * quickest way to bring the device back to an operational state.. | |
1207 | */ | |
1208 | if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN)) | |
1209 | tg3_bmcr_reset(tp); | |
1210 | ||
298cf9be | 1211 | i = mdiobus_register(tp->mdio_bus); |
a9daf367 | 1212 | if (i) { |
ab96b241 | 1213 | dev_warn(&tp->pdev->dev, "mdiobus_reg failed (0x%x)\n", i); |
9c61d6bc | 1214 | mdiobus_free(tp->mdio_bus); |
a9daf367 MC |
1215 | return i; |
1216 | } | |
158d7abd | 1217 | |
3f0e3ad7 | 1218 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
a9daf367 | 1219 | |
9c61d6bc | 1220 | if (!phydev || !phydev->drv) { |
ab96b241 | 1221 | dev_warn(&tp->pdev->dev, "No PHY devices\n"); |
9c61d6bc MC |
1222 | mdiobus_unregister(tp->mdio_bus); |
1223 | mdiobus_free(tp->mdio_bus); | |
1224 | return -ENODEV; | |
1225 | } | |
1226 | ||
1227 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { | |
6a443a0f | 1228 | case PHY_ID_BCM57780: |
321d32a0 | 1229 | phydev->interface = PHY_INTERFACE_MODE_GMII; |
c704dc23 | 1230 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
321d32a0 | 1231 | break; |
6a443a0f MC |
1232 | case PHY_ID_BCM50610: |
1233 | case PHY_ID_BCM50610M: | |
32e5a8d6 | 1234 | phydev->dev_flags |= PHY_BRCM_CLEAR_RGMII_MODE | |
c704dc23 | 1235 | PHY_BRCM_RX_REFCLK_UNUSED | |
52fae083 | 1236 | PHY_BRCM_DIS_TXCRXC_NOENRGY | |
c704dc23 | 1237 | PHY_BRCM_AUTO_PWRDWN_ENABLE; |
63c3a66f | 1238 | if (tg3_flag(tp, RGMII_INBAND_DISABLE)) |
a9daf367 | 1239 | phydev->dev_flags |= PHY_BRCM_STD_IBND_DISABLE; |
63c3a66f | 1240 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
a9daf367 | 1241 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_RX_ENABLE; |
63c3a66f | 1242 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
a9daf367 | 1243 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_TX_ENABLE; |
fcb389df | 1244 | /* fallthru */ |
6a443a0f | 1245 | case PHY_ID_RTL8211C: |
fcb389df | 1246 | phydev->interface = PHY_INTERFACE_MODE_RGMII; |
a9daf367 | 1247 | break; |
6a443a0f MC |
1248 | case PHY_ID_RTL8201E: |
1249 | case PHY_ID_BCMAC131: | |
a9daf367 | 1250 | phydev->interface = PHY_INTERFACE_MODE_MII; |
cdd4e09d | 1251 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
f07e9af3 | 1252 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
a9daf367 MC |
1253 | break; |
1254 | } | |
1255 | ||
63c3a66f | 1256 | tg3_flag_set(tp, MDIOBUS_INITED); |
9c61d6bc MC |
1257 | |
1258 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) | |
1259 | tg3_mdio_config_5785(tp); | |
a9daf367 MC |
1260 | |
1261 | return 0; | |
158d7abd MC |
1262 | } |
1263 | ||
1264 | static void tg3_mdio_fini(struct tg3 *tp) | |
1265 | { | |
63c3a66f JP |
1266 | if (tg3_flag(tp, MDIOBUS_INITED)) { |
1267 | tg3_flag_clear(tp, MDIOBUS_INITED); | |
298cf9be LB |
1268 | mdiobus_unregister(tp->mdio_bus); |
1269 | mdiobus_free(tp->mdio_bus); | |
158d7abd MC |
1270 | } |
1271 | } | |
1272 | ||
4ba526ce MC |
1273 | /* tp->lock is held. */ |
1274 | static inline void tg3_generate_fw_event(struct tg3 *tp) | |
1275 | { | |
1276 | u32 val; | |
1277 | ||
1278 | val = tr32(GRC_RX_CPU_EVENT); | |
1279 | val |= GRC_RX_CPU_DRIVER_EVENT; | |
1280 | tw32_f(GRC_RX_CPU_EVENT, val); | |
1281 | ||
1282 | tp->last_event_jiffies = jiffies; | |
1283 | } | |
1284 | ||
1285 | #define TG3_FW_EVENT_TIMEOUT_USEC 2500 | |
1286 | ||
95e2869a MC |
1287 | /* tp->lock is held. */ |
1288 | static void tg3_wait_for_event_ack(struct tg3 *tp) | |
1289 | { | |
1290 | int i; | |
4ba526ce MC |
1291 | unsigned int delay_cnt; |
1292 | long time_remain; | |
1293 | ||
1294 | /* If enough time has passed, no wait is necessary. */ | |
1295 | time_remain = (long)(tp->last_event_jiffies + 1 + | |
1296 | usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC)) - | |
1297 | (long)jiffies; | |
1298 | if (time_remain < 0) | |
1299 | return; | |
1300 | ||
1301 | /* Check if we can shorten the wait time. */ | |
1302 | delay_cnt = jiffies_to_usecs(time_remain); | |
1303 | if (delay_cnt > TG3_FW_EVENT_TIMEOUT_USEC) | |
1304 | delay_cnt = TG3_FW_EVENT_TIMEOUT_USEC; | |
1305 | delay_cnt = (delay_cnt >> 3) + 1; | |
95e2869a | 1306 | |
4ba526ce | 1307 | for (i = 0; i < delay_cnt; i++) { |
95e2869a MC |
1308 | if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT)) |
1309 | break; | |
4ba526ce | 1310 | udelay(8); |
95e2869a MC |
1311 | } |
1312 | } | |
1313 | ||
1314 | /* tp->lock is held. */ | |
1315 | static void tg3_ump_link_report(struct tg3 *tp) | |
1316 | { | |
1317 | u32 reg; | |
1318 | u32 val; | |
1319 | ||
63c3a66f | 1320 | if (!tg3_flag(tp, 5780_CLASS) || !tg3_flag(tp, ENABLE_ASF)) |
95e2869a MC |
1321 | return; |
1322 | ||
1323 | tg3_wait_for_event_ack(tp); | |
1324 | ||
1325 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE); | |
1326 | ||
1327 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14); | |
1328 | ||
1329 | val = 0; | |
1330 | if (!tg3_readphy(tp, MII_BMCR, ®)) | |
1331 | val = reg << 16; | |
1332 | if (!tg3_readphy(tp, MII_BMSR, ®)) | |
1333 | val |= (reg & 0xffff); | |
1334 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, val); | |
1335 | ||
1336 | val = 0; | |
1337 | if (!tg3_readphy(tp, MII_ADVERTISE, ®)) | |
1338 | val = reg << 16; | |
1339 | if (!tg3_readphy(tp, MII_LPA, ®)) | |
1340 | val |= (reg & 0xffff); | |
1341 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 4, val); | |
1342 | ||
1343 | val = 0; | |
f07e9af3 | 1344 | if (!(tp->phy_flags & TG3_PHYFLG_MII_SERDES)) { |
95e2869a MC |
1345 | if (!tg3_readphy(tp, MII_CTRL1000, ®)) |
1346 | val = reg << 16; | |
1347 | if (!tg3_readphy(tp, MII_STAT1000, ®)) | |
1348 | val |= (reg & 0xffff); | |
1349 | } | |
1350 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 8, val); | |
1351 | ||
1352 | if (!tg3_readphy(tp, MII_PHYADDR, ®)) | |
1353 | val = reg << 16; | |
1354 | else | |
1355 | val = 0; | |
1356 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 12, val); | |
1357 | ||
4ba526ce | 1358 | tg3_generate_fw_event(tp); |
95e2869a MC |
1359 | } |
1360 | ||
1361 | static void tg3_link_report(struct tg3 *tp) | |
1362 | { | |
1363 | if (!netif_carrier_ok(tp->dev)) { | |
05dbe005 | 1364 | netif_info(tp, link, tp->dev, "Link is down\n"); |
95e2869a MC |
1365 | tg3_ump_link_report(tp); |
1366 | } else if (netif_msg_link(tp)) { | |
05dbe005 JP |
1367 | netdev_info(tp->dev, "Link is up at %d Mbps, %s duplex\n", |
1368 | (tp->link_config.active_speed == SPEED_1000 ? | |
1369 | 1000 : | |
1370 | (tp->link_config.active_speed == SPEED_100 ? | |
1371 | 100 : 10)), | |
1372 | (tp->link_config.active_duplex == DUPLEX_FULL ? | |
1373 | "full" : "half")); | |
1374 | ||
1375 | netdev_info(tp->dev, "Flow control is %s for TX and %s for RX\n", | |
1376 | (tp->link_config.active_flowctrl & FLOW_CTRL_TX) ? | |
1377 | "on" : "off", | |
1378 | (tp->link_config.active_flowctrl & FLOW_CTRL_RX) ? | |
1379 | "on" : "off"); | |
47007831 MC |
1380 | |
1381 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) | |
1382 | netdev_info(tp->dev, "EEE is %s\n", | |
1383 | tp->setlpicnt ? "enabled" : "disabled"); | |
1384 | ||
95e2869a MC |
1385 | tg3_ump_link_report(tp); |
1386 | } | |
1387 | } | |
1388 | ||
1389 | static u16 tg3_advert_flowctrl_1000T(u8 flow_ctrl) | |
1390 | { | |
1391 | u16 miireg; | |
1392 | ||
e18ce346 | 1393 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
95e2869a | 1394 | miireg = ADVERTISE_PAUSE_CAP; |
e18ce346 | 1395 | else if (flow_ctrl & FLOW_CTRL_TX) |
95e2869a | 1396 | miireg = ADVERTISE_PAUSE_ASYM; |
e18ce346 | 1397 | else if (flow_ctrl & FLOW_CTRL_RX) |
95e2869a MC |
1398 | miireg = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
1399 | else | |
1400 | miireg = 0; | |
1401 | ||
1402 | return miireg; | |
1403 | } | |
1404 | ||
1405 | static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl) | |
1406 | { | |
1407 | u16 miireg; | |
1408 | ||
e18ce346 | 1409 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
95e2869a | 1410 | miireg = ADVERTISE_1000XPAUSE; |
e18ce346 | 1411 | else if (flow_ctrl & FLOW_CTRL_TX) |
95e2869a | 1412 | miireg = ADVERTISE_1000XPSE_ASYM; |
e18ce346 | 1413 | else if (flow_ctrl & FLOW_CTRL_RX) |
95e2869a MC |
1414 | miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM; |
1415 | else | |
1416 | miireg = 0; | |
1417 | ||
1418 | return miireg; | |
1419 | } | |
1420 | ||
95e2869a MC |
1421 | static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv) |
1422 | { | |
1423 | u8 cap = 0; | |
1424 | ||
1425 | if (lcladv & ADVERTISE_1000XPAUSE) { | |
1426 | if (lcladv & ADVERTISE_1000XPSE_ASYM) { | |
1427 | if (rmtadv & LPA_1000XPAUSE) | |
e18ce346 | 1428 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
95e2869a | 1429 | else if (rmtadv & LPA_1000XPAUSE_ASYM) |
e18ce346 | 1430 | cap = FLOW_CTRL_RX; |
95e2869a MC |
1431 | } else { |
1432 | if (rmtadv & LPA_1000XPAUSE) | |
e18ce346 | 1433 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
95e2869a MC |
1434 | } |
1435 | } else if (lcladv & ADVERTISE_1000XPSE_ASYM) { | |
1436 | if ((rmtadv & LPA_1000XPAUSE) && (rmtadv & LPA_1000XPAUSE_ASYM)) | |
e18ce346 | 1437 | cap = FLOW_CTRL_TX; |
95e2869a MC |
1438 | } |
1439 | ||
1440 | return cap; | |
1441 | } | |
1442 | ||
f51f3562 | 1443 | static void tg3_setup_flow_control(struct tg3 *tp, u32 lcladv, u32 rmtadv) |
95e2869a | 1444 | { |
b02fd9e3 | 1445 | u8 autoneg; |
f51f3562 | 1446 | u8 flowctrl = 0; |
95e2869a MC |
1447 | u32 old_rx_mode = tp->rx_mode; |
1448 | u32 old_tx_mode = tp->tx_mode; | |
1449 | ||
63c3a66f | 1450 | if (tg3_flag(tp, USE_PHYLIB)) |
3f0e3ad7 | 1451 | autoneg = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]->autoneg; |
b02fd9e3 MC |
1452 | else |
1453 | autoneg = tp->link_config.autoneg; | |
1454 | ||
63c3a66f | 1455 | if (autoneg == AUTONEG_ENABLE && tg3_flag(tp, PAUSE_AUTONEG)) { |
f07e9af3 | 1456 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
f51f3562 | 1457 | flowctrl = tg3_resolve_flowctrl_1000X(lcladv, rmtadv); |
95e2869a | 1458 | else |
bc02ff95 | 1459 | flowctrl = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
f51f3562 MC |
1460 | } else |
1461 | flowctrl = tp->link_config.flowctrl; | |
95e2869a | 1462 | |
f51f3562 | 1463 | tp->link_config.active_flowctrl = flowctrl; |
95e2869a | 1464 | |
e18ce346 | 1465 | if (flowctrl & FLOW_CTRL_RX) |
95e2869a MC |
1466 | tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE; |
1467 | else | |
1468 | tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE; | |
1469 | ||
f51f3562 | 1470 | if (old_rx_mode != tp->rx_mode) |
95e2869a | 1471 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
95e2869a | 1472 | |
e18ce346 | 1473 | if (flowctrl & FLOW_CTRL_TX) |
95e2869a MC |
1474 | tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE; |
1475 | else | |
1476 | tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE; | |
1477 | ||
f51f3562 | 1478 | if (old_tx_mode != tp->tx_mode) |
95e2869a | 1479 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
95e2869a MC |
1480 | } |
1481 | ||
b02fd9e3 MC |
1482 | static void tg3_adjust_link(struct net_device *dev) |
1483 | { | |
1484 | u8 oldflowctrl, linkmesg = 0; | |
1485 | u32 mac_mode, lcl_adv, rmt_adv; | |
1486 | struct tg3 *tp = netdev_priv(dev); | |
3f0e3ad7 | 1487 | struct phy_device *phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
b02fd9e3 | 1488 | |
24bb4fb6 | 1489 | spin_lock_bh(&tp->lock); |
b02fd9e3 MC |
1490 | |
1491 | mac_mode = tp->mac_mode & ~(MAC_MODE_PORT_MODE_MASK | | |
1492 | MAC_MODE_HALF_DUPLEX); | |
1493 | ||
1494 | oldflowctrl = tp->link_config.active_flowctrl; | |
1495 | ||
1496 | if (phydev->link) { | |
1497 | lcl_adv = 0; | |
1498 | rmt_adv = 0; | |
1499 | ||
1500 | if (phydev->speed == SPEED_100 || phydev->speed == SPEED_10) | |
1501 | mac_mode |= MAC_MODE_PORT_MODE_MII; | |
c3df0748 MC |
1502 | else if (phydev->speed == SPEED_1000 || |
1503 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) | |
b02fd9e3 | 1504 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
c3df0748 MC |
1505 | else |
1506 | mac_mode |= MAC_MODE_PORT_MODE_MII; | |
b02fd9e3 MC |
1507 | |
1508 | if (phydev->duplex == DUPLEX_HALF) | |
1509 | mac_mode |= MAC_MODE_HALF_DUPLEX; | |
1510 | else { | |
1511 | lcl_adv = tg3_advert_flowctrl_1000T( | |
1512 | tp->link_config.flowctrl); | |
1513 | ||
1514 | if (phydev->pause) | |
1515 | rmt_adv = LPA_PAUSE_CAP; | |
1516 | if (phydev->asym_pause) | |
1517 | rmt_adv |= LPA_PAUSE_ASYM; | |
1518 | } | |
1519 | ||
1520 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); | |
1521 | } else | |
1522 | mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
1523 | ||
1524 | if (mac_mode != tp->mac_mode) { | |
1525 | tp->mac_mode = mac_mode; | |
1526 | tw32_f(MAC_MODE, tp->mac_mode); | |
1527 | udelay(40); | |
1528 | } | |
1529 | ||
fcb389df MC |
1530 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
1531 | if (phydev->speed == SPEED_10) | |
1532 | tw32(MAC_MI_STAT, | |
1533 | MAC_MI_STAT_10MBPS_MODE | | |
1534 | MAC_MI_STAT_LNKSTAT_ATTN_ENAB); | |
1535 | else | |
1536 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); | |
1537 | } | |
1538 | ||
b02fd9e3 MC |
1539 | if (phydev->speed == SPEED_1000 && phydev->duplex == DUPLEX_HALF) |
1540 | tw32(MAC_TX_LENGTHS, | |
1541 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | | |
1542 | (6 << TX_LENGTHS_IPG_SHIFT) | | |
1543 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); | |
1544 | else | |
1545 | tw32(MAC_TX_LENGTHS, | |
1546 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | | |
1547 | (6 << TX_LENGTHS_IPG_SHIFT) | | |
1548 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); | |
1549 | ||
1550 | if ((phydev->link && tp->link_config.active_speed == SPEED_INVALID) || | |
1551 | (!phydev->link && tp->link_config.active_speed != SPEED_INVALID) || | |
1552 | phydev->speed != tp->link_config.active_speed || | |
1553 | phydev->duplex != tp->link_config.active_duplex || | |
1554 | oldflowctrl != tp->link_config.active_flowctrl) | |
c6cdf436 | 1555 | linkmesg = 1; |
b02fd9e3 MC |
1556 | |
1557 | tp->link_config.active_speed = phydev->speed; | |
1558 | tp->link_config.active_duplex = phydev->duplex; | |
1559 | ||
24bb4fb6 | 1560 | spin_unlock_bh(&tp->lock); |
b02fd9e3 MC |
1561 | |
1562 | if (linkmesg) | |
1563 | tg3_link_report(tp); | |
1564 | } | |
1565 | ||
1566 | static int tg3_phy_init(struct tg3 *tp) | |
1567 | { | |
1568 | struct phy_device *phydev; | |
1569 | ||
f07e9af3 | 1570 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) |
b02fd9e3 MC |
1571 | return 0; |
1572 | ||
1573 | /* Bring the PHY back to a known state. */ | |
1574 | tg3_bmcr_reset(tp); | |
1575 | ||
3f0e3ad7 | 1576 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
b02fd9e3 MC |
1577 | |
1578 | /* Attach the MAC to the PHY. */ | |
fb28ad35 | 1579 | phydev = phy_connect(tp->dev, dev_name(&phydev->dev), tg3_adjust_link, |
a9daf367 | 1580 | phydev->dev_flags, phydev->interface); |
b02fd9e3 | 1581 | if (IS_ERR(phydev)) { |
ab96b241 | 1582 | dev_err(&tp->pdev->dev, "Could not attach to PHY\n"); |
b02fd9e3 MC |
1583 | return PTR_ERR(phydev); |
1584 | } | |
1585 | ||
b02fd9e3 | 1586 | /* Mask with MAC supported features. */ |
9c61d6bc MC |
1587 | switch (phydev->interface) { |
1588 | case PHY_INTERFACE_MODE_GMII: | |
1589 | case PHY_INTERFACE_MODE_RGMII: | |
f07e9af3 | 1590 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
321d32a0 MC |
1591 | phydev->supported &= (PHY_GBIT_FEATURES | |
1592 | SUPPORTED_Pause | | |
1593 | SUPPORTED_Asym_Pause); | |
1594 | break; | |
1595 | } | |
1596 | /* fallthru */ | |
9c61d6bc MC |
1597 | case PHY_INTERFACE_MODE_MII: |
1598 | phydev->supported &= (PHY_BASIC_FEATURES | | |
1599 | SUPPORTED_Pause | | |
1600 | SUPPORTED_Asym_Pause); | |
1601 | break; | |
1602 | default: | |
3f0e3ad7 | 1603 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
9c61d6bc MC |
1604 | return -EINVAL; |
1605 | } | |
1606 | ||
f07e9af3 | 1607 | tp->phy_flags |= TG3_PHYFLG_IS_CONNECTED; |
b02fd9e3 MC |
1608 | |
1609 | phydev->advertising = phydev->supported; | |
1610 | ||
b02fd9e3 MC |
1611 | return 0; |
1612 | } | |
1613 | ||
1614 | static void tg3_phy_start(struct tg3 *tp) | |
1615 | { | |
1616 | struct phy_device *phydev; | |
1617 | ||
f07e9af3 | 1618 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 MC |
1619 | return; |
1620 | ||
3f0e3ad7 | 1621 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
b02fd9e3 | 1622 | |
80096068 MC |
1623 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
1624 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; | |
b02fd9e3 MC |
1625 | phydev->speed = tp->link_config.orig_speed; |
1626 | phydev->duplex = tp->link_config.orig_duplex; | |
1627 | phydev->autoneg = tp->link_config.orig_autoneg; | |
1628 | phydev->advertising = tp->link_config.orig_advertising; | |
1629 | } | |
1630 | ||
1631 | phy_start(phydev); | |
1632 | ||
1633 | phy_start_aneg(phydev); | |
1634 | } | |
1635 | ||
1636 | static void tg3_phy_stop(struct tg3 *tp) | |
1637 | { | |
f07e9af3 | 1638 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 MC |
1639 | return; |
1640 | ||
3f0e3ad7 | 1641 | phy_stop(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
b02fd9e3 MC |
1642 | } |
1643 | ||
1644 | static void tg3_phy_fini(struct tg3 *tp) | |
1645 | { | |
f07e9af3 | 1646 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
3f0e3ad7 | 1647 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
f07e9af3 | 1648 | tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED; |
b02fd9e3 MC |
1649 | } |
1650 | } | |
1651 | ||
7f97a4bd MC |
1652 | static void tg3_phy_fet_toggle_apd(struct tg3 *tp, bool enable) |
1653 | { | |
1654 | u32 phytest; | |
1655 | ||
1656 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { | |
1657 | u32 phy; | |
1658 | ||
1659 | tg3_writephy(tp, MII_TG3_FET_TEST, | |
1660 | phytest | MII_TG3_FET_SHADOW_EN); | |
1661 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXSTAT2, &phy)) { | |
1662 | if (enable) | |
1663 | phy |= MII_TG3_FET_SHDW_AUXSTAT2_APD; | |
1664 | else | |
1665 | phy &= ~MII_TG3_FET_SHDW_AUXSTAT2_APD; | |
1666 | tg3_writephy(tp, MII_TG3_FET_SHDW_AUXSTAT2, phy); | |
1667 | } | |
1668 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); | |
1669 | } | |
1670 | } | |
1671 | ||
6833c043 MC |
1672 | static void tg3_phy_toggle_apd(struct tg3 *tp, bool enable) |
1673 | { | |
1674 | u32 reg; | |
1675 | ||
63c3a66f JP |
1676 | if (!tg3_flag(tp, 5705_PLUS) || |
1677 | (tg3_flag(tp, 5717_PLUS) && | |
f07e9af3 | 1678 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
6833c043 MC |
1679 | return; |
1680 | ||
f07e9af3 | 1681 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
7f97a4bd MC |
1682 | tg3_phy_fet_toggle_apd(tp, enable); |
1683 | return; | |
1684 | } | |
1685 | ||
6833c043 MC |
1686 | reg = MII_TG3_MISC_SHDW_WREN | |
1687 | MII_TG3_MISC_SHDW_SCR5_SEL | | |
1688 | MII_TG3_MISC_SHDW_SCR5_LPED | | |
1689 | MII_TG3_MISC_SHDW_SCR5_DLPTLM | | |
1690 | MII_TG3_MISC_SHDW_SCR5_SDTL | | |
1691 | MII_TG3_MISC_SHDW_SCR5_C125OE; | |
1692 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 || !enable) | |
1693 | reg |= MII_TG3_MISC_SHDW_SCR5_DLLAPD; | |
1694 | ||
1695 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); | |
1696 | ||
1697 | ||
1698 | reg = MII_TG3_MISC_SHDW_WREN | | |
1699 | MII_TG3_MISC_SHDW_APD_SEL | | |
1700 | MII_TG3_MISC_SHDW_APD_WKTM_84MS; | |
1701 | if (enable) | |
1702 | reg |= MII_TG3_MISC_SHDW_APD_ENABLE; | |
1703 | ||
1704 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); | |
1705 | } | |
1706 | ||
9ef8ca99 MC |
1707 | static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable) |
1708 | { | |
1709 | u32 phy; | |
1710 | ||
63c3a66f | 1711 | if (!tg3_flag(tp, 5705_PLUS) || |
f07e9af3 | 1712 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
9ef8ca99 MC |
1713 | return; |
1714 | ||
f07e9af3 | 1715 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
9ef8ca99 MC |
1716 | u32 ephy; |
1717 | ||
535ef6e1 MC |
1718 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &ephy)) { |
1719 | u32 reg = MII_TG3_FET_SHDW_MISCCTRL; | |
1720 | ||
1721 | tg3_writephy(tp, MII_TG3_FET_TEST, | |
1722 | ephy | MII_TG3_FET_SHADOW_EN); | |
1723 | if (!tg3_readphy(tp, reg, &phy)) { | |
9ef8ca99 | 1724 | if (enable) |
535ef6e1 | 1725 | phy |= MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
9ef8ca99 | 1726 | else |
535ef6e1 MC |
1727 | phy &= ~MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
1728 | tg3_writephy(tp, reg, phy); | |
9ef8ca99 | 1729 | } |
535ef6e1 | 1730 | tg3_writephy(tp, MII_TG3_FET_TEST, ephy); |
9ef8ca99 MC |
1731 | } |
1732 | } else { | |
15ee95c3 MC |
1733 | int ret; |
1734 | ||
1735 | ret = tg3_phy_auxctl_read(tp, | |
1736 | MII_TG3_AUXCTL_SHDWSEL_MISC, &phy); | |
1737 | if (!ret) { | |
9ef8ca99 MC |
1738 | if (enable) |
1739 | phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX; | |
1740 | else | |
1741 | phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX; | |
b4bd2929 MC |
1742 | tg3_phy_auxctl_write(tp, |
1743 | MII_TG3_AUXCTL_SHDWSEL_MISC, phy); | |
9ef8ca99 MC |
1744 | } |
1745 | } | |
1746 | } | |
1747 | ||
1da177e4 LT |
1748 | static void tg3_phy_set_wirespeed(struct tg3 *tp) |
1749 | { | |
15ee95c3 | 1750 | int ret; |
1da177e4 LT |
1751 | u32 val; |
1752 | ||
f07e9af3 | 1753 | if (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) |
1da177e4 LT |
1754 | return; |
1755 | ||
15ee95c3 MC |
1756 | ret = tg3_phy_auxctl_read(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, &val); |
1757 | if (!ret) | |
b4bd2929 MC |
1758 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, |
1759 | val | MII_TG3_AUXCTL_MISC_WIRESPD_EN); | |
1da177e4 LT |
1760 | } |
1761 | ||
b2a5c19c MC |
1762 | static void tg3_phy_apply_otp(struct tg3 *tp) |
1763 | { | |
1764 | u32 otp, phy; | |
1765 | ||
1766 | if (!tp->phy_otp) | |
1767 | return; | |
1768 | ||
1769 | otp = tp->phy_otp; | |
1770 | ||
1d36ba45 MC |
1771 | if (TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) |
1772 | return; | |
b2a5c19c MC |
1773 | |
1774 | phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT); | |
1775 | phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT; | |
1776 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy); | |
1777 | ||
1778 | phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) | | |
1779 | ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT); | |
1780 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy); | |
1781 | ||
1782 | phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT); | |
1783 | phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ; | |
1784 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy); | |
1785 | ||
1786 | phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT); | |
1787 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy); | |
1788 | ||
1789 | phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT); | |
1790 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy); | |
1791 | ||
1792 | phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) | | |
1793 | ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT); | |
1794 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy); | |
1795 | ||
1d36ba45 | 1796 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
b2a5c19c MC |
1797 | } |
1798 | ||
52b02d04 MC |
1799 | static void tg3_phy_eee_adjust(struct tg3 *tp, u32 current_link_up) |
1800 | { | |
1801 | u32 val; | |
1802 | ||
1803 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) | |
1804 | return; | |
1805 | ||
1806 | tp->setlpicnt = 0; | |
1807 | ||
1808 | if (tp->link_config.autoneg == AUTONEG_ENABLE && | |
1809 | current_link_up == 1 && | |
a6b68dab MC |
1810 | tp->link_config.active_duplex == DUPLEX_FULL && |
1811 | (tp->link_config.active_speed == SPEED_100 || | |
1812 | tp->link_config.active_speed == SPEED_1000)) { | |
52b02d04 MC |
1813 | u32 eeectl; |
1814 | ||
1815 | if (tp->link_config.active_speed == SPEED_1000) | |
1816 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_16_5_US; | |
1817 | else | |
1818 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_36_US; | |
1819 | ||
1820 | tw32(TG3_CPMU_EEE_CTRL, eeectl); | |
1821 | ||
3110f5f5 MC |
1822 | tg3_phy_cl45_read(tp, MDIO_MMD_AN, |
1823 | TG3_CL45_D7_EEERES_STAT, &val); | |
52b02d04 | 1824 | |
b0c5943f MC |
1825 | if (val == TG3_CL45_D7_EEERES_STAT_LP_1000T || |
1826 | val == TG3_CL45_D7_EEERES_STAT_LP_100TX) | |
52b02d04 MC |
1827 | tp->setlpicnt = 2; |
1828 | } | |
1829 | ||
1830 | if (!tp->setlpicnt) { | |
1831 | val = tr32(TG3_CPMU_EEE_MODE); | |
1832 | tw32(TG3_CPMU_EEE_MODE, val & ~TG3_CPMU_EEEMD_LPI_ENABLE); | |
1833 | } | |
1834 | } | |
1835 | ||
b0c5943f MC |
1836 | static void tg3_phy_eee_enable(struct tg3 *tp) |
1837 | { | |
1838 | u32 val; | |
1839 | ||
1840 | if (tp->link_config.active_speed == SPEED_1000 && | |
1841 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || | |
1842 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || | |
1843 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) && | |
1844 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { | |
1845 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, 0x0003); | |
1846 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); | |
1847 | } | |
1848 | ||
1849 | val = tr32(TG3_CPMU_EEE_MODE); | |
1850 | tw32(TG3_CPMU_EEE_MODE, val | TG3_CPMU_EEEMD_LPI_ENABLE); | |
1851 | } | |
1852 | ||
1da177e4 LT |
1853 | static int tg3_wait_macro_done(struct tg3 *tp) |
1854 | { | |
1855 | int limit = 100; | |
1856 | ||
1857 | while (limit--) { | |
1858 | u32 tmp32; | |
1859 | ||
f08aa1a8 | 1860 | if (!tg3_readphy(tp, MII_TG3_DSP_CONTROL, &tmp32)) { |
1da177e4 LT |
1861 | if ((tmp32 & 0x1000) == 0) |
1862 | break; | |
1863 | } | |
1864 | } | |
d4675b52 | 1865 | if (limit < 0) |
1da177e4 LT |
1866 | return -EBUSY; |
1867 | ||
1868 | return 0; | |
1869 | } | |
1870 | ||
1871 | static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp) | |
1872 | { | |
1873 | static const u32 test_pat[4][6] = { | |
1874 | { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 }, | |
1875 | { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 }, | |
1876 | { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 }, | |
1877 | { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 } | |
1878 | }; | |
1879 | int chan; | |
1880 | ||
1881 | for (chan = 0; chan < 4; chan++) { | |
1882 | int i; | |
1883 | ||
1884 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, | |
1885 | (chan * 0x2000) | 0x0200); | |
f08aa1a8 | 1886 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
1da177e4 LT |
1887 | |
1888 | for (i = 0; i < 6; i++) | |
1889 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, | |
1890 | test_pat[chan][i]); | |
1891 | ||
f08aa1a8 | 1892 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
1da177e4 LT |
1893 | if (tg3_wait_macro_done(tp)) { |
1894 | *resetp = 1; | |
1895 | return -EBUSY; | |
1896 | } | |
1897 | ||
1898 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, | |
1899 | (chan * 0x2000) | 0x0200); | |
f08aa1a8 | 1900 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0082); |
1da177e4 LT |
1901 | if (tg3_wait_macro_done(tp)) { |
1902 | *resetp = 1; | |
1903 | return -EBUSY; | |
1904 | } | |
1905 | ||
f08aa1a8 | 1906 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0802); |
1da177e4 LT |
1907 | if (tg3_wait_macro_done(tp)) { |
1908 | *resetp = 1; | |
1909 | return -EBUSY; | |
1910 | } | |
1911 | ||
1912 | for (i = 0; i < 6; i += 2) { | |
1913 | u32 low, high; | |
1914 | ||
1915 | if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) || | |
1916 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) || | |
1917 | tg3_wait_macro_done(tp)) { | |
1918 | *resetp = 1; | |
1919 | return -EBUSY; | |
1920 | } | |
1921 | low &= 0x7fff; | |
1922 | high &= 0x000f; | |
1923 | if (low != test_pat[chan][i] || | |
1924 | high != test_pat[chan][i+1]) { | |
1925 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b); | |
1926 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001); | |
1927 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005); | |
1928 | ||
1929 | return -EBUSY; | |
1930 | } | |
1931 | } | |
1932 | } | |
1933 | ||
1934 | return 0; | |
1935 | } | |
1936 | ||
1937 | static int tg3_phy_reset_chanpat(struct tg3 *tp) | |
1938 | { | |
1939 | int chan; | |
1940 | ||
1941 | for (chan = 0; chan < 4; chan++) { | |
1942 | int i; | |
1943 | ||
1944 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, | |
1945 | (chan * 0x2000) | 0x0200); | |
f08aa1a8 | 1946 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
1da177e4 LT |
1947 | for (i = 0; i < 6; i++) |
1948 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000); | |
f08aa1a8 | 1949 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
1da177e4 LT |
1950 | if (tg3_wait_macro_done(tp)) |
1951 | return -EBUSY; | |
1952 | } | |
1953 | ||
1954 | return 0; | |
1955 | } | |
1956 | ||
1957 | static int tg3_phy_reset_5703_4_5(struct tg3 *tp) | |
1958 | { | |
1959 | u32 reg32, phy9_orig; | |
1960 | int retries, do_phy_reset, err; | |
1961 | ||
1962 | retries = 10; | |
1963 | do_phy_reset = 1; | |
1964 | do { | |
1965 | if (do_phy_reset) { | |
1966 | err = tg3_bmcr_reset(tp); | |
1967 | if (err) | |
1968 | return err; | |
1969 | do_phy_reset = 0; | |
1970 | } | |
1971 | ||
1972 | /* Disable transmitter and interrupt. */ | |
1973 | if (tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) | |
1974 | continue; | |
1975 | ||
1976 | reg32 |= 0x3000; | |
1977 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); | |
1978 | ||
1979 | /* Set full-duplex, 1000 mbps. */ | |
1980 | tg3_writephy(tp, MII_BMCR, | |
1981 | BMCR_FULLDPLX | TG3_BMCR_SPEED1000); | |
1982 | ||
1983 | /* Set to master mode. */ | |
1984 | if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig)) | |
1985 | continue; | |
1986 | ||
1987 | tg3_writephy(tp, MII_TG3_CTRL, | |
1988 | (MII_TG3_CTRL_AS_MASTER | | |
1989 | MII_TG3_CTRL_ENABLE_AS_MASTER)); | |
1990 | ||
1d36ba45 MC |
1991 | err = TG3_PHY_AUXCTL_SMDSP_ENABLE(tp); |
1992 | if (err) | |
1993 | return err; | |
1da177e4 LT |
1994 | |
1995 | /* Block the PHY control access. */ | |
6ee7c0a0 | 1996 | tg3_phydsp_write(tp, 0x8005, 0x0800); |
1da177e4 LT |
1997 | |
1998 | err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset); | |
1999 | if (!err) | |
2000 | break; | |
2001 | } while (--retries); | |
2002 | ||
2003 | err = tg3_phy_reset_chanpat(tp); | |
2004 | if (err) | |
2005 | return err; | |
2006 | ||
6ee7c0a0 | 2007 | tg3_phydsp_write(tp, 0x8005, 0x0000); |
1da177e4 LT |
2008 | |
2009 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200); | |
f08aa1a8 | 2010 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0000); |
1da177e4 | 2011 | |
1d36ba45 | 2012 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
1da177e4 LT |
2013 | |
2014 | tg3_writephy(tp, MII_TG3_CTRL, phy9_orig); | |
2015 | ||
2016 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) { | |
2017 | reg32 &= ~0x3000; | |
2018 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); | |
2019 | } else if (!err) | |
2020 | err = -EBUSY; | |
2021 | ||
2022 | return err; | |
2023 | } | |
2024 | ||
2025 | /* This will reset the tigon3 PHY if there is no valid | |
2026 | * link unless the FORCE argument is non-zero. | |
2027 | */ | |
2028 | static int tg3_phy_reset(struct tg3 *tp) | |
2029 | { | |
f833c4c1 | 2030 | u32 val, cpmuctrl; |
1da177e4 LT |
2031 | int err; |
2032 | ||
60189ddf | 2033 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
60189ddf MC |
2034 | val = tr32(GRC_MISC_CFG); |
2035 | tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ); | |
2036 | udelay(40); | |
2037 | } | |
f833c4c1 MC |
2038 | err = tg3_readphy(tp, MII_BMSR, &val); |
2039 | err |= tg3_readphy(tp, MII_BMSR, &val); | |
1da177e4 LT |
2040 | if (err != 0) |
2041 | return -EBUSY; | |
2042 | ||
c8e1e82b MC |
2043 | if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) { |
2044 | netif_carrier_off(tp->dev); | |
2045 | tg3_link_report(tp); | |
2046 | } | |
2047 | ||
1da177e4 LT |
2048 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
2049 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || | |
2050 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { | |
2051 | err = tg3_phy_reset_5703_4_5(tp); | |
2052 | if (err) | |
2053 | return err; | |
2054 | goto out; | |
2055 | } | |
2056 | ||
b2a5c19c MC |
2057 | cpmuctrl = 0; |
2058 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && | |
2059 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { | |
2060 | cpmuctrl = tr32(TG3_CPMU_CTRL); | |
2061 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) | |
2062 | tw32(TG3_CPMU_CTRL, | |
2063 | cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY); | |
2064 | } | |
2065 | ||
1da177e4 LT |
2066 | err = tg3_bmcr_reset(tp); |
2067 | if (err) | |
2068 | return err; | |
2069 | ||
b2a5c19c | 2070 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) { |
f833c4c1 MC |
2071 | val = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz; |
2072 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, val); | |
b2a5c19c MC |
2073 | |
2074 | tw32(TG3_CPMU_CTRL, cpmuctrl); | |
2075 | } | |
2076 | ||
bcb37f6c MC |
2077 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
2078 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { | |
ce057f01 MC |
2079 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
2080 | if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) == | |
2081 | CPMU_LSPD_1000MB_MACCLK_12_5) { | |
2082 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; | |
2083 | udelay(40); | |
2084 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); | |
2085 | } | |
2086 | } | |
2087 | ||
63c3a66f | 2088 | if (tg3_flag(tp, 5717_PLUS) && |
f07e9af3 | 2089 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) |
ecf1410b MC |
2090 | return 0; |
2091 | ||
b2a5c19c MC |
2092 | tg3_phy_apply_otp(tp); |
2093 | ||
f07e9af3 | 2094 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
6833c043 MC |
2095 | tg3_phy_toggle_apd(tp, true); |
2096 | else | |
2097 | tg3_phy_toggle_apd(tp, false); | |
2098 | ||
1da177e4 | 2099 | out: |
1d36ba45 MC |
2100 | if ((tp->phy_flags & TG3_PHYFLG_ADC_BUG) && |
2101 | !TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { | |
6ee7c0a0 MC |
2102 | tg3_phydsp_write(tp, 0x201f, 0x2aaa); |
2103 | tg3_phydsp_write(tp, 0x000a, 0x0323); | |
1d36ba45 | 2104 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
1da177e4 | 2105 | } |
1d36ba45 | 2106 | |
f07e9af3 | 2107 | if (tp->phy_flags & TG3_PHYFLG_5704_A0_BUG) { |
f08aa1a8 MC |
2108 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
2109 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); | |
1da177e4 | 2110 | } |
1d36ba45 | 2111 | |
f07e9af3 | 2112 | if (tp->phy_flags & TG3_PHYFLG_BER_BUG) { |
1d36ba45 MC |
2113 | if (!TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
2114 | tg3_phydsp_write(tp, 0x000a, 0x310b); | |
2115 | tg3_phydsp_write(tp, 0x201f, 0x9506); | |
2116 | tg3_phydsp_write(tp, 0x401f, 0x14e2); | |
2117 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); | |
2118 | } | |
f07e9af3 | 2119 | } else if (tp->phy_flags & TG3_PHYFLG_JITTER_BUG) { |
1d36ba45 MC |
2120 | if (!TG3_PHY_AUXCTL_SMDSP_ENABLE(tp)) { |
2121 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); | |
2122 | if (tp->phy_flags & TG3_PHYFLG_ADJUST_TRIM) { | |
2123 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b); | |
2124 | tg3_writephy(tp, MII_TG3_TEST1, | |
2125 | MII_TG3_TEST1_TRIM_EN | 0x4); | |
2126 | } else | |
2127 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b); | |
2128 | ||
2129 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); | |
2130 | } | |
c424cb24 | 2131 | } |
1d36ba45 | 2132 | |
1da177e4 LT |
2133 | /* Set Extended packet length bit (bit 14) on all chips that */ |
2134 | /* support jumbo frames */ | |
79eb6904 | 2135 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
1da177e4 | 2136 | /* Cannot do read-modify-write on 5401 */ |
b4bd2929 | 2137 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
63c3a66f | 2138 | } else if (tg3_flag(tp, JUMBO_CAPABLE)) { |
1da177e4 | 2139 | /* Set bit 14 with read-modify-write to preserve other bits */ |
15ee95c3 MC |
2140 | err = tg3_phy_auxctl_read(tp, |
2141 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); | |
2142 | if (!err) | |
b4bd2929 MC |
2143 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
2144 | val | MII_TG3_AUXCTL_ACTL_EXTPKTLEN); | |
1da177e4 LT |
2145 | } |
2146 | ||
2147 | /* Set phy register 0x10 bit 0 to high fifo elasticity to support | |
2148 | * jumbo frames transmission. | |
2149 | */ | |
63c3a66f | 2150 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
f833c4c1 | 2151 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &val)) |
c6cdf436 | 2152 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
f833c4c1 | 2153 | val | MII_TG3_EXT_CTRL_FIFO_ELASTIC); |
1da177e4 LT |
2154 | } |
2155 | ||
715116a1 | 2156 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
715116a1 | 2157 | /* adjust output voltage */ |
535ef6e1 | 2158 | tg3_writephy(tp, MII_TG3_FET_PTEST, 0x12); |
715116a1 MC |
2159 | } |
2160 | ||
9ef8ca99 | 2161 | tg3_phy_toggle_automdix(tp, 1); |
1da177e4 LT |
2162 | tg3_phy_set_wirespeed(tp); |
2163 | return 0; | |
2164 | } | |
2165 | ||
2166 | static void tg3_frob_aux_power(struct tg3 *tp) | |
2167 | { | |
683644b7 | 2168 | bool need_vaux = false; |
1da177e4 | 2169 | |
334355aa | 2170 | /* The GPIOs do something completely different on 57765. */ |
63c3a66f | 2171 | if (!tg3_flag(tp, IS_NIC) || |
a50d0796 | 2172 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
334355aa | 2173 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
1da177e4 LT |
2174 | return; |
2175 | ||
683644b7 MC |
2176 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
2177 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 || | |
d78b59f5 MC |
2178 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
2179 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) && | |
683644b7 | 2180 | tp->pdev_peer != tp->pdev) { |
8c2dc7e1 MC |
2181 | struct net_device *dev_peer; |
2182 | ||
2183 | dev_peer = pci_get_drvdata(tp->pdev_peer); | |
683644b7 | 2184 | |
bc1c7567 | 2185 | /* remove_one() may have been run on the peer. */ |
683644b7 MC |
2186 | if (dev_peer) { |
2187 | struct tg3 *tp_peer = netdev_priv(dev_peer); | |
2188 | ||
63c3a66f | 2189 | if (tg3_flag(tp_peer, INIT_COMPLETE)) |
683644b7 MC |
2190 | return; |
2191 | ||
63c3a66f JP |
2192 | if (tg3_flag(tp_peer, WOL_ENABLE) || |
2193 | tg3_flag(tp_peer, ENABLE_ASF)) | |
683644b7 MC |
2194 | need_vaux = true; |
2195 | } | |
1da177e4 LT |
2196 | } |
2197 | ||
63c3a66f | 2198 | if (tg3_flag(tp, WOL_ENABLE) || tg3_flag(tp, ENABLE_ASF)) |
683644b7 MC |
2199 | need_vaux = true; |
2200 | ||
2201 | if (need_vaux) { | |
1da177e4 LT |
2202 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
2203 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { | |
b401e9e2 MC |
2204 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2205 | (GRC_LCLCTRL_GPIO_OE0 | | |
2206 | GRC_LCLCTRL_GPIO_OE1 | | |
2207 | GRC_LCLCTRL_GPIO_OE2 | | |
2208 | GRC_LCLCTRL_GPIO_OUTPUT0 | | |
2209 | GRC_LCLCTRL_GPIO_OUTPUT1), | |
2210 | 100); | |
8d519ab2 MC |
2211 | } else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
2212 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { | |
5f0c4a3c MC |
2213 | /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */ |
2214 | u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 | | |
2215 | GRC_LCLCTRL_GPIO_OE1 | | |
2216 | GRC_LCLCTRL_GPIO_OE2 | | |
2217 | GRC_LCLCTRL_GPIO_OUTPUT0 | | |
2218 | GRC_LCLCTRL_GPIO_OUTPUT1 | | |
2219 | tp->grc_local_ctrl; | |
2220 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); | |
2221 | ||
2222 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2; | |
2223 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); | |
2224 | ||
2225 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0; | |
2226 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); | |
1da177e4 LT |
2227 | } else { |
2228 | u32 no_gpio2; | |
dc56b7d4 | 2229 | u32 grc_local_ctrl = 0; |
1da177e4 | 2230 | |
dc56b7d4 MC |
2231 | /* Workaround to prevent overdrawing Amps. */ |
2232 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == | |
2233 | ASIC_REV_5714) { | |
2234 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; | |
b401e9e2 MC |
2235 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2236 | grc_local_ctrl, 100); | |
dc56b7d4 MC |
2237 | } |
2238 | ||
1da177e4 LT |
2239 | /* On 5753 and variants, GPIO2 cannot be used. */ |
2240 | no_gpio2 = tp->nic_sram_data_cfg & | |
2241 | NIC_SRAM_DATA_CFG_NO_GPIO2; | |
2242 | ||
dc56b7d4 | 2243 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
1da177e4 LT |
2244 | GRC_LCLCTRL_GPIO_OE1 | |
2245 | GRC_LCLCTRL_GPIO_OE2 | | |
2246 | GRC_LCLCTRL_GPIO_OUTPUT1 | | |
2247 | GRC_LCLCTRL_GPIO_OUTPUT2; | |
2248 | if (no_gpio2) { | |
2249 | grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 | | |
2250 | GRC_LCLCTRL_GPIO_OUTPUT2); | |
2251 | } | |
b401e9e2 MC |
2252 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2253 | grc_local_ctrl, 100); | |
1da177e4 LT |
2254 | |
2255 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0; | |
2256 | ||
b401e9e2 MC |
2257 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2258 | grc_local_ctrl, 100); | |
1da177e4 LT |
2259 | |
2260 | if (!no_gpio2) { | |
2261 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2; | |
b401e9e2 MC |
2262 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2263 | grc_local_ctrl, 100); | |
1da177e4 LT |
2264 | } |
2265 | } | |
2266 | } else { | |
2267 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && | |
2268 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { | |
b401e9e2 MC |
2269 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2270 | (GRC_LCLCTRL_GPIO_OE1 | | |
2271 | GRC_LCLCTRL_GPIO_OUTPUT1), 100); | |
1da177e4 | 2272 | |
b401e9e2 MC |
2273 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2274 | GRC_LCLCTRL_GPIO_OE1, 100); | |
1da177e4 | 2275 | |
b401e9e2 MC |
2276 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2277 | (GRC_LCLCTRL_GPIO_OE1 | | |
2278 | GRC_LCLCTRL_GPIO_OUTPUT1), 100); | |
1da177e4 LT |
2279 | } |
2280 | } | |
2281 | } | |
2282 | ||
e8f3f6ca MC |
2283 | static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed) |
2284 | { | |
2285 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_2) | |
2286 | return 1; | |
79eb6904 | 2287 | else if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411) { |
e8f3f6ca MC |
2288 | if (speed != SPEED_10) |
2289 | return 1; | |
2290 | } else if (speed == SPEED_10) | |
2291 | return 1; | |
2292 | ||
2293 | return 0; | |
2294 | } | |
2295 | ||
1da177e4 LT |
2296 | static int tg3_setup_phy(struct tg3 *, int); |
2297 | ||
2298 | #define RESET_KIND_SHUTDOWN 0 | |
2299 | #define RESET_KIND_INIT 1 | |
2300 | #define RESET_KIND_SUSPEND 2 | |
2301 | ||
2302 | static void tg3_write_sig_post_reset(struct tg3 *, int); | |
2303 | static int tg3_halt_cpu(struct tg3 *, u32); | |
2304 | ||
0a459aac | 2305 | static void tg3_power_down_phy(struct tg3 *tp, bool do_low_power) |
15c3b696 | 2306 | { |
ce057f01 MC |
2307 | u32 val; |
2308 | ||
f07e9af3 | 2309 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
5129724a MC |
2310 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
2311 | u32 sg_dig_ctrl = tr32(SG_DIG_CTRL); | |
2312 | u32 serdes_cfg = tr32(MAC_SERDES_CFG); | |
2313 | ||
2314 | sg_dig_ctrl |= | |
2315 | SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET; | |
2316 | tw32(SG_DIG_CTRL, sg_dig_ctrl); | |
2317 | tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15)); | |
2318 | } | |
3f7045c1 | 2319 | return; |
5129724a | 2320 | } |
3f7045c1 | 2321 | |
60189ddf | 2322 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
60189ddf MC |
2323 | tg3_bmcr_reset(tp); |
2324 | val = tr32(GRC_MISC_CFG); | |
2325 | tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ); | |
2326 | udelay(40); | |
2327 | return; | |
f07e9af3 | 2328 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
0e5f784c MC |
2329 | u32 phytest; |
2330 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { | |
2331 | u32 phy; | |
2332 | ||
2333 | tg3_writephy(tp, MII_ADVERTISE, 0); | |
2334 | tg3_writephy(tp, MII_BMCR, | |
2335 | BMCR_ANENABLE | BMCR_ANRESTART); | |
2336 | ||
2337 | tg3_writephy(tp, MII_TG3_FET_TEST, | |
2338 | phytest | MII_TG3_FET_SHADOW_EN); | |
2339 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXMODE4, &phy)) { | |
2340 | phy |= MII_TG3_FET_SHDW_AUXMODE4_SBPD; | |
2341 | tg3_writephy(tp, | |
2342 | MII_TG3_FET_SHDW_AUXMODE4, | |
2343 | phy); | |
2344 | } | |
2345 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); | |
2346 | } | |
2347 | return; | |
0a459aac | 2348 | } else if (do_low_power) { |
715116a1 MC |
2349 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
2350 | MII_TG3_EXT_CTRL_FORCE_LED_OFF); | |
0a459aac | 2351 | |
b4bd2929 MC |
2352 | val = MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
2353 | MII_TG3_AUXCTL_PCTL_SPR_ISOLATE | | |
2354 | MII_TG3_AUXCTL_PCTL_VREG_11V; | |
2355 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, val); | |
715116a1 | 2356 | } |
3f7045c1 | 2357 | |
15c3b696 MC |
2358 | /* The PHY should not be powered down on some chips because |
2359 | * of bugs. | |
2360 | */ | |
2361 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
2362 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || | |
2363 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 && | |
f07e9af3 | 2364 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
15c3b696 | 2365 | return; |
ce057f01 | 2366 | |
bcb37f6c MC |
2367 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
2368 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { | |
ce057f01 MC |
2369 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
2370 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; | |
2371 | val |= CPMU_LSPD_1000MB_MACCLK_12_5; | |
2372 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); | |
2373 | } | |
2374 | ||
15c3b696 MC |
2375 | tg3_writephy(tp, MII_BMCR, BMCR_PDOWN); |
2376 | } | |
2377 | ||
ffbcfed4 MC |
2378 | /* tp->lock is held. */ |
2379 | static int tg3_nvram_lock(struct tg3 *tp) | |
2380 | { | |
63c3a66f | 2381 | if (tg3_flag(tp, NVRAM)) { |
ffbcfed4 MC |
2382 | int i; |
2383 | ||
2384 | if (tp->nvram_lock_cnt == 0) { | |
2385 | tw32(NVRAM_SWARB, SWARB_REQ_SET1); | |
2386 | for (i = 0; i < 8000; i++) { | |
2387 | if (tr32(NVRAM_SWARB) & SWARB_GNT1) | |
2388 | break; | |
2389 | udelay(20); | |
2390 | } | |
2391 | if (i == 8000) { | |
2392 | tw32(NVRAM_SWARB, SWARB_REQ_CLR1); | |
2393 | return -ENODEV; | |
2394 | } | |
2395 | } | |
2396 | tp->nvram_lock_cnt++; | |
2397 | } | |
2398 | return 0; | |
2399 | } | |
2400 | ||
2401 | /* tp->lock is held. */ | |
2402 | static void tg3_nvram_unlock(struct tg3 *tp) | |
2403 | { | |
63c3a66f | 2404 | if (tg3_flag(tp, NVRAM)) { |
ffbcfed4 MC |
2405 | if (tp->nvram_lock_cnt > 0) |
2406 | tp->nvram_lock_cnt--; | |
2407 | if (tp->nvram_lock_cnt == 0) | |
2408 | tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1); | |
2409 | } | |
2410 | } | |
2411 | ||
2412 | /* tp->lock is held. */ | |
2413 | static void tg3_enable_nvram_access(struct tg3 *tp) | |
2414 | { | |
63c3a66f | 2415 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
ffbcfed4 MC |
2416 | u32 nvaccess = tr32(NVRAM_ACCESS); |
2417 | ||
2418 | tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE); | |
2419 | } | |
2420 | } | |
2421 | ||
2422 | /* tp->lock is held. */ | |
2423 | static void tg3_disable_nvram_access(struct tg3 *tp) | |
2424 | { | |
63c3a66f | 2425 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
ffbcfed4 MC |
2426 | u32 nvaccess = tr32(NVRAM_ACCESS); |
2427 | ||
2428 | tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE); | |
2429 | } | |
2430 | } | |
2431 | ||
2432 | static int tg3_nvram_read_using_eeprom(struct tg3 *tp, | |
2433 | u32 offset, u32 *val) | |
2434 | { | |
2435 | u32 tmp; | |
2436 | int i; | |
2437 | ||
2438 | if (offset > EEPROM_ADDR_ADDR_MASK || (offset % 4) != 0) | |
2439 | return -EINVAL; | |
2440 | ||
2441 | tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK | | |
2442 | EEPROM_ADDR_DEVID_MASK | | |
2443 | EEPROM_ADDR_READ); | |
2444 | tw32(GRC_EEPROM_ADDR, | |
2445 | tmp | | |
2446 | (0 << EEPROM_ADDR_DEVID_SHIFT) | | |
2447 | ((offset << EEPROM_ADDR_ADDR_SHIFT) & | |
2448 | EEPROM_ADDR_ADDR_MASK) | | |
2449 | EEPROM_ADDR_READ | EEPROM_ADDR_START); | |
2450 | ||
2451 | for (i = 0; i < 1000; i++) { | |
2452 | tmp = tr32(GRC_EEPROM_ADDR); | |
2453 | ||
2454 | if (tmp & EEPROM_ADDR_COMPLETE) | |
2455 | break; | |
2456 | msleep(1); | |
2457 | } | |
2458 | if (!(tmp & EEPROM_ADDR_COMPLETE)) | |
2459 | return -EBUSY; | |
2460 | ||
62cedd11 MC |
2461 | tmp = tr32(GRC_EEPROM_DATA); |
2462 | ||
2463 | /* | |
2464 | * The data will always be opposite the native endian | |
2465 | * format. Perform a blind byteswap to compensate. | |
2466 | */ | |
2467 | *val = swab32(tmp); | |
2468 | ||
ffbcfed4 MC |
2469 | return 0; |
2470 | } | |
2471 | ||
2472 | #define NVRAM_CMD_TIMEOUT 10000 | |
2473 | ||
2474 | static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd) | |
2475 | { | |
2476 | int i; | |
2477 | ||
2478 | tw32(NVRAM_CMD, nvram_cmd); | |
2479 | for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) { | |
2480 | udelay(10); | |
2481 | if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) { | |
2482 | udelay(10); | |
2483 | break; | |
2484 | } | |
2485 | } | |
2486 | ||
2487 | if (i == NVRAM_CMD_TIMEOUT) | |
2488 | return -EBUSY; | |
2489 | ||
2490 | return 0; | |
2491 | } | |
2492 | ||
2493 | static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr) | |
2494 | { | |
63c3a66f JP |
2495 | if (tg3_flag(tp, NVRAM) && |
2496 | tg3_flag(tp, NVRAM_BUFFERED) && | |
2497 | tg3_flag(tp, FLASH) && | |
2498 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && | |
ffbcfed4 MC |
2499 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
2500 | ||
2501 | addr = ((addr / tp->nvram_pagesize) << | |
2502 | ATMEL_AT45DB0X1B_PAGE_POS) + | |
2503 | (addr % tp->nvram_pagesize); | |
2504 | ||
2505 | return addr; | |
2506 | } | |
2507 | ||
2508 | static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr) | |
2509 | { | |
63c3a66f JP |
2510 | if (tg3_flag(tp, NVRAM) && |
2511 | tg3_flag(tp, NVRAM_BUFFERED) && | |
2512 | tg3_flag(tp, FLASH) && | |
2513 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && | |
ffbcfed4 MC |
2514 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
2515 | ||
2516 | addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) * | |
2517 | tp->nvram_pagesize) + | |
2518 | (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1)); | |
2519 | ||
2520 | return addr; | |
2521 | } | |
2522 | ||
e4f34110 MC |
2523 | /* NOTE: Data read in from NVRAM is byteswapped according to |
2524 | * the byteswapping settings for all other register accesses. | |
2525 | * tg3 devices are BE devices, so on a BE machine, the data | |
2526 | * returned will be exactly as it is seen in NVRAM. On a LE | |
2527 | * machine, the 32-bit value will be byteswapped. | |
2528 | */ | |
ffbcfed4 MC |
2529 | static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val) |
2530 | { | |
2531 | int ret; | |
2532 | ||
63c3a66f | 2533 | if (!tg3_flag(tp, NVRAM)) |
ffbcfed4 MC |
2534 | return tg3_nvram_read_using_eeprom(tp, offset, val); |
2535 | ||
2536 | offset = tg3_nvram_phys_addr(tp, offset); | |
2537 | ||
2538 | if (offset > NVRAM_ADDR_MSK) | |
2539 | return -EINVAL; | |
2540 | ||
2541 | ret = tg3_nvram_lock(tp); | |
2542 | if (ret) | |
2543 | return ret; | |
2544 | ||
2545 | tg3_enable_nvram_access(tp); | |
2546 | ||
2547 | tw32(NVRAM_ADDR, offset); | |
2548 | ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO | | |
2549 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE); | |
2550 | ||
2551 | if (ret == 0) | |
e4f34110 | 2552 | *val = tr32(NVRAM_RDDATA); |
ffbcfed4 MC |
2553 | |
2554 | tg3_disable_nvram_access(tp); | |
2555 | ||
2556 | tg3_nvram_unlock(tp); | |
2557 | ||
2558 | return ret; | |
2559 | } | |
2560 | ||
a9dc529d MC |
2561 | /* Ensures NVRAM data is in bytestream format. */ |
2562 | static int tg3_nvram_read_be32(struct tg3 *tp, u32 offset, __be32 *val) | |
ffbcfed4 MC |
2563 | { |
2564 | u32 v; | |
a9dc529d | 2565 | int res = tg3_nvram_read(tp, offset, &v); |
ffbcfed4 | 2566 | if (!res) |
a9dc529d | 2567 | *val = cpu_to_be32(v); |
ffbcfed4 MC |
2568 | return res; |
2569 | } | |
2570 | ||
3f007891 MC |
2571 | /* tp->lock is held. */ |
2572 | static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1) | |
2573 | { | |
2574 | u32 addr_high, addr_low; | |
2575 | int i; | |
2576 | ||
2577 | addr_high = ((tp->dev->dev_addr[0] << 8) | | |
2578 | tp->dev->dev_addr[1]); | |
2579 | addr_low = ((tp->dev->dev_addr[2] << 24) | | |
2580 | (tp->dev->dev_addr[3] << 16) | | |
2581 | (tp->dev->dev_addr[4] << 8) | | |
2582 | (tp->dev->dev_addr[5] << 0)); | |
2583 | for (i = 0; i < 4; i++) { | |
2584 | if (i == 1 && skip_mac_1) | |
2585 | continue; | |
2586 | tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high); | |
2587 | tw32(MAC_ADDR_0_LOW + (i * 8), addr_low); | |
2588 | } | |
2589 | ||
2590 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || | |
2591 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { | |
2592 | for (i = 0; i < 12; i++) { | |
2593 | tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high); | |
2594 | tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low); | |
2595 | } | |
2596 | } | |
2597 | ||
2598 | addr_high = (tp->dev->dev_addr[0] + | |
2599 | tp->dev->dev_addr[1] + | |
2600 | tp->dev->dev_addr[2] + | |
2601 | tp->dev->dev_addr[3] + | |
2602 | tp->dev->dev_addr[4] + | |
2603 | tp->dev->dev_addr[5]) & | |
2604 | TX_BACKOFF_SEED_MASK; | |
2605 | tw32(MAC_TX_BACKOFF_SEED, addr_high); | |
2606 | } | |
2607 | ||
c866b7ea | 2608 | static void tg3_enable_register_access(struct tg3 *tp) |
1da177e4 | 2609 | { |
c866b7ea RW |
2610 | /* |
2611 | * Make sure register accesses (indirect or otherwise) will function | |
2612 | * correctly. | |
1da177e4 LT |
2613 | */ |
2614 | pci_write_config_dword(tp->pdev, | |
c866b7ea RW |
2615 | TG3PCI_MISC_HOST_CTRL, tp->misc_host_ctrl); |
2616 | } | |
1da177e4 | 2617 | |
c866b7ea RW |
2618 | static int tg3_power_up(struct tg3 *tp) |
2619 | { | |
2620 | tg3_enable_register_access(tp); | |
8c6bda1a | 2621 | |
c866b7ea | 2622 | pci_set_power_state(tp->pdev, PCI_D0); |
1da177e4 | 2623 | |
c866b7ea | 2624 | /* Switch out of Vaux if it is a NIC */ |
63c3a66f | 2625 | if (tg3_flag(tp, IS_NIC)) |
c866b7ea | 2626 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100); |
1da177e4 | 2627 | |
c866b7ea RW |
2628 | return 0; |
2629 | } | |
1da177e4 | 2630 | |
c866b7ea RW |
2631 | static int tg3_power_down_prepare(struct tg3 *tp) |
2632 | { | |
2633 | u32 misc_host_ctrl; | |
2634 | bool device_should_wake, do_low_power; | |
2635 | ||
2636 | tg3_enable_register_access(tp); | |
5e7dfd0f MC |
2637 | |
2638 | /* Restore the CLKREQ setting. */ | |
63c3a66f | 2639 | if (tg3_flag(tp, CLKREQ_BUG)) { |
5e7dfd0f MC |
2640 | u16 lnkctl; |
2641 | ||
2642 | pci_read_config_word(tp->pdev, | |
2643 | tp->pcie_cap + PCI_EXP_LNKCTL, | |
2644 | &lnkctl); | |
2645 | lnkctl |= PCI_EXP_LNKCTL_CLKREQ_EN; | |
2646 | pci_write_config_word(tp->pdev, | |
2647 | tp->pcie_cap + PCI_EXP_LNKCTL, | |
2648 | lnkctl); | |
2649 | } | |
2650 | ||
1da177e4 LT |
2651 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
2652 | tw32(TG3PCI_MISC_HOST_CTRL, | |
2653 | misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT); | |
2654 | ||
c866b7ea | 2655 | device_should_wake = device_may_wakeup(&tp->pdev->dev) && |
63c3a66f | 2656 | tg3_flag(tp, WOL_ENABLE); |
05ac4cb7 | 2657 | |
63c3a66f | 2658 | if (tg3_flag(tp, USE_PHYLIB)) { |
0a459aac | 2659 | do_low_power = false; |
f07e9af3 | 2660 | if ((tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) && |
80096068 | 2661 | !(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
b02fd9e3 | 2662 | struct phy_device *phydev; |
0a459aac | 2663 | u32 phyid, advertising; |
b02fd9e3 | 2664 | |
3f0e3ad7 | 2665 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
b02fd9e3 | 2666 | |
80096068 | 2667 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
b02fd9e3 MC |
2668 | |
2669 | tp->link_config.orig_speed = phydev->speed; | |
2670 | tp->link_config.orig_duplex = phydev->duplex; | |
2671 | tp->link_config.orig_autoneg = phydev->autoneg; | |
2672 | tp->link_config.orig_advertising = phydev->advertising; | |
2673 | ||
2674 | advertising = ADVERTISED_TP | | |
2675 | ADVERTISED_Pause | | |
2676 | ADVERTISED_Autoneg | | |
2677 | ADVERTISED_10baseT_Half; | |
2678 | ||
63c3a66f JP |
2679 | if (tg3_flag(tp, ENABLE_ASF) || device_should_wake) { |
2680 | if (tg3_flag(tp, WOL_SPEED_100MB)) | |
b02fd9e3 MC |
2681 | advertising |= |
2682 | ADVERTISED_100baseT_Half | | |
2683 | ADVERTISED_100baseT_Full | | |
2684 | ADVERTISED_10baseT_Full; | |
2685 | else | |
2686 | advertising |= ADVERTISED_10baseT_Full; | |
2687 | } | |
2688 | ||
2689 | phydev->advertising = advertising; | |
2690 | ||
2691 | phy_start_aneg(phydev); | |
0a459aac MC |
2692 | |
2693 | phyid = phydev->drv->phy_id & phydev->drv->phy_id_mask; | |
6a443a0f MC |
2694 | if (phyid != PHY_ID_BCMAC131) { |
2695 | phyid &= PHY_BCM_OUI_MASK; | |
2696 | if (phyid == PHY_BCM_OUI_1 || | |
2697 | phyid == PHY_BCM_OUI_2 || | |
2698 | phyid == PHY_BCM_OUI_3) | |
0a459aac MC |
2699 | do_low_power = true; |
2700 | } | |
b02fd9e3 | 2701 | } |
dd477003 | 2702 | } else { |
2023276e | 2703 | do_low_power = true; |
0a459aac | 2704 | |
80096068 MC |
2705 | if (!(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
2706 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; | |
dd477003 MC |
2707 | tp->link_config.orig_speed = tp->link_config.speed; |
2708 | tp->link_config.orig_duplex = tp->link_config.duplex; | |
2709 | tp->link_config.orig_autoneg = tp->link_config.autoneg; | |
2710 | } | |
1da177e4 | 2711 | |
f07e9af3 | 2712 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
dd477003 MC |
2713 | tp->link_config.speed = SPEED_10; |
2714 | tp->link_config.duplex = DUPLEX_HALF; | |
2715 | tp->link_config.autoneg = AUTONEG_ENABLE; | |
2716 | tg3_setup_phy(tp, 0); | |
2717 | } | |
1da177e4 LT |
2718 | } |
2719 | ||
b5d3772c MC |
2720 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
2721 | u32 val; | |
2722 | ||
2723 | val = tr32(GRC_VCPU_EXT_CTRL); | |
2724 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL); | |
63c3a66f | 2725 | } else if (!tg3_flag(tp, ENABLE_ASF)) { |
6921d201 MC |
2726 | int i; |
2727 | u32 val; | |
2728 | ||
2729 | for (i = 0; i < 200; i++) { | |
2730 | tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val); | |
2731 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) | |
2732 | break; | |
2733 | msleep(1); | |
2734 | } | |
2735 | } | |
63c3a66f | 2736 | if (tg3_flag(tp, WOL_CAP)) |
a85feb8c GZ |
2737 | tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE | |
2738 | WOL_DRV_STATE_SHUTDOWN | | |
2739 | WOL_DRV_WOL | | |
2740 | WOL_SET_MAGIC_PKT); | |
6921d201 | 2741 | |
05ac4cb7 | 2742 | if (device_should_wake) { |
1da177e4 LT |
2743 | u32 mac_mode; |
2744 | ||
f07e9af3 | 2745 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
b4bd2929 MC |
2746 | if (do_low_power && |
2747 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { | |
2748 | tg3_phy_auxctl_write(tp, | |
2749 | MII_TG3_AUXCTL_SHDWSEL_PWRCTL, | |
2750 | MII_TG3_AUXCTL_PCTL_WOL_EN | | |
2751 | MII_TG3_AUXCTL_PCTL_100TX_LPWR | | |
2752 | MII_TG3_AUXCTL_PCTL_CL_AB_TXDAC); | |
dd477003 MC |
2753 | udelay(40); |
2754 | } | |
1da177e4 | 2755 | |
f07e9af3 | 2756 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
3f7045c1 MC |
2757 | mac_mode = MAC_MODE_PORT_MODE_GMII; |
2758 | else | |
2759 | mac_mode = MAC_MODE_PORT_MODE_MII; | |
1da177e4 | 2760 | |
e8f3f6ca MC |
2761 | mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY; |
2762 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == | |
2763 | ASIC_REV_5700) { | |
63c3a66f | 2764 | u32 speed = tg3_flag(tp, WOL_SPEED_100MB) ? |
e8f3f6ca MC |
2765 | SPEED_100 : SPEED_10; |
2766 | if (tg3_5700_link_polarity(tp, speed)) | |
2767 | mac_mode |= MAC_MODE_LINK_POLARITY; | |
2768 | else | |
2769 | mac_mode &= ~MAC_MODE_LINK_POLARITY; | |
2770 | } | |
1da177e4 LT |
2771 | } else { |
2772 | mac_mode = MAC_MODE_PORT_MODE_TBI; | |
2773 | } | |
2774 | ||
63c3a66f | 2775 | if (!tg3_flag(tp, 5750_PLUS)) |
1da177e4 LT |
2776 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
2777 | ||
05ac4cb7 | 2778 | mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE; |
63c3a66f JP |
2779 | if ((tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) && |
2780 | (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE))) | |
05ac4cb7 | 2781 | mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL; |
1da177e4 | 2782 | |
63c3a66f | 2783 | if (tg3_flag(tp, ENABLE_APE)) |
d2394e6b MC |
2784 | mac_mode |= MAC_MODE_APE_TX_EN | |
2785 | MAC_MODE_APE_RX_EN | | |
2786 | MAC_MODE_TDE_ENABLE; | |
3bda1258 | 2787 | |
1da177e4 LT |
2788 | tw32_f(MAC_MODE, mac_mode); |
2789 | udelay(100); | |
2790 | ||
2791 | tw32_f(MAC_RX_MODE, RX_MODE_ENABLE); | |
2792 | udelay(10); | |
2793 | } | |
2794 | ||
63c3a66f | 2795 | if (!tg3_flag(tp, WOL_SPEED_100MB) && |
1da177e4 LT |
2796 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
2797 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { | |
2798 | u32 base_val; | |
2799 | ||
2800 | base_val = tp->pci_clock_ctrl; | |
2801 | base_val |= (CLOCK_CTRL_RXCLK_DISABLE | | |
2802 | CLOCK_CTRL_TXCLK_DISABLE); | |
2803 | ||
b401e9e2 MC |
2804 | tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK | |
2805 | CLOCK_CTRL_PWRDOWN_PLL133, 40); | |
63c3a66f JP |
2806 | } else if (tg3_flag(tp, 5780_CLASS) || |
2807 | tg3_flag(tp, CPMU_PRESENT) || | |
d7b0a857 | 2808 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)) { |
4cf78e4f | 2809 | /* do nothing */ |
63c3a66f | 2810 | } else if (!(tg3_flag(tp, 5750_PLUS) && tg3_flag(tp, ENABLE_ASF))) { |
1da177e4 LT |
2811 | u32 newbits1, newbits2; |
2812 | ||
2813 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
2814 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { | |
2815 | newbits1 = (CLOCK_CTRL_RXCLK_DISABLE | | |
2816 | CLOCK_CTRL_TXCLK_DISABLE | | |
2817 | CLOCK_CTRL_ALTCLK); | |
2818 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; | |
63c3a66f | 2819 | } else if (tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
2820 | newbits1 = CLOCK_CTRL_625_CORE; |
2821 | newbits2 = newbits1 | CLOCK_CTRL_ALTCLK; | |
2822 | } else { | |
2823 | newbits1 = CLOCK_CTRL_ALTCLK; | |
2824 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; | |
2825 | } | |
2826 | ||
b401e9e2 MC |
2827 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1, |
2828 | 40); | |
1da177e4 | 2829 | |
b401e9e2 MC |
2830 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2, |
2831 | 40); | |
1da177e4 | 2832 | |
63c3a66f | 2833 | if (!tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
2834 | u32 newbits3; |
2835 | ||
2836 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
2837 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { | |
2838 | newbits3 = (CLOCK_CTRL_RXCLK_DISABLE | | |
2839 | CLOCK_CTRL_TXCLK_DISABLE | | |
2840 | CLOCK_CTRL_44MHZ_CORE); | |
2841 | } else { | |
2842 | newbits3 = CLOCK_CTRL_44MHZ_CORE; | |
2843 | } | |
2844 | ||
b401e9e2 MC |
2845 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
2846 | tp->pci_clock_ctrl | newbits3, 40); | |
1da177e4 LT |
2847 | } |
2848 | } | |
2849 | ||
63c3a66f | 2850 | if (!(device_should_wake) && !tg3_flag(tp, ENABLE_ASF)) |
0a459aac | 2851 | tg3_power_down_phy(tp, do_low_power); |
6921d201 | 2852 | |
1da177e4 LT |
2853 | tg3_frob_aux_power(tp); |
2854 | ||
2855 | /* Workaround for unstable PLL clock */ | |
2856 | if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) || | |
2857 | (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) { | |
2858 | u32 val = tr32(0x7d00); | |
2859 | ||
2860 | val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1); | |
2861 | tw32(0x7d00, val); | |
63c3a66f | 2862 | if (!tg3_flag(tp, ENABLE_ASF)) { |
ec41c7df MC |
2863 | int err; |
2864 | ||
2865 | err = tg3_nvram_lock(tp); | |
1da177e4 | 2866 | tg3_halt_cpu(tp, RX_CPU_BASE); |
ec41c7df MC |
2867 | if (!err) |
2868 | tg3_nvram_unlock(tp); | |
6921d201 | 2869 | } |
1da177e4 LT |
2870 | } |
2871 | ||
bbadf503 MC |
2872 | tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN); |
2873 | ||
c866b7ea RW |
2874 | return 0; |
2875 | } | |
12dac075 | 2876 | |
c866b7ea RW |
2877 | static void tg3_power_down(struct tg3 *tp) |
2878 | { | |
2879 | tg3_power_down_prepare(tp); | |
1da177e4 | 2880 | |
63c3a66f | 2881 | pci_wake_from_d3(tp->pdev, tg3_flag(tp, WOL_ENABLE)); |
c866b7ea | 2882 | pci_set_power_state(tp->pdev, PCI_D3hot); |
1da177e4 LT |
2883 | } |
2884 | ||
1da177e4 LT |
2885 | static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex) |
2886 | { | |
2887 | switch (val & MII_TG3_AUX_STAT_SPDMASK) { | |
2888 | case MII_TG3_AUX_STAT_10HALF: | |
2889 | *speed = SPEED_10; | |
2890 | *duplex = DUPLEX_HALF; | |
2891 | break; | |
2892 | ||
2893 | case MII_TG3_AUX_STAT_10FULL: | |
2894 | *speed = SPEED_10; | |
2895 | *duplex = DUPLEX_FULL; | |
2896 | break; | |
2897 | ||
2898 | case MII_TG3_AUX_STAT_100HALF: | |
2899 | *speed = SPEED_100; | |
2900 | *duplex = DUPLEX_HALF; | |
2901 | break; | |
2902 | ||
2903 | case MII_TG3_AUX_STAT_100FULL: | |
2904 | *speed = SPEED_100; | |
2905 | *duplex = DUPLEX_FULL; | |
2906 | break; | |
2907 | ||
2908 | case MII_TG3_AUX_STAT_1000HALF: | |
2909 | *speed = SPEED_1000; | |
2910 | *duplex = DUPLEX_HALF; | |
2911 | break; | |
2912 | ||
2913 | case MII_TG3_AUX_STAT_1000FULL: | |
2914 | *speed = SPEED_1000; | |
2915 | *duplex = DUPLEX_FULL; | |
2916 | break; | |
2917 | ||
2918 | default: | |
f07e9af3 | 2919 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
715116a1 MC |
2920 | *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 : |
2921 | SPEED_10; | |
2922 | *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL : | |
2923 | DUPLEX_HALF; | |
2924 | break; | |
2925 | } | |
1da177e4 LT |
2926 | *speed = SPEED_INVALID; |
2927 | *duplex = DUPLEX_INVALID; | |
2928 | break; | |
855e1111 | 2929 | } |
1da177e4 LT |
2930 | } |
2931 | ||
2932 | static void tg3_phy_copper_begin(struct tg3 *tp) | |
2933 | { | |
2934 | u32 new_adv; | |
2935 | int i; | |
2936 | ||
80096068 | 2937 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
1da177e4 LT |
2938 | /* Entering low power mode. Disable gigabit and |
2939 | * 100baseT advertisements. | |
2940 | */ | |
2941 | tg3_writephy(tp, MII_TG3_CTRL, 0); | |
2942 | ||
2943 | new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL | | |
2944 | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); | |
63c3a66f | 2945 | if (tg3_flag(tp, WOL_SPEED_100MB)) |
1da177e4 LT |
2946 | new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL); |
2947 | ||
2948 | tg3_writephy(tp, MII_ADVERTISE, new_adv); | |
2949 | } else if (tp->link_config.speed == SPEED_INVALID) { | |
f07e9af3 | 2950 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
1da177e4 LT |
2951 | tp->link_config.advertising &= |
2952 | ~(ADVERTISED_1000baseT_Half | | |
2953 | ADVERTISED_1000baseT_Full); | |
2954 | ||
ba4d07a8 | 2955 | new_adv = ADVERTISE_CSMA; |
1da177e4 LT |
2956 | if (tp->link_config.advertising & ADVERTISED_10baseT_Half) |
2957 | new_adv |= ADVERTISE_10HALF; | |
2958 | if (tp->link_config.advertising & ADVERTISED_10baseT_Full) | |
2959 | new_adv |= ADVERTISE_10FULL; | |
2960 | if (tp->link_config.advertising & ADVERTISED_100baseT_Half) | |
2961 | new_adv |= ADVERTISE_100HALF; | |
2962 | if (tp->link_config.advertising & ADVERTISED_100baseT_Full) | |
2963 | new_adv |= ADVERTISE_100FULL; | |
ba4d07a8 MC |
2964 | |
2965 | new_adv |= tg3_advert_flowctrl_1000T(tp->link_config.flowctrl); | |
2966 | ||
1da177e4 LT |
2967 | tg3_writephy(tp, MII_ADVERTISE, new_adv); |
2968 | ||
2969 | if (tp->link_config.advertising & | |
2970 | (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) { | |
2971 | new_adv = 0; | |
2972 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Half) | |
2973 | new_adv |= MII_TG3_CTRL_ADV_1000_HALF; | |
2974 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Full) | |
2975 | new_adv |= MII_TG3_CTRL_ADV_1000_FULL; | |
f07e9af3 | 2976 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY) && |
1da177e4 LT |
2977 | (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
2978 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)) | |
2979 | new_adv |= (MII_TG3_CTRL_AS_MASTER | | |
2980 | MII_TG3_CTRL_ENABLE_AS_MASTER); | |
2981 | tg3_writephy(tp, MII_TG3_CTRL, new_adv); | |
2982 | } else { | |
2983 | tg3_writephy(tp, MII_TG3_CTRL, 0); | |
2984 | } | |
2985 | } else { | |
ba4d07a8 MC |
2986 | new_adv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl); |
2987 | new_adv |= ADVERTISE_CSMA; | |
2988 | ||
1da177e4 LT |
2989 | /* Asking for a specific link mode. */ |
2990 | if (tp->link_config.speed == SPEED_1000) { | |
1da177e4 LT |
2991 | tg3_writephy(tp, MII_ADVERTISE, new_adv); |
2992 | ||
2993 | if (tp->link_config.duplex == DUPLEX_FULL) | |
2994 | new_adv = MII_TG3_CTRL_ADV_1000_FULL; | |
2995 | else | |
2996 | new_adv = MII_TG3_CTRL_ADV_1000_HALF; | |
2997 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || | |
2998 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) | |
2999 | new_adv |= (MII_TG3_CTRL_AS_MASTER | | |
3000 | MII_TG3_CTRL_ENABLE_AS_MASTER); | |
1da177e4 | 3001 | } else { |
1da177e4 LT |
3002 | if (tp->link_config.speed == SPEED_100) { |
3003 | if (tp->link_config.duplex == DUPLEX_FULL) | |
3004 | new_adv |= ADVERTISE_100FULL; | |
3005 | else | |
3006 | new_adv |= ADVERTISE_100HALF; | |
3007 | } else { | |
3008 | if (tp->link_config.duplex == DUPLEX_FULL) | |
3009 | new_adv |= ADVERTISE_10FULL; | |
3010 | else | |
3011 | new_adv |= ADVERTISE_10HALF; | |
3012 | } | |
3013 | tg3_writephy(tp, MII_ADVERTISE, new_adv); | |
ba4d07a8 MC |
3014 | |
3015 | new_adv = 0; | |
1da177e4 | 3016 | } |
ba4d07a8 MC |
3017 | |
3018 | tg3_writephy(tp, MII_TG3_CTRL, new_adv); | |
1da177e4 LT |
3019 | } |
3020 | ||
52b02d04 | 3021 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) { |
a6b68dab | 3022 | u32 val; |
52b02d04 MC |
3023 | |
3024 | tw32(TG3_CPMU_EEE_MODE, | |
3025 | tr32(TG3_CPMU_EEE_MODE) & ~TG3_CPMU_EEEMD_LPI_ENABLE); | |
3026 | ||
1d36ba45 | 3027 | TG3_PHY_AUXCTL_SMDSP_ENABLE(tp); |
52b02d04 | 3028 | |
21a00ab2 MC |
3029 | switch (GET_ASIC_REV(tp->pci_chip_rev_id)) { |
3030 | case ASIC_REV_5717: | |
3031 | case ASIC_REV_57765: | |
3032 | if (!tg3_phydsp_read(tp, MII_TG3_DSP_CH34TP2, &val)) | |
3033 | tg3_phydsp_write(tp, MII_TG3_DSP_CH34TP2, val | | |
3034 | MII_TG3_DSP_CH34TP2_HIBW01); | |
3035 | /* Fall through */ | |
3036 | case ASIC_REV_5719: | |
3037 | val = MII_TG3_DSP_TAP26_ALNOKO | | |
3038 | MII_TG3_DSP_TAP26_RMRXSTO | | |
3039 | MII_TG3_DSP_TAP26_OPCSINPT; | |
3040 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); | |
3041 | } | |
52b02d04 | 3042 | |
a6b68dab | 3043 | val = 0; |
52b02d04 MC |
3044 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { |
3045 | /* Advertise 100-BaseTX EEE ability */ | |
3046 | if (tp->link_config.advertising & | |
3110f5f5 MC |
3047 | ADVERTISED_100baseT_Full) |
3048 | val |= MDIO_AN_EEE_ADV_100TX; | |
52b02d04 MC |
3049 | /* Advertise 1000-BaseT EEE ability */ |
3050 | if (tp->link_config.advertising & | |
3110f5f5 MC |
3051 | ADVERTISED_1000baseT_Full) |
3052 | val |= MDIO_AN_EEE_ADV_1000T; | |
52b02d04 | 3053 | } |
3110f5f5 | 3054 | tg3_phy_cl45_write(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV, val); |
52b02d04 | 3055 | |
1d36ba45 | 3056 | TG3_PHY_AUXCTL_SMDSP_DISABLE(tp); |
52b02d04 MC |
3057 | } |
3058 | ||
1da177e4 LT |
3059 | if (tp->link_config.autoneg == AUTONEG_DISABLE && |
3060 | tp->link_config.speed != SPEED_INVALID) { | |
3061 | u32 bmcr, orig_bmcr; | |
3062 | ||
3063 | tp->link_config.active_speed = tp->link_config.speed; | |
3064 | tp->link_config.active_duplex = tp->link_config.duplex; | |
3065 | ||
3066 | bmcr = 0; | |
3067 | switch (tp->link_config.speed) { | |
3068 | default: | |
3069 | case SPEED_10: | |
3070 | break; | |
3071 | ||
3072 | case SPEED_100: | |
3073 | bmcr |= BMCR_SPEED100; | |
3074 | break; | |
3075 | ||
3076 | case SPEED_1000: | |
3077 | bmcr |= TG3_BMCR_SPEED1000; | |
3078 | break; | |
855e1111 | 3079 | } |
1da177e4 LT |
3080 | |
3081 | if (tp->link_config.duplex == DUPLEX_FULL) | |
3082 | bmcr |= BMCR_FULLDPLX; | |
3083 | ||
3084 | if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) && | |
3085 | (bmcr != orig_bmcr)) { | |
3086 | tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK); | |
3087 | for (i = 0; i < 1500; i++) { | |
3088 | u32 tmp; | |
3089 | ||
3090 | udelay(10); | |
3091 | if (tg3_readphy(tp, MII_BMSR, &tmp) || | |
3092 | tg3_readphy(tp, MII_BMSR, &tmp)) | |
3093 | continue; | |
3094 | if (!(tmp & BMSR_LSTATUS)) { | |
3095 | udelay(40); | |
3096 | break; | |
3097 | } | |
3098 | } | |
3099 | tg3_writephy(tp, MII_BMCR, bmcr); | |
3100 | udelay(40); | |
3101 | } | |
3102 | } else { | |
3103 | tg3_writephy(tp, MII_BMCR, | |
3104 | BMCR_ANENABLE | BMCR_ANRESTART); | |
3105 | } | |
3106 | } | |
3107 | ||
3108 | static int tg3_init_5401phy_dsp(struct tg3 *tp) | |
3109 | { | |
3110 | int err; | |
3111 | ||
3112 | /* Turn off tap power management. */ | |
3113 | /* Set Extended packet length bit */ | |
b4bd2929 | 3114 | err = tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
1da177e4 | 3115 | |
6ee7c0a0 MC |
3116 | err |= tg3_phydsp_write(tp, 0x0012, 0x1804); |
3117 | err |= tg3_phydsp_write(tp, 0x0013, 0x1204); | |
3118 | err |= tg3_phydsp_write(tp, 0x8006, 0x0132); | |
3119 | err |= tg3_phydsp_write(tp, 0x8006, 0x0232); | |
3120 | err |= tg3_phydsp_write(tp, 0x201f, 0x0a20); | |
1da177e4 LT |
3121 | |
3122 | udelay(40); | |
3123 | ||
3124 | return err; | |
3125 | } | |
3126 | ||
3600d918 | 3127 | static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask) |
1da177e4 | 3128 | { |
3600d918 MC |
3129 | u32 adv_reg, all_mask = 0; |
3130 | ||
3131 | if (mask & ADVERTISED_10baseT_Half) | |
3132 | all_mask |= ADVERTISE_10HALF; | |
3133 | if (mask & ADVERTISED_10baseT_Full) | |
3134 | all_mask |= ADVERTISE_10FULL; | |
3135 | if (mask & ADVERTISED_100baseT_Half) | |
3136 | all_mask |= ADVERTISE_100HALF; | |
3137 | if (mask & ADVERTISED_100baseT_Full) | |
3138 | all_mask |= ADVERTISE_100FULL; | |
1da177e4 LT |
3139 | |
3140 | if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg)) | |
3141 | return 0; | |
3142 | ||
1da177e4 LT |
3143 | if ((adv_reg & all_mask) != all_mask) |
3144 | return 0; | |
f07e9af3 | 3145 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
1da177e4 LT |
3146 | u32 tg3_ctrl; |
3147 | ||
3600d918 MC |
3148 | all_mask = 0; |
3149 | if (mask & ADVERTISED_1000baseT_Half) | |
3150 | all_mask |= ADVERTISE_1000HALF; | |
3151 | if (mask & ADVERTISED_1000baseT_Full) | |
3152 | all_mask |= ADVERTISE_1000FULL; | |
3153 | ||
1da177e4 LT |
3154 | if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl)) |
3155 | return 0; | |
3156 | ||
1da177e4 LT |
3157 | if ((tg3_ctrl & all_mask) != all_mask) |
3158 | return 0; | |
3159 | } | |
3160 | return 1; | |
3161 | } | |
3162 | ||
ef167e27 MC |
3163 | static int tg3_adv_1000T_flowctrl_ok(struct tg3 *tp, u32 *lcladv, u32 *rmtadv) |
3164 | { | |
3165 | u32 curadv, reqadv; | |
3166 | ||
3167 | if (tg3_readphy(tp, MII_ADVERTISE, lcladv)) | |
3168 | return 1; | |
3169 | ||
3170 | curadv = *lcladv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM); | |
3171 | reqadv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl); | |
3172 | ||
3173 | if (tp->link_config.active_duplex == DUPLEX_FULL) { | |
3174 | if (curadv != reqadv) | |
3175 | return 0; | |
3176 | ||
63c3a66f | 3177 | if (tg3_flag(tp, PAUSE_AUTONEG)) |
ef167e27 MC |
3178 | tg3_readphy(tp, MII_LPA, rmtadv); |
3179 | } else { | |
3180 | /* Reprogram the advertisement register, even if it | |
3181 | * does not affect the current link. If the link | |
3182 | * gets renegotiated in the future, we can save an | |
3183 | * additional renegotiation cycle by advertising | |
3184 | * it correctly in the first place. | |
3185 | */ | |
3186 | if (curadv != reqadv) { | |
3187 | *lcladv &= ~(ADVERTISE_PAUSE_CAP | | |
3188 | ADVERTISE_PAUSE_ASYM); | |
3189 | tg3_writephy(tp, MII_ADVERTISE, *lcladv | reqadv); | |
3190 | } | |
3191 | } | |
3192 | ||
3193 | return 1; | |
3194 | } | |
3195 | ||
1da177e4 LT |
3196 | static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset) |
3197 | { | |
3198 | int current_link_up; | |
f833c4c1 | 3199 | u32 bmsr, val; |
ef167e27 | 3200 | u32 lcl_adv, rmt_adv; |
1da177e4 LT |
3201 | u16 current_speed; |
3202 | u8 current_duplex; | |
3203 | int i, err; | |
3204 | ||
3205 | tw32(MAC_EVENT, 0); | |
3206 | ||
3207 | tw32_f(MAC_STATUS, | |
3208 | (MAC_STATUS_SYNC_CHANGED | | |
3209 | MAC_STATUS_CFG_CHANGED | | |
3210 | MAC_STATUS_MI_COMPLETION | | |
3211 | MAC_STATUS_LNKSTATE_CHANGED)); | |
3212 | udelay(40); | |
3213 | ||
8ef21428 MC |
3214 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
3215 | tw32_f(MAC_MI_MODE, | |
3216 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); | |
3217 | udelay(80); | |
3218 | } | |
1da177e4 | 3219 | |
b4bd2929 | 3220 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, 0); |
1da177e4 LT |
3221 | |
3222 | /* Some third-party PHYs need to be reset on link going | |
3223 | * down. | |
3224 | */ | |
3225 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || | |
3226 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || | |
3227 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && | |
3228 | netif_carrier_ok(tp->dev)) { | |
3229 | tg3_readphy(tp, MII_BMSR, &bmsr); | |
3230 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && | |
3231 | !(bmsr & BMSR_LSTATUS)) | |
3232 | force_reset = 1; | |
3233 | } | |
3234 | if (force_reset) | |
3235 | tg3_phy_reset(tp); | |
3236 | ||
79eb6904 | 3237 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
1da177e4 LT |
3238 | tg3_readphy(tp, MII_BMSR, &bmsr); |
3239 | if (tg3_readphy(tp, MII_BMSR, &bmsr) || | |
63c3a66f | 3240 | !tg3_flag(tp, INIT_COMPLETE)) |
1da177e4 LT |
3241 | bmsr = 0; |
3242 | ||
3243 | if (!(bmsr & BMSR_LSTATUS)) { | |
3244 | err = tg3_init_5401phy_dsp(tp); | |
3245 | if (err) | |
3246 | return err; | |
3247 | ||
3248 | tg3_readphy(tp, MII_BMSR, &bmsr); | |
3249 | for (i = 0; i < 1000; i++) { | |
3250 | udelay(10); | |
3251 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && | |
3252 | (bmsr & BMSR_LSTATUS)) { | |
3253 | udelay(40); | |
3254 | break; | |
3255 | } | |
3256 | } | |
3257 | ||
79eb6904 MC |
3258 | if ((tp->phy_id & TG3_PHY_ID_REV_MASK) == |
3259 | TG3_PHY_REV_BCM5401_B0 && | |
1da177e4 LT |
3260 | !(bmsr & BMSR_LSTATUS) && |
3261 | tp->link_config.active_speed == SPEED_1000) { | |
3262 | err = tg3_phy_reset(tp); | |
3263 | if (!err) | |
3264 | err = tg3_init_5401phy_dsp(tp); | |
3265 | if (err) | |
3266 | return err; | |
3267 | } | |
3268 | } | |
3269 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || | |
3270 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) { | |
3271 | /* 5701 {A0,B0} CRC bug workaround */ | |
3272 | tg3_writephy(tp, 0x15, 0x0a75); | |
f08aa1a8 MC |
3273 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
3274 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); | |
3275 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); | |
1da177e4 LT |
3276 | } |
3277 | ||
3278 | /* Clear pending interrupts... */ | |
f833c4c1 MC |
3279 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
3280 | tg3_readphy(tp, MII_TG3_ISTAT, &val); | |
1da177e4 | 3281 | |
f07e9af3 | 3282 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) |
1da177e4 | 3283 | tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG); |
f07e9af3 | 3284 | else if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) |
1da177e4 LT |
3285 | tg3_writephy(tp, MII_TG3_IMASK, ~0); |
3286 | ||
3287 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
3288 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { | |
3289 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_1) | |
3290 | tg3_writephy(tp, MII_TG3_EXT_CTRL, | |
3291 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); | |
3292 | else | |
3293 | tg3_writephy(tp, MII_TG3_EXT_CTRL, 0); | |
3294 | } | |
3295 | ||
3296 | current_link_up = 0; | |
3297 | current_speed = SPEED_INVALID; | |
3298 | current_duplex = DUPLEX_INVALID; | |
3299 | ||
f07e9af3 | 3300 | if (tp->phy_flags & TG3_PHYFLG_CAPACITIVE_COUPLING) { |
15ee95c3 MC |
3301 | err = tg3_phy_auxctl_read(tp, |
3302 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, | |
3303 | &val); | |
3304 | if (!err && !(val & (1 << 10))) { | |
b4bd2929 MC |
3305 | tg3_phy_auxctl_write(tp, |
3306 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, | |
3307 | val | (1 << 10)); | |
1da177e4 LT |
3308 | goto relink; |
3309 | } | |
3310 | } | |
3311 | ||
3312 | bmsr = 0; | |
3313 | for (i = 0; i < 100; i++) { | |
3314 | tg3_readphy(tp, MII_BMSR, &bmsr); | |
3315 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && | |
3316 | (bmsr & BMSR_LSTATUS)) | |
3317 | break; | |
3318 | udelay(40); | |
3319 | } | |
3320 | ||
3321 | if (bmsr & BMSR_LSTATUS) { | |
3322 | u32 aux_stat, bmcr; | |
3323 | ||
3324 | tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat); | |
3325 | for (i = 0; i < 2000; i++) { | |
3326 | udelay(10); | |
3327 | if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) && | |
3328 | aux_stat) | |
3329 | break; | |
3330 | } | |
3331 | ||
3332 | tg3_aux_stat_to_speed_duplex(tp, aux_stat, | |
3333 | ¤t_speed, | |
3334 | ¤t_duplex); | |
3335 | ||
3336 | bmcr = 0; | |
3337 | for (i = 0; i < 200; i++) { | |
3338 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
3339 | if (tg3_readphy(tp, MII_BMCR, &bmcr)) | |
3340 | continue; | |
3341 | if (bmcr && bmcr != 0x7fff) | |
3342 | break; | |
3343 | udelay(10); | |
3344 | } | |
3345 | ||
ef167e27 MC |
3346 | lcl_adv = 0; |
3347 | rmt_adv = 0; | |
1da177e4 | 3348 | |
ef167e27 MC |
3349 | tp->link_config.active_speed = current_speed; |
3350 | tp->link_config.active_duplex = current_duplex; | |
3351 | ||
3352 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { | |
3353 | if ((bmcr & BMCR_ANENABLE) && | |
3354 | tg3_copper_is_advertising_all(tp, | |
3355 | tp->link_config.advertising)) { | |
3356 | if (tg3_adv_1000T_flowctrl_ok(tp, &lcl_adv, | |
3357 | &rmt_adv)) | |
3358 | current_link_up = 1; | |
1da177e4 LT |
3359 | } |
3360 | } else { | |
3361 | if (!(bmcr & BMCR_ANENABLE) && | |
3362 | tp->link_config.speed == current_speed && | |
ef167e27 MC |
3363 | tp->link_config.duplex == current_duplex && |
3364 | tp->link_config.flowctrl == | |
3365 | tp->link_config.active_flowctrl) { | |
1da177e4 | 3366 | current_link_up = 1; |
1da177e4 LT |
3367 | } |
3368 | } | |
3369 | ||
ef167e27 MC |
3370 | if (current_link_up == 1 && |
3371 | tp->link_config.active_duplex == DUPLEX_FULL) | |
3372 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); | |
1da177e4 LT |
3373 | } |
3374 | ||
1da177e4 | 3375 | relink: |
80096068 | 3376 | if (current_link_up == 0 || (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
1da177e4 LT |
3377 | tg3_phy_copper_begin(tp); |
3378 | ||
f833c4c1 | 3379 | tg3_readphy(tp, MII_BMSR, &bmsr); |
06c03c02 MB |
3380 | if ((!tg3_readphy(tp, MII_BMSR, &bmsr) && (bmsr & BMSR_LSTATUS)) || |
3381 | (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) | |
1da177e4 LT |
3382 | current_link_up = 1; |
3383 | } | |
3384 | ||
3385 | tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; | |
3386 | if (current_link_up == 1) { | |
3387 | if (tp->link_config.active_speed == SPEED_100 || | |
3388 | tp->link_config.active_speed == SPEED_10) | |
3389 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; | |
3390 | else | |
3391 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
f07e9af3 | 3392 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
7f97a4bd MC |
3393 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
3394 | else | |
1da177e4 LT |
3395 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
3396 | ||
3397 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; | |
3398 | if (tp->link_config.active_duplex == DUPLEX_HALF) | |
3399 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; | |
3400 | ||
1da177e4 | 3401 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
e8f3f6ca MC |
3402 | if (current_link_up == 1 && |
3403 | tg3_5700_link_polarity(tp, tp->link_config.active_speed)) | |
1da177e4 | 3404 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
e8f3f6ca MC |
3405 | else |
3406 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; | |
1da177e4 LT |
3407 | } |
3408 | ||
3409 | /* ??? Without this setting Netgear GA302T PHY does not | |
3410 | * ??? send/receive packets... | |
3411 | */ | |
79eb6904 | 3412 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411 && |
1da177e4 LT |
3413 | tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) { |
3414 | tp->mi_mode |= MAC_MI_MODE_AUTO_POLL; | |
3415 | tw32_f(MAC_MI_MODE, tp->mi_mode); | |
3416 | udelay(80); | |
3417 | } | |
3418 | ||
3419 | tw32_f(MAC_MODE, tp->mac_mode); | |
3420 | udelay(40); | |
3421 | ||
52b02d04 MC |
3422 | tg3_phy_eee_adjust(tp, current_link_up); |
3423 | ||
63c3a66f | 3424 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
1da177e4 LT |
3425 | /* Polled via timer. */ |
3426 | tw32_f(MAC_EVENT, 0); | |
3427 | } else { | |
3428 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); | |
3429 | } | |
3430 | udelay(40); | |
3431 | ||
3432 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 && | |
3433 | current_link_up == 1 && | |
3434 | tp->link_config.active_speed == SPEED_1000 && | |
63c3a66f | 3435 | (tg3_flag(tp, PCIX_MODE) || tg3_flag(tp, PCI_HIGH_SPEED))) { |
1da177e4 LT |
3436 | udelay(120); |
3437 | tw32_f(MAC_STATUS, | |
3438 | (MAC_STATUS_SYNC_CHANGED | | |
3439 | MAC_STATUS_CFG_CHANGED)); | |
3440 | udelay(40); | |
3441 | tg3_write_mem(tp, | |
3442 | NIC_SRAM_FIRMWARE_MBOX, | |
3443 | NIC_SRAM_FIRMWARE_MBOX_MAGIC2); | |
3444 | } | |
3445 | ||
5e7dfd0f | 3446 | /* Prevent send BD corruption. */ |
63c3a66f | 3447 | if (tg3_flag(tp, CLKREQ_BUG)) { |
5e7dfd0f MC |
3448 | u16 oldlnkctl, newlnkctl; |
3449 | ||
3450 | pci_read_config_word(tp->pdev, | |
3451 | tp->pcie_cap + PCI_EXP_LNKCTL, | |
3452 | &oldlnkctl); | |
3453 | if (tp->link_config.active_speed == SPEED_100 || | |
3454 | tp->link_config.active_speed == SPEED_10) | |
3455 | newlnkctl = oldlnkctl & ~PCI_EXP_LNKCTL_CLKREQ_EN; | |
3456 | else | |
3457 | newlnkctl = oldlnkctl | PCI_EXP_LNKCTL_CLKREQ_EN; | |
3458 | if (newlnkctl != oldlnkctl) | |
3459 | pci_write_config_word(tp->pdev, | |
3460 | tp->pcie_cap + PCI_EXP_LNKCTL, | |
3461 | newlnkctl); | |
3462 | } | |
3463 | ||
1da177e4 LT |
3464 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
3465 | if (current_link_up) | |
3466 | netif_carrier_on(tp->dev); | |
3467 | else | |
3468 | netif_carrier_off(tp->dev); | |
3469 | tg3_link_report(tp); | |
3470 | } | |
3471 | ||
3472 | return 0; | |
3473 | } | |
3474 | ||
3475 | struct tg3_fiber_aneginfo { | |
3476 | int state; | |
3477 | #define ANEG_STATE_UNKNOWN 0 | |
3478 | #define ANEG_STATE_AN_ENABLE 1 | |
3479 | #define ANEG_STATE_RESTART_INIT 2 | |
3480 | #define ANEG_STATE_RESTART 3 | |
3481 | #define ANEG_STATE_DISABLE_LINK_OK 4 | |
3482 | #define ANEG_STATE_ABILITY_DETECT_INIT 5 | |
3483 | #define ANEG_STATE_ABILITY_DETECT 6 | |
3484 | #define ANEG_STATE_ACK_DETECT_INIT 7 | |
3485 | #define ANEG_STATE_ACK_DETECT 8 | |
3486 | #define ANEG_STATE_COMPLETE_ACK_INIT 9 | |
3487 | #define ANEG_STATE_COMPLETE_ACK 10 | |
3488 | #define ANEG_STATE_IDLE_DETECT_INIT 11 | |
3489 | #define ANEG_STATE_IDLE_DETECT 12 | |
3490 | #define ANEG_STATE_LINK_OK 13 | |
3491 | #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14 | |
3492 | #define ANEG_STATE_NEXT_PAGE_WAIT 15 | |
3493 | ||
3494 | u32 flags; | |
3495 | #define MR_AN_ENABLE 0x00000001 | |
3496 | #define MR_RESTART_AN 0x00000002 | |
3497 | #define MR_AN_COMPLETE 0x00000004 | |
3498 | #define MR_PAGE_RX 0x00000008 | |
3499 | #define MR_NP_LOADED 0x00000010 | |
3500 | #define MR_TOGGLE_TX 0x00000020 | |
3501 | #define MR_LP_ADV_FULL_DUPLEX 0x00000040 | |
3502 | #define MR_LP_ADV_HALF_DUPLEX 0x00000080 | |
3503 | #define MR_LP_ADV_SYM_PAUSE 0x00000100 | |
3504 | #define MR_LP_ADV_ASYM_PAUSE 0x00000200 | |
3505 | #define MR_LP_ADV_REMOTE_FAULT1 0x00000400 | |
3506 | #define MR_LP_ADV_REMOTE_FAULT2 0x00000800 | |
3507 | #define MR_LP_ADV_NEXT_PAGE 0x00001000 | |
3508 | #define MR_TOGGLE_RX 0x00002000 | |
3509 | #define MR_NP_RX 0x00004000 | |
3510 | ||
3511 | #define MR_LINK_OK 0x80000000 | |
3512 | ||
3513 | unsigned long link_time, cur_time; | |
3514 | ||
3515 | u32 ability_match_cfg; | |
3516 | int ability_match_count; | |
3517 | ||
3518 | char ability_match, idle_match, ack_match; | |
3519 | ||
3520 | u32 txconfig, rxconfig; | |
3521 | #define ANEG_CFG_NP 0x00000080 | |
3522 | #define ANEG_CFG_ACK 0x00000040 | |
3523 | #define ANEG_CFG_RF2 0x00000020 | |
3524 | #define ANEG_CFG_RF1 0x00000010 | |
3525 | #define ANEG_CFG_PS2 0x00000001 | |
3526 | #define ANEG_CFG_PS1 0x00008000 | |
3527 | #define ANEG_CFG_HD 0x00004000 | |
3528 | #define ANEG_CFG_FD 0x00002000 | |
3529 | #define ANEG_CFG_INVAL 0x00001f06 | |
3530 | ||
3531 | }; | |
3532 | #define ANEG_OK 0 | |
3533 | #define ANEG_DONE 1 | |
3534 | #define ANEG_TIMER_ENAB 2 | |
3535 | #define ANEG_FAILED -1 | |
3536 | ||
3537 | #define ANEG_STATE_SETTLE_TIME 10000 | |
3538 | ||
3539 | static int tg3_fiber_aneg_smachine(struct tg3 *tp, | |
3540 | struct tg3_fiber_aneginfo *ap) | |
3541 | { | |
5be73b47 | 3542 | u16 flowctrl; |
1da177e4 LT |
3543 | unsigned long delta; |
3544 | u32 rx_cfg_reg; | |
3545 | int ret; | |
3546 | ||
3547 | if (ap->state == ANEG_STATE_UNKNOWN) { | |
3548 | ap->rxconfig = 0; | |
3549 | ap->link_time = 0; | |
3550 | ap->cur_time = 0; | |
3551 | ap->ability_match_cfg = 0; | |
3552 | ap->ability_match_count = 0; | |
3553 | ap->ability_match = 0; | |
3554 | ap->idle_match = 0; | |
3555 | ap->ack_match = 0; | |
3556 | } | |
3557 | ap->cur_time++; | |
3558 | ||
3559 | if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) { | |
3560 | rx_cfg_reg = tr32(MAC_RX_AUTO_NEG); | |
3561 | ||
3562 | if (rx_cfg_reg != ap->ability_match_cfg) { | |
3563 | ap->ability_match_cfg = rx_cfg_reg; | |
3564 | ap->ability_match = 0; | |
3565 | ap->ability_match_count = 0; | |
3566 | } else { | |
3567 | if (++ap->ability_match_count > 1) { | |
3568 | ap->ability_match = 1; | |
3569 | ap->ability_match_cfg = rx_cfg_reg; | |
3570 | } | |
3571 | } | |
3572 | if (rx_cfg_reg & ANEG_CFG_ACK) | |
3573 | ap->ack_match = 1; | |
3574 | else | |
3575 | ap->ack_match = 0; | |
3576 | ||
3577 | ap->idle_match = 0; | |
3578 | } else { | |
3579 | ap->idle_match = 1; | |
3580 | ap->ability_match_cfg = 0; | |
3581 | ap->ability_match_count = 0; | |
3582 | ap->ability_match = 0; | |
3583 | ap->ack_match = 0; | |
3584 | ||
3585 | rx_cfg_reg = 0; | |
3586 | } | |
3587 | ||
3588 | ap->rxconfig = rx_cfg_reg; | |
3589 | ret = ANEG_OK; | |
3590 | ||
33f401ae | 3591 | switch (ap->state) { |
1da177e4 LT |
3592 | case ANEG_STATE_UNKNOWN: |
3593 | if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN)) | |
3594 | ap->state = ANEG_STATE_AN_ENABLE; | |
3595 | ||
3596 | /* fallthru */ | |
3597 | case ANEG_STATE_AN_ENABLE: | |
3598 | ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX); | |
3599 | if (ap->flags & MR_AN_ENABLE) { | |
3600 | ap->link_time = 0; | |
3601 | ap->cur_time = 0; | |
3602 | ap->ability_match_cfg = 0; | |
3603 | ap->ability_match_count = 0; | |
3604 | ap->ability_match = 0; | |
3605 | ap->idle_match = 0; | |
3606 | ap->ack_match = 0; | |
3607 | ||
3608 | ap->state = ANEG_STATE_RESTART_INIT; | |
3609 | } else { | |
3610 | ap->state = ANEG_STATE_DISABLE_LINK_OK; | |
3611 | } | |
3612 | break; | |
3613 | ||
3614 | case ANEG_STATE_RESTART_INIT: | |
3615 | ap->link_time = ap->cur_time; | |
3616 | ap->flags &= ~(MR_NP_LOADED); | |
3617 | ap->txconfig = 0; | |
3618 | tw32(MAC_TX_AUTO_NEG, 0); | |
3619 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; | |
3620 | tw32_f(MAC_MODE, tp->mac_mode); | |
3621 | udelay(40); | |
3622 | ||
3623 | ret = ANEG_TIMER_ENAB; | |
3624 | ap->state = ANEG_STATE_RESTART; | |
3625 | ||
3626 | /* fallthru */ | |
3627 | case ANEG_STATE_RESTART: | |
3628 | delta = ap->cur_time - ap->link_time; | |
859a5887 | 3629 | if (delta > ANEG_STATE_SETTLE_TIME) |
1da177e4 | 3630 | ap->state = ANEG_STATE_ABILITY_DETECT_INIT; |
859a5887 | 3631 | else |
1da177e4 | 3632 | ret = ANEG_TIMER_ENAB; |
1da177e4 LT |
3633 | break; |
3634 | ||
3635 | case ANEG_STATE_DISABLE_LINK_OK: | |
3636 | ret = ANEG_DONE; | |
3637 | break; | |
3638 | ||
3639 | case ANEG_STATE_ABILITY_DETECT_INIT: | |
3640 | ap->flags &= ~(MR_TOGGLE_TX); | |
5be73b47 MC |
3641 | ap->txconfig = ANEG_CFG_FD; |
3642 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); | |
3643 | if (flowctrl & ADVERTISE_1000XPAUSE) | |
3644 | ap->txconfig |= ANEG_CFG_PS1; | |
3645 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) | |
3646 | ap->txconfig |= ANEG_CFG_PS2; | |
1da177e4 LT |
3647 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
3648 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; | |
3649 | tw32_f(MAC_MODE, tp->mac_mode); | |
3650 | udelay(40); | |
3651 | ||
3652 | ap->state = ANEG_STATE_ABILITY_DETECT; | |
3653 | break; | |
3654 | ||
3655 | case ANEG_STATE_ABILITY_DETECT: | |
859a5887 | 3656 | if (ap->ability_match != 0 && ap->rxconfig != 0) |
1da177e4 | 3657 | ap->state = ANEG_STATE_ACK_DETECT_INIT; |
1da177e4 LT |
3658 | break; |
3659 | ||
3660 | case ANEG_STATE_ACK_DETECT_INIT: | |
3661 | ap->txconfig |= ANEG_CFG_ACK; | |
3662 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); | |
3663 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; | |
3664 | tw32_f(MAC_MODE, tp->mac_mode); | |
3665 | udelay(40); | |
3666 | ||
3667 | ap->state = ANEG_STATE_ACK_DETECT; | |
3668 | ||
3669 | /* fallthru */ | |
3670 | case ANEG_STATE_ACK_DETECT: | |
3671 | if (ap->ack_match != 0) { | |
3672 | if ((ap->rxconfig & ~ANEG_CFG_ACK) == | |
3673 | (ap->ability_match_cfg & ~ANEG_CFG_ACK)) { | |
3674 | ap->state = ANEG_STATE_COMPLETE_ACK_INIT; | |
3675 | } else { | |
3676 | ap->state = ANEG_STATE_AN_ENABLE; | |
3677 | } | |
3678 | } else if (ap->ability_match != 0 && | |
3679 | ap->rxconfig == 0) { | |
3680 | ap->state = ANEG_STATE_AN_ENABLE; | |
3681 | } | |
3682 | break; | |
3683 | ||
3684 | case ANEG_STATE_COMPLETE_ACK_INIT: | |
3685 | if (ap->rxconfig & ANEG_CFG_INVAL) { | |
3686 | ret = ANEG_FAILED; | |
3687 | break; | |
3688 | } | |
3689 | ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX | | |
3690 | MR_LP_ADV_HALF_DUPLEX | | |
3691 | MR_LP_ADV_SYM_PAUSE | | |
3692 | MR_LP_ADV_ASYM_PAUSE | | |
3693 | MR_LP_ADV_REMOTE_FAULT1 | | |
3694 | MR_LP_ADV_REMOTE_FAULT2 | | |
3695 | MR_LP_ADV_NEXT_PAGE | | |
3696 | MR_TOGGLE_RX | | |
3697 | MR_NP_RX); | |
3698 | if (ap->rxconfig & ANEG_CFG_FD) | |
3699 | ap->flags |= MR_LP_ADV_FULL_DUPLEX; | |
3700 | if (ap->rxconfig & ANEG_CFG_HD) | |
3701 | ap->flags |= MR_LP_ADV_HALF_DUPLEX; | |
3702 | if (ap->rxconfig & ANEG_CFG_PS1) | |
3703 | ap->flags |= MR_LP_ADV_SYM_PAUSE; | |
3704 | if (ap->rxconfig & ANEG_CFG_PS2) | |
3705 | ap->flags |= MR_LP_ADV_ASYM_PAUSE; | |
3706 | if (ap->rxconfig & ANEG_CFG_RF1) | |
3707 | ap->flags |= MR_LP_ADV_REMOTE_FAULT1; | |
3708 | if (ap->rxconfig & ANEG_CFG_RF2) | |
3709 | ap->flags |= MR_LP_ADV_REMOTE_FAULT2; | |
3710 | if (ap->rxconfig & ANEG_CFG_NP) | |
3711 | ap->flags |= MR_LP_ADV_NEXT_PAGE; | |
3712 | ||
3713 | ap->link_time = ap->cur_time; | |
3714 | ||
3715 | ap->flags ^= (MR_TOGGLE_TX); | |
3716 | if (ap->rxconfig & 0x0008) | |
3717 | ap->flags |= MR_TOGGLE_RX; | |
3718 | if (ap->rxconfig & ANEG_CFG_NP) | |
3719 | ap->flags |= MR_NP_RX; | |
3720 | ap->flags |= MR_PAGE_RX; | |
3721 | ||
3722 | ap->state = ANEG_STATE_COMPLETE_ACK; | |
3723 | ret = ANEG_TIMER_ENAB; | |
3724 | break; | |
3725 | ||
3726 | case ANEG_STATE_COMPLETE_ACK: | |
3727 | if (ap->ability_match != 0 && | |
3728 | ap->rxconfig == 0) { | |
3729 | ap->state = ANEG_STATE_AN_ENABLE; | |
3730 | break; | |
3731 | } | |
3732 | delta = ap->cur_time - ap->link_time; | |
3733 | if (delta > ANEG_STATE_SETTLE_TIME) { | |
3734 | if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) { | |
3735 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; | |
3736 | } else { | |
3737 | if ((ap->txconfig & ANEG_CFG_NP) == 0 && | |
3738 | !(ap->flags & MR_NP_RX)) { | |
3739 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; | |
3740 | } else { | |
3741 | ret = ANEG_FAILED; | |
3742 | } | |
3743 | } | |
3744 | } | |
3745 | break; | |
3746 | ||
3747 | case ANEG_STATE_IDLE_DETECT_INIT: | |
3748 | ap->link_time = ap->cur_time; | |
3749 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; | |
3750 | tw32_f(MAC_MODE, tp->mac_mode); | |
3751 | udelay(40); | |
3752 | ||
3753 | ap->state = ANEG_STATE_IDLE_DETECT; | |
3754 | ret = ANEG_TIMER_ENAB; | |
3755 | break; | |
3756 | ||
3757 | case ANEG_STATE_IDLE_DETECT: | |
3758 | if (ap->ability_match != 0 && | |
3759 | ap->rxconfig == 0) { | |
3760 | ap->state = ANEG_STATE_AN_ENABLE; | |
3761 | break; | |
3762 | } | |
3763 | delta = ap->cur_time - ap->link_time; | |
3764 | if (delta > ANEG_STATE_SETTLE_TIME) { | |
3765 | /* XXX another gem from the Broadcom driver :( */ | |
3766 | ap->state = ANEG_STATE_LINK_OK; | |
3767 | } | |
3768 | break; | |
3769 | ||
3770 | case ANEG_STATE_LINK_OK: | |
3771 | ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK); | |
3772 | ret = ANEG_DONE; | |
3773 | break; | |
3774 | ||
3775 | case ANEG_STATE_NEXT_PAGE_WAIT_INIT: | |
3776 | /* ??? unimplemented */ | |
3777 | break; | |
3778 | ||
3779 | case ANEG_STATE_NEXT_PAGE_WAIT: | |
3780 | /* ??? unimplemented */ | |
3781 | break; | |
3782 | ||
3783 | default: | |
3784 | ret = ANEG_FAILED; | |
3785 | break; | |
855e1111 | 3786 | } |
1da177e4 LT |
3787 | |
3788 | return ret; | |
3789 | } | |
3790 | ||
5be73b47 | 3791 | static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags) |
1da177e4 LT |
3792 | { |
3793 | int res = 0; | |
3794 | struct tg3_fiber_aneginfo aninfo; | |
3795 | int status = ANEG_FAILED; | |
3796 | unsigned int tick; | |
3797 | u32 tmp; | |
3798 | ||
3799 | tw32_f(MAC_TX_AUTO_NEG, 0); | |
3800 | ||
3801 | tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; | |
3802 | tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII); | |
3803 | udelay(40); | |
3804 | ||
3805 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS); | |
3806 | udelay(40); | |
3807 | ||
3808 | memset(&aninfo, 0, sizeof(aninfo)); | |
3809 | aninfo.flags |= MR_AN_ENABLE; | |
3810 | aninfo.state = ANEG_STATE_UNKNOWN; | |
3811 | aninfo.cur_time = 0; | |
3812 | tick = 0; | |
3813 | while (++tick < 195000) { | |
3814 | status = tg3_fiber_aneg_smachine(tp, &aninfo); | |
3815 | if (status == ANEG_DONE || status == ANEG_FAILED) | |
3816 | break; | |
3817 | ||
3818 | udelay(1); | |
3819 | } | |
3820 | ||
3821 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; | |
3822 | tw32_f(MAC_MODE, tp->mac_mode); | |
3823 | udelay(40); | |
3824 | ||
5be73b47 MC |
3825 | *txflags = aninfo.txconfig; |
3826 | *rxflags = aninfo.flags; | |
1da177e4 LT |
3827 | |
3828 | if (status == ANEG_DONE && | |
3829 | (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK | | |
3830 | MR_LP_ADV_FULL_DUPLEX))) | |
3831 | res = 1; | |
3832 | ||
3833 | return res; | |
3834 | } | |
3835 | ||
3836 | static void tg3_init_bcm8002(struct tg3 *tp) | |
3837 | { | |
3838 | u32 mac_status = tr32(MAC_STATUS); | |
3839 | int i; | |
3840 | ||
3841 | /* Reset when initting first time or we have a link. */ | |
63c3a66f | 3842 | if (tg3_flag(tp, INIT_COMPLETE) && |
1da177e4 LT |
3843 | !(mac_status & MAC_STATUS_PCS_SYNCED)) |
3844 | return; | |
3845 | ||
3846 | /* Set PLL lock range. */ | |
3847 | tg3_writephy(tp, 0x16, 0x8007); | |
3848 | ||
3849 | /* SW reset */ | |
3850 | tg3_writephy(tp, MII_BMCR, BMCR_RESET); | |
3851 | ||
3852 | /* Wait for reset to complete. */ | |
3853 | /* XXX schedule_timeout() ... */ | |
3854 | for (i = 0; i < 500; i++) | |
3855 | udelay(10); | |
3856 | ||
3857 | /* Config mode; select PMA/Ch 1 regs. */ | |
3858 | tg3_writephy(tp, 0x10, 0x8411); | |
3859 | ||
3860 | /* Enable auto-lock and comdet, select txclk for tx. */ | |
3861 | tg3_writephy(tp, 0x11, 0x0a10); | |
3862 | ||
3863 | tg3_writephy(tp, 0x18, 0x00a0); | |
3864 | tg3_writephy(tp, 0x16, 0x41ff); | |
3865 | ||
3866 | /* Assert and deassert POR. */ | |
3867 | tg3_writephy(tp, 0x13, 0x0400); | |
3868 | udelay(40); | |
3869 | tg3_writephy(tp, 0x13, 0x0000); | |
3870 | ||
3871 | tg3_writephy(tp, 0x11, 0x0a50); | |
3872 | udelay(40); | |
3873 | tg3_writephy(tp, 0x11, 0x0a10); | |
3874 | ||
3875 | /* Wait for signal to stabilize */ | |
3876 | /* XXX schedule_timeout() ... */ | |
3877 | for (i = 0; i < 15000; i++) | |
3878 | udelay(10); | |
3879 | ||
3880 | /* Deselect the channel register so we can read the PHYID | |
3881 | * later. | |
3882 | */ | |
3883 | tg3_writephy(tp, 0x10, 0x8011); | |
3884 | } | |
3885 | ||
3886 | static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status) | |
3887 | { | |
82cd3d11 | 3888 | u16 flowctrl; |
1da177e4 LT |
3889 | u32 sg_dig_ctrl, sg_dig_status; |
3890 | u32 serdes_cfg, expected_sg_dig_ctrl; | |
3891 | int workaround, port_a; | |
3892 | int current_link_up; | |
3893 | ||
3894 | serdes_cfg = 0; | |
3895 | expected_sg_dig_ctrl = 0; | |
3896 | workaround = 0; | |
3897 | port_a = 1; | |
3898 | current_link_up = 0; | |
3899 | ||
3900 | if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 && | |
3901 | tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) { | |
3902 | workaround = 1; | |
3903 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) | |
3904 | port_a = 0; | |
3905 | ||
3906 | /* preserve bits 0-11,13,14 for signal pre-emphasis */ | |
3907 | /* preserve bits 20-23 for voltage regulator */ | |
3908 | serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff; | |
3909 | } | |
3910 | ||
3911 | sg_dig_ctrl = tr32(SG_DIG_CTRL); | |
3912 | ||
3913 | if (tp->link_config.autoneg != AUTONEG_ENABLE) { | |
c98f6e3b | 3914 | if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) { |
1da177e4 LT |
3915 | if (workaround) { |
3916 | u32 val = serdes_cfg; | |
3917 | ||
3918 | if (port_a) | |
3919 | val |= 0xc010000; | |
3920 | else | |
3921 | val |= 0x4010000; | |
3922 | tw32_f(MAC_SERDES_CFG, val); | |
3923 | } | |
c98f6e3b MC |
3924 | |
3925 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); | |
1da177e4 LT |
3926 | } |
3927 | if (mac_status & MAC_STATUS_PCS_SYNCED) { | |
3928 | tg3_setup_flow_control(tp, 0, 0); | |
3929 | current_link_up = 1; | |
3930 | } | |
3931 | goto out; | |
3932 | } | |
3933 | ||
3934 | /* Want auto-negotiation. */ | |
c98f6e3b | 3935 | expected_sg_dig_ctrl = SG_DIG_USING_HW_AUTONEG | SG_DIG_COMMON_SETUP; |
1da177e4 | 3936 | |
82cd3d11 MC |
3937 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
3938 | if (flowctrl & ADVERTISE_1000XPAUSE) | |
3939 | expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP; | |
3940 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) | |
3941 | expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE; | |
1da177e4 LT |
3942 | |
3943 | if (sg_dig_ctrl != expected_sg_dig_ctrl) { | |
f07e9af3 | 3944 | if ((tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT) && |
3d3ebe74 MC |
3945 | tp->serdes_counter && |
3946 | ((mac_status & (MAC_STATUS_PCS_SYNCED | | |
3947 | MAC_STATUS_RCVD_CFG)) == | |
3948 | MAC_STATUS_PCS_SYNCED)) { | |
3949 | tp->serdes_counter--; | |
3950 | current_link_up = 1; | |
3951 | goto out; | |
3952 | } | |
3953 | restart_autoneg: | |
1da177e4 LT |
3954 | if (workaround) |
3955 | tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000); | |
c98f6e3b | 3956 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | SG_DIG_SOFT_RESET); |
1da177e4 LT |
3957 | udelay(5); |
3958 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl); | |
3959 | ||
3d3ebe74 | 3960 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
f07e9af3 | 3961 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
1da177e4 LT |
3962 | } else if (mac_status & (MAC_STATUS_PCS_SYNCED | |
3963 | MAC_STATUS_SIGNAL_DET)) { | |
3d3ebe74 | 3964 | sg_dig_status = tr32(SG_DIG_STATUS); |
1da177e4 LT |
3965 | mac_status = tr32(MAC_STATUS); |
3966 | ||
c98f6e3b | 3967 | if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) && |
1da177e4 | 3968 | (mac_status & MAC_STATUS_PCS_SYNCED)) { |
82cd3d11 MC |
3969 | u32 local_adv = 0, remote_adv = 0; |
3970 | ||
3971 | if (sg_dig_ctrl & SG_DIG_PAUSE_CAP) | |
3972 | local_adv |= ADVERTISE_1000XPAUSE; | |
3973 | if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE) | |
3974 | local_adv |= ADVERTISE_1000XPSE_ASYM; | |
1da177e4 | 3975 | |
c98f6e3b | 3976 | if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE) |
82cd3d11 | 3977 | remote_adv |= LPA_1000XPAUSE; |
c98f6e3b | 3978 | if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE) |
82cd3d11 | 3979 | remote_adv |= LPA_1000XPAUSE_ASYM; |
1da177e4 LT |
3980 | |
3981 | tg3_setup_flow_control(tp, local_adv, remote_adv); | |
3982 | current_link_up = 1; | |
3d3ebe74 | 3983 | tp->serdes_counter = 0; |
f07e9af3 | 3984 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
c98f6e3b | 3985 | } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) { |
3d3ebe74 MC |
3986 | if (tp->serdes_counter) |
3987 | tp->serdes_counter--; | |
1da177e4 LT |
3988 | else { |
3989 | if (workaround) { | |
3990 | u32 val = serdes_cfg; | |
3991 | ||
3992 | if (port_a) | |
3993 | val |= 0xc010000; | |
3994 | else | |
3995 | val |= 0x4010000; | |
3996 | ||
3997 | tw32_f(MAC_SERDES_CFG, val); | |
3998 | } | |
3999 | ||
c98f6e3b | 4000 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
1da177e4 LT |
4001 | udelay(40); |
4002 | ||
4003 | /* Link parallel detection - link is up */ | |
4004 | /* only if we have PCS_SYNC and not */ | |
4005 | /* receiving config code words */ | |
4006 | mac_status = tr32(MAC_STATUS); | |
4007 | if ((mac_status & MAC_STATUS_PCS_SYNCED) && | |
4008 | !(mac_status & MAC_STATUS_RCVD_CFG)) { | |
4009 | tg3_setup_flow_control(tp, 0, 0); | |
4010 | current_link_up = 1; | |
f07e9af3 MC |
4011 | tp->phy_flags |= |
4012 | TG3_PHYFLG_PARALLEL_DETECT; | |
3d3ebe74 MC |
4013 | tp->serdes_counter = |
4014 | SERDES_PARALLEL_DET_TIMEOUT; | |
4015 | } else | |
4016 | goto restart_autoneg; | |
1da177e4 LT |
4017 | } |
4018 | } | |
3d3ebe74 MC |
4019 | } else { |
4020 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; | |
f07e9af3 | 4021 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
1da177e4 LT |
4022 | } |
4023 | ||
4024 | out: | |
4025 | return current_link_up; | |
4026 | } | |
4027 | ||
4028 | static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status) | |
4029 | { | |
4030 | int current_link_up = 0; | |
4031 | ||
5cf64b8a | 4032 | if (!(mac_status & MAC_STATUS_PCS_SYNCED)) |
1da177e4 | 4033 | goto out; |
1da177e4 LT |
4034 | |
4035 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { | |
5be73b47 | 4036 | u32 txflags, rxflags; |
1da177e4 | 4037 | int i; |
6aa20a22 | 4038 | |
5be73b47 MC |
4039 | if (fiber_autoneg(tp, &txflags, &rxflags)) { |
4040 | u32 local_adv = 0, remote_adv = 0; | |
1da177e4 | 4041 | |
5be73b47 MC |
4042 | if (txflags & ANEG_CFG_PS1) |
4043 | local_adv |= ADVERTISE_1000XPAUSE; | |
4044 | if (txflags & ANEG_CFG_PS2) | |
4045 | local_adv |= ADVERTISE_1000XPSE_ASYM; | |
4046 | ||
4047 | if (rxflags & MR_LP_ADV_SYM_PAUSE) | |
4048 | remote_adv |= LPA_1000XPAUSE; | |
4049 | if (rxflags & MR_LP_ADV_ASYM_PAUSE) | |
4050 | remote_adv |= LPA_1000XPAUSE_ASYM; | |
1da177e4 LT |
4051 | |
4052 | tg3_setup_flow_control(tp, local_adv, remote_adv); | |
4053 | ||
1da177e4 LT |
4054 | current_link_up = 1; |
4055 | } | |
4056 | for (i = 0; i < 30; i++) { | |
4057 | udelay(20); | |
4058 | tw32_f(MAC_STATUS, | |
4059 | (MAC_STATUS_SYNC_CHANGED | | |
4060 | MAC_STATUS_CFG_CHANGED)); | |
4061 | udelay(40); | |
4062 | if ((tr32(MAC_STATUS) & | |
4063 | (MAC_STATUS_SYNC_CHANGED | | |
4064 | MAC_STATUS_CFG_CHANGED)) == 0) | |
4065 | break; | |
4066 | } | |
4067 | ||
4068 | mac_status = tr32(MAC_STATUS); | |
4069 | if (current_link_up == 0 && | |
4070 | (mac_status & MAC_STATUS_PCS_SYNCED) && | |
4071 | !(mac_status & MAC_STATUS_RCVD_CFG)) | |
4072 | current_link_up = 1; | |
4073 | } else { | |
5be73b47 MC |
4074 | tg3_setup_flow_control(tp, 0, 0); |
4075 | ||
1da177e4 LT |
4076 | /* Forcing 1000FD link up. */ |
4077 | current_link_up = 1; | |
1da177e4 LT |
4078 | |
4079 | tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS)); | |
4080 | udelay(40); | |
e8f3f6ca MC |
4081 | |
4082 | tw32_f(MAC_MODE, tp->mac_mode); | |
4083 | udelay(40); | |
1da177e4 LT |
4084 | } |
4085 | ||
4086 | out: | |
4087 | return current_link_up; | |
4088 | } | |
4089 | ||
4090 | static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset) | |
4091 | { | |
4092 | u32 orig_pause_cfg; | |
4093 | u16 orig_active_speed; | |
4094 | u8 orig_active_duplex; | |
4095 | u32 mac_status; | |
4096 | int current_link_up; | |
4097 | int i; | |
4098 | ||
8d018621 | 4099 | orig_pause_cfg = tp->link_config.active_flowctrl; |
1da177e4 LT |
4100 | orig_active_speed = tp->link_config.active_speed; |
4101 | orig_active_duplex = tp->link_config.active_duplex; | |
4102 | ||
63c3a66f | 4103 | if (!tg3_flag(tp, HW_AUTONEG) && |
1da177e4 | 4104 | netif_carrier_ok(tp->dev) && |
63c3a66f | 4105 | tg3_flag(tp, INIT_COMPLETE)) { |
1da177e4 LT |
4106 | mac_status = tr32(MAC_STATUS); |
4107 | mac_status &= (MAC_STATUS_PCS_SYNCED | | |
4108 | MAC_STATUS_SIGNAL_DET | | |
4109 | MAC_STATUS_CFG_CHANGED | | |
4110 | MAC_STATUS_RCVD_CFG); | |
4111 | if (mac_status == (MAC_STATUS_PCS_SYNCED | | |
4112 | MAC_STATUS_SIGNAL_DET)) { | |
4113 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | | |
4114 | MAC_STATUS_CFG_CHANGED)); | |
4115 | return 0; | |
4116 | } | |
4117 | } | |
4118 | ||
4119 | tw32_f(MAC_TX_AUTO_NEG, 0); | |
4120 | ||
4121 | tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); | |
4122 | tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; | |
4123 | tw32_f(MAC_MODE, tp->mac_mode); | |
4124 | udelay(40); | |
4125 | ||
79eb6904 | 4126 | if (tp->phy_id == TG3_PHY_ID_BCM8002) |
1da177e4 LT |
4127 | tg3_init_bcm8002(tp); |
4128 | ||
4129 | /* Enable link change event even when serdes polling. */ | |
4130 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); | |
4131 | udelay(40); | |
4132 | ||
4133 | current_link_up = 0; | |
4134 | mac_status = tr32(MAC_STATUS); | |
4135 | ||
63c3a66f | 4136 | if (tg3_flag(tp, HW_AUTONEG)) |
1da177e4 LT |
4137 | current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status); |
4138 | else | |
4139 | current_link_up = tg3_setup_fiber_by_hand(tp, mac_status); | |
4140 | ||
898a56f8 | 4141 | tp->napi[0].hw_status->status = |
1da177e4 | 4142 | (SD_STATUS_UPDATED | |
898a56f8 | 4143 | (tp->napi[0].hw_status->status & ~SD_STATUS_LINK_CHG)); |
1da177e4 LT |
4144 | |
4145 | for (i = 0; i < 100; i++) { | |
4146 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | | |
4147 | MAC_STATUS_CFG_CHANGED)); | |
4148 | udelay(5); | |
4149 | if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED | | |
3d3ebe74 MC |
4150 | MAC_STATUS_CFG_CHANGED | |
4151 | MAC_STATUS_LNKSTATE_CHANGED)) == 0) | |
1da177e4 LT |
4152 | break; |
4153 | } | |
4154 | ||
4155 | mac_status = tr32(MAC_STATUS); | |
4156 | if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) { | |
4157 | current_link_up = 0; | |
3d3ebe74 MC |
4158 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
4159 | tp->serdes_counter == 0) { | |
1da177e4 LT |
4160 | tw32_f(MAC_MODE, (tp->mac_mode | |
4161 | MAC_MODE_SEND_CONFIGS)); | |
4162 | udelay(1); | |
4163 | tw32_f(MAC_MODE, tp->mac_mode); | |
4164 | } | |
4165 | } | |
4166 | ||
4167 | if (current_link_up == 1) { | |
4168 | tp->link_config.active_speed = SPEED_1000; | |
4169 | tp->link_config.active_duplex = DUPLEX_FULL; | |
4170 | tw32(MAC_LED_CTRL, (tp->led_ctrl | | |
4171 | LED_CTRL_LNKLED_OVERRIDE | | |
4172 | LED_CTRL_1000MBPS_ON)); | |
4173 | } else { | |
4174 | tp->link_config.active_speed = SPEED_INVALID; | |
4175 | tp->link_config.active_duplex = DUPLEX_INVALID; | |
4176 | tw32(MAC_LED_CTRL, (tp->led_ctrl | | |
4177 | LED_CTRL_LNKLED_OVERRIDE | | |
4178 | LED_CTRL_TRAFFIC_OVERRIDE)); | |
4179 | } | |
4180 | ||
4181 | if (current_link_up != netif_carrier_ok(tp->dev)) { | |
4182 | if (current_link_up) | |
4183 | netif_carrier_on(tp->dev); | |
4184 | else | |
4185 | netif_carrier_off(tp->dev); | |
4186 | tg3_link_report(tp); | |
4187 | } else { | |
8d018621 | 4188 | u32 now_pause_cfg = tp->link_config.active_flowctrl; |
1da177e4 LT |
4189 | if (orig_pause_cfg != now_pause_cfg || |
4190 | orig_active_speed != tp->link_config.active_speed || | |
4191 | orig_active_duplex != tp->link_config.active_duplex) | |
4192 | tg3_link_report(tp); | |
4193 | } | |
4194 | ||
4195 | return 0; | |
4196 | } | |
4197 | ||
747e8f8b MC |
4198 | static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset) |
4199 | { | |
4200 | int current_link_up, err = 0; | |
4201 | u32 bmsr, bmcr; | |
4202 | u16 current_speed; | |
4203 | u8 current_duplex; | |
ef167e27 | 4204 | u32 local_adv, remote_adv; |
747e8f8b MC |
4205 | |
4206 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
4207 | tw32_f(MAC_MODE, tp->mac_mode); | |
4208 | udelay(40); | |
4209 | ||
4210 | tw32(MAC_EVENT, 0); | |
4211 | ||
4212 | tw32_f(MAC_STATUS, | |
4213 | (MAC_STATUS_SYNC_CHANGED | | |
4214 | MAC_STATUS_CFG_CHANGED | | |
4215 | MAC_STATUS_MI_COMPLETION | | |
4216 | MAC_STATUS_LNKSTATE_CHANGED)); | |
4217 | udelay(40); | |
4218 | ||
4219 | if (force_reset) | |
4220 | tg3_phy_reset(tp); | |
4221 | ||
4222 | current_link_up = 0; | |
4223 | current_speed = SPEED_INVALID; | |
4224 | current_duplex = DUPLEX_INVALID; | |
4225 | ||
4226 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); | |
4227 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); | |
d4d2c558 MC |
4228 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
4229 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) | |
4230 | bmsr |= BMSR_LSTATUS; | |
4231 | else | |
4232 | bmsr &= ~BMSR_LSTATUS; | |
4233 | } | |
747e8f8b MC |
4234 | |
4235 | err |= tg3_readphy(tp, MII_BMCR, &bmcr); | |
4236 | ||
4237 | if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset && | |
f07e9af3 | 4238 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
747e8f8b MC |
4239 | /* do nothing, just check for link up at the end */ |
4240 | } else if (tp->link_config.autoneg == AUTONEG_ENABLE) { | |
4241 | u32 adv, new_adv; | |
4242 | ||
4243 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); | |
4244 | new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF | | |
4245 | ADVERTISE_1000XPAUSE | | |
4246 | ADVERTISE_1000XPSE_ASYM | | |
4247 | ADVERTISE_SLCT); | |
4248 | ||
ba4d07a8 | 4249 | new_adv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
747e8f8b MC |
4250 | |
4251 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Half) | |
4252 | new_adv |= ADVERTISE_1000XHALF; | |
4253 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Full) | |
4254 | new_adv |= ADVERTISE_1000XFULL; | |
4255 | ||
4256 | if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) { | |
4257 | tg3_writephy(tp, MII_ADVERTISE, new_adv); | |
4258 | bmcr |= BMCR_ANENABLE | BMCR_ANRESTART; | |
4259 | tg3_writephy(tp, MII_BMCR, bmcr); | |
4260 | ||
4261 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); | |
3d3ebe74 | 4262 | tp->serdes_counter = SERDES_AN_TIMEOUT_5714S; |
f07e9af3 | 4263 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
4264 | |
4265 | return err; | |
4266 | } | |
4267 | } else { | |
4268 | u32 new_bmcr; | |
4269 | ||
4270 | bmcr &= ~BMCR_SPEED1000; | |
4271 | new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX); | |
4272 | ||
4273 | if (tp->link_config.duplex == DUPLEX_FULL) | |
4274 | new_bmcr |= BMCR_FULLDPLX; | |
4275 | ||
4276 | if (new_bmcr != bmcr) { | |
4277 | /* BMCR_SPEED1000 is a reserved bit that needs | |
4278 | * to be set on write. | |
4279 | */ | |
4280 | new_bmcr |= BMCR_SPEED1000; | |
4281 | ||
4282 | /* Force a linkdown */ | |
4283 | if (netif_carrier_ok(tp->dev)) { | |
4284 | u32 adv; | |
4285 | ||
4286 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); | |
4287 | adv &= ~(ADVERTISE_1000XFULL | | |
4288 | ADVERTISE_1000XHALF | | |
4289 | ADVERTISE_SLCT); | |
4290 | tg3_writephy(tp, MII_ADVERTISE, adv); | |
4291 | tg3_writephy(tp, MII_BMCR, bmcr | | |
4292 | BMCR_ANRESTART | | |
4293 | BMCR_ANENABLE); | |
4294 | udelay(10); | |
4295 | netif_carrier_off(tp->dev); | |
4296 | } | |
4297 | tg3_writephy(tp, MII_BMCR, new_bmcr); | |
4298 | bmcr = new_bmcr; | |
4299 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); | |
4300 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); | |
d4d2c558 MC |
4301 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
4302 | ASIC_REV_5714) { | |
4303 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) | |
4304 | bmsr |= BMSR_LSTATUS; | |
4305 | else | |
4306 | bmsr &= ~BMSR_LSTATUS; | |
4307 | } | |
f07e9af3 | 4308 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
4309 | } |
4310 | } | |
4311 | ||
4312 | if (bmsr & BMSR_LSTATUS) { | |
4313 | current_speed = SPEED_1000; | |
4314 | current_link_up = 1; | |
4315 | if (bmcr & BMCR_FULLDPLX) | |
4316 | current_duplex = DUPLEX_FULL; | |
4317 | else | |
4318 | current_duplex = DUPLEX_HALF; | |
4319 | ||
ef167e27 MC |
4320 | local_adv = 0; |
4321 | remote_adv = 0; | |
4322 | ||
747e8f8b | 4323 | if (bmcr & BMCR_ANENABLE) { |
ef167e27 | 4324 | u32 common; |
747e8f8b MC |
4325 | |
4326 | err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv); | |
4327 | err |= tg3_readphy(tp, MII_LPA, &remote_adv); | |
4328 | common = local_adv & remote_adv; | |
4329 | if (common & (ADVERTISE_1000XHALF | | |
4330 | ADVERTISE_1000XFULL)) { | |
4331 | if (common & ADVERTISE_1000XFULL) | |
4332 | current_duplex = DUPLEX_FULL; | |
4333 | else | |
4334 | current_duplex = DUPLEX_HALF; | |
63c3a66f | 4335 | } else if (!tg3_flag(tp, 5780_CLASS)) { |
57d8b880 | 4336 | /* Link is up via parallel detect */ |
859a5887 | 4337 | } else { |
747e8f8b | 4338 | current_link_up = 0; |
859a5887 | 4339 | } |
747e8f8b MC |
4340 | } |
4341 | } | |
4342 | ||
ef167e27 MC |
4343 | if (current_link_up == 1 && current_duplex == DUPLEX_FULL) |
4344 | tg3_setup_flow_control(tp, local_adv, remote_adv); | |
4345 | ||
747e8f8b MC |
4346 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
4347 | if (tp->link_config.active_duplex == DUPLEX_HALF) | |
4348 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; | |
4349 | ||
4350 | tw32_f(MAC_MODE, tp->mac_mode); | |
4351 | udelay(40); | |
4352 | ||
4353 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); | |
4354 | ||
4355 | tp->link_config.active_speed = current_speed; | |
4356 | tp->link_config.active_duplex = current_duplex; | |
4357 | ||
4358 | if (current_link_up != netif_carrier_ok(tp->dev)) { | |
4359 | if (current_link_up) | |
4360 | netif_carrier_on(tp->dev); | |
4361 | else { | |
4362 | netif_carrier_off(tp->dev); | |
f07e9af3 | 4363 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
4364 | } |
4365 | tg3_link_report(tp); | |
4366 | } | |
4367 | return err; | |
4368 | } | |
4369 | ||
4370 | static void tg3_serdes_parallel_detect(struct tg3 *tp) | |
4371 | { | |
3d3ebe74 | 4372 | if (tp->serdes_counter) { |
747e8f8b | 4373 | /* Give autoneg time to complete. */ |
3d3ebe74 | 4374 | tp->serdes_counter--; |
747e8f8b MC |
4375 | return; |
4376 | } | |
c6cdf436 | 4377 | |
747e8f8b MC |
4378 | if (!netif_carrier_ok(tp->dev) && |
4379 | (tp->link_config.autoneg == AUTONEG_ENABLE)) { | |
4380 | u32 bmcr; | |
4381 | ||
4382 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
4383 | if (bmcr & BMCR_ANENABLE) { | |
4384 | u32 phy1, phy2; | |
4385 | ||
4386 | /* Select shadow register 0x1f */ | |
f08aa1a8 MC |
4387 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x7c00); |
4388 | tg3_readphy(tp, MII_TG3_MISC_SHDW, &phy1); | |
747e8f8b MC |
4389 | |
4390 | /* Select expansion interrupt status register */ | |
f08aa1a8 MC |
4391 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
4392 | MII_TG3_DSP_EXP1_INT_STAT); | |
4393 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); | |
4394 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); | |
747e8f8b MC |
4395 | |
4396 | if ((phy1 & 0x10) && !(phy2 & 0x20)) { | |
4397 | /* We have signal detect and not receiving | |
4398 | * config code words, link is up by parallel | |
4399 | * detection. | |
4400 | */ | |
4401 | ||
4402 | bmcr &= ~BMCR_ANENABLE; | |
4403 | bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX; | |
4404 | tg3_writephy(tp, MII_BMCR, bmcr); | |
f07e9af3 | 4405 | tp->phy_flags |= TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
4406 | } |
4407 | } | |
859a5887 MC |
4408 | } else if (netif_carrier_ok(tp->dev) && |
4409 | (tp->link_config.autoneg == AUTONEG_ENABLE) && | |
f07e9af3 | 4410 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
747e8f8b MC |
4411 | u32 phy2; |
4412 | ||
4413 | /* Select expansion interrupt status register */ | |
f08aa1a8 MC |
4414 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
4415 | MII_TG3_DSP_EXP1_INT_STAT); | |
4416 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); | |
747e8f8b MC |
4417 | if (phy2 & 0x20) { |
4418 | u32 bmcr; | |
4419 | ||
4420 | /* Config code words received, turn on autoneg. */ | |
4421 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
4422 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE); | |
4423 | ||
f07e9af3 | 4424 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
4425 | |
4426 | } | |
4427 | } | |
4428 | } | |
4429 | ||
1da177e4 LT |
4430 | static int tg3_setup_phy(struct tg3 *tp, int force_reset) |
4431 | { | |
f2096f94 | 4432 | u32 val; |
1da177e4 LT |
4433 | int err; |
4434 | ||
f07e9af3 | 4435 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
1da177e4 | 4436 | err = tg3_setup_fiber_phy(tp, force_reset); |
f07e9af3 | 4437 | else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
747e8f8b | 4438 | err = tg3_setup_fiber_mii_phy(tp, force_reset); |
859a5887 | 4439 | else |
1da177e4 | 4440 | err = tg3_setup_copper_phy(tp, force_reset); |
1da177e4 | 4441 | |
bcb37f6c | 4442 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
f2096f94 | 4443 | u32 scale; |
aa6c91fe MC |
4444 | |
4445 | val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK; | |
4446 | if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5) | |
4447 | scale = 65; | |
4448 | else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25) | |
4449 | scale = 6; | |
4450 | else | |
4451 | scale = 12; | |
4452 | ||
4453 | val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK; | |
4454 | val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT); | |
4455 | tw32(GRC_MISC_CFG, val); | |
4456 | } | |
4457 | ||
f2096f94 MC |
4458 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
4459 | (6 << TX_LENGTHS_IPG_SHIFT); | |
4460 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) | |
4461 | val |= tr32(MAC_TX_LENGTHS) & | |
4462 | (TX_LENGTHS_JMB_FRM_LEN_MSK | | |
4463 | TX_LENGTHS_CNT_DWN_VAL_MSK); | |
4464 | ||
1da177e4 LT |
4465 | if (tp->link_config.active_speed == SPEED_1000 && |
4466 | tp->link_config.active_duplex == DUPLEX_HALF) | |
f2096f94 MC |
4467 | tw32(MAC_TX_LENGTHS, val | |
4468 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)); | |
1da177e4 | 4469 | else |
f2096f94 MC |
4470 | tw32(MAC_TX_LENGTHS, val | |
4471 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT)); | |
1da177e4 | 4472 | |
63c3a66f | 4473 | if (!tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
4474 | if (netif_carrier_ok(tp->dev)) { |
4475 | tw32(HOSTCC_STAT_COAL_TICKS, | |
15f9850d | 4476 | tp->coal.stats_block_coalesce_usecs); |
1da177e4 LT |
4477 | } else { |
4478 | tw32(HOSTCC_STAT_COAL_TICKS, 0); | |
4479 | } | |
4480 | } | |
4481 | ||
63c3a66f | 4482 | if (tg3_flag(tp, ASPM_WORKAROUND)) { |
f2096f94 | 4483 | val = tr32(PCIE_PWR_MGMT_THRESH); |
8ed5d97e MC |
4484 | if (!netif_carrier_ok(tp->dev)) |
4485 | val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) | | |
4486 | tp->pwrmgmt_thresh; | |
4487 | else | |
4488 | val |= PCIE_PWR_MGMT_L1_THRESH_MSK; | |
4489 | tw32(PCIE_PWR_MGMT_THRESH, val); | |
4490 | } | |
4491 | ||
1da177e4 LT |
4492 | return err; |
4493 | } | |
4494 | ||
66cfd1bd MC |
4495 | static inline int tg3_irq_sync(struct tg3 *tp) |
4496 | { | |
4497 | return tp->irq_sync; | |
4498 | } | |
4499 | ||
97bd8e49 MC |
4500 | static inline void tg3_rd32_loop(struct tg3 *tp, u32 *dst, u32 off, u32 len) |
4501 | { | |
4502 | int i; | |
4503 | ||
4504 | dst = (u32 *)((u8 *)dst + off); | |
4505 | for (i = 0; i < len; i += sizeof(u32)) | |
4506 | *dst++ = tr32(off + i); | |
4507 | } | |
4508 | ||
4509 | static void tg3_dump_legacy_regs(struct tg3 *tp, u32 *regs) | |
4510 | { | |
4511 | tg3_rd32_loop(tp, regs, TG3PCI_VENDOR, 0xb0); | |
4512 | tg3_rd32_loop(tp, regs, MAILBOX_INTERRUPT_0, 0x200); | |
4513 | tg3_rd32_loop(tp, regs, MAC_MODE, 0x4f0); | |
4514 | tg3_rd32_loop(tp, regs, SNDDATAI_MODE, 0xe0); | |
4515 | tg3_rd32_loop(tp, regs, SNDDATAC_MODE, 0x04); | |
4516 | tg3_rd32_loop(tp, regs, SNDBDS_MODE, 0x80); | |
4517 | tg3_rd32_loop(tp, regs, SNDBDI_MODE, 0x48); | |
4518 | tg3_rd32_loop(tp, regs, SNDBDC_MODE, 0x04); | |
4519 | tg3_rd32_loop(tp, regs, RCVLPC_MODE, 0x20); | |
4520 | tg3_rd32_loop(tp, regs, RCVLPC_SELLST_BASE, 0x15c); | |
4521 | tg3_rd32_loop(tp, regs, RCVDBDI_MODE, 0x0c); | |
4522 | tg3_rd32_loop(tp, regs, RCVDBDI_JUMBO_BD, 0x3c); | |
4523 | tg3_rd32_loop(tp, regs, RCVDBDI_BD_PROD_IDX_0, 0x44); | |
4524 | tg3_rd32_loop(tp, regs, RCVDCC_MODE, 0x04); | |
4525 | tg3_rd32_loop(tp, regs, RCVBDI_MODE, 0x20); | |
4526 | tg3_rd32_loop(tp, regs, RCVCC_MODE, 0x14); | |
4527 | tg3_rd32_loop(tp, regs, RCVLSC_MODE, 0x08); | |
4528 | tg3_rd32_loop(tp, regs, MBFREE_MODE, 0x08); | |
4529 | tg3_rd32_loop(tp, regs, HOSTCC_MODE, 0x100); | |
4530 | ||
63c3a66f | 4531 | if (tg3_flag(tp, SUPPORT_MSIX)) |
97bd8e49 MC |
4532 | tg3_rd32_loop(tp, regs, HOSTCC_RXCOL_TICKS_VEC1, 0x180); |
4533 | ||
4534 | tg3_rd32_loop(tp, regs, MEMARB_MODE, 0x10); | |
4535 | tg3_rd32_loop(tp, regs, BUFMGR_MODE, 0x58); | |
4536 | tg3_rd32_loop(tp, regs, RDMAC_MODE, 0x08); | |
4537 | tg3_rd32_loop(tp, regs, WDMAC_MODE, 0x08); | |
4538 | tg3_rd32_loop(tp, regs, RX_CPU_MODE, 0x04); | |
4539 | tg3_rd32_loop(tp, regs, RX_CPU_STATE, 0x04); | |
4540 | tg3_rd32_loop(tp, regs, RX_CPU_PGMCTR, 0x04); | |
4541 | tg3_rd32_loop(tp, regs, RX_CPU_HWBKPT, 0x04); | |
4542 | ||
63c3a66f | 4543 | if (!tg3_flag(tp, 5705_PLUS)) { |
97bd8e49 MC |
4544 | tg3_rd32_loop(tp, regs, TX_CPU_MODE, 0x04); |
4545 | tg3_rd32_loop(tp, regs, TX_CPU_STATE, 0x04); | |
4546 | tg3_rd32_loop(tp, regs, TX_CPU_PGMCTR, 0x04); | |
4547 | } | |
4548 | ||
4549 | tg3_rd32_loop(tp, regs, GRCMBOX_INTERRUPT_0, 0x110); | |
4550 | tg3_rd32_loop(tp, regs, FTQ_RESET, 0x120); | |
4551 | tg3_rd32_loop(tp, regs, MSGINT_MODE, 0x0c); | |
4552 | tg3_rd32_loop(tp, regs, DMAC_MODE, 0x04); | |
4553 | tg3_rd32_loop(tp, regs, GRC_MODE, 0x4c); | |
4554 | ||
63c3a66f | 4555 | if (tg3_flag(tp, NVRAM)) |
97bd8e49 MC |
4556 | tg3_rd32_loop(tp, regs, NVRAM_CMD, 0x24); |
4557 | } | |
4558 | ||
4559 | static void tg3_dump_state(struct tg3 *tp) | |
4560 | { | |
4561 | int i; | |
4562 | u32 *regs; | |
4563 | ||
4564 | regs = kzalloc(TG3_REG_BLK_SIZE, GFP_ATOMIC); | |
4565 | if (!regs) { | |
4566 | netdev_err(tp->dev, "Failed allocating register dump buffer\n"); | |
4567 | return; | |
4568 | } | |
4569 | ||
63c3a66f | 4570 | if (tg3_flag(tp, PCI_EXPRESS)) { |
97bd8e49 MC |
4571 | /* Read up to but not including private PCI registers */ |
4572 | for (i = 0; i < TG3_PCIE_TLDLPL_PORT; i += sizeof(u32)) | |
4573 | regs[i / sizeof(u32)] = tr32(i); | |
4574 | } else | |
4575 | tg3_dump_legacy_regs(tp, regs); | |
4576 | ||
4577 | for (i = 0; i < TG3_REG_BLK_SIZE / sizeof(u32); i += 4) { | |
4578 | if (!regs[i + 0] && !regs[i + 1] && | |
4579 | !regs[i + 2] && !regs[i + 3]) | |
4580 | continue; | |
4581 | ||
4582 | netdev_err(tp->dev, "0x%08x: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n", | |
4583 | i * 4, | |
4584 | regs[i + 0], regs[i + 1], regs[i + 2], regs[i + 3]); | |
4585 | } | |
4586 | ||
4587 | kfree(regs); | |
4588 | ||
4589 | for (i = 0; i < tp->irq_cnt; i++) { | |
4590 | struct tg3_napi *tnapi = &tp->napi[i]; | |
4591 | ||
4592 | /* SW status block */ | |
4593 | netdev_err(tp->dev, | |
4594 | "%d: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n", | |
4595 | i, | |
4596 | tnapi->hw_status->status, | |
4597 | tnapi->hw_status->status_tag, | |
4598 | tnapi->hw_status->rx_jumbo_consumer, | |
4599 | tnapi->hw_status->rx_consumer, | |
4600 | tnapi->hw_status->rx_mini_consumer, | |
4601 | tnapi->hw_status->idx[0].rx_producer, | |
4602 | tnapi->hw_status->idx[0].tx_consumer); | |
4603 | ||
4604 | netdev_err(tp->dev, | |
4605 | "%d: NAPI info [%08x:%08x:(%04x:%04x:%04x):%04x:(%04x:%04x:%04x:%04x)]\n", | |
4606 | i, | |
4607 | tnapi->last_tag, tnapi->last_irq_tag, | |
4608 | tnapi->tx_prod, tnapi->tx_cons, tnapi->tx_pending, | |
4609 | tnapi->rx_rcb_ptr, | |
4610 | tnapi->prodring.rx_std_prod_idx, | |
4611 | tnapi->prodring.rx_std_cons_idx, | |
4612 | tnapi->prodring.rx_jmb_prod_idx, | |
4613 | tnapi->prodring.rx_jmb_cons_idx); | |
4614 | } | |
4615 | } | |
4616 | ||
df3e6548 MC |
4617 | /* This is called whenever we suspect that the system chipset is re- |
4618 | * ordering the sequence of MMIO to the tx send mailbox. The symptom | |
4619 | * is bogus tx completions. We try to recover by setting the | |
4620 | * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later | |
4621 | * in the workqueue. | |
4622 | */ | |
4623 | static void tg3_tx_recover(struct tg3 *tp) | |
4624 | { | |
63c3a66f | 4625 | BUG_ON(tg3_flag(tp, MBOX_WRITE_REORDER) || |
df3e6548 MC |
4626 | tp->write32_tx_mbox == tg3_write_indirect_mbox); |
4627 | ||
5129c3a3 MC |
4628 | netdev_warn(tp->dev, |
4629 | "The system may be re-ordering memory-mapped I/O " | |
4630 | "cycles to the network device, attempting to recover. " | |
4631 | "Please report the problem to the driver maintainer " | |
4632 | "and include system chipset information.\n"); | |
df3e6548 MC |
4633 | |
4634 | spin_lock(&tp->lock); | |
63c3a66f | 4635 | tg3_flag_set(tp, TX_RECOVERY_PENDING); |
df3e6548 MC |
4636 | spin_unlock(&tp->lock); |
4637 | } | |
4638 | ||
f3f3f27e | 4639 | static inline u32 tg3_tx_avail(struct tg3_napi *tnapi) |
1b2a7205 | 4640 | { |
f65aac16 MC |
4641 | /* Tell compiler to fetch tx indices from memory. */ |
4642 | barrier(); | |
f3f3f27e MC |
4643 | return tnapi->tx_pending - |
4644 | ((tnapi->tx_prod - tnapi->tx_cons) & (TG3_TX_RING_SIZE - 1)); | |
1b2a7205 MC |
4645 | } |
4646 | ||
1da177e4 LT |
4647 | /* Tigon3 never reports partial packet sends. So we do not |
4648 | * need special logic to handle SKBs that have not had all | |
4649 | * of their frags sent yet, like SunGEM does. | |
4650 | */ | |
17375d25 | 4651 | static void tg3_tx(struct tg3_napi *tnapi) |
1da177e4 | 4652 | { |
17375d25 | 4653 | struct tg3 *tp = tnapi->tp; |
898a56f8 | 4654 | u32 hw_idx = tnapi->hw_status->idx[0].tx_consumer; |
f3f3f27e | 4655 | u32 sw_idx = tnapi->tx_cons; |
fe5f5787 MC |
4656 | struct netdev_queue *txq; |
4657 | int index = tnapi - tp->napi; | |
4658 | ||
63c3a66f | 4659 | if (tg3_flag(tp, ENABLE_TSS)) |
fe5f5787 MC |
4660 | index--; |
4661 | ||
4662 | txq = netdev_get_tx_queue(tp->dev, index); | |
1da177e4 LT |
4663 | |
4664 | while (sw_idx != hw_idx) { | |
f4188d8a | 4665 | struct ring_info *ri = &tnapi->tx_buffers[sw_idx]; |
1da177e4 | 4666 | struct sk_buff *skb = ri->skb; |
df3e6548 MC |
4667 | int i, tx_bug = 0; |
4668 | ||
4669 | if (unlikely(skb == NULL)) { | |
4670 | tg3_tx_recover(tp); | |
4671 | return; | |
4672 | } | |
1da177e4 | 4673 | |
f4188d8a | 4674 | pci_unmap_single(tp->pdev, |
4e5e4f0d | 4675 | dma_unmap_addr(ri, mapping), |
f4188d8a AD |
4676 | skb_headlen(skb), |
4677 | PCI_DMA_TODEVICE); | |
1da177e4 LT |
4678 | |
4679 | ri->skb = NULL; | |
4680 | ||
4681 | sw_idx = NEXT_TX(sw_idx); | |
4682 | ||
4683 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { | |
f3f3f27e | 4684 | ri = &tnapi->tx_buffers[sw_idx]; |
df3e6548 MC |
4685 | if (unlikely(ri->skb != NULL || sw_idx == hw_idx)) |
4686 | tx_bug = 1; | |
f4188d8a AD |
4687 | |
4688 | pci_unmap_page(tp->pdev, | |
4e5e4f0d | 4689 | dma_unmap_addr(ri, mapping), |
f4188d8a AD |
4690 | skb_shinfo(skb)->frags[i].size, |
4691 | PCI_DMA_TODEVICE); | |
1da177e4 LT |
4692 | sw_idx = NEXT_TX(sw_idx); |
4693 | } | |
4694 | ||
f47c11ee | 4695 | dev_kfree_skb(skb); |
df3e6548 MC |
4696 | |
4697 | if (unlikely(tx_bug)) { | |
4698 | tg3_tx_recover(tp); | |
4699 | return; | |
4700 | } | |
1da177e4 LT |
4701 | } |
4702 | ||
f3f3f27e | 4703 | tnapi->tx_cons = sw_idx; |
1da177e4 | 4704 | |
1b2a7205 MC |
4705 | /* Need to make the tx_cons update visible to tg3_start_xmit() |
4706 | * before checking for netif_queue_stopped(). Without the | |
4707 | * memory barrier, there is a small possibility that tg3_start_xmit() | |
4708 | * will miss it and cause the queue to be stopped forever. | |
4709 | */ | |
4710 | smp_mb(); | |
4711 | ||
fe5f5787 | 4712 | if (unlikely(netif_tx_queue_stopped(txq) && |
f3f3f27e | 4713 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)))) { |
fe5f5787 MC |
4714 | __netif_tx_lock(txq, smp_processor_id()); |
4715 | if (netif_tx_queue_stopped(txq) && | |
f3f3f27e | 4716 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi))) |
fe5f5787 MC |
4717 | netif_tx_wake_queue(txq); |
4718 | __netif_tx_unlock(txq); | |
51b91468 | 4719 | } |
1da177e4 LT |
4720 | } |
4721 | ||
2b2cdb65 MC |
4722 | static void tg3_rx_skb_free(struct tg3 *tp, struct ring_info *ri, u32 map_sz) |
4723 | { | |
4724 | if (!ri->skb) | |
4725 | return; | |
4726 | ||
4e5e4f0d | 4727 | pci_unmap_single(tp->pdev, dma_unmap_addr(ri, mapping), |
2b2cdb65 MC |
4728 | map_sz, PCI_DMA_FROMDEVICE); |
4729 | dev_kfree_skb_any(ri->skb); | |
4730 | ri->skb = NULL; | |
4731 | } | |
4732 | ||
1da177e4 LT |
4733 | /* Returns size of skb allocated or < 0 on error. |
4734 | * | |
4735 | * We only need to fill in the address because the other members | |
4736 | * of the RX descriptor are invariant, see tg3_init_rings. | |
4737 | * | |
4738 | * Note the purposeful assymetry of cpu vs. chip accesses. For | |
4739 | * posting buffers we only dirty the first cache line of the RX | |
4740 | * descriptor (containing the address). Whereas for the RX status | |
4741 | * buffers the cpu only reads the last cacheline of the RX descriptor | |
4742 | * (to fetch the error flags, vlan tag, checksum, and opaque cookie). | |
4743 | */ | |
86b21e59 | 4744 | static int tg3_alloc_rx_skb(struct tg3 *tp, struct tg3_rx_prodring_set *tpr, |
a3896167 | 4745 | u32 opaque_key, u32 dest_idx_unmasked) |
1da177e4 LT |
4746 | { |
4747 | struct tg3_rx_buffer_desc *desc; | |
f94e290e | 4748 | struct ring_info *map; |
1da177e4 LT |
4749 | struct sk_buff *skb; |
4750 | dma_addr_t mapping; | |
4751 | int skb_size, dest_idx; | |
4752 | ||
1da177e4 LT |
4753 | switch (opaque_key) { |
4754 | case RXD_OPAQUE_RING_STD: | |
2c49a44d | 4755 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
21f581a5 MC |
4756 | desc = &tpr->rx_std[dest_idx]; |
4757 | map = &tpr->rx_std_buffers[dest_idx]; | |
287be12e | 4758 | skb_size = tp->rx_pkt_map_sz; |
1da177e4 LT |
4759 | break; |
4760 | ||
4761 | case RXD_OPAQUE_RING_JUMBO: | |
2c49a44d | 4762 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
79ed5ac7 | 4763 | desc = &tpr->rx_jmb[dest_idx].std; |
21f581a5 | 4764 | map = &tpr->rx_jmb_buffers[dest_idx]; |
287be12e | 4765 | skb_size = TG3_RX_JMB_MAP_SZ; |
1da177e4 LT |
4766 | break; |
4767 | ||
4768 | default: | |
4769 | return -EINVAL; | |
855e1111 | 4770 | } |
1da177e4 LT |
4771 | |
4772 | /* Do not overwrite any of the map or rp information | |
4773 | * until we are sure we can commit to a new buffer. | |
4774 | * | |
4775 | * Callers depend upon this behavior and assume that | |
4776 | * we leave everything unchanged if we fail. | |
4777 | */ | |
287be12e | 4778 | skb = netdev_alloc_skb(tp->dev, skb_size + tp->rx_offset); |
1da177e4 LT |
4779 | if (skb == NULL) |
4780 | return -ENOMEM; | |
4781 | ||
1da177e4 LT |
4782 | skb_reserve(skb, tp->rx_offset); |
4783 | ||
287be12e | 4784 | mapping = pci_map_single(tp->pdev, skb->data, skb_size, |
1da177e4 | 4785 | PCI_DMA_FROMDEVICE); |
a21771dd MC |
4786 | if (pci_dma_mapping_error(tp->pdev, mapping)) { |
4787 | dev_kfree_skb(skb); | |
4788 | return -EIO; | |
4789 | } | |
1da177e4 LT |
4790 | |
4791 | map->skb = skb; | |
4e5e4f0d | 4792 | dma_unmap_addr_set(map, mapping, mapping); |
1da177e4 | 4793 | |
1da177e4 LT |
4794 | desc->addr_hi = ((u64)mapping >> 32); |
4795 | desc->addr_lo = ((u64)mapping & 0xffffffff); | |
4796 | ||
4797 | return skb_size; | |
4798 | } | |
4799 | ||
4800 | /* We only need to move over in the address because the other | |
4801 | * members of the RX descriptor are invariant. See notes above | |
4802 | * tg3_alloc_rx_skb for full details. | |
4803 | */ | |
a3896167 MC |
4804 | static void tg3_recycle_rx(struct tg3_napi *tnapi, |
4805 | struct tg3_rx_prodring_set *dpr, | |
4806 | u32 opaque_key, int src_idx, | |
4807 | u32 dest_idx_unmasked) | |
1da177e4 | 4808 | { |
17375d25 | 4809 | struct tg3 *tp = tnapi->tp; |
1da177e4 LT |
4810 | struct tg3_rx_buffer_desc *src_desc, *dest_desc; |
4811 | struct ring_info *src_map, *dest_map; | |
8fea32b9 | 4812 | struct tg3_rx_prodring_set *spr = &tp->napi[0].prodring; |
c6cdf436 | 4813 | int dest_idx; |
1da177e4 LT |
4814 | |
4815 | switch (opaque_key) { | |
4816 | case RXD_OPAQUE_RING_STD: | |
2c49a44d | 4817 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
a3896167 MC |
4818 | dest_desc = &dpr->rx_std[dest_idx]; |
4819 | dest_map = &dpr->rx_std_buffers[dest_idx]; | |
4820 | src_desc = &spr->rx_std[src_idx]; | |
4821 | src_map = &spr->rx_std_buffers[src_idx]; | |
1da177e4 LT |
4822 | break; |
4823 | ||
4824 | case RXD_OPAQUE_RING_JUMBO: | |
2c49a44d | 4825 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
a3896167 MC |
4826 | dest_desc = &dpr->rx_jmb[dest_idx].std; |
4827 | dest_map = &dpr->rx_jmb_buffers[dest_idx]; | |
4828 | src_desc = &spr->rx_jmb[src_idx].std; | |
4829 | src_map = &spr->rx_jmb_buffers[src_idx]; | |
1da177e4 LT |
4830 | break; |
4831 | ||
4832 | default: | |
4833 | return; | |
855e1111 | 4834 | } |
1da177e4 LT |
4835 | |
4836 | dest_map->skb = src_map->skb; | |
4e5e4f0d FT |
4837 | dma_unmap_addr_set(dest_map, mapping, |
4838 | dma_unmap_addr(src_map, mapping)); | |
1da177e4 LT |
4839 | dest_desc->addr_hi = src_desc->addr_hi; |
4840 | dest_desc->addr_lo = src_desc->addr_lo; | |
e92967bf MC |
4841 | |
4842 | /* Ensure that the update to the skb happens after the physical | |
4843 | * addresses have been transferred to the new BD location. | |
4844 | */ | |
4845 | smp_wmb(); | |
4846 | ||
1da177e4 LT |
4847 | src_map->skb = NULL; |
4848 | } | |
4849 | ||
1da177e4 LT |
4850 | /* The RX ring scheme is composed of multiple rings which post fresh |
4851 | * buffers to the chip, and one special ring the chip uses to report | |
4852 | * status back to the host. | |
4853 | * | |
4854 | * The special ring reports the status of received packets to the | |
4855 | * host. The chip does not write into the original descriptor the | |
4856 | * RX buffer was obtained from. The chip simply takes the original | |
4857 | * descriptor as provided by the host, updates the status and length | |
4858 | * field, then writes this into the next status ring entry. | |
4859 | * | |
4860 | * Each ring the host uses to post buffers to the chip is described | |
4861 | * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives, | |
4862 | * it is first placed into the on-chip ram. When the packet's length | |
4863 | * is known, it walks down the TG3_BDINFO entries to select the ring. | |
4864 | * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO | |
4865 | * which is within the range of the new packet's length is chosen. | |
4866 | * | |
4867 | * The "separate ring for rx status" scheme may sound queer, but it makes | |
4868 | * sense from a cache coherency perspective. If only the host writes | |
4869 | * to the buffer post rings, and only the chip writes to the rx status | |
4870 | * rings, then cache lines never move beyond shared-modified state. | |
4871 | * If both the host and chip were to write into the same ring, cache line | |
4872 | * eviction could occur since both entities want it in an exclusive state. | |
4873 | */ | |
17375d25 | 4874 | static int tg3_rx(struct tg3_napi *tnapi, int budget) |
1da177e4 | 4875 | { |
17375d25 | 4876 | struct tg3 *tp = tnapi->tp; |
f92905de | 4877 | u32 work_mask, rx_std_posted = 0; |
4361935a | 4878 | u32 std_prod_idx, jmb_prod_idx; |
72334482 | 4879 | u32 sw_idx = tnapi->rx_rcb_ptr; |
483ba50b | 4880 | u16 hw_idx; |
1da177e4 | 4881 | int received; |
8fea32b9 | 4882 | struct tg3_rx_prodring_set *tpr = &tnapi->prodring; |
1da177e4 | 4883 | |
8d9d7cfc | 4884 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
1da177e4 LT |
4885 | /* |
4886 | * We need to order the read of hw_idx and the read of | |
4887 | * the opaque cookie. | |
4888 | */ | |
4889 | rmb(); | |
1da177e4 LT |
4890 | work_mask = 0; |
4891 | received = 0; | |
4361935a MC |
4892 | std_prod_idx = tpr->rx_std_prod_idx; |
4893 | jmb_prod_idx = tpr->rx_jmb_prod_idx; | |
1da177e4 | 4894 | while (sw_idx != hw_idx && budget > 0) { |
afc081f8 | 4895 | struct ring_info *ri; |
72334482 | 4896 | struct tg3_rx_buffer_desc *desc = &tnapi->rx_rcb[sw_idx]; |
1da177e4 LT |
4897 | unsigned int len; |
4898 | struct sk_buff *skb; | |
4899 | dma_addr_t dma_addr; | |
4900 | u32 opaque_key, desc_idx, *post_ptr; | |
4901 | ||
4902 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; | |
4903 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; | |
4904 | if (opaque_key == RXD_OPAQUE_RING_STD) { | |
8fea32b9 | 4905 | ri = &tp->napi[0].prodring.rx_std_buffers[desc_idx]; |
4e5e4f0d | 4906 | dma_addr = dma_unmap_addr(ri, mapping); |
21f581a5 | 4907 | skb = ri->skb; |
4361935a | 4908 | post_ptr = &std_prod_idx; |
f92905de | 4909 | rx_std_posted++; |
1da177e4 | 4910 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
8fea32b9 | 4911 | ri = &tp->napi[0].prodring.rx_jmb_buffers[desc_idx]; |
4e5e4f0d | 4912 | dma_addr = dma_unmap_addr(ri, mapping); |
21f581a5 | 4913 | skb = ri->skb; |
4361935a | 4914 | post_ptr = &jmb_prod_idx; |
21f581a5 | 4915 | } else |
1da177e4 | 4916 | goto next_pkt_nopost; |
1da177e4 LT |
4917 | |
4918 | work_mask |= opaque_key; | |
4919 | ||
4920 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && | |
4921 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) { | |
4922 | drop_it: | |
a3896167 | 4923 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
1da177e4 LT |
4924 | desc_idx, *post_ptr); |
4925 | drop_it_no_recycle: | |
4926 | /* Other statistics kept track of by card. */ | |
b0057c51 | 4927 | tp->rx_dropped++; |
1da177e4 LT |
4928 | goto next_pkt; |
4929 | } | |
4930 | ||
ad829268 MC |
4931 | len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - |
4932 | ETH_FCS_LEN; | |
1da177e4 | 4933 | |
d2757fc4 | 4934 | if (len > TG3_RX_COPY_THRESH(tp)) { |
1da177e4 LT |
4935 | int skb_size; |
4936 | ||
86b21e59 | 4937 | skb_size = tg3_alloc_rx_skb(tp, tpr, opaque_key, |
afc081f8 | 4938 | *post_ptr); |
1da177e4 LT |
4939 | if (skb_size < 0) |
4940 | goto drop_it; | |
4941 | ||
287be12e | 4942 | pci_unmap_single(tp->pdev, dma_addr, skb_size, |
1da177e4 LT |
4943 | PCI_DMA_FROMDEVICE); |
4944 | ||
61e800cf MC |
4945 | /* Ensure that the update to the skb happens |
4946 | * after the usage of the old DMA mapping. | |
4947 | */ | |
4948 | smp_wmb(); | |
4949 | ||
4950 | ri->skb = NULL; | |
4951 | ||
1da177e4 LT |
4952 | skb_put(skb, len); |
4953 | } else { | |
4954 | struct sk_buff *copy_skb; | |
4955 | ||
a3896167 | 4956 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
1da177e4 LT |
4957 | desc_idx, *post_ptr); |
4958 | ||
bf933c80 | 4959 | copy_skb = netdev_alloc_skb(tp->dev, len + |
9dc7a113 | 4960 | TG3_RAW_IP_ALIGN); |
1da177e4 LT |
4961 | if (copy_skb == NULL) |
4962 | goto drop_it_no_recycle; | |
4963 | ||
bf933c80 | 4964 | skb_reserve(copy_skb, TG3_RAW_IP_ALIGN); |
1da177e4 LT |
4965 | skb_put(copy_skb, len); |
4966 | pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); | |
d626f62b | 4967 | skb_copy_from_linear_data(skb, copy_skb->data, len); |
1da177e4 LT |
4968 | pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); |
4969 | ||
4970 | /* We'll reuse the original ring buffer. */ | |
4971 | skb = copy_skb; | |
4972 | } | |
4973 | ||
dc668910 | 4974 | if ((tp->dev->features & NETIF_F_RXCSUM) && |
1da177e4 LT |
4975 | (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
4976 | (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK) | |
4977 | >> RXD_TCPCSUM_SHIFT) == 0xffff)) | |
4978 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
4979 | else | |
bc8acf2c | 4980 | skb_checksum_none_assert(skb); |
1da177e4 LT |
4981 | |
4982 | skb->protocol = eth_type_trans(skb, tp->dev); | |
f7b493e0 MC |
4983 | |
4984 | if (len > (tp->dev->mtu + ETH_HLEN) && | |
4985 | skb->protocol != htons(ETH_P_8021Q)) { | |
4986 | dev_kfree_skb(skb); | |
b0057c51 | 4987 | goto drop_it_no_recycle; |
f7b493e0 MC |
4988 | } |
4989 | ||
9dc7a113 | 4990 | if (desc->type_flags & RXD_FLAG_VLAN && |
bf933c80 MC |
4991 | !(tp->rx_mode & RX_MODE_KEEP_VLAN_TAG)) |
4992 | __vlan_hwaccel_put_tag(skb, | |
4993 | desc->err_vlan & RXD_VLAN_MASK); | |
9dc7a113 | 4994 | |
bf933c80 | 4995 | napi_gro_receive(&tnapi->napi, skb); |
1da177e4 | 4996 | |
1da177e4 LT |
4997 | received++; |
4998 | budget--; | |
4999 | ||
5000 | next_pkt: | |
5001 | (*post_ptr)++; | |
f92905de MC |
5002 | |
5003 | if (unlikely(rx_std_posted >= tp->rx_std_max_post)) { | |
2c49a44d MC |
5004 | tpr->rx_std_prod_idx = std_prod_idx & |
5005 | tp->rx_std_ring_mask; | |
86cfe4ff MC |
5006 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
5007 | tpr->rx_std_prod_idx); | |
f92905de MC |
5008 | work_mask &= ~RXD_OPAQUE_RING_STD; |
5009 | rx_std_posted = 0; | |
5010 | } | |
1da177e4 | 5011 | next_pkt_nopost: |
483ba50b | 5012 | sw_idx++; |
7cb32cf2 | 5013 | sw_idx &= tp->rx_ret_ring_mask; |
52f6d697 MC |
5014 | |
5015 | /* Refresh hw_idx to see if there is new work */ | |
5016 | if (sw_idx == hw_idx) { | |
8d9d7cfc | 5017 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
52f6d697 MC |
5018 | rmb(); |
5019 | } | |
1da177e4 LT |
5020 | } |
5021 | ||
5022 | /* ACK the status ring. */ | |
72334482 MC |
5023 | tnapi->rx_rcb_ptr = sw_idx; |
5024 | tw32_rx_mbox(tnapi->consmbox, sw_idx); | |
1da177e4 LT |
5025 | |
5026 | /* Refill RX ring(s). */ | |
63c3a66f | 5027 | if (!tg3_flag(tp, ENABLE_RSS)) { |
b196c7e4 | 5028 | if (work_mask & RXD_OPAQUE_RING_STD) { |
2c49a44d MC |
5029 | tpr->rx_std_prod_idx = std_prod_idx & |
5030 | tp->rx_std_ring_mask; | |
b196c7e4 MC |
5031 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
5032 | tpr->rx_std_prod_idx); | |
5033 | } | |
5034 | if (work_mask & RXD_OPAQUE_RING_JUMBO) { | |
2c49a44d MC |
5035 | tpr->rx_jmb_prod_idx = jmb_prod_idx & |
5036 | tp->rx_jmb_ring_mask; | |
b196c7e4 MC |
5037 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
5038 | tpr->rx_jmb_prod_idx); | |
5039 | } | |
5040 | mmiowb(); | |
5041 | } else if (work_mask) { | |
5042 | /* rx_std_buffers[] and rx_jmb_buffers[] entries must be | |
5043 | * updated before the producer indices can be updated. | |
5044 | */ | |
5045 | smp_wmb(); | |
5046 | ||
2c49a44d MC |
5047 | tpr->rx_std_prod_idx = std_prod_idx & tp->rx_std_ring_mask; |
5048 | tpr->rx_jmb_prod_idx = jmb_prod_idx & tp->rx_jmb_ring_mask; | |
b196c7e4 | 5049 | |
e4af1af9 MC |
5050 | if (tnapi != &tp->napi[1]) |
5051 | napi_schedule(&tp->napi[1].napi); | |
1da177e4 | 5052 | } |
1da177e4 LT |
5053 | |
5054 | return received; | |
5055 | } | |
5056 | ||
35f2d7d0 | 5057 | static void tg3_poll_link(struct tg3 *tp) |
1da177e4 | 5058 | { |
1da177e4 | 5059 | /* handle link change and other phy events */ |
63c3a66f | 5060 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
35f2d7d0 MC |
5061 | struct tg3_hw_status *sblk = tp->napi[0].hw_status; |
5062 | ||
1da177e4 LT |
5063 | if (sblk->status & SD_STATUS_LINK_CHG) { |
5064 | sblk->status = SD_STATUS_UPDATED | | |
35f2d7d0 | 5065 | (sblk->status & ~SD_STATUS_LINK_CHG); |
f47c11ee | 5066 | spin_lock(&tp->lock); |
63c3a66f | 5067 | if (tg3_flag(tp, USE_PHYLIB)) { |
dd477003 MC |
5068 | tw32_f(MAC_STATUS, |
5069 | (MAC_STATUS_SYNC_CHANGED | | |
5070 | MAC_STATUS_CFG_CHANGED | | |
5071 | MAC_STATUS_MI_COMPLETION | | |
5072 | MAC_STATUS_LNKSTATE_CHANGED)); | |
5073 | udelay(40); | |
5074 | } else | |
5075 | tg3_setup_phy(tp, 0); | |
f47c11ee | 5076 | spin_unlock(&tp->lock); |
1da177e4 LT |
5077 | } |
5078 | } | |
35f2d7d0 MC |
5079 | } |
5080 | ||
f89f38b8 MC |
5081 | static int tg3_rx_prodring_xfer(struct tg3 *tp, |
5082 | struct tg3_rx_prodring_set *dpr, | |
5083 | struct tg3_rx_prodring_set *spr) | |
b196c7e4 MC |
5084 | { |
5085 | u32 si, di, cpycnt, src_prod_idx; | |
f89f38b8 | 5086 | int i, err = 0; |
b196c7e4 MC |
5087 | |
5088 | while (1) { | |
5089 | src_prod_idx = spr->rx_std_prod_idx; | |
5090 | ||
5091 | /* Make sure updates to the rx_std_buffers[] entries and the | |
5092 | * standard producer index are seen in the correct order. | |
5093 | */ | |
5094 | smp_rmb(); | |
5095 | ||
5096 | if (spr->rx_std_cons_idx == src_prod_idx) | |
5097 | break; | |
5098 | ||
5099 | if (spr->rx_std_cons_idx < src_prod_idx) | |
5100 | cpycnt = src_prod_idx - spr->rx_std_cons_idx; | |
5101 | else | |
2c49a44d MC |
5102 | cpycnt = tp->rx_std_ring_mask + 1 - |
5103 | spr->rx_std_cons_idx; | |
b196c7e4 | 5104 | |
2c49a44d MC |
5105 | cpycnt = min(cpycnt, |
5106 | tp->rx_std_ring_mask + 1 - dpr->rx_std_prod_idx); | |
b196c7e4 MC |
5107 | |
5108 | si = spr->rx_std_cons_idx; | |
5109 | di = dpr->rx_std_prod_idx; | |
5110 | ||
e92967bf MC |
5111 | for (i = di; i < di + cpycnt; i++) { |
5112 | if (dpr->rx_std_buffers[i].skb) { | |
5113 | cpycnt = i - di; | |
f89f38b8 | 5114 | err = -ENOSPC; |
e92967bf MC |
5115 | break; |
5116 | } | |
5117 | } | |
5118 | ||
5119 | if (!cpycnt) | |
5120 | break; | |
5121 | ||
5122 | /* Ensure that updates to the rx_std_buffers ring and the | |
5123 | * shadowed hardware producer ring from tg3_recycle_skb() are | |
5124 | * ordered correctly WRT the skb check above. | |
5125 | */ | |
5126 | smp_rmb(); | |
5127 | ||
b196c7e4 MC |
5128 | memcpy(&dpr->rx_std_buffers[di], |
5129 | &spr->rx_std_buffers[si], | |
5130 | cpycnt * sizeof(struct ring_info)); | |
5131 | ||
5132 | for (i = 0; i < cpycnt; i++, di++, si++) { | |
5133 | struct tg3_rx_buffer_desc *sbd, *dbd; | |
5134 | sbd = &spr->rx_std[si]; | |
5135 | dbd = &dpr->rx_std[di]; | |
5136 | dbd->addr_hi = sbd->addr_hi; | |
5137 | dbd->addr_lo = sbd->addr_lo; | |
5138 | } | |
5139 | ||
2c49a44d MC |
5140 | spr->rx_std_cons_idx = (spr->rx_std_cons_idx + cpycnt) & |
5141 | tp->rx_std_ring_mask; | |
5142 | dpr->rx_std_prod_idx = (dpr->rx_std_prod_idx + cpycnt) & | |
5143 | tp->rx_std_ring_mask; | |
b196c7e4 MC |
5144 | } |
5145 | ||
5146 | while (1) { | |
5147 | src_prod_idx = spr->rx_jmb_prod_idx; | |
5148 | ||
5149 | /* Make sure updates to the rx_jmb_buffers[] entries and | |
5150 | * the jumbo producer index are seen in the correct order. | |
5151 | */ | |
5152 | smp_rmb(); | |
5153 | ||
5154 | if (spr->rx_jmb_cons_idx == src_prod_idx) | |
5155 | break; | |
5156 | ||
5157 | if (spr->rx_jmb_cons_idx < src_prod_idx) | |
5158 | cpycnt = src_prod_idx - spr->rx_jmb_cons_idx; | |
5159 | else | |
2c49a44d MC |
5160 | cpycnt = tp->rx_jmb_ring_mask + 1 - |
5161 | spr->rx_jmb_cons_idx; | |
b196c7e4 MC |
5162 | |
5163 | cpycnt = min(cpycnt, | |
2c49a44d | 5164 | tp->rx_jmb_ring_mask + 1 - dpr->rx_jmb_prod_idx); |
b196c7e4 MC |
5165 | |
5166 | si = spr->rx_jmb_cons_idx; | |
5167 | di = dpr->rx_jmb_prod_idx; | |
5168 | ||
e92967bf MC |
5169 | for (i = di; i < di + cpycnt; i++) { |
5170 | if (dpr->rx_jmb_buffers[i].skb) { | |
5171 | cpycnt = i - di; | |
f89f38b8 | 5172 | err = -ENOSPC; |
e92967bf MC |
5173 | break; |
5174 | } | |
5175 | } | |
5176 | ||
5177 | if (!cpycnt) | |
5178 | break; | |
5179 | ||
5180 | /* Ensure that updates to the rx_jmb_buffers ring and the | |
5181 | * shadowed hardware producer ring from tg3_recycle_skb() are | |
5182 | * ordered correctly WRT the skb check above. | |
5183 | */ | |
5184 | smp_rmb(); | |
5185 | ||
b196c7e4 MC |
5186 | memcpy(&dpr->rx_jmb_buffers[di], |
5187 | &spr->rx_jmb_buffers[si], | |
5188 | cpycnt * sizeof(struct ring_info)); | |
5189 | ||
5190 | for (i = 0; i < cpycnt; i++, di++, si++) { | |
5191 | struct tg3_rx_buffer_desc *sbd, *dbd; | |
5192 | sbd = &spr->rx_jmb[si].std; | |
5193 | dbd = &dpr->rx_jmb[di].std; | |
5194 | dbd->addr_hi = sbd->addr_hi; | |
5195 | dbd->addr_lo = sbd->addr_lo; | |
5196 | } | |
5197 | ||
2c49a44d MC |
5198 | spr->rx_jmb_cons_idx = (spr->rx_jmb_cons_idx + cpycnt) & |
5199 | tp->rx_jmb_ring_mask; | |
5200 | dpr->rx_jmb_prod_idx = (dpr->rx_jmb_prod_idx + cpycnt) & | |
5201 | tp->rx_jmb_ring_mask; | |
b196c7e4 | 5202 | } |
f89f38b8 MC |
5203 | |
5204 | return err; | |
b196c7e4 MC |
5205 | } |
5206 | ||
35f2d7d0 MC |
5207 | static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget) |
5208 | { | |
5209 | struct tg3 *tp = tnapi->tp; | |
1da177e4 LT |
5210 | |
5211 | /* run TX completion thread */ | |
f3f3f27e | 5212 | if (tnapi->hw_status->idx[0].tx_consumer != tnapi->tx_cons) { |
17375d25 | 5213 | tg3_tx(tnapi); |
63c3a66f | 5214 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
4fd7ab59 | 5215 | return work_done; |
1da177e4 LT |
5216 | } |
5217 | ||
1da177e4 LT |
5218 | /* run RX thread, within the bounds set by NAPI. |
5219 | * All RX "locking" is done by ensuring outside | |
bea3348e | 5220 | * code synchronizes with tg3->napi.poll() |
1da177e4 | 5221 | */ |
8d9d7cfc | 5222 | if (*(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
17375d25 | 5223 | work_done += tg3_rx(tnapi, budget - work_done); |
1da177e4 | 5224 | |
63c3a66f | 5225 | if (tg3_flag(tp, ENABLE_RSS) && tnapi == &tp->napi[1]) { |
8fea32b9 | 5226 | struct tg3_rx_prodring_set *dpr = &tp->napi[0].prodring; |
f89f38b8 | 5227 | int i, err = 0; |
e4af1af9 MC |
5228 | u32 std_prod_idx = dpr->rx_std_prod_idx; |
5229 | u32 jmb_prod_idx = dpr->rx_jmb_prod_idx; | |
b196c7e4 | 5230 | |
e4af1af9 | 5231 | for (i = 1; i < tp->irq_cnt; i++) |
f89f38b8 | 5232 | err |= tg3_rx_prodring_xfer(tp, dpr, |
8fea32b9 | 5233 | &tp->napi[i].prodring); |
b196c7e4 MC |
5234 | |
5235 | wmb(); | |
5236 | ||
e4af1af9 MC |
5237 | if (std_prod_idx != dpr->rx_std_prod_idx) |
5238 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, | |
5239 | dpr->rx_std_prod_idx); | |
b196c7e4 | 5240 | |
e4af1af9 MC |
5241 | if (jmb_prod_idx != dpr->rx_jmb_prod_idx) |
5242 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, | |
5243 | dpr->rx_jmb_prod_idx); | |
b196c7e4 MC |
5244 | |
5245 | mmiowb(); | |
f89f38b8 MC |
5246 | |
5247 | if (err) | |
5248 | tw32_f(HOSTCC_MODE, tp->coal_now); | |
b196c7e4 MC |
5249 | } |
5250 | ||
6f535763 DM |
5251 | return work_done; |
5252 | } | |
5253 | ||
35f2d7d0 MC |
5254 | static int tg3_poll_msix(struct napi_struct *napi, int budget) |
5255 | { | |
5256 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); | |
5257 | struct tg3 *tp = tnapi->tp; | |
5258 | int work_done = 0; | |
5259 | struct tg3_hw_status *sblk = tnapi->hw_status; | |
5260 | ||
5261 | while (1) { | |
5262 | work_done = tg3_poll_work(tnapi, work_done, budget); | |
5263 | ||
63c3a66f | 5264 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
35f2d7d0 MC |
5265 | goto tx_recovery; |
5266 | ||
5267 | if (unlikely(work_done >= budget)) | |
5268 | break; | |
5269 | ||
c6cdf436 | 5270 | /* tp->last_tag is used in tg3_int_reenable() below |
35f2d7d0 MC |
5271 | * to tell the hw how much work has been processed, |
5272 | * so we must read it before checking for more work. | |
5273 | */ | |
5274 | tnapi->last_tag = sblk->status_tag; | |
5275 | tnapi->last_irq_tag = tnapi->last_tag; | |
5276 | rmb(); | |
5277 | ||
5278 | /* check for RX/TX work to do */ | |
6d40db7b MC |
5279 | if (likely(sblk->idx[0].tx_consumer == tnapi->tx_cons && |
5280 | *(tnapi->rx_rcb_prod_idx) == tnapi->rx_rcb_ptr)) { | |
35f2d7d0 MC |
5281 | napi_complete(napi); |
5282 | /* Reenable interrupts. */ | |
5283 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); | |
5284 | mmiowb(); | |
5285 | break; | |
5286 | } | |
5287 | } | |
5288 | ||
5289 | return work_done; | |
5290 | ||
5291 | tx_recovery: | |
5292 | /* work_done is guaranteed to be less than budget. */ | |
5293 | napi_complete(napi); | |
5294 | schedule_work(&tp->reset_task); | |
5295 | return work_done; | |
5296 | } | |
5297 | ||
e64de4e6 MC |
5298 | static void tg3_process_error(struct tg3 *tp) |
5299 | { | |
5300 | u32 val; | |
5301 | bool real_error = false; | |
5302 | ||
63c3a66f | 5303 | if (tg3_flag(tp, ERROR_PROCESSED)) |
e64de4e6 MC |
5304 | return; |
5305 | ||
5306 | /* Check Flow Attention register */ | |
5307 | val = tr32(HOSTCC_FLOW_ATTN); | |
5308 | if (val & ~HOSTCC_FLOW_ATTN_MBUF_LWM) { | |
5309 | netdev_err(tp->dev, "FLOW Attention error. Resetting chip.\n"); | |
5310 | real_error = true; | |
5311 | } | |
5312 | ||
5313 | if (tr32(MSGINT_STATUS) & ~MSGINT_STATUS_MSI_REQ) { | |
5314 | netdev_err(tp->dev, "MSI Status error. Resetting chip.\n"); | |
5315 | real_error = true; | |
5316 | } | |
5317 | ||
5318 | if (tr32(RDMAC_STATUS) || tr32(WDMAC_STATUS)) { | |
5319 | netdev_err(tp->dev, "DMA Status error. Resetting chip.\n"); | |
5320 | real_error = true; | |
5321 | } | |
5322 | ||
5323 | if (!real_error) | |
5324 | return; | |
5325 | ||
5326 | tg3_dump_state(tp); | |
5327 | ||
63c3a66f | 5328 | tg3_flag_set(tp, ERROR_PROCESSED); |
e64de4e6 MC |
5329 | schedule_work(&tp->reset_task); |
5330 | } | |
5331 | ||
6f535763 DM |
5332 | static int tg3_poll(struct napi_struct *napi, int budget) |
5333 | { | |
8ef0442f MC |
5334 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
5335 | struct tg3 *tp = tnapi->tp; | |
6f535763 | 5336 | int work_done = 0; |
898a56f8 | 5337 | struct tg3_hw_status *sblk = tnapi->hw_status; |
6f535763 DM |
5338 | |
5339 | while (1) { | |
e64de4e6 MC |
5340 | if (sblk->status & SD_STATUS_ERROR) |
5341 | tg3_process_error(tp); | |
5342 | ||
35f2d7d0 MC |
5343 | tg3_poll_link(tp); |
5344 | ||
17375d25 | 5345 | work_done = tg3_poll_work(tnapi, work_done, budget); |
6f535763 | 5346 | |
63c3a66f | 5347 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
6f535763 DM |
5348 | goto tx_recovery; |
5349 | ||
5350 | if (unlikely(work_done >= budget)) | |
5351 | break; | |
5352 | ||
63c3a66f | 5353 | if (tg3_flag(tp, TAGGED_STATUS)) { |
17375d25 | 5354 | /* tp->last_tag is used in tg3_int_reenable() below |
4fd7ab59 MC |
5355 | * to tell the hw how much work has been processed, |
5356 | * so we must read it before checking for more work. | |
5357 | */ | |
898a56f8 MC |
5358 | tnapi->last_tag = sblk->status_tag; |
5359 | tnapi->last_irq_tag = tnapi->last_tag; | |
4fd7ab59 MC |
5360 | rmb(); |
5361 | } else | |
5362 | sblk->status &= ~SD_STATUS_UPDATED; | |
6f535763 | 5363 | |
17375d25 | 5364 | if (likely(!tg3_has_work(tnapi))) { |
288379f0 | 5365 | napi_complete(napi); |
17375d25 | 5366 | tg3_int_reenable(tnapi); |
6f535763 DM |
5367 | break; |
5368 | } | |
1da177e4 LT |
5369 | } |
5370 | ||
bea3348e | 5371 | return work_done; |
6f535763 DM |
5372 | |
5373 | tx_recovery: | |
4fd7ab59 | 5374 | /* work_done is guaranteed to be less than budget. */ |
288379f0 | 5375 | napi_complete(napi); |
6f535763 | 5376 | schedule_work(&tp->reset_task); |
4fd7ab59 | 5377 | return work_done; |
1da177e4 LT |
5378 | } |
5379 | ||
66cfd1bd MC |
5380 | static void tg3_napi_disable(struct tg3 *tp) |
5381 | { | |
5382 | int i; | |
5383 | ||
5384 | for (i = tp->irq_cnt - 1; i >= 0; i--) | |
5385 | napi_disable(&tp->napi[i].napi); | |
5386 | } | |
5387 | ||
5388 | static void tg3_napi_enable(struct tg3 *tp) | |
5389 | { | |
5390 | int i; | |
5391 | ||
5392 | for (i = 0; i < tp->irq_cnt; i++) | |
5393 | napi_enable(&tp->napi[i].napi); | |
5394 | } | |
5395 | ||
5396 | static void tg3_napi_init(struct tg3 *tp) | |
5397 | { | |
5398 | int i; | |
5399 | ||
5400 | netif_napi_add(tp->dev, &tp->napi[0].napi, tg3_poll, 64); | |
5401 | for (i = 1; i < tp->irq_cnt; i++) | |
5402 | netif_napi_add(tp->dev, &tp->napi[i].napi, tg3_poll_msix, 64); | |
5403 | } | |
5404 | ||
5405 | static void tg3_napi_fini(struct tg3 *tp) | |
5406 | { | |
5407 | int i; | |
5408 | ||
5409 | for (i = 0; i < tp->irq_cnt; i++) | |
5410 | netif_napi_del(&tp->napi[i].napi); | |
5411 | } | |
5412 | ||
5413 | static inline void tg3_netif_stop(struct tg3 *tp) | |
5414 | { | |
5415 | tp->dev->trans_start = jiffies; /* prevent tx timeout */ | |
5416 | tg3_napi_disable(tp); | |
5417 | netif_tx_disable(tp->dev); | |
5418 | } | |
5419 | ||
5420 | static inline void tg3_netif_start(struct tg3 *tp) | |
5421 | { | |
5422 | /* NOTE: unconditional netif_tx_wake_all_queues is only | |
5423 | * appropriate so long as all callers are assured to | |
5424 | * have free tx slots (such as after tg3_init_hw) | |
5425 | */ | |
5426 | netif_tx_wake_all_queues(tp->dev); | |
5427 | ||
5428 | tg3_napi_enable(tp); | |
5429 | tp->napi[0].hw_status->status |= SD_STATUS_UPDATED; | |
5430 | tg3_enable_ints(tp); | |
5431 | } | |
5432 | ||
f47c11ee DM |
5433 | static void tg3_irq_quiesce(struct tg3 *tp) |
5434 | { | |
4f125f42 MC |
5435 | int i; |
5436 | ||
f47c11ee DM |
5437 | BUG_ON(tp->irq_sync); |
5438 | ||
5439 | tp->irq_sync = 1; | |
5440 | smp_mb(); | |
5441 | ||
4f125f42 MC |
5442 | for (i = 0; i < tp->irq_cnt; i++) |
5443 | synchronize_irq(tp->napi[i].irq_vec); | |
f47c11ee DM |
5444 | } |
5445 | ||
f47c11ee DM |
5446 | /* Fully shutdown all tg3 driver activity elsewhere in the system. |
5447 | * If irq_sync is non-zero, then the IRQ handler must be synchronized | |
5448 | * with as well. Most of the time, this is not necessary except when | |
5449 | * shutting down the device. | |
5450 | */ | |
5451 | static inline void tg3_full_lock(struct tg3 *tp, int irq_sync) | |
5452 | { | |
46966545 | 5453 | spin_lock_bh(&tp->lock); |
f47c11ee DM |
5454 | if (irq_sync) |
5455 | tg3_irq_quiesce(tp); | |
f47c11ee DM |
5456 | } |
5457 | ||
5458 | static inline void tg3_full_unlock(struct tg3 *tp) | |
5459 | { | |
f47c11ee DM |
5460 | spin_unlock_bh(&tp->lock); |
5461 | } | |
5462 | ||
fcfa0a32 MC |
5463 | /* One-shot MSI handler - Chip automatically disables interrupt |
5464 | * after sending MSI so driver doesn't have to do it. | |
5465 | */ | |
7d12e780 | 5466 | static irqreturn_t tg3_msi_1shot(int irq, void *dev_id) |
fcfa0a32 | 5467 | { |
09943a18 MC |
5468 | struct tg3_napi *tnapi = dev_id; |
5469 | struct tg3 *tp = tnapi->tp; | |
fcfa0a32 | 5470 | |
898a56f8 | 5471 | prefetch(tnapi->hw_status); |
0c1d0e2b MC |
5472 | if (tnapi->rx_rcb) |
5473 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); | |
fcfa0a32 MC |
5474 | |
5475 | if (likely(!tg3_irq_sync(tp))) | |
09943a18 | 5476 | napi_schedule(&tnapi->napi); |
fcfa0a32 MC |
5477 | |
5478 | return IRQ_HANDLED; | |
5479 | } | |
5480 | ||
88b06bc2 MC |
5481 | /* MSI ISR - No need to check for interrupt sharing and no need to |
5482 | * flush status block and interrupt mailbox. PCI ordering rules | |
5483 | * guarantee that MSI will arrive after the status block. | |
5484 | */ | |
7d12e780 | 5485 | static irqreturn_t tg3_msi(int irq, void *dev_id) |
88b06bc2 | 5486 | { |
09943a18 MC |
5487 | struct tg3_napi *tnapi = dev_id; |
5488 | struct tg3 *tp = tnapi->tp; | |
88b06bc2 | 5489 | |
898a56f8 | 5490 | prefetch(tnapi->hw_status); |
0c1d0e2b MC |
5491 | if (tnapi->rx_rcb) |
5492 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); | |
88b06bc2 | 5493 | /* |
fac9b83e | 5494 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
88b06bc2 | 5495 | * chip-internal interrupt pending events. |
fac9b83e | 5496 | * Writing non-zero to intr-mbox-0 additional tells the |
88b06bc2 MC |
5497 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
5498 | * event coalescing. | |
5499 | */ | |
5500 | tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); | |
61487480 | 5501 | if (likely(!tg3_irq_sync(tp))) |
09943a18 | 5502 | napi_schedule(&tnapi->napi); |
61487480 | 5503 | |
88b06bc2 MC |
5504 | return IRQ_RETVAL(1); |
5505 | } | |
5506 | ||
7d12e780 | 5507 | static irqreturn_t tg3_interrupt(int irq, void *dev_id) |
1da177e4 | 5508 | { |
09943a18 MC |
5509 | struct tg3_napi *tnapi = dev_id; |
5510 | struct tg3 *tp = tnapi->tp; | |
898a56f8 | 5511 | struct tg3_hw_status *sblk = tnapi->hw_status; |
1da177e4 LT |
5512 | unsigned int handled = 1; |
5513 | ||
1da177e4 LT |
5514 | /* In INTx mode, it is possible for the interrupt to arrive at |
5515 | * the CPU before the status block posted prior to the interrupt. | |
5516 | * Reading the PCI State register will confirm whether the | |
5517 | * interrupt is ours and will flush the status block. | |
5518 | */ | |
d18edcb2 | 5519 | if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) { |
63c3a66f | 5520 | if (tg3_flag(tp, CHIP_RESETTING) || |
d18edcb2 MC |
5521 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
5522 | handled = 0; | |
f47c11ee | 5523 | goto out; |
fac9b83e | 5524 | } |
d18edcb2 MC |
5525 | } |
5526 | ||
5527 | /* | |
5528 | * Writing any value to intr-mbox-0 clears PCI INTA# and | |
5529 | * chip-internal interrupt pending events. | |
5530 | * Writing non-zero to intr-mbox-0 additional tells the | |
5531 | * NIC to stop sending us irqs, engaging "in-intr-handler" | |
5532 | * event coalescing. | |
c04cb347 MC |
5533 | * |
5534 | * Flush the mailbox to de-assert the IRQ immediately to prevent | |
5535 | * spurious interrupts. The flush impacts performance but | |
5536 | * excessive spurious interrupts can be worse in some cases. | |
d18edcb2 | 5537 | */ |
c04cb347 | 5538 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
d18edcb2 MC |
5539 | if (tg3_irq_sync(tp)) |
5540 | goto out; | |
5541 | sblk->status &= ~SD_STATUS_UPDATED; | |
17375d25 | 5542 | if (likely(tg3_has_work(tnapi))) { |
72334482 | 5543 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
09943a18 | 5544 | napi_schedule(&tnapi->napi); |
d18edcb2 MC |
5545 | } else { |
5546 | /* No work, shared interrupt perhaps? re-enable | |
5547 | * interrupts, and flush that PCI write | |
5548 | */ | |
5549 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, | |
5550 | 0x00000000); | |
fac9b83e | 5551 | } |
f47c11ee | 5552 | out: |
fac9b83e DM |
5553 | return IRQ_RETVAL(handled); |
5554 | } | |
5555 | ||
7d12e780 | 5556 | static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id) |
fac9b83e | 5557 | { |
09943a18 MC |
5558 | struct tg3_napi *tnapi = dev_id; |
5559 | struct tg3 *tp = tnapi->tp; | |
898a56f8 | 5560 | struct tg3_hw_status *sblk = tnapi->hw_status; |
fac9b83e DM |
5561 | unsigned int handled = 1; |
5562 | ||
fac9b83e DM |
5563 | /* In INTx mode, it is possible for the interrupt to arrive at |
5564 | * the CPU before the status block posted prior to the interrupt. | |
5565 | * Reading the PCI State register will confirm whether the | |
5566 | * interrupt is ours and will flush the status block. | |
5567 | */ | |
898a56f8 | 5568 | if (unlikely(sblk->status_tag == tnapi->last_irq_tag)) { |
63c3a66f | 5569 | if (tg3_flag(tp, CHIP_RESETTING) || |
d18edcb2 MC |
5570 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
5571 | handled = 0; | |
f47c11ee | 5572 | goto out; |
1da177e4 | 5573 | } |
d18edcb2 MC |
5574 | } |
5575 | ||
5576 | /* | |
5577 | * writing any value to intr-mbox-0 clears PCI INTA# and | |
5578 | * chip-internal interrupt pending events. | |
5579 | * writing non-zero to intr-mbox-0 additional tells the | |
5580 | * NIC to stop sending us irqs, engaging "in-intr-handler" | |
5581 | * event coalescing. | |
c04cb347 MC |
5582 | * |
5583 | * Flush the mailbox to de-assert the IRQ immediately to prevent | |
5584 | * spurious interrupts. The flush impacts performance but | |
5585 | * excessive spurious interrupts can be worse in some cases. | |
d18edcb2 | 5586 | */ |
c04cb347 | 5587 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
624f8e50 MC |
5588 | |
5589 | /* | |
5590 | * In a shared interrupt configuration, sometimes other devices' | |
5591 | * interrupts will scream. We record the current status tag here | |
5592 | * so that the above check can report that the screaming interrupts | |
5593 | * are unhandled. Eventually they will be silenced. | |
5594 | */ | |
898a56f8 | 5595 | tnapi->last_irq_tag = sblk->status_tag; |
624f8e50 | 5596 | |
d18edcb2 MC |
5597 | if (tg3_irq_sync(tp)) |
5598 | goto out; | |
624f8e50 | 5599 | |
72334482 | 5600 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
624f8e50 | 5601 | |
09943a18 | 5602 | napi_schedule(&tnapi->napi); |
624f8e50 | 5603 | |
f47c11ee | 5604 | out: |
1da177e4 LT |
5605 | return IRQ_RETVAL(handled); |
5606 | } | |
5607 | ||
7938109f | 5608 | /* ISR for interrupt test */ |
7d12e780 | 5609 | static irqreturn_t tg3_test_isr(int irq, void *dev_id) |
7938109f | 5610 | { |
09943a18 MC |
5611 | struct tg3_napi *tnapi = dev_id; |
5612 | struct tg3 *tp = tnapi->tp; | |
898a56f8 | 5613 | struct tg3_hw_status *sblk = tnapi->hw_status; |
7938109f | 5614 | |
f9804ddb MC |
5615 | if ((sblk->status & SD_STATUS_UPDATED) || |
5616 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { | |
b16250e3 | 5617 | tg3_disable_ints(tp); |
7938109f MC |
5618 | return IRQ_RETVAL(1); |
5619 | } | |
5620 | return IRQ_RETVAL(0); | |
5621 | } | |
5622 | ||
8e7a22e3 | 5623 | static int tg3_init_hw(struct tg3 *, int); |
944d980e | 5624 | static int tg3_halt(struct tg3 *, int, int); |
1da177e4 | 5625 | |
b9ec6c1b MC |
5626 | /* Restart hardware after configuration changes, self-test, etc. |
5627 | * Invoked with tp->lock held. | |
5628 | */ | |
5629 | static int tg3_restart_hw(struct tg3 *tp, int reset_phy) | |
78c6146f ED |
5630 | __releases(tp->lock) |
5631 | __acquires(tp->lock) | |
b9ec6c1b MC |
5632 | { |
5633 | int err; | |
5634 | ||
5635 | err = tg3_init_hw(tp, reset_phy); | |
5636 | if (err) { | |
5129c3a3 MC |
5637 | netdev_err(tp->dev, |
5638 | "Failed to re-initialize device, aborting\n"); | |
b9ec6c1b MC |
5639 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
5640 | tg3_full_unlock(tp); | |
5641 | del_timer_sync(&tp->timer); | |
5642 | tp->irq_sync = 0; | |
fed97810 | 5643 | tg3_napi_enable(tp); |
b9ec6c1b MC |
5644 | dev_close(tp->dev); |
5645 | tg3_full_lock(tp, 0); | |
5646 | } | |
5647 | return err; | |
5648 | } | |
5649 | ||
1da177e4 LT |
5650 | #ifdef CONFIG_NET_POLL_CONTROLLER |
5651 | static void tg3_poll_controller(struct net_device *dev) | |
5652 | { | |
4f125f42 | 5653 | int i; |
88b06bc2 MC |
5654 | struct tg3 *tp = netdev_priv(dev); |
5655 | ||
4f125f42 | 5656 | for (i = 0; i < tp->irq_cnt; i++) |
fe234f0e | 5657 | tg3_interrupt(tp->napi[i].irq_vec, &tp->napi[i]); |
1da177e4 LT |
5658 | } |
5659 | #endif | |
5660 | ||
c4028958 | 5661 | static void tg3_reset_task(struct work_struct *work) |
1da177e4 | 5662 | { |
c4028958 | 5663 | struct tg3 *tp = container_of(work, struct tg3, reset_task); |
b02fd9e3 | 5664 | int err; |
1da177e4 LT |
5665 | unsigned int restart_timer; |
5666 | ||
7faa006f | 5667 | tg3_full_lock(tp, 0); |
7faa006f MC |
5668 | |
5669 | if (!netif_running(tp->dev)) { | |
7faa006f MC |
5670 | tg3_full_unlock(tp); |
5671 | return; | |
5672 | } | |
5673 | ||
5674 | tg3_full_unlock(tp); | |
5675 | ||
b02fd9e3 MC |
5676 | tg3_phy_stop(tp); |
5677 | ||
1da177e4 LT |
5678 | tg3_netif_stop(tp); |
5679 | ||
f47c11ee | 5680 | tg3_full_lock(tp, 1); |
1da177e4 | 5681 | |
63c3a66f JP |
5682 | restart_timer = tg3_flag(tp, RESTART_TIMER); |
5683 | tg3_flag_clear(tp, RESTART_TIMER); | |
1da177e4 | 5684 | |
63c3a66f | 5685 | if (tg3_flag(tp, TX_RECOVERY_PENDING)) { |
df3e6548 MC |
5686 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
5687 | tp->write32_rx_mbox = tg3_write_flush_reg32; | |
63c3a66f JP |
5688 | tg3_flag_set(tp, MBOX_WRITE_REORDER); |
5689 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); | |
df3e6548 MC |
5690 | } |
5691 | ||
944d980e | 5692 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
b02fd9e3 MC |
5693 | err = tg3_init_hw(tp, 1); |
5694 | if (err) | |
b9ec6c1b | 5695 | goto out; |
1da177e4 LT |
5696 | |
5697 | tg3_netif_start(tp); | |
5698 | ||
1da177e4 LT |
5699 | if (restart_timer) |
5700 | mod_timer(&tp->timer, jiffies + 1); | |
7faa006f | 5701 | |
b9ec6c1b | 5702 | out: |
7faa006f | 5703 | tg3_full_unlock(tp); |
b02fd9e3 MC |
5704 | |
5705 | if (!err) | |
5706 | tg3_phy_start(tp); | |
1da177e4 LT |
5707 | } |
5708 | ||
5709 | static void tg3_tx_timeout(struct net_device *dev) | |
5710 | { | |
5711 | struct tg3 *tp = netdev_priv(dev); | |
5712 | ||
b0408751 | 5713 | if (netif_msg_tx_err(tp)) { |
05dbe005 | 5714 | netdev_err(dev, "transmit timed out, resetting\n"); |
97bd8e49 | 5715 | tg3_dump_state(tp); |
b0408751 | 5716 | } |
1da177e4 LT |
5717 | |
5718 | schedule_work(&tp->reset_task); | |
5719 | } | |
5720 | ||
c58ec932 MC |
5721 | /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */ |
5722 | static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len) | |
5723 | { | |
5724 | u32 base = (u32) mapping & 0xffffffff; | |
5725 | ||
807540ba | 5726 | return (base > 0xffffdcc0) && (base + len + 8 < base); |
c58ec932 MC |
5727 | } |
5728 | ||
72f2afb8 MC |
5729 | /* Test for DMA addresses > 40-bit */ |
5730 | static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping, | |
5731 | int len) | |
5732 | { | |
5733 | #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64) | |
63c3a66f | 5734 | if (tg3_flag(tp, 40BIT_DMA_BUG)) |
807540ba | 5735 | return ((u64) mapping + len) > DMA_BIT_MASK(40); |
72f2afb8 MC |
5736 | return 0; |
5737 | #else | |
5738 | return 0; | |
5739 | #endif | |
5740 | } | |
5741 | ||
2ffcc981 MC |
5742 | static void tg3_set_txd(struct tg3_napi *tnapi, int entry, |
5743 | dma_addr_t mapping, int len, u32 flags, | |
5744 | u32 mss_and_is_end) | |
5745 | { | |
5746 | struct tg3_tx_buffer_desc *txd = &tnapi->tx_ring[entry]; | |
5747 | int is_end = (mss_and_is_end & 0x1); | |
5748 | u32 mss = (mss_and_is_end >> 1); | |
5749 | u32 vlan_tag = 0; | |
5750 | ||
5751 | if (is_end) | |
5752 | flags |= TXD_FLAG_END; | |
5753 | if (flags & TXD_FLAG_VLAN) { | |
5754 | vlan_tag = flags >> 16; | |
5755 | flags &= 0xffff; | |
5756 | } | |
5757 | vlan_tag |= (mss << TXD_MSS_SHIFT); | |
5758 | ||
5759 | txd->addr_hi = ((u64) mapping >> 32); | |
5760 | txd->addr_lo = ((u64) mapping & 0xffffffff); | |
5761 | txd->len_flags = (len << TXD_LEN_SHIFT) | flags; | |
5762 | txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT; | |
5763 | } | |
1da177e4 | 5764 | |
432aa7ed MC |
5765 | static void tg3_skb_error_unmap(struct tg3_napi *tnapi, |
5766 | struct sk_buff *skb, int last) | |
5767 | { | |
5768 | int i; | |
5769 | u32 entry = tnapi->tx_prod; | |
5770 | struct ring_info *txb = &tnapi->tx_buffers[entry]; | |
5771 | ||
5772 | pci_unmap_single(tnapi->tp->pdev, | |
5773 | dma_unmap_addr(txb, mapping), | |
5774 | skb_headlen(skb), | |
5775 | PCI_DMA_TODEVICE); | |
5776 | for (i = 0; i <= last; i++) { | |
5777 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | |
5778 | ||
5779 | entry = NEXT_TX(entry); | |
5780 | txb = &tnapi->tx_buffers[entry]; | |
5781 | ||
5782 | pci_unmap_page(tnapi->tp->pdev, | |
5783 | dma_unmap_addr(txb, mapping), | |
5784 | frag->size, PCI_DMA_TODEVICE); | |
5785 | } | |
5786 | } | |
5787 | ||
72f2afb8 | 5788 | /* Workaround 4GB and 40-bit hardware DMA bugs. */ |
24f4efd4 | 5789 | static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi, |
432aa7ed MC |
5790 | struct sk_buff *skb, |
5791 | u32 base_flags, u32 mss) | |
1da177e4 | 5792 | { |
24f4efd4 | 5793 | struct tg3 *tp = tnapi->tp; |
41588ba1 | 5794 | struct sk_buff *new_skb; |
c58ec932 | 5795 | dma_addr_t new_addr = 0; |
432aa7ed MC |
5796 | u32 entry = tnapi->tx_prod; |
5797 | int ret = 0; | |
1da177e4 | 5798 | |
41588ba1 MC |
5799 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
5800 | new_skb = skb_copy(skb, GFP_ATOMIC); | |
5801 | else { | |
5802 | int more_headroom = 4 - ((unsigned long)skb->data & 3); | |
5803 | ||
5804 | new_skb = skb_copy_expand(skb, | |
5805 | skb_headroom(skb) + more_headroom, | |
5806 | skb_tailroom(skb), GFP_ATOMIC); | |
5807 | } | |
5808 | ||
1da177e4 | 5809 | if (!new_skb) { |
c58ec932 MC |
5810 | ret = -1; |
5811 | } else { | |
5812 | /* New SKB is guaranteed to be linear. */ | |
f4188d8a AD |
5813 | new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len, |
5814 | PCI_DMA_TODEVICE); | |
5815 | /* Make sure the mapping succeeded */ | |
5816 | if (pci_dma_mapping_error(tp->pdev, new_addr)) { | |
5817 | ret = -1; | |
5818 | dev_kfree_skb(new_skb); | |
90079ce8 | 5819 | |
c58ec932 MC |
5820 | /* Make sure new skb does not cross any 4G boundaries. |
5821 | * Drop the packet if it does. | |
5822 | */ | |
63c3a66f JP |
5823 | } else if (tg3_flag(tp, 4G_DMA_BNDRY_BUG) && |
5824 | tg3_4g_overflow_test(new_addr, new_skb->len)) { | |
f4188d8a AD |
5825 | pci_unmap_single(tp->pdev, new_addr, new_skb->len, |
5826 | PCI_DMA_TODEVICE); | |
c58ec932 MC |
5827 | ret = -1; |
5828 | dev_kfree_skb(new_skb); | |
c58ec932 | 5829 | } else { |
432aa7ed MC |
5830 | tnapi->tx_buffers[entry].skb = new_skb; |
5831 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], | |
5832 | mapping, new_addr); | |
5833 | ||
f3f3f27e | 5834 | tg3_set_txd(tnapi, entry, new_addr, new_skb->len, |
c58ec932 | 5835 | base_flags, 1 | (mss << 1)); |
f4188d8a | 5836 | } |
1da177e4 LT |
5837 | } |
5838 | ||
5839 | dev_kfree_skb(skb); | |
5840 | ||
c58ec932 | 5841 | return ret; |
1da177e4 LT |
5842 | } |
5843 | ||
2ffcc981 | 5844 | static netdev_tx_t tg3_start_xmit(struct sk_buff *, struct net_device *); |
52c0fd83 MC |
5845 | |
5846 | /* Use GSO to workaround a rare TSO bug that may be triggered when the | |
5847 | * TSO header is greater than 80 bytes. | |
5848 | */ | |
5849 | static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb) | |
5850 | { | |
5851 | struct sk_buff *segs, *nskb; | |
f3f3f27e | 5852 | u32 frag_cnt_est = skb_shinfo(skb)->gso_segs * 3; |
52c0fd83 MC |
5853 | |
5854 | /* Estimate the number of fragments in the worst case */ | |
f3f3f27e | 5855 | if (unlikely(tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est)) { |
52c0fd83 | 5856 | netif_stop_queue(tp->dev); |
f65aac16 MC |
5857 | |
5858 | /* netif_tx_stop_queue() must be done before checking | |
5859 | * checking tx index in tg3_tx_avail() below, because in | |
5860 | * tg3_tx(), we update tx index before checking for | |
5861 | * netif_tx_queue_stopped(). | |
5862 | */ | |
5863 | smp_mb(); | |
f3f3f27e | 5864 | if (tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est) |
7f62ad5d MC |
5865 | return NETDEV_TX_BUSY; |
5866 | ||
5867 | netif_wake_queue(tp->dev); | |
52c0fd83 MC |
5868 | } |
5869 | ||
5870 | segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO); | |
801678c5 | 5871 | if (IS_ERR(segs)) |
52c0fd83 MC |
5872 | goto tg3_tso_bug_end; |
5873 | ||
5874 | do { | |
5875 | nskb = segs; | |
5876 | segs = segs->next; | |
5877 | nskb->next = NULL; | |
2ffcc981 | 5878 | tg3_start_xmit(nskb, tp->dev); |
52c0fd83 MC |
5879 | } while (segs); |
5880 | ||
5881 | tg3_tso_bug_end: | |
5882 | dev_kfree_skb(skb); | |
5883 | ||
5884 | return NETDEV_TX_OK; | |
5885 | } | |
52c0fd83 | 5886 | |
5a6f3074 | 5887 | /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and |
63c3a66f | 5888 | * support TG3_FLAG_HW_TSO_1 or firmware TSO only. |
5a6f3074 | 5889 | */ |
2ffcc981 | 5890 | static netdev_tx_t tg3_start_xmit(struct sk_buff *skb, struct net_device *dev) |
1da177e4 LT |
5891 | { |
5892 | struct tg3 *tp = netdev_priv(dev); | |
1da177e4 | 5893 | u32 len, entry, base_flags, mss; |
432aa7ed | 5894 | int i = -1, would_hit_hwbug; |
90079ce8 | 5895 | dma_addr_t mapping; |
24f4efd4 MC |
5896 | struct tg3_napi *tnapi; |
5897 | struct netdev_queue *txq; | |
432aa7ed | 5898 | unsigned int last; |
f4188d8a | 5899 | |
24f4efd4 MC |
5900 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
5901 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; | |
63c3a66f | 5902 | if (tg3_flag(tp, ENABLE_TSS)) |
24f4efd4 | 5903 | tnapi++; |
1da177e4 | 5904 | |
00b70504 | 5905 | /* We are running in BH disabled context with netif_tx_lock |
bea3348e | 5906 | * and TX reclaim runs via tp->napi.poll inside of a software |
f47c11ee DM |
5907 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
5908 | * no IRQ context deadlocks to worry about either. Rejoice! | |
1da177e4 | 5909 | */ |
f3f3f27e | 5910 | if (unlikely(tg3_tx_avail(tnapi) <= (skb_shinfo(skb)->nr_frags + 1))) { |
24f4efd4 MC |
5911 | if (!netif_tx_queue_stopped(txq)) { |
5912 | netif_tx_stop_queue(txq); | |
1f064a87 SH |
5913 | |
5914 | /* This is a hard error, log it. */ | |
5129c3a3 MC |
5915 | netdev_err(dev, |
5916 | "BUG! Tx Ring full when queue awake!\n"); | |
1f064a87 | 5917 | } |
1da177e4 LT |
5918 | return NETDEV_TX_BUSY; |
5919 | } | |
5920 | ||
f3f3f27e | 5921 | entry = tnapi->tx_prod; |
1da177e4 | 5922 | base_flags = 0; |
84fa7933 | 5923 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
1da177e4 | 5924 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
24f4efd4 | 5925 | |
be98da6a MC |
5926 | mss = skb_shinfo(skb)->gso_size; |
5927 | if (mss) { | |
eddc9ec5 | 5928 | struct iphdr *iph; |
34195c3d | 5929 | u32 tcp_opt_len, hdr_len; |
1da177e4 LT |
5930 | |
5931 | if (skb_header_cloned(skb) && | |
5932 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) { | |
5933 | dev_kfree_skb(skb); | |
5934 | goto out_unlock; | |
5935 | } | |
5936 | ||
34195c3d | 5937 | iph = ip_hdr(skb); |
ab6a5bb6 | 5938 | tcp_opt_len = tcp_optlen(skb); |
1da177e4 | 5939 | |
02e96080 | 5940 | if (skb_is_gso_v6(skb)) { |
34195c3d MC |
5941 | hdr_len = skb_headlen(skb) - ETH_HLEN; |
5942 | } else { | |
5943 | u32 ip_tcp_len; | |
5944 | ||
5945 | ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr); | |
5946 | hdr_len = ip_tcp_len + tcp_opt_len; | |
5947 | ||
5948 | iph->check = 0; | |
5949 | iph->tot_len = htons(mss + hdr_len); | |
5950 | } | |
5951 | ||
52c0fd83 | 5952 | if (unlikely((ETH_HLEN + hdr_len) > 80) && |
63c3a66f | 5953 | tg3_flag(tp, TSO_BUG)) |
de6f31eb | 5954 | return tg3_tso_bug(tp, skb); |
52c0fd83 | 5955 | |
1da177e4 LT |
5956 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
5957 | TXD_FLAG_CPU_POST_DMA); | |
5958 | ||
63c3a66f JP |
5959 | if (tg3_flag(tp, HW_TSO_1) || |
5960 | tg3_flag(tp, HW_TSO_2) || | |
5961 | tg3_flag(tp, HW_TSO_3)) { | |
aa8223c7 | 5962 | tcp_hdr(skb)->check = 0; |
1da177e4 | 5963 | base_flags &= ~TXD_FLAG_TCPUDP_CSUM; |
aa8223c7 ACM |
5964 | } else |
5965 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, | |
5966 | iph->daddr, 0, | |
5967 | IPPROTO_TCP, | |
5968 | 0); | |
1da177e4 | 5969 | |
63c3a66f | 5970 | if (tg3_flag(tp, HW_TSO_3)) { |
615774fe MC |
5971 | mss |= (hdr_len & 0xc) << 12; |
5972 | if (hdr_len & 0x10) | |
5973 | base_flags |= 0x00000010; | |
5974 | base_flags |= (hdr_len & 0x3e0) << 5; | |
63c3a66f | 5975 | } else if (tg3_flag(tp, HW_TSO_2)) |
92c6b8d1 | 5976 | mss |= hdr_len << 9; |
63c3a66f | 5977 | else if (tg3_flag(tp, HW_TSO_1) || |
92c6b8d1 | 5978 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
eddc9ec5 | 5979 | if (tcp_opt_len || iph->ihl > 5) { |
1da177e4 LT |
5980 | int tsflags; |
5981 | ||
eddc9ec5 | 5982 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
1da177e4 LT |
5983 | mss |= (tsflags << 11); |
5984 | } | |
5985 | } else { | |
eddc9ec5 | 5986 | if (tcp_opt_len || iph->ihl > 5) { |
1da177e4 LT |
5987 | int tsflags; |
5988 | ||
eddc9ec5 | 5989 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
1da177e4 LT |
5990 | base_flags |= tsflags << 12; |
5991 | } | |
5992 | } | |
5993 | } | |
bf933c80 | 5994 | |
eab6d18d | 5995 | if (vlan_tx_tag_present(skb)) |
1da177e4 LT |
5996 | base_flags |= (TXD_FLAG_VLAN | |
5997 | (vlan_tx_tag_get(skb) << 16)); | |
1da177e4 | 5998 | |
63c3a66f | 5999 | if (tg3_flag(tp, USE_JUMBO_BDFLAG) && |
8fc2f995 | 6000 | !mss && skb->len > VLAN_ETH_FRAME_LEN) |
615774fe MC |
6001 | base_flags |= TXD_FLAG_JMB_PKT; |
6002 | ||
f4188d8a AD |
6003 | len = skb_headlen(skb); |
6004 | ||
6005 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); | |
6006 | if (pci_dma_mapping_error(tp->pdev, mapping)) { | |
90079ce8 DM |
6007 | dev_kfree_skb(skb); |
6008 | goto out_unlock; | |
6009 | } | |
6010 | ||
f3f3f27e | 6011 | tnapi->tx_buffers[entry].skb = skb; |
4e5e4f0d | 6012 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
1da177e4 LT |
6013 | |
6014 | would_hit_hwbug = 0; | |
6015 | ||
63c3a66f | 6016 | if (tg3_flag(tp, SHORT_DMA_BUG) && len <= 8) |
92c6b8d1 MC |
6017 | would_hit_hwbug = 1; |
6018 | ||
63c3a66f | 6019 | if (tg3_flag(tp, 4G_DMA_BNDRY_BUG) && |
0e1406dd MC |
6020 | tg3_4g_overflow_test(mapping, len)) |
6021 | would_hit_hwbug = 1; | |
6022 | ||
63c3a66f | 6023 | if (tg3_flag(tp, 40BIT_DMA_LIMIT_BUG) && |
0e1406dd | 6024 | tg3_40bit_overflow_test(tp, mapping, len)) |
41588ba1 | 6025 | would_hit_hwbug = 1; |
0e1406dd | 6026 | |
63c3a66f | 6027 | if (tg3_flag(tp, 5701_DMA_BUG)) |
c58ec932 | 6028 | would_hit_hwbug = 1; |
1da177e4 | 6029 | |
f3f3f27e | 6030 | tg3_set_txd(tnapi, entry, mapping, len, base_flags, |
1da177e4 LT |
6031 | (skb_shinfo(skb)->nr_frags == 0) | (mss << 1)); |
6032 | ||
6033 | entry = NEXT_TX(entry); | |
6034 | ||
6035 | /* Now loop through additional data fragments, and queue them. */ | |
6036 | if (skb_shinfo(skb)->nr_frags > 0) { | |
1da177e4 LT |
6037 | last = skb_shinfo(skb)->nr_frags - 1; |
6038 | for (i = 0; i <= last; i++) { | |
6039 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | |
6040 | ||
6041 | len = frag->size; | |
f4188d8a AD |
6042 | mapping = pci_map_page(tp->pdev, |
6043 | frag->page, | |
6044 | frag->page_offset, | |
6045 | len, PCI_DMA_TODEVICE); | |
1da177e4 | 6046 | |
f3f3f27e | 6047 | tnapi->tx_buffers[entry].skb = NULL; |
4e5e4f0d | 6048 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
f4188d8a AD |
6049 | mapping); |
6050 | if (pci_dma_mapping_error(tp->pdev, mapping)) | |
6051 | goto dma_error; | |
1da177e4 | 6052 | |
63c3a66f | 6053 | if (tg3_flag(tp, SHORT_DMA_BUG) && |
92c6b8d1 MC |
6054 | len <= 8) |
6055 | would_hit_hwbug = 1; | |
6056 | ||
63c3a66f | 6057 | if (tg3_flag(tp, 4G_DMA_BNDRY_BUG) && |
0e1406dd | 6058 | tg3_4g_overflow_test(mapping, len)) |
c58ec932 | 6059 | would_hit_hwbug = 1; |
1da177e4 | 6060 | |
63c3a66f | 6061 | if (tg3_flag(tp, 40BIT_DMA_LIMIT_BUG) && |
0e1406dd | 6062 | tg3_40bit_overflow_test(tp, mapping, len)) |
72f2afb8 MC |
6063 | would_hit_hwbug = 1; |
6064 | ||
63c3a66f JP |
6065 | if (tg3_flag(tp, HW_TSO_1) || |
6066 | tg3_flag(tp, HW_TSO_2) || | |
6067 | tg3_flag(tp, HW_TSO_3)) | |
f3f3f27e | 6068 | tg3_set_txd(tnapi, entry, mapping, len, |
1da177e4 LT |
6069 | base_flags, (i == last)|(mss << 1)); |
6070 | else | |
f3f3f27e | 6071 | tg3_set_txd(tnapi, entry, mapping, len, |
1da177e4 LT |
6072 | base_flags, (i == last)); |
6073 | ||
6074 | entry = NEXT_TX(entry); | |
6075 | } | |
6076 | } | |
6077 | ||
6078 | if (would_hit_hwbug) { | |
432aa7ed | 6079 | tg3_skb_error_unmap(tnapi, skb, i); |
1da177e4 LT |
6080 | |
6081 | /* If the workaround fails due to memory/mapping | |
6082 | * failure, silently drop this packet. | |
6083 | */ | |
432aa7ed | 6084 | if (tigon3_dma_hwbug_workaround(tnapi, skb, base_flags, mss)) |
1da177e4 LT |
6085 | goto out_unlock; |
6086 | ||
432aa7ed | 6087 | entry = NEXT_TX(tnapi->tx_prod); |
1da177e4 LT |
6088 | } |
6089 | ||
6090 | /* Packets are ready, update Tx producer idx local and on card. */ | |
24f4efd4 | 6091 | tw32_tx_mbox(tnapi->prodmbox, entry); |
1da177e4 | 6092 | |
f3f3f27e MC |
6093 | tnapi->tx_prod = entry; |
6094 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { | |
24f4efd4 | 6095 | netif_tx_stop_queue(txq); |
f65aac16 MC |
6096 | |
6097 | /* netif_tx_stop_queue() must be done before checking | |
6098 | * checking tx index in tg3_tx_avail() below, because in | |
6099 | * tg3_tx(), we update tx index before checking for | |
6100 | * netif_tx_queue_stopped(). | |
6101 | */ | |
6102 | smp_mb(); | |
f3f3f27e | 6103 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
24f4efd4 | 6104 | netif_tx_wake_queue(txq); |
51b91468 | 6105 | } |
1da177e4 LT |
6106 | |
6107 | out_unlock: | |
cdd0db05 | 6108 | mmiowb(); |
1da177e4 LT |
6109 | |
6110 | return NETDEV_TX_OK; | |
f4188d8a AD |
6111 | |
6112 | dma_error: | |
432aa7ed | 6113 | tg3_skb_error_unmap(tnapi, skb, i); |
f4188d8a | 6114 | dev_kfree_skb(skb); |
432aa7ed | 6115 | tnapi->tx_buffers[tnapi->tx_prod].skb = NULL; |
f4188d8a | 6116 | return NETDEV_TX_OK; |
1da177e4 LT |
6117 | } |
6118 | ||
06c03c02 MB |
6119 | static void tg3_set_loopback(struct net_device *dev, u32 features) |
6120 | { | |
6121 | struct tg3 *tp = netdev_priv(dev); | |
6122 | ||
6123 | if (features & NETIF_F_LOOPBACK) { | |
6124 | if (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK) | |
6125 | return; | |
6126 | ||
6127 | /* | |
6128 | * Clear MAC_MODE_HALF_DUPLEX or you won't get packets back in | |
6129 | * loopback mode if Half-Duplex mode was negotiated earlier. | |
6130 | */ | |
6131 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; | |
6132 | ||
6133 | /* Enable internal MAC loopback mode */ | |
6134 | tp->mac_mode |= MAC_MODE_PORT_INT_LPBACK; | |
6135 | spin_lock_bh(&tp->lock); | |
6136 | tw32(MAC_MODE, tp->mac_mode); | |
6137 | netif_carrier_on(tp->dev); | |
6138 | spin_unlock_bh(&tp->lock); | |
6139 | netdev_info(dev, "Internal MAC loopback mode enabled.\n"); | |
6140 | } else { | |
6141 | if (!(tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) | |
6142 | return; | |
6143 | ||
6144 | /* Disable internal MAC loopback mode */ | |
6145 | tp->mac_mode &= ~MAC_MODE_PORT_INT_LPBACK; | |
6146 | spin_lock_bh(&tp->lock); | |
6147 | tw32(MAC_MODE, tp->mac_mode); | |
6148 | /* Force link status check */ | |
6149 | tg3_setup_phy(tp, 1); | |
6150 | spin_unlock_bh(&tp->lock); | |
6151 | netdev_info(dev, "Internal MAC loopback mode disabled.\n"); | |
6152 | } | |
6153 | } | |
6154 | ||
dc668910 MM |
6155 | static u32 tg3_fix_features(struct net_device *dev, u32 features) |
6156 | { | |
6157 | struct tg3 *tp = netdev_priv(dev); | |
6158 | ||
63c3a66f | 6159 | if (dev->mtu > ETH_DATA_LEN && tg3_flag(tp, 5780_CLASS)) |
dc668910 MM |
6160 | features &= ~NETIF_F_ALL_TSO; |
6161 | ||
6162 | return features; | |
6163 | } | |
6164 | ||
06c03c02 MB |
6165 | static int tg3_set_features(struct net_device *dev, u32 features) |
6166 | { | |
6167 | u32 changed = dev->features ^ features; | |
6168 | ||
6169 | if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) | |
6170 | tg3_set_loopback(dev, features); | |
6171 | ||
6172 | return 0; | |
6173 | } | |
6174 | ||
1da177e4 LT |
6175 | static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp, |
6176 | int new_mtu) | |
6177 | { | |
6178 | dev->mtu = new_mtu; | |
6179 | ||
ef7f5ec0 | 6180 | if (new_mtu > ETH_DATA_LEN) { |
63c3a66f | 6181 | if (tg3_flag(tp, 5780_CLASS)) { |
dc668910 | 6182 | netdev_update_features(dev); |
63c3a66f | 6183 | tg3_flag_clear(tp, TSO_CAPABLE); |
859a5887 | 6184 | } else { |
63c3a66f | 6185 | tg3_flag_set(tp, JUMBO_RING_ENABLE); |
859a5887 | 6186 | } |
ef7f5ec0 | 6187 | } else { |
63c3a66f JP |
6188 | if (tg3_flag(tp, 5780_CLASS)) { |
6189 | tg3_flag_set(tp, TSO_CAPABLE); | |
dc668910 MM |
6190 | netdev_update_features(dev); |
6191 | } | |
63c3a66f | 6192 | tg3_flag_clear(tp, JUMBO_RING_ENABLE); |
ef7f5ec0 | 6193 | } |
1da177e4 LT |
6194 | } |
6195 | ||
6196 | static int tg3_change_mtu(struct net_device *dev, int new_mtu) | |
6197 | { | |
6198 | struct tg3 *tp = netdev_priv(dev); | |
b9ec6c1b | 6199 | int err; |
1da177e4 LT |
6200 | |
6201 | if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp)) | |
6202 | return -EINVAL; | |
6203 | ||
6204 | if (!netif_running(dev)) { | |
6205 | /* We'll just catch it later when the | |
6206 | * device is up'd. | |
6207 | */ | |
6208 | tg3_set_mtu(dev, tp, new_mtu); | |
6209 | return 0; | |
6210 | } | |
6211 | ||
b02fd9e3 MC |
6212 | tg3_phy_stop(tp); |
6213 | ||
1da177e4 | 6214 | tg3_netif_stop(tp); |
f47c11ee DM |
6215 | |
6216 | tg3_full_lock(tp, 1); | |
1da177e4 | 6217 | |
944d980e | 6218 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
1da177e4 LT |
6219 | |
6220 | tg3_set_mtu(dev, tp, new_mtu); | |
6221 | ||
b9ec6c1b | 6222 | err = tg3_restart_hw(tp, 0); |
1da177e4 | 6223 | |
b9ec6c1b MC |
6224 | if (!err) |
6225 | tg3_netif_start(tp); | |
1da177e4 | 6226 | |
f47c11ee | 6227 | tg3_full_unlock(tp); |
1da177e4 | 6228 | |
b02fd9e3 MC |
6229 | if (!err) |
6230 | tg3_phy_start(tp); | |
6231 | ||
b9ec6c1b | 6232 | return err; |
1da177e4 LT |
6233 | } |
6234 | ||
21f581a5 MC |
6235 | static void tg3_rx_prodring_free(struct tg3 *tp, |
6236 | struct tg3_rx_prodring_set *tpr) | |
1da177e4 | 6237 | { |
1da177e4 LT |
6238 | int i; |
6239 | ||
8fea32b9 | 6240 | if (tpr != &tp->napi[0].prodring) { |
b196c7e4 | 6241 | for (i = tpr->rx_std_cons_idx; i != tpr->rx_std_prod_idx; |
2c49a44d | 6242 | i = (i + 1) & tp->rx_std_ring_mask) |
b196c7e4 MC |
6243 | tg3_rx_skb_free(tp, &tpr->rx_std_buffers[i], |
6244 | tp->rx_pkt_map_sz); | |
6245 | ||
63c3a66f | 6246 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
b196c7e4 MC |
6247 | for (i = tpr->rx_jmb_cons_idx; |
6248 | i != tpr->rx_jmb_prod_idx; | |
2c49a44d | 6249 | i = (i + 1) & tp->rx_jmb_ring_mask) { |
b196c7e4 MC |
6250 | tg3_rx_skb_free(tp, &tpr->rx_jmb_buffers[i], |
6251 | TG3_RX_JMB_MAP_SZ); | |
6252 | } | |
6253 | } | |
6254 | ||
2b2cdb65 | 6255 | return; |
b196c7e4 | 6256 | } |
1da177e4 | 6257 | |
2c49a44d | 6258 | for (i = 0; i <= tp->rx_std_ring_mask; i++) |
2b2cdb65 MC |
6259 | tg3_rx_skb_free(tp, &tpr->rx_std_buffers[i], |
6260 | tp->rx_pkt_map_sz); | |
1da177e4 | 6261 | |
63c3a66f | 6262 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
2c49a44d | 6263 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) |
2b2cdb65 MC |
6264 | tg3_rx_skb_free(tp, &tpr->rx_jmb_buffers[i], |
6265 | TG3_RX_JMB_MAP_SZ); | |
1da177e4 LT |
6266 | } |
6267 | } | |
6268 | ||
c6cdf436 | 6269 | /* Initialize rx rings for packet processing. |
1da177e4 LT |
6270 | * |
6271 | * The chip has been shut down and the driver detached from | |
6272 | * the networking, so no interrupts or new tx packets will | |
6273 | * end up in the driver. tp->{tx,}lock are held and thus | |
6274 | * we may not sleep. | |
6275 | */ | |
21f581a5 MC |
6276 | static int tg3_rx_prodring_alloc(struct tg3 *tp, |
6277 | struct tg3_rx_prodring_set *tpr) | |
1da177e4 | 6278 | { |
287be12e | 6279 | u32 i, rx_pkt_dma_sz; |
1da177e4 | 6280 | |
b196c7e4 MC |
6281 | tpr->rx_std_cons_idx = 0; |
6282 | tpr->rx_std_prod_idx = 0; | |
6283 | tpr->rx_jmb_cons_idx = 0; | |
6284 | tpr->rx_jmb_prod_idx = 0; | |
6285 | ||
8fea32b9 | 6286 | if (tpr != &tp->napi[0].prodring) { |
2c49a44d MC |
6287 | memset(&tpr->rx_std_buffers[0], 0, |
6288 | TG3_RX_STD_BUFF_RING_SIZE(tp)); | |
48035728 | 6289 | if (tpr->rx_jmb_buffers) |
2b2cdb65 | 6290 | memset(&tpr->rx_jmb_buffers[0], 0, |
2c49a44d | 6291 | TG3_RX_JMB_BUFF_RING_SIZE(tp)); |
2b2cdb65 MC |
6292 | goto done; |
6293 | } | |
6294 | ||
1da177e4 | 6295 | /* Zero out all descriptors. */ |
2c49a44d | 6296 | memset(tpr->rx_std, 0, TG3_RX_STD_RING_BYTES(tp)); |
1da177e4 | 6297 | |
287be12e | 6298 | rx_pkt_dma_sz = TG3_RX_STD_DMA_SZ; |
63c3a66f | 6299 | if (tg3_flag(tp, 5780_CLASS) && |
287be12e MC |
6300 | tp->dev->mtu > ETH_DATA_LEN) |
6301 | rx_pkt_dma_sz = TG3_RX_JMB_DMA_SZ; | |
6302 | tp->rx_pkt_map_sz = TG3_RX_DMA_TO_MAP_SZ(rx_pkt_dma_sz); | |
7e72aad4 | 6303 | |
1da177e4 LT |
6304 | /* Initialize invariants of the rings, we only set this |
6305 | * stuff once. This works because the card does not | |
6306 | * write into the rx buffer posting rings. | |
6307 | */ | |
2c49a44d | 6308 | for (i = 0; i <= tp->rx_std_ring_mask; i++) { |
1da177e4 LT |
6309 | struct tg3_rx_buffer_desc *rxd; |
6310 | ||
21f581a5 | 6311 | rxd = &tpr->rx_std[i]; |
287be12e | 6312 | rxd->idx_len = rx_pkt_dma_sz << RXD_LEN_SHIFT; |
1da177e4 LT |
6313 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT); |
6314 | rxd->opaque = (RXD_OPAQUE_RING_STD | | |
6315 | (i << RXD_OPAQUE_INDEX_SHIFT)); | |
6316 | } | |
6317 | ||
1da177e4 LT |
6318 | /* Now allocate fresh SKBs for each rx ring. */ |
6319 | for (i = 0; i < tp->rx_pending; i++) { | |
86b21e59 | 6320 | if (tg3_alloc_rx_skb(tp, tpr, RXD_OPAQUE_RING_STD, i) < 0) { |
5129c3a3 MC |
6321 | netdev_warn(tp->dev, |
6322 | "Using a smaller RX standard ring. Only " | |
6323 | "%d out of %d buffers were allocated " | |
6324 | "successfully\n", i, tp->rx_pending); | |
32d8c572 | 6325 | if (i == 0) |
cf7a7298 | 6326 | goto initfail; |
32d8c572 | 6327 | tp->rx_pending = i; |
1da177e4 | 6328 | break; |
32d8c572 | 6329 | } |
1da177e4 LT |
6330 | } |
6331 | ||
63c3a66f | 6332 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
cf7a7298 MC |
6333 | goto done; |
6334 | ||
2c49a44d | 6335 | memset(tpr->rx_jmb, 0, TG3_RX_JMB_RING_BYTES(tp)); |
cf7a7298 | 6336 | |
63c3a66f | 6337 | if (!tg3_flag(tp, JUMBO_RING_ENABLE)) |
0d86df80 | 6338 | goto done; |
cf7a7298 | 6339 | |
2c49a44d | 6340 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) { |
0d86df80 MC |
6341 | struct tg3_rx_buffer_desc *rxd; |
6342 | ||
6343 | rxd = &tpr->rx_jmb[i].std; | |
6344 | rxd->idx_len = TG3_RX_JMB_DMA_SZ << RXD_LEN_SHIFT; | |
6345 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) | | |
6346 | RXD_FLAG_JUMBO; | |
6347 | rxd->opaque = (RXD_OPAQUE_RING_JUMBO | | |
6348 | (i << RXD_OPAQUE_INDEX_SHIFT)); | |
6349 | } | |
6350 | ||
6351 | for (i = 0; i < tp->rx_jumbo_pending; i++) { | |
6352 | if (tg3_alloc_rx_skb(tp, tpr, RXD_OPAQUE_RING_JUMBO, i) < 0) { | |
5129c3a3 MC |
6353 | netdev_warn(tp->dev, |
6354 | "Using a smaller RX jumbo ring. Only %d " | |
6355 | "out of %d buffers were allocated " | |
6356 | "successfully\n", i, tp->rx_jumbo_pending); | |
0d86df80 MC |
6357 | if (i == 0) |
6358 | goto initfail; | |
6359 | tp->rx_jumbo_pending = i; | |
6360 | break; | |
1da177e4 LT |
6361 | } |
6362 | } | |
cf7a7298 MC |
6363 | |
6364 | done: | |
32d8c572 | 6365 | return 0; |
cf7a7298 MC |
6366 | |
6367 | initfail: | |
21f581a5 | 6368 | tg3_rx_prodring_free(tp, tpr); |
cf7a7298 | 6369 | return -ENOMEM; |
1da177e4 LT |
6370 | } |
6371 | ||
21f581a5 MC |
6372 | static void tg3_rx_prodring_fini(struct tg3 *tp, |
6373 | struct tg3_rx_prodring_set *tpr) | |
1da177e4 | 6374 | { |
21f581a5 MC |
6375 | kfree(tpr->rx_std_buffers); |
6376 | tpr->rx_std_buffers = NULL; | |
6377 | kfree(tpr->rx_jmb_buffers); | |
6378 | tpr->rx_jmb_buffers = NULL; | |
6379 | if (tpr->rx_std) { | |
4bae65c8 MC |
6380 | dma_free_coherent(&tp->pdev->dev, TG3_RX_STD_RING_BYTES(tp), |
6381 | tpr->rx_std, tpr->rx_std_mapping); | |
21f581a5 | 6382 | tpr->rx_std = NULL; |
1da177e4 | 6383 | } |
21f581a5 | 6384 | if (tpr->rx_jmb) { |
4bae65c8 MC |
6385 | dma_free_coherent(&tp->pdev->dev, TG3_RX_JMB_RING_BYTES(tp), |
6386 | tpr->rx_jmb, tpr->rx_jmb_mapping); | |
21f581a5 | 6387 | tpr->rx_jmb = NULL; |
1da177e4 | 6388 | } |
cf7a7298 MC |
6389 | } |
6390 | ||
21f581a5 MC |
6391 | static int tg3_rx_prodring_init(struct tg3 *tp, |
6392 | struct tg3_rx_prodring_set *tpr) | |
cf7a7298 | 6393 | { |
2c49a44d MC |
6394 | tpr->rx_std_buffers = kzalloc(TG3_RX_STD_BUFF_RING_SIZE(tp), |
6395 | GFP_KERNEL); | |
21f581a5 | 6396 | if (!tpr->rx_std_buffers) |
cf7a7298 MC |
6397 | return -ENOMEM; |
6398 | ||
4bae65c8 MC |
6399 | tpr->rx_std = dma_alloc_coherent(&tp->pdev->dev, |
6400 | TG3_RX_STD_RING_BYTES(tp), | |
6401 | &tpr->rx_std_mapping, | |
6402 | GFP_KERNEL); | |
21f581a5 | 6403 | if (!tpr->rx_std) |
cf7a7298 MC |
6404 | goto err_out; |
6405 | ||
63c3a66f | 6406 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
2c49a44d | 6407 | tpr->rx_jmb_buffers = kzalloc(TG3_RX_JMB_BUFF_RING_SIZE(tp), |
21f581a5 MC |
6408 | GFP_KERNEL); |
6409 | if (!tpr->rx_jmb_buffers) | |
cf7a7298 MC |
6410 | goto err_out; |
6411 | ||
4bae65c8 MC |
6412 | tpr->rx_jmb = dma_alloc_coherent(&tp->pdev->dev, |
6413 | TG3_RX_JMB_RING_BYTES(tp), | |
6414 | &tpr->rx_jmb_mapping, | |
6415 | GFP_KERNEL); | |
21f581a5 | 6416 | if (!tpr->rx_jmb) |
cf7a7298 MC |
6417 | goto err_out; |
6418 | } | |
6419 | ||
6420 | return 0; | |
6421 | ||
6422 | err_out: | |
21f581a5 | 6423 | tg3_rx_prodring_fini(tp, tpr); |
cf7a7298 MC |
6424 | return -ENOMEM; |
6425 | } | |
6426 | ||
6427 | /* Free up pending packets in all rx/tx rings. | |
6428 | * | |
6429 | * The chip has been shut down and the driver detached from | |
6430 | * the networking, so no interrupts or new tx packets will | |
6431 | * end up in the driver. tp->{tx,}lock is not held and we are not | |
6432 | * in an interrupt context and thus may sleep. | |
6433 | */ | |
6434 | static void tg3_free_rings(struct tg3 *tp) | |
6435 | { | |
f77a6a8e | 6436 | int i, j; |
cf7a7298 | 6437 | |
f77a6a8e MC |
6438 | for (j = 0; j < tp->irq_cnt; j++) { |
6439 | struct tg3_napi *tnapi = &tp->napi[j]; | |
cf7a7298 | 6440 | |
8fea32b9 | 6441 | tg3_rx_prodring_free(tp, &tnapi->prodring); |
b28f6428 | 6442 | |
0c1d0e2b MC |
6443 | if (!tnapi->tx_buffers) |
6444 | continue; | |
6445 | ||
f77a6a8e | 6446 | for (i = 0; i < TG3_TX_RING_SIZE; ) { |
f4188d8a | 6447 | struct ring_info *txp; |
f77a6a8e | 6448 | struct sk_buff *skb; |
f4188d8a | 6449 | unsigned int k; |
cf7a7298 | 6450 | |
f77a6a8e MC |
6451 | txp = &tnapi->tx_buffers[i]; |
6452 | skb = txp->skb; | |
cf7a7298 | 6453 | |
f77a6a8e MC |
6454 | if (skb == NULL) { |
6455 | i++; | |
6456 | continue; | |
6457 | } | |
cf7a7298 | 6458 | |
f4188d8a | 6459 | pci_unmap_single(tp->pdev, |
4e5e4f0d | 6460 | dma_unmap_addr(txp, mapping), |
f4188d8a AD |
6461 | skb_headlen(skb), |
6462 | PCI_DMA_TODEVICE); | |
f77a6a8e | 6463 | txp->skb = NULL; |
cf7a7298 | 6464 | |
f4188d8a AD |
6465 | i++; |
6466 | ||
6467 | for (k = 0; k < skb_shinfo(skb)->nr_frags; k++) { | |
6468 | txp = &tnapi->tx_buffers[i & (TG3_TX_RING_SIZE - 1)]; | |
6469 | pci_unmap_page(tp->pdev, | |
4e5e4f0d | 6470 | dma_unmap_addr(txp, mapping), |
f4188d8a AD |
6471 | skb_shinfo(skb)->frags[k].size, |
6472 | PCI_DMA_TODEVICE); | |
6473 | i++; | |
6474 | } | |
f77a6a8e MC |
6475 | |
6476 | dev_kfree_skb_any(skb); | |
6477 | } | |
2b2cdb65 | 6478 | } |
cf7a7298 MC |
6479 | } |
6480 | ||
6481 | /* Initialize tx/rx rings for packet processing. | |
6482 | * | |
6483 | * The chip has been shut down and the driver detached from | |
6484 | * the networking, so no interrupts or new tx packets will | |
6485 | * end up in the driver. tp->{tx,}lock are held and thus | |
6486 | * we may not sleep. | |
6487 | */ | |
6488 | static int tg3_init_rings(struct tg3 *tp) | |
6489 | { | |
f77a6a8e | 6490 | int i; |
72334482 | 6491 | |
cf7a7298 MC |
6492 | /* Free up all the SKBs. */ |
6493 | tg3_free_rings(tp); | |
6494 | ||
f77a6a8e MC |
6495 | for (i = 0; i < tp->irq_cnt; i++) { |
6496 | struct tg3_napi *tnapi = &tp->napi[i]; | |
6497 | ||
6498 | tnapi->last_tag = 0; | |
6499 | tnapi->last_irq_tag = 0; | |
6500 | tnapi->hw_status->status = 0; | |
6501 | tnapi->hw_status->status_tag = 0; | |
6502 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); | |
cf7a7298 | 6503 | |
f77a6a8e MC |
6504 | tnapi->tx_prod = 0; |
6505 | tnapi->tx_cons = 0; | |
0c1d0e2b MC |
6506 | if (tnapi->tx_ring) |
6507 | memset(tnapi->tx_ring, 0, TG3_TX_RING_BYTES); | |
f77a6a8e MC |
6508 | |
6509 | tnapi->rx_rcb_ptr = 0; | |
0c1d0e2b MC |
6510 | if (tnapi->rx_rcb) |
6511 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); | |
2b2cdb65 | 6512 | |
8fea32b9 | 6513 | if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) { |
e4af1af9 | 6514 | tg3_free_rings(tp); |
2b2cdb65 | 6515 | return -ENOMEM; |
e4af1af9 | 6516 | } |
f77a6a8e | 6517 | } |
72334482 | 6518 | |
2b2cdb65 | 6519 | return 0; |
cf7a7298 MC |
6520 | } |
6521 | ||
6522 | /* | |
6523 | * Must not be invoked with interrupt sources disabled and | |
6524 | * the hardware shutdown down. | |
6525 | */ | |
6526 | static void tg3_free_consistent(struct tg3 *tp) | |
6527 | { | |
f77a6a8e | 6528 | int i; |
898a56f8 | 6529 | |
f77a6a8e MC |
6530 | for (i = 0; i < tp->irq_cnt; i++) { |
6531 | struct tg3_napi *tnapi = &tp->napi[i]; | |
6532 | ||
6533 | if (tnapi->tx_ring) { | |
4bae65c8 | 6534 | dma_free_coherent(&tp->pdev->dev, TG3_TX_RING_BYTES, |
f77a6a8e MC |
6535 | tnapi->tx_ring, tnapi->tx_desc_mapping); |
6536 | tnapi->tx_ring = NULL; | |
6537 | } | |
6538 | ||
6539 | kfree(tnapi->tx_buffers); | |
6540 | tnapi->tx_buffers = NULL; | |
6541 | ||
6542 | if (tnapi->rx_rcb) { | |
4bae65c8 MC |
6543 | dma_free_coherent(&tp->pdev->dev, |
6544 | TG3_RX_RCB_RING_BYTES(tp), | |
6545 | tnapi->rx_rcb, | |
6546 | tnapi->rx_rcb_mapping); | |
f77a6a8e MC |
6547 | tnapi->rx_rcb = NULL; |
6548 | } | |
6549 | ||
8fea32b9 MC |
6550 | tg3_rx_prodring_fini(tp, &tnapi->prodring); |
6551 | ||
f77a6a8e | 6552 | if (tnapi->hw_status) { |
4bae65c8 MC |
6553 | dma_free_coherent(&tp->pdev->dev, TG3_HW_STATUS_SIZE, |
6554 | tnapi->hw_status, | |
6555 | tnapi->status_mapping); | |
f77a6a8e MC |
6556 | tnapi->hw_status = NULL; |
6557 | } | |
1da177e4 | 6558 | } |
f77a6a8e | 6559 | |
1da177e4 | 6560 | if (tp->hw_stats) { |
4bae65c8 MC |
6561 | dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats), |
6562 | tp->hw_stats, tp->stats_mapping); | |
1da177e4 LT |
6563 | tp->hw_stats = NULL; |
6564 | } | |
6565 | } | |
6566 | ||
6567 | /* | |
6568 | * Must not be invoked with interrupt sources disabled and | |
6569 | * the hardware shutdown down. Can sleep. | |
6570 | */ | |
6571 | static int tg3_alloc_consistent(struct tg3 *tp) | |
6572 | { | |
f77a6a8e | 6573 | int i; |
898a56f8 | 6574 | |
4bae65c8 MC |
6575 | tp->hw_stats = dma_alloc_coherent(&tp->pdev->dev, |
6576 | sizeof(struct tg3_hw_stats), | |
6577 | &tp->stats_mapping, | |
6578 | GFP_KERNEL); | |
f77a6a8e | 6579 | if (!tp->hw_stats) |
1da177e4 LT |
6580 | goto err_out; |
6581 | ||
f77a6a8e | 6582 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
1da177e4 | 6583 | |
f77a6a8e MC |
6584 | for (i = 0; i < tp->irq_cnt; i++) { |
6585 | struct tg3_napi *tnapi = &tp->napi[i]; | |
8d9d7cfc | 6586 | struct tg3_hw_status *sblk; |
1da177e4 | 6587 | |
4bae65c8 MC |
6588 | tnapi->hw_status = dma_alloc_coherent(&tp->pdev->dev, |
6589 | TG3_HW_STATUS_SIZE, | |
6590 | &tnapi->status_mapping, | |
6591 | GFP_KERNEL); | |
f77a6a8e MC |
6592 | if (!tnapi->hw_status) |
6593 | goto err_out; | |
898a56f8 | 6594 | |
f77a6a8e | 6595 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
8d9d7cfc MC |
6596 | sblk = tnapi->hw_status; |
6597 | ||
8fea32b9 MC |
6598 | if (tg3_rx_prodring_init(tp, &tnapi->prodring)) |
6599 | goto err_out; | |
6600 | ||
19cfaecc MC |
6601 | /* If multivector TSS is enabled, vector 0 does not handle |
6602 | * tx interrupts. Don't allocate any resources for it. | |
6603 | */ | |
63c3a66f JP |
6604 | if ((!i && !tg3_flag(tp, ENABLE_TSS)) || |
6605 | (i && tg3_flag(tp, ENABLE_TSS))) { | |
19cfaecc MC |
6606 | tnapi->tx_buffers = kzalloc(sizeof(struct ring_info) * |
6607 | TG3_TX_RING_SIZE, | |
6608 | GFP_KERNEL); | |
6609 | if (!tnapi->tx_buffers) | |
6610 | goto err_out; | |
6611 | ||
4bae65c8 MC |
6612 | tnapi->tx_ring = dma_alloc_coherent(&tp->pdev->dev, |
6613 | TG3_TX_RING_BYTES, | |
6614 | &tnapi->tx_desc_mapping, | |
6615 | GFP_KERNEL); | |
19cfaecc MC |
6616 | if (!tnapi->tx_ring) |
6617 | goto err_out; | |
6618 | } | |
6619 | ||
8d9d7cfc MC |
6620 | /* |
6621 | * When RSS is enabled, the status block format changes | |
6622 | * slightly. The "rx_jumbo_consumer", "reserved", | |
6623 | * and "rx_mini_consumer" members get mapped to the | |
6624 | * other three rx return ring producer indexes. | |
6625 | */ | |
6626 | switch (i) { | |
6627 | default: | |
6628 | tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer; | |
6629 | break; | |
6630 | case 2: | |
6631 | tnapi->rx_rcb_prod_idx = &sblk->rx_jumbo_consumer; | |
6632 | break; | |
6633 | case 3: | |
6634 | tnapi->rx_rcb_prod_idx = &sblk->reserved; | |
6635 | break; | |
6636 | case 4: | |
6637 | tnapi->rx_rcb_prod_idx = &sblk->rx_mini_consumer; | |
6638 | break; | |
6639 | } | |
72334482 | 6640 | |
0c1d0e2b MC |
6641 | /* |
6642 | * If multivector RSS is enabled, vector 0 does not handle | |
6643 | * rx or tx interrupts. Don't allocate any resources for it. | |
6644 | */ | |
63c3a66f | 6645 | if (!i && tg3_flag(tp, ENABLE_RSS)) |
0c1d0e2b MC |
6646 | continue; |
6647 | ||
4bae65c8 MC |
6648 | tnapi->rx_rcb = dma_alloc_coherent(&tp->pdev->dev, |
6649 | TG3_RX_RCB_RING_BYTES(tp), | |
6650 | &tnapi->rx_rcb_mapping, | |
6651 | GFP_KERNEL); | |
f77a6a8e MC |
6652 | if (!tnapi->rx_rcb) |
6653 | goto err_out; | |
72334482 | 6654 | |
f77a6a8e | 6655 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
f77a6a8e | 6656 | } |
1da177e4 LT |
6657 | |
6658 | return 0; | |
6659 | ||
6660 | err_out: | |
6661 | tg3_free_consistent(tp); | |
6662 | return -ENOMEM; | |
6663 | } | |
6664 | ||
6665 | #define MAX_WAIT_CNT 1000 | |
6666 | ||
6667 | /* To stop a block, clear the enable bit and poll till it | |
6668 | * clears. tp->lock is held. | |
6669 | */ | |
b3b7d6be | 6670 | static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent) |
1da177e4 LT |
6671 | { |
6672 | unsigned int i; | |
6673 | u32 val; | |
6674 | ||
63c3a66f | 6675 | if (tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
6676 | switch (ofs) { |
6677 | case RCVLSC_MODE: | |
6678 | case DMAC_MODE: | |
6679 | case MBFREE_MODE: | |
6680 | case BUFMGR_MODE: | |
6681 | case MEMARB_MODE: | |
6682 | /* We can't enable/disable these bits of the | |
6683 | * 5705/5750, just say success. | |
6684 | */ | |
6685 | return 0; | |
6686 | ||
6687 | default: | |
6688 | break; | |
855e1111 | 6689 | } |
1da177e4 LT |
6690 | } |
6691 | ||
6692 | val = tr32(ofs); | |
6693 | val &= ~enable_bit; | |
6694 | tw32_f(ofs, val); | |
6695 | ||
6696 | for (i = 0; i < MAX_WAIT_CNT; i++) { | |
6697 | udelay(100); | |
6698 | val = tr32(ofs); | |
6699 | if ((val & enable_bit) == 0) | |
6700 | break; | |
6701 | } | |
6702 | ||
b3b7d6be | 6703 | if (i == MAX_WAIT_CNT && !silent) { |
2445e461 MC |
6704 | dev_err(&tp->pdev->dev, |
6705 | "tg3_stop_block timed out, ofs=%lx enable_bit=%x\n", | |
6706 | ofs, enable_bit); | |
1da177e4 LT |
6707 | return -ENODEV; |
6708 | } | |
6709 | ||
6710 | return 0; | |
6711 | } | |
6712 | ||
6713 | /* tp->lock is held. */ | |
b3b7d6be | 6714 | static int tg3_abort_hw(struct tg3 *tp, int silent) |
1da177e4 LT |
6715 | { |
6716 | int i, err; | |
6717 | ||
6718 | tg3_disable_ints(tp); | |
6719 | ||
6720 | tp->rx_mode &= ~RX_MODE_ENABLE; | |
6721 | tw32_f(MAC_RX_MODE, tp->rx_mode); | |
6722 | udelay(10); | |
6723 | ||
b3b7d6be DM |
6724 | err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent); |
6725 | err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent); | |
6726 | err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent); | |
6727 | err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent); | |
6728 | err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent); | |
6729 | err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent); | |
6730 | ||
6731 | err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent); | |
6732 | err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent); | |
6733 | err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent); | |
6734 | err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent); | |
6735 | err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent); | |
6736 | err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent); | |
6737 | err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent); | |
1da177e4 LT |
6738 | |
6739 | tp->mac_mode &= ~MAC_MODE_TDE_ENABLE; | |
6740 | tw32_f(MAC_MODE, tp->mac_mode); | |
6741 | udelay(40); | |
6742 | ||
6743 | tp->tx_mode &= ~TX_MODE_ENABLE; | |
6744 | tw32_f(MAC_TX_MODE, tp->tx_mode); | |
6745 | ||
6746 | for (i = 0; i < MAX_WAIT_CNT; i++) { | |
6747 | udelay(100); | |
6748 | if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE)) | |
6749 | break; | |
6750 | } | |
6751 | if (i >= MAX_WAIT_CNT) { | |
ab96b241 MC |
6752 | dev_err(&tp->pdev->dev, |
6753 | "%s timed out, TX_MODE_ENABLE will not clear " | |
6754 | "MAC_TX_MODE=%08x\n", __func__, tr32(MAC_TX_MODE)); | |
e6de8ad1 | 6755 | err |= -ENODEV; |
1da177e4 LT |
6756 | } |
6757 | ||
e6de8ad1 | 6758 | err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent); |
b3b7d6be DM |
6759 | err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent); |
6760 | err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent); | |
1da177e4 LT |
6761 | |
6762 | tw32(FTQ_RESET, 0xffffffff); | |
6763 | tw32(FTQ_RESET, 0x00000000); | |
6764 | ||
b3b7d6be DM |
6765 | err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent); |
6766 | err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent); | |
1da177e4 | 6767 | |
f77a6a8e MC |
6768 | for (i = 0; i < tp->irq_cnt; i++) { |
6769 | struct tg3_napi *tnapi = &tp->napi[i]; | |
6770 | if (tnapi->hw_status) | |
6771 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); | |
6772 | } | |
1da177e4 LT |
6773 | if (tp->hw_stats) |
6774 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); | |
6775 | ||
1da177e4 LT |
6776 | return err; |
6777 | } | |
6778 | ||
0d3031d9 MC |
6779 | static void tg3_ape_send_event(struct tg3 *tp, u32 event) |
6780 | { | |
6781 | int i; | |
6782 | u32 apedata; | |
6783 | ||
dc6d0744 | 6784 | /* NCSI does not support APE events */ |
63c3a66f | 6785 | if (tg3_flag(tp, APE_HAS_NCSI)) |
dc6d0744 MC |
6786 | return; |
6787 | ||
0d3031d9 MC |
6788 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); |
6789 | if (apedata != APE_SEG_SIG_MAGIC) | |
6790 | return; | |
6791 | ||
6792 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); | |
731fd79c | 6793 | if (!(apedata & APE_FW_STATUS_READY)) |
0d3031d9 MC |
6794 | return; |
6795 | ||
6796 | /* Wait for up to 1 millisecond for APE to service previous event. */ | |
6797 | for (i = 0; i < 10; i++) { | |
6798 | if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM)) | |
6799 | return; | |
6800 | ||
6801 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); | |
6802 | ||
6803 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) | |
6804 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, | |
6805 | event | APE_EVENT_STATUS_EVENT_PENDING); | |
6806 | ||
6807 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); | |
6808 | ||
6809 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) | |
6810 | break; | |
6811 | ||
6812 | udelay(100); | |
6813 | } | |
6814 | ||
6815 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) | |
6816 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); | |
6817 | } | |
6818 | ||
6819 | static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) | |
6820 | { | |
6821 | u32 event; | |
6822 | u32 apedata; | |
6823 | ||
63c3a66f | 6824 | if (!tg3_flag(tp, ENABLE_APE)) |
0d3031d9 MC |
6825 | return; |
6826 | ||
6827 | switch (kind) { | |
33f401ae MC |
6828 | case RESET_KIND_INIT: |
6829 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, | |
6830 | APE_HOST_SEG_SIG_MAGIC); | |
6831 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN, | |
6832 | APE_HOST_SEG_LEN_MAGIC); | |
6833 | apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT); | |
6834 | tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata); | |
6835 | tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID, | |
6867c843 | 6836 | APE_HOST_DRIVER_ID_MAGIC(TG3_MAJ_NUM, TG3_MIN_NUM)); |
33f401ae MC |
6837 | tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR, |
6838 | APE_HOST_BEHAV_NO_PHYLOCK); | |
dc6d0744 MC |
6839 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, |
6840 | TG3_APE_HOST_DRVR_STATE_START); | |
33f401ae MC |
6841 | |
6842 | event = APE_EVENT_STATUS_STATE_START; | |
6843 | break; | |
6844 | case RESET_KIND_SHUTDOWN: | |
6845 | /* With the interface we are currently using, | |
6846 | * APE does not track driver state. Wiping | |
6847 | * out the HOST SEGMENT SIGNATURE forces | |
6848 | * the APE to assume OS absent status. | |
6849 | */ | |
6850 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 0x0); | |
b2aee154 | 6851 | |
dc6d0744 | 6852 | if (device_may_wakeup(&tp->pdev->dev) && |
63c3a66f | 6853 | tg3_flag(tp, WOL_ENABLE)) { |
dc6d0744 MC |
6854 | tg3_ape_write32(tp, TG3_APE_HOST_WOL_SPEED, |
6855 | TG3_APE_HOST_WOL_SPEED_AUTO); | |
6856 | apedata = TG3_APE_HOST_DRVR_STATE_WOL; | |
6857 | } else | |
6858 | apedata = TG3_APE_HOST_DRVR_STATE_UNLOAD; | |
6859 | ||
6860 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, apedata); | |
6861 | ||
33f401ae MC |
6862 | event = APE_EVENT_STATUS_STATE_UNLOAD; |
6863 | break; | |
6864 | case RESET_KIND_SUSPEND: | |
6865 | event = APE_EVENT_STATUS_STATE_SUSPEND; | |
6866 | break; | |
6867 | default: | |
6868 | return; | |
0d3031d9 MC |
6869 | } |
6870 | ||
6871 | event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE; | |
6872 | ||
6873 | tg3_ape_send_event(tp, event); | |
6874 | } | |
6875 | ||
1da177e4 LT |
6876 | /* tp->lock is held. */ |
6877 | static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind) | |
6878 | { | |
f49639e6 DM |
6879 | tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX, |
6880 | NIC_SRAM_FIRMWARE_MBOX_MAGIC1); | |
1da177e4 | 6881 | |
63c3a66f | 6882 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { |
1da177e4 LT |
6883 | switch (kind) { |
6884 | case RESET_KIND_INIT: | |
6885 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
6886 | DRV_STATE_START); | |
6887 | break; | |
6888 | ||
6889 | case RESET_KIND_SHUTDOWN: | |
6890 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
6891 | DRV_STATE_UNLOAD); | |
6892 | break; | |
6893 | ||
6894 | case RESET_KIND_SUSPEND: | |
6895 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
6896 | DRV_STATE_SUSPEND); | |
6897 | break; | |
6898 | ||
6899 | default: | |
6900 | break; | |
855e1111 | 6901 | } |
1da177e4 | 6902 | } |
0d3031d9 MC |
6903 | |
6904 | if (kind == RESET_KIND_INIT || | |
6905 | kind == RESET_KIND_SUSPEND) | |
6906 | tg3_ape_driver_state_change(tp, kind); | |
1da177e4 LT |
6907 | } |
6908 | ||
6909 | /* tp->lock is held. */ | |
6910 | static void tg3_write_sig_post_reset(struct tg3 *tp, int kind) | |
6911 | { | |
63c3a66f | 6912 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { |
1da177e4 LT |
6913 | switch (kind) { |
6914 | case RESET_KIND_INIT: | |
6915 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
6916 | DRV_STATE_START_DONE); | |
6917 | break; | |
6918 | ||
6919 | case RESET_KIND_SHUTDOWN: | |
6920 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
6921 | DRV_STATE_UNLOAD_DONE); | |
6922 | break; | |
6923 | ||
6924 | default: | |
6925 | break; | |
855e1111 | 6926 | } |
1da177e4 | 6927 | } |
0d3031d9 MC |
6928 | |
6929 | if (kind == RESET_KIND_SHUTDOWN) | |
6930 | tg3_ape_driver_state_change(tp, kind); | |
1da177e4 LT |
6931 | } |
6932 | ||
6933 | /* tp->lock is held. */ | |
6934 | static void tg3_write_sig_legacy(struct tg3 *tp, int kind) | |
6935 | { | |
63c3a66f | 6936 | if (tg3_flag(tp, ENABLE_ASF)) { |
1da177e4 LT |
6937 | switch (kind) { |
6938 | case RESET_KIND_INIT: | |
6939 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
6940 | DRV_STATE_START); | |
6941 | break; | |
6942 | ||
6943 | case RESET_KIND_SHUTDOWN: | |
6944 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
6945 | DRV_STATE_UNLOAD); | |
6946 | break; | |
6947 | ||
6948 | case RESET_KIND_SUSPEND: | |
6949 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
6950 | DRV_STATE_SUSPEND); | |
6951 | break; | |
6952 | ||
6953 | default: | |
6954 | break; | |
855e1111 | 6955 | } |
1da177e4 LT |
6956 | } |
6957 | } | |
6958 | ||
7a6f4369 MC |
6959 | static int tg3_poll_fw(struct tg3 *tp) |
6960 | { | |
6961 | int i; | |
6962 | u32 val; | |
6963 | ||
b5d3772c | 6964 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
0ccead18 GZ |
6965 | /* Wait up to 20ms for init done. */ |
6966 | for (i = 0; i < 200; i++) { | |
b5d3772c MC |
6967 | if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE) |
6968 | return 0; | |
0ccead18 | 6969 | udelay(100); |
b5d3772c MC |
6970 | } |
6971 | return -ENODEV; | |
6972 | } | |
6973 | ||
7a6f4369 MC |
6974 | /* Wait for firmware initialization to complete. */ |
6975 | for (i = 0; i < 100000; i++) { | |
6976 | tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val); | |
6977 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) | |
6978 | break; | |
6979 | udelay(10); | |
6980 | } | |
6981 | ||
6982 | /* Chip might not be fitted with firmware. Some Sun onboard | |
6983 | * parts are configured like that. So don't signal the timeout | |
6984 | * of the above loop as an error, but do report the lack of | |
6985 | * running firmware once. | |
6986 | */ | |
63c3a66f JP |
6987 | if (i >= 100000 && !tg3_flag(tp, NO_FWARE_REPORTED)) { |
6988 | tg3_flag_set(tp, NO_FWARE_REPORTED); | |
7a6f4369 | 6989 | |
05dbe005 | 6990 | netdev_info(tp->dev, "No firmware running\n"); |
7a6f4369 MC |
6991 | } |
6992 | ||
6b10c165 MC |
6993 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
6994 | /* The 57765 A0 needs a little more | |
6995 | * time to do some important work. | |
6996 | */ | |
6997 | mdelay(10); | |
6998 | } | |
6999 | ||
7a6f4369 MC |
7000 | return 0; |
7001 | } | |
7002 | ||
ee6a99b5 MC |
7003 | /* Save PCI command register before chip reset */ |
7004 | static void tg3_save_pci_state(struct tg3 *tp) | |
7005 | { | |
8a6eac90 | 7006 | pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd); |
ee6a99b5 MC |
7007 | } |
7008 | ||
7009 | /* Restore PCI state after chip reset */ | |
7010 | static void tg3_restore_pci_state(struct tg3 *tp) | |
7011 | { | |
7012 | u32 val; | |
7013 | ||
7014 | /* Re-enable indirect register accesses. */ | |
7015 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
7016 | tp->misc_host_ctrl); | |
7017 | ||
7018 | /* Set MAX PCI retry to zero. */ | |
7019 | val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE); | |
7020 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && | |
63c3a66f | 7021 | tg3_flag(tp, PCIX_MODE)) |
ee6a99b5 | 7022 | val |= PCISTATE_RETRY_SAME_DMA; |
0d3031d9 | 7023 | /* Allow reads and writes to the APE register and memory space. */ |
63c3a66f | 7024 | if (tg3_flag(tp, ENABLE_APE)) |
0d3031d9 | 7025 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
f92d9dc1 MC |
7026 | PCISTATE_ALLOW_APE_SHMEM_WR | |
7027 | PCISTATE_ALLOW_APE_PSPACE_WR; | |
ee6a99b5 MC |
7028 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); |
7029 | ||
8a6eac90 | 7030 | pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd); |
ee6a99b5 | 7031 | |
fcb389df | 7032 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) { |
63c3a66f | 7033 | if (tg3_flag(tp, PCI_EXPRESS)) |
cf79003d | 7034 | pcie_set_readrq(tp->pdev, tp->pcie_readrq); |
fcb389df MC |
7035 | else { |
7036 | pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, | |
7037 | tp->pci_cacheline_sz); | |
7038 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, | |
7039 | tp->pci_lat_timer); | |
7040 | } | |
114342f2 | 7041 | } |
5f5c51e3 | 7042 | |
ee6a99b5 | 7043 | /* Make sure PCI-X relaxed ordering bit is clear. */ |
63c3a66f | 7044 | if (tg3_flag(tp, PCIX_MODE)) { |
9974a356 MC |
7045 | u16 pcix_cmd; |
7046 | ||
7047 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, | |
7048 | &pcix_cmd); | |
7049 | pcix_cmd &= ~PCI_X_CMD_ERO; | |
7050 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, | |
7051 | pcix_cmd); | |
7052 | } | |
ee6a99b5 | 7053 | |
63c3a66f | 7054 | if (tg3_flag(tp, 5780_CLASS)) { |
ee6a99b5 MC |
7055 | |
7056 | /* Chip reset on 5780 will reset MSI enable bit, | |
7057 | * so need to restore it. | |
7058 | */ | |
63c3a66f | 7059 | if (tg3_flag(tp, USING_MSI)) { |
ee6a99b5 MC |
7060 | u16 ctrl; |
7061 | ||
7062 | pci_read_config_word(tp->pdev, | |
7063 | tp->msi_cap + PCI_MSI_FLAGS, | |
7064 | &ctrl); | |
7065 | pci_write_config_word(tp->pdev, | |
7066 | tp->msi_cap + PCI_MSI_FLAGS, | |
7067 | ctrl | PCI_MSI_FLAGS_ENABLE); | |
7068 | val = tr32(MSGINT_MODE); | |
7069 | tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE); | |
7070 | } | |
7071 | } | |
7072 | } | |
7073 | ||
1da177e4 LT |
7074 | static void tg3_stop_fw(struct tg3 *); |
7075 | ||
7076 | /* tp->lock is held. */ | |
7077 | static int tg3_chip_reset(struct tg3 *tp) | |
7078 | { | |
7079 | u32 val; | |
1ee582d8 | 7080 | void (*write_op)(struct tg3 *, u32, u32); |
4f125f42 | 7081 | int i, err; |
1da177e4 | 7082 | |
f49639e6 DM |
7083 | tg3_nvram_lock(tp); |
7084 | ||
77b483f1 MC |
7085 | tg3_ape_lock(tp, TG3_APE_LOCK_GRC); |
7086 | ||
f49639e6 DM |
7087 | /* No matching tg3_nvram_unlock() after this because |
7088 | * chip reset below will undo the nvram lock. | |
7089 | */ | |
7090 | tp->nvram_lock_cnt = 0; | |
1da177e4 | 7091 | |
ee6a99b5 MC |
7092 | /* GRC_MISC_CFG core clock reset will clear the memory |
7093 | * enable bit in PCI register 4 and the MSI enable bit | |
7094 | * on some chips, so we save relevant registers here. | |
7095 | */ | |
7096 | tg3_save_pci_state(tp); | |
7097 | ||
d9ab5ad1 | 7098 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
63c3a66f | 7099 | tg3_flag(tp, 5755_PLUS)) |
d9ab5ad1 MC |
7100 | tw32(GRC_FASTBOOT_PC, 0); |
7101 | ||
1da177e4 LT |
7102 | /* |
7103 | * We must avoid the readl() that normally takes place. | |
7104 | * It locks machines, causes machine checks, and other | |
7105 | * fun things. So, temporarily disable the 5701 | |
7106 | * hardware workaround, while we do the reset. | |
7107 | */ | |
1ee582d8 MC |
7108 | write_op = tp->write32; |
7109 | if (write_op == tg3_write_flush_reg32) | |
7110 | tp->write32 = tg3_write32; | |
1da177e4 | 7111 | |
d18edcb2 MC |
7112 | /* Prevent the irq handler from reading or writing PCI registers |
7113 | * during chip reset when the memory enable bit in the PCI command | |
7114 | * register may be cleared. The chip does not generate interrupt | |
7115 | * at this time, but the irq handler may still be called due to irq | |
7116 | * sharing or irqpoll. | |
7117 | */ | |
63c3a66f | 7118 | tg3_flag_set(tp, CHIP_RESETTING); |
f77a6a8e MC |
7119 | for (i = 0; i < tp->irq_cnt; i++) { |
7120 | struct tg3_napi *tnapi = &tp->napi[i]; | |
7121 | if (tnapi->hw_status) { | |
7122 | tnapi->hw_status->status = 0; | |
7123 | tnapi->hw_status->status_tag = 0; | |
7124 | } | |
7125 | tnapi->last_tag = 0; | |
7126 | tnapi->last_irq_tag = 0; | |
b8fa2f3a | 7127 | } |
d18edcb2 | 7128 | smp_mb(); |
4f125f42 MC |
7129 | |
7130 | for (i = 0; i < tp->irq_cnt; i++) | |
7131 | synchronize_irq(tp->napi[i].irq_vec); | |
d18edcb2 | 7132 | |
255ca311 MC |
7133 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
7134 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; | |
7135 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); | |
7136 | } | |
7137 | ||
1da177e4 LT |
7138 | /* do the reset */ |
7139 | val = GRC_MISC_CFG_CORECLK_RESET; | |
7140 | ||
63c3a66f | 7141 | if (tg3_flag(tp, PCI_EXPRESS)) { |
88075d91 MC |
7142 | /* Force PCIe 1.0a mode */ |
7143 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && | |
63c3a66f | 7144 | !tg3_flag(tp, 57765_PLUS) && |
88075d91 MC |
7145 | tr32(TG3_PCIE_PHY_TSTCTL) == |
7146 | (TG3_PCIE_PHY_TSTCTL_PCIE10 | TG3_PCIE_PHY_TSTCTL_PSCRAM)) | |
7147 | tw32(TG3_PCIE_PHY_TSTCTL, TG3_PCIE_PHY_TSTCTL_PSCRAM); | |
7148 | ||
1da177e4 LT |
7149 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) { |
7150 | tw32(GRC_MISC_CFG, (1 << 29)); | |
7151 | val |= (1 << 29); | |
7152 | } | |
7153 | } | |
7154 | ||
b5d3772c MC |
7155 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
7156 | tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET); | |
7157 | tw32(GRC_VCPU_EXT_CTRL, | |
7158 | tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU); | |
7159 | } | |
7160 | ||
f37500d3 | 7161 | /* Manage gphy power for all CPMU absent PCIe devices. */ |
63c3a66f | 7162 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, CPMU_PRESENT)) |
1da177e4 | 7163 | val |= GRC_MISC_CFG_KEEP_GPHY_POWER; |
f37500d3 | 7164 | |
1da177e4 LT |
7165 | tw32(GRC_MISC_CFG, val); |
7166 | ||
1ee582d8 MC |
7167 | /* restore 5701 hardware bug workaround write method */ |
7168 | tp->write32 = write_op; | |
1da177e4 LT |
7169 | |
7170 | /* Unfortunately, we have to delay before the PCI read back. | |
7171 | * Some 575X chips even will not respond to a PCI cfg access | |
7172 | * when the reset command is given to the chip. | |
7173 | * | |
7174 | * How do these hardware designers expect things to work | |
7175 | * properly if the PCI write is posted for a long period | |
7176 | * of time? It is always necessary to have some method by | |
7177 | * which a register read back can occur to push the write | |
7178 | * out which does the reset. | |
7179 | * | |
7180 | * For most tg3 variants the trick below was working. | |
7181 | * Ho hum... | |
7182 | */ | |
7183 | udelay(120); | |
7184 | ||
7185 | /* Flush PCI posted writes. The normal MMIO registers | |
7186 | * are inaccessible at this time so this is the only | |
7187 | * way to make this reliably (actually, this is no longer | |
7188 | * the case, see above). I tried to use indirect | |
7189 | * register read/write but this upset some 5701 variants. | |
7190 | */ | |
7191 | pci_read_config_dword(tp->pdev, PCI_COMMAND, &val); | |
7192 | ||
7193 | udelay(120); | |
7194 | ||
63c3a66f | 7195 | if (tg3_flag(tp, PCI_EXPRESS) && tp->pcie_cap) { |
e7126997 MC |
7196 | u16 val16; |
7197 | ||
1da177e4 LT |
7198 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) { |
7199 | int i; | |
7200 | u32 cfg_val; | |
7201 | ||
7202 | /* Wait for link training to complete. */ | |
7203 | for (i = 0; i < 5000; i++) | |
7204 | udelay(100); | |
7205 | ||
7206 | pci_read_config_dword(tp->pdev, 0xc4, &cfg_val); | |
7207 | pci_write_config_dword(tp->pdev, 0xc4, | |
7208 | cfg_val | (1 << 15)); | |
7209 | } | |
5e7dfd0f | 7210 | |
e7126997 MC |
7211 | /* Clear the "no snoop" and "relaxed ordering" bits. */ |
7212 | pci_read_config_word(tp->pdev, | |
7213 | tp->pcie_cap + PCI_EXP_DEVCTL, | |
7214 | &val16); | |
7215 | val16 &= ~(PCI_EXP_DEVCTL_RELAX_EN | | |
7216 | PCI_EXP_DEVCTL_NOSNOOP_EN); | |
7217 | /* | |
7218 | * Older PCIe devices only support the 128 byte | |
7219 | * MPS setting. Enforce the restriction. | |
5e7dfd0f | 7220 | */ |
63c3a66f | 7221 | if (!tg3_flag(tp, CPMU_PRESENT)) |
e7126997 | 7222 | val16 &= ~PCI_EXP_DEVCTL_PAYLOAD; |
5e7dfd0f MC |
7223 | pci_write_config_word(tp->pdev, |
7224 | tp->pcie_cap + PCI_EXP_DEVCTL, | |
e7126997 | 7225 | val16); |
5e7dfd0f | 7226 | |
cf79003d | 7227 | pcie_set_readrq(tp->pdev, tp->pcie_readrq); |
5e7dfd0f MC |
7228 | |
7229 | /* Clear error status */ | |
7230 | pci_write_config_word(tp->pdev, | |
7231 | tp->pcie_cap + PCI_EXP_DEVSTA, | |
7232 | PCI_EXP_DEVSTA_CED | | |
7233 | PCI_EXP_DEVSTA_NFED | | |
7234 | PCI_EXP_DEVSTA_FED | | |
7235 | PCI_EXP_DEVSTA_URD); | |
1da177e4 LT |
7236 | } |
7237 | ||
ee6a99b5 | 7238 | tg3_restore_pci_state(tp); |
1da177e4 | 7239 | |
63c3a66f JP |
7240 | tg3_flag_clear(tp, CHIP_RESETTING); |
7241 | tg3_flag_clear(tp, ERROR_PROCESSED); | |
d18edcb2 | 7242 | |
ee6a99b5 | 7243 | val = 0; |
63c3a66f | 7244 | if (tg3_flag(tp, 5780_CLASS)) |
4cf78e4f | 7245 | val = tr32(MEMARB_MODE); |
ee6a99b5 | 7246 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
1da177e4 LT |
7247 | |
7248 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) { | |
7249 | tg3_stop_fw(tp); | |
7250 | tw32(0x5000, 0x400); | |
7251 | } | |
7252 | ||
7253 | tw32(GRC_MODE, tp->grc_mode); | |
7254 | ||
7255 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) { | |
ab0049b4 | 7256 | val = tr32(0xc4); |
1da177e4 LT |
7257 | |
7258 | tw32(0xc4, val | (1 << 15)); | |
7259 | } | |
7260 | ||
7261 | if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 && | |
7262 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { | |
7263 | tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE; | |
7264 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) | |
7265 | tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN; | |
7266 | tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); | |
7267 | } | |
7268 | ||
63c3a66f | 7269 | if (tg3_flag(tp, ENABLE_APE)) |
d2394e6b MC |
7270 | tp->mac_mode = MAC_MODE_APE_TX_EN | |
7271 | MAC_MODE_APE_RX_EN | | |
7272 | MAC_MODE_TDE_ENABLE; | |
7273 | ||
f07e9af3 | 7274 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
d2394e6b MC |
7275 | tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; |
7276 | val = tp->mac_mode; | |
f07e9af3 | 7277 | } else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
d2394e6b MC |
7278 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
7279 | val = tp->mac_mode; | |
1da177e4 | 7280 | } else |
d2394e6b MC |
7281 | val = 0; |
7282 | ||
7283 | tw32_f(MAC_MODE, val); | |
1da177e4 LT |
7284 | udelay(40); |
7285 | ||
77b483f1 MC |
7286 | tg3_ape_unlock(tp, TG3_APE_LOCK_GRC); |
7287 | ||
7a6f4369 MC |
7288 | err = tg3_poll_fw(tp); |
7289 | if (err) | |
7290 | return err; | |
1da177e4 | 7291 | |
0a9140cf MC |
7292 | tg3_mdio_start(tp); |
7293 | ||
63c3a66f | 7294 | if (tg3_flag(tp, PCI_EXPRESS) && |
f6eb9b1f MC |
7295 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
7296 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && | |
63c3a66f | 7297 | !tg3_flag(tp, 57765_PLUS)) { |
ab0049b4 | 7298 | val = tr32(0x7c00); |
1da177e4 LT |
7299 | |
7300 | tw32(0x7c00, val | (1 << 25)); | |
7301 | } | |
7302 | ||
d78b59f5 MC |
7303 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { |
7304 | val = tr32(TG3_CPMU_CLCK_ORIDE); | |
7305 | tw32(TG3_CPMU_CLCK_ORIDE, val & ~CPMU_CLCK_ORIDE_MAC_ORIDE_EN); | |
7306 | } | |
7307 | ||
1da177e4 | 7308 | /* Reprobe ASF enable state. */ |
63c3a66f JP |
7309 | tg3_flag_clear(tp, ENABLE_ASF); |
7310 | tg3_flag_clear(tp, ASF_NEW_HANDSHAKE); | |
1da177e4 LT |
7311 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
7312 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { | |
7313 | u32 nic_cfg; | |
7314 | ||
7315 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); | |
7316 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { | |
63c3a66f | 7317 | tg3_flag_set(tp, ENABLE_ASF); |
4ba526ce | 7318 | tp->last_event_jiffies = jiffies; |
63c3a66f JP |
7319 | if (tg3_flag(tp, 5750_PLUS)) |
7320 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); | |
1da177e4 LT |
7321 | } |
7322 | } | |
7323 | ||
7324 | return 0; | |
7325 | } | |
7326 | ||
7327 | /* tp->lock is held. */ | |
7328 | static void tg3_stop_fw(struct tg3 *tp) | |
7329 | { | |
63c3a66f | 7330 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
7c5026aa MC |
7331 | /* Wait for RX cpu to ACK the previous event. */ |
7332 | tg3_wait_for_event_ack(tp); | |
1da177e4 LT |
7333 | |
7334 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW); | |
4ba526ce MC |
7335 | |
7336 | tg3_generate_fw_event(tp); | |
1da177e4 | 7337 | |
7c5026aa MC |
7338 | /* Wait for RX cpu to ACK this event. */ |
7339 | tg3_wait_for_event_ack(tp); | |
1da177e4 LT |
7340 | } |
7341 | } | |
7342 | ||
7343 | /* tp->lock is held. */ | |
944d980e | 7344 | static int tg3_halt(struct tg3 *tp, int kind, int silent) |
1da177e4 LT |
7345 | { |
7346 | int err; | |
7347 | ||
7348 | tg3_stop_fw(tp); | |
7349 | ||
944d980e | 7350 | tg3_write_sig_pre_reset(tp, kind); |
1da177e4 | 7351 | |
b3b7d6be | 7352 | tg3_abort_hw(tp, silent); |
1da177e4 LT |
7353 | err = tg3_chip_reset(tp); |
7354 | ||
daba2a63 MC |
7355 | __tg3_set_mac_addr(tp, 0); |
7356 | ||
944d980e MC |
7357 | tg3_write_sig_legacy(tp, kind); |
7358 | tg3_write_sig_post_reset(tp, kind); | |
1da177e4 LT |
7359 | |
7360 | if (err) | |
7361 | return err; | |
7362 | ||
7363 | return 0; | |
7364 | } | |
7365 | ||
1da177e4 LT |
7366 | #define RX_CPU_SCRATCH_BASE 0x30000 |
7367 | #define RX_CPU_SCRATCH_SIZE 0x04000 | |
7368 | #define TX_CPU_SCRATCH_BASE 0x34000 | |
7369 | #define TX_CPU_SCRATCH_SIZE 0x04000 | |
7370 | ||
7371 | /* tp->lock is held. */ | |
7372 | static int tg3_halt_cpu(struct tg3 *tp, u32 offset) | |
7373 | { | |
7374 | int i; | |
7375 | ||
63c3a66f | 7376 | BUG_ON(offset == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)); |
1da177e4 | 7377 | |
b5d3772c MC |
7378 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
7379 | u32 val = tr32(GRC_VCPU_EXT_CTRL); | |
7380 | ||
7381 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU); | |
7382 | return 0; | |
7383 | } | |
1da177e4 LT |
7384 | if (offset == RX_CPU_BASE) { |
7385 | for (i = 0; i < 10000; i++) { | |
7386 | tw32(offset + CPU_STATE, 0xffffffff); | |
7387 | tw32(offset + CPU_MODE, CPU_MODE_HALT); | |
7388 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) | |
7389 | break; | |
7390 | } | |
7391 | ||
7392 | tw32(offset + CPU_STATE, 0xffffffff); | |
7393 | tw32_f(offset + CPU_MODE, CPU_MODE_HALT); | |
7394 | udelay(10); | |
7395 | } else { | |
7396 | for (i = 0; i < 10000; i++) { | |
7397 | tw32(offset + CPU_STATE, 0xffffffff); | |
7398 | tw32(offset + CPU_MODE, CPU_MODE_HALT); | |
7399 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) | |
7400 | break; | |
7401 | } | |
7402 | } | |
7403 | ||
7404 | if (i >= 10000) { | |
05dbe005 JP |
7405 | netdev_err(tp->dev, "%s timed out, %s CPU\n", |
7406 | __func__, offset == RX_CPU_BASE ? "RX" : "TX"); | |
1da177e4 LT |
7407 | return -ENODEV; |
7408 | } | |
ec41c7df MC |
7409 | |
7410 | /* Clear firmware's nvram arbitration. */ | |
63c3a66f | 7411 | if (tg3_flag(tp, NVRAM)) |
ec41c7df | 7412 | tw32(NVRAM_SWARB, SWARB_REQ_CLR0); |
1da177e4 LT |
7413 | return 0; |
7414 | } | |
7415 | ||
7416 | struct fw_info { | |
077f849d JSR |
7417 | unsigned int fw_base; |
7418 | unsigned int fw_len; | |
7419 | const __be32 *fw_data; | |
1da177e4 LT |
7420 | }; |
7421 | ||
7422 | /* tp->lock is held. */ | |
7423 | static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base, | |
7424 | int cpu_scratch_size, struct fw_info *info) | |
7425 | { | |
ec41c7df | 7426 | int err, lock_err, i; |
1da177e4 LT |
7427 | void (*write_op)(struct tg3 *, u32, u32); |
7428 | ||
63c3a66f | 7429 | if (cpu_base == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)) { |
5129c3a3 MC |
7430 | netdev_err(tp->dev, |
7431 | "%s: Trying to load TX cpu firmware which is 5705\n", | |
05dbe005 | 7432 | __func__); |
1da177e4 LT |
7433 | return -EINVAL; |
7434 | } | |
7435 | ||
63c3a66f | 7436 | if (tg3_flag(tp, 5705_PLUS)) |
1da177e4 LT |
7437 | write_op = tg3_write_mem; |
7438 | else | |
7439 | write_op = tg3_write_indirect_reg32; | |
7440 | ||
1b628151 MC |
7441 | /* It is possible that bootcode is still loading at this point. |
7442 | * Get the nvram lock first before halting the cpu. | |
7443 | */ | |
ec41c7df | 7444 | lock_err = tg3_nvram_lock(tp); |
1da177e4 | 7445 | err = tg3_halt_cpu(tp, cpu_base); |
ec41c7df MC |
7446 | if (!lock_err) |
7447 | tg3_nvram_unlock(tp); | |
1da177e4 LT |
7448 | if (err) |
7449 | goto out; | |
7450 | ||
7451 | for (i = 0; i < cpu_scratch_size; i += sizeof(u32)) | |
7452 | write_op(tp, cpu_scratch_base + i, 0); | |
7453 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
7454 | tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT); | |
077f849d | 7455 | for (i = 0; i < (info->fw_len / sizeof(u32)); i++) |
1da177e4 | 7456 | write_op(tp, (cpu_scratch_base + |
077f849d | 7457 | (info->fw_base & 0xffff) + |
1da177e4 | 7458 | (i * sizeof(u32))), |
077f849d | 7459 | be32_to_cpu(info->fw_data[i])); |
1da177e4 LT |
7460 | |
7461 | err = 0; | |
7462 | ||
7463 | out: | |
1da177e4 LT |
7464 | return err; |
7465 | } | |
7466 | ||
7467 | /* tp->lock is held. */ | |
7468 | static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp) | |
7469 | { | |
7470 | struct fw_info info; | |
077f849d | 7471 | const __be32 *fw_data; |
1da177e4 LT |
7472 | int err, i; |
7473 | ||
077f849d JSR |
7474 | fw_data = (void *)tp->fw->data; |
7475 | ||
7476 | /* Firmware blob starts with version numbers, followed by | |
7477 | start address and length. We are setting complete length. | |
7478 | length = end_address_of_bss - start_address_of_text. | |
7479 | Remainder is the blob to be loaded contiguously | |
7480 | from start address. */ | |
7481 | ||
7482 | info.fw_base = be32_to_cpu(fw_data[1]); | |
7483 | info.fw_len = tp->fw->size - 12; | |
7484 | info.fw_data = &fw_data[3]; | |
1da177e4 LT |
7485 | |
7486 | err = tg3_load_firmware_cpu(tp, RX_CPU_BASE, | |
7487 | RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE, | |
7488 | &info); | |
7489 | if (err) | |
7490 | return err; | |
7491 | ||
7492 | err = tg3_load_firmware_cpu(tp, TX_CPU_BASE, | |
7493 | TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE, | |
7494 | &info); | |
7495 | if (err) | |
7496 | return err; | |
7497 | ||
7498 | /* Now startup only the RX cpu. */ | |
7499 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); | |
077f849d | 7500 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
1da177e4 LT |
7501 | |
7502 | for (i = 0; i < 5; i++) { | |
077f849d | 7503 | if (tr32(RX_CPU_BASE + CPU_PC) == info.fw_base) |
1da177e4 LT |
7504 | break; |
7505 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); | |
7506 | tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT); | |
077f849d | 7507 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
1da177e4 LT |
7508 | udelay(1000); |
7509 | } | |
7510 | if (i >= 5) { | |
5129c3a3 MC |
7511 | netdev_err(tp->dev, "%s fails to set RX CPU PC, is %08x " |
7512 | "should be %08x\n", __func__, | |
05dbe005 | 7513 | tr32(RX_CPU_BASE + CPU_PC), info.fw_base); |
1da177e4 LT |
7514 | return -ENODEV; |
7515 | } | |
7516 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); | |
7517 | tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000); | |
7518 | ||
7519 | return 0; | |
7520 | } | |
7521 | ||
1da177e4 LT |
7522 | /* tp->lock is held. */ |
7523 | static int tg3_load_tso_firmware(struct tg3 *tp) | |
7524 | { | |
7525 | struct fw_info info; | |
077f849d | 7526 | const __be32 *fw_data; |
1da177e4 LT |
7527 | unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size; |
7528 | int err, i; | |
7529 | ||
63c3a66f JP |
7530 | if (tg3_flag(tp, HW_TSO_1) || |
7531 | tg3_flag(tp, HW_TSO_2) || | |
7532 | tg3_flag(tp, HW_TSO_3)) | |
1da177e4 LT |
7533 | return 0; |
7534 | ||
077f849d JSR |
7535 | fw_data = (void *)tp->fw->data; |
7536 | ||
7537 | /* Firmware blob starts with version numbers, followed by | |
7538 | start address and length. We are setting complete length. | |
7539 | length = end_address_of_bss - start_address_of_text. | |
7540 | Remainder is the blob to be loaded contiguously | |
7541 | from start address. */ | |
7542 | ||
7543 | info.fw_base = be32_to_cpu(fw_data[1]); | |
7544 | cpu_scratch_size = tp->fw_len; | |
7545 | info.fw_len = tp->fw->size - 12; | |
7546 | info.fw_data = &fw_data[3]; | |
7547 | ||
1da177e4 | 7548 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
1da177e4 LT |
7549 | cpu_base = RX_CPU_BASE; |
7550 | cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705; | |
1da177e4 | 7551 | } else { |
1da177e4 LT |
7552 | cpu_base = TX_CPU_BASE; |
7553 | cpu_scratch_base = TX_CPU_SCRATCH_BASE; | |
7554 | cpu_scratch_size = TX_CPU_SCRATCH_SIZE; | |
7555 | } | |
7556 | ||
7557 | err = tg3_load_firmware_cpu(tp, cpu_base, | |
7558 | cpu_scratch_base, cpu_scratch_size, | |
7559 | &info); | |
7560 | if (err) | |
7561 | return err; | |
7562 | ||
7563 | /* Now startup the cpu. */ | |
7564 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
077f849d | 7565 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
1da177e4 LT |
7566 | |
7567 | for (i = 0; i < 5; i++) { | |
077f849d | 7568 | if (tr32(cpu_base + CPU_PC) == info.fw_base) |
1da177e4 LT |
7569 | break; |
7570 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
7571 | tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); | |
077f849d | 7572 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
1da177e4 LT |
7573 | udelay(1000); |
7574 | } | |
7575 | if (i >= 5) { | |
5129c3a3 MC |
7576 | netdev_err(tp->dev, |
7577 | "%s fails to set CPU PC, is %08x should be %08x\n", | |
05dbe005 | 7578 | __func__, tr32(cpu_base + CPU_PC), info.fw_base); |
1da177e4 LT |
7579 | return -ENODEV; |
7580 | } | |
7581 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
7582 | tw32_f(cpu_base + CPU_MODE, 0x00000000); | |
7583 | return 0; | |
7584 | } | |
7585 | ||
1da177e4 | 7586 | |
1da177e4 LT |
7587 | static int tg3_set_mac_addr(struct net_device *dev, void *p) |
7588 | { | |
7589 | struct tg3 *tp = netdev_priv(dev); | |
7590 | struct sockaddr *addr = p; | |
986e0aeb | 7591 | int err = 0, skip_mac_1 = 0; |
1da177e4 | 7592 | |
f9804ddb MC |
7593 | if (!is_valid_ether_addr(addr->sa_data)) |
7594 | return -EINVAL; | |
7595 | ||
1da177e4 LT |
7596 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
7597 | ||
e75f7c90 MC |
7598 | if (!netif_running(dev)) |
7599 | return 0; | |
7600 | ||
63c3a66f | 7601 | if (tg3_flag(tp, ENABLE_ASF)) { |
986e0aeb | 7602 | u32 addr0_high, addr0_low, addr1_high, addr1_low; |
58712ef9 | 7603 | |
986e0aeb MC |
7604 | addr0_high = tr32(MAC_ADDR_0_HIGH); |
7605 | addr0_low = tr32(MAC_ADDR_0_LOW); | |
7606 | addr1_high = tr32(MAC_ADDR_1_HIGH); | |
7607 | addr1_low = tr32(MAC_ADDR_1_LOW); | |
7608 | ||
7609 | /* Skip MAC addr 1 if ASF is using it. */ | |
7610 | if ((addr0_high != addr1_high || addr0_low != addr1_low) && | |
7611 | !(addr1_high == 0 && addr1_low == 0)) | |
7612 | skip_mac_1 = 1; | |
58712ef9 | 7613 | } |
986e0aeb MC |
7614 | spin_lock_bh(&tp->lock); |
7615 | __tg3_set_mac_addr(tp, skip_mac_1); | |
7616 | spin_unlock_bh(&tp->lock); | |
1da177e4 | 7617 | |
b9ec6c1b | 7618 | return err; |
1da177e4 LT |
7619 | } |
7620 | ||
7621 | /* tp->lock is held. */ | |
7622 | static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr, | |
7623 | dma_addr_t mapping, u32 maxlen_flags, | |
7624 | u32 nic_addr) | |
7625 | { | |
7626 | tg3_write_mem(tp, | |
7627 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH), | |
7628 | ((u64) mapping >> 32)); | |
7629 | tg3_write_mem(tp, | |
7630 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW), | |
7631 | ((u64) mapping & 0xffffffff)); | |
7632 | tg3_write_mem(tp, | |
7633 | (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS), | |
7634 | maxlen_flags); | |
7635 | ||
63c3a66f | 7636 | if (!tg3_flag(tp, 5705_PLUS)) |
1da177e4 LT |
7637 | tg3_write_mem(tp, |
7638 | (bdinfo_addr + TG3_BDINFO_NIC_ADDR), | |
7639 | nic_addr); | |
7640 | } | |
7641 | ||
7642 | static void __tg3_set_rx_mode(struct net_device *); | |
d244c892 | 7643 | static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec) |
15f9850d | 7644 | { |
b6080e12 MC |
7645 | int i; |
7646 | ||
63c3a66f | 7647 | if (!tg3_flag(tp, ENABLE_TSS)) { |
b6080e12 MC |
7648 | tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs); |
7649 | tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames); | |
7650 | tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq); | |
b6080e12 MC |
7651 | } else { |
7652 | tw32(HOSTCC_TXCOL_TICKS, 0); | |
7653 | tw32(HOSTCC_TXMAX_FRAMES, 0); | |
7654 | tw32(HOSTCC_TXCOAL_MAXF_INT, 0); | |
19cfaecc | 7655 | } |
b6080e12 | 7656 | |
63c3a66f | 7657 | if (!tg3_flag(tp, ENABLE_RSS)) { |
19cfaecc MC |
7658 | tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs); |
7659 | tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames); | |
7660 | tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq); | |
7661 | } else { | |
b6080e12 MC |
7662 | tw32(HOSTCC_RXCOL_TICKS, 0); |
7663 | tw32(HOSTCC_RXMAX_FRAMES, 0); | |
7664 | tw32(HOSTCC_RXCOAL_MAXF_INT, 0); | |
15f9850d | 7665 | } |
b6080e12 | 7666 | |
63c3a66f | 7667 | if (!tg3_flag(tp, 5705_PLUS)) { |
15f9850d DM |
7668 | u32 val = ec->stats_block_coalesce_usecs; |
7669 | ||
b6080e12 MC |
7670 | tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq); |
7671 | tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq); | |
7672 | ||
15f9850d DM |
7673 | if (!netif_carrier_ok(tp->dev)) |
7674 | val = 0; | |
7675 | ||
7676 | tw32(HOSTCC_STAT_COAL_TICKS, val); | |
7677 | } | |
b6080e12 MC |
7678 | |
7679 | for (i = 0; i < tp->irq_cnt - 1; i++) { | |
7680 | u32 reg; | |
7681 | ||
7682 | reg = HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18; | |
7683 | tw32(reg, ec->rx_coalesce_usecs); | |
b6080e12 MC |
7684 | reg = HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18; |
7685 | tw32(reg, ec->rx_max_coalesced_frames); | |
b6080e12 MC |
7686 | reg = HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18; |
7687 | tw32(reg, ec->rx_max_coalesced_frames_irq); | |
19cfaecc | 7688 | |
63c3a66f | 7689 | if (tg3_flag(tp, ENABLE_TSS)) { |
19cfaecc MC |
7690 | reg = HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18; |
7691 | tw32(reg, ec->tx_coalesce_usecs); | |
7692 | reg = HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18; | |
7693 | tw32(reg, ec->tx_max_coalesced_frames); | |
7694 | reg = HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18; | |
7695 | tw32(reg, ec->tx_max_coalesced_frames_irq); | |
7696 | } | |
b6080e12 MC |
7697 | } |
7698 | ||
7699 | for (; i < tp->irq_max - 1; i++) { | |
7700 | tw32(HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18, 0); | |
b6080e12 | 7701 | tw32(HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18, 0); |
b6080e12 | 7702 | tw32(HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
19cfaecc | 7703 | |
63c3a66f | 7704 | if (tg3_flag(tp, ENABLE_TSS)) { |
19cfaecc MC |
7705 | tw32(HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18, 0); |
7706 | tw32(HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18, 0); | |
7707 | tw32(HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); | |
7708 | } | |
b6080e12 | 7709 | } |
15f9850d | 7710 | } |
1da177e4 | 7711 | |
2d31ecaf MC |
7712 | /* tp->lock is held. */ |
7713 | static void tg3_rings_reset(struct tg3 *tp) | |
7714 | { | |
7715 | int i; | |
f77a6a8e | 7716 | u32 stblk, txrcb, rxrcb, limit; |
2d31ecaf MC |
7717 | struct tg3_napi *tnapi = &tp->napi[0]; |
7718 | ||
7719 | /* Disable all transmit rings but the first. */ | |
63c3a66f | 7720 | if (!tg3_flag(tp, 5705_PLUS)) |
2d31ecaf | 7721 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 16; |
63c3a66f | 7722 | else if (tg3_flag(tp, 5717_PLUS)) |
3d37728b | 7723 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 4; |
b703df6f MC |
7724 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
7725 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 2; | |
2d31ecaf MC |
7726 | else |
7727 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; | |
7728 | ||
7729 | for (txrcb = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; | |
7730 | txrcb < limit; txrcb += TG3_BDINFO_SIZE) | |
7731 | tg3_write_mem(tp, txrcb + TG3_BDINFO_MAXLEN_FLAGS, | |
7732 | BDINFO_FLAGS_DISABLED); | |
7733 | ||
7734 | ||
7735 | /* Disable all receive return rings but the first. */ | |
63c3a66f | 7736 | if (tg3_flag(tp, 5717_PLUS)) |
f6eb9b1f | 7737 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 17; |
63c3a66f | 7738 | else if (!tg3_flag(tp, 5705_PLUS)) |
2d31ecaf | 7739 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 16; |
b703df6f MC |
7740 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
7741 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) | |
2d31ecaf MC |
7742 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 4; |
7743 | else | |
7744 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; | |
7745 | ||
7746 | for (rxrcb = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; | |
7747 | rxrcb < limit; rxrcb += TG3_BDINFO_SIZE) | |
7748 | tg3_write_mem(tp, rxrcb + TG3_BDINFO_MAXLEN_FLAGS, | |
7749 | BDINFO_FLAGS_DISABLED); | |
7750 | ||
7751 | /* Disable interrupts */ | |
7752 | tw32_mailbox_f(tp->napi[0].int_mbox, 1); | |
7753 | ||
7754 | /* Zero mailbox registers. */ | |
63c3a66f | 7755 | if (tg3_flag(tp, SUPPORT_MSIX)) { |
6fd45cb8 | 7756 | for (i = 1; i < tp->irq_max; i++) { |
f77a6a8e MC |
7757 | tp->napi[i].tx_prod = 0; |
7758 | tp->napi[i].tx_cons = 0; | |
63c3a66f | 7759 | if (tg3_flag(tp, ENABLE_TSS)) |
c2353a32 | 7760 | tw32_mailbox(tp->napi[i].prodmbox, 0); |
f77a6a8e MC |
7761 | tw32_rx_mbox(tp->napi[i].consmbox, 0); |
7762 | tw32_mailbox_f(tp->napi[i].int_mbox, 1); | |
7763 | } | |
63c3a66f | 7764 | if (!tg3_flag(tp, ENABLE_TSS)) |
c2353a32 | 7765 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
f77a6a8e MC |
7766 | } else { |
7767 | tp->napi[0].tx_prod = 0; | |
7768 | tp->napi[0].tx_cons = 0; | |
7769 | tw32_mailbox(tp->napi[0].prodmbox, 0); | |
7770 | tw32_rx_mbox(tp->napi[0].consmbox, 0); | |
7771 | } | |
2d31ecaf MC |
7772 | |
7773 | /* Make sure the NIC-based send BD rings are disabled. */ | |
63c3a66f | 7774 | if (!tg3_flag(tp, 5705_PLUS)) { |
2d31ecaf MC |
7775 | u32 mbox = MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
7776 | for (i = 0; i < 16; i++) | |
7777 | tw32_tx_mbox(mbox + i * 8, 0); | |
7778 | } | |
7779 | ||
7780 | txrcb = NIC_SRAM_SEND_RCB; | |
7781 | rxrcb = NIC_SRAM_RCV_RET_RCB; | |
7782 | ||
7783 | /* Clear status block in ram. */ | |
7784 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); | |
7785 | ||
7786 | /* Set status block DMA address */ | |
7787 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, | |
7788 | ((u64) tnapi->status_mapping >> 32)); | |
7789 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, | |
7790 | ((u64) tnapi->status_mapping & 0xffffffff)); | |
7791 | ||
f77a6a8e MC |
7792 | if (tnapi->tx_ring) { |
7793 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, | |
7794 | (TG3_TX_RING_SIZE << | |
7795 | BDINFO_FLAGS_MAXLEN_SHIFT), | |
7796 | NIC_SRAM_TX_BUFFER_DESC); | |
7797 | txrcb += TG3_BDINFO_SIZE; | |
7798 | } | |
7799 | ||
7800 | if (tnapi->rx_rcb) { | |
7801 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, | |
7cb32cf2 MC |
7802 | (tp->rx_ret_ring_mask + 1) << |
7803 | BDINFO_FLAGS_MAXLEN_SHIFT, 0); | |
f77a6a8e MC |
7804 | rxrcb += TG3_BDINFO_SIZE; |
7805 | } | |
7806 | ||
7807 | stblk = HOSTCC_STATBLCK_RING1; | |
2d31ecaf | 7808 | |
f77a6a8e MC |
7809 | for (i = 1, tnapi++; i < tp->irq_cnt; i++, tnapi++) { |
7810 | u64 mapping = (u64)tnapi->status_mapping; | |
7811 | tw32(stblk + TG3_64BIT_REG_HIGH, mapping >> 32); | |
7812 | tw32(stblk + TG3_64BIT_REG_LOW, mapping & 0xffffffff); | |
7813 | ||
7814 | /* Clear status block in ram. */ | |
7815 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); | |
7816 | ||
19cfaecc MC |
7817 | if (tnapi->tx_ring) { |
7818 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, | |
7819 | (TG3_TX_RING_SIZE << | |
7820 | BDINFO_FLAGS_MAXLEN_SHIFT), | |
7821 | NIC_SRAM_TX_BUFFER_DESC); | |
7822 | txrcb += TG3_BDINFO_SIZE; | |
7823 | } | |
f77a6a8e MC |
7824 | |
7825 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, | |
7cb32cf2 | 7826 | ((tp->rx_ret_ring_mask + 1) << |
f77a6a8e MC |
7827 | BDINFO_FLAGS_MAXLEN_SHIFT), 0); |
7828 | ||
7829 | stblk += 8; | |
f77a6a8e MC |
7830 | rxrcb += TG3_BDINFO_SIZE; |
7831 | } | |
2d31ecaf MC |
7832 | } |
7833 | ||
eb07a940 MC |
7834 | static void tg3_setup_rxbd_thresholds(struct tg3 *tp) |
7835 | { | |
7836 | u32 val, bdcache_maxcnt, host_rep_thresh, nic_rep_thresh; | |
7837 | ||
63c3a66f JP |
7838 | if (!tg3_flag(tp, 5750_PLUS) || |
7839 | tg3_flag(tp, 5780_CLASS) || | |
eb07a940 MC |
7840 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || |
7841 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) | |
7842 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5700; | |
7843 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || | |
7844 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787) | |
7845 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5755; | |
7846 | else | |
7847 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5906; | |
7848 | ||
7849 | nic_rep_thresh = min(bdcache_maxcnt / 2, tp->rx_std_max_post); | |
7850 | host_rep_thresh = max_t(u32, tp->rx_pending / 8, 1); | |
7851 | ||
7852 | val = min(nic_rep_thresh, host_rep_thresh); | |
7853 | tw32(RCVBDI_STD_THRESH, val); | |
7854 | ||
63c3a66f | 7855 | if (tg3_flag(tp, 57765_PLUS)) |
eb07a940 MC |
7856 | tw32(STD_REPLENISH_LWM, bdcache_maxcnt); |
7857 | ||
63c3a66f | 7858 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
eb07a940 MC |
7859 | return; |
7860 | ||
63c3a66f | 7861 | if (!tg3_flag(tp, 5705_PLUS)) |
eb07a940 MC |
7862 | bdcache_maxcnt = TG3_SRAM_RX_JMB_BDCACHE_SIZE_5700; |
7863 | else | |
7864 | bdcache_maxcnt = TG3_SRAM_RX_JMB_BDCACHE_SIZE_5717; | |
7865 | ||
7866 | host_rep_thresh = max_t(u32, tp->rx_jumbo_pending / 8, 1); | |
7867 | ||
7868 | val = min(bdcache_maxcnt / 2, host_rep_thresh); | |
7869 | tw32(RCVBDI_JUMBO_THRESH, val); | |
7870 | ||
63c3a66f | 7871 | if (tg3_flag(tp, 57765_PLUS)) |
eb07a940 MC |
7872 | tw32(JMB_REPLENISH_LWM, bdcache_maxcnt); |
7873 | } | |
7874 | ||
1da177e4 | 7875 | /* tp->lock is held. */ |
8e7a22e3 | 7876 | static int tg3_reset_hw(struct tg3 *tp, int reset_phy) |
1da177e4 LT |
7877 | { |
7878 | u32 val, rdmac_mode; | |
7879 | int i, err, limit; | |
8fea32b9 | 7880 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
1da177e4 LT |
7881 | |
7882 | tg3_disable_ints(tp); | |
7883 | ||
7884 | tg3_stop_fw(tp); | |
7885 | ||
7886 | tg3_write_sig_pre_reset(tp, RESET_KIND_INIT); | |
7887 | ||
63c3a66f | 7888 | if (tg3_flag(tp, INIT_COMPLETE)) |
e6de8ad1 | 7889 | tg3_abort_hw(tp, 1); |
1da177e4 | 7890 | |
699c0193 MC |
7891 | /* Enable MAC control of LPI */ |
7892 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) { | |
7893 | tw32_f(TG3_CPMU_EEE_LNKIDL_CTRL, | |
7894 | TG3_CPMU_EEE_LNKIDL_PCIE_NL0 | | |
7895 | TG3_CPMU_EEE_LNKIDL_UART_IDL); | |
7896 | ||
7897 | tw32_f(TG3_CPMU_EEE_CTRL, | |
7898 | TG3_CPMU_EEE_CTRL_EXIT_20_1_US); | |
7899 | ||
a386b901 MC |
7900 | val = TG3_CPMU_EEEMD_ERLY_L1_XIT_DET | |
7901 | TG3_CPMU_EEEMD_LPI_IN_TX | | |
7902 | TG3_CPMU_EEEMD_LPI_IN_RX | | |
7903 | TG3_CPMU_EEEMD_EEE_ENABLE; | |
7904 | ||
7905 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) | |
7906 | val |= TG3_CPMU_EEEMD_SND_IDX_DET_EN; | |
7907 | ||
63c3a66f | 7908 | if (tg3_flag(tp, ENABLE_APE)) |
a386b901 MC |
7909 | val |= TG3_CPMU_EEEMD_APE_TX_DET_EN; |
7910 | ||
7911 | tw32_f(TG3_CPMU_EEE_MODE, val); | |
7912 | ||
7913 | tw32_f(TG3_CPMU_EEE_DBTMR1, | |
7914 | TG3_CPMU_DBTMR1_PCIEXIT_2047US | | |
7915 | TG3_CPMU_DBTMR1_LNKIDLE_2047US); | |
7916 | ||
7917 | tw32_f(TG3_CPMU_EEE_DBTMR2, | |
d7f2ab20 | 7918 | TG3_CPMU_DBTMR2_APE_TX_2047US | |
a386b901 | 7919 | TG3_CPMU_DBTMR2_TXIDXEQ_2047US); |
699c0193 MC |
7920 | } |
7921 | ||
603f1173 | 7922 | if (reset_phy) |
d4d2c558 MC |
7923 | tg3_phy_reset(tp); |
7924 | ||
1da177e4 LT |
7925 | err = tg3_chip_reset(tp); |
7926 | if (err) | |
7927 | return err; | |
7928 | ||
7929 | tg3_write_sig_legacy(tp, RESET_KIND_INIT); | |
7930 | ||
bcb37f6c | 7931 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
d30cdd28 MC |
7932 | val = tr32(TG3_CPMU_CTRL); |
7933 | val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE); | |
7934 | tw32(TG3_CPMU_CTRL, val); | |
9acb961e MC |
7935 | |
7936 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); | |
7937 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; | |
7938 | val |= CPMU_LSPD_10MB_MACCLK_6_25; | |
7939 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); | |
7940 | ||
7941 | val = tr32(TG3_CPMU_LNK_AWARE_PWRMD); | |
7942 | val &= ~CPMU_LNK_AWARE_MACCLK_MASK; | |
7943 | val |= CPMU_LNK_AWARE_MACCLK_6_25; | |
7944 | tw32(TG3_CPMU_LNK_AWARE_PWRMD, val); | |
7945 | ||
7946 | val = tr32(TG3_CPMU_HST_ACC); | |
7947 | val &= ~CPMU_HST_ACC_MACCLK_MASK; | |
7948 | val |= CPMU_HST_ACC_MACCLK_6_25; | |
7949 | tw32(TG3_CPMU_HST_ACC, val); | |
d30cdd28 MC |
7950 | } |
7951 | ||
33466d93 MC |
7952 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
7953 | val = tr32(PCIE_PWR_MGMT_THRESH) & ~PCIE_PWR_MGMT_L1_THRESH_MSK; | |
7954 | val |= PCIE_PWR_MGMT_EXT_ASPM_TMR_EN | | |
7955 | PCIE_PWR_MGMT_L1_THRESH_4MS; | |
7956 | tw32(PCIE_PWR_MGMT_THRESH, val); | |
521e6b90 MC |
7957 | |
7958 | val = tr32(TG3_PCIE_EIDLE_DELAY) & ~TG3_PCIE_EIDLE_DELAY_MASK; | |
7959 | tw32(TG3_PCIE_EIDLE_DELAY, val | TG3_PCIE_EIDLE_DELAY_13_CLKS); | |
7960 | ||
7961 | tw32(TG3_CORR_ERR_STAT, TG3_CORR_ERR_STAT_CLEAR); | |
33466d93 | 7962 | |
f40386c8 MC |
7963 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
7964 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); | |
255ca311 MC |
7965 | } |
7966 | ||
63c3a66f | 7967 | if (tg3_flag(tp, L1PLLPD_EN)) { |
614b0590 MC |
7968 | u32 grc_mode = tr32(GRC_MODE); |
7969 | ||
7970 | /* Access the lower 1K of PL PCIE block registers. */ | |
7971 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; | |
7972 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); | |
7973 | ||
7974 | val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1); | |
7975 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1, | |
7976 | val | TG3_PCIE_PL_LO_PHYCTL1_L1PLLPD_EN); | |
7977 | ||
7978 | tw32(GRC_MODE, grc_mode); | |
7979 | } | |
7980 | ||
5093eedc MC |
7981 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { |
7982 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { | |
7983 | u32 grc_mode = tr32(GRC_MODE); | |
cea46462 | 7984 | |
5093eedc MC |
7985 | /* Access the lower 1K of PL PCIE block registers. */ |
7986 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; | |
7987 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); | |
cea46462 | 7988 | |
5093eedc MC |
7989 | val = tr32(TG3_PCIE_TLDLPL_PORT + |
7990 | TG3_PCIE_PL_LO_PHYCTL5); | |
7991 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL5, | |
7992 | val | TG3_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ); | |
cea46462 | 7993 | |
5093eedc MC |
7994 | tw32(GRC_MODE, grc_mode); |
7995 | } | |
a977dbe8 | 7996 | |
1ff30a59 MC |
7997 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_57765_AX) { |
7998 | u32 grc_mode = tr32(GRC_MODE); | |
7999 | ||
8000 | /* Access the lower 1K of DL PCIE block registers. */ | |
8001 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; | |
8002 | tw32(GRC_MODE, val | GRC_MODE_PCIE_DL_SEL); | |
8003 | ||
8004 | val = tr32(TG3_PCIE_TLDLPL_PORT + | |
8005 | TG3_PCIE_DL_LO_FTSMAX); | |
8006 | val &= ~TG3_PCIE_DL_LO_FTSMAX_MSK; | |
8007 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_DL_LO_FTSMAX, | |
8008 | val | TG3_PCIE_DL_LO_FTSMAX_VAL); | |
8009 | ||
8010 | tw32(GRC_MODE, grc_mode); | |
8011 | } | |
8012 | ||
a977dbe8 MC |
8013 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
8014 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; | |
8015 | val |= CPMU_LSPD_10MB_MACCLK_6_25; | |
8016 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); | |
cea46462 MC |
8017 | } |
8018 | ||
1da177e4 LT |
8019 | /* This works around an issue with Athlon chipsets on |
8020 | * B3 tigon3 silicon. This bit has no effect on any | |
8021 | * other revision. But do not set this on PCI Express | |
795d01c5 | 8022 | * chips and don't even touch the clocks if the CPMU is present. |
1da177e4 | 8023 | */ |
63c3a66f JP |
8024 | if (!tg3_flag(tp, CPMU_PRESENT)) { |
8025 | if (!tg3_flag(tp, PCI_EXPRESS)) | |
795d01c5 MC |
8026 | tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT; |
8027 | tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); | |
8028 | } | |
1da177e4 LT |
8029 | |
8030 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && | |
63c3a66f | 8031 | tg3_flag(tp, PCIX_MODE)) { |
1da177e4 LT |
8032 | val = tr32(TG3PCI_PCISTATE); |
8033 | val |= PCISTATE_RETRY_SAME_DMA; | |
8034 | tw32(TG3PCI_PCISTATE, val); | |
8035 | } | |
8036 | ||
63c3a66f | 8037 | if (tg3_flag(tp, ENABLE_APE)) { |
0d3031d9 MC |
8038 | /* Allow reads and writes to the |
8039 | * APE register and memory space. | |
8040 | */ | |
8041 | val = tr32(TG3PCI_PCISTATE); | |
8042 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | | |
f92d9dc1 MC |
8043 | PCISTATE_ALLOW_APE_SHMEM_WR | |
8044 | PCISTATE_ALLOW_APE_PSPACE_WR; | |
0d3031d9 MC |
8045 | tw32(TG3PCI_PCISTATE, val); |
8046 | } | |
8047 | ||
1da177e4 LT |
8048 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) { |
8049 | /* Enable some hw fixes. */ | |
8050 | val = tr32(TG3PCI_MSI_DATA); | |
8051 | val |= (1 << 26) | (1 << 28) | (1 << 29); | |
8052 | tw32(TG3PCI_MSI_DATA, val); | |
8053 | } | |
8054 | ||
8055 | /* Descriptor ring init may make accesses to the | |
8056 | * NIC SRAM area to setup the TX descriptors, so we | |
8057 | * can only do this after the hardware has been | |
8058 | * successfully reset. | |
8059 | */ | |
32d8c572 MC |
8060 | err = tg3_init_rings(tp); |
8061 | if (err) | |
8062 | return err; | |
1da177e4 | 8063 | |
63c3a66f | 8064 | if (tg3_flag(tp, 57765_PLUS)) { |
cbf9ca6c MC |
8065 | val = tr32(TG3PCI_DMA_RW_CTRL) & |
8066 | ~DMA_RWCTRL_DIS_CACHE_ALIGNMENT; | |
1a319025 MC |
8067 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) |
8068 | val &= ~DMA_RWCTRL_CRDRDR_RDMA_MRRS_MSK; | |
0aebff48 MC |
8069 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57765 && |
8070 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) | |
8071 | val |= DMA_RWCTRL_TAGGED_STAT_WA; | |
cbf9ca6c MC |
8072 | tw32(TG3PCI_DMA_RW_CTRL, val | tp->dma_rwctrl); |
8073 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 && | |
8074 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) { | |
d30cdd28 MC |
8075 | /* This value is determined during the probe time DMA |
8076 | * engine test, tg3_test_dma. | |
8077 | */ | |
8078 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); | |
8079 | } | |
1da177e4 LT |
8080 | |
8081 | tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS | | |
8082 | GRC_MODE_4X_NIC_SEND_RINGS | | |
8083 | GRC_MODE_NO_TX_PHDR_CSUM | | |
8084 | GRC_MODE_NO_RX_PHDR_CSUM); | |
8085 | tp->grc_mode |= GRC_MODE_HOST_SENDBDS; | |
d2d746f8 MC |
8086 | |
8087 | /* Pseudo-header checksum is done by hardware logic and not | |
8088 | * the offload processers, so make the chip do the pseudo- | |
8089 | * header checksums on receive. For transmit it is more | |
8090 | * convenient to do the pseudo-header checksum in software | |
8091 | * as Linux does that on transmit for us in all cases. | |
8092 | */ | |
8093 | tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM; | |
1da177e4 LT |
8094 | |
8095 | tw32(GRC_MODE, | |
8096 | tp->grc_mode | | |
8097 | (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP)); | |
8098 | ||
8099 | /* Setup the timer prescalar register. Clock is always 66Mhz. */ | |
8100 | val = tr32(GRC_MISC_CFG); | |
8101 | val &= ~0xff; | |
8102 | val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT); | |
8103 | tw32(GRC_MISC_CFG, val); | |
8104 | ||
8105 | /* Initialize MBUF/DESC pool. */ | |
63c3a66f | 8106 | if (tg3_flag(tp, 5750_PLUS)) { |
1da177e4 LT |
8107 | /* Do nothing. */ |
8108 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) { | |
8109 | tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE); | |
8110 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) | |
8111 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64); | |
8112 | else | |
8113 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96); | |
8114 | tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE); | |
8115 | tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE); | |
63c3a66f | 8116 | } else if (tg3_flag(tp, TSO_CAPABLE)) { |
1da177e4 LT |
8117 | int fw_len; |
8118 | ||
077f849d | 8119 | fw_len = tp->fw_len; |
1da177e4 LT |
8120 | fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1); |
8121 | tw32(BUFMGR_MB_POOL_ADDR, | |
8122 | NIC_SRAM_MBUF_POOL_BASE5705 + fw_len); | |
8123 | tw32(BUFMGR_MB_POOL_SIZE, | |
8124 | NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00); | |
8125 | } | |
1da177e4 | 8126 | |
0f893dc6 | 8127 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
1da177e4 LT |
8128 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
8129 | tp->bufmgr_config.mbuf_read_dma_low_water); | |
8130 | tw32(BUFMGR_MB_MACRX_LOW_WATER, | |
8131 | tp->bufmgr_config.mbuf_mac_rx_low_water); | |
8132 | tw32(BUFMGR_MB_HIGH_WATER, | |
8133 | tp->bufmgr_config.mbuf_high_water); | |
8134 | } else { | |
8135 | tw32(BUFMGR_MB_RDMA_LOW_WATER, | |
8136 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo); | |
8137 | tw32(BUFMGR_MB_MACRX_LOW_WATER, | |
8138 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo); | |
8139 | tw32(BUFMGR_MB_HIGH_WATER, | |
8140 | tp->bufmgr_config.mbuf_high_water_jumbo); | |
8141 | } | |
8142 | tw32(BUFMGR_DMA_LOW_WATER, | |
8143 | tp->bufmgr_config.dma_low_water); | |
8144 | tw32(BUFMGR_DMA_HIGH_WATER, | |
8145 | tp->bufmgr_config.dma_high_water); | |
8146 | ||
d309a46e MC |
8147 | val = BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE; |
8148 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) | |
8149 | val |= BUFMGR_MODE_NO_TX_UNDERRUN; | |
4d958473 MC |
8150 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
8151 | tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || | |
8152 | tp->pci_chip_rev_id == CHIPREV_ID_5720_A0) | |
8153 | val |= BUFMGR_MODE_MBLOW_ATTN_ENAB; | |
d309a46e | 8154 | tw32(BUFMGR_MODE, val); |
1da177e4 LT |
8155 | for (i = 0; i < 2000; i++) { |
8156 | if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE) | |
8157 | break; | |
8158 | udelay(10); | |
8159 | } | |
8160 | if (i >= 2000) { | |
05dbe005 | 8161 | netdev_err(tp->dev, "%s cannot enable BUFMGR\n", __func__); |
1da177e4 LT |
8162 | return -ENODEV; |
8163 | } | |
8164 | ||
eb07a940 MC |
8165 | if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1) |
8166 | tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2); | |
b5d3772c | 8167 | |
eb07a940 | 8168 | tg3_setup_rxbd_thresholds(tp); |
1da177e4 LT |
8169 | |
8170 | /* Initialize TG3_BDINFO's at: | |
8171 | * RCVDBDI_STD_BD: standard eth size rx ring | |
8172 | * RCVDBDI_JUMBO_BD: jumbo frame rx ring | |
8173 | * RCVDBDI_MINI_BD: small frame rx ring (??? does not work) | |
8174 | * | |
8175 | * like so: | |
8176 | * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring | |
8177 | * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) | | |
8178 | * ring attribute flags | |
8179 | * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM | |
8180 | * | |
8181 | * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries. | |
8182 | * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries. | |
8183 | * | |
8184 | * The size of each ring is fixed in the firmware, but the location is | |
8185 | * configurable. | |
8186 | */ | |
8187 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, | |
21f581a5 | 8188 | ((u64) tpr->rx_std_mapping >> 32)); |
1da177e4 | 8189 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
21f581a5 | 8190 | ((u64) tpr->rx_std_mapping & 0xffffffff)); |
63c3a66f | 8191 | if (!tg3_flag(tp, 5717_PLUS)) |
87668d35 MC |
8192 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR, |
8193 | NIC_SRAM_RX_BUFFER_DESC); | |
1da177e4 | 8194 | |
fdb72b38 | 8195 | /* Disable the mini ring */ |
63c3a66f | 8196 | if (!tg3_flag(tp, 5705_PLUS)) |
1da177e4 LT |
8197 | tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS, |
8198 | BDINFO_FLAGS_DISABLED); | |
8199 | ||
fdb72b38 MC |
8200 | /* Program the jumbo buffer descriptor ring control |
8201 | * blocks on those devices that have them. | |
8202 | */ | |
bb18bb94 | 8203 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
63c3a66f | 8204 | (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS))) { |
1da177e4 | 8205 | |
63c3a66f | 8206 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) { |
1da177e4 | 8207 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
21f581a5 | 8208 | ((u64) tpr->rx_jmb_mapping >> 32)); |
1da177e4 | 8209 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
21f581a5 | 8210 | ((u64) tpr->rx_jmb_mapping & 0xffffffff)); |
de9f5230 MC |
8211 | val = TG3_RX_JMB_RING_SIZE(tp) << |
8212 | BDINFO_FLAGS_MAXLEN_SHIFT; | |
1da177e4 | 8213 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
de9f5230 | 8214 | val | BDINFO_FLAGS_USE_EXT_RECV); |
63c3a66f | 8215 | if (!tg3_flag(tp, USE_JUMBO_BDFLAG) || |
a50d0796 | 8216 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
87668d35 MC |
8217 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR, |
8218 | NIC_SRAM_RX_JUMBO_BUFFER_DESC); | |
1da177e4 LT |
8219 | } else { |
8220 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, | |
8221 | BDINFO_FLAGS_DISABLED); | |
8222 | } | |
8223 | ||
63c3a66f | 8224 | if (tg3_flag(tp, 57765_PLUS)) { |
7cb32cf2 | 8225 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
de9f5230 | 8226 | val = TG3_RX_STD_MAX_SIZE_5700; |
7cb32cf2 | 8227 | else |
de9f5230 | 8228 | val = TG3_RX_STD_MAX_SIZE_5717; |
7cb32cf2 MC |
8229 | val <<= BDINFO_FLAGS_MAXLEN_SHIFT; |
8230 | val |= (TG3_RX_STD_DMA_SZ << 2); | |
8231 | } else | |
04380d40 | 8232 | val = TG3_RX_STD_DMA_SZ << BDINFO_FLAGS_MAXLEN_SHIFT; |
fdb72b38 | 8233 | } else |
de9f5230 | 8234 | val = TG3_RX_STD_MAX_SIZE_5700 << BDINFO_FLAGS_MAXLEN_SHIFT; |
fdb72b38 MC |
8235 | |
8236 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS, val); | |
1da177e4 | 8237 | |
411da640 | 8238 | tpr->rx_std_prod_idx = tp->rx_pending; |
66711e66 | 8239 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, tpr->rx_std_prod_idx); |
1da177e4 | 8240 | |
63c3a66f JP |
8241 | tpr->rx_jmb_prod_idx = |
8242 | tg3_flag(tp, JUMBO_RING_ENABLE) ? tp->rx_jumbo_pending : 0; | |
66711e66 | 8243 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, tpr->rx_jmb_prod_idx); |
1da177e4 | 8244 | |
2d31ecaf MC |
8245 | tg3_rings_reset(tp); |
8246 | ||
1da177e4 | 8247 | /* Initialize MAC address and backoff seed. */ |
986e0aeb | 8248 | __tg3_set_mac_addr(tp, 0); |
1da177e4 LT |
8249 | |
8250 | /* MTU + ethernet header + FCS + optional VLAN tag */ | |
f7b493e0 MC |
8251 | tw32(MAC_RX_MTU_SIZE, |
8252 | tp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); | |
1da177e4 LT |
8253 | |
8254 | /* The slot time is changed by tg3_setup_phy if we | |
8255 | * run at gigabit with half duplex. | |
8256 | */ | |
f2096f94 MC |
8257 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
8258 | (6 << TX_LENGTHS_IPG_SHIFT) | | |
8259 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT); | |
8260 | ||
8261 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) | |
8262 | val |= tr32(MAC_TX_LENGTHS) & | |
8263 | (TX_LENGTHS_JMB_FRM_LEN_MSK | | |
8264 | TX_LENGTHS_CNT_DWN_VAL_MSK); | |
8265 | ||
8266 | tw32(MAC_TX_LENGTHS, val); | |
1da177e4 LT |
8267 | |
8268 | /* Receive rules. */ | |
8269 | tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS); | |
8270 | tw32(RCVLPC_CONFIG, 0x0181); | |
8271 | ||
8272 | /* Calculate RDMAC_MODE setting early, we need it to determine | |
8273 | * the RCVLPC_STATE_ENABLE mask. | |
8274 | */ | |
8275 | rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB | | |
8276 | RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB | | |
8277 | RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB | | |
8278 | RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB | | |
8279 | RDMAC_MODE_LNGREAD_ENAB); | |
85e94ced | 8280 | |
deabaac8 | 8281 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) |
0339e4e3 MC |
8282 | rdmac_mode |= RDMAC_MODE_MULT_DMA_RD_DIS; |
8283 | ||
57e6983c | 8284 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
321d32a0 MC |
8285 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
8286 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) | |
d30cdd28 MC |
8287 | rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB | |
8288 | RDMAC_MODE_MBUF_RBD_CRPT_ENAB | | |
8289 | RDMAC_MODE_MBUF_SBD_CRPT_ENAB; | |
8290 | ||
c5908939 MC |
8291 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
8292 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { | |
63c3a66f | 8293 | if (tg3_flag(tp, TSO_CAPABLE) && |
c13e3713 | 8294 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
1da177e4 LT |
8295 | rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128; |
8296 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && | |
63c3a66f | 8297 | !tg3_flag(tp, IS_5788)) { |
1da177e4 LT |
8298 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
8299 | } | |
8300 | } | |
8301 | ||
63c3a66f | 8302 | if (tg3_flag(tp, PCI_EXPRESS)) |
85e94ced MC |
8303 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
8304 | ||
63c3a66f JP |
8305 | if (tg3_flag(tp, HW_TSO_1) || |
8306 | tg3_flag(tp, HW_TSO_2) || | |
8307 | tg3_flag(tp, HW_TSO_3)) | |
027455ad MC |
8308 | rdmac_mode |= RDMAC_MODE_IPV4_LSO_EN; |
8309 | ||
108a6c16 | 8310 | if (tg3_flag(tp, 57765_PLUS) || |
e849cdc3 | 8311 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
027455ad MC |
8312 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
8313 | rdmac_mode |= RDMAC_MODE_IPV6_LSO_EN; | |
1da177e4 | 8314 | |
f2096f94 MC |
8315 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
8316 | rdmac_mode |= tr32(RDMAC_MODE) & RDMAC_MODE_H2BNC_VLAN_DET; | |
8317 | ||
41a8a7ee MC |
8318 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
8319 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || | |
8320 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || | |
8321 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || | |
63c3a66f | 8322 | tg3_flag(tp, 57765_PLUS)) { |
41a8a7ee | 8323 | val = tr32(TG3_RDMA_RSRVCTRL_REG); |
d78b59f5 MC |
8324 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
8325 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { | |
b4495ed8 MC |
8326 | val &= ~(TG3_RDMA_RSRVCTRL_TXMRGN_MASK | |
8327 | TG3_RDMA_RSRVCTRL_FIFO_LWM_MASK | | |
8328 | TG3_RDMA_RSRVCTRL_FIFO_HWM_MASK); | |
8329 | val |= TG3_RDMA_RSRVCTRL_TXMRGN_320B | | |
8330 | TG3_RDMA_RSRVCTRL_FIFO_LWM_1_5K | | |
8331 | TG3_RDMA_RSRVCTRL_FIFO_HWM_1_5K; | |
b75cc0e4 | 8332 | } |
41a8a7ee MC |
8333 | tw32(TG3_RDMA_RSRVCTRL_REG, |
8334 | val | TG3_RDMA_RSRVCTRL_FIFO_OFLW_FIX); | |
8335 | } | |
8336 | ||
d78b59f5 MC |
8337 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
8338 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { | |
d309a46e MC |
8339 | val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); |
8340 | tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val | | |
8341 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_BD_4K | | |
8342 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_LSO_4K); | |
8343 | } | |
8344 | ||
1da177e4 | 8345 | /* Receive/send statistics. */ |
63c3a66f | 8346 | if (tg3_flag(tp, 5750_PLUS)) { |
1661394e MC |
8347 | val = tr32(RCVLPC_STATS_ENABLE); |
8348 | val &= ~RCVLPC_STATSENAB_DACK_FIX; | |
8349 | tw32(RCVLPC_STATS_ENABLE, val); | |
8350 | } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) && | |
63c3a66f | 8351 | tg3_flag(tp, TSO_CAPABLE)) { |
1da177e4 LT |
8352 | val = tr32(RCVLPC_STATS_ENABLE); |
8353 | val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX; | |
8354 | tw32(RCVLPC_STATS_ENABLE, val); | |
8355 | } else { | |
8356 | tw32(RCVLPC_STATS_ENABLE, 0xffffff); | |
8357 | } | |
8358 | tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE); | |
8359 | tw32(SNDDATAI_STATSENAB, 0xffffff); | |
8360 | tw32(SNDDATAI_STATSCTRL, | |
8361 | (SNDDATAI_SCTRL_ENABLE | | |
8362 | SNDDATAI_SCTRL_FASTUPD)); | |
8363 | ||
8364 | /* Setup host coalescing engine. */ | |
8365 | tw32(HOSTCC_MODE, 0); | |
8366 | for (i = 0; i < 2000; i++) { | |
8367 | if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE)) | |
8368 | break; | |
8369 | udelay(10); | |
8370 | } | |
8371 | ||
d244c892 | 8372 | __tg3_set_coalesce(tp, &tp->coal); |
1da177e4 | 8373 | |
63c3a66f | 8374 | if (!tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
8375 | /* Status/statistics block address. See tg3_timer, |
8376 | * the tg3_periodic_fetch_stats call there, and | |
8377 | * tg3_get_stats to see how this works for 5705/5750 chips. | |
8378 | */ | |
1da177e4 LT |
8379 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
8380 | ((u64) tp->stats_mapping >> 32)); | |
8381 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, | |
8382 | ((u64) tp->stats_mapping & 0xffffffff)); | |
8383 | tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK); | |
2d31ecaf | 8384 | |
1da177e4 | 8385 | tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK); |
2d31ecaf MC |
8386 | |
8387 | /* Clear statistics and status block memory areas */ | |
8388 | for (i = NIC_SRAM_STATS_BLK; | |
8389 | i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE; | |
8390 | i += sizeof(u32)) { | |
8391 | tg3_write_mem(tp, i, 0); | |
8392 | udelay(40); | |
8393 | } | |
1da177e4 LT |
8394 | } |
8395 | ||
8396 | tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode); | |
8397 | ||
8398 | tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE); | |
8399 | tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE); | |
63c3a66f | 8400 | if (!tg3_flag(tp, 5705_PLUS)) |
1da177e4 LT |
8401 | tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE); |
8402 | ||
f07e9af3 MC |
8403 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
8404 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; | |
c94e3941 MC |
8405 | /* reset to prevent losing 1st rx packet intermittently */ |
8406 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); | |
8407 | udelay(10); | |
8408 | } | |
8409 | ||
63c3a66f | 8410 | if (tg3_flag(tp, ENABLE_APE)) |
d2394e6b | 8411 | tp->mac_mode = MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; |
3bda1258 MC |
8412 | else |
8413 | tp->mac_mode = 0; | |
8414 | tp->mac_mode |= MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE | | |
1da177e4 | 8415 | MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE; |
63c3a66f | 8416 | if (!tg3_flag(tp, 5705_PLUS) && |
f07e9af3 | 8417 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
e8f3f6ca MC |
8418 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) |
8419 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; | |
1da177e4 LT |
8420 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR); |
8421 | udelay(40); | |
8422 | ||
314fba34 | 8423 | /* tp->grc_local_ctrl is partially set up during tg3_get_invariants(). |
63c3a66f | 8424 | * If TG3_FLAG_IS_NIC is zero, we should read the |
314fba34 MC |
8425 | * register to preserve the GPIO settings for LOMs. The GPIOs, |
8426 | * whether used as inputs or outputs, are set by boot code after | |
8427 | * reset. | |
8428 | */ | |
63c3a66f | 8429 | if (!tg3_flag(tp, IS_NIC)) { |
314fba34 MC |
8430 | u32 gpio_mask; |
8431 | ||
9d26e213 MC |
8432 | gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 | |
8433 | GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 | | |
8434 | GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2; | |
3e7d83bc MC |
8435 | |
8436 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) | |
8437 | gpio_mask |= GRC_LCLCTRL_GPIO_OE3 | | |
8438 | GRC_LCLCTRL_GPIO_OUTPUT3; | |
8439 | ||
af36e6b6 MC |
8440 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
8441 | gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL; | |
8442 | ||
aaf84465 | 8443 | tp->grc_local_ctrl &= ~gpio_mask; |
314fba34 MC |
8444 | tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask; |
8445 | ||
8446 | /* GPIO1 must be driven high for eeprom write protect */ | |
63c3a66f | 8447 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) |
9d26e213 MC |
8448 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
8449 | GRC_LCLCTRL_GPIO_OUTPUT1); | |
314fba34 | 8450 | } |
1da177e4 LT |
8451 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
8452 | udelay(100); | |
8453 | ||
63c3a66f | 8454 | if (tg3_flag(tp, USING_MSIX) && tp->irq_cnt > 1) { |
baf8a94a MC |
8455 | val = tr32(MSGINT_MODE); |
8456 | val |= MSGINT_MODE_MULTIVEC_EN | MSGINT_MODE_ENABLE; | |
8457 | tw32(MSGINT_MODE, val); | |
8458 | } | |
8459 | ||
63c3a66f | 8460 | if (!tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
8461 | tw32_f(DMAC_MODE, DMAC_MODE_ENABLE); |
8462 | udelay(40); | |
8463 | } | |
8464 | ||
8465 | val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB | | |
8466 | WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB | | |
8467 | WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB | | |
8468 | WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB | | |
8469 | WDMAC_MODE_LNGREAD_ENAB); | |
8470 | ||
c5908939 MC |
8471 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
8472 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { | |
63c3a66f | 8473 | if (tg3_flag(tp, TSO_CAPABLE) && |
1da177e4 LT |
8474 | (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 || |
8475 | tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) { | |
8476 | /* nothing */ | |
8477 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && | |
63c3a66f | 8478 | !tg3_flag(tp, IS_5788)) { |
1da177e4 LT |
8479 | val |= WDMAC_MODE_RX_ACCEL; |
8480 | } | |
8481 | } | |
8482 | ||
d9ab5ad1 | 8483 | /* Enable host coalescing bug fix */ |
63c3a66f | 8484 | if (tg3_flag(tp, 5755_PLUS)) |
f51f3562 | 8485 | val |= WDMAC_MODE_STATUS_TAG_FIX; |
d9ab5ad1 | 8486 | |
788a035e MC |
8487 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
8488 | val |= WDMAC_MODE_BURST_ALL_DATA; | |
8489 | ||
1da177e4 LT |
8490 | tw32_f(WDMAC_MODE, val); |
8491 | udelay(40); | |
8492 | ||
63c3a66f | 8493 | if (tg3_flag(tp, PCIX_MODE)) { |
9974a356 MC |
8494 | u16 pcix_cmd; |
8495 | ||
8496 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, | |
8497 | &pcix_cmd); | |
1da177e4 | 8498 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) { |
9974a356 MC |
8499 | pcix_cmd &= ~PCI_X_CMD_MAX_READ; |
8500 | pcix_cmd |= PCI_X_CMD_READ_2K; | |
1da177e4 | 8501 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
9974a356 MC |
8502 | pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ); |
8503 | pcix_cmd |= PCI_X_CMD_READ_2K; | |
1da177e4 | 8504 | } |
9974a356 MC |
8505 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
8506 | pcix_cmd); | |
1da177e4 LT |
8507 | } |
8508 | ||
8509 | tw32_f(RDMAC_MODE, rdmac_mode); | |
8510 | udelay(40); | |
8511 | ||
8512 | tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE); | |
63c3a66f | 8513 | if (!tg3_flag(tp, 5705_PLUS)) |
1da177e4 | 8514 | tw32(MBFREE_MODE, MBFREE_MODE_ENABLE); |
9936bcf6 MC |
8515 | |
8516 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) | |
8517 | tw32(SNDDATAC_MODE, | |
8518 | SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY); | |
8519 | else | |
8520 | tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE); | |
8521 | ||
1da177e4 LT |
8522 | tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE); |
8523 | tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB); | |
7cb32cf2 | 8524 | val = RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ; |
63c3a66f | 8525 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
7cb32cf2 MC |
8526 | val |= RCVDBDI_MODE_LRG_RING_SZ; |
8527 | tw32(RCVDBDI_MODE, val); | |
1da177e4 | 8528 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE); |
63c3a66f JP |
8529 | if (tg3_flag(tp, HW_TSO_1) || |
8530 | tg3_flag(tp, HW_TSO_2) || | |
8531 | tg3_flag(tp, HW_TSO_3)) | |
1da177e4 | 8532 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8); |
baf8a94a | 8533 | val = SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE; |
63c3a66f | 8534 | if (tg3_flag(tp, ENABLE_TSS)) |
baf8a94a MC |
8535 | val |= SNDBDI_MODE_MULTI_TXQ_EN; |
8536 | tw32(SNDBDI_MODE, val); | |
1da177e4 LT |
8537 | tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE); |
8538 | ||
8539 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { | |
8540 | err = tg3_load_5701_a0_firmware_fix(tp); | |
8541 | if (err) | |
8542 | return err; | |
8543 | } | |
8544 | ||
63c3a66f | 8545 | if (tg3_flag(tp, TSO_CAPABLE)) { |
1da177e4 LT |
8546 | err = tg3_load_tso_firmware(tp); |
8547 | if (err) | |
8548 | return err; | |
8549 | } | |
1da177e4 LT |
8550 | |
8551 | tp->tx_mode = TX_MODE_ENABLE; | |
f2096f94 | 8552 | |
63c3a66f | 8553 | if (tg3_flag(tp, 5755_PLUS) || |
b1d05210 MC |
8554 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
8555 | tp->tx_mode |= TX_MODE_MBUF_LOCKUP_FIX; | |
f2096f94 MC |
8556 | |
8557 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { | |
8558 | val = TX_MODE_JMB_FRM_LEN | TX_MODE_CNT_DN_MODE; | |
8559 | tp->tx_mode &= ~val; | |
8560 | tp->tx_mode |= tr32(MAC_TX_MODE) & val; | |
8561 | } | |
8562 | ||
1da177e4 LT |
8563 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
8564 | udelay(100); | |
8565 | ||
63c3a66f | 8566 | if (tg3_flag(tp, ENABLE_RSS)) { |
baf8a94a MC |
8567 | u32 reg = MAC_RSS_INDIR_TBL_0; |
8568 | u8 *ent = (u8 *)&val; | |
8569 | ||
8570 | /* Setup the indirection table */ | |
8571 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) { | |
8572 | int idx = i % sizeof(val); | |
8573 | ||
5efeeea1 | 8574 | ent[idx] = i % (tp->irq_cnt - 1); |
baf8a94a MC |
8575 | if (idx == sizeof(val) - 1) { |
8576 | tw32(reg, val); | |
8577 | reg += 4; | |
8578 | } | |
8579 | } | |
8580 | ||
8581 | /* Setup the "secret" hash key. */ | |
8582 | tw32(MAC_RSS_HASH_KEY_0, 0x5f865437); | |
8583 | tw32(MAC_RSS_HASH_KEY_1, 0xe4ac62cc); | |
8584 | tw32(MAC_RSS_HASH_KEY_2, 0x50103a45); | |
8585 | tw32(MAC_RSS_HASH_KEY_3, 0x36621985); | |
8586 | tw32(MAC_RSS_HASH_KEY_4, 0xbf14c0e8); | |
8587 | tw32(MAC_RSS_HASH_KEY_5, 0x1bc27a1e); | |
8588 | tw32(MAC_RSS_HASH_KEY_6, 0x84f4b556); | |
8589 | tw32(MAC_RSS_HASH_KEY_7, 0x094ea6fe); | |
8590 | tw32(MAC_RSS_HASH_KEY_8, 0x7dda01e7); | |
8591 | tw32(MAC_RSS_HASH_KEY_9, 0xc04d7481); | |
8592 | } | |
8593 | ||
1da177e4 | 8594 | tp->rx_mode = RX_MODE_ENABLE; |
63c3a66f | 8595 | if (tg3_flag(tp, 5755_PLUS)) |
af36e6b6 MC |
8596 | tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE; |
8597 | ||
63c3a66f | 8598 | if (tg3_flag(tp, ENABLE_RSS)) |
baf8a94a MC |
8599 | tp->rx_mode |= RX_MODE_RSS_ENABLE | |
8600 | RX_MODE_RSS_ITBL_HASH_BITS_7 | | |
8601 | RX_MODE_RSS_IPV6_HASH_EN | | |
8602 | RX_MODE_RSS_TCP_IPV6_HASH_EN | | |
8603 | RX_MODE_RSS_IPV4_HASH_EN | | |
8604 | RX_MODE_RSS_TCP_IPV4_HASH_EN; | |
8605 | ||
1da177e4 LT |
8606 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
8607 | udelay(10); | |
8608 | ||
1da177e4 LT |
8609 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
8610 | ||
8611 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); | |
f07e9af3 | 8612 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
1da177e4 LT |
8613 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
8614 | udelay(10); | |
8615 | } | |
8616 | tw32_f(MAC_RX_MODE, tp->rx_mode); | |
8617 | udelay(10); | |
8618 | ||
f07e9af3 | 8619 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
1da177e4 | 8620 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) && |
f07e9af3 | 8621 | !(tp->phy_flags & TG3_PHYFLG_SERDES_PREEMPHASIS)) { |
1da177e4 LT |
8622 | /* Set drive transmission level to 1.2V */ |
8623 | /* only if the signal pre-emphasis bit is not set */ | |
8624 | val = tr32(MAC_SERDES_CFG); | |
8625 | val &= 0xfffff000; | |
8626 | val |= 0x880; | |
8627 | tw32(MAC_SERDES_CFG, val); | |
8628 | } | |
8629 | if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) | |
8630 | tw32(MAC_SERDES_CFG, 0x616000); | |
8631 | } | |
8632 | ||
8633 | /* Prevent chip from dropping frames when flow control | |
8634 | * is enabled. | |
8635 | */ | |
666bc831 MC |
8636 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
8637 | val = 1; | |
8638 | else | |
8639 | val = 2; | |
8640 | tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, val); | |
1da177e4 LT |
8641 | |
8642 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 && | |
f07e9af3 | 8643 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
1da177e4 | 8644 | /* Use hardware link auto-negotiation */ |
63c3a66f | 8645 | tg3_flag_set(tp, HW_AUTONEG); |
1da177e4 LT |
8646 | } |
8647 | ||
f07e9af3 | 8648 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
d4d2c558 MC |
8649 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) { |
8650 | u32 tmp; | |
8651 | ||
8652 | tmp = tr32(SERDES_RX_CTRL); | |
8653 | tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT); | |
8654 | tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT; | |
8655 | tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT; | |
8656 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl); | |
8657 | } | |
8658 | ||
63c3a66f | 8659 | if (!tg3_flag(tp, USE_PHYLIB)) { |
80096068 MC |
8660 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
8661 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; | |
dd477003 MC |
8662 | tp->link_config.speed = tp->link_config.orig_speed; |
8663 | tp->link_config.duplex = tp->link_config.orig_duplex; | |
8664 | tp->link_config.autoneg = tp->link_config.orig_autoneg; | |
8665 | } | |
1da177e4 | 8666 | |
dd477003 MC |
8667 | err = tg3_setup_phy(tp, 0); |
8668 | if (err) | |
8669 | return err; | |
1da177e4 | 8670 | |
f07e9af3 MC |
8671 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
8672 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { | |
dd477003 MC |
8673 | u32 tmp; |
8674 | ||
8675 | /* Clear CRC stats. */ | |
8676 | if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) { | |
8677 | tg3_writephy(tp, MII_TG3_TEST1, | |
8678 | tmp | MII_TG3_TEST1_CRC_EN); | |
f08aa1a8 | 8679 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &tmp); |
dd477003 | 8680 | } |
1da177e4 LT |
8681 | } |
8682 | } | |
8683 | ||
8684 | __tg3_set_rx_mode(tp->dev); | |
8685 | ||
8686 | /* Initialize receive rules. */ | |
8687 | tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK); | |
8688 | tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK); | |
8689 | tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK); | |
8690 | tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK); | |
8691 | ||
63c3a66f | 8692 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) |
1da177e4 LT |
8693 | limit = 8; |
8694 | else | |
8695 | limit = 16; | |
63c3a66f | 8696 | if (tg3_flag(tp, ENABLE_ASF)) |
1da177e4 LT |
8697 | limit -= 4; |
8698 | switch (limit) { | |
8699 | case 16: | |
8700 | tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0); | |
8701 | case 15: | |
8702 | tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0); | |
8703 | case 14: | |
8704 | tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0); | |
8705 | case 13: | |
8706 | tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0); | |
8707 | case 12: | |
8708 | tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0); | |
8709 | case 11: | |
8710 | tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0); | |
8711 | case 10: | |
8712 | tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0); | |
8713 | case 9: | |
8714 | tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0); | |
8715 | case 8: | |
8716 | tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0); | |
8717 | case 7: | |
8718 | tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0); | |
8719 | case 6: | |
8720 | tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0); | |
8721 | case 5: | |
8722 | tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0); | |
8723 | case 4: | |
8724 | /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */ | |
8725 | case 3: | |
8726 | /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */ | |
8727 | case 2: | |
8728 | case 1: | |
8729 | ||
8730 | default: | |
8731 | break; | |
855e1111 | 8732 | } |
1da177e4 | 8733 | |
63c3a66f | 8734 | if (tg3_flag(tp, ENABLE_APE)) |
9ce768ea MC |
8735 | /* Write our heartbeat update interval to APE. */ |
8736 | tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS, | |
8737 | APE_HOST_HEARTBEAT_INT_DISABLE); | |
0d3031d9 | 8738 | |
1da177e4 LT |
8739 | tg3_write_sig_post_reset(tp, RESET_KIND_INIT); |
8740 | ||
1da177e4 LT |
8741 | return 0; |
8742 | } | |
8743 | ||
8744 | /* Called at device open time to get the chip ready for | |
8745 | * packet processing. Invoked with tp->lock held. | |
8746 | */ | |
8e7a22e3 | 8747 | static int tg3_init_hw(struct tg3 *tp, int reset_phy) |
1da177e4 | 8748 | { |
1da177e4 LT |
8749 | tg3_switch_clocks(tp); |
8750 | ||
8751 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
8752 | ||
2f751b67 | 8753 | return tg3_reset_hw(tp, reset_phy); |
1da177e4 LT |
8754 | } |
8755 | ||
8756 | #define TG3_STAT_ADD32(PSTAT, REG) \ | |
8757 | do { u32 __val = tr32(REG); \ | |
8758 | (PSTAT)->low += __val; \ | |
8759 | if ((PSTAT)->low < __val) \ | |
8760 | (PSTAT)->high += 1; \ | |
8761 | } while (0) | |
8762 | ||
8763 | static void tg3_periodic_fetch_stats(struct tg3 *tp) | |
8764 | { | |
8765 | struct tg3_hw_stats *sp = tp->hw_stats; | |
8766 | ||
8767 | if (!netif_carrier_ok(tp->dev)) | |
8768 | return; | |
8769 | ||
8770 | TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS); | |
8771 | TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS); | |
8772 | TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT); | |
8773 | TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT); | |
8774 | TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS); | |
8775 | TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS); | |
8776 | TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS); | |
8777 | TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED); | |
8778 | TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL); | |
8779 | TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL); | |
8780 | TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST); | |
8781 | TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST); | |
8782 | TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST); | |
8783 | ||
8784 | TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS); | |
8785 | TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS); | |
8786 | TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST); | |
8787 | TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST); | |
8788 | TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST); | |
8789 | TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS); | |
8790 | TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS); | |
8791 | TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD); | |
8792 | TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD); | |
8793 | TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD); | |
8794 | TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED); | |
8795 | TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG); | |
8796 | TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS); | |
8797 | TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE); | |
463d305b MC |
8798 | |
8799 | TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT); | |
4d958473 MC |
8800 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717) { |
8801 | TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT); | |
8802 | } else { | |
8803 | u32 val = tr32(HOSTCC_FLOW_ATTN); | |
8804 | val = (val & HOSTCC_FLOW_ATTN_MBUF_LWM) ? 1 : 0; | |
8805 | if (val) { | |
8806 | tw32(HOSTCC_FLOW_ATTN, HOSTCC_FLOW_ATTN_MBUF_LWM); | |
8807 | sp->rx_discards.low += val; | |
8808 | if (sp->rx_discards.low < val) | |
8809 | sp->rx_discards.high += 1; | |
8810 | } | |
8811 | sp->mbuf_lwm_thresh_hit = sp->rx_discards; | |
8812 | } | |
463d305b | 8813 | TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT); |
1da177e4 LT |
8814 | } |
8815 | ||
8816 | static void tg3_timer(unsigned long __opaque) | |
8817 | { | |
8818 | struct tg3 *tp = (struct tg3 *) __opaque; | |
1da177e4 | 8819 | |
f475f163 MC |
8820 | if (tp->irq_sync) |
8821 | goto restart_timer; | |
8822 | ||
f47c11ee | 8823 | spin_lock(&tp->lock); |
1da177e4 | 8824 | |
63c3a66f | 8825 | if (!tg3_flag(tp, TAGGED_STATUS)) { |
fac9b83e DM |
8826 | /* All of this garbage is because when using non-tagged |
8827 | * IRQ status the mailbox/status_block protocol the chip | |
8828 | * uses with the cpu is race prone. | |
8829 | */ | |
898a56f8 | 8830 | if (tp->napi[0].hw_status->status & SD_STATUS_UPDATED) { |
fac9b83e DM |
8831 | tw32(GRC_LOCAL_CTRL, |
8832 | tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); | |
8833 | } else { | |
8834 | tw32(HOSTCC_MODE, tp->coalesce_mode | | |
fd2ce37f | 8835 | HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW); |
fac9b83e | 8836 | } |
1da177e4 | 8837 | |
fac9b83e | 8838 | if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
63c3a66f | 8839 | tg3_flag_set(tp, RESTART_TIMER); |
f47c11ee | 8840 | spin_unlock(&tp->lock); |
fac9b83e DM |
8841 | schedule_work(&tp->reset_task); |
8842 | return; | |
8843 | } | |
1da177e4 LT |
8844 | } |
8845 | ||
1da177e4 LT |
8846 | /* This part only runs once per second. */ |
8847 | if (!--tp->timer_counter) { | |
63c3a66f | 8848 | if (tg3_flag(tp, 5705_PLUS)) |
fac9b83e DM |
8849 | tg3_periodic_fetch_stats(tp); |
8850 | ||
b0c5943f MC |
8851 | if (tp->setlpicnt && !--tp->setlpicnt) |
8852 | tg3_phy_eee_enable(tp); | |
52b02d04 | 8853 | |
63c3a66f | 8854 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
1da177e4 LT |
8855 | u32 mac_stat; |
8856 | int phy_event; | |
8857 | ||
8858 | mac_stat = tr32(MAC_STATUS); | |
8859 | ||
8860 | phy_event = 0; | |
f07e9af3 | 8861 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) { |
1da177e4 LT |
8862 | if (mac_stat & MAC_STATUS_MI_INTERRUPT) |
8863 | phy_event = 1; | |
8864 | } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED) | |
8865 | phy_event = 1; | |
8866 | ||
8867 | if (phy_event) | |
8868 | tg3_setup_phy(tp, 0); | |
63c3a66f | 8869 | } else if (tg3_flag(tp, POLL_SERDES)) { |
1da177e4 LT |
8870 | u32 mac_stat = tr32(MAC_STATUS); |
8871 | int need_setup = 0; | |
8872 | ||
8873 | if (netif_carrier_ok(tp->dev) && | |
8874 | (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) { | |
8875 | need_setup = 1; | |
8876 | } | |
be98da6a | 8877 | if (!netif_carrier_ok(tp->dev) && |
1da177e4 LT |
8878 | (mac_stat & (MAC_STATUS_PCS_SYNCED | |
8879 | MAC_STATUS_SIGNAL_DET))) { | |
8880 | need_setup = 1; | |
8881 | } | |
8882 | if (need_setup) { | |
3d3ebe74 MC |
8883 | if (!tp->serdes_counter) { |
8884 | tw32_f(MAC_MODE, | |
8885 | (tp->mac_mode & | |
8886 | ~MAC_MODE_PORT_MODE_MASK)); | |
8887 | udelay(40); | |
8888 | tw32_f(MAC_MODE, tp->mac_mode); | |
8889 | udelay(40); | |
8890 | } | |
1da177e4 LT |
8891 | tg3_setup_phy(tp, 0); |
8892 | } | |
f07e9af3 | 8893 | } else if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
63c3a66f | 8894 | tg3_flag(tp, 5780_CLASS)) { |
747e8f8b | 8895 | tg3_serdes_parallel_detect(tp); |
57d8b880 | 8896 | } |
1da177e4 LT |
8897 | |
8898 | tp->timer_counter = tp->timer_multiplier; | |
8899 | } | |
8900 | ||
130b8e4d MC |
8901 | /* Heartbeat is only sent once every 2 seconds. |
8902 | * | |
8903 | * The heartbeat is to tell the ASF firmware that the host | |
8904 | * driver is still alive. In the event that the OS crashes, | |
8905 | * ASF needs to reset the hardware to free up the FIFO space | |
8906 | * that may be filled with rx packets destined for the host. | |
8907 | * If the FIFO is full, ASF will no longer function properly. | |
8908 | * | |
8909 | * Unintended resets have been reported on real time kernels | |
8910 | * where the timer doesn't run on time. Netpoll will also have | |
8911 | * same problem. | |
8912 | * | |
8913 | * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware | |
8914 | * to check the ring condition when the heartbeat is expiring | |
8915 | * before doing the reset. This will prevent most unintended | |
8916 | * resets. | |
8917 | */ | |
1da177e4 | 8918 | if (!--tp->asf_counter) { |
63c3a66f | 8919 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
7c5026aa MC |
8920 | tg3_wait_for_event_ack(tp); |
8921 | ||
bbadf503 | 8922 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, |
130b8e4d | 8923 | FWCMD_NICDRV_ALIVE3); |
bbadf503 | 8924 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); |
c6cdf436 MC |
8925 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, |
8926 | TG3_FW_UPDATE_TIMEOUT_SEC); | |
4ba526ce MC |
8927 | |
8928 | tg3_generate_fw_event(tp); | |
1da177e4 LT |
8929 | } |
8930 | tp->asf_counter = tp->asf_multiplier; | |
8931 | } | |
8932 | ||
f47c11ee | 8933 | spin_unlock(&tp->lock); |
1da177e4 | 8934 | |
f475f163 | 8935 | restart_timer: |
1da177e4 LT |
8936 | tp->timer.expires = jiffies + tp->timer_offset; |
8937 | add_timer(&tp->timer); | |
8938 | } | |
8939 | ||
4f125f42 | 8940 | static int tg3_request_irq(struct tg3 *tp, int irq_num) |
fcfa0a32 | 8941 | { |
7d12e780 | 8942 | irq_handler_t fn; |
fcfa0a32 | 8943 | unsigned long flags; |
4f125f42 MC |
8944 | char *name; |
8945 | struct tg3_napi *tnapi = &tp->napi[irq_num]; | |
8946 | ||
8947 | if (tp->irq_cnt == 1) | |
8948 | name = tp->dev->name; | |
8949 | else { | |
8950 | name = &tnapi->irq_lbl[0]; | |
8951 | snprintf(name, IFNAMSIZ, "%s-%d", tp->dev->name, irq_num); | |
8952 | name[IFNAMSIZ-1] = 0; | |
8953 | } | |
fcfa0a32 | 8954 | |
63c3a66f | 8955 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
fcfa0a32 | 8956 | fn = tg3_msi; |
63c3a66f | 8957 | if (tg3_flag(tp, 1SHOT_MSI)) |
fcfa0a32 | 8958 | fn = tg3_msi_1shot; |
ab392d2d | 8959 | flags = 0; |
fcfa0a32 MC |
8960 | } else { |
8961 | fn = tg3_interrupt; | |
63c3a66f | 8962 | if (tg3_flag(tp, TAGGED_STATUS)) |
fcfa0a32 | 8963 | fn = tg3_interrupt_tagged; |
ab392d2d | 8964 | flags = IRQF_SHARED; |
fcfa0a32 | 8965 | } |
4f125f42 MC |
8966 | |
8967 | return request_irq(tnapi->irq_vec, fn, flags, name, tnapi); | |
fcfa0a32 MC |
8968 | } |
8969 | ||
7938109f MC |
8970 | static int tg3_test_interrupt(struct tg3 *tp) |
8971 | { | |
09943a18 | 8972 | struct tg3_napi *tnapi = &tp->napi[0]; |
7938109f | 8973 | struct net_device *dev = tp->dev; |
b16250e3 | 8974 | int err, i, intr_ok = 0; |
f6eb9b1f | 8975 | u32 val; |
7938109f | 8976 | |
d4bc3927 MC |
8977 | if (!netif_running(dev)) |
8978 | return -ENODEV; | |
8979 | ||
7938109f MC |
8980 | tg3_disable_ints(tp); |
8981 | ||
4f125f42 | 8982 | free_irq(tnapi->irq_vec, tnapi); |
7938109f | 8983 | |
f6eb9b1f MC |
8984 | /* |
8985 | * Turn off MSI one shot mode. Otherwise this test has no | |
8986 | * observable way to know whether the interrupt was delivered. | |
8987 | */ | |
63c3a66f | 8988 | if (tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, USING_MSI)) { |
f6eb9b1f MC |
8989 | val = tr32(MSGINT_MODE) | MSGINT_MODE_ONE_SHOT_DISABLE; |
8990 | tw32(MSGINT_MODE, val); | |
8991 | } | |
8992 | ||
4f125f42 | 8993 | err = request_irq(tnapi->irq_vec, tg3_test_isr, |
09943a18 | 8994 | IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, tnapi); |
7938109f MC |
8995 | if (err) |
8996 | return err; | |
8997 | ||
898a56f8 | 8998 | tnapi->hw_status->status &= ~SD_STATUS_UPDATED; |
7938109f MC |
8999 | tg3_enable_ints(tp); |
9000 | ||
9001 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | | |
fd2ce37f | 9002 | tnapi->coal_now); |
7938109f MC |
9003 | |
9004 | for (i = 0; i < 5; i++) { | |
b16250e3 MC |
9005 | u32 int_mbox, misc_host_ctrl; |
9006 | ||
898a56f8 | 9007 | int_mbox = tr32_mailbox(tnapi->int_mbox); |
b16250e3 MC |
9008 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
9009 | ||
9010 | if ((int_mbox != 0) || | |
9011 | (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) { | |
9012 | intr_ok = 1; | |
7938109f | 9013 | break; |
b16250e3 MC |
9014 | } |
9015 | ||
7938109f MC |
9016 | msleep(10); |
9017 | } | |
9018 | ||
9019 | tg3_disable_ints(tp); | |
9020 | ||
4f125f42 | 9021 | free_irq(tnapi->irq_vec, tnapi); |
6aa20a22 | 9022 | |
4f125f42 | 9023 | err = tg3_request_irq(tp, 0); |
7938109f MC |
9024 | |
9025 | if (err) | |
9026 | return err; | |
9027 | ||
f6eb9b1f MC |
9028 | if (intr_ok) { |
9029 | /* Reenable MSI one shot mode. */ | |
63c3a66f | 9030 | if (tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, USING_MSI)) { |
f6eb9b1f MC |
9031 | val = tr32(MSGINT_MODE) & ~MSGINT_MODE_ONE_SHOT_DISABLE; |
9032 | tw32(MSGINT_MODE, val); | |
9033 | } | |
7938109f | 9034 | return 0; |
f6eb9b1f | 9035 | } |
7938109f MC |
9036 | |
9037 | return -EIO; | |
9038 | } | |
9039 | ||
9040 | /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is | |
9041 | * successfully restored | |
9042 | */ | |
9043 | static int tg3_test_msi(struct tg3 *tp) | |
9044 | { | |
7938109f MC |
9045 | int err; |
9046 | u16 pci_cmd; | |
9047 | ||
63c3a66f | 9048 | if (!tg3_flag(tp, USING_MSI)) |
7938109f MC |
9049 | return 0; |
9050 | ||
9051 | /* Turn off SERR reporting in case MSI terminates with Master | |
9052 | * Abort. | |
9053 | */ | |
9054 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); | |
9055 | pci_write_config_word(tp->pdev, PCI_COMMAND, | |
9056 | pci_cmd & ~PCI_COMMAND_SERR); | |
9057 | ||
9058 | err = tg3_test_interrupt(tp); | |
9059 | ||
9060 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); | |
9061 | ||
9062 | if (!err) | |
9063 | return 0; | |
9064 | ||
9065 | /* other failures */ | |
9066 | if (err != -EIO) | |
9067 | return err; | |
9068 | ||
9069 | /* MSI test failed, go back to INTx mode */ | |
5129c3a3 MC |
9070 | netdev_warn(tp->dev, "No interrupt was generated using MSI. Switching " |
9071 | "to INTx mode. Please report this failure to the PCI " | |
9072 | "maintainer and include system chipset information\n"); | |
7938109f | 9073 | |
4f125f42 | 9074 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
09943a18 | 9075 | |
7938109f MC |
9076 | pci_disable_msi(tp->pdev); |
9077 | ||
63c3a66f | 9078 | tg3_flag_clear(tp, USING_MSI); |
dc8bf1b1 | 9079 | tp->napi[0].irq_vec = tp->pdev->irq; |
7938109f | 9080 | |
4f125f42 | 9081 | err = tg3_request_irq(tp, 0); |
7938109f MC |
9082 | if (err) |
9083 | return err; | |
9084 | ||
9085 | /* Need to reset the chip because the MSI cycle may have terminated | |
9086 | * with Master Abort. | |
9087 | */ | |
f47c11ee | 9088 | tg3_full_lock(tp, 1); |
7938109f | 9089 | |
944d980e | 9090 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
8e7a22e3 | 9091 | err = tg3_init_hw(tp, 1); |
7938109f | 9092 | |
f47c11ee | 9093 | tg3_full_unlock(tp); |
7938109f MC |
9094 | |
9095 | if (err) | |
4f125f42 | 9096 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
7938109f MC |
9097 | |
9098 | return err; | |
9099 | } | |
9100 | ||
9e9fd12d MC |
9101 | static int tg3_request_firmware(struct tg3 *tp) |
9102 | { | |
9103 | const __be32 *fw_data; | |
9104 | ||
9105 | if (request_firmware(&tp->fw, tp->fw_needed, &tp->pdev->dev)) { | |
05dbe005 JP |
9106 | netdev_err(tp->dev, "Failed to load firmware \"%s\"\n", |
9107 | tp->fw_needed); | |
9e9fd12d MC |
9108 | return -ENOENT; |
9109 | } | |
9110 | ||
9111 | fw_data = (void *)tp->fw->data; | |
9112 | ||
9113 | /* Firmware blob starts with version numbers, followed by | |
9114 | * start address and _full_ length including BSS sections | |
9115 | * (which must be longer than the actual data, of course | |
9116 | */ | |
9117 | ||
9118 | tp->fw_len = be32_to_cpu(fw_data[2]); /* includes bss */ | |
9119 | if (tp->fw_len < (tp->fw->size - 12)) { | |
05dbe005 JP |
9120 | netdev_err(tp->dev, "bogus length %d in \"%s\"\n", |
9121 | tp->fw_len, tp->fw_needed); | |
9e9fd12d MC |
9122 | release_firmware(tp->fw); |
9123 | tp->fw = NULL; | |
9124 | return -EINVAL; | |
9125 | } | |
9126 | ||
9127 | /* We no longer need firmware; we have it. */ | |
9128 | tp->fw_needed = NULL; | |
9129 | return 0; | |
9130 | } | |
9131 | ||
679563f4 MC |
9132 | static bool tg3_enable_msix(struct tg3 *tp) |
9133 | { | |
9134 | int i, rc, cpus = num_online_cpus(); | |
9135 | struct msix_entry msix_ent[tp->irq_max]; | |
9136 | ||
9137 | if (cpus == 1) | |
9138 | /* Just fallback to the simpler MSI mode. */ | |
9139 | return false; | |
9140 | ||
9141 | /* | |
9142 | * We want as many rx rings enabled as there are cpus. | |
9143 | * The first MSIX vector only deals with link interrupts, etc, | |
9144 | * so we add one to the number of vectors we are requesting. | |
9145 | */ | |
9146 | tp->irq_cnt = min_t(unsigned, cpus + 1, tp->irq_max); | |
9147 | ||
9148 | for (i = 0; i < tp->irq_max; i++) { | |
9149 | msix_ent[i].entry = i; | |
9150 | msix_ent[i].vector = 0; | |
9151 | } | |
9152 | ||
9153 | rc = pci_enable_msix(tp->pdev, msix_ent, tp->irq_cnt); | |
2430b031 MC |
9154 | if (rc < 0) { |
9155 | return false; | |
9156 | } else if (rc != 0) { | |
679563f4 MC |
9157 | if (pci_enable_msix(tp->pdev, msix_ent, rc)) |
9158 | return false; | |
05dbe005 JP |
9159 | netdev_notice(tp->dev, "Requested %d MSI-X vectors, received %d\n", |
9160 | tp->irq_cnt, rc); | |
679563f4 MC |
9161 | tp->irq_cnt = rc; |
9162 | } | |
9163 | ||
9164 | for (i = 0; i < tp->irq_max; i++) | |
9165 | tp->napi[i].irq_vec = msix_ent[i].vector; | |
9166 | ||
2ddaad39 BH |
9167 | netif_set_real_num_tx_queues(tp->dev, 1); |
9168 | rc = tp->irq_cnt > 1 ? tp->irq_cnt - 1 : 1; | |
9169 | if (netif_set_real_num_rx_queues(tp->dev, rc)) { | |
9170 | pci_disable_msix(tp->pdev); | |
9171 | return false; | |
9172 | } | |
b92b9040 MC |
9173 | |
9174 | if (tp->irq_cnt > 1) { | |
63c3a66f | 9175 | tg3_flag_set(tp, ENABLE_RSS); |
d78b59f5 MC |
9176 | |
9177 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || | |
9178 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) { | |
63c3a66f | 9179 | tg3_flag_set(tp, ENABLE_TSS); |
b92b9040 MC |
9180 | netif_set_real_num_tx_queues(tp->dev, tp->irq_cnt - 1); |
9181 | } | |
9182 | } | |
2430b031 | 9183 | |
679563f4 MC |
9184 | return true; |
9185 | } | |
9186 | ||
07b0173c MC |
9187 | static void tg3_ints_init(struct tg3 *tp) |
9188 | { | |
63c3a66f JP |
9189 | if ((tg3_flag(tp, SUPPORT_MSI) || tg3_flag(tp, SUPPORT_MSIX)) && |
9190 | !tg3_flag(tp, TAGGED_STATUS)) { | |
07b0173c MC |
9191 | /* All MSI supporting chips should support tagged |
9192 | * status. Assert that this is the case. | |
9193 | */ | |
5129c3a3 MC |
9194 | netdev_warn(tp->dev, |
9195 | "MSI without TAGGED_STATUS? Not using MSI\n"); | |
679563f4 | 9196 | goto defcfg; |
07b0173c | 9197 | } |
4f125f42 | 9198 | |
63c3a66f JP |
9199 | if (tg3_flag(tp, SUPPORT_MSIX) && tg3_enable_msix(tp)) |
9200 | tg3_flag_set(tp, USING_MSIX); | |
9201 | else if (tg3_flag(tp, SUPPORT_MSI) && pci_enable_msi(tp->pdev) == 0) | |
9202 | tg3_flag_set(tp, USING_MSI); | |
679563f4 | 9203 | |
63c3a66f | 9204 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
679563f4 | 9205 | u32 msi_mode = tr32(MSGINT_MODE); |
63c3a66f | 9206 | if (tg3_flag(tp, USING_MSIX) && tp->irq_cnt > 1) |
baf8a94a | 9207 | msi_mode |= MSGINT_MODE_MULTIVEC_EN; |
679563f4 MC |
9208 | tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE); |
9209 | } | |
9210 | defcfg: | |
63c3a66f | 9211 | if (!tg3_flag(tp, USING_MSIX)) { |
679563f4 MC |
9212 | tp->irq_cnt = 1; |
9213 | tp->napi[0].irq_vec = tp->pdev->irq; | |
2ddaad39 | 9214 | netif_set_real_num_tx_queues(tp->dev, 1); |
85407885 | 9215 | netif_set_real_num_rx_queues(tp->dev, 1); |
679563f4 | 9216 | } |
07b0173c MC |
9217 | } |
9218 | ||
9219 | static void tg3_ints_fini(struct tg3 *tp) | |
9220 | { | |
63c3a66f | 9221 | if (tg3_flag(tp, USING_MSIX)) |
679563f4 | 9222 | pci_disable_msix(tp->pdev); |
63c3a66f | 9223 | else if (tg3_flag(tp, USING_MSI)) |
679563f4 | 9224 | pci_disable_msi(tp->pdev); |
63c3a66f JP |
9225 | tg3_flag_clear(tp, USING_MSI); |
9226 | tg3_flag_clear(tp, USING_MSIX); | |
9227 | tg3_flag_clear(tp, ENABLE_RSS); | |
9228 | tg3_flag_clear(tp, ENABLE_TSS); | |
07b0173c MC |
9229 | } |
9230 | ||
1da177e4 LT |
9231 | static int tg3_open(struct net_device *dev) |
9232 | { | |
9233 | struct tg3 *tp = netdev_priv(dev); | |
4f125f42 | 9234 | int i, err; |
1da177e4 | 9235 | |
9e9fd12d MC |
9236 | if (tp->fw_needed) { |
9237 | err = tg3_request_firmware(tp); | |
9238 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { | |
9239 | if (err) | |
9240 | return err; | |
9241 | } else if (err) { | |
05dbe005 | 9242 | netdev_warn(tp->dev, "TSO capability disabled\n"); |
63c3a66f JP |
9243 | tg3_flag_clear(tp, TSO_CAPABLE); |
9244 | } else if (!tg3_flag(tp, TSO_CAPABLE)) { | |
05dbe005 | 9245 | netdev_notice(tp->dev, "TSO capability restored\n"); |
63c3a66f | 9246 | tg3_flag_set(tp, TSO_CAPABLE); |
9e9fd12d MC |
9247 | } |
9248 | } | |
9249 | ||
c49a1561 MC |
9250 | netif_carrier_off(tp->dev); |
9251 | ||
c866b7ea | 9252 | err = tg3_power_up(tp); |
2f751b67 | 9253 | if (err) |
bc1c7567 | 9254 | return err; |
2f751b67 MC |
9255 | |
9256 | tg3_full_lock(tp, 0); | |
bc1c7567 | 9257 | |
1da177e4 | 9258 | tg3_disable_ints(tp); |
63c3a66f | 9259 | tg3_flag_clear(tp, INIT_COMPLETE); |
1da177e4 | 9260 | |
f47c11ee | 9261 | tg3_full_unlock(tp); |
1da177e4 | 9262 | |
679563f4 MC |
9263 | /* |
9264 | * Setup interrupts first so we know how | |
9265 | * many NAPI resources to allocate | |
9266 | */ | |
9267 | tg3_ints_init(tp); | |
9268 | ||
1da177e4 LT |
9269 | /* The placement of this call is tied |
9270 | * to the setup and use of Host TX descriptors. | |
9271 | */ | |
9272 | err = tg3_alloc_consistent(tp); | |
9273 | if (err) | |
679563f4 | 9274 | goto err_out1; |
88b06bc2 | 9275 | |
66cfd1bd MC |
9276 | tg3_napi_init(tp); |
9277 | ||
fed97810 | 9278 | tg3_napi_enable(tp); |
1da177e4 | 9279 | |
4f125f42 MC |
9280 | for (i = 0; i < tp->irq_cnt; i++) { |
9281 | struct tg3_napi *tnapi = &tp->napi[i]; | |
9282 | err = tg3_request_irq(tp, i); | |
9283 | if (err) { | |
9284 | for (i--; i >= 0; i--) | |
9285 | free_irq(tnapi->irq_vec, tnapi); | |
9286 | break; | |
9287 | } | |
9288 | } | |
1da177e4 | 9289 | |
07b0173c | 9290 | if (err) |
679563f4 | 9291 | goto err_out2; |
bea3348e | 9292 | |
f47c11ee | 9293 | tg3_full_lock(tp, 0); |
1da177e4 | 9294 | |
8e7a22e3 | 9295 | err = tg3_init_hw(tp, 1); |
1da177e4 | 9296 | if (err) { |
944d980e | 9297 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
1da177e4 LT |
9298 | tg3_free_rings(tp); |
9299 | } else { | |
63c3a66f | 9300 | if (tg3_flag(tp, TAGGED_STATUS)) |
fac9b83e DM |
9301 | tp->timer_offset = HZ; |
9302 | else | |
9303 | tp->timer_offset = HZ / 10; | |
9304 | ||
9305 | BUG_ON(tp->timer_offset > HZ); | |
9306 | tp->timer_counter = tp->timer_multiplier = | |
9307 | (HZ / tp->timer_offset); | |
9308 | tp->asf_counter = tp->asf_multiplier = | |
28fbef78 | 9309 | ((HZ / tp->timer_offset) * 2); |
1da177e4 LT |
9310 | |
9311 | init_timer(&tp->timer); | |
9312 | tp->timer.expires = jiffies + tp->timer_offset; | |
9313 | tp->timer.data = (unsigned long) tp; | |
9314 | tp->timer.function = tg3_timer; | |
1da177e4 LT |
9315 | } |
9316 | ||
f47c11ee | 9317 | tg3_full_unlock(tp); |
1da177e4 | 9318 | |
07b0173c | 9319 | if (err) |
679563f4 | 9320 | goto err_out3; |
1da177e4 | 9321 | |
63c3a66f | 9322 | if (tg3_flag(tp, USING_MSI)) { |
7938109f | 9323 | err = tg3_test_msi(tp); |
fac9b83e | 9324 | |
7938109f | 9325 | if (err) { |
f47c11ee | 9326 | tg3_full_lock(tp, 0); |
944d980e | 9327 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
7938109f | 9328 | tg3_free_rings(tp); |
f47c11ee | 9329 | tg3_full_unlock(tp); |
7938109f | 9330 | |
679563f4 | 9331 | goto err_out2; |
7938109f | 9332 | } |
fcfa0a32 | 9333 | |
63c3a66f | 9334 | if (!tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, USING_MSI)) { |
f6eb9b1f | 9335 | u32 val = tr32(PCIE_TRANSACTION_CFG); |
fcfa0a32 | 9336 | |
f6eb9b1f MC |
9337 | tw32(PCIE_TRANSACTION_CFG, |
9338 | val | PCIE_TRANS_CFG_1SHOT_MSI); | |
fcfa0a32 | 9339 | } |
7938109f MC |
9340 | } |
9341 | ||
b02fd9e3 MC |
9342 | tg3_phy_start(tp); |
9343 | ||
f47c11ee | 9344 | tg3_full_lock(tp, 0); |
1da177e4 | 9345 | |
7938109f | 9346 | add_timer(&tp->timer); |
63c3a66f | 9347 | tg3_flag_set(tp, INIT_COMPLETE); |
1da177e4 LT |
9348 | tg3_enable_ints(tp); |
9349 | ||
f47c11ee | 9350 | tg3_full_unlock(tp); |
1da177e4 | 9351 | |
fe5f5787 | 9352 | netif_tx_start_all_queues(dev); |
1da177e4 | 9353 | |
06c03c02 MB |
9354 | /* |
9355 | * Reset loopback feature if it was turned on while the device was down | |
9356 | * make sure that it's installed properly now. | |
9357 | */ | |
9358 | if (dev->features & NETIF_F_LOOPBACK) | |
9359 | tg3_set_loopback(dev, dev->features); | |
9360 | ||
1da177e4 | 9361 | return 0; |
07b0173c | 9362 | |
679563f4 | 9363 | err_out3: |
4f125f42 MC |
9364 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
9365 | struct tg3_napi *tnapi = &tp->napi[i]; | |
9366 | free_irq(tnapi->irq_vec, tnapi); | |
9367 | } | |
07b0173c | 9368 | |
679563f4 | 9369 | err_out2: |
fed97810 | 9370 | tg3_napi_disable(tp); |
66cfd1bd | 9371 | tg3_napi_fini(tp); |
07b0173c | 9372 | tg3_free_consistent(tp); |
679563f4 MC |
9373 | |
9374 | err_out1: | |
9375 | tg3_ints_fini(tp); | |
07b0173c | 9376 | return err; |
1da177e4 LT |
9377 | } |
9378 | ||
511d2224 ED |
9379 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *, |
9380 | struct rtnl_link_stats64 *); | |
1da177e4 LT |
9381 | static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *); |
9382 | ||
9383 | static int tg3_close(struct net_device *dev) | |
9384 | { | |
4f125f42 | 9385 | int i; |
1da177e4 LT |
9386 | struct tg3 *tp = netdev_priv(dev); |
9387 | ||
fed97810 | 9388 | tg3_napi_disable(tp); |
28e53bdd | 9389 | cancel_work_sync(&tp->reset_task); |
7faa006f | 9390 | |
fe5f5787 | 9391 | netif_tx_stop_all_queues(dev); |
1da177e4 LT |
9392 | |
9393 | del_timer_sync(&tp->timer); | |
9394 | ||
24bb4fb6 MC |
9395 | tg3_phy_stop(tp); |
9396 | ||
f47c11ee | 9397 | tg3_full_lock(tp, 1); |
1da177e4 LT |
9398 | |
9399 | tg3_disable_ints(tp); | |
9400 | ||
944d980e | 9401 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
1da177e4 | 9402 | tg3_free_rings(tp); |
63c3a66f | 9403 | tg3_flag_clear(tp, INIT_COMPLETE); |
1da177e4 | 9404 | |
f47c11ee | 9405 | tg3_full_unlock(tp); |
1da177e4 | 9406 | |
4f125f42 MC |
9407 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
9408 | struct tg3_napi *tnapi = &tp->napi[i]; | |
9409 | free_irq(tnapi->irq_vec, tnapi); | |
9410 | } | |
07b0173c MC |
9411 | |
9412 | tg3_ints_fini(tp); | |
1da177e4 | 9413 | |
511d2224 ED |
9414 | tg3_get_stats64(tp->dev, &tp->net_stats_prev); |
9415 | ||
1da177e4 LT |
9416 | memcpy(&tp->estats_prev, tg3_get_estats(tp), |
9417 | sizeof(tp->estats_prev)); | |
9418 | ||
66cfd1bd MC |
9419 | tg3_napi_fini(tp); |
9420 | ||
1da177e4 LT |
9421 | tg3_free_consistent(tp); |
9422 | ||
c866b7ea | 9423 | tg3_power_down(tp); |
bc1c7567 MC |
9424 | |
9425 | netif_carrier_off(tp->dev); | |
9426 | ||
1da177e4 LT |
9427 | return 0; |
9428 | } | |
9429 | ||
511d2224 | 9430 | static inline u64 get_stat64(tg3_stat64_t *val) |
816f8b86 SB |
9431 | { |
9432 | return ((u64)val->high << 32) | ((u64)val->low); | |
9433 | } | |
9434 | ||
511d2224 | 9435 | static u64 calc_crc_errors(struct tg3 *tp) |
1da177e4 LT |
9436 | { |
9437 | struct tg3_hw_stats *hw_stats = tp->hw_stats; | |
9438 | ||
f07e9af3 | 9439 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
1da177e4 LT |
9440 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
9441 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { | |
1da177e4 LT |
9442 | u32 val; |
9443 | ||
f47c11ee | 9444 | spin_lock_bh(&tp->lock); |
569a5df8 MC |
9445 | if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) { |
9446 | tg3_writephy(tp, MII_TG3_TEST1, | |
9447 | val | MII_TG3_TEST1_CRC_EN); | |
f08aa1a8 | 9448 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &val); |
1da177e4 LT |
9449 | } else |
9450 | val = 0; | |
f47c11ee | 9451 | spin_unlock_bh(&tp->lock); |
1da177e4 LT |
9452 | |
9453 | tp->phy_crc_errors += val; | |
9454 | ||
9455 | return tp->phy_crc_errors; | |
9456 | } | |
9457 | ||
9458 | return get_stat64(&hw_stats->rx_fcs_errors); | |
9459 | } | |
9460 | ||
9461 | #define ESTAT_ADD(member) \ | |
9462 | estats->member = old_estats->member + \ | |
511d2224 | 9463 | get_stat64(&hw_stats->member) |
1da177e4 LT |
9464 | |
9465 | static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp) | |
9466 | { | |
9467 | struct tg3_ethtool_stats *estats = &tp->estats; | |
9468 | struct tg3_ethtool_stats *old_estats = &tp->estats_prev; | |
9469 | struct tg3_hw_stats *hw_stats = tp->hw_stats; | |
9470 | ||
9471 | if (!hw_stats) | |
9472 | return old_estats; | |
9473 | ||
9474 | ESTAT_ADD(rx_octets); | |
9475 | ESTAT_ADD(rx_fragments); | |
9476 | ESTAT_ADD(rx_ucast_packets); | |
9477 | ESTAT_ADD(rx_mcast_packets); | |
9478 | ESTAT_ADD(rx_bcast_packets); | |
9479 | ESTAT_ADD(rx_fcs_errors); | |
9480 | ESTAT_ADD(rx_align_errors); | |
9481 | ESTAT_ADD(rx_xon_pause_rcvd); | |
9482 | ESTAT_ADD(rx_xoff_pause_rcvd); | |
9483 | ESTAT_ADD(rx_mac_ctrl_rcvd); | |
9484 | ESTAT_ADD(rx_xoff_entered); | |
9485 | ESTAT_ADD(rx_frame_too_long_errors); | |
9486 | ESTAT_ADD(rx_jabbers); | |
9487 | ESTAT_ADD(rx_undersize_packets); | |
9488 | ESTAT_ADD(rx_in_length_errors); | |
9489 | ESTAT_ADD(rx_out_length_errors); | |
9490 | ESTAT_ADD(rx_64_or_less_octet_packets); | |
9491 | ESTAT_ADD(rx_65_to_127_octet_packets); | |
9492 | ESTAT_ADD(rx_128_to_255_octet_packets); | |
9493 | ESTAT_ADD(rx_256_to_511_octet_packets); | |
9494 | ESTAT_ADD(rx_512_to_1023_octet_packets); | |
9495 | ESTAT_ADD(rx_1024_to_1522_octet_packets); | |
9496 | ESTAT_ADD(rx_1523_to_2047_octet_packets); | |
9497 | ESTAT_ADD(rx_2048_to_4095_octet_packets); | |
9498 | ESTAT_ADD(rx_4096_to_8191_octet_packets); | |
9499 | ESTAT_ADD(rx_8192_to_9022_octet_packets); | |
9500 | ||
9501 | ESTAT_ADD(tx_octets); | |
9502 | ESTAT_ADD(tx_collisions); | |
9503 | ESTAT_ADD(tx_xon_sent); | |
9504 | ESTAT_ADD(tx_xoff_sent); | |
9505 | ESTAT_ADD(tx_flow_control); | |
9506 | ESTAT_ADD(tx_mac_errors); | |
9507 | ESTAT_ADD(tx_single_collisions); | |
9508 | ESTAT_ADD(tx_mult_collisions); | |
9509 | ESTAT_ADD(tx_deferred); | |
9510 | ESTAT_ADD(tx_excessive_collisions); | |
9511 | ESTAT_ADD(tx_late_collisions); | |
9512 | ESTAT_ADD(tx_collide_2times); | |
9513 | ESTAT_ADD(tx_collide_3times); | |
9514 | ESTAT_ADD(tx_collide_4times); | |
9515 | ESTAT_ADD(tx_collide_5times); | |
9516 | ESTAT_ADD(tx_collide_6times); | |
9517 | ESTAT_ADD(tx_collide_7times); | |
9518 | ESTAT_ADD(tx_collide_8times); | |
9519 | ESTAT_ADD(tx_collide_9times); | |
9520 | ESTAT_ADD(tx_collide_10times); | |
9521 | ESTAT_ADD(tx_collide_11times); | |
9522 | ESTAT_ADD(tx_collide_12times); | |
9523 | ESTAT_ADD(tx_collide_13times); | |
9524 | ESTAT_ADD(tx_collide_14times); | |
9525 | ESTAT_ADD(tx_collide_15times); | |
9526 | ESTAT_ADD(tx_ucast_packets); | |
9527 | ESTAT_ADD(tx_mcast_packets); | |
9528 | ESTAT_ADD(tx_bcast_packets); | |
9529 | ESTAT_ADD(tx_carrier_sense_errors); | |
9530 | ESTAT_ADD(tx_discards); | |
9531 | ESTAT_ADD(tx_errors); | |
9532 | ||
9533 | ESTAT_ADD(dma_writeq_full); | |
9534 | ESTAT_ADD(dma_write_prioq_full); | |
9535 | ESTAT_ADD(rxbds_empty); | |
9536 | ESTAT_ADD(rx_discards); | |
9537 | ESTAT_ADD(rx_errors); | |
9538 | ESTAT_ADD(rx_threshold_hit); | |
9539 | ||
9540 | ESTAT_ADD(dma_readq_full); | |
9541 | ESTAT_ADD(dma_read_prioq_full); | |
9542 | ESTAT_ADD(tx_comp_queue_full); | |
9543 | ||
9544 | ESTAT_ADD(ring_set_send_prod_index); | |
9545 | ESTAT_ADD(ring_status_update); | |
9546 | ESTAT_ADD(nic_irqs); | |
9547 | ESTAT_ADD(nic_avoided_irqs); | |
9548 | ESTAT_ADD(nic_tx_threshold_hit); | |
9549 | ||
9550 | return estats; | |
9551 | } | |
9552 | ||
511d2224 ED |
9553 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *dev, |
9554 | struct rtnl_link_stats64 *stats) | |
1da177e4 LT |
9555 | { |
9556 | struct tg3 *tp = netdev_priv(dev); | |
511d2224 | 9557 | struct rtnl_link_stats64 *old_stats = &tp->net_stats_prev; |
1da177e4 LT |
9558 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
9559 | ||
9560 | if (!hw_stats) | |
9561 | return old_stats; | |
9562 | ||
9563 | stats->rx_packets = old_stats->rx_packets + | |
9564 | get_stat64(&hw_stats->rx_ucast_packets) + | |
9565 | get_stat64(&hw_stats->rx_mcast_packets) + | |
9566 | get_stat64(&hw_stats->rx_bcast_packets); | |
6aa20a22 | 9567 | |
1da177e4 LT |
9568 | stats->tx_packets = old_stats->tx_packets + |
9569 | get_stat64(&hw_stats->tx_ucast_packets) + | |
9570 | get_stat64(&hw_stats->tx_mcast_packets) + | |
9571 | get_stat64(&hw_stats->tx_bcast_packets); | |
9572 | ||
9573 | stats->rx_bytes = old_stats->rx_bytes + | |
9574 | get_stat64(&hw_stats->rx_octets); | |
9575 | stats->tx_bytes = old_stats->tx_bytes + | |
9576 | get_stat64(&hw_stats->tx_octets); | |
9577 | ||
9578 | stats->rx_errors = old_stats->rx_errors + | |
4f63b877 | 9579 | get_stat64(&hw_stats->rx_errors); |
1da177e4 LT |
9580 | stats->tx_errors = old_stats->tx_errors + |
9581 | get_stat64(&hw_stats->tx_errors) + | |
9582 | get_stat64(&hw_stats->tx_mac_errors) + | |
9583 | get_stat64(&hw_stats->tx_carrier_sense_errors) + | |
9584 | get_stat64(&hw_stats->tx_discards); | |
9585 | ||
9586 | stats->multicast = old_stats->multicast + | |
9587 | get_stat64(&hw_stats->rx_mcast_packets); | |
9588 | stats->collisions = old_stats->collisions + | |
9589 | get_stat64(&hw_stats->tx_collisions); | |
9590 | ||
9591 | stats->rx_length_errors = old_stats->rx_length_errors + | |
9592 | get_stat64(&hw_stats->rx_frame_too_long_errors) + | |
9593 | get_stat64(&hw_stats->rx_undersize_packets); | |
9594 | ||
9595 | stats->rx_over_errors = old_stats->rx_over_errors + | |
9596 | get_stat64(&hw_stats->rxbds_empty); | |
9597 | stats->rx_frame_errors = old_stats->rx_frame_errors + | |
9598 | get_stat64(&hw_stats->rx_align_errors); | |
9599 | stats->tx_aborted_errors = old_stats->tx_aborted_errors + | |
9600 | get_stat64(&hw_stats->tx_discards); | |
9601 | stats->tx_carrier_errors = old_stats->tx_carrier_errors + | |
9602 | get_stat64(&hw_stats->tx_carrier_sense_errors); | |
9603 | ||
9604 | stats->rx_crc_errors = old_stats->rx_crc_errors + | |
9605 | calc_crc_errors(tp); | |
9606 | ||
4f63b877 JL |
9607 | stats->rx_missed_errors = old_stats->rx_missed_errors + |
9608 | get_stat64(&hw_stats->rx_discards); | |
9609 | ||
b0057c51 ED |
9610 | stats->rx_dropped = tp->rx_dropped; |
9611 | ||
1da177e4 LT |
9612 | return stats; |
9613 | } | |
9614 | ||
9615 | static inline u32 calc_crc(unsigned char *buf, int len) | |
9616 | { | |
9617 | u32 reg; | |
9618 | u32 tmp; | |
9619 | int j, k; | |
9620 | ||
9621 | reg = 0xffffffff; | |
9622 | ||
9623 | for (j = 0; j < len; j++) { | |
9624 | reg ^= buf[j]; | |
9625 | ||
9626 | for (k = 0; k < 8; k++) { | |
9627 | tmp = reg & 0x01; | |
9628 | ||
9629 | reg >>= 1; | |
9630 | ||
859a5887 | 9631 | if (tmp) |
1da177e4 | 9632 | reg ^= 0xedb88320; |
1da177e4 LT |
9633 | } |
9634 | } | |
9635 | ||
9636 | return ~reg; | |
9637 | } | |
9638 | ||
9639 | static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all) | |
9640 | { | |
9641 | /* accept or reject all multicast frames */ | |
9642 | tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0); | |
9643 | tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0); | |
9644 | tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0); | |
9645 | tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0); | |
9646 | } | |
9647 | ||
9648 | static void __tg3_set_rx_mode(struct net_device *dev) | |
9649 | { | |
9650 | struct tg3 *tp = netdev_priv(dev); | |
9651 | u32 rx_mode; | |
9652 | ||
9653 | rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC | | |
9654 | RX_MODE_KEEP_VLAN_TAG); | |
9655 | ||
bf933c80 | 9656 | #if !defined(CONFIG_VLAN_8021Q) && !defined(CONFIG_VLAN_8021Q_MODULE) |
1da177e4 LT |
9657 | /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG |
9658 | * flag clear. | |
9659 | */ | |
63c3a66f | 9660 | if (!tg3_flag(tp, ENABLE_ASF)) |
1da177e4 LT |
9661 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; |
9662 | #endif | |
9663 | ||
9664 | if (dev->flags & IFF_PROMISC) { | |
9665 | /* Promiscuous mode. */ | |
9666 | rx_mode |= RX_MODE_PROMISC; | |
9667 | } else if (dev->flags & IFF_ALLMULTI) { | |
9668 | /* Accept all multicast. */ | |
de6f31eb | 9669 | tg3_set_multi(tp, 1); |
4cd24eaf | 9670 | } else if (netdev_mc_empty(dev)) { |
1da177e4 | 9671 | /* Reject all multicast. */ |
de6f31eb | 9672 | tg3_set_multi(tp, 0); |
1da177e4 LT |
9673 | } else { |
9674 | /* Accept one or more multicast(s). */ | |
22bedad3 | 9675 | struct netdev_hw_addr *ha; |
1da177e4 LT |
9676 | u32 mc_filter[4] = { 0, }; |
9677 | u32 regidx; | |
9678 | u32 bit; | |
9679 | u32 crc; | |
9680 | ||
22bedad3 JP |
9681 | netdev_for_each_mc_addr(ha, dev) { |
9682 | crc = calc_crc(ha->addr, ETH_ALEN); | |
1da177e4 LT |
9683 | bit = ~crc & 0x7f; |
9684 | regidx = (bit & 0x60) >> 5; | |
9685 | bit &= 0x1f; | |
9686 | mc_filter[regidx] |= (1 << bit); | |
9687 | } | |
9688 | ||
9689 | tw32(MAC_HASH_REG_0, mc_filter[0]); | |
9690 | tw32(MAC_HASH_REG_1, mc_filter[1]); | |
9691 | tw32(MAC_HASH_REG_2, mc_filter[2]); | |
9692 | tw32(MAC_HASH_REG_3, mc_filter[3]); | |
9693 | } | |
9694 | ||
9695 | if (rx_mode != tp->rx_mode) { | |
9696 | tp->rx_mode = rx_mode; | |
9697 | tw32_f(MAC_RX_MODE, rx_mode); | |
9698 | udelay(10); | |
9699 | } | |
9700 | } | |
9701 | ||
9702 | static void tg3_set_rx_mode(struct net_device *dev) | |
9703 | { | |
9704 | struct tg3 *tp = netdev_priv(dev); | |
9705 | ||
e75f7c90 MC |
9706 | if (!netif_running(dev)) |
9707 | return; | |
9708 | ||
f47c11ee | 9709 | tg3_full_lock(tp, 0); |
1da177e4 | 9710 | __tg3_set_rx_mode(dev); |
f47c11ee | 9711 | tg3_full_unlock(tp); |
1da177e4 LT |
9712 | } |
9713 | ||
1da177e4 LT |
9714 | static int tg3_get_regs_len(struct net_device *dev) |
9715 | { | |
97bd8e49 | 9716 | return TG3_REG_BLK_SIZE; |
1da177e4 LT |
9717 | } |
9718 | ||
9719 | static void tg3_get_regs(struct net_device *dev, | |
9720 | struct ethtool_regs *regs, void *_p) | |
9721 | { | |
1da177e4 | 9722 | struct tg3 *tp = netdev_priv(dev); |
1da177e4 LT |
9723 | |
9724 | regs->version = 0; | |
9725 | ||
97bd8e49 | 9726 | memset(_p, 0, TG3_REG_BLK_SIZE); |
1da177e4 | 9727 | |
80096068 | 9728 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
bc1c7567 MC |
9729 | return; |
9730 | ||
f47c11ee | 9731 | tg3_full_lock(tp, 0); |
1da177e4 | 9732 | |
97bd8e49 | 9733 | tg3_dump_legacy_regs(tp, (u32 *)_p); |
1da177e4 | 9734 | |
f47c11ee | 9735 | tg3_full_unlock(tp); |
1da177e4 LT |
9736 | } |
9737 | ||
9738 | static int tg3_get_eeprom_len(struct net_device *dev) | |
9739 | { | |
9740 | struct tg3 *tp = netdev_priv(dev); | |
9741 | ||
9742 | return tp->nvram_size; | |
9743 | } | |
9744 | ||
1da177e4 LT |
9745 | static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
9746 | { | |
9747 | struct tg3 *tp = netdev_priv(dev); | |
9748 | int ret; | |
9749 | u8 *pd; | |
b9fc7dc5 | 9750 | u32 i, offset, len, b_offset, b_count; |
a9dc529d | 9751 | __be32 val; |
1da177e4 | 9752 | |
63c3a66f | 9753 | if (tg3_flag(tp, NO_NVRAM)) |
df259d8c MC |
9754 | return -EINVAL; |
9755 | ||
80096068 | 9756 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
bc1c7567 MC |
9757 | return -EAGAIN; |
9758 | ||
1da177e4 LT |
9759 | offset = eeprom->offset; |
9760 | len = eeprom->len; | |
9761 | eeprom->len = 0; | |
9762 | ||
9763 | eeprom->magic = TG3_EEPROM_MAGIC; | |
9764 | ||
9765 | if (offset & 3) { | |
9766 | /* adjustments to start on required 4 byte boundary */ | |
9767 | b_offset = offset & 3; | |
9768 | b_count = 4 - b_offset; | |
9769 | if (b_count > len) { | |
9770 | /* i.e. offset=1 len=2 */ | |
9771 | b_count = len; | |
9772 | } | |
a9dc529d | 9773 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &val); |
1da177e4 LT |
9774 | if (ret) |
9775 | return ret; | |
be98da6a | 9776 | memcpy(data, ((char *)&val) + b_offset, b_count); |
1da177e4 LT |
9777 | len -= b_count; |
9778 | offset += b_count; | |
c6cdf436 | 9779 | eeprom->len += b_count; |
1da177e4 LT |
9780 | } |
9781 | ||
25985edc | 9782 | /* read bytes up to the last 4 byte boundary */ |
1da177e4 LT |
9783 | pd = &data[eeprom->len]; |
9784 | for (i = 0; i < (len - (len & 3)); i += 4) { | |
a9dc529d | 9785 | ret = tg3_nvram_read_be32(tp, offset + i, &val); |
1da177e4 LT |
9786 | if (ret) { |
9787 | eeprom->len += i; | |
9788 | return ret; | |
9789 | } | |
1da177e4 LT |
9790 | memcpy(pd + i, &val, 4); |
9791 | } | |
9792 | eeprom->len += i; | |
9793 | ||
9794 | if (len & 3) { | |
9795 | /* read last bytes not ending on 4 byte boundary */ | |
9796 | pd = &data[eeprom->len]; | |
9797 | b_count = len & 3; | |
9798 | b_offset = offset + len - b_count; | |
a9dc529d | 9799 | ret = tg3_nvram_read_be32(tp, b_offset, &val); |
1da177e4 LT |
9800 | if (ret) |
9801 | return ret; | |
b9fc7dc5 | 9802 | memcpy(pd, &val, b_count); |
1da177e4 LT |
9803 | eeprom->len += b_count; |
9804 | } | |
9805 | return 0; | |
9806 | } | |
9807 | ||
6aa20a22 | 9808 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf); |
1da177e4 LT |
9809 | |
9810 | static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) | |
9811 | { | |
9812 | struct tg3 *tp = netdev_priv(dev); | |
9813 | int ret; | |
b9fc7dc5 | 9814 | u32 offset, len, b_offset, odd_len; |
1da177e4 | 9815 | u8 *buf; |
a9dc529d | 9816 | __be32 start, end; |
1da177e4 | 9817 | |
80096068 | 9818 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
bc1c7567 MC |
9819 | return -EAGAIN; |
9820 | ||
63c3a66f | 9821 | if (tg3_flag(tp, NO_NVRAM) || |
df259d8c | 9822 | eeprom->magic != TG3_EEPROM_MAGIC) |
1da177e4 LT |
9823 | return -EINVAL; |
9824 | ||
9825 | offset = eeprom->offset; | |
9826 | len = eeprom->len; | |
9827 | ||
9828 | if ((b_offset = (offset & 3))) { | |
9829 | /* adjustments to start on required 4 byte boundary */ | |
a9dc529d | 9830 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &start); |
1da177e4 LT |
9831 | if (ret) |
9832 | return ret; | |
1da177e4 LT |
9833 | len += b_offset; |
9834 | offset &= ~3; | |
1c8594b4 MC |
9835 | if (len < 4) |
9836 | len = 4; | |
1da177e4 LT |
9837 | } |
9838 | ||
9839 | odd_len = 0; | |
1c8594b4 | 9840 | if (len & 3) { |
1da177e4 LT |
9841 | /* adjustments to end on required 4 byte boundary */ |
9842 | odd_len = 1; | |
9843 | len = (len + 3) & ~3; | |
a9dc529d | 9844 | ret = tg3_nvram_read_be32(tp, offset+len-4, &end); |
1da177e4 LT |
9845 | if (ret) |
9846 | return ret; | |
1da177e4 LT |
9847 | } |
9848 | ||
9849 | buf = data; | |
9850 | if (b_offset || odd_len) { | |
9851 | buf = kmalloc(len, GFP_KERNEL); | |
ab0049b4 | 9852 | if (!buf) |
1da177e4 LT |
9853 | return -ENOMEM; |
9854 | if (b_offset) | |
9855 | memcpy(buf, &start, 4); | |
9856 | if (odd_len) | |
9857 | memcpy(buf+len-4, &end, 4); | |
9858 | memcpy(buf + b_offset, data, eeprom->len); | |
9859 | } | |
9860 | ||
9861 | ret = tg3_nvram_write_block(tp, offset, len, buf); | |
9862 | ||
9863 | if (buf != data) | |
9864 | kfree(buf); | |
9865 | ||
9866 | return ret; | |
9867 | } | |
9868 | ||
9869 | static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) | |
9870 | { | |
b02fd9e3 MC |
9871 | struct tg3 *tp = netdev_priv(dev); |
9872 | ||
63c3a66f | 9873 | if (tg3_flag(tp, USE_PHYLIB)) { |
3f0e3ad7 | 9874 | struct phy_device *phydev; |
f07e9af3 | 9875 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 | 9876 | return -EAGAIN; |
3f0e3ad7 MC |
9877 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
9878 | return phy_ethtool_gset(phydev, cmd); | |
b02fd9e3 | 9879 | } |
6aa20a22 | 9880 | |
1da177e4 LT |
9881 | cmd->supported = (SUPPORTED_Autoneg); |
9882 | ||
f07e9af3 | 9883 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
1da177e4 LT |
9884 | cmd->supported |= (SUPPORTED_1000baseT_Half | |
9885 | SUPPORTED_1000baseT_Full); | |
9886 | ||
f07e9af3 | 9887 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
1da177e4 LT |
9888 | cmd->supported |= (SUPPORTED_100baseT_Half | |
9889 | SUPPORTED_100baseT_Full | | |
9890 | SUPPORTED_10baseT_Half | | |
9891 | SUPPORTED_10baseT_Full | | |
3bebab59 | 9892 | SUPPORTED_TP); |
ef348144 KK |
9893 | cmd->port = PORT_TP; |
9894 | } else { | |
1da177e4 | 9895 | cmd->supported |= SUPPORTED_FIBRE; |
ef348144 KK |
9896 | cmd->port = PORT_FIBRE; |
9897 | } | |
6aa20a22 | 9898 | |
1da177e4 LT |
9899 | cmd->advertising = tp->link_config.advertising; |
9900 | if (netif_running(dev)) { | |
70739497 | 9901 | ethtool_cmd_speed_set(cmd, tp->link_config.active_speed); |
1da177e4 | 9902 | cmd->duplex = tp->link_config.active_duplex; |
64c22182 | 9903 | } else { |
70739497 | 9904 | ethtool_cmd_speed_set(cmd, SPEED_INVALID); |
64c22182 | 9905 | cmd->duplex = DUPLEX_INVALID; |
1da177e4 | 9906 | } |
882e9793 | 9907 | cmd->phy_address = tp->phy_addr; |
7e5856bd | 9908 | cmd->transceiver = XCVR_INTERNAL; |
1da177e4 LT |
9909 | cmd->autoneg = tp->link_config.autoneg; |
9910 | cmd->maxtxpkt = 0; | |
9911 | cmd->maxrxpkt = 0; | |
9912 | return 0; | |
9913 | } | |
6aa20a22 | 9914 | |
1da177e4 LT |
9915 | static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
9916 | { | |
9917 | struct tg3 *tp = netdev_priv(dev); | |
25db0338 | 9918 | u32 speed = ethtool_cmd_speed(cmd); |
6aa20a22 | 9919 | |
63c3a66f | 9920 | if (tg3_flag(tp, USE_PHYLIB)) { |
3f0e3ad7 | 9921 | struct phy_device *phydev; |
f07e9af3 | 9922 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 | 9923 | return -EAGAIN; |
3f0e3ad7 MC |
9924 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
9925 | return phy_ethtool_sset(phydev, cmd); | |
b02fd9e3 MC |
9926 | } |
9927 | ||
7e5856bd MC |
9928 | if (cmd->autoneg != AUTONEG_ENABLE && |
9929 | cmd->autoneg != AUTONEG_DISABLE) | |
37ff238d | 9930 | return -EINVAL; |
7e5856bd MC |
9931 | |
9932 | if (cmd->autoneg == AUTONEG_DISABLE && | |
9933 | cmd->duplex != DUPLEX_FULL && | |
9934 | cmd->duplex != DUPLEX_HALF) | |
37ff238d | 9935 | return -EINVAL; |
1da177e4 | 9936 | |
7e5856bd MC |
9937 | if (cmd->autoneg == AUTONEG_ENABLE) { |
9938 | u32 mask = ADVERTISED_Autoneg | | |
9939 | ADVERTISED_Pause | | |
9940 | ADVERTISED_Asym_Pause; | |
9941 | ||
f07e9af3 | 9942 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
7e5856bd MC |
9943 | mask |= ADVERTISED_1000baseT_Half | |
9944 | ADVERTISED_1000baseT_Full; | |
9945 | ||
f07e9af3 | 9946 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
7e5856bd MC |
9947 | mask |= ADVERTISED_100baseT_Half | |
9948 | ADVERTISED_100baseT_Full | | |
9949 | ADVERTISED_10baseT_Half | | |
9950 | ADVERTISED_10baseT_Full | | |
9951 | ADVERTISED_TP; | |
9952 | else | |
9953 | mask |= ADVERTISED_FIBRE; | |
9954 | ||
9955 | if (cmd->advertising & ~mask) | |
9956 | return -EINVAL; | |
9957 | ||
9958 | mask &= (ADVERTISED_1000baseT_Half | | |
9959 | ADVERTISED_1000baseT_Full | | |
9960 | ADVERTISED_100baseT_Half | | |
9961 | ADVERTISED_100baseT_Full | | |
9962 | ADVERTISED_10baseT_Half | | |
9963 | ADVERTISED_10baseT_Full); | |
9964 | ||
9965 | cmd->advertising &= mask; | |
9966 | } else { | |
f07e9af3 | 9967 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) { |
25db0338 | 9968 | if (speed != SPEED_1000) |
7e5856bd MC |
9969 | return -EINVAL; |
9970 | ||
9971 | if (cmd->duplex != DUPLEX_FULL) | |
9972 | return -EINVAL; | |
9973 | } else { | |
25db0338 DD |
9974 | if (speed != SPEED_100 && |
9975 | speed != SPEED_10) | |
7e5856bd MC |
9976 | return -EINVAL; |
9977 | } | |
9978 | } | |
9979 | ||
f47c11ee | 9980 | tg3_full_lock(tp, 0); |
1da177e4 LT |
9981 | |
9982 | tp->link_config.autoneg = cmd->autoneg; | |
9983 | if (cmd->autoneg == AUTONEG_ENABLE) { | |
405d8e5c AG |
9984 | tp->link_config.advertising = (cmd->advertising | |
9985 | ADVERTISED_Autoneg); | |
1da177e4 LT |
9986 | tp->link_config.speed = SPEED_INVALID; |
9987 | tp->link_config.duplex = DUPLEX_INVALID; | |
9988 | } else { | |
9989 | tp->link_config.advertising = 0; | |
25db0338 | 9990 | tp->link_config.speed = speed; |
1da177e4 | 9991 | tp->link_config.duplex = cmd->duplex; |
b02fd9e3 | 9992 | } |
6aa20a22 | 9993 | |
24fcad6b MC |
9994 | tp->link_config.orig_speed = tp->link_config.speed; |
9995 | tp->link_config.orig_duplex = tp->link_config.duplex; | |
9996 | tp->link_config.orig_autoneg = tp->link_config.autoneg; | |
9997 | ||
1da177e4 LT |
9998 | if (netif_running(dev)) |
9999 | tg3_setup_phy(tp, 1); | |
10000 | ||
f47c11ee | 10001 | tg3_full_unlock(tp); |
6aa20a22 | 10002 | |
1da177e4 LT |
10003 | return 0; |
10004 | } | |
6aa20a22 | 10005 | |
1da177e4 LT |
10006 | static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
10007 | { | |
10008 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 10009 | |
1da177e4 LT |
10010 | strcpy(info->driver, DRV_MODULE_NAME); |
10011 | strcpy(info->version, DRV_MODULE_VERSION); | |
c4e6575c | 10012 | strcpy(info->fw_version, tp->fw_ver); |
1da177e4 LT |
10013 | strcpy(info->bus_info, pci_name(tp->pdev)); |
10014 | } | |
6aa20a22 | 10015 | |
1da177e4 LT |
10016 | static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
10017 | { | |
10018 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 10019 | |
63c3a66f | 10020 | if (tg3_flag(tp, WOL_CAP) && device_can_wakeup(&tp->pdev->dev)) |
a85feb8c GZ |
10021 | wol->supported = WAKE_MAGIC; |
10022 | else | |
10023 | wol->supported = 0; | |
1da177e4 | 10024 | wol->wolopts = 0; |
63c3a66f | 10025 | if (tg3_flag(tp, WOL_ENABLE) && device_can_wakeup(&tp->pdev->dev)) |
1da177e4 LT |
10026 | wol->wolopts = WAKE_MAGIC; |
10027 | memset(&wol->sopass, 0, sizeof(wol->sopass)); | |
10028 | } | |
6aa20a22 | 10029 | |
1da177e4 LT |
10030 | static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
10031 | { | |
10032 | struct tg3 *tp = netdev_priv(dev); | |
12dac075 | 10033 | struct device *dp = &tp->pdev->dev; |
6aa20a22 | 10034 | |
1da177e4 LT |
10035 | if (wol->wolopts & ~WAKE_MAGIC) |
10036 | return -EINVAL; | |
10037 | if ((wol->wolopts & WAKE_MAGIC) && | |
63c3a66f | 10038 | !(tg3_flag(tp, WOL_CAP) && device_can_wakeup(dp))) |
1da177e4 | 10039 | return -EINVAL; |
6aa20a22 | 10040 | |
f2dc0d18 RW |
10041 | device_set_wakeup_enable(dp, wol->wolopts & WAKE_MAGIC); |
10042 | ||
f47c11ee | 10043 | spin_lock_bh(&tp->lock); |
f2dc0d18 | 10044 | if (device_may_wakeup(dp)) |
63c3a66f | 10045 | tg3_flag_set(tp, WOL_ENABLE); |
f2dc0d18 | 10046 | else |
63c3a66f | 10047 | tg3_flag_clear(tp, WOL_ENABLE); |
f47c11ee | 10048 | spin_unlock_bh(&tp->lock); |
6aa20a22 | 10049 | |
1da177e4 LT |
10050 | return 0; |
10051 | } | |
6aa20a22 | 10052 | |
1da177e4 LT |
10053 | static u32 tg3_get_msglevel(struct net_device *dev) |
10054 | { | |
10055 | struct tg3 *tp = netdev_priv(dev); | |
10056 | return tp->msg_enable; | |
10057 | } | |
6aa20a22 | 10058 | |
1da177e4 LT |
10059 | static void tg3_set_msglevel(struct net_device *dev, u32 value) |
10060 | { | |
10061 | struct tg3 *tp = netdev_priv(dev); | |
10062 | tp->msg_enable = value; | |
10063 | } | |
6aa20a22 | 10064 | |
1da177e4 LT |
10065 | static int tg3_nway_reset(struct net_device *dev) |
10066 | { | |
10067 | struct tg3 *tp = netdev_priv(dev); | |
1da177e4 | 10068 | int r; |
6aa20a22 | 10069 | |
1da177e4 LT |
10070 | if (!netif_running(dev)) |
10071 | return -EAGAIN; | |
10072 | ||
f07e9af3 | 10073 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
c94e3941 MC |
10074 | return -EINVAL; |
10075 | ||
63c3a66f | 10076 | if (tg3_flag(tp, USE_PHYLIB)) { |
f07e9af3 | 10077 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 | 10078 | return -EAGAIN; |
3f0e3ad7 | 10079 | r = phy_start_aneg(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
b02fd9e3 MC |
10080 | } else { |
10081 | u32 bmcr; | |
10082 | ||
10083 | spin_lock_bh(&tp->lock); | |
10084 | r = -EINVAL; | |
10085 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
10086 | if (!tg3_readphy(tp, MII_BMCR, &bmcr) && | |
10087 | ((bmcr & BMCR_ANENABLE) || | |
f07e9af3 | 10088 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT))) { |
b02fd9e3 MC |
10089 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART | |
10090 | BMCR_ANENABLE); | |
10091 | r = 0; | |
10092 | } | |
10093 | spin_unlock_bh(&tp->lock); | |
1da177e4 | 10094 | } |
6aa20a22 | 10095 | |
1da177e4 LT |
10096 | return r; |
10097 | } | |
6aa20a22 | 10098 | |
1da177e4 LT |
10099 | static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
10100 | { | |
10101 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 10102 | |
2c49a44d | 10103 | ering->rx_max_pending = tp->rx_std_ring_mask; |
1da177e4 | 10104 | ering->rx_mini_max_pending = 0; |
63c3a66f | 10105 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
2c49a44d | 10106 | ering->rx_jumbo_max_pending = tp->rx_jmb_ring_mask; |
4f81c32b MC |
10107 | else |
10108 | ering->rx_jumbo_max_pending = 0; | |
10109 | ||
10110 | ering->tx_max_pending = TG3_TX_RING_SIZE - 1; | |
1da177e4 LT |
10111 | |
10112 | ering->rx_pending = tp->rx_pending; | |
10113 | ering->rx_mini_pending = 0; | |
63c3a66f | 10114 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
4f81c32b MC |
10115 | ering->rx_jumbo_pending = tp->rx_jumbo_pending; |
10116 | else | |
10117 | ering->rx_jumbo_pending = 0; | |
10118 | ||
f3f3f27e | 10119 | ering->tx_pending = tp->napi[0].tx_pending; |
1da177e4 | 10120 | } |
6aa20a22 | 10121 | |
1da177e4 LT |
10122 | static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
10123 | { | |
10124 | struct tg3 *tp = netdev_priv(dev); | |
646c9edd | 10125 | int i, irq_sync = 0, err = 0; |
6aa20a22 | 10126 | |
2c49a44d MC |
10127 | if ((ering->rx_pending > tp->rx_std_ring_mask) || |
10128 | (ering->rx_jumbo_pending > tp->rx_jmb_ring_mask) || | |
bc3a9254 MC |
10129 | (ering->tx_pending > TG3_TX_RING_SIZE - 1) || |
10130 | (ering->tx_pending <= MAX_SKB_FRAGS) || | |
63c3a66f | 10131 | (tg3_flag(tp, TSO_BUG) && |
bc3a9254 | 10132 | (ering->tx_pending <= (MAX_SKB_FRAGS * 3)))) |
1da177e4 | 10133 | return -EINVAL; |
6aa20a22 | 10134 | |
bbe832c0 | 10135 | if (netif_running(dev)) { |
b02fd9e3 | 10136 | tg3_phy_stop(tp); |
1da177e4 | 10137 | tg3_netif_stop(tp); |
bbe832c0 MC |
10138 | irq_sync = 1; |
10139 | } | |
1da177e4 | 10140 | |
bbe832c0 | 10141 | tg3_full_lock(tp, irq_sync); |
6aa20a22 | 10142 | |
1da177e4 LT |
10143 | tp->rx_pending = ering->rx_pending; |
10144 | ||
63c3a66f | 10145 | if (tg3_flag(tp, MAX_RXPEND_64) && |
1da177e4 LT |
10146 | tp->rx_pending > 63) |
10147 | tp->rx_pending = 63; | |
10148 | tp->rx_jumbo_pending = ering->rx_jumbo_pending; | |
646c9edd | 10149 | |
6fd45cb8 | 10150 | for (i = 0; i < tp->irq_max; i++) |
646c9edd | 10151 | tp->napi[i].tx_pending = ering->tx_pending; |
1da177e4 LT |
10152 | |
10153 | if (netif_running(dev)) { | |
944d980e | 10154 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
b9ec6c1b MC |
10155 | err = tg3_restart_hw(tp, 1); |
10156 | if (!err) | |
10157 | tg3_netif_start(tp); | |
1da177e4 LT |
10158 | } |
10159 | ||
f47c11ee | 10160 | tg3_full_unlock(tp); |
6aa20a22 | 10161 | |
b02fd9e3 MC |
10162 | if (irq_sync && !err) |
10163 | tg3_phy_start(tp); | |
10164 | ||
b9ec6c1b | 10165 | return err; |
1da177e4 | 10166 | } |
6aa20a22 | 10167 | |
1da177e4 LT |
10168 | static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
10169 | { | |
10170 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 10171 | |
63c3a66f | 10172 | epause->autoneg = !!tg3_flag(tp, PAUSE_AUTONEG); |
8d018621 | 10173 | |
e18ce346 | 10174 | if (tp->link_config.active_flowctrl & FLOW_CTRL_RX) |
8d018621 MC |
10175 | epause->rx_pause = 1; |
10176 | else | |
10177 | epause->rx_pause = 0; | |
10178 | ||
e18ce346 | 10179 | if (tp->link_config.active_flowctrl & FLOW_CTRL_TX) |
8d018621 MC |
10180 | epause->tx_pause = 1; |
10181 | else | |
10182 | epause->tx_pause = 0; | |
1da177e4 | 10183 | } |
6aa20a22 | 10184 | |
1da177e4 LT |
10185 | static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
10186 | { | |
10187 | struct tg3 *tp = netdev_priv(dev); | |
b02fd9e3 | 10188 | int err = 0; |
6aa20a22 | 10189 | |
63c3a66f | 10190 | if (tg3_flag(tp, USE_PHYLIB)) { |
2712168f MC |
10191 | u32 newadv; |
10192 | struct phy_device *phydev; | |
1da177e4 | 10193 | |
2712168f | 10194 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
f47c11ee | 10195 | |
2712168f MC |
10196 | if (!(phydev->supported & SUPPORTED_Pause) || |
10197 | (!(phydev->supported & SUPPORTED_Asym_Pause) && | |
2259dca3 | 10198 | (epause->rx_pause != epause->tx_pause))) |
2712168f | 10199 | return -EINVAL; |
1da177e4 | 10200 | |
2712168f MC |
10201 | tp->link_config.flowctrl = 0; |
10202 | if (epause->rx_pause) { | |
10203 | tp->link_config.flowctrl |= FLOW_CTRL_RX; | |
10204 | ||
10205 | if (epause->tx_pause) { | |
10206 | tp->link_config.flowctrl |= FLOW_CTRL_TX; | |
10207 | newadv = ADVERTISED_Pause; | |
b02fd9e3 | 10208 | } else |
2712168f MC |
10209 | newadv = ADVERTISED_Pause | |
10210 | ADVERTISED_Asym_Pause; | |
10211 | } else if (epause->tx_pause) { | |
10212 | tp->link_config.flowctrl |= FLOW_CTRL_TX; | |
10213 | newadv = ADVERTISED_Asym_Pause; | |
10214 | } else | |
10215 | newadv = 0; | |
10216 | ||
10217 | if (epause->autoneg) | |
63c3a66f | 10218 | tg3_flag_set(tp, PAUSE_AUTONEG); |
2712168f | 10219 | else |
63c3a66f | 10220 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
2712168f | 10221 | |
f07e9af3 | 10222 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
2712168f MC |
10223 | u32 oldadv = phydev->advertising & |
10224 | (ADVERTISED_Pause | ADVERTISED_Asym_Pause); | |
10225 | if (oldadv != newadv) { | |
10226 | phydev->advertising &= | |
10227 | ~(ADVERTISED_Pause | | |
10228 | ADVERTISED_Asym_Pause); | |
10229 | phydev->advertising |= newadv; | |
10230 | if (phydev->autoneg) { | |
10231 | /* | |
10232 | * Always renegotiate the link to | |
10233 | * inform our link partner of our | |
10234 | * flow control settings, even if the | |
10235 | * flow control is forced. Let | |
10236 | * tg3_adjust_link() do the final | |
10237 | * flow control setup. | |
10238 | */ | |
10239 | return phy_start_aneg(phydev); | |
b02fd9e3 | 10240 | } |
b02fd9e3 | 10241 | } |
b02fd9e3 | 10242 | |
2712168f | 10243 | if (!epause->autoneg) |
b02fd9e3 | 10244 | tg3_setup_flow_control(tp, 0, 0); |
2712168f MC |
10245 | } else { |
10246 | tp->link_config.orig_advertising &= | |
10247 | ~(ADVERTISED_Pause | | |
10248 | ADVERTISED_Asym_Pause); | |
10249 | tp->link_config.orig_advertising |= newadv; | |
b02fd9e3 MC |
10250 | } |
10251 | } else { | |
10252 | int irq_sync = 0; | |
10253 | ||
10254 | if (netif_running(dev)) { | |
10255 | tg3_netif_stop(tp); | |
10256 | irq_sync = 1; | |
10257 | } | |
10258 | ||
10259 | tg3_full_lock(tp, irq_sync); | |
10260 | ||
10261 | if (epause->autoneg) | |
63c3a66f | 10262 | tg3_flag_set(tp, PAUSE_AUTONEG); |
b02fd9e3 | 10263 | else |
63c3a66f | 10264 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
b02fd9e3 | 10265 | if (epause->rx_pause) |
e18ce346 | 10266 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
b02fd9e3 | 10267 | else |
e18ce346 | 10268 | tp->link_config.flowctrl &= ~FLOW_CTRL_RX; |
b02fd9e3 | 10269 | if (epause->tx_pause) |
e18ce346 | 10270 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
b02fd9e3 | 10271 | else |
e18ce346 | 10272 | tp->link_config.flowctrl &= ~FLOW_CTRL_TX; |
b02fd9e3 MC |
10273 | |
10274 | if (netif_running(dev)) { | |
10275 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); | |
10276 | err = tg3_restart_hw(tp, 1); | |
10277 | if (!err) | |
10278 | tg3_netif_start(tp); | |
10279 | } | |
10280 | ||
10281 | tg3_full_unlock(tp); | |
10282 | } | |
6aa20a22 | 10283 | |
b9ec6c1b | 10284 | return err; |
1da177e4 | 10285 | } |
6aa20a22 | 10286 | |
de6f31eb | 10287 | static int tg3_get_sset_count(struct net_device *dev, int sset) |
1da177e4 | 10288 | { |
b9f2c044 JG |
10289 | switch (sset) { |
10290 | case ETH_SS_TEST: | |
10291 | return TG3_NUM_TEST; | |
10292 | case ETH_SS_STATS: | |
10293 | return TG3_NUM_STATS; | |
10294 | default: | |
10295 | return -EOPNOTSUPP; | |
10296 | } | |
4cafd3f5 MC |
10297 | } |
10298 | ||
de6f31eb | 10299 | static void tg3_get_strings(struct net_device *dev, u32 stringset, u8 *buf) |
1da177e4 LT |
10300 | { |
10301 | switch (stringset) { | |
10302 | case ETH_SS_STATS: | |
10303 | memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys)); | |
10304 | break; | |
4cafd3f5 MC |
10305 | case ETH_SS_TEST: |
10306 | memcpy(buf, ðtool_test_keys, sizeof(ethtool_test_keys)); | |
10307 | break; | |
1da177e4 LT |
10308 | default: |
10309 | WARN_ON(1); /* we need a WARN() */ | |
10310 | break; | |
10311 | } | |
10312 | } | |
10313 | ||
81b8709c | 10314 | static int tg3_set_phys_id(struct net_device *dev, |
10315 | enum ethtool_phys_id_state state) | |
4009a93d MC |
10316 | { |
10317 | struct tg3 *tp = netdev_priv(dev); | |
4009a93d MC |
10318 | |
10319 | if (!netif_running(tp->dev)) | |
10320 | return -EAGAIN; | |
10321 | ||
81b8709c | 10322 | switch (state) { |
10323 | case ETHTOOL_ID_ACTIVE: | |
fce55922 | 10324 | return 1; /* cycle on/off once per second */ |
4009a93d | 10325 | |
81b8709c | 10326 | case ETHTOOL_ID_ON: |
10327 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | | |
10328 | LED_CTRL_1000MBPS_ON | | |
10329 | LED_CTRL_100MBPS_ON | | |
10330 | LED_CTRL_10MBPS_ON | | |
10331 | LED_CTRL_TRAFFIC_OVERRIDE | | |
10332 | LED_CTRL_TRAFFIC_BLINK | | |
10333 | LED_CTRL_TRAFFIC_LED); | |
10334 | break; | |
6aa20a22 | 10335 | |
81b8709c | 10336 | case ETHTOOL_ID_OFF: |
10337 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | | |
10338 | LED_CTRL_TRAFFIC_OVERRIDE); | |
10339 | break; | |
4009a93d | 10340 | |
81b8709c | 10341 | case ETHTOOL_ID_INACTIVE: |
10342 | tw32(MAC_LED_CTRL, tp->led_ctrl); | |
10343 | break; | |
4009a93d | 10344 | } |
81b8709c | 10345 | |
4009a93d MC |
10346 | return 0; |
10347 | } | |
10348 | ||
de6f31eb | 10349 | static void tg3_get_ethtool_stats(struct net_device *dev, |
1da177e4 LT |
10350 | struct ethtool_stats *estats, u64 *tmp_stats) |
10351 | { | |
10352 | struct tg3 *tp = netdev_priv(dev); | |
10353 | memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats)); | |
10354 | } | |
10355 | ||
c3e94500 MC |
10356 | static __be32 * tg3_vpd_readblock(struct tg3 *tp) |
10357 | { | |
10358 | int i; | |
10359 | __be32 *buf; | |
10360 | u32 offset = 0, len = 0; | |
10361 | u32 magic, val; | |
10362 | ||
63c3a66f | 10363 | if (tg3_flag(tp, NO_NVRAM) || tg3_nvram_read(tp, 0, &magic)) |
c3e94500 MC |
10364 | return NULL; |
10365 | ||
10366 | if (magic == TG3_EEPROM_MAGIC) { | |
10367 | for (offset = TG3_NVM_DIR_START; | |
10368 | offset < TG3_NVM_DIR_END; | |
10369 | offset += TG3_NVM_DIRENT_SIZE) { | |
10370 | if (tg3_nvram_read(tp, offset, &val)) | |
10371 | return NULL; | |
10372 | ||
10373 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == | |
10374 | TG3_NVM_DIRTYPE_EXTVPD) | |
10375 | break; | |
10376 | } | |
10377 | ||
10378 | if (offset != TG3_NVM_DIR_END) { | |
10379 | len = (val & TG3_NVM_DIRTYPE_LENMSK) * 4; | |
10380 | if (tg3_nvram_read(tp, offset + 4, &offset)) | |
10381 | return NULL; | |
10382 | ||
10383 | offset = tg3_nvram_logical_addr(tp, offset); | |
10384 | } | |
10385 | } | |
10386 | ||
10387 | if (!offset || !len) { | |
10388 | offset = TG3_NVM_VPD_OFF; | |
10389 | len = TG3_NVM_VPD_LEN; | |
10390 | } | |
10391 | ||
10392 | buf = kmalloc(len, GFP_KERNEL); | |
10393 | if (buf == NULL) | |
10394 | return NULL; | |
10395 | ||
10396 | if (magic == TG3_EEPROM_MAGIC) { | |
10397 | for (i = 0; i < len; i += 4) { | |
10398 | /* The data is in little-endian format in NVRAM. | |
10399 | * Use the big-endian read routines to preserve | |
10400 | * the byte order as it exists in NVRAM. | |
10401 | */ | |
10402 | if (tg3_nvram_read_be32(tp, offset + i, &buf[i/4])) | |
10403 | goto error; | |
10404 | } | |
10405 | } else { | |
10406 | u8 *ptr; | |
10407 | ssize_t cnt; | |
10408 | unsigned int pos = 0; | |
10409 | ||
10410 | ptr = (u8 *)&buf[0]; | |
10411 | for (i = 0; pos < len && i < 3; i++, pos += cnt, ptr += cnt) { | |
10412 | cnt = pci_read_vpd(tp->pdev, pos, | |
10413 | len - pos, ptr); | |
10414 | if (cnt == -ETIMEDOUT || cnt == -EINTR) | |
10415 | cnt = 0; | |
10416 | else if (cnt < 0) | |
10417 | goto error; | |
10418 | } | |
10419 | if (pos != len) | |
10420 | goto error; | |
10421 | } | |
10422 | ||
10423 | return buf; | |
10424 | ||
10425 | error: | |
10426 | kfree(buf); | |
10427 | return NULL; | |
10428 | } | |
10429 | ||
566f86ad | 10430 | #define NVRAM_TEST_SIZE 0x100 |
a5767dec MC |
10431 | #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14 |
10432 | #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18 | |
10433 | #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c | |
b16250e3 MC |
10434 | #define NVRAM_SELFBOOT_HW_SIZE 0x20 |
10435 | #define NVRAM_SELFBOOT_DATA_SIZE 0x1c | |
566f86ad MC |
10436 | |
10437 | static int tg3_test_nvram(struct tg3 *tp) | |
10438 | { | |
b9fc7dc5 | 10439 | u32 csum, magic; |
a9dc529d | 10440 | __be32 *buf; |
ab0049b4 | 10441 | int i, j, k, err = 0, size; |
566f86ad | 10442 | |
63c3a66f | 10443 | if (tg3_flag(tp, NO_NVRAM)) |
df259d8c MC |
10444 | return 0; |
10445 | ||
e4f34110 | 10446 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
1b27777a MC |
10447 | return -EIO; |
10448 | ||
1b27777a MC |
10449 | if (magic == TG3_EEPROM_MAGIC) |
10450 | size = NVRAM_TEST_SIZE; | |
b16250e3 | 10451 | else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) { |
a5767dec MC |
10452 | if ((magic & TG3_EEPROM_SB_FORMAT_MASK) == |
10453 | TG3_EEPROM_SB_FORMAT_1) { | |
10454 | switch (magic & TG3_EEPROM_SB_REVISION_MASK) { | |
10455 | case TG3_EEPROM_SB_REVISION_0: | |
10456 | size = NVRAM_SELFBOOT_FORMAT1_0_SIZE; | |
10457 | break; | |
10458 | case TG3_EEPROM_SB_REVISION_2: | |
10459 | size = NVRAM_SELFBOOT_FORMAT1_2_SIZE; | |
10460 | break; | |
10461 | case TG3_EEPROM_SB_REVISION_3: | |
10462 | size = NVRAM_SELFBOOT_FORMAT1_3_SIZE; | |
10463 | break; | |
10464 | default: | |
10465 | return 0; | |
10466 | } | |
10467 | } else | |
1b27777a | 10468 | return 0; |
b16250e3 MC |
10469 | } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
10470 | size = NVRAM_SELFBOOT_HW_SIZE; | |
10471 | else | |
1b27777a MC |
10472 | return -EIO; |
10473 | ||
10474 | buf = kmalloc(size, GFP_KERNEL); | |
566f86ad MC |
10475 | if (buf == NULL) |
10476 | return -ENOMEM; | |
10477 | ||
1b27777a MC |
10478 | err = -EIO; |
10479 | for (i = 0, j = 0; i < size; i += 4, j++) { | |
a9dc529d MC |
10480 | err = tg3_nvram_read_be32(tp, i, &buf[j]); |
10481 | if (err) | |
566f86ad | 10482 | break; |
566f86ad | 10483 | } |
1b27777a | 10484 | if (i < size) |
566f86ad MC |
10485 | goto out; |
10486 | ||
1b27777a | 10487 | /* Selfboot format */ |
a9dc529d | 10488 | magic = be32_to_cpu(buf[0]); |
b9fc7dc5 | 10489 | if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == |
b16250e3 | 10490 | TG3_EEPROM_MAGIC_FW) { |
1b27777a MC |
10491 | u8 *buf8 = (u8 *) buf, csum8 = 0; |
10492 | ||
b9fc7dc5 | 10493 | if ((magic & TG3_EEPROM_SB_REVISION_MASK) == |
a5767dec MC |
10494 | TG3_EEPROM_SB_REVISION_2) { |
10495 | /* For rev 2, the csum doesn't include the MBA. */ | |
10496 | for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++) | |
10497 | csum8 += buf8[i]; | |
10498 | for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++) | |
10499 | csum8 += buf8[i]; | |
10500 | } else { | |
10501 | for (i = 0; i < size; i++) | |
10502 | csum8 += buf8[i]; | |
10503 | } | |
1b27777a | 10504 | |
ad96b485 AB |
10505 | if (csum8 == 0) { |
10506 | err = 0; | |
10507 | goto out; | |
10508 | } | |
10509 | ||
10510 | err = -EIO; | |
10511 | goto out; | |
1b27777a | 10512 | } |
566f86ad | 10513 | |
b9fc7dc5 | 10514 | if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == |
b16250e3 MC |
10515 | TG3_EEPROM_MAGIC_HW) { |
10516 | u8 data[NVRAM_SELFBOOT_DATA_SIZE]; | |
a9dc529d | 10517 | u8 parity[NVRAM_SELFBOOT_DATA_SIZE]; |
b16250e3 | 10518 | u8 *buf8 = (u8 *) buf; |
b16250e3 MC |
10519 | |
10520 | /* Separate the parity bits and the data bytes. */ | |
10521 | for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) { | |
10522 | if ((i == 0) || (i == 8)) { | |
10523 | int l; | |
10524 | u8 msk; | |
10525 | ||
10526 | for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1) | |
10527 | parity[k++] = buf8[i] & msk; | |
10528 | i++; | |
859a5887 | 10529 | } else if (i == 16) { |
b16250e3 MC |
10530 | int l; |
10531 | u8 msk; | |
10532 | ||
10533 | for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1) | |
10534 | parity[k++] = buf8[i] & msk; | |
10535 | i++; | |
10536 | ||
10537 | for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1) | |
10538 | parity[k++] = buf8[i] & msk; | |
10539 | i++; | |
10540 | } | |
10541 | data[j++] = buf8[i]; | |
10542 | } | |
10543 | ||
10544 | err = -EIO; | |
10545 | for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) { | |
10546 | u8 hw8 = hweight8(data[i]); | |
10547 | ||
10548 | if ((hw8 & 0x1) && parity[i]) | |
10549 | goto out; | |
10550 | else if (!(hw8 & 0x1) && !parity[i]) | |
10551 | goto out; | |
10552 | } | |
10553 | err = 0; | |
10554 | goto out; | |
10555 | } | |
10556 | ||
01c3a392 MC |
10557 | err = -EIO; |
10558 | ||
566f86ad MC |
10559 | /* Bootstrap checksum at offset 0x10 */ |
10560 | csum = calc_crc((unsigned char *) buf, 0x10); | |
01c3a392 | 10561 | if (csum != le32_to_cpu(buf[0x10/4])) |
566f86ad MC |
10562 | goto out; |
10563 | ||
10564 | /* Manufacturing block starts at offset 0x74, checksum at 0xfc */ | |
10565 | csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88); | |
01c3a392 | 10566 | if (csum != le32_to_cpu(buf[0xfc/4])) |
a9dc529d | 10567 | goto out; |
566f86ad | 10568 | |
c3e94500 MC |
10569 | kfree(buf); |
10570 | ||
10571 | buf = tg3_vpd_readblock(tp); | |
10572 | if (!buf) | |
10573 | return -ENOMEM; | |
d4894f3e MC |
10574 | |
10575 | i = pci_vpd_find_tag((u8 *)buf, 0, TG3_NVM_VPD_LEN, | |
10576 | PCI_VPD_LRDT_RO_DATA); | |
10577 | if (i > 0) { | |
10578 | j = pci_vpd_lrdt_size(&((u8 *)buf)[i]); | |
10579 | if (j < 0) | |
10580 | goto out; | |
10581 | ||
10582 | if (i + PCI_VPD_LRDT_TAG_SIZE + j > TG3_NVM_VPD_LEN) | |
10583 | goto out; | |
10584 | ||
10585 | i += PCI_VPD_LRDT_TAG_SIZE; | |
10586 | j = pci_vpd_find_info_keyword((u8 *)buf, i, j, | |
10587 | PCI_VPD_RO_KEYWORD_CHKSUM); | |
10588 | if (j > 0) { | |
10589 | u8 csum8 = 0; | |
10590 | ||
10591 | j += PCI_VPD_INFO_FLD_HDR_SIZE; | |
10592 | ||
10593 | for (i = 0; i <= j; i++) | |
10594 | csum8 += ((u8 *)buf)[i]; | |
10595 | ||
10596 | if (csum8) | |
10597 | goto out; | |
10598 | } | |
10599 | } | |
10600 | ||
566f86ad MC |
10601 | err = 0; |
10602 | ||
10603 | out: | |
10604 | kfree(buf); | |
10605 | return err; | |
10606 | } | |
10607 | ||
ca43007a MC |
10608 | #define TG3_SERDES_TIMEOUT_SEC 2 |
10609 | #define TG3_COPPER_TIMEOUT_SEC 6 | |
10610 | ||
10611 | static int tg3_test_link(struct tg3 *tp) | |
10612 | { | |
10613 | int i, max; | |
10614 | ||
10615 | if (!netif_running(tp->dev)) | |
10616 | return -ENODEV; | |
10617 | ||
f07e9af3 | 10618 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
ca43007a MC |
10619 | max = TG3_SERDES_TIMEOUT_SEC; |
10620 | else | |
10621 | max = TG3_COPPER_TIMEOUT_SEC; | |
10622 | ||
10623 | for (i = 0; i < max; i++) { | |
10624 | if (netif_carrier_ok(tp->dev)) | |
10625 | return 0; | |
10626 | ||
10627 | if (msleep_interruptible(1000)) | |
10628 | break; | |
10629 | } | |
10630 | ||
10631 | return -EIO; | |
10632 | } | |
10633 | ||
a71116d1 | 10634 | /* Only test the commonly used registers */ |
30ca3e37 | 10635 | static int tg3_test_registers(struct tg3 *tp) |
a71116d1 | 10636 | { |
b16250e3 | 10637 | int i, is_5705, is_5750; |
a71116d1 MC |
10638 | u32 offset, read_mask, write_mask, val, save_val, read_val; |
10639 | static struct { | |
10640 | u16 offset; | |
10641 | u16 flags; | |
10642 | #define TG3_FL_5705 0x1 | |
10643 | #define TG3_FL_NOT_5705 0x2 | |
10644 | #define TG3_FL_NOT_5788 0x4 | |
b16250e3 | 10645 | #define TG3_FL_NOT_5750 0x8 |
a71116d1 MC |
10646 | u32 read_mask; |
10647 | u32 write_mask; | |
10648 | } reg_tbl[] = { | |
10649 | /* MAC Control Registers */ | |
10650 | { MAC_MODE, TG3_FL_NOT_5705, | |
10651 | 0x00000000, 0x00ef6f8c }, | |
10652 | { MAC_MODE, TG3_FL_5705, | |
10653 | 0x00000000, 0x01ef6b8c }, | |
10654 | { MAC_STATUS, TG3_FL_NOT_5705, | |
10655 | 0x03800107, 0x00000000 }, | |
10656 | { MAC_STATUS, TG3_FL_5705, | |
10657 | 0x03800100, 0x00000000 }, | |
10658 | { MAC_ADDR_0_HIGH, 0x0000, | |
10659 | 0x00000000, 0x0000ffff }, | |
10660 | { MAC_ADDR_0_LOW, 0x0000, | |
c6cdf436 | 10661 | 0x00000000, 0xffffffff }, |
a71116d1 MC |
10662 | { MAC_RX_MTU_SIZE, 0x0000, |
10663 | 0x00000000, 0x0000ffff }, | |
10664 | { MAC_TX_MODE, 0x0000, | |
10665 | 0x00000000, 0x00000070 }, | |
10666 | { MAC_TX_LENGTHS, 0x0000, | |
10667 | 0x00000000, 0x00003fff }, | |
10668 | { MAC_RX_MODE, TG3_FL_NOT_5705, | |
10669 | 0x00000000, 0x000007fc }, | |
10670 | { MAC_RX_MODE, TG3_FL_5705, | |
10671 | 0x00000000, 0x000007dc }, | |
10672 | { MAC_HASH_REG_0, 0x0000, | |
10673 | 0x00000000, 0xffffffff }, | |
10674 | { MAC_HASH_REG_1, 0x0000, | |
10675 | 0x00000000, 0xffffffff }, | |
10676 | { MAC_HASH_REG_2, 0x0000, | |
10677 | 0x00000000, 0xffffffff }, | |
10678 | { MAC_HASH_REG_3, 0x0000, | |
10679 | 0x00000000, 0xffffffff }, | |
10680 | ||
10681 | /* Receive Data and Receive BD Initiator Control Registers. */ | |
10682 | { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705, | |
10683 | 0x00000000, 0xffffffff }, | |
10684 | { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705, | |
10685 | 0x00000000, 0xffffffff }, | |
10686 | { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705, | |
10687 | 0x00000000, 0x00000003 }, | |
10688 | { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705, | |
10689 | 0x00000000, 0xffffffff }, | |
10690 | { RCVDBDI_STD_BD+0, 0x0000, | |
10691 | 0x00000000, 0xffffffff }, | |
10692 | { RCVDBDI_STD_BD+4, 0x0000, | |
10693 | 0x00000000, 0xffffffff }, | |
10694 | { RCVDBDI_STD_BD+8, 0x0000, | |
10695 | 0x00000000, 0xffff0002 }, | |
10696 | { RCVDBDI_STD_BD+0xc, 0x0000, | |
10697 | 0x00000000, 0xffffffff }, | |
6aa20a22 | 10698 | |
a71116d1 MC |
10699 | /* Receive BD Initiator Control Registers. */ |
10700 | { RCVBDI_STD_THRESH, TG3_FL_NOT_5705, | |
10701 | 0x00000000, 0xffffffff }, | |
10702 | { RCVBDI_STD_THRESH, TG3_FL_5705, | |
10703 | 0x00000000, 0x000003ff }, | |
10704 | { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705, | |
10705 | 0x00000000, 0xffffffff }, | |
6aa20a22 | 10706 | |
a71116d1 MC |
10707 | /* Host Coalescing Control Registers. */ |
10708 | { HOSTCC_MODE, TG3_FL_NOT_5705, | |
10709 | 0x00000000, 0x00000004 }, | |
10710 | { HOSTCC_MODE, TG3_FL_5705, | |
10711 | 0x00000000, 0x000000f6 }, | |
10712 | { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705, | |
10713 | 0x00000000, 0xffffffff }, | |
10714 | { HOSTCC_RXCOL_TICKS, TG3_FL_5705, | |
10715 | 0x00000000, 0x000003ff }, | |
10716 | { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705, | |
10717 | 0x00000000, 0xffffffff }, | |
10718 | { HOSTCC_TXCOL_TICKS, TG3_FL_5705, | |
10719 | 0x00000000, 0x000003ff }, | |
10720 | { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705, | |
10721 | 0x00000000, 0xffffffff }, | |
10722 | { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, | |
10723 | 0x00000000, 0x000000ff }, | |
10724 | { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705, | |
10725 | 0x00000000, 0xffffffff }, | |
10726 | { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, | |
10727 | 0x00000000, 0x000000ff }, | |
10728 | { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705, | |
10729 | 0x00000000, 0xffffffff }, | |
10730 | { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705, | |
10731 | 0x00000000, 0xffffffff }, | |
10732 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705, | |
10733 | 0x00000000, 0xffffffff }, | |
10734 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, | |
10735 | 0x00000000, 0x000000ff }, | |
10736 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705, | |
10737 | 0x00000000, 0xffffffff }, | |
10738 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, | |
10739 | 0x00000000, 0x000000ff }, | |
10740 | { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705, | |
10741 | 0x00000000, 0xffffffff }, | |
10742 | { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705, | |
10743 | 0x00000000, 0xffffffff }, | |
10744 | { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705, | |
10745 | 0x00000000, 0xffffffff }, | |
10746 | { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000, | |
10747 | 0x00000000, 0xffffffff }, | |
10748 | { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000, | |
10749 | 0x00000000, 0xffffffff }, | |
10750 | { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000, | |
10751 | 0xffffffff, 0x00000000 }, | |
10752 | { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000, | |
10753 | 0xffffffff, 0x00000000 }, | |
10754 | ||
10755 | /* Buffer Manager Control Registers. */ | |
b16250e3 | 10756 | { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750, |
a71116d1 | 10757 | 0x00000000, 0x007fff80 }, |
b16250e3 | 10758 | { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750, |
a71116d1 MC |
10759 | 0x00000000, 0x007fffff }, |
10760 | { BUFMGR_MB_RDMA_LOW_WATER, 0x0000, | |
10761 | 0x00000000, 0x0000003f }, | |
10762 | { BUFMGR_MB_MACRX_LOW_WATER, 0x0000, | |
10763 | 0x00000000, 0x000001ff }, | |
10764 | { BUFMGR_MB_HIGH_WATER, 0x0000, | |
10765 | 0x00000000, 0x000001ff }, | |
10766 | { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705, | |
10767 | 0xffffffff, 0x00000000 }, | |
10768 | { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705, | |
10769 | 0xffffffff, 0x00000000 }, | |
6aa20a22 | 10770 | |
a71116d1 MC |
10771 | /* Mailbox Registers */ |
10772 | { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000, | |
10773 | 0x00000000, 0x000001ff }, | |
10774 | { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705, | |
10775 | 0x00000000, 0x000001ff }, | |
10776 | { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000, | |
10777 | 0x00000000, 0x000007ff }, | |
10778 | { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000, | |
10779 | 0x00000000, 0x000001ff }, | |
10780 | ||
10781 | { 0xffff, 0x0000, 0x00000000, 0x00000000 }, | |
10782 | }; | |
10783 | ||
b16250e3 | 10784 | is_5705 = is_5750 = 0; |
63c3a66f | 10785 | if (tg3_flag(tp, 5705_PLUS)) { |
a71116d1 | 10786 | is_5705 = 1; |
63c3a66f | 10787 | if (tg3_flag(tp, 5750_PLUS)) |
b16250e3 MC |
10788 | is_5750 = 1; |
10789 | } | |
a71116d1 MC |
10790 | |
10791 | for (i = 0; reg_tbl[i].offset != 0xffff; i++) { | |
10792 | if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705)) | |
10793 | continue; | |
10794 | ||
10795 | if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705)) | |
10796 | continue; | |
10797 | ||
63c3a66f | 10798 | if (tg3_flag(tp, IS_5788) && |
a71116d1 MC |
10799 | (reg_tbl[i].flags & TG3_FL_NOT_5788)) |
10800 | continue; | |
10801 | ||
b16250e3 MC |
10802 | if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750)) |
10803 | continue; | |
10804 | ||
a71116d1 MC |
10805 | offset = (u32) reg_tbl[i].offset; |
10806 | read_mask = reg_tbl[i].read_mask; | |
10807 | write_mask = reg_tbl[i].write_mask; | |
10808 | ||
10809 | /* Save the original register content */ | |
10810 | save_val = tr32(offset); | |
10811 | ||
10812 | /* Determine the read-only value. */ | |
10813 | read_val = save_val & read_mask; | |
10814 | ||
10815 | /* Write zero to the register, then make sure the read-only bits | |
10816 | * are not changed and the read/write bits are all zeros. | |
10817 | */ | |
10818 | tw32(offset, 0); | |
10819 | ||
10820 | val = tr32(offset); | |
10821 | ||
10822 | /* Test the read-only and read/write bits. */ | |
10823 | if (((val & read_mask) != read_val) || (val & write_mask)) | |
10824 | goto out; | |
10825 | ||
10826 | /* Write ones to all the bits defined by RdMask and WrMask, then | |
10827 | * make sure the read-only bits are not changed and the | |
10828 | * read/write bits are all ones. | |
10829 | */ | |
10830 | tw32(offset, read_mask | write_mask); | |
10831 | ||
10832 | val = tr32(offset); | |
10833 | ||
10834 | /* Test the read-only bits. */ | |
10835 | if ((val & read_mask) != read_val) | |
10836 | goto out; | |
10837 | ||
10838 | /* Test the read/write bits. */ | |
10839 | if ((val & write_mask) != write_mask) | |
10840 | goto out; | |
10841 | ||
10842 | tw32(offset, save_val); | |
10843 | } | |
10844 | ||
10845 | return 0; | |
10846 | ||
10847 | out: | |
9f88f29f | 10848 | if (netif_msg_hw(tp)) |
2445e461 MC |
10849 | netdev_err(tp->dev, |
10850 | "Register test failed at offset %x\n", offset); | |
a71116d1 MC |
10851 | tw32(offset, save_val); |
10852 | return -EIO; | |
10853 | } | |
10854 | ||
7942e1db MC |
10855 | static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len) |
10856 | { | |
f71e1309 | 10857 | static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a }; |
7942e1db MC |
10858 | int i; |
10859 | u32 j; | |
10860 | ||
e9edda69 | 10861 | for (i = 0; i < ARRAY_SIZE(test_pattern); i++) { |
7942e1db MC |
10862 | for (j = 0; j < len; j += 4) { |
10863 | u32 val; | |
10864 | ||
10865 | tg3_write_mem(tp, offset + j, test_pattern[i]); | |
10866 | tg3_read_mem(tp, offset + j, &val); | |
10867 | if (val != test_pattern[i]) | |
10868 | return -EIO; | |
10869 | } | |
10870 | } | |
10871 | return 0; | |
10872 | } | |
10873 | ||
10874 | static int tg3_test_memory(struct tg3 *tp) | |
10875 | { | |
10876 | static struct mem_entry { | |
10877 | u32 offset; | |
10878 | u32 len; | |
10879 | } mem_tbl_570x[] = { | |
38690194 | 10880 | { 0x00000000, 0x00b50}, |
7942e1db MC |
10881 | { 0x00002000, 0x1c000}, |
10882 | { 0xffffffff, 0x00000} | |
10883 | }, mem_tbl_5705[] = { | |
10884 | { 0x00000100, 0x0000c}, | |
10885 | { 0x00000200, 0x00008}, | |
7942e1db MC |
10886 | { 0x00004000, 0x00800}, |
10887 | { 0x00006000, 0x01000}, | |
10888 | { 0x00008000, 0x02000}, | |
10889 | { 0x00010000, 0x0e000}, | |
10890 | { 0xffffffff, 0x00000} | |
79f4d13a MC |
10891 | }, mem_tbl_5755[] = { |
10892 | { 0x00000200, 0x00008}, | |
10893 | { 0x00004000, 0x00800}, | |
10894 | { 0x00006000, 0x00800}, | |
10895 | { 0x00008000, 0x02000}, | |
10896 | { 0x00010000, 0x0c000}, | |
10897 | { 0xffffffff, 0x00000} | |
b16250e3 MC |
10898 | }, mem_tbl_5906[] = { |
10899 | { 0x00000200, 0x00008}, | |
10900 | { 0x00004000, 0x00400}, | |
10901 | { 0x00006000, 0x00400}, | |
10902 | { 0x00008000, 0x01000}, | |
10903 | { 0x00010000, 0x01000}, | |
10904 | { 0xffffffff, 0x00000} | |
8b5a6c42 MC |
10905 | }, mem_tbl_5717[] = { |
10906 | { 0x00000200, 0x00008}, | |
10907 | { 0x00010000, 0x0a000}, | |
10908 | { 0x00020000, 0x13c00}, | |
10909 | { 0xffffffff, 0x00000} | |
10910 | }, mem_tbl_57765[] = { | |
10911 | { 0x00000200, 0x00008}, | |
10912 | { 0x00004000, 0x00800}, | |
10913 | { 0x00006000, 0x09800}, | |
10914 | { 0x00010000, 0x0a000}, | |
10915 | { 0xffffffff, 0x00000} | |
7942e1db MC |
10916 | }; |
10917 | struct mem_entry *mem_tbl; | |
10918 | int err = 0; | |
10919 | int i; | |
10920 | ||
63c3a66f | 10921 | if (tg3_flag(tp, 5717_PLUS)) |
8b5a6c42 MC |
10922 | mem_tbl = mem_tbl_5717; |
10923 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) | |
10924 | mem_tbl = mem_tbl_57765; | |
63c3a66f | 10925 | else if (tg3_flag(tp, 5755_PLUS)) |
321d32a0 MC |
10926 | mem_tbl = mem_tbl_5755; |
10927 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) | |
10928 | mem_tbl = mem_tbl_5906; | |
63c3a66f | 10929 | else if (tg3_flag(tp, 5705_PLUS)) |
321d32a0 MC |
10930 | mem_tbl = mem_tbl_5705; |
10931 | else | |
7942e1db MC |
10932 | mem_tbl = mem_tbl_570x; |
10933 | ||
10934 | for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) { | |
be98da6a MC |
10935 | err = tg3_do_mem_test(tp, mem_tbl[i].offset, mem_tbl[i].len); |
10936 | if (err) | |
7942e1db MC |
10937 | break; |
10938 | } | |
6aa20a22 | 10939 | |
7942e1db MC |
10940 | return err; |
10941 | } | |
10942 | ||
9f40dead MC |
10943 | #define TG3_MAC_LOOPBACK 0 |
10944 | #define TG3_PHY_LOOPBACK 1 | |
bb158d69 MC |
10945 | #define TG3_TSO_LOOPBACK 2 |
10946 | ||
10947 | #define TG3_TSO_MSS 500 | |
10948 | ||
10949 | #define TG3_TSO_IP_HDR_LEN 20 | |
10950 | #define TG3_TSO_TCP_HDR_LEN 20 | |
10951 | #define TG3_TSO_TCP_OPT_LEN 12 | |
10952 | ||
10953 | static const u8 tg3_tso_header[] = { | |
10954 | 0x08, 0x00, | |
10955 | 0x45, 0x00, 0x00, 0x00, | |
10956 | 0x00, 0x00, 0x40, 0x00, | |
10957 | 0x40, 0x06, 0x00, 0x00, | |
10958 | 0x0a, 0x00, 0x00, 0x01, | |
10959 | 0x0a, 0x00, 0x00, 0x02, | |
10960 | 0x0d, 0x00, 0xe0, 0x00, | |
10961 | 0x00, 0x00, 0x01, 0x00, | |
10962 | 0x00, 0x00, 0x02, 0x00, | |
10963 | 0x80, 0x10, 0x10, 0x00, | |
10964 | 0x14, 0x09, 0x00, 0x00, | |
10965 | 0x01, 0x01, 0x08, 0x0a, | |
10966 | 0x11, 0x11, 0x11, 0x11, | |
10967 | 0x11, 0x11, 0x11, 0x11, | |
10968 | }; | |
9f40dead | 10969 | |
4852a861 | 10970 | static int tg3_run_loopback(struct tg3 *tp, u32 pktsz, int loopback_mode) |
c76949a6 | 10971 | { |
9f40dead | 10972 | u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key; |
bb158d69 | 10973 | u32 base_flags = 0, mss = 0, desc_idx, coal_now, data_off, val; |
c76949a6 MC |
10974 | struct sk_buff *skb, *rx_skb; |
10975 | u8 *tx_data; | |
10976 | dma_addr_t map; | |
10977 | int num_pkts, tx_len, rx_len, i, err; | |
10978 | struct tg3_rx_buffer_desc *desc; | |
898a56f8 | 10979 | struct tg3_napi *tnapi, *rnapi; |
8fea32b9 | 10980 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
c76949a6 | 10981 | |
c8873405 MC |
10982 | tnapi = &tp->napi[0]; |
10983 | rnapi = &tp->napi[0]; | |
0c1d0e2b | 10984 | if (tp->irq_cnt > 1) { |
63c3a66f | 10985 | if (tg3_flag(tp, ENABLE_RSS)) |
1da85aa3 | 10986 | rnapi = &tp->napi[1]; |
63c3a66f | 10987 | if (tg3_flag(tp, ENABLE_TSS)) |
c8873405 | 10988 | tnapi = &tp->napi[1]; |
0c1d0e2b | 10989 | } |
fd2ce37f | 10990 | coal_now = tnapi->coal_now | rnapi->coal_now; |
898a56f8 | 10991 | |
9f40dead | 10992 | if (loopback_mode == TG3_MAC_LOOPBACK) { |
c94e3941 MC |
10993 | /* HW errata - mac loopback fails in some cases on 5780. |
10994 | * Normal traffic and PHY loopback are not affected by | |
aba49f24 MC |
10995 | * errata. Also, the MAC loopback test is deprecated for |
10996 | * all newer ASIC revisions. | |
c94e3941 | 10997 | */ |
aba49f24 | 10998 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 || |
63c3a66f | 10999 | tg3_flag(tp, CPMU_PRESENT)) |
c94e3941 MC |
11000 | return 0; |
11001 | ||
49692ca1 MC |
11002 | mac_mode = tp->mac_mode & |
11003 | ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); | |
11004 | mac_mode |= MAC_MODE_PORT_INT_LPBACK; | |
63c3a66f | 11005 | if (!tg3_flag(tp, 5705_PLUS)) |
e8f3f6ca | 11006 | mac_mode |= MAC_MODE_LINK_POLARITY; |
f07e9af3 | 11007 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
3f7045c1 MC |
11008 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
11009 | else | |
11010 | mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
9f40dead | 11011 | tw32(MAC_MODE, mac_mode); |
bb158d69 | 11012 | } else { |
f07e9af3 | 11013 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
7f97a4bd | 11014 | tg3_phy_fet_toggle_apd(tp, false); |
5d64ad34 MC |
11015 | val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100; |
11016 | } else | |
11017 | val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000; | |
3f7045c1 | 11018 | |
9ef8ca99 MC |
11019 | tg3_phy_toggle_automdix(tp, 0); |
11020 | ||
3f7045c1 | 11021 | tg3_writephy(tp, MII_BMCR, val); |
c94e3941 | 11022 | udelay(40); |
5d64ad34 | 11023 | |
49692ca1 MC |
11024 | mac_mode = tp->mac_mode & |
11025 | ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); | |
f07e9af3 | 11026 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
1061b7c5 MC |
11027 | tg3_writephy(tp, MII_TG3_FET_PTEST, |
11028 | MII_TG3_FET_PTEST_FRC_TX_LINK | | |
11029 | MII_TG3_FET_PTEST_FRC_TX_LOCK); | |
11030 | /* The write needs to be flushed for the AC131 */ | |
11031 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) | |
11032 | tg3_readphy(tp, MII_TG3_FET_PTEST, &val); | |
5d64ad34 MC |
11033 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
11034 | } else | |
11035 | mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
b16250e3 | 11036 | |
c94e3941 | 11037 | /* reset to prevent losing 1st rx packet intermittently */ |
f07e9af3 | 11038 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
c94e3941 MC |
11039 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
11040 | udelay(10); | |
11041 | tw32_f(MAC_RX_MODE, tp->rx_mode); | |
11042 | } | |
e8f3f6ca | 11043 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
79eb6904 MC |
11044 | u32 masked_phy_id = tp->phy_id & TG3_PHY_ID_MASK; |
11045 | if (masked_phy_id == TG3_PHY_ID_BCM5401) | |
e8f3f6ca | 11046 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
79eb6904 | 11047 | else if (masked_phy_id == TG3_PHY_ID_BCM5411) |
e8f3f6ca | 11048 | mac_mode |= MAC_MODE_LINK_POLARITY; |
ff18ff02 MC |
11049 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
11050 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); | |
11051 | } | |
9f40dead | 11052 | tw32(MAC_MODE, mac_mode); |
49692ca1 MC |
11053 | |
11054 | /* Wait for link */ | |
11055 | for (i = 0; i < 100; i++) { | |
11056 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) | |
11057 | break; | |
11058 | mdelay(1); | |
11059 | } | |
859a5887 | 11060 | } |
c76949a6 MC |
11061 | |
11062 | err = -EIO; | |
11063 | ||
4852a861 | 11064 | tx_len = pktsz; |
a20e9c62 | 11065 | skb = netdev_alloc_skb(tp->dev, tx_len); |
a50bb7b9 JJ |
11066 | if (!skb) |
11067 | return -ENOMEM; | |
11068 | ||
c76949a6 MC |
11069 | tx_data = skb_put(skb, tx_len); |
11070 | memcpy(tx_data, tp->dev->dev_addr, 6); | |
11071 | memset(tx_data + 6, 0x0, 8); | |
11072 | ||
4852a861 | 11073 | tw32(MAC_RX_MTU_SIZE, tx_len + ETH_FCS_LEN); |
c76949a6 | 11074 | |
bb158d69 MC |
11075 | if (loopback_mode == TG3_TSO_LOOPBACK) { |
11076 | struct iphdr *iph = (struct iphdr *)&tx_data[ETH_HLEN]; | |
11077 | ||
11078 | u32 hdr_len = TG3_TSO_IP_HDR_LEN + TG3_TSO_TCP_HDR_LEN + | |
11079 | TG3_TSO_TCP_OPT_LEN; | |
11080 | ||
11081 | memcpy(tx_data + ETH_ALEN * 2, tg3_tso_header, | |
11082 | sizeof(tg3_tso_header)); | |
11083 | mss = TG3_TSO_MSS; | |
11084 | ||
11085 | val = tx_len - ETH_ALEN * 2 - sizeof(tg3_tso_header); | |
11086 | num_pkts = DIV_ROUND_UP(val, TG3_TSO_MSS); | |
11087 | ||
11088 | /* Set the total length field in the IP header */ | |
11089 | iph->tot_len = htons((u16)(mss + hdr_len)); | |
11090 | ||
11091 | base_flags = (TXD_FLAG_CPU_PRE_DMA | | |
11092 | TXD_FLAG_CPU_POST_DMA); | |
11093 | ||
63c3a66f JP |
11094 | if (tg3_flag(tp, HW_TSO_1) || |
11095 | tg3_flag(tp, HW_TSO_2) || | |
11096 | tg3_flag(tp, HW_TSO_3)) { | |
bb158d69 MC |
11097 | struct tcphdr *th; |
11098 | val = ETH_HLEN + TG3_TSO_IP_HDR_LEN; | |
11099 | th = (struct tcphdr *)&tx_data[val]; | |
11100 | th->check = 0; | |
11101 | } else | |
11102 | base_flags |= TXD_FLAG_TCPUDP_CSUM; | |
11103 | ||
63c3a66f | 11104 | if (tg3_flag(tp, HW_TSO_3)) { |
bb158d69 MC |
11105 | mss |= (hdr_len & 0xc) << 12; |
11106 | if (hdr_len & 0x10) | |
11107 | base_flags |= 0x00000010; | |
11108 | base_flags |= (hdr_len & 0x3e0) << 5; | |
63c3a66f | 11109 | } else if (tg3_flag(tp, HW_TSO_2)) |
bb158d69 | 11110 | mss |= hdr_len << 9; |
63c3a66f | 11111 | else if (tg3_flag(tp, HW_TSO_1) || |
bb158d69 MC |
11112 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
11113 | mss |= (TG3_TSO_TCP_OPT_LEN << 9); | |
11114 | } else { | |
11115 | base_flags |= (TG3_TSO_TCP_OPT_LEN << 10); | |
11116 | } | |
11117 | ||
11118 | data_off = ETH_ALEN * 2 + sizeof(tg3_tso_header); | |
11119 | } else { | |
11120 | num_pkts = 1; | |
11121 | data_off = ETH_HLEN; | |
11122 | } | |
11123 | ||
11124 | for (i = data_off; i < tx_len; i++) | |
c76949a6 MC |
11125 | tx_data[i] = (u8) (i & 0xff); |
11126 | ||
f4188d8a AD |
11127 | map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE); |
11128 | if (pci_dma_mapping_error(tp->pdev, map)) { | |
a21771dd MC |
11129 | dev_kfree_skb(skb); |
11130 | return -EIO; | |
11131 | } | |
c76949a6 MC |
11132 | |
11133 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | | |
fd2ce37f | 11134 | rnapi->coal_now); |
c76949a6 MC |
11135 | |
11136 | udelay(10); | |
11137 | ||
898a56f8 | 11138 | rx_start_idx = rnapi->hw_status->idx[0].rx_producer; |
c76949a6 | 11139 | |
bb158d69 MC |
11140 | tg3_set_txd(tnapi, tnapi->tx_prod, map, tx_len, |
11141 | base_flags, (mss << 1) | 1); | |
c76949a6 | 11142 | |
f3f3f27e | 11143 | tnapi->tx_prod++; |
c76949a6 | 11144 | |
f3f3f27e MC |
11145 | tw32_tx_mbox(tnapi->prodmbox, tnapi->tx_prod); |
11146 | tr32_mailbox(tnapi->prodmbox); | |
c76949a6 MC |
11147 | |
11148 | udelay(10); | |
11149 | ||
303fc921 MC |
11150 | /* 350 usec to allow enough time on some 10/100 Mbps devices. */ |
11151 | for (i = 0; i < 35; i++) { | |
c76949a6 | 11152 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
fd2ce37f | 11153 | coal_now); |
c76949a6 MC |
11154 | |
11155 | udelay(10); | |
11156 | ||
898a56f8 MC |
11157 | tx_idx = tnapi->hw_status->idx[0].tx_consumer; |
11158 | rx_idx = rnapi->hw_status->idx[0].rx_producer; | |
f3f3f27e | 11159 | if ((tx_idx == tnapi->tx_prod) && |
c76949a6 MC |
11160 | (rx_idx == (rx_start_idx + num_pkts))) |
11161 | break; | |
11162 | } | |
11163 | ||
f4188d8a | 11164 | pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE); |
c76949a6 MC |
11165 | dev_kfree_skb(skb); |
11166 | ||
f3f3f27e | 11167 | if (tx_idx != tnapi->tx_prod) |
c76949a6 MC |
11168 | goto out; |
11169 | ||
11170 | if (rx_idx != rx_start_idx + num_pkts) | |
11171 | goto out; | |
11172 | ||
bb158d69 MC |
11173 | val = data_off; |
11174 | while (rx_idx != rx_start_idx) { | |
11175 | desc = &rnapi->rx_rcb[rx_start_idx++]; | |
11176 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; | |
11177 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; | |
c76949a6 | 11178 | |
bb158d69 MC |
11179 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
11180 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) | |
11181 | goto out; | |
c76949a6 | 11182 | |
bb158d69 MC |
11183 | rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) |
11184 | - ETH_FCS_LEN; | |
c76949a6 | 11185 | |
bb158d69 MC |
11186 | if (loopback_mode != TG3_TSO_LOOPBACK) { |
11187 | if (rx_len != tx_len) | |
11188 | goto out; | |
4852a861 | 11189 | |
bb158d69 MC |
11190 | if (pktsz <= TG3_RX_STD_DMA_SZ - ETH_FCS_LEN) { |
11191 | if (opaque_key != RXD_OPAQUE_RING_STD) | |
11192 | goto out; | |
11193 | } else { | |
11194 | if (opaque_key != RXD_OPAQUE_RING_JUMBO) | |
11195 | goto out; | |
11196 | } | |
11197 | } else if ((desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && | |
11198 | (desc->ip_tcp_csum & RXD_TCPCSUM_MASK) | |
11199 | >> RXD_TCPCSUM_SHIFT == 0xffff) { | |
4852a861 | 11200 | goto out; |
bb158d69 | 11201 | } |
4852a861 | 11202 | |
bb158d69 MC |
11203 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
11204 | rx_skb = tpr->rx_std_buffers[desc_idx].skb; | |
11205 | map = dma_unmap_addr(&tpr->rx_std_buffers[desc_idx], | |
11206 | mapping); | |
11207 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { | |
11208 | rx_skb = tpr->rx_jmb_buffers[desc_idx].skb; | |
11209 | map = dma_unmap_addr(&tpr->rx_jmb_buffers[desc_idx], | |
11210 | mapping); | |
11211 | } else | |
11212 | goto out; | |
c76949a6 | 11213 | |
bb158d69 MC |
11214 | pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, |
11215 | PCI_DMA_FROMDEVICE); | |
c76949a6 | 11216 | |
bb158d69 MC |
11217 | for (i = data_off; i < rx_len; i++, val++) { |
11218 | if (*(rx_skb->data + i) != (u8) (val & 0xff)) | |
11219 | goto out; | |
11220 | } | |
c76949a6 | 11221 | } |
bb158d69 | 11222 | |
c76949a6 | 11223 | err = 0; |
6aa20a22 | 11224 | |
c76949a6 MC |
11225 | /* tg3_free_rings will unmap and free the rx_skb */ |
11226 | out: | |
11227 | return err; | |
11228 | } | |
11229 | ||
00c266b7 MC |
11230 | #define TG3_STD_LOOPBACK_FAILED 1 |
11231 | #define TG3_JMB_LOOPBACK_FAILED 2 | |
bb158d69 | 11232 | #define TG3_TSO_LOOPBACK_FAILED 4 |
00c266b7 MC |
11233 | |
11234 | #define TG3_MAC_LOOPBACK_SHIFT 0 | |
11235 | #define TG3_PHY_LOOPBACK_SHIFT 4 | |
bb158d69 | 11236 | #define TG3_LOOPBACK_FAILED 0x00000077 |
9f40dead MC |
11237 | |
11238 | static int tg3_test_loopback(struct tg3 *tp) | |
11239 | { | |
11240 | int err = 0; | |
ab789046 | 11241 | u32 eee_cap, cpmuctrl = 0; |
9f40dead MC |
11242 | |
11243 | if (!netif_running(tp->dev)) | |
11244 | return TG3_LOOPBACK_FAILED; | |
11245 | ||
ab789046 MC |
11246 | eee_cap = tp->phy_flags & TG3_PHYFLG_EEE_CAP; |
11247 | tp->phy_flags &= ~TG3_PHYFLG_EEE_CAP; | |
11248 | ||
b9ec6c1b | 11249 | err = tg3_reset_hw(tp, 1); |
ab789046 MC |
11250 | if (err) { |
11251 | err = TG3_LOOPBACK_FAILED; | |
11252 | goto done; | |
11253 | } | |
9f40dead | 11254 | |
63c3a66f | 11255 | if (tg3_flag(tp, ENABLE_RSS)) { |
4a85f098 MC |
11256 | int i; |
11257 | ||
11258 | /* Reroute all rx packets to the 1st queue */ | |
11259 | for (i = MAC_RSS_INDIR_TBL_0; | |
11260 | i < MAC_RSS_INDIR_TBL_0 + TG3_RSS_INDIR_TBL_SIZE; i += 4) | |
11261 | tw32(i, 0x0); | |
11262 | } | |
11263 | ||
6833c043 | 11264 | /* Turn off gphy autopowerdown. */ |
f07e9af3 | 11265 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
6833c043 MC |
11266 | tg3_phy_toggle_apd(tp, false); |
11267 | ||
63c3a66f | 11268 | if (tg3_flag(tp, CPMU_PRESENT)) { |
9936bcf6 MC |
11269 | int i; |
11270 | u32 status; | |
11271 | ||
11272 | tw32(TG3_CPMU_MUTEX_REQ, CPMU_MUTEX_REQ_DRIVER); | |
11273 | ||
11274 | /* Wait for up to 40 microseconds to acquire lock. */ | |
11275 | for (i = 0; i < 4; i++) { | |
11276 | status = tr32(TG3_CPMU_MUTEX_GNT); | |
11277 | if (status == CPMU_MUTEX_GNT_DRIVER) | |
11278 | break; | |
11279 | udelay(10); | |
11280 | } | |
11281 | ||
ab789046 MC |
11282 | if (status != CPMU_MUTEX_GNT_DRIVER) { |
11283 | err = TG3_LOOPBACK_FAILED; | |
11284 | goto done; | |
11285 | } | |
9936bcf6 | 11286 | |
b2a5c19c | 11287 | /* Turn off link-based power management. */ |
e875093c | 11288 | cpmuctrl = tr32(TG3_CPMU_CTRL); |
109115e1 MC |
11289 | tw32(TG3_CPMU_CTRL, |
11290 | cpmuctrl & ~(CPMU_CTRL_LINK_SPEED_MODE | | |
11291 | CPMU_CTRL_LINK_AWARE_MODE)); | |
9936bcf6 MC |
11292 | } |
11293 | ||
4852a861 | 11294 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, TG3_MAC_LOOPBACK)) |
00c266b7 | 11295 | err |= TG3_STD_LOOPBACK_FAILED << TG3_MAC_LOOPBACK_SHIFT; |
9936bcf6 | 11296 | |
63c3a66f | 11297 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
4852a861 | 11298 | tg3_run_loopback(tp, 9000 + ETH_HLEN, TG3_MAC_LOOPBACK)) |
00c266b7 | 11299 | err |= TG3_JMB_LOOPBACK_FAILED << TG3_MAC_LOOPBACK_SHIFT; |
4852a861 | 11300 | |
63c3a66f | 11301 | if (tg3_flag(tp, CPMU_PRESENT)) { |
9936bcf6 MC |
11302 | tw32(TG3_CPMU_CTRL, cpmuctrl); |
11303 | ||
11304 | /* Release the mutex */ | |
11305 | tw32(TG3_CPMU_MUTEX_GNT, CPMU_MUTEX_GNT_DRIVER); | |
11306 | } | |
11307 | ||
f07e9af3 | 11308 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
63c3a66f | 11309 | !tg3_flag(tp, USE_PHYLIB)) { |
4852a861 | 11310 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, TG3_PHY_LOOPBACK)) |
00c266b7 MC |
11311 | err |= TG3_STD_LOOPBACK_FAILED << |
11312 | TG3_PHY_LOOPBACK_SHIFT; | |
63c3a66f | 11313 | if (tg3_flag(tp, TSO_CAPABLE) && |
bb158d69 MC |
11314 | tg3_run_loopback(tp, ETH_FRAME_LEN, TG3_TSO_LOOPBACK)) |
11315 | err |= TG3_TSO_LOOPBACK_FAILED << | |
11316 | TG3_PHY_LOOPBACK_SHIFT; | |
63c3a66f | 11317 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
4852a861 | 11318 | tg3_run_loopback(tp, 9000 + ETH_HLEN, TG3_PHY_LOOPBACK)) |
00c266b7 MC |
11319 | err |= TG3_JMB_LOOPBACK_FAILED << |
11320 | TG3_PHY_LOOPBACK_SHIFT; | |
9f40dead MC |
11321 | } |
11322 | ||
6833c043 | 11323 | /* Re-enable gphy autopowerdown. */ |
f07e9af3 | 11324 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
6833c043 MC |
11325 | tg3_phy_toggle_apd(tp, true); |
11326 | ||
ab789046 MC |
11327 | done: |
11328 | tp->phy_flags |= eee_cap; | |
11329 | ||
9f40dead MC |
11330 | return err; |
11331 | } | |
11332 | ||
4cafd3f5 MC |
11333 | static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, |
11334 | u64 *data) | |
11335 | { | |
566f86ad MC |
11336 | struct tg3 *tp = netdev_priv(dev); |
11337 | ||
80096068 | 11338 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
c866b7ea | 11339 | tg3_power_up(tp); |
bc1c7567 | 11340 | |
566f86ad MC |
11341 | memset(data, 0, sizeof(u64) * TG3_NUM_TEST); |
11342 | ||
11343 | if (tg3_test_nvram(tp) != 0) { | |
11344 | etest->flags |= ETH_TEST_FL_FAILED; | |
11345 | data[0] = 1; | |
11346 | } | |
ca43007a MC |
11347 | if (tg3_test_link(tp) != 0) { |
11348 | etest->flags |= ETH_TEST_FL_FAILED; | |
11349 | data[1] = 1; | |
11350 | } | |
a71116d1 | 11351 | if (etest->flags & ETH_TEST_FL_OFFLINE) { |
b02fd9e3 | 11352 | int err, err2 = 0, irq_sync = 0; |
bbe832c0 MC |
11353 | |
11354 | if (netif_running(dev)) { | |
b02fd9e3 | 11355 | tg3_phy_stop(tp); |
a71116d1 | 11356 | tg3_netif_stop(tp); |
bbe832c0 MC |
11357 | irq_sync = 1; |
11358 | } | |
a71116d1 | 11359 | |
bbe832c0 | 11360 | tg3_full_lock(tp, irq_sync); |
a71116d1 MC |
11361 | |
11362 | tg3_halt(tp, RESET_KIND_SUSPEND, 1); | |
ec41c7df | 11363 | err = tg3_nvram_lock(tp); |
a71116d1 | 11364 | tg3_halt_cpu(tp, RX_CPU_BASE); |
63c3a66f | 11365 | if (!tg3_flag(tp, 5705_PLUS)) |
a71116d1 | 11366 | tg3_halt_cpu(tp, TX_CPU_BASE); |
ec41c7df MC |
11367 | if (!err) |
11368 | tg3_nvram_unlock(tp); | |
a71116d1 | 11369 | |
f07e9af3 | 11370 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
d9ab5ad1 MC |
11371 | tg3_phy_reset(tp); |
11372 | ||
a71116d1 MC |
11373 | if (tg3_test_registers(tp) != 0) { |
11374 | etest->flags |= ETH_TEST_FL_FAILED; | |
11375 | data[2] = 1; | |
11376 | } | |
7942e1db MC |
11377 | if (tg3_test_memory(tp) != 0) { |
11378 | etest->flags |= ETH_TEST_FL_FAILED; | |
11379 | data[3] = 1; | |
11380 | } | |
9f40dead | 11381 | if ((data[4] = tg3_test_loopback(tp)) != 0) |
c76949a6 | 11382 | etest->flags |= ETH_TEST_FL_FAILED; |
a71116d1 | 11383 | |
f47c11ee DM |
11384 | tg3_full_unlock(tp); |
11385 | ||
d4bc3927 MC |
11386 | if (tg3_test_interrupt(tp) != 0) { |
11387 | etest->flags |= ETH_TEST_FL_FAILED; | |
11388 | data[5] = 1; | |
11389 | } | |
f47c11ee DM |
11390 | |
11391 | tg3_full_lock(tp, 0); | |
d4bc3927 | 11392 | |
a71116d1 MC |
11393 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
11394 | if (netif_running(dev)) { | |
63c3a66f | 11395 | tg3_flag_set(tp, INIT_COMPLETE); |
b02fd9e3 MC |
11396 | err2 = tg3_restart_hw(tp, 1); |
11397 | if (!err2) | |
b9ec6c1b | 11398 | tg3_netif_start(tp); |
a71116d1 | 11399 | } |
f47c11ee DM |
11400 | |
11401 | tg3_full_unlock(tp); | |
b02fd9e3 MC |
11402 | |
11403 | if (irq_sync && !err2) | |
11404 | tg3_phy_start(tp); | |
a71116d1 | 11405 | } |
80096068 | 11406 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
c866b7ea | 11407 | tg3_power_down(tp); |
bc1c7567 | 11408 | |
4cafd3f5 MC |
11409 | } |
11410 | ||
1da177e4 LT |
11411 | static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
11412 | { | |
11413 | struct mii_ioctl_data *data = if_mii(ifr); | |
11414 | struct tg3 *tp = netdev_priv(dev); | |
11415 | int err; | |
11416 | ||
63c3a66f | 11417 | if (tg3_flag(tp, USE_PHYLIB)) { |
3f0e3ad7 | 11418 | struct phy_device *phydev; |
f07e9af3 | 11419 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 | 11420 | return -EAGAIN; |
3f0e3ad7 | 11421 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
28b04113 | 11422 | return phy_mii_ioctl(phydev, ifr, cmd); |
b02fd9e3 MC |
11423 | } |
11424 | ||
33f401ae | 11425 | switch (cmd) { |
1da177e4 | 11426 | case SIOCGMIIPHY: |
882e9793 | 11427 | data->phy_id = tp->phy_addr; |
1da177e4 LT |
11428 | |
11429 | /* fallthru */ | |
11430 | case SIOCGMIIREG: { | |
11431 | u32 mii_regval; | |
11432 | ||
f07e9af3 | 11433 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
1da177e4 LT |
11434 | break; /* We have no PHY */ |
11435 | ||
34eea5ac | 11436 | if (!netif_running(dev)) |
bc1c7567 MC |
11437 | return -EAGAIN; |
11438 | ||
f47c11ee | 11439 | spin_lock_bh(&tp->lock); |
1da177e4 | 11440 | err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval); |
f47c11ee | 11441 | spin_unlock_bh(&tp->lock); |
1da177e4 LT |
11442 | |
11443 | data->val_out = mii_regval; | |
11444 | ||
11445 | return err; | |
11446 | } | |
11447 | ||
11448 | case SIOCSMIIREG: | |
f07e9af3 | 11449 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
1da177e4 LT |
11450 | break; /* We have no PHY */ |
11451 | ||
34eea5ac | 11452 | if (!netif_running(dev)) |
bc1c7567 MC |
11453 | return -EAGAIN; |
11454 | ||
f47c11ee | 11455 | spin_lock_bh(&tp->lock); |
1da177e4 | 11456 | err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in); |
f47c11ee | 11457 | spin_unlock_bh(&tp->lock); |
1da177e4 LT |
11458 | |
11459 | return err; | |
11460 | ||
11461 | default: | |
11462 | /* do nothing */ | |
11463 | break; | |
11464 | } | |
11465 | return -EOPNOTSUPP; | |
11466 | } | |
11467 | ||
15f9850d DM |
11468 | static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
11469 | { | |
11470 | struct tg3 *tp = netdev_priv(dev); | |
11471 | ||
11472 | memcpy(ec, &tp->coal, sizeof(*ec)); | |
11473 | return 0; | |
11474 | } | |
11475 | ||
d244c892 MC |
11476 | static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
11477 | { | |
11478 | struct tg3 *tp = netdev_priv(dev); | |
11479 | u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0; | |
11480 | u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0; | |
11481 | ||
63c3a66f | 11482 | if (!tg3_flag(tp, 5705_PLUS)) { |
d244c892 MC |
11483 | max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT; |
11484 | max_txcoal_tick_int = MAX_TXCOAL_TICK_INT; | |
11485 | max_stat_coal_ticks = MAX_STAT_COAL_TICKS; | |
11486 | min_stat_coal_ticks = MIN_STAT_COAL_TICKS; | |
11487 | } | |
11488 | ||
11489 | if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) || | |
11490 | (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) || | |
11491 | (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) || | |
11492 | (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) || | |
11493 | (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) || | |
11494 | (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) || | |
11495 | (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) || | |
11496 | (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) || | |
11497 | (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) || | |
11498 | (ec->stats_block_coalesce_usecs < min_stat_coal_ticks)) | |
11499 | return -EINVAL; | |
11500 | ||
11501 | /* No rx interrupts will be generated if both are zero */ | |
11502 | if ((ec->rx_coalesce_usecs == 0) && | |
11503 | (ec->rx_max_coalesced_frames == 0)) | |
11504 | return -EINVAL; | |
11505 | ||
11506 | /* No tx interrupts will be generated if both are zero */ | |
11507 | if ((ec->tx_coalesce_usecs == 0) && | |
11508 | (ec->tx_max_coalesced_frames == 0)) | |
11509 | return -EINVAL; | |
11510 | ||
11511 | /* Only copy relevant parameters, ignore all others. */ | |
11512 | tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs; | |
11513 | tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs; | |
11514 | tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames; | |
11515 | tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames; | |
11516 | tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; | |
11517 | tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; | |
11518 | tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; | |
11519 | tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; | |
11520 | tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs; | |
11521 | ||
11522 | if (netif_running(dev)) { | |
11523 | tg3_full_lock(tp, 0); | |
11524 | __tg3_set_coalesce(tp, &tp->coal); | |
11525 | tg3_full_unlock(tp); | |
11526 | } | |
11527 | return 0; | |
11528 | } | |
11529 | ||
7282d491 | 11530 | static const struct ethtool_ops tg3_ethtool_ops = { |
1da177e4 LT |
11531 | .get_settings = tg3_get_settings, |
11532 | .set_settings = tg3_set_settings, | |
11533 | .get_drvinfo = tg3_get_drvinfo, | |
11534 | .get_regs_len = tg3_get_regs_len, | |
11535 | .get_regs = tg3_get_regs, | |
11536 | .get_wol = tg3_get_wol, | |
11537 | .set_wol = tg3_set_wol, | |
11538 | .get_msglevel = tg3_get_msglevel, | |
11539 | .set_msglevel = tg3_set_msglevel, | |
11540 | .nway_reset = tg3_nway_reset, | |
11541 | .get_link = ethtool_op_get_link, | |
11542 | .get_eeprom_len = tg3_get_eeprom_len, | |
11543 | .get_eeprom = tg3_get_eeprom, | |
11544 | .set_eeprom = tg3_set_eeprom, | |
11545 | .get_ringparam = tg3_get_ringparam, | |
11546 | .set_ringparam = tg3_set_ringparam, | |
11547 | .get_pauseparam = tg3_get_pauseparam, | |
11548 | .set_pauseparam = tg3_set_pauseparam, | |
4cafd3f5 | 11549 | .self_test = tg3_self_test, |
1da177e4 | 11550 | .get_strings = tg3_get_strings, |
81b8709c | 11551 | .set_phys_id = tg3_set_phys_id, |
1da177e4 | 11552 | .get_ethtool_stats = tg3_get_ethtool_stats, |
15f9850d | 11553 | .get_coalesce = tg3_get_coalesce, |
d244c892 | 11554 | .set_coalesce = tg3_set_coalesce, |
b9f2c044 | 11555 | .get_sset_count = tg3_get_sset_count, |
1da177e4 LT |
11556 | }; |
11557 | ||
11558 | static void __devinit tg3_get_eeprom_size(struct tg3 *tp) | |
11559 | { | |
1b27777a | 11560 | u32 cursize, val, magic; |
1da177e4 LT |
11561 | |
11562 | tp->nvram_size = EEPROM_CHIP_SIZE; | |
11563 | ||
e4f34110 | 11564 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
1da177e4 LT |
11565 | return; |
11566 | ||
b16250e3 MC |
11567 | if ((magic != TG3_EEPROM_MAGIC) && |
11568 | ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) && | |
11569 | ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW)) | |
1da177e4 LT |
11570 | return; |
11571 | ||
11572 | /* | |
11573 | * Size the chip by reading offsets at increasing powers of two. | |
11574 | * When we encounter our validation signature, we know the addressing | |
11575 | * has wrapped around, and thus have our chip size. | |
11576 | */ | |
1b27777a | 11577 | cursize = 0x10; |
1da177e4 LT |
11578 | |
11579 | while (cursize < tp->nvram_size) { | |
e4f34110 | 11580 | if (tg3_nvram_read(tp, cursize, &val) != 0) |
1da177e4 LT |
11581 | return; |
11582 | ||
1820180b | 11583 | if (val == magic) |
1da177e4 LT |
11584 | break; |
11585 | ||
11586 | cursize <<= 1; | |
11587 | } | |
11588 | ||
11589 | tp->nvram_size = cursize; | |
11590 | } | |
6aa20a22 | 11591 | |
1da177e4 LT |
11592 | static void __devinit tg3_get_nvram_size(struct tg3 *tp) |
11593 | { | |
11594 | u32 val; | |
11595 | ||
63c3a66f | 11596 | if (tg3_flag(tp, NO_NVRAM) || tg3_nvram_read(tp, 0, &val) != 0) |
1b27777a MC |
11597 | return; |
11598 | ||
11599 | /* Selfboot format */ | |
1820180b | 11600 | if (val != TG3_EEPROM_MAGIC) { |
1b27777a MC |
11601 | tg3_get_eeprom_size(tp); |
11602 | return; | |
11603 | } | |
11604 | ||
6d348f2c | 11605 | if (tg3_nvram_read(tp, 0xf0, &val) == 0) { |
1da177e4 | 11606 | if (val != 0) { |
6d348f2c MC |
11607 | /* This is confusing. We want to operate on the |
11608 | * 16-bit value at offset 0xf2. The tg3_nvram_read() | |
11609 | * call will read from NVRAM and byteswap the data | |
11610 | * according to the byteswapping settings for all | |
11611 | * other register accesses. This ensures the data we | |
11612 | * want will always reside in the lower 16-bits. | |
11613 | * However, the data in NVRAM is in LE format, which | |
11614 | * means the data from the NVRAM read will always be | |
11615 | * opposite the endianness of the CPU. The 16-bit | |
11616 | * byteswap then brings the data to CPU endianness. | |
11617 | */ | |
11618 | tp->nvram_size = swab16((u16)(val & 0x0000ffff)) * 1024; | |
1da177e4 LT |
11619 | return; |
11620 | } | |
11621 | } | |
fd1122a2 | 11622 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
1da177e4 LT |
11623 | } |
11624 | ||
11625 | static void __devinit tg3_get_nvram_info(struct tg3 *tp) | |
11626 | { | |
11627 | u32 nvcfg1; | |
11628 | ||
11629 | nvcfg1 = tr32(NVRAM_CFG1); | |
11630 | if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) { | |
63c3a66f | 11631 | tg3_flag_set(tp, FLASH); |
8590a603 | 11632 | } else { |
1da177e4 LT |
11633 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
11634 | tw32(NVRAM_CFG1, nvcfg1); | |
11635 | } | |
11636 | ||
4c987487 | 11637 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) || |
63c3a66f | 11638 | tg3_flag(tp, 5780_CLASS)) { |
1da177e4 | 11639 | switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { |
8590a603 MC |
11640 | case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: |
11641 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11642 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; | |
63c3a66f | 11643 | tg3_flag_set(tp, NVRAM_BUFFERED); |
8590a603 MC |
11644 | break; |
11645 | case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED: | |
11646 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11647 | tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE; | |
11648 | break; | |
11649 | case FLASH_VENDOR_ATMEL_EEPROM: | |
11650 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11651 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; | |
63c3a66f | 11652 | tg3_flag_set(tp, NVRAM_BUFFERED); |
8590a603 MC |
11653 | break; |
11654 | case FLASH_VENDOR_ST: | |
11655 | tp->nvram_jedecnum = JEDEC_ST; | |
11656 | tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE; | |
63c3a66f | 11657 | tg3_flag_set(tp, NVRAM_BUFFERED); |
8590a603 MC |
11658 | break; |
11659 | case FLASH_VENDOR_SAIFUN: | |
11660 | tp->nvram_jedecnum = JEDEC_SAIFUN; | |
11661 | tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE; | |
11662 | break; | |
11663 | case FLASH_VENDOR_SST_SMALL: | |
11664 | case FLASH_VENDOR_SST_LARGE: | |
11665 | tp->nvram_jedecnum = JEDEC_SST; | |
11666 | tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE; | |
11667 | break; | |
1da177e4 | 11668 | } |
8590a603 | 11669 | } else { |
1da177e4 LT |
11670 | tp->nvram_jedecnum = JEDEC_ATMEL; |
11671 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; | |
63c3a66f | 11672 | tg3_flag_set(tp, NVRAM_BUFFERED); |
1da177e4 LT |
11673 | } |
11674 | } | |
11675 | ||
a1b950d5 MC |
11676 | static void __devinit tg3_nvram_get_pagesize(struct tg3 *tp, u32 nvmcfg1) |
11677 | { | |
11678 | switch (nvmcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) { | |
11679 | case FLASH_5752PAGE_SIZE_256: | |
11680 | tp->nvram_pagesize = 256; | |
11681 | break; | |
11682 | case FLASH_5752PAGE_SIZE_512: | |
11683 | tp->nvram_pagesize = 512; | |
11684 | break; | |
11685 | case FLASH_5752PAGE_SIZE_1K: | |
11686 | tp->nvram_pagesize = 1024; | |
11687 | break; | |
11688 | case FLASH_5752PAGE_SIZE_2K: | |
11689 | tp->nvram_pagesize = 2048; | |
11690 | break; | |
11691 | case FLASH_5752PAGE_SIZE_4K: | |
11692 | tp->nvram_pagesize = 4096; | |
11693 | break; | |
11694 | case FLASH_5752PAGE_SIZE_264: | |
11695 | tp->nvram_pagesize = 264; | |
11696 | break; | |
11697 | case FLASH_5752PAGE_SIZE_528: | |
11698 | tp->nvram_pagesize = 528; | |
11699 | break; | |
11700 | } | |
11701 | } | |
11702 | ||
361b4ac2 MC |
11703 | static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp) |
11704 | { | |
11705 | u32 nvcfg1; | |
11706 | ||
11707 | nvcfg1 = tr32(NVRAM_CFG1); | |
11708 | ||
e6af301b MC |
11709 | /* NVRAM protection for TPM */ |
11710 | if (nvcfg1 & (1 << 27)) | |
63c3a66f | 11711 | tg3_flag_set(tp, PROTECTED_NVRAM); |
e6af301b | 11712 | |
361b4ac2 | 11713 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
8590a603 MC |
11714 | case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ: |
11715 | case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ: | |
11716 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 11717 | tg3_flag_set(tp, NVRAM_BUFFERED); |
8590a603 MC |
11718 | break; |
11719 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: | |
11720 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
11721 | tg3_flag_set(tp, NVRAM_BUFFERED); |
11722 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
11723 | break; |
11724 | case FLASH_5752VENDOR_ST_M45PE10: | |
11725 | case FLASH_5752VENDOR_ST_M45PE20: | |
11726 | case FLASH_5752VENDOR_ST_M45PE40: | |
11727 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
11728 | tg3_flag_set(tp, NVRAM_BUFFERED); |
11729 | tg3_flag_set(tp, FLASH); | |
8590a603 | 11730 | break; |
361b4ac2 MC |
11731 | } |
11732 | ||
63c3a66f | 11733 | if (tg3_flag(tp, FLASH)) { |
a1b950d5 | 11734 | tg3_nvram_get_pagesize(tp, nvcfg1); |
8590a603 | 11735 | } else { |
361b4ac2 MC |
11736 | /* For eeprom, set pagesize to maximum eeprom size */ |
11737 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; | |
11738 | ||
11739 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; | |
11740 | tw32(NVRAM_CFG1, nvcfg1); | |
11741 | } | |
11742 | } | |
11743 | ||
d3c7b886 MC |
11744 | static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp) |
11745 | { | |
989a9d23 | 11746 | u32 nvcfg1, protect = 0; |
d3c7b886 MC |
11747 | |
11748 | nvcfg1 = tr32(NVRAM_CFG1); | |
11749 | ||
11750 | /* NVRAM protection for TPM */ | |
989a9d23 | 11751 | if (nvcfg1 & (1 << 27)) { |
63c3a66f | 11752 | tg3_flag_set(tp, PROTECTED_NVRAM); |
989a9d23 MC |
11753 | protect = 1; |
11754 | } | |
d3c7b886 | 11755 | |
989a9d23 MC |
11756 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
11757 | switch (nvcfg1) { | |
8590a603 MC |
11758 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
11759 | case FLASH_5755VENDOR_ATMEL_FLASH_2: | |
11760 | case FLASH_5755VENDOR_ATMEL_FLASH_3: | |
11761 | case FLASH_5755VENDOR_ATMEL_FLASH_5: | |
11762 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
11763 | tg3_flag_set(tp, NVRAM_BUFFERED); |
11764 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
11765 | tp->nvram_pagesize = 264; |
11766 | if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 || | |
11767 | nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5) | |
11768 | tp->nvram_size = (protect ? 0x3e200 : | |
11769 | TG3_NVRAM_SIZE_512KB); | |
11770 | else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) | |
11771 | tp->nvram_size = (protect ? 0x1f200 : | |
11772 | TG3_NVRAM_SIZE_256KB); | |
11773 | else | |
11774 | tp->nvram_size = (protect ? 0x1f200 : | |
11775 | TG3_NVRAM_SIZE_128KB); | |
11776 | break; | |
11777 | case FLASH_5752VENDOR_ST_M45PE10: | |
11778 | case FLASH_5752VENDOR_ST_M45PE20: | |
11779 | case FLASH_5752VENDOR_ST_M45PE40: | |
11780 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
11781 | tg3_flag_set(tp, NVRAM_BUFFERED); |
11782 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
11783 | tp->nvram_pagesize = 256; |
11784 | if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10) | |
11785 | tp->nvram_size = (protect ? | |
11786 | TG3_NVRAM_SIZE_64KB : | |
11787 | TG3_NVRAM_SIZE_128KB); | |
11788 | else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20) | |
11789 | tp->nvram_size = (protect ? | |
11790 | TG3_NVRAM_SIZE_64KB : | |
11791 | TG3_NVRAM_SIZE_256KB); | |
11792 | else | |
11793 | tp->nvram_size = (protect ? | |
11794 | TG3_NVRAM_SIZE_128KB : | |
11795 | TG3_NVRAM_SIZE_512KB); | |
11796 | break; | |
d3c7b886 MC |
11797 | } |
11798 | } | |
11799 | ||
1b27777a MC |
11800 | static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp) |
11801 | { | |
11802 | u32 nvcfg1; | |
11803 | ||
11804 | nvcfg1 = tr32(NVRAM_CFG1); | |
11805 | ||
11806 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
8590a603 MC |
11807 | case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ: |
11808 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: | |
11809 | case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ: | |
11810 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: | |
11811 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 11812 | tg3_flag_set(tp, NVRAM_BUFFERED); |
8590a603 | 11813 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
1b27777a | 11814 | |
8590a603 MC |
11815 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
11816 | tw32(NVRAM_CFG1, nvcfg1); | |
11817 | break; | |
11818 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: | |
11819 | case FLASH_5755VENDOR_ATMEL_FLASH_1: | |
11820 | case FLASH_5755VENDOR_ATMEL_FLASH_2: | |
11821 | case FLASH_5755VENDOR_ATMEL_FLASH_3: | |
11822 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
11823 | tg3_flag_set(tp, NVRAM_BUFFERED); |
11824 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
11825 | tp->nvram_pagesize = 264; |
11826 | break; | |
11827 | case FLASH_5752VENDOR_ST_M45PE10: | |
11828 | case FLASH_5752VENDOR_ST_M45PE20: | |
11829 | case FLASH_5752VENDOR_ST_M45PE40: | |
11830 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
11831 | tg3_flag_set(tp, NVRAM_BUFFERED); |
11832 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
11833 | tp->nvram_pagesize = 256; |
11834 | break; | |
1b27777a MC |
11835 | } |
11836 | } | |
11837 | ||
6b91fa02 MC |
11838 | static void __devinit tg3_get_5761_nvram_info(struct tg3 *tp) |
11839 | { | |
11840 | u32 nvcfg1, protect = 0; | |
11841 | ||
11842 | nvcfg1 = tr32(NVRAM_CFG1); | |
11843 | ||
11844 | /* NVRAM protection for TPM */ | |
11845 | if (nvcfg1 & (1 << 27)) { | |
63c3a66f | 11846 | tg3_flag_set(tp, PROTECTED_NVRAM); |
6b91fa02 MC |
11847 | protect = 1; |
11848 | } | |
11849 | ||
11850 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; | |
11851 | switch (nvcfg1) { | |
8590a603 MC |
11852 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
11853 | case FLASH_5761VENDOR_ATMEL_ADB041D: | |
11854 | case FLASH_5761VENDOR_ATMEL_ADB081D: | |
11855 | case FLASH_5761VENDOR_ATMEL_ADB161D: | |
11856 | case FLASH_5761VENDOR_ATMEL_MDB021D: | |
11857 | case FLASH_5761VENDOR_ATMEL_MDB041D: | |
11858 | case FLASH_5761VENDOR_ATMEL_MDB081D: | |
11859 | case FLASH_5761VENDOR_ATMEL_MDB161D: | |
11860 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
11861 | tg3_flag_set(tp, NVRAM_BUFFERED); |
11862 | tg3_flag_set(tp, FLASH); | |
11863 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); | |
8590a603 MC |
11864 | tp->nvram_pagesize = 256; |
11865 | break; | |
11866 | case FLASH_5761VENDOR_ST_A_M45PE20: | |
11867 | case FLASH_5761VENDOR_ST_A_M45PE40: | |
11868 | case FLASH_5761VENDOR_ST_A_M45PE80: | |
11869 | case FLASH_5761VENDOR_ST_A_M45PE16: | |
11870 | case FLASH_5761VENDOR_ST_M_M45PE20: | |
11871 | case FLASH_5761VENDOR_ST_M_M45PE40: | |
11872 | case FLASH_5761VENDOR_ST_M_M45PE80: | |
11873 | case FLASH_5761VENDOR_ST_M_M45PE16: | |
11874 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
11875 | tg3_flag_set(tp, NVRAM_BUFFERED); |
11876 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
11877 | tp->nvram_pagesize = 256; |
11878 | break; | |
6b91fa02 MC |
11879 | } |
11880 | ||
11881 | if (protect) { | |
11882 | tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT); | |
11883 | } else { | |
11884 | switch (nvcfg1) { | |
8590a603 MC |
11885 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
11886 | case FLASH_5761VENDOR_ATMEL_MDB161D: | |
11887 | case FLASH_5761VENDOR_ST_A_M45PE16: | |
11888 | case FLASH_5761VENDOR_ST_M_M45PE16: | |
11889 | tp->nvram_size = TG3_NVRAM_SIZE_2MB; | |
11890 | break; | |
11891 | case FLASH_5761VENDOR_ATMEL_ADB081D: | |
11892 | case FLASH_5761VENDOR_ATMEL_MDB081D: | |
11893 | case FLASH_5761VENDOR_ST_A_M45PE80: | |
11894 | case FLASH_5761VENDOR_ST_M_M45PE80: | |
11895 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; | |
11896 | break; | |
11897 | case FLASH_5761VENDOR_ATMEL_ADB041D: | |
11898 | case FLASH_5761VENDOR_ATMEL_MDB041D: | |
11899 | case FLASH_5761VENDOR_ST_A_M45PE40: | |
11900 | case FLASH_5761VENDOR_ST_M_M45PE40: | |
11901 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
11902 | break; | |
11903 | case FLASH_5761VENDOR_ATMEL_ADB021D: | |
11904 | case FLASH_5761VENDOR_ATMEL_MDB021D: | |
11905 | case FLASH_5761VENDOR_ST_A_M45PE20: | |
11906 | case FLASH_5761VENDOR_ST_M_M45PE20: | |
11907 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
11908 | break; | |
6b91fa02 MC |
11909 | } |
11910 | } | |
11911 | } | |
11912 | ||
b5d3772c MC |
11913 | static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp) |
11914 | { | |
11915 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 11916 | tg3_flag_set(tp, NVRAM_BUFFERED); |
b5d3772c MC |
11917 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
11918 | } | |
11919 | ||
321d32a0 MC |
11920 | static void __devinit tg3_get_57780_nvram_info(struct tg3 *tp) |
11921 | { | |
11922 | u32 nvcfg1; | |
11923 | ||
11924 | nvcfg1 = tr32(NVRAM_CFG1); | |
11925 | ||
11926 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
11927 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: | |
11928 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: | |
11929 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 11930 | tg3_flag_set(tp, NVRAM_BUFFERED); |
321d32a0 MC |
11931 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
11932 | ||
11933 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; | |
11934 | tw32(NVRAM_CFG1, nvcfg1); | |
11935 | return; | |
11936 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: | |
11937 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: | |
11938 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: | |
11939 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: | |
11940 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: | |
11941 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: | |
11942 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: | |
11943 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
11944 | tg3_flag_set(tp, NVRAM_BUFFERED); |
11945 | tg3_flag_set(tp, FLASH); | |
321d32a0 MC |
11946 | |
11947 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
11948 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: | |
11949 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: | |
11950 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: | |
11951 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
11952 | break; | |
11953 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: | |
11954 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: | |
11955 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
11956 | break; | |
11957 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: | |
11958 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: | |
11959 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
11960 | break; | |
11961 | } | |
11962 | break; | |
11963 | case FLASH_5752VENDOR_ST_M45PE10: | |
11964 | case FLASH_5752VENDOR_ST_M45PE20: | |
11965 | case FLASH_5752VENDOR_ST_M45PE40: | |
11966 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
11967 | tg3_flag_set(tp, NVRAM_BUFFERED); |
11968 | tg3_flag_set(tp, FLASH); | |
321d32a0 MC |
11969 | |
11970 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
11971 | case FLASH_5752VENDOR_ST_M45PE10: | |
11972 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
11973 | break; | |
11974 | case FLASH_5752VENDOR_ST_M45PE20: | |
11975 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
11976 | break; | |
11977 | case FLASH_5752VENDOR_ST_M45PE40: | |
11978 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
11979 | break; | |
11980 | } | |
11981 | break; | |
11982 | default: | |
63c3a66f | 11983 | tg3_flag_set(tp, NO_NVRAM); |
321d32a0 MC |
11984 | return; |
11985 | } | |
11986 | ||
a1b950d5 MC |
11987 | tg3_nvram_get_pagesize(tp, nvcfg1); |
11988 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) | |
63c3a66f | 11989 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
a1b950d5 MC |
11990 | } |
11991 | ||
11992 | ||
11993 | static void __devinit tg3_get_5717_nvram_info(struct tg3 *tp) | |
11994 | { | |
11995 | u32 nvcfg1; | |
11996 | ||
11997 | nvcfg1 = tr32(NVRAM_CFG1); | |
11998 | ||
11999 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
12000 | case FLASH_5717VENDOR_ATMEL_EEPROM: | |
12001 | case FLASH_5717VENDOR_MICRO_EEPROM: | |
12002 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 12003 | tg3_flag_set(tp, NVRAM_BUFFERED); |
a1b950d5 MC |
12004 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
12005 | ||
12006 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; | |
12007 | tw32(NVRAM_CFG1, nvcfg1); | |
12008 | return; | |
12009 | case FLASH_5717VENDOR_ATMEL_MDB011D: | |
12010 | case FLASH_5717VENDOR_ATMEL_ADB011B: | |
12011 | case FLASH_5717VENDOR_ATMEL_ADB011D: | |
12012 | case FLASH_5717VENDOR_ATMEL_MDB021D: | |
12013 | case FLASH_5717VENDOR_ATMEL_ADB021B: | |
12014 | case FLASH_5717VENDOR_ATMEL_ADB021D: | |
12015 | case FLASH_5717VENDOR_ATMEL_45USPT: | |
12016 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
12017 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12018 | tg3_flag_set(tp, FLASH); | |
a1b950d5 MC |
12019 | |
12020 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
12021 | case FLASH_5717VENDOR_ATMEL_MDB021D: | |
66ee33bf MC |
12022 | /* Detect size with tg3_nvram_get_size() */ |
12023 | break; | |
a1b950d5 MC |
12024 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
12025 | case FLASH_5717VENDOR_ATMEL_ADB021D: | |
12026 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
12027 | break; | |
12028 | default: | |
12029 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
12030 | break; | |
12031 | } | |
321d32a0 | 12032 | break; |
a1b950d5 MC |
12033 | case FLASH_5717VENDOR_ST_M_M25PE10: |
12034 | case FLASH_5717VENDOR_ST_A_M25PE10: | |
12035 | case FLASH_5717VENDOR_ST_M_M45PE10: | |
12036 | case FLASH_5717VENDOR_ST_A_M45PE10: | |
12037 | case FLASH_5717VENDOR_ST_M_M25PE20: | |
12038 | case FLASH_5717VENDOR_ST_A_M25PE20: | |
12039 | case FLASH_5717VENDOR_ST_M_M45PE20: | |
12040 | case FLASH_5717VENDOR_ST_A_M45PE20: | |
12041 | case FLASH_5717VENDOR_ST_25USPT: | |
12042 | case FLASH_5717VENDOR_ST_45USPT: | |
12043 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
12044 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12045 | tg3_flag_set(tp, FLASH); | |
a1b950d5 MC |
12046 | |
12047 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
12048 | case FLASH_5717VENDOR_ST_M_M25PE20: | |
a1b950d5 | 12049 | case FLASH_5717VENDOR_ST_M_M45PE20: |
66ee33bf MC |
12050 | /* Detect size with tg3_nvram_get_size() */ |
12051 | break; | |
12052 | case FLASH_5717VENDOR_ST_A_M25PE20: | |
a1b950d5 MC |
12053 | case FLASH_5717VENDOR_ST_A_M45PE20: |
12054 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
12055 | break; | |
12056 | default: | |
12057 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
12058 | break; | |
12059 | } | |
321d32a0 | 12060 | break; |
a1b950d5 | 12061 | default: |
63c3a66f | 12062 | tg3_flag_set(tp, NO_NVRAM); |
a1b950d5 | 12063 | return; |
321d32a0 | 12064 | } |
a1b950d5 MC |
12065 | |
12066 | tg3_nvram_get_pagesize(tp, nvcfg1); | |
12067 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) | |
63c3a66f | 12068 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
321d32a0 MC |
12069 | } |
12070 | ||
9b91b5f1 MC |
12071 | static void __devinit tg3_get_5720_nvram_info(struct tg3 *tp) |
12072 | { | |
12073 | u32 nvcfg1, nvmpinstrp; | |
12074 | ||
12075 | nvcfg1 = tr32(NVRAM_CFG1); | |
12076 | nvmpinstrp = nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK; | |
12077 | ||
12078 | switch (nvmpinstrp) { | |
12079 | case FLASH_5720_EEPROM_HD: | |
12080 | case FLASH_5720_EEPROM_LD: | |
12081 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 12082 | tg3_flag_set(tp, NVRAM_BUFFERED); |
9b91b5f1 MC |
12083 | |
12084 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; | |
12085 | tw32(NVRAM_CFG1, nvcfg1); | |
12086 | if (nvmpinstrp == FLASH_5720_EEPROM_HD) | |
12087 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; | |
12088 | else | |
12089 | tp->nvram_pagesize = ATMEL_AT24C02_CHIP_SIZE; | |
12090 | return; | |
12091 | case FLASH_5720VENDOR_M_ATMEL_DB011D: | |
12092 | case FLASH_5720VENDOR_A_ATMEL_DB011B: | |
12093 | case FLASH_5720VENDOR_A_ATMEL_DB011D: | |
12094 | case FLASH_5720VENDOR_M_ATMEL_DB021D: | |
12095 | case FLASH_5720VENDOR_A_ATMEL_DB021B: | |
12096 | case FLASH_5720VENDOR_A_ATMEL_DB021D: | |
12097 | case FLASH_5720VENDOR_M_ATMEL_DB041D: | |
12098 | case FLASH_5720VENDOR_A_ATMEL_DB041B: | |
12099 | case FLASH_5720VENDOR_A_ATMEL_DB041D: | |
12100 | case FLASH_5720VENDOR_M_ATMEL_DB081D: | |
12101 | case FLASH_5720VENDOR_A_ATMEL_DB081D: | |
12102 | case FLASH_5720VENDOR_ATMEL_45USPT: | |
12103 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
12104 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12105 | tg3_flag_set(tp, FLASH); | |
9b91b5f1 MC |
12106 | |
12107 | switch (nvmpinstrp) { | |
12108 | case FLASH_5720VENDOR_M_ATMEL_DB021D: | |
12109 | case FLASH_5720VENDOR_A_ATMEL_DB021B: | |
12110 | case FLASH_5720VENDOR_A_ATMEL_DB021D: | |
12111 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
12112 | break; | |
12113 | case FLASH_5720VENDOR_M_ATMEL_DB041D: | |
12114 | case FLASH_5720VENDOR_A_ATMEL_DB041B: | |
12115 | case FLASH_5720VENDOR_A_ATMEL_DB041D: | |
12116 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
12117 | break; | |
12118 | case FLASH_5720VENDOR_M_ATMEL_DB081D: | |
12119 | case FLASH_5720VENDOR_A_ATMEL_DB081D: | |
12120 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; | |
12121 | break; | |
12122 | default: | |
12123 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
12124 | break; | |
12125 | } | |
12126 | break; | |
12127 | case FLASH_5720VENDOR_M_ST_M25PE10: | |
12128 | case FLASH_5720VENDOR_M_ST_M45PE10: | |
12129 | case FLASH_5720VENDOR_A_ST_M25PE10: | |
12130 | case FLASH_5720VENDOR_A_ST_M45PE10: | |
12131 | case FLASH_5720VENDOR_M_ST_M25PE20: | |
12132 | case FLASH_5720VENDOR_M_ST_M45PE20: | |
12133 | case FLASH_5720VENDOR_A_ST_M25PE20: | |
12134 | case FLASH_5720VENDOR_A_ST_M45PE20: | |
12135 | case FLASH_5720VENDOR_M_ST_M25PE40: | |
12136 | case FLASH_5720VENDOR_M_ST_M45PE40: | |
12137 | case FLASH_5720VENDOR_A_ST_M25PE40: | |
12138 | case FLASH_5720VENDOR_A_ST_M45PE40: | |
12139 | case FLASH_5720VENDOR_M_ST_M25PE80: | |
12140 | case FLASH_5720VENDOR_M_ST_M45PE80: | |
12141 | case FLASH_5720VENDOR_A_ST_M25PE80: | |
12142 | case FLASH_5720VENDOR_A_ST_M45PE80: | |
12143 | case FLASH_5720VENDOR_ST_25USPT: | |
12144 | case FLASH_5720VENDOR_ST_45USPT: | |
12145 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
12146 | tg3_flag_set(tp, NVRAM_BUFFERED); |
12147 | tg3_flag_set(tp, FLASH); | |
9b91b5f1 MC |
12148 | |
12149 | switch (nvmpinstrp) { | |
12150 | case FLASH_5720VENDOR_M_ST_M25PE20: | |
12151 | case FLASH_5720VENDOR_M_ST_M45PE20: | |
12152 | case FLASH_5720VENDOR_A_ST_M25PE20: | |
12153 | case FLASH_5720VENDOR_A_ST_M45PE20: | |
12154 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
12155 | break; | |
12156 | case FLASH_5720VENDOR_M_ST_M25PE40: | |
12157 | case FLASH_5720VENDOR_M_ST_M45PE40: | |
12158 | case FLASH_5720VENDOR_A_ST_M25PE40: | |
12159 | case FLASH_5720VENDOR_A_ST_M45PE40: | |
12160 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
12161 | break; | |
12162 | case FLASH_5720VENDOR_M_ST_M25PE80: | |
12163 | case FLASH_5720VENDOR_M_ST_M45PE80: | |
12164 | case FLASH_5720VENDOR_A_ST_M25PE80: | |
12165 | case FLASH_5720VENDOR_A_ST_M45PE80: | |
12166 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; | |
12167 | break; | |
12168 | default: | |
12169 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
12170 | break; | |
12171 | } | |
12172 | break; | |
12173 | default: | |
63c3a66f | 12174 | tg3_flag_set(tp, NO_NVRAM); |
9b91b5f1 MC |
12175 | return; |
12176 | } | |
12177 | ||
12178 | tg3_nvram_get_pagesize(tp, nvcfg1); | |
12179 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) | |
63c3a66f | 12180 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
9b91b5f1 MC |
12181 | } |
12182 | ||
1da177e4 LT |
12183 | /* Chips other than 5700/5701 use the NVRAM for fetching info. */ |
12184 | static void __devinit tg3_nvram_init(struct tg3 *tp) | |
12185 | { | |
1da177e4 LT |
12186 | tw32_f(GRC_EEPROM_ADDR, |
12187 | (EEPROM_ADDR_FSM_RESET | | |
12188 | (EEPROM_DEFAULT_CLOCK_PERIOD << | |
12189 | EEPROM_ADDR_CLKPERD_SHIFT))); | |
12190 | ||
9d57f01c | 12191 | msleep(1); |
1da177e4 LT |
12192 | |
12193 | /* Enable seeprom accesses. */ | |
12194 | tw32_f(GRC_LOCAL_CTRL, | |
12195 | tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM); | |
12196 | udelay(100); | |
12197 | ||
12198 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && | |
12199 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { | |
63c3a66f | 12200 | tg3_flag_set(tp, NVRAM); |
1da177e4 | 12201 | |
ec41c7df | 12202 | if (tg3_nvram_lock(tp)) { |
5129c3a3 MC |
12203 | netdev_warn(tp->dev, |
12204 | "Cannot get nvram lock, %s failed\n", | |
05dbe005 | 12205 | __func__); |
ec41c7df MC |
12206 | return; |
12207 | } | |
e6af301b | 12208 | tg3_enable_nvram_access(tp); |
1da177e4 | 12209 | |
989a9d23 MC |
12210 | tp->nvram_size = 0; |
12211 | ||
361b4ac2 MC |
12212 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
12213 | tg3_get_5752_nvram_info(tp); | |
d3c7b886 MC |
12214 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
12215 | tg3_get_5755_nvram_info(tp); | |
d30cdd28 | 12216 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
57e6983c MC |
12217 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
12218 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) | |
1b27777a | 12219 | tg3_get_5787_nvram_info(tp); |
6b91fa02 MC |
12220 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
12221 | tg3_get_5761_nvram_info(tp); | |
b5d3772c MC |
12222 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
12223 | tg3_get_5906_nvram_info(tp); | |
b703df6f MC |
12224 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
12225 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) | |
321d32a0 | 12226 | tg3_get_57780_nvram_info(tp); |
9b91b5f1 MC |
12227 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
12228 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) | |
a1b950d5 | 12229 | tg3_get_5717_nvram_info(tp); |
9b91b5f1 MC |
12230 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
12231 | tg3_get_5720_nvram_info(tp); | |
361b4ac2 MC |
12232 | else |
12233 | tg3_get_nvram_info(tp); | |
12234 | ||
989a9d23 MC |
12235 | if (tp->nvram_size == 0) |
12236 | tg3_get_nvram_size(tp); | |
1da177e4 | 12237 | |
e6af301b | 12238 | tg3_disable_nvram_access(tp); |
381291b7 | 12239 | tg3_nvram_unlock(tp); |
1da177e4 LT |
12240 | |
12241 | } else { | |
63c3a66f JP |
12242 | tg3_flag_clear(tp, NVRAM); |
12243 | tg3_flag_clear(tp, NVRAM_BUFFERED); | |
1da177e4 LT |
12244 | |
12245 | tg3_get_eeprom_size(tp); | |
12246 | } | |
12247 | } | |
12248 | ||
1da177e4 LT |
12249 | static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp, |
12250 | u32 offset, u32 len, u8 *buf) | |
12251 | { | |
12252 | int i, j, rc = 0; | |
12253 | u32 val; | |
12254 | ||
12255 | for (i = 0; i < len; i += 4) { | |
b9fc7dc5 | 12256 | u32 addr; |
a9dc529d | 12257 | __be32 data; |
1da177e4 LT |
12258 | |
12259 | addr = offset + i; | |
12260 | ||
12261 | memcpy(&data, buf + i, 4); | |
12262 | ||
62cedd11 MC |
12263 | /* |
12264 | * The SEEPROM interface expects the data to always be opposite | |
12265 | * the native endian format. We accomplish this by reversing | |
12266 | * all the operations that would have been performed on the | |
12267 | * data from a call to tg3_nvram_read_be32(). | |
12268 | */ | |
12269 | tw32(GRC_EEPROM_DATA, swab32(be32_to_cpu(data))); | |
1da177e4 LT |
12270 | |
12271 | val = tr32(GRC_EEPROM_ADDR); | |
12272 | tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE); | |
12273 | ||
12274 | val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK | | |
12275 | EEPROM_ADDR_READ); | |
12276 | tw32(GRC_EEPROM_ADDR, val | | |
12277 | (0 << EEPROM_ADDR_DEVID_SHIFT) | | |
12278 | (addr & EEPROM_ADDR_ADDR_MASK) | | |
12279 | EEPROM_ADDR_START | | |
12280 | EEPROM_ADDR_WRITE); | |
6aa20a22 | 12281 | |
9d57f01c | 12282 | for (j = 0; j < 1000; j++) { |
1da177e4 LT |
12283 | val = tr32(GRC_EEPROM_ADDR); |
12284 | ||
12285 | if (val & EEPROM_ADDR_COMPLETE) | |
12286 | break; | |
9d57f01c | 12287 | msleep(1); |
1da177e4 LT |
12288 | } |
12289 | if (!(val & EEPROM_ADDR_COMPLETE)) { | |
12290 | rc = -EBUSY; | |
12291 | break; | |
12292 | } | |
12293 | } | |
12294 | ||
12295 | return rc; | |
12296 | } | |
12297 | ||
12298 | /* offset and length are dword aligned */ | |
12299 | static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, | |
12300 | u8 *buf) | |
12301 | { | |
12302 | int ret = 0; | |
12303 | u32 pagesize = tp->nvram_pagesize; | |
12304 | u32 pagemask = pagesize - 1; | |
12305 | u32 nvram_cmd; | |
12306 | u8 *tmp; | |
12307 | ||
12308 | tmp = kmalloc(pagesize, GFP_KERNEL); | |
12309 | if (tmp == NULL) | |
12310 | return -ENOMEM; | |
12311 | ||
12312 | while (len) { | |
12313 | int j; | |
e6af301b | 12314 | u32 phy_addr, page_off, size; |
1da177e4 LT |
12315 | |
12316 | phy_addr = offset & ~pagemask; | |
6aa20a22 | 12317 | |
1da177e4 | 12318 | for (j = 0; j < pagesize; j += 4) { |
a9dc529d MC |
12319 | ret = tg3_nvram_read_be32(tp, phy_addr + j, |
12320 | (__be32 *) (tmp + j)); | |
12321 | if (ret) | |
1da177e4 LT |
12322 | break; |
12323 | } | |
12324 | if (ret) | |
12325 | break; | |
12326 | ||
c6cdf436 | 12327 | page_off = offset & pagemask; |
1da177e4 LT |
12328 | size = pagesize; |
12329 | if (len < size) | |
12330 | size = len; | |
12331 | ||
12332 | len -= size; | |
12333 | ||
12334 | memcpy(tmp + page_off, buf, size); | |
12335 | ||
12336 | offset = offset + (pagesize - page_off); | |
12337 | ||
e6af301b | 12338 | tg3_enable_nvram_access(tp); |
1da177e4 LT |
12339 | |
12340 | /* | |
12341 | * Before we can erase the flash page, we need | |
12342 | * to issue a special "write enable" command. | |
12343 | */ | |
12344 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; | |
12345 | ||
12346 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) | |
12347 | break; | |
12348 | ||
12349 | /* Erase the target page */ | |
12350 | tw32(NVRAM_ADDR, phy_addr); | |
12351 | ||
12352 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR | | |
12353 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE; | |
12354 | ||
c6cdf436 | 12355 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
1da177e4 LT |
12356 | break; |
12357 | ||
12358 | /* Issue another write enable to start the write. */ | |
12359 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; | |
12360 | ||
12361 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) | |
12362 | break; | |
12363 | ||
12364 | for (j = 0; j < pagesize; j += 4) { | |
b9fc7dc5 | 12365 | __be32 data; |
1da177e4 | 12366 | |
b9fc7dc5 | 12367 | data = *((__be32 *) (tmp + j)); |
a9dc529d | 12368 | |
b9fc7dc5 | 12369 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
1da177e4 LT |
12370 | |
12371 | tw32(NVRAM_ADDR, phy_addr + j); | |
12372 | ||
12373 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | | |
12374 | NVRAM_CMD_WR; | |
12375 | ||
12376 | if (j == 0) | |
12377 | nvram_cmd |= NVRAM_CMD_FIRST; | |
12378 | else if (j == (pagesize - 4)) | |
12379 | nvram_cmd |= NVRAM_CMD_LAST; | |
12380 | ||
12381 | if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd))) | |
12382 | break; | |
12383 | } | |
12384 | if (ret) | |
12385 | break; | |
12386 | } | |
12387 | ||
12388 | nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE; | |
12389 | tg3_nvram_exec_cmd(tp, nvram_cmd); | |
12390 | ||
12391 | kfree(tmp); | |
12392 | ||
12393 | return ret; | |
12394 | } | |
12395 | ||
12396 | /* offset and length are dword aligned */ | |
12397 | static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len, | |
12398 | u8 *buf) | |
12399 | { | |
12400 | int i, ret = 0; | |
12401 | ||
12402 | for (i = 0; i < len; i += 4, offset += 4) { | |
b9fc7dc5 AV |
12403 | u32 page_off, phy_addr, nvram_cmd; |
12404 | __be32 data; | |
1da177e4 LT |
12405 | |
12406 | memcpy(&data, buf + i, 4); | |
b9fc7dc5 | 12407 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
1da177e4 | 12408 | |
c6cdf436 | 12409 | page_off = offset % tp->nvram_pagesize; |
1da177e4 | 12410 | |
1820180b | 12411 | phy_addr = tg3_nvram_phys_addr(tp, offset); |
1da177e4 LT |
12412 | |
12413 | tw32(NVRAM_ADDR, phy_addr); | |
12414 | ||
12415 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR; | |
12416 | ||
c6cdf436 | 12417 | if (page_off == 0 || i == 0) |
1da177e4 | 12418 | nvram_cmd |= NVRAM_CMD_FIRST; |
f6d9a256 | 12419 | if (page_off == (tp->nvram_pagesize - 4)) |
1da177e4 LT |
12420 | nvram_cmd |= NVRAM_CMD_LAST; |
12421 | ||
12422 | if (i == (len - 4)) | |
12423 | nvram_cmd |= NVRAM_CMD_LAST; | |
12424 | ||
321d32a0 | 12425 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 && |
63c3a66f | 12426 | !tg3_flag(tp, 5755_PLUS) && |
4c987487 MC |
12427 | (tp->nvram_jedecnum == JEDEC_ST) && |
12428 | (nvram_cmd & NVRAM_CMD_FIRST)) { | |
1da177e4 LT |
12429 | |
12430 | if ((ret = tg3_nvram_exec_cmd(tp, | |
12431 | NVRAM_CMD_WREN | NVRAM_CMD_GO | | |
12432 | NVRAM_CMD_DONE))) | |
12433 | ||
12434 | break; | |
12435 | } | |
63c3a66f | 12436 | if (!tg3_flag(tp, FLASH)) { |
1da177e4 LT |
12437 | /* We always do complete word writes to eeprom. */ |
12438 | nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST); | |
12439 | } | |
12440 | ||
12441 | if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd))) | |
12442 | break; | |
12443 | } | |
12444 | return ret; | |
12445 | } | |
12446 | ||
12447 | /* offset and length are dword aligned */ | |
12448 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf) | |
12449 | { | |
12450 | int ret; | |
12451 | ||
63c3a66f | 12452 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
314fba34 MC |
12453 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl & |
12454 | ~GRC_LCLCTRL_GPIO_OUTPUT1); | |
1da177e4 LT |
12455 | udelay(40); |
12456 | } | |
12457 | ||
63c3a66f | 12458 | if (!tg3_flag(tp, NVRAM)) { |
1da177e4 | 12459 | ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf); |
859a5887 | 12460 | } else { |
1da177e4 LT |
12461 | u32 grc_mode; |
12462 | ||
ec41c7df MC |
12463 | ret = tg3_nvram_lock(tp); |
12464 | if (ret) | |
12465 | return ret; | |
1da177e4 | 12466 | |
e6af301b | 12467 | tg3_enable_nvram_access(tp); |
63c3a66f | 12468 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) |
1da177e4 | 12469 | tw32(NVRAM_WRITE1, 0x406); |
1da177e4 LT |
12470 | |
12471 | grc_mode = tr32(GRC_MODE); | |
12472 | tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE); | |
12473 | ||
63c3a66f | 12474 | if (tg3_flag(tp, NVRAM_BUFFERED) || !tg3_flag(tp, FLASH)) { |
1da177e4 LT |
12475 | ret = tg3_nvram_write_block_buffered(tp, offset, len, |
12476 | buf); | |
859a5887 | 12477 | } else { |
1da177e4 LT |
12478 | ret = tg3_nvram_write_block_unbuffered(tp, offset, len, |
12479 | buf); | |
12480 | } | |
12481 | ||
12482 | grc_mode = tr32(GRC_MODE); | |
12483 | tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE); | |
12484 | ||
e6af301b | 12485 | tg3_disable_nvram_access(tp); |
1da177e4 LT |
12486 | tg3_nvram_unlock(tp); |
12487 | } | |
12488 | ||
63c3a66f | 12489 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { |
314fba34 | 12490 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
1da177e4 LT |
12491 | udelay(40); |
12492 | } | |
12493 | ||
12494 | return ret; | |
12495 | } | |
12496 | ||
12497 | struct subsys_tbl_ent { | |
12498 | u16 subsys_vendor, subsys_devid; | |
12499 | u32 phy_id; | |
12500 | }; | |
12501 | ||
24daf2b0 | 12502 | static struct subsys_tbl_ent subsys_id_to_phy_id[] __devinitdata = { |
1da177e4 | 12503 | /* Broadcom boards. */ |
24daf2b0 | 12504 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 12505 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A6, TG3_PHY_ID_BCM5401 }, |
24daf2b0 | 12506 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 12507 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A5, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 12508 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 12509 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700T6, TG3_PHY_ID_BCM8002 }, |
24daf2b0 MC |
12510 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
12511 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A9, 0 }, | |
12512 | { TG3PCI_SUBVENDOR_ID_BROADCOM, | |
79eb6904 | 12513 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T1, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 12514 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 12515 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T8, TG3_PHY_ID_BCM5701 }, |
24daf2b0 MC |
12516 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
12517 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A7, 0 }, | |
12518 | { TG3PCI_SUBVENDOR_ID_BROADCOM, | |
79eb6904 | 12519 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A10, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 12520 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 12521 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A12, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 12522 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 12523 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX1, TG3_PHY_ID_BCM5703 }, |
24daf2b0 | 12524 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 12525 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX2, TG3_PHY_ID_BCM5703 }, |
1da177e4 LT |
12526 | |
12527 | /* 3com boards. */ | |
24daf2b0 | 12528 | { TG3PCI_SUBVENDOR_ID_3COM, |
79eb6904 | 12529 | TG3PCI_SUBDEVICE_ID_3COM_3C996T, TG3_PHY_ID_BCM5401 }, |
24daf2b0 | 12530 | { TG3PCI_SUBVENDOR_ID_3COM, |
79eb6904 | 12531 | TG3PCI_SUBDEVICE_ID_3COM_3C996BT, TG3_PHY_ID_BCM5701 }, |
24daf2b0 MC |
12532 | { TG3PCI_SUBVENDOR_ID_3COM, |
12533 | TG3PCI_SUBDEVICE_ID_3COM_3C996SX, 0 }, | |
12534 | { TG3PCI_SUBVENDOR_ID_3COM, | |
79eb6904 | 12535 | TG3PCI_SUBDEVICE_ID_3COM_3C1000T, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 12536 | { TG3PCI_SUBVENDOR_ID_3COM, |
79eb6904 | 12537 | TG3PCI_SUBDEVICE_ID_3COM_3C940BR01, TG3_PHY_ID_BCM5701 }, |
1da177e4 LT |
12538 | |
12539 | /* DELL boards. */ | |
24daf2b0 | 12540 | { TG3PCI_SUBVENDOR_ID_DELL, |
79eb6904 | 12541 | TG3PCI_SUBDEVICE_ID_DELL_VIPER, TG3_PHY_ID_BCM5401 }, |
24daf2b0 | 12542 | { TG3PCI_SUBVENDOR_ID_DELL, |
79eb6904 | 12543 | TG3PCI_SUBDEVICE_ID_DELL_JAGUAR, TG3_PHY_ID_BCM5401 }, |
24daf2b0 | 12544 | { TG3PCI_SUBVENDOR_ID_DELL, |
79eb6904 | 12545 | TG3PCI_SUBDEVICE_ID_DELL_MERLOT, TG3_PHY_ID_BCM5411 }, |
24daf2b0 | 12546 | { TG3PCI_SUBVENDOR_ID_DELL, |
79eb6904 | 12547 | TG3PCI_SUBDEVICE_ID_DELL_SLIM_MERLOT, TG3_PHY_ID_BCM5411 }, |
1da177e4 LT |
12548 | |
12549 | /* Compaq boards. */ | |
24daf2b0 | 12550 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
79eb6904 | 12551 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 12552 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
79eb6904 | 12553 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE_2, TG3_PHY_ID_BCM5701 }, |
24daf2b0 MC |
12554 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
12555 | TG3PCI_SUBDEVICE_ID_COMPAQ_CHANGELING, 0 }, | |
12556 | { TG3PCI_SUBVENDOR_ID_COMPAQ, | |
79eb6904 | 12557 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 12558 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
79eb6904 | 12559 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780_2, TG3_PHY_ID_BCM5701 }, |
1da177e4 LT |
12560 | |
12561 | /* IBM boards. */ | |
24daf2b0 MC |
12562 | { TG3PCI_SUBVENDOR_ID_IBM, |
12563 | TG3PCI_SUBDEVICE_ID_IBM_5703SAX2, 0 } | |
1da177e4 LT |
12564 | }; |
12565 | ||
24daf2b0 | 12566 | static struct subsys_tbl_ent * __devinit tg3_lookup_by_subsys(struct tg3 *tp) |
1da177e4 LT |
12567 | { |
12568 | int i; | |
12569 | ||
12570 | for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) { | |
12571 | if ((subsys_id_to_phy_id[i].subsys_vendor == | |
12572 | tp->pdev->subsystem_vendor) && | |
12573 | (subsys_id_to_phy_id[i].subsys_devid == | |
12574 | tp->pdev->subsystem_device)) | |
12575 | return &subsys_id_to_phy_id[i]; | |
12576 | } | |
12577 | return NULL; | |
12578 | } | |
12579 | ||
7d0c41ef | 12580 | static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp) |
1da177e4 | 12581 | { |
1da177e4 | 12582 | u32 val; |
caf636c7 MC |
12583 | u16 pmcsr; |
12584 | ||
12585 | /* On some early chips the SRAM cannot be accessed in D3hot state, | |
12586 | * so need make sure we're in D0. | |
12587 | */ | |
12588 | pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr); | |
12589 | pmcsr &= ~PCI_PM_CTRL_STATE_MASK; | |
12590 | pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr); | |
12591 | msleep(1); | |
7d0c41ef MC |
12592 | |
12593 | /* Make sure register accesses (indirect or otherwise) | |
12594 | * will function correctly. | |
12595 | */ | |
12596 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
12597 | tp->misc_host_ctrl); | |
1da177e4 | 12598 | |
f49639e6 DM |
12599 | /* The memory arbiter has to be enabled in order for SRAM accesses |
12600 | * to succeed. Normally on powerup the tg3 chip firmware will make | |
12601 | * sure it is enabled, but other entities such as system netboot | |
12602 | * code might disable it. | |
12603 | */ | |
12604 | val = tr32(MEMARB_MODE); | |
12605 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); | |
12606 | ||
79eb6904 | 12607 | tp->phy_id = TG3_PHY_ID_INVALID; |
7d0c41ef MC |
12608 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
12609 | ||
a85feb8c | 12610 | /* Assume an onboard device and WOL capable by default. */ |
63c3a66f JP |
12611 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
12612 | tg3_flag_set(tp, WOL_CAP); | |
72b845e0 | 12613 | |
b5d3772c | 12614 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
9d26e213 | 12615 | if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) { |
63c3a66f JP |
12616 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
12617 | tg3_flag_set(tp, IS_NIC); | |
9d26e213 | 12618 | } |
0527ba35 MC |
12619 | val = tr32(VCPU_CFGSHDW); |
12620 | if (val & VCPU_CFGSHDW_ASPM_DBNC) | |
63c3a66f | 12621 | tg3_flag_set(tp, ASPM_WORKAROUND); |
0527ba35 | 12622 | if ((val & VCPU_CFGSHDW_WOL_ENABLE) && |
6fdbab9d | 12623 | (val & VCPU_CFGSHDW_WOL_MAGPKT)) { |
63c3a66f | 12624 | tg3_flag_set(tp, WOL_ENABLE); |
6fdbab9d RW |
12625 | device_set_wakeup_enable(&tp->pdev->dev, true); |
12626 | } | |
05ac4cb7 | 12627 | goto done; |
b5d3772c MC |
12628 | } |
12629 | ||
1da177e4 LT |
12630 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
12631 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { | |
12632 | u32 nic_cfg, led_cfg; | |
a9daf367 | 12633 | u32 nic_phy_id, ver, cfg2 = 0, cfg4 = 0, eeprom_phy_id; |
7d0c41ef | 12634 | int eeprom_phy_serdes = 0; |
1da177e4 LT |
12635 | |
12636 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); | |
12637 | tp->nic_sram_data_cfg = nic_cfg; | |
12638 | ||
12639 | tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver); | |
12640 | ver >>= NIC_SRAM_DATA_VER_SHIFT; | |
12641 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) && | |
12642 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) && | |
12643 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) && | |
12644 | (ver > 0) && (ver < 0x100)) | |
12645 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2); | |
12646 | ||
a9daf367 MC |
12647 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
12648 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_4, &cfg4); | |
12649 | ||
1da177e4 LT |
12650 | if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) == |
12651 | NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER) | |
12652 | eeprom_phy_serdes = 1; | |
12653 | ||
12654 | tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id); | |
12655 | if (nic_phy_id != 0) { | |
12656 | u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK; | |
12657 | u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK; | |
12658 | ||
12659 | eeprom_phy_id = (id1 >> 16) << 10; | |
12660 | eeprom_phy_id |= (id2 & 0xfc00) << 16; | |
12661 | eeprom_phy_id |= (id2 & 0x03ff) << 0; | |
12662 | } else | |
12663 | eeprom_phy_id = 0; | |
12664 | ||
7d0c41ef | 12665 | tp->phy_id = eeprom_phy_id; |
747e8f8b | 12666 | if (eeprom_phy_serdes) { |
63c3a66f | 12667 | if (!tg3_flag(tp, 5705_PLUS)) |
f07e9af3 | 12668 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
a50d0796 | 12669 | else |
f07e9af3 | 12670 | tp->phy_flags |= TG3_PHYFLG_MII_SERDES; |
747e8f8b | 12671 | } |
7d0c41ef | 12672 | |
63c3a66f | 12673 | if (tg3_flag(tp, 5750_PLUS)) |
1da177e4 LT |
12674 | led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK | |
12675 | SHASTA_EXT_LED_MODE_MASK); | |
cbf46853 | 12676 | else |
1da177e4 LT |
12677 | led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK; |
12678 | ||
12679 | switch (led_cfg) { | |
12680 | default: | |
12681 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1: | |
12682 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; | |
12683 | break; | |
12684 | ||
12685 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2: | |
12686 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; | |
12687 | break; | |
12688 | ||
12689 | case NIC_SRAM_DATA_CFG_LED_MODE_MAC: | |
12690 | tp->led_ctrl = LED_CTRL_MODE_MAC; | |
9ba27794 MC |
12691 | |
12692 | /* Default to PHY_1_MODE if 0 (MAC_MODE) is | |
12693 | * read on some older 5700/5701 bootcode. | |
12694 | */ | |
12695 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == | |
12696 | ASIC_REV_5700 || | |
12697 | GET_ASIC_REV(tp->pci_chip_rev_id) == | |
12698 | ASIC_REV_5701) | |
12699 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; | |
12700 | ||
1da177e4 LT |
12701 | break; |
12702 | ||
12703 | case SHASTA_EXT_LED_SHARED: | |
12704 | tp->led_ctrl = LED_CTRL_MODE_SHARED; | |
12705 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && | |
12706 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A1) | |
12707 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | | |
12708 | LED_CTRL_MODE_PHY_2); | |
12709 | break; | |
12710 | ||
12711 | case SHASTA_EXT_LED_MAC: | |
12712 | tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC; | |
12713 | break; | |
12714 | ||
12715 | case SHASTA_EXT_LED_COMBO: | |
12716 | tp->led_ctrl = LED_CTRL_MODE_COMBO; | |
12717 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) | |
12718 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | | |
12719 | LED_CTRL_MODE_PHY_2); | |
12720 | break; | |
12721 | ||
855e1111 | 12722 | } |
1da177e4 LT |
12723 | |
12724 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
12725 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) && | |
12726 | tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL) | |
12727 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; | |
12728 | ||
b2a5c19c MC |
12729 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) |
12730 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; | |
5f60891b | 12731 | |
9d26e213 | 12732 | if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) { |
63c3a66f | 12733 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
9d26e213 MC |
12734 | if ((tp->pdev->subsystem_vendor == |
12735 | PCI_VENDOR_ID_ARIMA) && | |
12736 | (tp->pdev->subsystem_device == 0x205a || | |
12737 | tp->pdev->subsystem_device == 0x2063)) | |
63c3a66f | 12738 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
9d26e213 | 12739 | } else { |
63c3a66f JP |
12740 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
12741 | tg3_flag_set(tp, IS_NIC); | |
9d26e213 | 12742 | } |
1da177e4 LT |
12743 | |
12744 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { | |
63c3a66f JP |
12745 | tg3_flag_set(tp, ENABLE_ASF); |
12746 | if (tg3_flag(tp, 5750_PLUS)) | |
12747 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); | |
1da177e4 | 12748 | } |
b2b98d4a MC |
12749 | |
12750 | if ((nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE) && | |
63c3a66f JP |
12751 | tg3_flag(tp, 5750_PLUS)) |
12752 | tg3_flag_set(tp, ENABLE_APE); | |
b2b98d4a | 12753 | |
f07e9af3 | 12754 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES && |
a85feb8c | 12755 | !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)) |
63c3a66f | 12756 | tg3_flag_clear(tp, WOL_CAP); |
1da177e4 | 12757 | |
63c3a66f | 12758 | if (tg3_flag(tp, WOL_CAP) && |
6fdbab9d | 12759 | (nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)) { |
63c3a66f | 12760 | tg3_flag_set(tp, WOL_ENABLE); |
6fdbab9d RW |
12761 | device_set_wakeup_enable(&tp->pdev->dev, true); |
12762 | } | |
0527ba35 | 12763 | |
1da177e4 | 12764 | if (cfg2 & (1 << 17)) |
f07e9af3 | 12765 | tp->phy_flags |= TG3_PHYFLG_CAPACITIVE_COUPLING; |
1da177e4 LT |
12766 | |
12767 | /* serdes signal pre-emphasis in register 0x590 set by */ | |
12768 | /* bootcode if bit 18 is set */ | |
12769 | if (cfg2 & (1 << 18)) | |
f07e9af3 | 12770 | tp->phy_flags |= TG3_PHYFLG_SERDES_PREEMPHASIS; |
8ed5d97e | 12771 | |
63c3a66f JP |
12772 | if ((tg3_flag(tp, 57765_PLUS) || |
12773 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && | |
12774 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX)) && | |
6833c043 | 12775 | (cfg2 & NIC_SRAM_DATA_CFG_2_APD_EN)) |
f07e9af3 | 12776 | tp->phy_flags |= TG3_PHYFLG_ENABLE_APD; |
6833c043 | 12777 | |
63c3a66f | 12778 | if (tg3_flag(tp, PCI_EXPRESS) && |
8c69b1e7 | 12779 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
63c3a66f | 12780 | !tg3_flag(tp, 57765_PLUS)) { |
8ed5d97e MC |
12781 | u32 cfg3; |
12782 | ||
12783 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3); | |
12784 | if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE) | |
63c3a66f | 12785 | tg3_flag_set(tp, ASPM_WORKAROUND); |
8ed5d97e | 12786 | } |
a9daf367 | 12787 | |
14417063 | 12788 | if (cfg4 & NIC_SRAM_RGMII_INBAND_DISABLE) |
63c3a66f | 12789 | tg3_flag_set(tp, RGMII_INBAND_DISABLE); |
a9daf367 | 12790 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_RX_EN) |
63c3a66f | 12791 | tg3_flag_set(tp, RGMII_EXT_IBND_RX_EN); |
a9daf367 | 12792 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_TX_EN) |
63c3a66f | 12793 | tg3_flag_set(tp, RGMII_EXT_IBND_TX_EN); |
1da177e4 | 12794 | } |
05ac4cb7 | 12795 | done: |
63c3a66f | 12796 | if (tg3_flag(tp, WOL_CAP)) |
43067ed8 | 12797 | device_set_wakeup_enable(&tp->pdev->dev, |
63c3a66f | 12798 | tg3_flag(tp, WOL_ENABLE)); |
43067ed8 RW |
12799 | else |
12800 | device_set_wakeup_capable(&tp->pdev->dev, false); | |
7d0c41ef MC |
12801 | } |
12802 | ||
b2a5c19c MC |
12803 | static int __devinit tg3_issue_otp_command(struct tg3 *tp, u32 cmd) |
12804 | { | |
12805 | int i; | |
12806 | u32 val; | |
12807 | ||
12808 | tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START); | |
12809 | tw32(OTP_CTRL, cmd); | |
12810 | ||
12811 | /* Wait for up to 1 ms for command to execute. */ | |
12812 | for (i = 0; i < 100; i++) { | |
12813 | val = tr32(OTP_STATUS); | |
12814 | if (val & OTP_STATUS_CMD_DONE) | |
12815 | break; | |
12816 | udelay(10); | |
12817 | } | |
12818 | ||
12819 | return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY; | |
12820 | } | |
12821 | ||
12822 | /* Read the gphy configuration from the OTP region of the chip. The gphy | |
12823 | * configuration is a 32-bit value that straddles the alignment boundary. | |
12824 | * We do two 32-bit reads and then shift and merge the results. | |
12825 | */ | |
12826 | static u32 __devinit tg3_read_otp_phycfg(struct tg3 *tp) | |
12827 | { | |
12828 | u32 bhalf_otp, thalf_otp; | |
12829 | ||
12830 | tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC); | |
12831 | ||
12832 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT)) | |
12833 | return 0; | |
12834 | ||
12835 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1); | |
12836 | ||
12837 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) | |
12838 | return 0; | |
12839 | ||
12840 | thalf_otp = tr32(OTP_READ_DATA); | |
12841 | ||
12842 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2); | |
12843 | ||
12844 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) | |
12845 | return 0; | |
12846 | ||
12847 | bhalf_otp = tr32(OTP_READ_DATA); | |
12848 | ||
12849 | return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16); | |
12850 | } | |
12851 | ||
e256f8a3 MC |
12852 | static void __devinit tg3_phy_init_link_config(struct tg3 *tp) |
12853 | { | |
12854 | u32 adv = ADVERTISED_Autoneg | | |
12855 | ADVERTISED_Pause; | |
12856 | ||
12857 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) | |
12858 | adv |= ADVERTISED_1000baseT_Half | | |
12859 | ADVERTISED_1000baseT_Full; | |
12860 | ||
12861 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) | |
12862 | adv |= ADVERTISED_100baseT_Half | | |
12863 | ADVERTISED_100baseT_Full | | |
12864 | ADVERTISED_10baseT_Half | | |
12865 | ADVERTISED_10baseT_Full | | |
12866 | ADVERTISED_TP; | |
12867 | else | |
12868 | adv |= ADVERTISED_FIBRE; | |
12869 | ||
12870 | tp->link_config.advertising = adv; | |
12871 | tp->link_config.speed = SPEED_INVALID; | |
12872 | tp->link_config.duplex = DUPLEX_INVALID; | |
12873 | tp->link_config.autoneg = AUTONEG_ENABLE; | |
12874 | tp->link_config.active_speed = SPEED_INVALID; | |
12875 | tp->link_config.active_duplex = DUPLEX_INVALID; | |
12876 | tp->link_config.orig_speed = SPEED_INVALID; | |
12877 | tp->link_config.orig_duplex = DUPLEX_INVALID; | |
12878 | tp->link_config.orig_autoneg = AUTONEG_INVALID; | |
12879 | } | |
12880 | ||
7d0c41ef MC |
12881 | static int __devinit tg3_phy_probe(struct tg3 *tp) |
12882 | { | |
12883 | u32 hw_phy_id_1, hw_phy_id_2; | |
12884 | u32 hw_phy_id, hw_phy_id_masked; | |
12885 | int err; | |
1da177e4 | 12886 | |
e256f8a3 | 12887 | /* flow control autonegotiation is default behavior */ |
63c3a66f | 12888 | tg3_flag_set(tp, PAUSE_AUTONEG); |
e256f8a3 MC |
12889 | tp->link_config.flowctrl = FLOW_CTRL_TX | FLOW_CTRL_RX; |
12890 | ||
63c3a66f | 12891 | if (tg3_flag(tp, USE_PHYLIB)) |
b02fd9e3 MC |
12892 | return tg3_phy_init(tp); |
12893 | ||
1da177e4 | 12894 | /* Reading the PHY ID register can conflict with ASF |
877d0310 | 12895 | * firmware access to the PHY hardware. |
1da177e4 LT |
12896 | */ |
12897 | err = 0; | |
63c3a66f | 12898 | if (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE)) { |
79eb6904 | 12899 | hw_phy_id = hw_phy_id_masked = TG3_PHY_ID_INVALID; |
1da177e4 LT |
12900 | } else { |
12901 | /* Now read the physical PHY_ID from the chip and verify | |
12902 | * that it is sane. If it doesn't look good, we fall back | |
12903 | * to either the hard-coded table based PHY_ID and failing | |
12904 | * that the value found in the eeprom area. | |
12905 | */ | |
12906 | err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1); | |
12907 | err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2); | |
12908 | ||
12909 | hw_phy_id = (hw_phy_id_1 & 0xffff) << 10; | |
12910 | hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16; | |
12911 | hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0; | |
12912 | ||
79eb6904 | 12913 | hw_phy_id_masked = hw_phy_id & TG3_PHY_ID_MASK; |
1da177e4 LT |
12914 | } |
12915 | ||
79eb6904 | 12916 | if (!err && TG3_KNOWN_PHY_ID(hw_phy_id_masked)) { |
1da177e4 | 12917 | tp->phy_id = hw_phy_id; |
79eb6904 | 12918 | if (hw_phy_id_masked == TG3_PHY_ID_BCM8002) |
f07e9af3 | 12919 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
da6b2d01 | 12920 | else |
f07e9af3 | 12921 | tp->phy_flags &= ~TG3_PHYFLG_PHY_SERDES; |
1da177e4 | 12922 | } else { |
79eb6904 | 12923 | if (tp->phy_id != TG3_PHY_ID_INVALID) { |
7d0c41ef MC |
12924 | /* Do nothing, phy ID already set up in |
12925 | * tg3_get_eeprom_hw_cfg(). | |
12926 | */ | |
1da177e4 LT |
12927 | } else { |
12928 | struct subsys_tbl_ent *p; | |
12929 | ||
12930 | /* No eeprom signature? Try the hardcoded | |
12931 | * subsys device table. | |
12932 | */ | |
24daf2b0 | 12933 | p = tg3_lookup_by_subsys(tp); |
1da177e4 LT |
12934 | if (!p) |
12935 | return -ENODEV; | |
12936 | ||
12937 | tp->phy_id = p->phy_id; | |
12938 | if (!tp->phy_id || | |
79eb6904 | 12939 | tp->phy_id == TG3_PHY_ID_BCM8002) |
f07e9af3 | 12940 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
1da177e4 LT |
12941 | } |
12942 | } | |
12943 | ||
a6b68dab MC |
12944 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
12945 | ((tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 && | |
12946 | tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) || | |
12947 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && | |
12948 | tp->pci_chip_rev_id != CHIPREV_ID_57765_A0))) | |
52b02d04 MC |
12949 | tp->phy_flags |= TG3_PHYFLG_EEE_CAP; |
12950 | ||
e256f8a3 MC |
12951 | tg3_phy_init_link_config(tp); |
12952 | ||
f07e9af3 | 12953 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
63c3a66f JP |
12954 | !tg3_flag(tp, ENABLE_APE) && |
12955 | !tg3_flag(tp, ENABLE_ASF)) { | |
3600d918 | 12956 | u32 bmsr, adv_reg, tg3_ctrl, mask; |
1da177e4 LT |
12957 | |
12958 | tg3_readphy(tp, MII_BMSR, &bmsr); | |
12959 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && | |
12960 | (bmsr & BMSR_LSTATUS)) | |
12961 | goto skip_phy_reset; | |
6aa20a22 | 12962 | |
1da177e4 LT |
12963 | err = tg3_phy_reset(tp); |
12964 | if (err) | |
12965 | return err; | |
12966 | ||
12967 | adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL | | |
12968 | ADVERTISE_100HALF | ADVERTISE_100FULL | | |
12969 | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); | |
12970 | tg3_ctrl = 0; | |
f07e9af3 | 12971 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
1da177e4 LT |
12972 | tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF | |
12973 | MII_TG3_CTRL_ADV_1000_FULL); | |
12974 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || | |
12975 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) | |
12976 | tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER | | |
12977 | MII_TG3_CTRL_ENABLE_AS_MASTER); | |
12978 | } | |
12979 | ||
3600d918 MC |
12980 | mask = (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
12981 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | | |
12982 | ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full); | |
12983 | if (!tg3_copper_is_advertising_all(tp, mask)) { | |
1da177e4 LT |
12984 | tg3_writephy(tp, MII_ADVERTISE, adv_reg); |
12985 | ||
f07e9af3 | 12986 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
1da177e4 LT |
12987 | tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl); |
12988 | ||
12989 | tg3_writephy(tp, MII_BMCR, | |
12990 | BMCR_ANENABLE | BMCR_ANRESTART); | |
12991 | } | |
12992 | tg3_phy_set_wirespeed(tp); | |
12993 | ||
12994 | tg3_writephy(tp, MII_ADVERTISE, adv_reg); | |
f07e9af3 | 12995 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
1da177e4 LT |
12996 | tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl); |
12997 | } | |
12998 | ||
12999 | skip_phy_reset: | |
79eb6904 | 13000 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
1da177e4 LT |
13001 | err = tg3_init_5401phy_dsp(tp); |
13002 | if (err) | |
13003 | return err; | |
1da177e4 | 13004 | |
1da177e4 LT |
13005 | err = tg3_init_5401phy_dsp(tp); |
13006 | } | |
13007 | ||
1da177e4 LT |
13008 | return err; |
13009 | } | |
13010 | ||
184b8904 | 13011 | static void __devinit tg3_read_vpd(struct tg3 *tp) |
1da177e4 | 13012 | { |
a4a8bb15 | 13013 | u8 *vpd_data; |
4181b2c8 | 13014 | unsigned int block_end, rosize, len; |
184b8904 | 13015 | int j, i = 0; |
a4a8bb15 | 13016 | |
c3e94500 | 13017 | vpd_data = (u8 *)tg3_vpd_readblock(tp); |
a4a8bb15 MC |
13018 | if (!vpd_data) |
13019 | goto out_no_vpd; | |
1da177e4 | 13020 | |
4181b2c8 MC |
13021 | i = pci_vpd_find_tag(vpd_data, 0, TG3_NVM_VPD_LEN, |
13022 | PCI_VPD_LRDT_RO_DATA); | |
13023 | if (i < 0) | |
13024 | goto out_not_found; | |
1da177e4 | 13025 | |
4181b2c8 MC |
13026 | rosize = pci_vpd_lrdt_size(&vpd_data[i]); |
13027 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize; | |
13028 | i += PCI_VPD_LRDT_TAG_SIZE; | |
1da177e4 | 13029 | |
4181b2c8 MC |
13030 | if (block_end > TG3_NVM_VPD_LEN) |
13031 | goto out_not_found; | |
af2c6a4a | 13032 | |
184b8904 MC |
13033 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
13034 | PCI_VPD_RO_KEYWORD_MFR_ID); | |
13035 | if (j > 0) { | |
13036 | len = pci_vpd_info_field_size(&vpd_data[j]); | |
13037 | ||
13038 | j += PCI_VPD_INFO_FLD_HDR_SIZE; | |
13039 | if (j + len > block_end || len != 4 || | |
13040 | memcmp(&vpd_data[j], "1028", 4)) | |
13041 | goto partno; | |
13042 | ||
13043 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, | |
13044 | PCI_VPD_RO_KEYWORD_VENDOR0); | |
13045 | if (j < 0) | |
13046 | goto partno; | |
13047 | ||
13048 | len = pci_vpd_info_field_size(&vpd_data[j]); | |
13049 | ||
13050 | j += PCI_VPD_INFO_FLD_HDR_SIZE; | |
13051 | if (j + len > block_end) | |
13052 | goto partno; | |
13053 | ||
13054 | memcpy(tp->fw_ver, &vpd_data[j], len); | |
13055 | strncat(tp->fw_ver, " bc ", TG3_NVM_VPD_LEN - len - 1); | |
13056 | } | |
13057 | ||
13058 | partno: | |
4181b2c8 MC |
13059 | i = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
13060 | PCI_VPD_RO_KEYWORD_PARTNO); | |
13061 | if (i < 0) | |
13062 | goto out_not_found; | |
af2c6a4a | 13063 | |
4181b2c8 | 13064 | len = pci_vpd_info_field_size(&vpd_data[i]); |
1da177e4 | 13065 | |
4181b2c8 MC |
13066 | i += PCI_VPD_INFO_FLD_HDR_SIZE; |
13067 | if (len > TG3_BPN_SIZE || | |
13068 | (len + i) > TG3_NVM_VPD_LEN) | |
13069 | goto out_not_found; | |
1da177e4 | 13070 | |
4181b2c8 | 13071 | memcpy(tp->board_part_number, &vpd_data[i], len); |
1da177e4 | 13072 | |
1da177e4 | 13073 | out_not_found: |
a4a8bb15 | 13074 | kfree(vpd_data); |
37a949c5 | 13075 | if (tp->board_part_number[0]) |
a4a8bb15 MC |
13076 | return; |
13077 | ||
13078 | out_no_vpd: | |
37a949c5 MC |
13079 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { |
13080 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717) | |
13081 | strcpy(tp->board_part_number, "BCM5717"); | |
13082 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718) | |
13083 | strcpy(tp->board_part_number, "BCM5718"); | |
13084 | else | |
13085 | goto nomatch; | |
13086 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { | |
13087 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57780) | |
13088 | strcpy(tp->board_part_number, "BCM57780"); | |
13089 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57760) | |
13090 | strcpy(tp->board_part_number, "BCM57760"); | |
13091 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790) | |
13092 | strcpy(tp->board_part_number, "BCM57790"); | |
13093 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57788) | |
13094 | strcpy(tp->board_part_number, "BCM57788"); | |
13095 | else | |
13096 | goto nomatch; | |
13097 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) { | |
13098 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761) | |
13099 | strcpy(tp->board_part_number, "BCM57761"); | |
13100 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765) | |
13101 | strcpy(tp->board_part_number, "BCM57765"); | |
13102 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781) | |
13103 | strcpy(tp->board_part_number, "BCM57781"); | |
13104 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785) | |
13105 | strcpy(tp->board_part_number, "BCM57785"); | |
13106 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791) | |
13107 | strcpy(tp->board_part_number, "BCM57791"); | |
13108 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) | |
13109 | strcpy(tp->board_part_number, "BCM57795"); | |
13110 | else | |
13111 | goto nomatch; | |
13112 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { | |
b5d3772c | 13113 | strcpy(tp->board_part_number, "BCM95906"); |
37a949c5 MC |
13114 | } else { |
13115 | nomatch: | |
b5d3772c | 13116 | strcpy(tp->board_part_number, "none"); |
37a949c5 | 13117 | } |
1da177e4 LT |
13118 | } |
13119 | ||
9c8a620e MC |
13120 | static int __devinit tg3_fw_img_is_valid(struct tg3 *tp, u32 offset) |
13121 | { | |
13122 | u32 val; | |
13123 | ||
e4f34110 | 13124 | if (tg3_nvram_read(tp, offset, &val) || |
9c8a620e | 13125 | (val & 0xfc000000) != 0x0c000000 || |
e4f34110 | 13126 | tg3_nvram_read(tp, offset + 4, &val) || |
9c8a620e MC |
13127 | val != 0) |
13128 | return 0; | |
13129 | ||
13130 | return 1; | |
13131 | } | |
13132 | ||
acd9c119 MC |
13133 | static void __devinit tg3_read_bc_ver(struct tg3 *tp) |
13134 | { | |
ff3a7cb2 | 13135 | u32 val, offset, start, ver_offset; |
75f9936e | 13136 | int i, dst_off; |
ff3a7cb2 | 13137 | bool newver = false; |
acd9c119 MC |
13138 | |
13139 | if (tg3_nvram_read(tp, 0xc, &offset) || | |
13140 | tg3_nvram_read(tp, 0x4, &start)) | |
13141 | return; | |
13142 | ||
13143 | offset = tg3_nvram_logical_addr(tp, offset); | |
13144 | ||
ff3a7cb2 | 13145 | if (tg3_nvram_read(tp, offset, &val)) |
acd9c119 MC |
13146 | return; |
13147 | ||
ff3a7cb2 MC |
13148 | if ((val & 0xfc000000) == 0x0c000000) { |
13149 | if (tg3_nvram_read(tp, offset + 4, &val)) | |
acd9c119 MC |
13150 | return; |
13151 | ||
ff3a7cb2 MC |
13152 | if (val == 0) |
13153 | newver = true; | |
13154 | } | |
13155 | ||
75f9936e MC |
13156 | dst_off = strlen(tp->fw_ver); |
13157 | ||
ff3a7cb2 | 13158 | if (newver) { |
75f9936e MC |
13159 | if (TG3_VER_SIZE - dst_off < 16 || |
13160 | tg3_nvram_read(tp, offset + 8, &ver_offset)) | |
ff3a7cb2 MC |
13161 | return; |
13162 | ||
13163 | offset = offset + ver_offset - start; | |
13164 | for (i = 0; i < 16; i += 4) { | |
13165 | __be32 v; | |
13166 | if (tg3_nvram_read_be32(tp, offset + i, &v)) | |
13167 | return; | |
13168 | ||
75f9936e | 13169 | memcpy(tp->fw_ver + dst_off + i, &v, sizeof(v)); |
ff3a7cb2 MC |
13170 | } |
13171 | } else { | |
13172 | u32 major, minor; | |
13173 | ||
13174 | if (tg3_nvram_read(tp, TG3_NVM_PTREV_BCVER, &ver_offset)) | |
13175 | return; | |
13176 | ||
13177 | major = (ver_offset & TG3_NVM_BCVER_MAJMSK) >> | |
13178 | TG3_NVM_BCVER_MAJSFT; | |
13179 | minor = ver_offset & TG3_NVM_BCVER_MINMSK; | |
75f9936e MC |
13180 | snprintf(&tp->fw_ver[dst_off], TG3_VER_SIZE - dst_off, |
13181 | "v%d.%02d", major, minor); | |
acd9c119 MC |
13182 | } |
13183 | } | |
13184 | ||
a6f6cb1c MC |
13185 | static void __devinit tg3_read_hwsb_ver(struct tg3 *tp) |
13186 | { | |
13187 | u32 val, major, minor; | |
13188 | ||
13189 | /* Use native endian representation */ | |
13190 | if (tg3_nvram_read(tp, TG3_NVM_HWSB_CFG1, &val)) | |
13191 | return; | |
13192 | ||
13193 | major = (val & TG3_NVM_HWSB_CFG1_MAJMSK) >> | |
13194 | TG3_NVM_HWSB_CFG1_MAJSFT; | |
13195 | minor = (val & TG3_NVM_HWSB_CFG1_MINMSK) >> | |
13196 | TG3_NVM_HWSB_CFG1_MINSFT; | |
13197 | ||
13198 | snprintf(&tp->fw_ver[0], 32, "sb v%d.%02d", major, minor); | |
13199 | } | |
13200 | ||
dfe00d7d MC |
13201 | static void __devinit tg3_read_sb_ver(struct tg3 *tp, u32 val) |
13202 | { | |
13203 | u32 offset, major, minor, build; | |
13204 | ||
75f9936e | 13205 | strncat(tp->fw_ver, "sb", TG3_VER_SIZE - strlen(tp->fw_ver) - 1); |
dfe00d7d MC |
13206 | |
13207 | if ((val & TG3_EEPROM_SB_FORMAT_MASK) != TG3_EEPROM_SB_FORMAT_1) | |
13208 | return; | |
13209 | ||
13210 | switch (val & TG3_EEPROM_SB_REVISION_MASK) { | |
13211 | case TG3_EEPROM_SB_REVISION_0: | |
13212 | offset = TG3_EEPROM_SB_F1R0_EDH_OFF; | |
13213 | break; | |
13214 | case TG3_EEPROM_SB_REVISION_2: | |
13215 | offset = TG3_EEPROM_SB_F1R2_EDH_OFF; | |
13216 | break; | |
13217 | case TG3_EEPROM_SB_REVISION_3: | |
13218 | offset = TG3_EEPROM_SB_F1R3_EDH_OFF; | |
13219 | break; | |
a4153d40 MC |
13220 | case TG3_EEPROM_SB_REVISION_4: |
13221 | offset = TG3_EEPROM_SB_F1R4_EDH_OFF; | |
13222 | break; | |
13223 | case TG3_EEPROM_SB_REVISION_5: | |
13224 | offset = TG3_EEPROM_SB_F1R5_EDH_OFF; | |
13225 | break; | |
bba226ac MC |
13226 | case TG3_EEPROM_SB_REVISION_6: |
13227 | offset = TG3_EEPROM_SB_F1R6_EDH_OFF; | |
13228 | break; | |
dfe00d7d MC |
13229 | default: |
13230 | return; | |
13231 | } | |
13232 | ||
e4f34110 | 13233 | if (tg3_nvram_read(tp, offset, &val)) |
dfe00d7d MC |
13234 | return; |
13235 | ||
13236 | build = (val & TG3_EEPROM_SB_EDH_BLD_MASK) >> | |
13237 | TG3_EEPROM_SB_EDH_BLD_SHFT; | |
13238 | major = (val & TG3_EEPROM_SB_EDH_MAJ_MASK) >> | |
13239 | TG3_EEPROM_SB_EDH_MAJ_SHFT; | |
13240 | minor = val & TG3_EEPROM_SB_EDH_MIN_MASK; | |
13241 | ||
13242 | if (minor > 99 || build > 26) | |
13243 | return; | |
13244 | ||
75f9936e MC |
13245 | offset = strlen(tp->fw_ver); |
13246 | snprintf(&tp->fw_ver[offset], TG3_VER_SIZE - offset, | |
13247 | " v%d.%02d", major, minor); | |
dfe00d7d MC |
13248 | |
13249 | if (build > 0) { | |
75f9936e MC |
13250 | offset = strlen(tp->fw_ver); |
13251 | if (offset < TG3_VER_SIZE - 1) | |
13252 | tp->fw_ver[offset] = 'a' + build - 1; | |
dfe00d7d MC |
13253 | } |
13254 | } | |
13255 | ||
acd9c119 | 13256 | static void __devinit tg3_read_mgmtfw_ver(struct tg3 *tp) |
c4e6575c MC |
13257 | { |
13258 | u32 val, offset, start; | |
acd9c119 | 13259 | int i, vlen; |
9c8a620e MC |
13260 | |
13261 | for (offset = TG3_NVM_DIR_START; | |
13262 | offset < TG3_NVM_DIR_END; | |
13263 | offset += TG3_NVM_DIRENT_SIZE) { | |
e4f34110 | 13264 | if (tg3_nvram_read(tp, offset, &val)) |
c4e6575c MC |
13265 | return; |
13266 | ||
9c8a620e MC |
13267 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI) |
13268 | break; | |
13269 | } | |
13270 | ||
13271 | if (offset == TG3_NVM_DIR_END) | |
13272 | return; | |
13273 | ||
63c3a66f | 13274 | if (!tg3_flag(tp, 5705_PLUS)) |
9c8a620e | 13275 | start = 0x08000000; |
e4f34110 | 13276 | else if (tg3_nvram_read(tp, offset - 4, &start)) |
9c8a620e MC |
13277 | return; |
13278 | ||
e4f34110 | 13279 | if (tg3_nvram_read(tp, offset + 4, &offset) || |
9c8a620e | 13280 | !tg3_fw_img_is_valid(tp, offset) || |
e4f34110 | 13281 | tg3_nvram_read(tp, offset + 8, &val)) |
9c8a620e MC |
13282 | return; |
13283 | ||
13284 | offset += val - start; | |
13285 | ||
acd9c119 | 13286 | vlen = strlen(tp->fw_ver); |
9c8a620e | 13287 | |
acd9c119 MC |
13288 | tp->fw_ver[vlen++] = ','; |
13289 | tp->fw_ver[vlen++] = ' '; | |
9c8a620e MC |
13290 | |
13291 | for (i = 0; i < 4; i++) { | |
a9dc529d MC |
13292 | __be32 v; |
13293 | if (tg3_nvram_read_be32(tp, offset, &v)) | |
c4e6575c MC |
13294 | return; |
13295 | ||
b9fc7dc5 | 13296 | offset += sizeof(v); |
c4e6575c | 13297 | |
acd9c119 MC |
13298 | if (vlen > TG3_VER_SIZE - sizeof(v)) { |
13299 | memcpy(&tp->fw_ver[vlen], &v, TG3_VER_SIZE - vlen); | |
9c8a620e | 13300 | break; |
c4e6575c | 13301 | } |
9c8a620e | 13302 | |
acd9c119 MC |
13303 | memcpy(&tp->fw_ver[vlen], &v, sizeof(v)); |
13304 | vlen += sizeof(v); | |
c4e6575c | 13305 | } |
acd9c119 MC |
13306 | } |
13307 | ||
7fd76445 MC |
13308 | static void __devinit tg3_read_dash_ver(struct tg3 *tp) |
13309 | { | |
13310 | int vlen; | |
13311 | u32 apedata; | |
ecc79648 | 13312 | char *fwtype; |
7fd76445 | 13313 | |
63c3a66f | 13314 | if (!tg3_flag(tp, ENABLE_APE) || !tg3_flag(tp, ENABLE_ASF)) |
7fd76445 MC |
13315 | return; |
13316 | ||
13317 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); | |
13318 | if (apedata != APE_SEG_SIG_MAGIC) | |
13319 | return; | |
13320 | ||
13321 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); | |
13322 | if (!(apedata & APE_FW_STATUS_READY)) | |
13323 | return; | |
13324 | ||
13325 | apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION); | |
13326 | ||
dc6d0744 | 13327 | if (tg3_ape_read32(tp, TG3_APE_FW_FEATURES) & TG3_APE_FW_FEATURE_NCSI) { |
63c3a66f | 13328 | tg3_flag_set(tp, APE_HAS_NCSI); |
ecc79648 | 13329 | fwtype = "NCSI"; |
dc6d0744 | 13330 | } else { |
ecc79648 | 13331 | fwtype = "DASH"; |
dc6d0744 | 13332 | } |
ecc79648 | 13333 | |
7fd76445 MC |
13334 | vlen = strlen(tp->fw_ver); |
13335 | ||
ecc79648 MC |
13336 | snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " %s v%d.%d.%d.%d", |
13337 | fwtype, | |
7fd76445 MC |
13338 | (apedata & APE_FW_VERSION_MAJMSK) >> APE_FW_VERSION_MAJSFT, |
13339 | (apedata & APE_FW_VERSION_MINMSK) >> APE_FW_VERSION_MINSFT, | |
13340 | (apedata & APE_FW_VERSION_REVMSK) >> APE_FW_VERSION_REVSFT, | |
13341 | (apedata & APE_FW_VERSION_BLDMSK)); | |
13342 | } | |
13343 | ||
acd9c119 MC |
13344 | static void __devinit tg3_read_fw_ver(struct tg3 *tp) |
13345 | { | |
13346 | u32 val; | |
75f9936e | 13347 | bool vpd_vers = false; |
acd9c119 | 13348 | |
75f9936e MC |
13349 | if (tp->fw_ver[0] != 0) |
13350 | vpd_vers = true; | |
df259d8c | 13351 | |
63c3a66f | 13352 | if (tg3_flag(tp, NO_NVRAM)) { |
75f9936e | 13353 | strcat(tp->fw_ver, "sb"); |
df259d8c MC |
13354 | return; |
13355 | } | |
13356 | ||
acd9c119 MC |
13357 | if (tg3_nvram_read(tp, 0, &val)) |
13358 | return; | |
13359 | ||
13360 | if (val == TG3_EEPROM_MAGIC) | |
13361 | tg3_read_bc_ver(tp); | |
13362 | else if ((val & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) | |
13363 | tg3_read_sb_ver(tp, val); | |
a6f6cb1c MC |
13364 | else if ((val & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
13365 | tg3_read_hwsb_ver(tp); | |
acd9c119 MC |
13366 | else |
13367 | return; | |
13368 | ||
63c3a66f | 13369 | if (!tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE) || vpd_vers) |
75f9936e | 13370 | goto done; |
acd9c119 MC |
13371 | |
13372 | tg3_read_mgmtfw_ver(tp); | |
9c8a620e | 13373 | |
75f9936e | 13374 | done: |
9c8a620e | 13375 | tp->fw_ver[TG3_VER_SIZE - 1] = 0; |
c4e6575c MC |
13376 | } |
13377 | ||
7544b097 MC |
13378 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *); |
13379 | ||
7cb32cf2 MC |
13380 | static inline u32 tg3_rx_ret_ring_size(struct tg3 *tp) |
13381 | { | |
63c3a66f | 13382 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
de9f5230 | 13383 | return TG3_RX_RET_MAX_SIZE_5717; |
63c3a66f | 13384 | else if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) |
de9f5230 | 13385 | return TG3_RX_RET_MAX_SIZE_5700; |
7cb32cf2 | 13386 | else |
de9f5230 | 13387 | return TG3_RX_RET_MAX_SIZE_5705; |
7cb32cf2 MC |
13388 | } |
13389 | ||
4143470c | 13390 | static DEFINE_PCI_DEVICE_TABLE(tg3_write_reorder_chipsets) = { |
895950c2 JP |
13391 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C) }, |
13392 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE) }, | |
13393 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8385_0) }, | |
13394 | { }, | |
13395 | }; | |
13396 | ||
1da177e4 LT |
13397 | static int __devinit tg3_get_invariants(struct tg3 *tp) |
13398 | { | |
1da177e4 | 13399 | u32 misc_ctrl_reg; |
1da177e4 LT |
13400 | u32 pci_state_reg, grc_misc_cfg; |
13401 | u32 val; | |
13402 | u16 pci_cmd; | |
5e7dfd0f | 13403 | int err; |
1da177e4 | 13404 | |
1da177e4 LT |
13405 | /* Force memory write invalidate off. If we leave it on, |
13406 | * then on 5700_BX chips we have to enable a workaround. | |
13407 | * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary | |
13408 | * to match the cacheline size. The Broadcom driver have this | |
13409 | * workaround but turns MWI off all the times so never uses | |
13410 | * it. This seems to suggest that the workaround is insufficient. | |
13411 | */ | |
13412 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); | |
13413 | pci_cmd &= ~PCI_COMMAND_INVALIDATE; | |
13414 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); | |
13415 | ||
13416 | /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL | |
13417 | * has the register indirect write enable bit set before | |
13418 | * we try to access any of the MMIO registers. It is also | |
13419 | * critical that the PCI-X hw workaround situation is decided | |
13420 | * before that as well. | |
13421 | */ | |
13422 | pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
13423 | &misc_ctrl_reg); | |
13424 | ||
13425 | tp->pci_chip_rev_id = (misc_ctrl_reg >> | |
13426 | MISC_HOST_CTRL_CHIPREV_SHIFT); | |
795d01c5 MC |
13427 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_USE_PROD_ID_REG) { |
13428 | u32 prod_id_asic_rev; | |
13429 | ||
5001e2f6 MC |
13430 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
13431 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || | |
d78b59f5 MC |
13432 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || |
13433 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720) | |
f6eb9b1f MC |
13434 | pci_read_config_dword(tp->pdev, |
13435 | TG3PCI_GEN2_PRODID_ASICREV, | |
13436 | &prod_id_asic_rev); | |
b703df6f MC |
13437 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781 || |
13438 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785 || | |
13439 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761 || | |
13440 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765 || | |
13441 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || | |
13442 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) | |
13443 | pci_read_config_dword(tp->pdev, | |
13444 | TG3PCI_GEN15_PRODID_ASICREV, | |
13445 | &prod_id_asic_rev); | |
f6eb9b1f MC |
13446 | else |
13447 | pci_read_config_dword(tp->pdev, TG3PCI_PRODID_ASICREV, | |
13448 | &prod_id_asic_rev); | |
13449 | ||
321d32a0 | 13450 | tp->pci_chip_rev_id = prod_id_asic_rev; |
795d01c5 | 13451 | } |
1da177e4 | 13452 | |
ff645bec MC |
13453 | /* Wrong chip ID in 5752 A0. This code can be removed later |
13454 | * as A0 is not in production. | |
13455 | */ | |
13456 | if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW) | |
13457 | tp->pci_chip_rev_id = CHIPREV_ID_5752_A0; | |
13458 | ||
6892914f MC |
13459 | /* If we have 5702/03 A1 or A2 on certain ICH chipsets, |
13460 | * we need to disable memory and use config. cycles | |
13461 | * only to access all registers. The 5702/03 chips | |
13462 | * can mistakenly decode the special cycles from the | |
13463 | * ICH chipsets as memory write cycles, causing corruption | |
13464 | * of register and memory space. Only certain ICH bridges | |
13465 | * will drive special cycles with non-zero data during the | |
13466 | * address phase which can fall within the 5703's address | |
13467 | * range. This is not an ICH bug as the PCI spec allows | |
13468 | * non-zero address during special cycles. However, only | |
13469 | * these ICH bridges are known to drive non-zero addresses | |
13470 | * during special cycles. | |
13471 | * | |
13472 | * Since special cycles do not cross PCI bridges, we only | |
13473 | * enable this workaround if the 5703 is on the secondary | |
13474 | * bus of these ICH bridges. | |
13475 | */ | |
13476 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) || | |
13477 | (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) { | |
13478 | static struct tg3_dev_id { | |
13479 | u32 vendor; | |
13480 | u32 device; | |
13481 | u32 rev; | |
13482 | } ich_chipsets[] = { | |
13483 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8, | |
13484 | PCI_ANY_ID }, | |
13485 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8, | |
13486 | PCI_ANY_ID }, | |
13487 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11, | |
13488 | 0xa }, | |
13489 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6, | |
13490 | PCI_ANY_ID }, | |
13491 | { }, | |
13492 | }; | |
13493 | struct tg3_dev_id *pci_id = &ich_chipsets[0]; | |
13494 | struct pci_dev *bridge = NULL; | |
13495 | ||
13496 | while (pci_id->vendor != 0) { | |
13497 | bridge = pci_get_device(pci_id->vendor, pci_id->device, | |
13498 | bridge); | |
13499 | if (!bridge) { | |
13500 | pci_id++; | |
13501 | continue; | |
13502 | } | |
13503 | if (pci_id->rev != PCI_ANY_ID) { | |
44c10138 | 13504 | if (bridge->revision > pci_id->rev) |
6892914f MC |
13505 | continue; |
13506 | } | |
13507 | if (bridge->subordinate && | |
13508 | (bridge->subordinate->number == | |
13509 | tp->pdev->bus->number)) { | |
63c3a66f | 13510 | tg3_flag_set(tp, ICH_WORKAROUND); |
6892914f MC |
13511 | pci_dev_put(bridge); |
13512 | break; | |
13513 | } | |
13514 | } | |
13515 | } | |
13516 | ||
41588ba1 MC |
13517 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
13518 | static struct tg3_dev_id { | |
13519 | u32 vendor; | |
13520 | u32 device; | |
13521 | } bridge_chipsets[] = { | |
13522 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 }, | |
13523 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 }, | |
13524 | { }, | |
13525 | }; | |
13526 | struct tg3_dev_id *pci_id = &bridge_chipsets[0]; | |
13527 | struct pci_dev *bridge = NULL; | |
13528 | ||
13529 | while (pci_id->vendor != 0) { | |
13530 | bridge = pci_get_device(pci_id->vendor, | |
13531 | pci_id->device, | |
13532 | bridge); | |
13533 | if (!bridge) { | |
13534 | pci_id++; | |
13535 | continue; | |
13536 | } | |
13537 | if (bridge->subordinate && | |
13538 | (bridge->subordinate->number <= | |
13539 | tp->pdev->bus->number) && | |
13540 | (bridge->subordinate->subordinate >= | |
13541 | tp->pdev->bus->number)) { | |
63c3a66f | 13542 | tg3_flag_set(tp, 5701_DMA_BUG); |
41588ba1 MC |
13543 | pci_dev_put(bridge); |
13544 | break; | |
13545 | } | |
13546 | } | |
13547 | } | |
13548 | ||
4a29cc2e MC |
13549 | /* The EPB bridge inside 5714, 5715, and 5780 cannot support |
13550 | * DMA addresses > 40-bit. This bridge may have other additional | |
13551 | * 57xx devices behind it in some 4-port NIC designs for example. | |
13552 | * Any tg3 device found behind the bridge will also need the 40-bit | |
13553 | * DMA workaround. | |
13554 | */ | |
a4e2b347 MC |
13555 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 || |
13556 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { | |
63c3a66f JP |
13557 | tg3_flag_set(tp, 5780_CLASS); |
13558 | tg3_flag_set(tp, 40BIT_DMA_BUG); | |
4cf78e4f | 13559 | tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI); |
859a5887 | 13560 | } else { |
4a29cc2e MC |
13561 | struct pci_dev *bridge = NULL; |
13562 | ||
13563 | do { | |
13564 | bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, | |
13565 | PCI_DEVICE_ID_SERVERWORKS_EPB, | |
13566 | bridge); | |
13567 | if (bridge && bridge->subordinate && | |
13568 | (bridge->subordinate->number <= | |
13569 | tp->pdev->bus->number) && | |
13570 | (bridge->subordinate->subordinate >= | |
13571 | tp->pdev->bus->number)) { | |
63c3a66f | 13572 | tg3_flag_set(tp, 40BIT_DMA_BUG); |
4a29cc2e MC |
13573 | pci_dev_put(bridge); |
13574 | break; | |
13575 | } | |
13576 | } while (bridge); | |
13577 | } | |
4cf78e4f | 13578 | |
1da177e4 LT |
13579 | /* Initialize misc host control in PCI block. */ |
13580 | tp->misc_host_ctrl |= (misc_ctrl_reg & | |
13581 | MISC_HOST_CTRL_CHIPREV); | |
13582 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
13583 | tp->misc_host_ctrl); | |
13584 | ||
f6eb9b1f MC |
13585 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
13586 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 || | |
d78b59f5 MC |
13587 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
13588 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) | |
7544b097 MC |
13589 | tp->pdev_peer = tg3_find_peer(tp); |
13590 | ||
c885e824 | 13591 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
d78b59f5 MC |
13592 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
13593 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) | |
63c3a66f | 13594 | tg3_flag_set(tp, 5717_PLUS); |
0a58d668 MC |
13595 | |
13596 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 || | |
63c3a66f JP |
13597 | tg3_flag(tp, 5717_PLUS)) |
13598 | tg3_flag_set(tp, 57765_PLUS); | |
c885e824 | 13599 | |
321d32a0 MC |
13600 | /* Intentionally exclude ASIC_REV_5906 */ |
13601 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || | |
d9ab5ad1 | 13602 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
d30cdd28 | 13603 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
9936bcf6 | 13604 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
57e6983c | 13605 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
f6eb9b1f | 13606 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
63c3a66f JP |
13607 | tg3_flag(tp, 57765_PLUS)) |
13608 | tg3_flag_set(tp, 5755_PLUS); | |
321d32a0 MC |
13609 | |
13610 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || | |
13611 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || | |
b5d3772c | 13612 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 || |
63c3a66f JP |
13613 | tg3_flag(tp, 5755_PLUS) || |
13614 | tg3_flag(tp, 5780_CLASS)) | |
13615 | tg3_flag_set(tp, 5750_PLUS); | |
6708e5cc | 13616 | |
1b440c56 | 13617 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) || |
63c3a66f JP |
13618 | tg3_flag(tp, 5750_PLUS)) |
13619 | tg3_flag_set(tp, 5705_PLUS); | |
1b440c56 | 13620 | |
027455ad MC |
13621 | /* 5700 B0 chips do not support checksumming correctly due |
13622 | * to hardware bugs. | |
13623 | */ | |
dc668910 MM |
13624 | if (tp->pci_chip_rev_id != CHIPREV_ID_5700_B0) { |
13625 | u32 features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM; | |
7fe876af | 13626 | |
63c3a66f | 13627 | if (tg3_flag(tp, 5755_PLUS)) |
7fe876af ED |
13628 | features |= NETIF_F_IPV6_CSUM; |
13629 | tp->dev->features |= features; | |
dc668910 MM |
13630 | tp->dev->hw_features |= features; |
13631 | tp->dev->vlan_features |= features; | |
027455ad MC |
13632 | } |
13633 | ||
507399f1 | 13634 | /* Determine TSO capabilities */ |
2866d956 | 13635 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) |
4d163b75 | 13636 | ; /* Do nothing. HW bug. */ |
63c3a66f JP |
13637 | else if (tg3_flag(tp, 57765_PLUS)) |
13638 | tg3_flag_set(tp, HW_TSO_3); | |
13639 | else if (tg3_flag(tp, 5755_PLUS) || | |
e849cdc3 | 13640 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
63c3a66f JP |
13641 | tg3_flag_set(tp, HW_TSO_2); |
13642 | else if (tg3_flag(tp, 5750_PLUS)) { | |
13643 | tg3_flag_set(tp, HW_TSO_1); | |
13644 | tg3_flag_set(tp, TSO_BUG); | |
507399f1 MC |
13645 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 && |
13646 | tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2) | |
63c3a66f | 13647 | tg3_flag_clear(tp, TSO_BUG); |
507399f1 MC |
13648 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
13649 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && | |
13650 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { | |
63c3a66f | 13651 | tg3_flag_set(tp, TSO_BUG); |
507399f1 MC |
13652 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) |
13653 | tp->fw_needed = FIRMWARE_TG3TSO5; | |
13654 | else | |
13655 | tp->fw_needed = FIRMWARE_TG3TSO; | |
13656 | } | |
13657 | ||
13658 | tp->irq_max = 1; | |
13659 | ||
63c3a66f JP |
13660 | if (tg3_flag(tp, 5750_PLUS)) { |
13661 | tg3_flag_set(tp, SUPPORT_MSI); | |
7544b097 MC |
13662 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX || |
13663 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX || | |
13664 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 && | |
13665 | tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 && | |
13666 | tp->pdev_peer == tp->pdev)) | |
63c3a66f | 13667 | tg3_flag_clear(tp, SUPPORT_MSI); |
7544b097 | 13668 | |
63c3a66f | 13669 | if (tg3_flag(tp, 5755_PLUS) || |
b5d3772c | 13670 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
63c3a66f | 13671 | tg3_flag_set(tp, 1SHOT_MSI); |
52c0fd83 | 13672 | } |
4f125f42 | 13673 | |
63c3a66f JP |
13674 | if (tg3_flag(tp, 57765_PLUS)) { |
13675 | tg3_flag_set(tp, SUPPORT_MSIX); | |
507399f1 MC |
13676 | tp->irq_max = TG3_IRQ_MAX_VECS; |
13677 | } | |
f6eb9b1f | 13678 | } |
0e1406dd | 13679 | |
2ffcc981 MC |
13680 | /* All chips can get confused if TX buffers |
13681 | * straddle the 4GB address boundary. | |
13682 | */ | |
13683 | tg3_flag_set(tp, 4G_DMA_BNDRY_BUG); | |
13684 | ||
13685 | if (tg3_flag(tp, 5755_PLUS)) | |
63c3a66f | 13686 | tg3_flag_set(tp, SHORT_DMA_BUG); |
2ffcc981 | 13687 | else |
63c3a66f | 13688 | tg3_flag_set(tp, 40BIT_DMA_LIMIT_BUG); |
f6eb9b1f | 13689 | |
63c3a66f JP |
13690 | if (tg3_flag(tp, 5717_PLUS)) |
13691 | tg3_flag_set(tp, LRG_PROD_RING_CAP); | |
de9f5230 | 13692 | |
63c3a66f | 13693 | if (tg3_flag(tp, 57765_PLUS) && |
2866d956 | 13694 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5719) |
63c3a66f | 13695 | tg3_flag_set(tp, USE_JUMBO_BDFLAG); |
b703df6f | 13696 | |
63c3a66f JP |
13697 | if (!tg3_flag(tp, 5705_PLUS) || |
13698 | tg3_flag(tp, 5780_CLASS) || | |
13699 | tg3_flag(tp, USE_JUMBO_BDFLAG)) | |
13700 | tg3_flag_set(tp, JUMBO_CAPABLE); | |
0f893dc6 | 13701 | |
52f4490c MC |
13702 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
13703 | &pci_state_reg); | |
13704 | ||
5e7dfd0f MC |
13705 | tp->pcie_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_EXP); |
13706 | if (tp->pcie_cap != 0) { | |
13707 | u16 lnkctl; | |
13708 | ||
63c3a66f | 13709 | tg3_flag_set(tp, PCI_EXPRESS); |
5f5c51e3 | 13710 | |
cf79003d | 13711 | tp->pcie_readrq = 4096; |
d78b59f5 MC |
13712 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
13713 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) | |
b4495ed8 | 13714 | tp->pcie_readrq = 2048; |
cf79003d MC |
13715 | |
13716 | pcie_set_readrq(tp->pdev, tp->pcie_readrq); | |
5f5c51e3 | 13717 | |
5e7dfd0f MC |
13718 | pci_read_config_word(tp->pdev, |
13719 | tp->pcie_cap + PCI_EXP_LNKCTL, | |
13720 | &lnkctl); | |
13721 | if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) { | |
13722 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) | |
63c3a66f | 13723 | tg3_flag_clear(tp, HW_TSO_2); |
5e7dfd0f | 13724 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
321d32a0 | 13725 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
9cf74ebb MC |
13726 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A0 || |
13727 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A1) | |
63c3a66f | 13728 | tg3_flag_set(tp, CLKREQ_BUG); |
614b0590 | 13729 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5717_A0) { |
63c3a66f | 13730 | tg3_flag_set(tp, L1PLLPD_EN); |
c7835a77 | 13731 | } |
52f4490c | 13732 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
63c3a66f JP |
13733 | tg3_flag_set(tp, PCI_EXPRESS); |
13734 | } else if (!tg3_flag(tp, 5705_PLUS) || | |
13735 | tg3_flag(tp, 5780_CLASS)) { | |
52f4490c MC |
13736 | tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX); |
13737 | if (!tp->pcix_cap) { | |
2445e461 MC |
13738 | dev_err(&tp->pdev->dev, |
13739 | "Cannot find PCI-X capability, aborting\n"); | |
52f4490c MC |
13740 | return -EIO; |
13741 | } | |
13742 | ||
13743 | if (!(pci_state_reg & PCISTATE_CONV_PCI_MODE)) | |
63c3a66f | 13744 | tg3_flag_set(tp, PCIX_MODE); |
52f4490c | 13745 | } |
1da177e4 | 13746 | |
399de50b MC |
13747 | /* If we have an AMD 762 or VIA K8T800 chipset, write |
13748 | * reordering to the mailbox registers done by the host | |
13749 | * controller can cause major troubles. We read back from | |
13750 | * every mailbox register write to force the writes to be | |
13751 | * posted to the chip in order. | |
13752 | */ | |
4143470c | 13753 | if (pci_dev_present(tg3_write_reorder_chipsets) && |
63c3a66f JP |
13754 | !tg3_flag(tp, PCI_EXPRESS)) |
13755 | tg3_flag_set(tp, MBOX_WRITE_REORDER); | |
399de50b | 13756 | |
69fc4053 MC |
13757 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
13758 | &tp->pci_cacheline_sz); | |
13759 | pci_read_config_byte(tp->pdev, PCI_LATENCY_TIMER, | |
13760 | &tp->pci_lat_timer); | |
1da177e4 LT |
13761 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
13762 | tp->pci_lat_timer < 64) { | |
13763 | tp->pci_lat_timer = 64; | |
69fc4053 MC |
13764 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
13765 | tp->pci_lat_timer); | |
1da177e4 LT |
13766 | } |
13767 | ||
52f4490c MC |
13768 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) { |
13769 | /* 5700 BX chips need to have their TX producer index | |
13770 | * mailboxes written twice to workaround a bug. | |
13771 | */ | |
63c3a66f | 13772 | tg3_flag_set(tp, TXD_MBOX_HWBUG); |
1da177e4 | 13773 | |
52f4490c | 13774 | /* If we are in PCI-X mode, enable register write workaround. |
1da177e4 LT |
13775 | * |
13776 | * The workaround is to use indirect register accesses | |
13777 | * for all chip writes not to mailbox registers. | |
13778 | */ | |
63c3a66f | 13779 | if (tg3_flag(tp, PCIX_MODE)) { |
1da177e4 | 13780 | u32 pm_reg; |
1da177e4 | 13781 | |
63c3a66f | 13782 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
1da177e4 LT |
13783 | |
13784 | /* The chip can have it's power management PCI config | |
13785 | * space registers clobbered due to this bug. | |
13786 | * So explicitly force the chip into D0 here. | |
13787 | */ | |
9974a356 MC |
13788 | pci_read_config_dword(tp->pdev, |
13789 | tp->pm_cap + PCI_PM_CTRL, | |
1da177e4 LT |
13790 | &pm_reg); |
13791 | pm_reg &= ~PCI_PM_CTRL_STATE_MASK; | |
13792 | pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */; | |
9974a356 MC |
13793 | pci_write_config_dword(tp->pdev, |
13794 | tp->pm_cap + PCI_PM_CTRL, | |
1da177e4 LT |
13795 | pm_reg); |
13796 | ||
13797 | /* Also, force SERR#/PERR# in PCI command. */ | |
13798 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); | |
13799 | pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; | |
13800 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); | |
13801 | } | |
13802 | } | |
13803 | ||
1da177e4 | 13804 | if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0) |
63c3a66f | 13805 | tg3_flag_set(tp, PCI_HIGH_SPEED); |
1da177e4 | 13806 | if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0) |
63c3a66f | 13807 | tg3_flag_set(tp, PCI_32BIT); |
1da177e4 LT |
13808 | |
13809 | /* Chip-specific fixup from Broadcom driver */ | |
13810 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) && | |
13811 | (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) { | |
13812 | pci_state_reg |= PCISTATE_RETRY_SAME_DMA; | |
13813 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg); | |
13814 | } | |
13815 | ||
1ee582d8 | 13816 | /* Default fast path register access methods */ |
20094930 | 13817 | tp->read32 = tg3_read32; |
1ee582d8 | 13818 | tp->write32 = tg3_write32; |
09ee929c | 13819 | tp->read32_mbox = tg3_read32; |
20094930 | 13820 | tp->write32_mbox = tg3_write32; |
1ee582d8 MC |
13821 | tp->write32_tx_mbox = tg3_write32; |
13822 | tp->write32_rx_mbox = tg3_write32; | |
13823 | ||
13824 | /* Various workaround register access methods */ | |
63c3a66f | 13825 | if (tg3_flag(tp, PCIX_TARGET_HWBUG)) |
1ee582d8 | 13826 | tp->write32 = tg3_write_indirect_reg32; |
98efd8a6 | 13827 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 || |
63c3a66f | 13828 | (tg3_flag(tp, PCI_EXPRESS) && |
98efd8a6 MC |
13829 | tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) { |
13830 | /* | |
13831 | * Back to back register writes can cause problems on these | |
13832 | * chips, the workaround is to read back all reg writes | |
13833 | * except those to mailbox regs. | |
13834 | * | |
13835 | * See tg3_write_indirect_reg32(). | |
13836 | */ | |
1ee582d8 | 13837 | tp->write32 = tg3_write_flush_reg32; |
98efd8a6 MC |
13838 | } |
13839 | ||
63c3a66f | 13840 | if (tg3_flag(tp, TXD_MBOX_HWBUG) || tg3_flag(tp, MBOX_WRITE_REORDER)) { |
1ee582d8 | 13841 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
63c3a66f | 13842 | if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
1ee582d8 MC |
13843 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
13844 | } | |
20094930 | 13845 | |
63c3a66f | 13846 | if (tg3_flag(tp, ICH_WORKAROUND)) { |
6892914f MC |
13847 | tp->read32 = tg3_read_indirect_reg32; |
13848 | tp->write32 = tg3_write_indirect_reg32; | |
13849 | tp->read32_mbox = tg3_read_indirect_mbox; | |
13850 | tp->write32_mbox = tg3_write_indirect_mbox; | |
13851 | tp->write32_tx_mbox = tg3_write_indirect_mbox; | |
13852 | tp->write32_rx_mbox = tg3_write_indirect_mbox; | |
13853 | ||
13854 | iounmap(tp->regs); | |
22abe310 | 13855 | tp->regs = NULL; |
6892914f MC |
13856 | |
13857 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); | |
13858 | pci_cmd &= ~PCI_COMMAND_MEMORY; | |
13859 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); | |
13860 | } | |
b5d3772c MC |
13861 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
13862 | tp->read32_mbox = tg3_read32_mbox_5906; | |
13863 | tp->write32_mbox = tg3_write32_mbox_5906; | |
13864 | tp->write32_tx_mbox = tg3_write32_mbox_5906; | |
13865 | tp->write32_rx_mbox = tg3_write32_mbox_5906; | |
13866 | } | |
6892914f | 13867 | |
bbadf503 | 13868 | if (tp->write32 == tg3_write_indirect_reg32 || |
63c3a66f | 13869 | (tg3_flag(tp, PCIX_MODE) && |
bbadf503 | 13870 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
f49639e6 | 13871 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701))) |
63c3a66f | 13872 | tg3_flag_set(tp, SRAM_USE_CONFIG); |
bbadf503 | 13873 | |
7d0c41ef | 13874 | /* Get eeprom hw config before calling tg3_set_power_state(). |
63c3a66f | 13875 | * In particular, the TG3_FLAG_IS_NIC flag must be |
7d0c41ef MC |
13876 | * determined before calling tg3_set_power_state() so that |
13877 | * we know whether or not to switch out of Vaux power. | |
13878 | * When the flag is set, it means that GPIO1 is used for eeprom | |
13879 | * write protect and also implies that it is a LOM where GPIOs | |
13880 | * are not used to switch power. | |
6aa20a22 | 13881 | */ |
7d0c41ef MC |
13882 | tg3_get_eeprom_hw_cfg(tp); |
13883 | ||
63c3a66f | 13884 | if (tg3_flag(tp, ENABLE_APE)) { |
0d3031d9 MC |
13885 | /* Allow reads and writes to the |
13886 | * APE register and memory space. | |
13887 | */ | |
13888 | pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR | | |
f92d9dc1 MC |
13889 | PCISTATE_ALLOW_APE_SHMEM_WR | |
13890 | PCISTATE_ALLOW_APE_PSPACE_WR; | |
0d3031d9 MC |
13891 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, |
13892 | pci_state_reg); | |
13893 | } | |
13894 | ||
9936bcf6 | 13895 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
57e6983c | 13896 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
321d32a0 | 13897 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
f6eb9b1f | 13898 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
63c3a66f JP |
13899 | tg3_flag(tp, 57765_PLUS)) |
13900 | tg3_flag_set(tp, CPMU_PRESENT); | |
d30cdd28 | 13901 | |
bea8a63b | 13902 | /* Set up tp->grc_local_ctrl before calling tg3_power_up(). |
314fba34 MC |
13903 | * GPIO1 driven high will bring 5700's external PHY out of reset. |
13904 | * It is also used as eeprom write protect on LOMs. | |
13905 | */ | |
13906 | tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM; | |
13907 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) || | |
63c3a66f | 13908 | tg3_flag(tp, EEPROM_WRITE_PROT)) |
314fba34 MC |
13909 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
13910 | GRC_LCLCTRL_GPIO_OUTPUT1); | |
3e7d83bc MC |
13911 | /* Unused GPIO3 must be driven as output on 5752 because there |
13912 | * are no pull-up resistors on unused GPIO pins. | |
13913 | */ | |
13914 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) | |
13915 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; | |
314fba34 | 13916 | |
321d32a0 | 13917 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
cb4ed1fd MC |
13918 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
13919 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) | |
af36e6b6 MC |
13920 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
13921 | ||
8d519ab2 MC |
13922 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
13923 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { | |
5f0c4a3c MC |
13924 | /* Turn off the debug UART. */ |
13925 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; | |
63c3a66f | 13926 | if (tg3_flag(tp, IS_NIC)) |
5f0c4a3c MC |
13927 | /* Keep VMain power. */ |
13928 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | | |
13929 | GRC_LCLCTRL_GPIO_OUTPUT0; | |
13930 | } | |
13931 | ||
1da177e4 | 13932 | /* Force the chip into D0. */ |
c866b7ea | 13933 | err = tg3_power_up(tp); |
1da177e4 | 13934 | if (err) { |
2445e461 | 13935 | dev_err(&tp->pdev->dev, "Transition to D0 failed\n"); |
1da177e4 LT |
13936 | return err; |
13937 | } | |
13938 | ||
1da177e4 LT |
13939 | /* Derive initial jumbo mode from MTU assigned in |
13940 | * ether_setup() via the alloc_etherdev() call | |
13941 | */ | |
63c3a66f JP |
13942 | if (tp->dev->mtu > ETH_DATA_LEN && !tg3_flag(tp, 5780_CLASS)) |
13943 | tg3_flag_set(tp, JUMBO_RING_ENABLE); | |
1da177e4 LT |
13944 | |
13945 | /* Determine WakeOnLan speed to use. */ | |
13946 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
13947 | tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || | |
13948 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 || | |
13949 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) { | |
63c3a66f | 13950 | tg3_flag_clear(tp, WOL_SPEED_100MB); |
1da177e4 | 13951 | } else { |
63c3a66f | 13952 | tg3_flag_set(tp, WOL_SPEED_100MB); |
1da177e4 LT |
13953 | } |
13954 | ||
7f97a4bd | 13955 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
f07e9af3 | 13956 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
7f97a4bd | 13957 | |
1da177e4 LT |
13958 | /* A few boards don't want Ethernet@WireSpeed phy feature */ |
13959 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) || | |
13960 | ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && | |
13961 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) && | |
747e8f8b | 13962 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) || |
f07e9af3 MC |
13963 | (tp->phy_flags & TG3_PHYFLG_IS_FET) || |
13964 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) | |
13965 | tp->phy_flags |= TG3_PHYFLG_NO_ETH_WIRE_SPEED; | |
1da177e4 LT |
13966 | |
13967 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX || | |
13968 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX) | |
f07e9af3 | 13969 | tp->phy_flags |= TG3_PHYFLG_ADC_BUG; |
1da177e4 | 13970 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) |
f07e9af3 | 13971 | tp->phy_flags |= TG3_PHYFLG_5704_A0_BUG; |
1da177e4 | 13972 | |
63c3a66f | 13973 | if (tg3_flag(tp, 5705_PLUS) && |
f07e9af3 | 13974 | !(tp->phy_flags & TG3_PHYFLG_IS_FET) && |
321d32a0 | 13975 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
f6eb9b1f | 13976 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57780 && |
63c3a66f | 13977 | !tg3_flag(tp, 57765_PLUS)) { |
c424cb24 | 13978 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
d30cdd28 | 13979 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
9936bcf6 MC |
13980 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
13981 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { | |
d4011ada MC |
13982 | if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 && |
13983 | tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722) | |
f07e9af3 | 13984 | tp->phy_flags |= TG3_PHYFLG_JITTER_BUG; |
c1d2a196 | 13985 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M) |
f07e9af3 | 13986 | tp->phy_flags |= TG3_PHYFLG_ADJUST_TRIM; |
321d32a0 | 13987 | } else |
f07e9af3 | 13988 | tp->phy_flags |= TG3_PHYFLG_BER_BUG; |
c424cb24 | 13989 | } |
1da177e4 | 13990 | |
b2a5c19c MC |
13991 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
13992 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { | |
13993 | tp->phy_otp = tg3_read_otp_phycfg(tp); | |
13994 | if (tp->phy_otp == 0) | |
13995 | tp->phy_otp = TG3_OTP_DEFAULT; | |
13996 | } | |
13997 | ||
63c3a66f | 13998 | if (tg3_flag(tp, CPMU_PRESENT)) |
8ef21428 MC |
13999 | tp->mi_mode = MAC_MI_MODE_500KHZ_CONST; |
14000 | else | |
14001 | tp->mi_mode = MAC_MI_MODE_BASE; | |
14002 | ||
1da177e4 | 14003 | tp->coalesce_mode = 0; |
1da177e4 LT |
14004 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX && |
14005 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX) | |
14006 | tp->coalesce_mode |= HOSTCC_MODE_32BYTE; | |
14007 | ||
4d958473 MC |
14008 | /* Set these bits to enable statistics workaround. */ |
14009 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || | |
14010 | tp->pci_chip_rev_id == CHIPREV_ID_5719_A0 || | |
14011 | tp->pci_chip_rev_id == CHIPREV_ID_5720_A0) { | |
14012 | tp->coalesce_mode |= HOSTCC_MODE_ATTN; | |
14013 | tp->grc_mode |= GRC_MODE_IRQ_ON_FLOW_ATTN; | |
14014 | } | |
14015 | ||
321d32a0 MC |
14016 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
14017 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) | |
63c3a66f | 14018 | tg3_flag_set(tp, USE_PHYLIB); |
57e6983c | 14019 | |
158d7abd MC |
14020 | err = tg3_mdio_init(tp); |
14021 | if (err) | |
14022 | return err; | |
1da177e4 LT |
14023 | |
14024 | /* Initialize data/descriptor byte/word swapping. */ | |
14025 | val = tr32(GRC_MODE); | |
f2096f94 MC |
14026 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5720) |
14027 | val &= (GRC_MODE_BYTE_SWAP_B2HRX_DATA | | |
14028 | GRC_MODE_WORD_SWAP_B2HRX_DATA | | |
14029 | GRC_MODE_B2HRX_ENABLE | | |
14030 | GRC_MODE_HTX2B_ENABLE | | |
14031 | GRC_MODE_HOST_STACKUP); | |
14032 | else | |
14033 | val &= GRC_MODE_HOST_STACKUP; | |
14034 | ||
1da177e4 LT |
14035 | tw32(GRC_MODE, val | tp->grc_mode); |
14036 | ||
14037 | tg3_switch_clocks(tp); | |
14038 | ||
14039 | /* Clear this out for sanity. */ | |
14040 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
14041 | ||
14042 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, | |
14043 | &pci_state_reg); | |
14044 | if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 && | |
63c3a66f | 14045 | !tg3_flag(tp, PCIX_TARGET_HWBUG)) { |
1da177e4 LT |
14046 | u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl); |
14047 | ||
14048 | if (chiprevid == CHIPREV_ID_5701_A0 || | |
14049 | chiprevid == CHIPREV_ID_5701_B0 || | |
14050 | chiprevid == CHIPREV_ID_5701_B2 || | |
14051 | chiprevid == CHIPREV_ID_5701_B5) { | |
14052 | void __iomem *sram_base; | |
14053 | ||
14054 | /* Write some dummy words into the SRAM status block | |
14055 | * area, see if it reads back correctly. If the return | |
14056 | * value is bad, force enable the PCIX workaround. | |
14057 | */ | |
14058 | sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK; | |
14059 | ||
14060 | writel(0x00000000, sram_base); | |
14061 | writel(0x00000000, sram_base + 4); | |
14062 | writel(0xffffffff, sram_base + 4); | |
14063 | if (readl(sram_base) != 0x00000000) | |
63c3a66f | 14064 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
1da177e4 LT |
14065 | } |
14066 | } | |
14067 | ||
14068 | udelay(50); | |
14069 | tg3_nvram_init(tp); | |
14070 | ||
14071 | grc_misc_cfg = tr32(GRC_MISC_CFG); | |
14072 | grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK; | |
14073 | ||
1da177e4 LT |
14074 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
14075 | (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 || | |
14076 | grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M)) | |
63c3a66f | 14077 | tg3_flag_set(tp, IS_5788); |
1da177e4 | 14078 | |
63c3a66f | 14079 | if (!tg3_flag(tp, IS_5788) && |
fac9b83e | 14080 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700)) |
63c3a66f JP |
14081 | tg3_flag_set(tp, TAGGED_STATUS); |
14082 | if (tg3_flag(tp, TAGGED_STATUS)) { | |
fac9b83e DM |
14083 | tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD | |
14084 | HOSTCC_MODE_CLRTICK_TXBD); | |
14085 | ||
14086 | tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS; | |
14087 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
14088 | tp->misc_host_ctrl); | |
14089 | } | |
14090 | ||
3bda1258 | 14091 | /* Preserve the APE MAC_MODE bits */ |
63c3a66f | 14092 | if (tg3_flag(tp, ENABLE_APE)) |
d2394e6b | 14093 | tp->mac_mode = MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; |
3bda1258 MC |
14094 | else |
14095 | tp->mac_mode = TG3_DEF_MAC_MODE; | |
14096 | ||
1da177e4 LT |
14097 | /* these are limited to 10/100 only */ |
14098 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && | |
14099 | (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) || | |
14100 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && | |
14101 | tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && | |
14102 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 || | |
14103 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 || | |
14104 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) || | |
14105 | (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && | |
14106 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F || | |
676917d4 MC |
14107 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F || |
14108 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) || | |
321d32a0 | 14109 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790 || |
d1101142 MC |
14110 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
14111 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 || | |
f07e9af3 MC |
14112 | (tp->phy_flags & TG3_PHYFLG_IS_FET)) |
14113 | tp->phy_flags |= TG3_PHYFLG_10_100_ONLY; | |
1da177e4 LT |
14114 | |
14115 | err = tg3_phy_probe(tp); | |
14116 | if (err) { | |
2445e461 | 14117 | dev_err(&tp->pdev->dev, "phy probe failed, err %d\n", err); |
1da177e4 | 14118 | /* ... but do not return immediately ... */ |
b02fd9e3 | 14119 | tg3_mdio_fini(tp); |
1da177e4 LT |
14120 | } |
14121 | ||
184b8904 | 14122 | tg3_read_vpd(tp); |
c4e6575c | 14123 | tg3_read_fw_ver(tp); |
1da177e4 | 14124 | |
f07e9af3 MC |
14125 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
14126 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; | |
1da177e4 LT |
14127 | } else { |
14128 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) | |
f07e9af3 | 14129 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
1da177e4 | 14130 | else |
f07e9af3 | 14131 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
1da177e4 LT |
14132 | } |
14133 | ||
14134 | /* 5700 {AX,BX} chips have a broken status block link | |
14135 | * change bit implementation, so we must use the | |
14136 | * status register in those cases. | |
14137 | */ | |
14138 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) | |
63c3a66f | 14139 | tg3_flag_set(tp, USE_LINKCHG_REG); |
1da177e4 | 14140 | else |
63c3a66f | 14141 | tg3_flag_clear(tp, USE_LINKCHG_REG); |
1da177e4 LT |
14142 | |
14143 | /* The led_ctrl is set during tg3_phy_probe, here we might | |
14144 | * have to force the link status polling mechanism based | |
14145 | * upon subsystem IDs. | |
14146 | */ | |
14147 | if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL && | |
007a880d | 14148 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
f07e9af3 MC |
14149 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
14150 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; | |
63c3a66f | 14151 | tg3_flag_set(tp, USE_LINKCHG_REG); |
1da177e4 LT |
14152 | } |
14153 | ||
14154 | /* For all SERDES we poll the MAC status register. */ | |
f07e9af3 | 14155 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
63c3a66f | 14156 | tg3_flag_set(tp, POLL_SERDES); |
1da177e4 | 14157 | else |
63c3a66f | 14158 | tg3_flag_clear(tp, POLL_SERDES); |
1da177e4 | 14159 | |
bf933c80 | 14160 | tp->rx_offset = NET_IP_ALIGN; |
d2757fc4 | 14161 | tp->rx_copy_thresh = TG3_RX_COPY_THRESHOLD; |
1da177e4 | 14162 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
63c3a66f | 14163 | tg3_flag(tp, PCIX_MODE)) { |
bf933c80 | 14164 | tp->rx_offset = 0; |
d2757fc4 | 14165 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
9dc7a113 | 14166 | tp->rx_copy_thresh = ~(u16)0; |
d2757fc4 MC |
14167 | #endif |
14168 | } | |
1da177e4 | 14169 | |
2c49a44d MC |
14170 | tp->rx_std_ring_mask = TG3_RX_STD_RING_SIZE(tp) - 1; |
14171 | tp->rx_jmb_ring_mask = TG3_RX_JMB_RING_SIZE(tp) - 1; | |
7cb32cf2 MC |
14172 | tp->rx_ret_ring_mask = tg3_rx_ret_ring_size(tp) - 1; |
14173 | ||
2c49a44d | 14174 | tp->rx_std_max_post = tp->rx_std_ring_mask + 1; |
f92905de MC |
14175 | |
14176 | /* Increment the rx prod index on the rx std ring by at most | |
14177 | * 8 for these chips to workaround hw errata. | |
14178 | */ | |
14179 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || | |
14180 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || | |
14181 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) | |
14182 | tp->rx_std_max_post = 8; | |
14183 | ||
63c3a66f | 14184 | if (tg3_flag(tp, ASPM_WORKAROUND)) |
8ed5d97e MC |
14185 | tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) & |
14186 | PCIE_PWR_MGMT_L1_THRESH_MSK; | |
14187 | ||
1da177e4 LT |
14188 | return err; |
14189 | } | |
14190 | ||
49b6e95f | 14191 | #ifdef CONFIG_SPARC |
1da177e4 LT |
14192 | static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp) |
14193 | { | |
14194 | struct net_device *dev = tp->dev; | |
14195 | struct pci_dev *pdev = tp->pdev; | |
49b6e95f | 14196 | struct device_node *dp = pci_device_to_OF_node(pdev); |
374d4cac | 14197 | const unsigned char *addr; |
49b6e95f DM |
14198 | int len; |
14199 | ||
14200 | addr = of_get_property(dp, "local-mac-address", &len); | |
14201 | if (addr && len == 6) { | |
14202 | memcpy(dev->dev_addr, addr, 6); | |
14203 | memcpy(dev->perm_addr, dev->dev_addr, 6); | |
14204 | return 0; | |
1da177e4 LT |
14205 | } |
14206 | return -ENODEV; | |
14207 | } | |
14208 | ||
14209 | static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp) | |
14210 | { | |
14211 | struct net_device *dev = tp->dev; | |
14212 | ||
14213 | memcpy(dev->dev_addr, idprom->id_ethaddr, 6); | |
2ff43697 | 14214 | memcpy(dev->perm_addr, idprom->id_ethaddr, 6); |
1da177e4 LT |
14215 | return 0; |
14216 | } | |
14217 | #endif | |
14218 | ||
14219 | static int __devinit tg3_get_device_address(struct tg3 *tp) | |
14220 | { | |
14221 | struct net_device *dev = tp->dev; | |
14222 | u32 hi, lo, mac_offset; | |
008652b3 | 14223 | int addr_ok = 0; |
1da177e4 | 14224 | |
49b6e95f | 14225 | #ifdef CONFIG_SPARC |
1da177e4 LT |
14226 | if (!tg3_get_macaddr_sparc(tp)) |
14227 | return 0; | |
14228 | #endif | |
14229 | ||
14230 | mac_offset = 0x7c; | |
f49639e6 | 14231 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) || |
63c3a66f | 14232 | tg3_flag(tp, 5780_CLASS)) { |
1da177e4 LT |
14233 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
14234 | mac_offset = 0xcc; | |
14235 | if (tg3_nvram_lock(tp)) | |
14236 | tw32_f(NVRAM_CMD, NVRAM_CMD_RESET); | |
14237 | else | |
14238 | tg3_nvram_unlock(tp); | |
63c3a66f | 14239 | } else if (tg3_flag(tp, 5717_PLUS)) { |
a50d0796 | 14240 | if (PCI_FUNC(tp->pdev->devfn) & 1) |
a1b950d5 | 14241 | mac_offset = 0xcc; |
a50d0796 MC |
14242 | if (PCI_FUNC(tp->pdev->devfn) > 1) |
14243 | mac_offset += 0x18c; | |
a1b950d5 | 14244 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
b5d3772c | 14245 | mac_offset = 0x10; |
1da177e4 LT |
14246 | |
14247 | /* First try to get it from MAC address mailbox. */ | |
14248 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi); | |
14249 | if ((hi >> 16) == 0x484b) { | |
14250 | dev->dev_addr[0] = (hi >> 8) & 0xff; | |
14251 | dev->dev_addr[1] = (hi >> 0) & 0xff; | |
14252 | ||
14253 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo); | |
14254 | dev->dev_addr[2] = (lo >> 24) & 0xff; | |
14255 | dev->dev_addr[3] = (lo >> 16) & 0xff; | |
14256 | dev->dev_addr[4] = (lo >> 8) & 0xff; | |
14257 | dev->dev_addr[5] = (lo >> 0) & 0xff; | |
1da177e4 | 14258 | |
008652b3 MC |
14259 | /* Some old bootcode may report a 0 MAC address in SRAM */ |
14260 | addr_ok = is_valid_ether_addr(&dev->dev_addr[0]); | |
14261 | } | |
14262 | if (!addr_ok) { | |
14263 | /* Next, try NVRAM. */ | |
63c3a66f | 14264 | if (!tg3_flag(tp, NO_NVRAM) && |
df259d8c | 14265 | !tg3_nvram_read_be32(tp, mac_offset + 0, &hi) && |
6d348f2c | 14266 | !tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) { |
62cedd11 MC |
14267 | memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2); |
14268 | memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo)); | |
008652b3 MC |
14269 | } |
14270 | /* Finally just fetch it out of the MAC control regs. */ | |
14271 | else { | |
14272 | hi = tr32(MAC_ADDR_0_HIGH); | |
14273 | lo = tr32(MAC_ADDR_0_LOW); | |
14274 | ||
14275 | dev->dev_addr[5] = lo & 0xff; | |
14276 | dev->dev_addr[4] = (lo >> 8) & 0xff; | |
14277 | dev->dev_addr[3] = (lo >> 16) & 0xff; | |
14278 | dev->dev_addr[2] = (lo >> 24) & 0xff; | |
14279 | dev->dev_addr[1] = hi & 0xff; | |
14280 | dev->dev_addr[0] = (hi >> 8) & 0xff; | |
14281 | } | |
1da177e4 LT |
14282 | } |
14283 | ||
14284 | if (!is_valid_ether_addr(&dev->dev_addr[0])) { | |
7582a335 | 14285 | #ifdef CONFIG_SPARC |
1da177e4 LT |
14286 | if (!tg3_get_default_macaddr_sparc(tp)) |
14287 | return 0; | |
14288 | #endif | |
14289 | return -EINVAL; | |
14290 | } | |
2ff43697 | 14291 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
1da177e4 LT |
14292 | return 0; |
14293 | } | |
14294 | ||
59e6b434 DM |
14295 | #define BOUNDARY_SINGLE_CACHELINE 1 |
14296 | #define BOUNDARY_MULTI_CACHELINE 2 | |
14297 | ||
14298 | static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val) | |
14299 | { | |
14300 | int cacheline_size; | |
14301 | u8 byte; | |
14302 | int goal; | |
14303 | ||
14304 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte); | |
14305 | if (byte == 0) | |
14306 | cacheline_size = 1024; | |
14307 | else | |
14308 | cacheline_size = (int) byte * 4; | |
14309 | ||
14310 | /* On 5703 and later chips, the boundary bits have no | |
14311 | * effect. | |
14312 | */ | |
14313 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && | |
14314 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && | |
63c3a66f | 14315 | !tg3_flag(tp, PCI_EXPRESS)) |
59e6b434 DM |
14316 | goto out; |
14317 | ||
14318 | #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC) | |
14319 | goal = BOUNDARY_MULTI_CACHELINE; | |
14320 | #else | |
14321 | #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA) | |
14322 | goal = BOUNDARY_SINGLE_CACHELINE; | |
14323 | #else | |
14324 | goal = 0; | |
14325 | #endif | |
14326 | #endif | |
14327 | ||
63c3a66f | 14328 | if (tg3_flag(tp, 57765_PLUS)) { |
cbf9ca6c MC |
14329 | val = goal ? 0 : DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
14330 | goto out; | |
14331 | } | |
14332 | ||
59e6b434 DM |
14333 | if (!goal) |
14334 | goto out; | |
14335 | ||
14336 | /* PCI controllers on most RISC systems tend to disconnect | |
14337 | * when a device tries to burst across a cache-line boundary. | |
14338 | * Therefore, letting tg3 do so just wastes PCI bandwidth. | |
14339 | * | |
14340 | * Unfortunately, for PCI-E there are only limited | |
14341 | * write-side controls for this, and thus for reads | |
14342 | * we will still get the disconnects. We'll also waste | |
14343 | * these PCI cycles for both read and write for chips | |
14344 | * other than 5700 and 5701 which do not implement the | |
14345 | * boundary bits. | |
14346 | */ | |
63c3a66f | 14347 | if (tg3_flag(tp, PCIX_MODE) && !tg3_flag(tp, PCI_EXPRESS)) { |
59e6b434 DM |
14348 | switch (cacheline_size) { |
14349 | case 16: | |
14350 | case 32: | |
14351 | case 64: | |
14352 | case 128: | |
14353 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
14354 | val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX | | |
14355 | DMA_RWCTRL_WRITE_BNDRY_128_PCIX); | |
14356 | } else { | |
14357 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | | |
14358 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); | |
14359 | } | |
14360 | break; | |
14361 | ||
14362 | case 256: | |
14363 | val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX | | |
14364 | DMA_RWCTRL_WRITE_BNDRY_256_PCIX); | |
14365 | break; | |
14366 | ||
14367 | default: | |
14368 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | | |
14369 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); | |
14370 | break; | |
855e1111 | 14371 | } |
63c3a66f | 14372 | } else if (tg3_flag(tp, PCI_EXPRESS)) { |
59e6b434 DM |
14373 | switch (cacheline_size) { |
14374 | case 16: | |
14375 | case 32: | |
14376 | case 64: | |
14377 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
14378 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; | |
14379 | val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE; | |
14380 | break; | |
14381 | } | |
14382 | /* fallthrough */ | |
14383 | case 128: | |
14384 | default: | |
14385 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; | |
14386 | val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE; | |
14387 | break; | |
855e1111 | 14388 | } |
59e6b434 DM |
14389 | } else { |
14390 | switch (cacheline_size) { | |
14391 | case 16: | |
14392 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
14393 | val |= (DMA_RWCTRL_READ_BNDRY_16 | | |
14394 | DMA_RWCTRL_WRITE_BNDRY_16); | |
14395 | break; | |
14396 | } | |
14397 | /* fallthrough */ | |
14398 | case 32: | |
14399 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
14400 | val |= (DMA_RWCTRL_READ_BNDRY_32 | | |
14401 | DMA_RWCTRL_WRITE_BNDRY_32); | |
14402 | break; | |
14403 | } | |
14404 | /* fallthrough */ | |
14405 | case 64: | |
14406 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
14407 | val |= (DMA_RWCTRL_READ_BNDRY_64 | | |
14408 | DMA_RWCTRL_WRITE_BNDRY_64); | |
14409 | break; | |
14410 | } | |
14411 | /* fallthrough */ | |
14412 | case 128: | |
14413 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
14414 | val |= (DMA_RWCTRL_READ_BNDRY_128 | | |
14415 | DMA_RWCTRL_WRITE_BNDRY_128); | |
14416 | break; | |
14417 | } | |
14418 | /* fallthrough */ | |
14419 | case 256: | |
14420 | val |= (DMA_RWCTRL_READ_BNDRY_256 | | |
14421 | DMA_RWCTRL_WRITE_BNDRY_256); | |
14422 | break; | |
14423 | case 512: | |
14424 | val |= (DMA_RWCTRL_READ_BNDRY_512 | | |
14425 | DMA_RWCTRL_WRITE_BNDRY_512); | |
14426 | break; | |
14427 | case 1024: | |
14428 | default: | |
14429 | val |= (DMA_RWCTRL_READ_BNDRY_1024 | | |
14430 | DMA_RWCTRL_WRITE_BNDRY_1024); | |
14431 | break; | |
855e1111 | 14432 | } |
59e6b434 DM |
14433 | } |
14434 | ||
14435 | out: | |
14436 | return val; | |
14437 | } | |
14438 | ||
1da177e4 LT |
14439 | static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device) |
14440 | { | |
14441 | struct tg3_internal_buffer_desc test_desc; | |
14442 | u32 sram_dma_descs; | |
14443 | int i, ret; | |
14444 | ||
14445 | sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE; | |
14446 | ||
14447 | tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0); | |
14448 | tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0); | |
14449 | tw32(RDMAC_STATUS, 0); | |
14450 | tw32(WDMAC_STATUS, 0); | |
14451 | ||
14452 | tw32(BUFMGR_MODE, 0); | |
14453 | tw32(FTQ_RESET, 0); | |
14454 | ||
14455 | test_desc.addr_hi = ((u64) buf_dma) >> 32; | |
14456 | test_desc.addr_lo = buf_dma & 0xffffffff; | |
14457 | test_desc.nic_mbuf = 0x00002100; | |
14458 | test_desc.len = size; | |
14459 | ||
14460 | /* | |
14461 | * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz | |
14462 | * the *second* time the tg3 driver was getting loaded after an | |
14463 | * initial scan. | |
14464 | * | |
14465 | * Broadcom tells me: | |
14466 | * ...the DMA engine is connected to the GRC block and a DMA | |
14467 | * reset may affect the GRC block in some unpredictable way... | |
14468 | * The behavior of resets to individual blocks has not been tested. | |
14469 | * | |
14470 | * Broadcom noted the GRC reset will also reset all sub-components. | |
14471 | */ | |
14472 | if (to_device) { | |
14473 | test_desc.cqid_sqid = (13 << 8) | 2; | |
14474 | ||
14475 | tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE); | |
14476 | udelay(40); | |
14477 | } else { | |
14478 | test_desc.cqid_sqid = (16 << 8) | 7; | |
14479 | ||
14480 | tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE); | |
14481 | udelay(40); | |
14482 | } | |
14483 | test_desc.flags = 0x00000005; | |
14484 | ||
14485 | for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) { | |
14486 | u32 val; | |
14487 | ||
14488 | val = *(((u32 *)&test_desc) + i); | |
14489 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, | |
14490 | sram_dma_descs + (i * sizeof(u32))); | |
14491 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); | |
14492 | } | |
14493 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
14494 | ||
859a5887 | 14495 | if (to_device) |
1da177e4 | 14496 | tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs); |
859a5887 | 14497 | else |
1da177e4 | 14498 | tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs); |
1da177e4 LT |
14499 | |
14500 | ret = -ENODEV; | |
14501 | for (i = 0; i < 40; i++) { | |
14502 | u32 val; | |
14503 | ||
14504 | if (to_device) | |
14505 | val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ); | |
14506 | else | |
14507 | val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ); | |
14508 | if ((val & 0xffff) == sram_dma_descs) { | |
14509 | ret = 0; | |
14510 | break; | |
14511 | } | |
14512 | ||
14513 | udelay(100); | |
14514 | } | |
14515 | ||
14516 | return ret; | |
14517 | } | |
14518 | ||
ded7340d | 14519 | #define TEST_BUFFER_SIZE 0x2000 |
1da177e4 | 14520 | |
4143470c | 14521 | static DEFINE_PCI_DEVICE_TABLE(tg3_dma_wait_state_chipsets) = { |
895950c2 JP |
14522 | { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_PCI15) }, |
14523 | { }, | |
14524 | }; | |
14525 | ||
1da177e4 LT |
14526 | static int __devinit tg3_test_dma(struct tg3 *tp) |
14527 | { | |
14528 | dma_addr_t buf_dma; | |
59e6b434 | 14529 | u32 *buf, saved_dma_rwctrl; |
cbf9ca6c | 14530 | int ret = 0; |
1da177e4 | 14531 | |
4bae65c8 MC |
14532 | buf = dma_alloc_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, |
14533 | &buf_dma, GFP_KERNEL); | |
1da177e4 LT |
14534 | if (!buf) { |
14535 | ret = -ENOMEM; | |
14536 | goto out_nofree; | |
14537 | } | |
14538 | ||
14539 | tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) | | |
14540 | (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT)); | |
14541 | ||
59e6b434 | 14542 | tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl); |
1da177e4 | 14543 | |
63c3a66f | 14544 | if (tg3_flag(tp, 57765_PLUS)) |
cbf9ca6c MC |
14545 | goto out; |
14546 | ||
63c3a66f | 14547 | if (tg3_flag(tp, PCI_EXPRESS)) { |
1da177e4 LT |
14548 | /* DMA read watermark not used on PCIE */ |
14549 | tp->dma_rwctrl |= 0x00180000; | |
63c3a66f | 14550 | } else if (!tg3_flag(tp, PCIX_MODE)) { |
85e94ced MC |
14551 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || |
14552 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) | |
1da177e4 LT |
14553 | tp->dma_rwctrl |= 0x003f0000; |
14554 | else | |
14555 | tp->dma_rwctrl |= 0x003f000f; | |
14556 | } else { | |
14557 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || | |
14558 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { | |
14559 | u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f); | |
49afdeb6 | 14560 | u32 read_water = 0x7; |
1da177e4 | 14561 | |
4a29cc2e MC |
14562 | /* If the 5704 is behind the EPB bridge, we can |
14563 | * do the less restrictive ONE_DMA workaround for | |
14564 | * better performance. | |
14565 | */ | |
63c3a66f | 14566 | if (tg3_flag(tp, 40BIT_DMA_BUG) && |
4a29cc2e MC |
14567 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) |
14568 | tp->dma_rwctrl |= 0x8000; | |
14569 | else if (ccval == 0x6 || ccval == 0x7) | |
1da177e4 LT |
14570 | tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; |
14571 | ||
49afdeb6 MC |
14572 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) |
14573 | read_water = 4; | |
59e6b434 | 14574 | /* Set bit 23 to enable PCIX hw bug fix */ |
49afdeb6 MC |
14575 | tp->dma_rwctrl |= |
14576 | (read_water << DMA_RWCTRL_READ_WATER_SHIFT) | | |
14577 | (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) | | |
14578 | (1 << 23); | |
4cf78e4f MC |
14579 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) { |
14580 | /* 5780 always in PCIX mode */ | |
14581 | tp->dma_rwctrl |= 0x00144000; | |
a4e2b347 MC |
14582 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
14583 | /* 5714 always in PCIX mode */ | |
14584 | tp->dma_rwctrl |= 0x00148000; | |
1da177e4 LT |
14585 | } else { |
14586 | tp->dma_rwctrl |= 0x001b000f; | |
14587 | } | |
14588 | } | |
14589 | ||
14590 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || | |
14591 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) | |
14592 | tp->dma_rwctrl &= 0xfffffff0; | |
14593 | ||
14594 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
14595 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { | |
14596 | /* Remove this if it causes problems for some boards. */ | |
14597 | tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT; | |
14598 | ||
14599 | /* On 5700/5701 chips, we need to set this bit. | |
14600 | * Otherwise the chip will issue cacheline transactions | |
14601 | * to streamable DMA memory with not all the byte | |
14602 | * enables turned on. This is an error on several | |
14603 | * RISC PCI controllers, in particular sparc64. | |
14604 | * | |
14605 | * On 5703/5704 chips, this bit has been reassigned | |
14606 | * a different meaning. In particular, it is used | |
14607 | * on those chips to enable a PCI-X workaround. | |
14608 | */ | |
14609 | tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE; | |
14610 | } | |
14611 | ||
14612 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); | |
14613 | ||
14614 | #if 0 | |
14615 | /* Unneeded, already done by tg3_get_invariants. */ | |
14616 | tg3_switch_clocks(tp); | |
14617 | #endif | |
14618 | ||
1da177e4 LT |
14619 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
14620 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) | |
14621 | goto out; | |
14622 | ||
59e6b434 DM |
14623 | /* It is best to perform DMA test with maximum write burst size |
14624 | * to expose the 5700/5701 write DMA bug. | |
14625 | */ | |
14626 | saved_dma_rwctrl = tp->dma_rwctrl; | |
14627 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; | |
14628 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); | |
14629 | ||
1da177e4 LT |
14630 | while (1) { |
14631 | u32 *p = buf, i; | |
14632 | ||
14633 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) | |
14634 | p[i] = i; | |
14635 | ||
14636 | /* Send the buffer to the chip. */ | |
14637 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1); | |
14638 | if (ret) { | |
2445e461 MC |
14639 | dev_err(&tp->pdev->dev, |
14640 | "%s: Buffer write failed. err = %d\n", | |
14641 | __func__, ret); | |
1da177e4 LT |
14642 | break; |
14643 | } | |
14644 | ||
14645 | #if 0 | |
14646 | /* validate data reached card RAM correctly. */ | |
14647 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { | |
14648 | u32 val; | |
14649 | tg3_read_mem(tp, 0x2100 + (i*4), &val); | |
14650 | if (le32_to_cpu(val) != p[i]) { | |
2445e461 MC |
14651 | dev_err(&tp->pdev->dev, |
14652 | "%s: Buffer corrupted on device! " | |
14653 | "(%d != %d)\n", __func__, val, i); | |
1da177e4 LT |
14654 | /* ret = -ENODEV here? */ |
14655 | } | |
14656 | p[i] = 0; | |
14657 | } | |
14658 | #endif | |
14659 | /* Now read it back. */ | |
14660 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0); | |
14661 | if (ret) { | |
5129c3a3 MC |
14662 | dev_err(&tp->pdev->dev, "%s: Buffer read failed. " |
14663 | "err = %d\n", __func__, ret); | |
1da177e4 LT |
14664 | break; |
14665 | } | |
14666 | ||
14667 | /* Verify it. */ | |
14668 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { | |
14669 | if (p[i] == i) | |
14670 | continue; | |
14671 | ||
59e6b434 DM |
14672 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
14673 | DMA_RWCTRL_WRITE_BNDRY_16) { | |
14674 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; | |
1da177e4 LT |
14675 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
14676 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); | |
14677 | break; | |
14678 | } else { | |
2445e461 MC |
14679 | dev_err(&tp->pdev->dev, |
14680 | "%s: Buffer corrupted on read back! " | |
14681 | "(%d != %d)\n", __func__, p[i], i); | |
1da177e4 LT |
14682 | ret = -ENODEV; |
14683 | goto out; | |
14684 | } | |
14685 | } | |
14686 | ||
14687 | if (i == (TEST_BUFFER_SIZE / sizeof(u32))) { | |
14688 | /* Success. */ | |
14689 | ret = 0; | |
14690 | break; | |
14691 | } | |
14692 | } | |
59e6b434 DM |
14693 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
14694 | DMA_RWCTRL_WRITE_BNDRY_16) { | |
14695 | /* DMA test passed without adjusting DMA boundary, | |
6d1cfbab MC |
14696 | * now look for chipsets that are known to expose the |
14697 | * DMA bug without failing the test. | |
59e6b434 | 14698 | */ |
4143470c | 14699 | if (pci_dev_present(tg3_dma_wait_state_chipsets)) { |
6d1cfbab MC |
14700 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
14701 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; | |
859a5887 | 14702 | } else { |
6d1cfbab MC |
14703 | /* Safe to use the calculated DMA boundary. */ |
14704 | tp->dma_rwctrl = saved_dma_rwctrl; | |
859a5887 | 14705 | } |
6d1cfbab | 14706 | |
59e6b434 DM |
14707 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
14708 | } | |
1da177e4 LT |
14709 | |
14710 | out: | |
4bae65c8 | 14711 | dma_free_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, buf, buf_dma); |
1da177e4 LT |
14712 | out_nofree: |
14713 | return ret; | |
14714 | } | |
14715 | ||
1da177e4 LT |
14716 | static void __devinit tg3_init_bufmgr_config(struct tg3 *tp) |
14717 | { | |
63c3a66f | 14718 | if (tg3_flag(tp, 57765_PLUS)) { |
666bc831 MC |
14719 | tp->bufmgr_config.mbuf_read_dma_low_water = |
14720 | DEFAULT_MB_RDMA_LOW_WATER_5705; | |
14721 | tp->bufmgr_config.mbuf_mac_rx_low_water = | |
14722 | DEFAULT_MB_MACRX_LOW_WATER_57765; | |
14723 | tp->bufmgr_config.mbuf_high_water = | |
14724 | DEFAULT_MB_HIGH_WATER_57765; | |
14725 | ||
14726 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = | |
14727 | DEFAULT_MB_RDMA_LOW_WATER_5705; | |
14728 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = | |
14729 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_57765; | |
14730 | tp->bufmgr_config.mbuf_high_water_jumbo = | |
14731 | DEFAULT_MB_HIGH_WATER_JUMBO_57765; | |
63c3a66f | 14732 | } else if (tg3_flag(tp, 5705_PLUS)) { |
fdfec172 MC |
14733 | tp->bufmgr_config.mbuf_read_dma_low_water = |
14734 | DEFAULT_MB_RDMA_LOW_WATER_5705; | |
14735 | tp->bufmgr_config.mbuf_mac_rx_low_water = | |
14736 | DEFAULT_MB_MACRX_LOW_WATER_5705; | |
14737 | tp->bufmgr_config.mbuf_high_water = | |
14738 | DEFAULT_MB_HIGH_WATER_5705; | |
b5d3772c MC |
14739 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
14740 | tp->bufmgr_config.mbuf_mac_rx_low_water = | |
14741 | DEFAULT_MB_MACRX_LOW_WATER_5906; | |
14742 | tp->bufmgr_config.mbuf_high_water = | |
14743 | DEFAULT_MB_HIGH_WATER_5906; | |
14744 | } | |
fdfec172 MC |
14745 | |
14746 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = | |
14747 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780; | |
14748 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = | |
14749 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780; | |
14750 | tp->bufmgr_config.mbuf_high_water_jumbo = | |
14751 | DEFAULT_MB_HIGH_WATER_JUMBO_5780; | |
14752 | } else { | |
14753 | tp->bufmgr_config.mbuf_read_dma_low_water = | |
14754 | DEFAULT_MB_RDMA_LOW_WATER; | |
14755 | tp->bufmgr_config.mbuf_mac_rx_low_water = | |
14756 | DEFAULT_MB_MACRX_LOW_WATER; | |
14757 | tp->bufmgr_config.mbuf_high_water = | |
14758 | DEFAULT_MB_HIGH_WATER; | |
14759 | ||
14760 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = | |
14761 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO; | |
14762 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = | |
14763 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO; | |
14764 | tp->bufmgr_config.mbuf_high_water_jumbo = | |
14765 | DEFAULT_MB_HIGH_WATER_JUMBO; | |
14766 | } | |
1da177e4 LT |
14767 | |
14768 | tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER; | |
14769 | tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER; | |
14770 | } | |
14771 | ||
14772 | static char * __devinit tg3_phy_string(struct tg3 *tp) | |
14773 | { | |
79eb6904 MC |
14774 | switch (tp->phy_id & TG3_PHY_ID_MASK) { |
14775 | case TG3_PHY_ID_BCM5400: return "5400"; | |
14776 | case TG3_PHY_ID_BCM5401: return "5401"; | |
14777 | case TG3_PHY_ID_BCM5411: return "5411"; | |
14778 | case TG3_PHY_ID_BCM5701: return "5701"; | |
14779 | case TG3_PHY_ID_BCM5703: return "5703"; | |
14780 | case TG3_PHY_ID_BCM5704: return "5704"; | |
14781 | case TG3_PHY_ID_BCM5705: return "5705"; | |
14782 | case TG3_PHY_ID_BCM5750: return "5750"; | |
14783 | case TG3_PHY_ID_BCM5752: return "5752"; | |
14784 | case TG3_PHY_ID_BCM5714: return "5714"; | |
14785 | case TG3_PHY_ID_BCM5780: return "5780"; | |
14786 | case TG3_PHY_ID_BCM5755: return "5755"; | |
14787 | case TG3_PHY_ID_BCM5787: return "5787"; | |
14788 | case TG3_PHY_ID_BCM5784: return "5784"; | |
14789 | case TG3_PHY_ID_BCM5756: return "5722/5756"; | |
14790 | case TG3_PHY_ID_BCM5906: return "5906"; | |
14791 | case TG3_PHY_ID_BCM5761: return "5761"; | |
14792 | case TG3_PHY_ID_BCM5718C: return "5718C"; | |
14793 | case TG3_PHY_ID_BCM5718S: return "5718S"; | |
14794 | case TG3_PHY_ID_BCM57765: return "57765"; | |
302b500b | 14795 | case TG3_PHY_ID_BCM5719C: return "5719C"; |
6418f2c1 | 14796 | case TG3_PHY_ID_BCM5720C: return "5720C"; |
79eb6904 | 14797 | case TG3_PHY_ID_BCM8002: return "8002/serdes"; |
1da177e4 LT |
14798 | case 0: return "serdes"; |
14799 | default: return "unknown"; | |
855e1111 | 14800 | } |
1da177e4 LT |
14801 | } |
14802 | ||
f9804ddb MC |
14803 | static char * __devinit tg3_bus_string(struct tg3 *tp, char *str) |
14804 | { | |
63c3a66f | 14805 | if (tg3_flag(tp, PCI_EXPRESS)) { |
f9804ddb MC |
14806 | strcpy(str, "PCI Express"); |
14807 | return str; | |
63c3a66f | 14808 | } else if (tg3_flag(tp, PCIX_MODE)) { |
f9804ddb MC |
14809 | u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f; |
14810 | ||
14811 | strcpy(str, "PCIX:"); | |
14812 | ||
14813 | if ((clock_ctrl == 7) || | |
14814 | ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) == | |
14815 | GRC_MISC_CFG_BOARD_ID_5704CIOBE)) | |
14816 | strcat(str, "133MHz"); | |
14817 | else if (clock_ctrl == 0) | |
14818 | strcat(str, "33MHz"); | |
14819 | else if (clock_ctrl == 2) | |
14820 | strcat(str, "50MHz"); | |
14821 | else if (clock_ctrl == 4) | |
14822 | strcat(str, "66MHz"); | |
14823 | else if (clock_ctrl == 6) | |
14824 | strcat(str, "100MHz"); | |
f9804ddb MC |
14825 | } else { |
14826 | strcpy(str, "PCI:"); | |
63c3a66f | 14827 | if (tg3_flag(tp, PCI_HIGH_SPEED)) |
f9804ddb MC |
14828 | strcat(str, "66MHz"); |
14829 | else | |
14830 | strcat(str, "33MHz"); | |
14831 | } | |
63c3a66f | 14832 | if (tg3_flag(tp, PCI_32BIT)) |
f9804ddb MC |
14833 | strcat(str, ":32-bit"); |
14834 | else | |
14835 | strcat(str, ":64-bit"); | |
14836 | return str; | |
14837 | } | |
14838 | ||
8c2dc7e1 | 14839 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp) |
1da177e4 LT |
14840 | { |
14841 | struct pci_dev *peer; | |
14842 | unsigned int func, devnr = tp->pdev->devfn & ~7; | |
14843 | ||
14844 | for (func = 0; func < 8; func++) { | |
14845 | peer = pci_get_slot(tp->pdev->bus, devnr | func); | |
14846 | if (peer && peer != tp->pdev) | |
14847 | break; | |
14848 | pci_dev_put(peer); | |
14849 | } | |
16fe9d74 MC |
14850 | /* 5704 can be configured in single-port mode, set peer to |
14851 | * tp->pdev in that case. | |
14852 | */ | |
14853 | if (!peer) { | |
14854 | peer = tp->pdev; | |
14855 | return peer; | |
14856 | } | |
1da177e4 LT |
14857 | |
14858 | /* | |
14859 | * We don't need to keep the refcount elevated; there's no way | |
14860 | * to remove one half of this device without removing the other | |
14861 | */ | |
14862 | pci_dev_put(peer); | |
14863 | ||
14864 | return peer; | |
14865 | } | |
14866 | ||
15f9850d DM |
14867 | static void __devinit tg3_init_coal(struct tg3 *tp) |
14868 | { | |
14869 | struct ethtool_coalesce *ec = &tp->coal; | |
14870 | ||
14871 | memset(ec, 0, sizeof(*ec)); | |
14872 | ec->cmd = ETHTOOL_GCOALESCE; | |
14873 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS; | |
14874 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS; | |
14875 | ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES; | |
14876 | ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES; | |
14877 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT; | |
14878 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT; | |
14879 | ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT; | |
14880 | ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT; | |
14881 | ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS; | |
14882 | ||
14883 | if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD | | |
14884 | HOSTCC_MODE_CLRTICK_TXBD)) { | |
14885 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS; | |
14886 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS; | |
14887 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS; | |
14888 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS; | |
14889 | } | |
d244c892 | 14890 | |
63c3a66f | 14891 | if (tg3_flag(tp, 5705_PLUS)) { |
d244c892 MC |
14892 | ec->rx_coalesce_usecs_irq = 0; |
14893 | ec->tx_coalesce_usecs_irq = 0; | |
14894 | ec->stats_block_coalesce_usecs = 0; | |
14895 | } | |
15f9850d DM |
14896 | } |
14897 | ||
7c7d64b8 SH |
14898 | static const struct net_device_ops tg3_netdev_ops = { |
14899 | .ndo_open = tg3_open, | |
14900 | .ndo_stop = tg3_close, | |
00829823 | 14901 | .ndo_start_xmit = tg3_start_xmit, |
511d2224 | 14902 | .ndo_get_stats64 = tg3_get_stats64, |
00829823 SH |
14903 | .ndo_validate_addr = eth_validate_addr, |
14904 | .ndo_set_multicast_list = tg3_set_rx_mode, | |
14905 | .ndo_set_mac_address = tg3_set_mac_addr, | |
14906 | .ndo_do_ioctl = tg3_ioctl, | |
14907 | .ndo_tx_timeout = tg3_tx_timeout, | |
14908 | .ndo_change_mtu = tg3_change_mtu, | |
dc668910 | 14909 | .ndo_fix_features = tg3_fix_features, |
06c03c02 | 14910 | .ndo_set_features = tg3_set_features, |
00829823 SH |
14911 | #ifdef CONFIG_NET_POLL_CONTROLLER |
14912 | .ndo_poll_controller = tg3_poll_controller, | |
14913 | #endif | |
14914 | }; | |
14915 | ||
1da177e4 LT |
14916 | static int __devinit tg3_init_one(struct pci_dev *pdev, |
14917 | const struct pci_device_id *ent) | |
14918 | { | |
1da177e4 LT |
14919 | struct net_device *dev; |
14920 | struct tg3 *tp; | |
646c9edd MC |
14921 | int i, err, pm_cap; |
14922 | u32 sndmbx, rcvmbx, intmbx; | |
f9804ddb | 14923 | char str[40]; |
72f2afb8 | 14924 | u64 dma_mask, persist_dma_mask; |
dc668910 | 14925 | u32 hw_features = 0; |
1da177e4 | 14926 | |
05dbe005 | 14927 | printk_once(KERN_INFO "%s\n", version); |
1da177e4 LT |
14928 | |
14929 | err = pci_enable_device(pdev); | |
14930 | if (err) { | |
2445e461 | 14931 | dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
1da177e4 LT |
14932 | return err; |
14933 | } | |
14934 | ||
1da177e4 LT |
14935 | err = pci_request_regions(pdev, DRV_MODULE_NAME); |
14936 | if (err) { | |
2445e461 | 14937 | dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
1da177e4 LT |
14938 | goto err_out_disable_pdev; |
14939 | } | |
14940 | ||
14941 | pci_set_master(pdev); | |
14942 | ||
14943 | /* Find power-management capability. */ | |
14944 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); | |
14945 | if (pm_cap == 0) { | |
2445e461 MC |
14946 | dev_err(&pdev->dev, |
14947 | "Cannot find Power Management capability, aborting\n"); | |
1da177e4 LT |
14948 | err = -EIO; |
14949 | goto err_out_free_res; | |
14950 | } | |
14951 | ||
fe5f5787 | 14952 | dev = alloc_etherdev_mq(sizeof(*tp), TG3_IRQ_MAX_VECS); |
1da177e4 | 14953 | if (!dev) { |
2445e461 | 14954 | dev_err(&pdev->dev, "Etherdev alloc failed, aborting\n"); |
1da177e4 LT |
14955 | err = -ENOMEM; |
14956 | goto err_out_free_res; | |
14957 | } | |
14958 | ||
1da177e4 LT |
14959 | SET_NETDEV_DEV(dev, &pdev->dev); |
14960 | ||
1da177e4 | 14961 | dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
1da177e4 LT |
14962 | |
14963 | tp = netdev_priv(dev); | |
14964 | tp->pdev = pdev; | |
14965 | tp->dev = dev; | |
14966 | tp->pm_cap = pm_cap; | |
1da177e4 LT |
14967 | tp->rx_mode = TG3_DEF_RX_MODE; |
14968 | tp->tx_mode = TG3_DEF_TX_MODE; | |
8ef21428 | 14969 | |
1da177e4 LT |
14970 | if (tg3_debug > 0) |
14971 | tp->msg_enable = tg3_debug; | |
14972 | else | |
14973 | tp->msg_enable = TG3_DEF_MSG_ENABLE; | |
14974 | ||
14975 | /* The word/byte swap controls here control register access byte | |
14976 | * swapping. DMA data byte swapping is controlled in the GRC_MODE | |
14977 | * setting below. | |
14978 | */ | |
14979 | tp->misc_host_ctrl = | |
14980 | MISC_HOST_CTRL_MASK_PCI_INT | | |
14981 | MISC_HOST_CTRL_WORD_SWAP | | |
14982 | MISC_HOST_CTRL_INDIR_ACCESS | | |
14983 | MISC_HOST_CTRL_PCISTATE_RW; | |
14984 | ||
14985 | /* The NONFRM (non-frame) byte/word swap controls take effect | |
14986 | * on descriptor entries, anything which isn't packet data. | |
14987 | * | |
14988 | * The StrongARM chips on the board (one for tx, one for rx) | |
14989 | * are running in big-endian mode. | |
14990 | */ | |
14991 | tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA | | |
14992 | GRC_MODE_WSWAP_NONFRM_DATA); | |
14993 | #ifdef __BIG_ENDIAN | |
14994 | tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA; | |
14995 | #endif | |
14996 | spin_lock_init(&tp->lock); | |
1da177e4 | 14997 | spin_lock_init(&tp->indirect_lock); |
c4028958 | 14998 | INIT_WORK(&tp->reset_task, tg3_reset_task); |
1da177e4 | 14999 | |
d5fe488a | 15000 | tp->regs = pci_ioremap_bar(pdev, BAR_0); |
ab0049b4 | 15001 | if (!tp->regs) { |
ab96b241 | 15002 | dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
1da177e4 LT |
15003 | err = -ENOMEM; |
15004 | goto err_out_free_dev; | |
15005 | } | |
15006 | ||
1da177e4 LT |
15007 | tp->rx_pending = TG3_DEF_RX_RING_PENDING; |
15008 | tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING; | |
1da177e4 | 15009 | |
1da177e4 | 15010 | dev->ethtool_ops = &tg3_ethtool_ops; |
1da177e4 | 15011 | dev->watchdog_timeo = TG3_TX_TIMEOUT; |
2ffcc981 | 15012 | dev->netdev_ops = &tg3_netdev_ops; |
1da177e4 | 15013 | dev->irq = pdev->irq; |
1da177e4 LT |
15014 | |
15015 | err = tg3_get_invariants(tp); | |
15016 | if (err) { | |
ab96b241 MC |
15017 | dev_err(&pdev->dev, |
15018 | "Problem fetching invariants of chip, aborting\n"); | |
1da177e4 LT |
15019 | goto err_out_iounmap; |
15020 | } | |
15021 | ||
4a29cc2e MC |
15022 | /* The EPB bridge inside 5714, 5715, and 5780 and any |
15023 | * device behind the EPB cannot support DMA addresses > 40-bit. | |
72f2afb8 MC |
15024 | * On 64-bit systems with IOMMU, use 40-bit dma_mask. |
15025 | * On 64-bit systems without IOMMU, use 64-bit dma_mask and | |
15026 | * do DMA address check in tg3_start_xmit(). | |
15027 | */ | |
63c3a66f | 15028 | if (tg3_flag(tp, IS_5788)) |
284901a9 | 15029 | persist_dma_mask = dma_mask = DMA_BIT_MASK(32); |
63c3a66f | 15030 | else if (tg3_flag(tp, 40BIT_DMA_BUG)) { |
50cf156a | 15031 | persist_dma_mask = dma_mask = DMA_BIT_MASK(40); |
72f2afb8 | 15032 | #ifdef CONFIG_HIGHMEM |
6a35528a | 15033 | dma_mask = DMA_BIT_MASK(64); |
72f2afb8 | 15034 | #endif |
4a29cc2e | 15035 | } else |
6a35528a | 15036 | persist_dma_mask = dma_mask = DMA_BIT_MASK(64); |
72f2afb8 MC |
15037 | |
15038 | /* Configure DMA attributes. */ | |
284901a9 | 15039 | if (dma_mask > DMA_BIT_MASK(32)) { |
72f2afb8 MC |
15040 | err = pci_set_dma_mask(pdev, dma_mask); |
15041 | if (!err) { | |
15042 | dev->features |= NETIF_F_HIGHDMA; | |
15043 | err = pci_set_consistent_dma_mask(pdev, | |
15044 | persist_dma_mask); | |
15045 | if (err < 0) { | |
ab96b241 MC |
15046 | dev_err(&pdev->dev, "Unable to obtain 64 bit " |
15047 | "DMA for consistent allocations\n"); | |
72f2afb8 MC |
15048 | goto err_out_iounmap; |
15049 | } | |
15050 | } | |
15051 | } | |
284901a9 YH |
15052 | if (err || dma_mask == DMA_BIT_MASK(32)) { |
15053 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); | |
72f2afb8 | 15054 | if (err) { |
ab96b241 MC |
15055 | dev_err(&pdev->dev, |
15056 | "No usable DMA configuration, aborting\n"); | |
72f2afb8 MC |
15057 | goto err_out_iounmap; |
15058 | } | |
15059 | } | |
15060 | ||
fdfec172 | 15061 | tg3_init_bufmgr_config(tp); |
1da177e4 | 15062 | |
507399f1 | 15063 | /* Selectively allow TSO based on operating conditions */ |
63c3a66f JP |
15064 | if ((tg3_flag(tp, HW_TSO_1) || |
15065 | tg3_flag(tp, HW_TSO_2) || | |
15066 | tg3_flag(tp, HW_TSO_3)) || | |
15067 | (tp->fw_needed && !tg3_flag(tp, ENABLE_ASF))) | |
15068 | tg3_flag_set(tp, TSO_CAPABLE); | |
507399f1 | 15069 | else { |
63c3a66f JP |
15070 | tg3_flag_clear(tp, TSO_CAPABLE); |
15071 | tg3_flag_clear(tp, TSO_BUG); | |
507399f1 | 15072 | tp->fw_needed = NULL; |
1da177e4 | 15073 | } |
507399f1 MC |
15074 | |
15075 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) | |
15076 | tp->fw_needed = FIRMWARE_TG3; | |
1da177e4 | 15077 | |
4e3a7aaa MC |
15078 | /* TSO is on by default on chips that support hardware TSO. |
15079 | * Firmware TSO on older chips gives lower performance, so it | |
15080 | * is off by default, but can be enabled using ethtool. | |
15081 | */ | |
63c3a66f JP |
15082 | if ((tg3_flag(tp, HW_TSO_1) || |
15083 | tg3_flag(tp, HW_TSO_2) || | |
15084 | tg3_flag(tp, HW_TSO_3)) && | |
dc668910 MM |
15085 | (dev->features & NETIF_F_IP_CSUM)) |
15086 | hw_features |= NETIF_F_TSO; | |
63c3a66f | 15087 | if (tg3_flag(tp, HW_TSO_2) || tg3_flag(tp, HW_TSO_3)) { |
dc668910 MM |
15088 | if (dev->features & NETIF_F_IPV6_CSUM) |
15089 | hw_features |= NETIF_F_TSO6; | |
63c3a66f | 15090 | if (tg3_flag(tp, HW_TSO_3) || |
e849cdc3 | 15091 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
57e6983c MC |
15092 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
15093 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) || | |
63c3a66f | 15094 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
dc668910 MM |
15095 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
15096 | hw_features |= NETIF_F_TSO_ECN; | |
b0026624 | 15097 | } |
1da177e4 | 15098 | |
dc668910 MM |
15099 | dev->hw_features |= hw_features; |
15100 | dev->features |= hw_features; | |
15101 | dev->vlan_features |= hw_features; | |
15102 | ||
06c03c02 MB |
15103 | /* |
15104 | * Add loopback capability only for a subset of devices that support | |
15105 | * MAC-LOOPBACK. Eventually this need to be enhanced to allow INT-PHY | |
15106 | * loopback for the remaining devices. | |
15107 | */ | |
15108 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5780 && | |
15109 | !tg3_flag(tp, CPMU_PRESENT)) | |
15110 | /* Add the loopback capability */ | |
15111 | dev->hw_features |= NETIF_F_LOOPBACK; | |
15112 | ||
1da177e4 | 15113 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 && |
63c3a66f | 15114 | !tg3_flag(tp, TSO_CAPABLE) && |
1da177e4 | 15115 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) { |
63c3a66f | 15116 | tg3_flag_set(tp, MAX_RXPEND_64); |
1da177e4 LT |
15117 | tp->rx_pending = 63; |
15118 | } | |
15119 | ||
1da177e4 LT |
15120 | err = tg3_get_device_address(tp); |
15121 | if (err) { | |
ab96b241 MC |
15122 | dev_err(&pdev->dev, |
15123 | "Could not obtain valid ethernet address, aborting\n"); | |
026a6c21 | 15124 | goto err_out_iounmap; |
1da177e4 LT |
15125 | } |
15126 | ||
63c3a66f | 15127 | if (tg3_flag(tp, ENABLE_APE)) { |
63532394 | 15128 | tp->aperegs = pci_ioremap_bar(pdev, BAR_2); |
79ea13ce | 15129 | if (!tp->aperegs) { |
ab96b241 MC |
15130 | dev_err(&pdev->dev, |
15131 | "Cannot map APE registers, aborting\n"); | |
c88864df | 15132 | err = -ENOMEM; |
026a6c21 | 15133 | goto err_out_iounmap; |
c88864df MC |
15134 | } |
15135 | ||
15136 | tg3_ape_lock_init(tp); | |
7fd76445 | 15137 | |
63c3a66f | 15138 | if (tg3_flag(tp, ENABLE_ASF)) |
7fd76445 | 15139 | tg3_read_dash_ver(tp); |
c88864df MC |
15140 | } |
15141 | ||
1da177e4 LT |
15142 | /* |
15143 | * Reset chip in case UNDI or EFI driver did not shutdown | |
15144 | * DMA self test will enable WDMAC and we'll see (spurious) | |
15145 | * pending DMA on the PCI bus at that point. | |
15146 | */ | |
15147 | if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) || | |
15148 | (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { | |
1da177e4 | 15149 | tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); |
944d980e | 15150 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
1da177e4 LT |
15151 | } |
15152 | ||
15153 | err = tg3_test_dma(tp); | |
15154 | if (err) { | |
ab96b241 | 15155 | dev_err(&pdev->dev, "DMA engine test failed, aborting\n"); |
c88864df | 15156 | goto err_out_apeunmap; |
1da177e4 LT |
15157 | } |
15158 | ||
78f90dcf MC |
15159 | intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW; |
15160 | rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW; | |
15161 | sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW; | |
6fd45cb8 | 15162 | for (i = 0; i < tp->irq_max; i++) { |
78f90dcf MC |
15163 | struct tg3_napi *tnapi = &tp->napi[i]; |
15164 | ||
15165 | tnapi->tp = tp; | |
15166 | tnapi->tx_pending = TG3_DEF_TX_RING_PENDING; | |
15167 | ||
15168 | tnapi->int_mbox = intmbx; | |
15169 | if (i < 4) | |
15170 | intmbx += 0x8; | |
15171 | else | |
15172 | intmbx += 0x4; | |
15173 | ||
15174 | tnapi->consmbox = rcvmbx; | |
15175 | tnapi->prodmbox = sndmbx; | |
15176 | ||
66cfd1bd | 15177 | if (i) |
78f90dcf | 15178 | tnapi->coal_now = HOSTCC_MODE_COAL_VEC1_NOW << (i - 1); |
66cfd1bd | 15179 | else |
78f90dcf | 15180 | tnapi->coal_now = HOSTCC_MODE_NOW; |
78f90dcf | 15181 | |
63c3a66f | 15182 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
78f90dcf MC |
15183 | break; |
15184 | ||
15185 | /* | |
15186 | * If we support MSIX, we'll be using RSS. If we're using | |
15187 | * RSS, the first vector only handles link interrupts and the | |
15188 | * remaining vectors handle rx and tx interrupts. Reuse the | |
15189 | * mailbox values for the next iteration. The values we setup | |
15190 | * above are still useful for the single vectored mode. | |
15191 | */ | |
15192 | if (!i) | |
15193 | continue; | |
15194 | ||
15195 | rcvmbx += 0x8; | |
15196 | ||
15197 | if (sndmbx & 0x4) | |
15198 | sndmbx -= 0x4; | |
15199 | else | |
15200 | sndmbx += 0xc; | |
15201 | } | |
15202 | ||
15f9850d DM |
15203 | tg3_init_coal(tp); |
15204 | ||
c49a1561 MC |
15205 | pci_set_drvdata(pdev, dev); |
15206 | ||
1da177e4 LT |
15207 | err = register_netdev(dev); |
15208 | if (err) { | |
ab96b241 | 15209 | dev_err(&pdev->dev, "Cannot register net device, aborting\n"); |
0d3031d9 | 15210 | goto err_out_apeunmap; |
1da177e4 LT |
15211 | } |
15212 | ||
05dbe005 JP |
15213 | netdev_info(dev, "Tigon3 [partno(%s) rev %04x] (%s) MAC address %pM\n", |
15214 | tp->board_part_number, | |
15215 | tp->pci_chip_rev_id, | |
15216 | tg3_bus_string(tp, str), | |
15217 | dev->dev_addr); | |
1da177e4 | 15218 | |
f07e9af3 | 15219 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
3f0e3ad7 MC |
15220 | struct phy_device *phydev; |
15221 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; | |
5129c3a3 MC |
15222 | netdev_info(dev, |
15223 | "attached PHY driver [%s] (mii_bus:phy_addr=%s)\n", | |
05dbe005 | 15224 | phydev->drv->name, dev_name(&phydev->dev)); |
f07e9af3 MC |
15225 | } else { |
15226 | char *ethtype; | |
15227 | ||
15228 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) | |
15229 | ethtype = "10/100Base-TX"; | |
15230 | else if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) | |
15231 | ethtype = "1000Base-SX"; | |
15232 | else | |
15233 | ethtype = "10/100/1000Base-T"; | |
15234 | ||
5129c3a3 | 15235 | netdev_info(dev, "attached PHY is %s (%s Ethernet) " |
47007831 MC |
15236 | "(WireSpeed[%d], EEE[%d])\n", |
15237 | tg3_phy_string(tp), ethtype, | |
15238 | (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) == 0, | |
15239 | (tp->phy_flags & TG3_PHYFLG_EEE_CAP) != 0); | |
f07e9af3 | 15240 | } |
05dbe005 JP |
15241 | |
15242 | netdev_info(dev, "RXcsums[%d] LinkChgREG[%d] MIirq[%d] ASF[%d] TSOcap[%d]\n", | |
dc668910 | 15243 | (dev->features & NETIF_F_RXCSUM) != 0, |
63c3a66f | 15244 | tg3_flag(tp, USE_LINKCHG_REG) != 0, |
f07e9af3 | 15245 | (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) != 0, |
63c3a66f JP |
15246 | tg3_flag(tp, ENABLE_ASF) != 0, |
15247 | tg3_flag(tp, TSO_CAPABLE) != 0); | |
05dbe005 JP |
15248 | netdev_info(dev, "dma_rwctrl[%08x] dma_mask[%d-bit]\n", |
15249 | tp->dma_rwctrl, | |
15250 | pdev->dma_mask == DMA_BIT_MASK(32) ? 32 : | |
15251 | ((u64)pdev->dma_mask) == DMA_BIT_MASK(40) ? 40 : 64); | |
1da177e4 | 15252 | |
b45aa2f6 MC |
15253 | pci_save_state(pdev); |
15254 | ||
1da177e4 LT |
15255 | return 0; |
15256 | ||
0d3031d9 MC |
15257 | err_out_apeunmap: |
15258 | if (tp->aperegs) { | |
15259 | iounmap(tp->aperegs); | |
15260 | tp->aperegs = NULL; | |
15261 | } | |
15262 | ||
1da177e4 | 15263 | err_out_iounmap: |
6892914f MC |
15264 | if (tp->regs) { |
15265 | iounmap(tp->regs); | |
22abe310 | 15266 | tp->regs = NULL; |
6892914f | 15267 | } |
1da177e4 LT |
15268 | |
15269 | err_out_free_dev: | |
15270 | free_netdev(dev); | |
15271 | ||
15272 | err_out_free_res: | |
15273 | pci_release_regions(pdev); | |
15274 | ||
15275 | err_out_disable_pdev: | |
15276 | pci_disable_device(pdev); | |
15277 | pci_set_drvdata(pdev, NULL); | |
15278 | return err; | |
15279 | } | |
15280 | ||
15281 | static void __devexit tg3_remove_one(struct pci_dev *pdev) | |
15282 | { | |
15283 | struct net_device *dev = pci_get_drvdata(pdev); | |
15284 | ||
15285 | if (dev) { | |
15286 | struct tg3 *tp = netdev_priv(dev); | |
15287 | ||
077f849d JSR |
15288 | if (tp->fw) |
15289 | release_firmware(tp->fw); | |
15290 | ||
23f333a2 | 15291 | cancel_work_sync(&tp->reset_task); |
158d7abd | 15292 | |
63c3a66f | 15293 | if (!tg3_flag(tp, USE_PHYLIB)) { |
b02fd9e3 | 15294 | tg3_phy_fini(tp); |
158d7abd | 15295 | tg3_mdio_fini(tp); |
b02fd9e3 | 15296 | } |
158d7abd | 15297 | |
1da177e4 | 15298 | unregister_netdev(dev); |
0d3031d9 MC |
15299 | if (tp->aperegs) { |
15300 | iounmap(tp->aperegs); | |
15301 | tp->aperegs = NULL; | |
15302 | } | |
6892914f MC |
15303 | if (tp->regs) { |
15304 | iounmap(tp->regs); | |
22abe310 | 15305 | tp->regs = NULL; |
6892914f | 15306 | } |
1da177e4 LT |
15307 | free_netdev(dev); |
15308 | pci_release_regions(pdev); | |
15309 | pci_disable_device(pdev); | |
15310 | pci_set_drvdata(pdev, NULL); | |
15311 | } | |
15312 | } | |
15313 | ||
aa6027ca | 15314 | #ifdef CONFIG_PM_SLEEP |
c866b7ea | 15315 | static int tg3_suspend(struct device *device) |
1da177e4 | 15316 | { |
c866b7ea | 15317 | struct pci_dev *pdev = to_pci_dev(device); |
1da177e4 LT |
15318 | struct net_device *dev = pci_get_drvdata(pdev); |
15319 | struct tg3 *tp = netdev_priv(dev); | |
15320 | int err; | |
15321 | ||
15322 | if (!netif_running(dev)) | |
15323 | return 0; | |
15324 | ||
23f333a2 | 15325 | flush_work_sync(&tp->reset_task); |
b02fd9e3 | 15326 | tg3_phy_stop(tp); |
1da177e4 LT |
15327 | tg3_netif_stop(tp); |
15328 | ||
15329 | del_timer_sync(&tp->timer); | |
15330 | ||
f47c11ee | 15331 | tg3_full_lock(tp, 1); |
1da177e4 | 15332 | tg3_disable_ints(tp); |
f47c11ee | 15333 | tg3_full_unlock(tp); |
1da177e4 LT |
15334 | |
15335 | netif_device_detach(dev); | |
15336 | ||
f47c11ee | 15337 | tg3_full_lock(tp, 0); |
944d980e | 15338 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
63c3a66f | 15339 | tg3_flag_clear(tp, INIT_COMPLETE); |
f47c11ee | 15340 | tg3_full_unlock(tp); |
1da177e4 | 15341 | |
c866b7ea | 15342 | err = tg3_power_down_prepare(tp); |
1da177e4 | 15343 | if (err) { |
b02fd9e3 MC |
15344 | int err2; |
15345 | ||
f47c11ee | 15346 | tg3_full_lock(tp, 0); |
1da177e4 | 15347 | |
63c3a66f | 15348 | tg3_flag_set(tp, INIT_COMPLETE); |
b02fd9e3 MC |
15349 | err2 = tg3_restart_hw(tp, 1); |
15350 | if (err2) | |
b9ec6c1b | 15351 | goto out; |
1da177e4 LT |
15352 | |
15353 | tp->timer.expires = jiffies + tp->timer_offset; | |
15354 | add_timer(&tp->timer); | |
15355 | ||
15356 | netif_device_attach(dev); | |
15357 | tg3_netif_start(tp); | |
15358 | ||
b9ec6c1b | 15359 | out: |
f47c11ee | 15360 | tg3_full_unlock(tp); |
b02fd9e3 MC |
15361 | |
15362 | if (!err2) | |
15363 | tg3_phy_start(tp); | |
1da177e4 LT |
15364 | } |
15365 | ||
15366 | return err; | |
15367 | } | |
15368 | ||
c866b7ea | 15369 | static int tg3_resume(struct device *device) |
1da177e4 | 15370 | { |
c866b7ea | 15371 | struct pci_dev *pdev = to_pci_dev(device); |
1da177e4 LT |
15372 | struct net_device *dev = pci_get_drvdata(pdev); |
15373 | struct tg3 *tp = netdev_priv(dev); | |
15374 | int err; | |
15375 | ||
15376 | if (!netif_running(dev)) | |
15377 | return 0; | |
15378 | ||
1da177e4 LT |
15379 | netif_device_attach(dev); |
15380 | ||
f47c11ee | 15381 | tg3_full_lock(tp, 0); |
1da177e4 | 15382 | |
63c3a66f | 15383 | tg3_flag_set(tp, INIT_COMPLETE); |
b9ec6c1b MC |
15384 | err = tg3_restart_hw(tp, 1); |
15385 | if (err) | |
15386 | goto out; | |
1da177e4 LT |
15387 | |
15388 | tp->timer.expires = jiffies + tp->timer_offset; | |
15389 | add_timer(&tp->timer); | |
15390 | ||
1da177e4 LT |
15391 | tg3_netif_start(tp); |
15392 | ||
b9ec6c1b | 15393 | out: |
f47c11ee | 15394 | tg3_full_unlock(tp); |
1da177e4 | 15395 | |
b02fd9e3 MC |
15396 | if (!err) |
15397 | tg3_phy_start(tp); | |
15398 | ||
b9ec6c1b | 15399 | return err; |
1da177e4 LT |
15400 | } |
15401 | ||
c866b7ea | 15402 | static SIMPLE_DEV_PM_OPS(tg3_pm_ops, tg3_suspend, tg3_resume); |
aa6027ca ED |
15403 | #define TG3_PM_OPS (&tg3_pm_ops) |
15404 | ||
15405 | #else | |
15406 | ||
15407 | #define TG3_PM_OPS NULL | |
15408 | ||
15409 | #endif /* CONFIG_PM_SLEEP */ | |
c866b7ea | 15410 | |
b45aa2f6 MC |
15411 | /** |
15412 | * tg3_io_error_detected - called when PCI error is detected | |
15413 | * @pdev: Pointer to PCI device | |
15414 | * @state: The current pci connection state | |
15415 | * | |
15416 | * This function is called after a PCI bus error affecting | |
15417 | * this device has been detected. | |
15418 | */ | |
15419 | static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev, | |
15420 | pci_channel_state_t state) | |
15421 | { | |
15422 | struct net_device *netdev = pci_get_drvdata(pdev); | |
15423 | struct tg3 *tp = netdev_priv(netdev); | |
15424 | pci_ers_result_t err = PCI_ERS_RESULT_NEED_RESET; | |
15425 | ||
15426 | netdev_info(netdev, "PCI I/O error detected\n"); | |
15427 | ||
15428 | rtnl_lock(); | |
15429 | ||
15430 | if (!netif_running(netdev)) | |
15431 | goto done; | |
15432 | ||
15433 | tg3_phy_stop(tp); | |
15434 | ||
15435 | tg3_netif_stop(tp); | |
15436 | ||
15437 | del_timer_sync(&tp->timer); | |
63c3a66f | 15438 | tg3_flag_clear(tp, RESTART_TIMER); |
b45aa2f6 MC |
15439 | |
15440 | /* Want to make sure that the reset task doesn't run */ | |
15441 | cancel_work_sync(&tp->reset_task); | |
63c3a66f JP |
15442 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
15443 | tg3_flag_clear(tp, RESTART_TIMER); | |
b45aa2f6 MC |
15444 | |
15445 | netif_device_detach(netdev); | |
15446 | ||
15447 | /* Clean up software state, even if MMIO is blocked */ | |
15448 | tg3_full_lock(tp, 0); | |
15449 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); | |
15450 | tg3_full_unlock(tp); | |
15451 | ||
15452 | done: | |
15453 | if (state == pci_channel_io_perm_failure) | |
15454 | err = PCI_ERS_RESULT_DISCONNECT; | |
15455 | else | |
15456 | pci_disable_device(pdev); | |
15457 | ||
15458 | rtnl_unlock(); | |
15459 | ||
15460 | return err; | |
15461 | } | |
15462 | ||
15463 | /** | |
15464 | * tg3_io_slot_reset - called after the pci bus has been reset. | |
15465 | * @pdev: Pointer to PCI device | |
15466 | * | |
15467 | * Restart the card from scratch, as if from a cold-boot. | |
15468 | * At this point, the card has exprienced a hard reset, | |
15469 | * followed by fixups by BIOS, and has its config space | |
15470 | * set up identically to what it was at cold boot. | |
15471 | */ | |
15472 | static pci_ers_result_t tg3_io_slot_reset(struct pci_dev *pdev) | |
15473 | { | |
15474 | struct net_device *netdev = pci_get_drvdata(pdev); | |
15475 | struct tg3 *tp = netdev_priv(netdev); | |
15476 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
15477 | int err; | |
15478 | ||
15479 | rtnl_lock(); | |
15480 | ||
15481 | if (pci_enable_device(pdev)) { | |
15482 | netdev_err(netdev, "Cannot re-enable PCI device after reset.\n"); | |
15483 | goto done; | |
15484 | } | |
15485 | ||
15486 | pci_set_master(pdev); | |
15487 | pci_restore_state(pdev); | |
15488 | pci_save_state(pdev); | |
15489 | ||
15490 | if (!netif_running(netdev)) { | |
15491 | rc = PCI_ERS_RESULT_RECOVERED; | |
15492 | goto done; | |
15493 | } | |
15494 | ||
15495 | err = tg3_power_up(tp); | |
15496 | if (err) { | |
15497 | netdev_err(netdev, "Failed to restore register access.\n"); | |
15498 | goto done; | |
15499 | } | |
15500 | ||
15501 | rc = PCI_ERS_RESULT_RECOVERED; | |
15502 | ||
15503 | done: | |
15504 | rtnl_unlock(); | |
15505 | ||
15506 | return rc; | |
15507 | } | |
15508 | ||
15509 | /** | |
15510 | * tg3_io_resume - called when traffic can start flowing again. | |
15511 | * @pdev: Pointer to PCI device | |
15512 | * | |
15513 | * This callback is called when the error recovery driver tells | |
15514 | * us that its OK to resume normal operation. | |
15515 | */ | |
15516 | static void tg3_io_resume(struct pci_dev *pdev) | |
15517 | { | |
15518 | struct net_device *netdev = pci_get_drvdata(pdev); | |
15519 | struct tg3 *tp = netdev_priv(netdev); | |
15520 | int err; | |
15521 | ||
15522 | rtnl_lock(); | |
15523 | ||
15524 | if (!netif_running(netdev)) | |
15525 | goto done; | |
15526 | ||
15527 | tg3_full_lock(tp, 0); | |
63c3a66f | 15528 | tg3_flag_set(tp, INIT_COMPLETE); |
b45aa2f6 MC |
15529 | err = tg3_restart_hw(tp, 1); |
15530 | tg3_full_unlock(tp); | |
15531 | if (err) { | |
15532 | netdev_err(netdev, "Cannot restart hardware after reset.\n"); | |
15533 | goto done; | |
15534 | } | |
15535 | ||
15536 | netif_device_attach(netdev); | |
15537 | ||
15538 | tp->timer.expires = jiffies + tp->timer_offset; | |
15539 | add_timer(&tp->timer); | |
15540 | ||
15541 | tg3_netif_start(tp); | |
15542 | ||
15543 | tg3_phy_start(tp); | |
15544 | ||
15545 | done: | |
15546 | rtnl_unlock(); | |
15547 | } | |
15548 | ||
15549 | static struct pci_error_handlers tg3_err_handler = { | |
15550 | .error_detected = tg3_io_error_detected, | |
15551 | .slot_reset = tg3_io_slot_reset, | |
15552 | .resume = tg3_io_resume | |
15553 | }; | |
15554 | ||
1da177e4 LT |
15555 | static struct pci_driver tg3_driver = { |
15556 | .name = DRV_MODULE_NAME, | |
15557 | .id_table = tg3_pci_tbl, | |
15558 | .probe = tg3_init_one, | |
15559 | .remove = __devexit_p(tg3_remove_one), | |
b45aa2f6 | 15560 | .err_handler = &tg3_err_handler, |
aa6027ca | 15561 | .driver.pm = TG3_PM_OPS, |
1da177e4 LT |
15562 | }; |
15563 | ||
15564 | static int __init tg3_init(void) | |
15565 | { | |
29917620 | 15566 | return pci_register_driver(&tg3_driver); |
1da177e4 LT |
15567 | } |
15568 | ||
15569 | static void __exit tg3_cleanup(void) | |
15570 | { | |
15571 | pci_unregister_driver(&tg3_driver); | |
15572 | } | |
15573 | ||
15574 | module_init(tg3_init); | |
15575 | module_exit(tg3_cleanup); |