]>
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. | |
ba5b0bfa | 7 | * Copyright (C) 2005-2010 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> | |
35 | #include <linux/mii.h> | |
158d7abd | 36 | #include <linux/phy.h> |
a9daf367 | 37 | #include <linux/brcmphy.h> |
1da177e4 LT |
38 | #include <linux/if_vlan.h> |
39 | #include <linux/ip.h> | |
40 | #include <linux/tcp.h> | |
41 | #include <linux/workqueue.h> | |
61487480 | 42 | #include <linux/prefetch.h> |
f9a5f7d3 | 43 | #include <linux/dma-mapping.h> |
077f849d | 44 | #include <linux/firmware.h> |
1da177e4 LT |
45 | |
46 | #include <net/checksum.h> | |
c9bdd4b5 | 47 | #include <net/ip.h> |
1da177e4 LT |
48 | |
49 | #include <asm/system.h> | |
50 | #include <asm/io.h> | |
51 | #include <asm/byteorder.h> | |
52 | #include <asm/uaccess.h> | |
53 | ||
49b6e95f | 54 | #ifdef CONFIG_SPARC |
1da177e4 | 55 | #include <asm/idprom.h> |
49b6e95f | 56 | #include <asm/prom.h> |
1da177e4 LT |
57 | #endif |
58 | ||
63532394 MC |
59 | #define BAR_0 0 |
60 | #define BAR_2 2 | |
61 | ||
1da177e4 LT |
62 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) |
63 | #define TG3_VLAN_TAG_USED 1 | |
64 | #else | |
65 | #define TG3_VLAN_TAG_USED 0 | |
66 | #endif | |
67 | ||
1da177e4 LT |
68 | #include "tg3.h" |
69 | ||
70 | #define DRV_MODULE_NAME "tg3" | |
6867c843 | 71 | #define TG3_MAJ_NUM 3 |
9ed6eda4 | 72 | #define TG3_MIN_NUM 113 |
6867c843 MC |
73 | #define DRV_MODULE_VERSION \ |
74 | __stringify(TG3_MAJ_NUM) "." __stringify(TG3_MIN_NUM) | |
9ed6eda4 | 75 | #define DRV_MODULE_RELDATE "August 2, 2010" |
1da177e4 LT |
76 | |
77 | #define TG3_DEF_MAC_MODE 0 | |
78 | #define TG3_DEF_RX_MODE 0 | |
79 | #define TG3_DEF_TX_MODE 0 | |
80 | #define TG3_DEF_MSG_ENABLE \ | |
81 | (NETIF_MSG_DRV | \ | |
82 | NETIF_MSG_PROBE | \ | |
83 | NETIF_MSG_LINK | \ | |
84 | NETIF_MSG_TIMER | \ | |
85 | NETIF_MSG_IFDOWN | \ | |
86 | NETIF_MSG_IFUP | \ | |
87 | NETIF_MSG_RX_ERR | \ | |
88 | NETIF_MSG_TX_ERR) | |
89 | ||
90 | /* length of time before we decide the hardware is borked, | |
91 | * and dev->tx_timeout() should be called to fix the problem | |
92 | */ | |
93 | #define TG3_TX_TIMEOUT (5 * HZ) | |
94 | ||
95 | /* hardware minimum and maximum for a single frame's data payload */ | |
96 | #define TG3_MIN_MTU 60 | |
97 | #define TG3_MAX_MTU(tp) \ | |
8f666b07 | 98 | ((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) ? 9000 : 1500) |
1da177e4 LT |
99 | |
100 | /* These numbers seem to be hard coded in the NIC firmware somehow. | |
101 | * You can't change the ring sizes, but you can change where you place | |
102 | * them in the NIC onboard memory. | |
103 | */ | |
104 | #define TG3_RX_RING_SIZE 512 | |
105 | #define TG3_DEF_RX_RING_PENDING 200 | |
106 | #define TG3_RX_JUMBO_RING_SIZE 256 | |
107 | #define TG3_DEF_RX_JUMBO_RING_PENDING 100 | |
c6cdf436 | 108 | #define TG3_RSS_INDIR_TBL_SIZE 128 |
1da177e4 LT |
109 | |
110 | /* Do not place this n-ring entries value into the tp struct itself, | |
111 | * we really want to expose these constants to GCC so that modulo et | |
112 | * al. operations are done with shifts and masks instead of with | |
113 | * hw multiply/modulo instructions. Another solution would be to | |
114 | * replace things like '% foo' with '& (foo - 1)'. | |
115 | */ | |
116 | #define TG3_RX_RCB_RING_SIZE(tp) \ | |
f6eb9b1f | 117 | (((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) && \ |
5ea1c506 | 118 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) ? 1024 : 512) |
1da177e4 LT |
119 | |
120 | #define TG3_TX_RING_SIZE 512 | |
121 | #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1) | |
122 | ||
123 | #define TG3_RX_RING_BYTES (sizeof(struct tg3_rx_buffer_desc) * \ | |
124 | TG3_RX_RING_SIZE) | |
79ed5ac7 MC |
125 | #define TG3_RX_JUMBO_RING_BYTES (sizeof(struct tg3_ext_rx_buffer_desc) * \ |
126 | TG3_RX_JUMBO_RING_SIZE) | |
1da177e4 | 127 | #define TG3_RX_RCB_RING_BYTES(tp) (sizeof(struct tg3_rx_buffer_desc) * \ |
79ed5ac7 | 128 | TG3_RX_RCB_RING_SIZE(tp)) |
1da177e4 LT |
129 | #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ |
130 | TG3_TX_RING_SIZE) | |
1da177e4 LT |
131 | #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) |
132 | ||
9dc7a113 MC |
133 | #define TG3_RX_DMA_ALIGN 16 |
134 | #define TG3_RX_HEADROOM ALIGN(VLAN_HLEN, TG3_RX_DMA_ALIGN) | |
135 | ||
287be12e MC |
136 | #define TG3_DMA_BYTE_ENAB 64 |
137 | ||
138 | #define TG3_RX_STD_DMA_SZ 1536 | |
139 | #define TG3_RX_JMB_DMA_SZ 9046 | |
140 | ||
141 | #define TG3_RX_DMA_TO_MAP_SZ(x) ((x) + TG3_DMA_BYTE_ENAB) | |
142 | ||
143 | #define TG3_RX_STD_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_STD_DMA_SZ) | |
144 | #define TG3_RX_JMB_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_JMB_DMA_SZ) | |
1da177e4 | 145 | |
2b2cdb65 MC |
146 | #define TG3_RX_STD_BUFF_RING_SIZE \ |
147 | (sizeof(struct ring_info) * TG3_RX_RING_SIZE) | |
148 | ||
149 | #define TG3_RX_JMB_BUFF_RING_SIZE \ | |
150 | (sizeof(struct ring_info) * TG3_RX_JUMBO_RING_SIZE) | |
151 | ||
d2757fc4 MC |
152 | /* Due to a hardware bug, the 5701 can only DMA to memory addresses |
153 | * that are at least dword aligned when used in PCIX mode. The driver | |
154 | * works around this bug by double copying the packet. This workaround | |
155 | * is built into the normal double copy length check for efficiency. | |
156 | * | |
157 | * However, the double copy is only necessary on those architectures | |
158 | * where unaligned memory accesses are inefficient. For those architectures | |
159 | * where unaligned memory accesses incur little penalty, we can reintegrate | |
160 | * the 5701 in the normal rx path. Doing so saves a device structure | |
161 | * dereference by hardcoding the double copy threshold in place. | |
162 | */ | |
163 | #define TG3_RX_COPY_THRESHOLD 256 | |
164 | #if NET_IP_ALIGN == 0 || defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) | |
165 | #define TG3_RX_COPY_THRESH(tp) TG3_RX_COPY_THRESHOLD | |
166 | #else | |
167 | #define TG3_RX_COPY_THRESH(tp) ((tp)->rx_copy_thresh) | |
168 | #endif | |
169 | ||
1da177e4 | 170 | /* minimum number of free TX descriptors required to wake up TX process */ |
f3f3f27e | 171 | #define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4) |
1da177e4 | 172 | |
ad829268 MC |
173 | #define TG3_RAW_IP_ALIGN 2 |
174 | ||
1da177e4 LT |
175 | /* number of ETHTOOL_GSTATS u64's */ |
176 | #define TG3_NUM_STATS (sizeof(struct tg3_ethtool_stats)/sizeof(u64)) | |
177 | ||
4cafd3f5 MC |
178 | #define TG3_NUM_TEST 6 |
179 | ||
c6cdf436 MC |
180 | #define TG3_FW_UPDATE_TIMEOUT_SEC 5 |
181 | ||
077f849d JSR |
182 | #define FIRMWARE_TG3 "tigon/tg3.bin" |
183 | #define FIRMWARE_TG3TSO "tigon/tg3_tso.bin" | |
184 | #define FIRMWARE_TG3TSO5 "tigon/tg3_tso5.bin" | |
185 | ||
1da177e4 | 186 | static char version[] __devinitdata = |
05dbe005 | 187 | DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")"; |
1da177e4 LT |
188 | |
189 | MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)"); | |
190 | MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver"); | |
191 | MODULE_LICENSE("GPL"); | |
192 | MODULE_VERSION(DRV_MODULE_VERSION); | |
077f849d JSR |
193 | MODULE_FIRMWARE(FIRMWARE_TG3); |
194 | MODULE_FIRMWARE(FIRMWARE_TG3TSO); | |
195 | MODULE_FIRMWARE(FIRMWARE_TG3TSO5); | |
196 | ||
1da177e4 LT |
197 | static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */ |
198 | module_param(tg3_debug, int, 0); | |
199 | MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value"); | |
200 | ||
a3aa1884 | 201 | static DEFINE_PCI_DEVICE_TABLE(tg3_pci_tbl) = { |
13185217 HK |
202 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)}, |
203 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)}, | |
204 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)}, | |
205 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)}, | |
206 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)}, | |
207 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)}, | |
208 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)}, | |
209 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)}, | |
210 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)}, | |
211 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)}, | |
212 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)}, | |
213 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)}, | |
214 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)}, | |
215 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)}, | |
216 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)}, | |
217 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)}, | |
218 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)}, | |
219 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)}, | |
220 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901)}, | |
221 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2)}, | |
222 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)}, | |
223 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F)}, | |
13185217 | 224 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)}, |
126a3368 | 225 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)}, |
13185217 | 226 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)}, |
13185217 HK |
227 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)}, |
228 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F)}, | |
229 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)}, | |
230 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)}, | |
231 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)}, | |
232 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)}, | |
233 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F)}, | |
234 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)}, | |
235 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)}, | |
236 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)}, | |
237 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)}, | |
126a3368 | 238 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)}, |
13185217 HK |
239 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)}, |
240 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)}, | |
241 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)}, | |
676917d4 | 242 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F)}, |
13185217 HK |
243 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)}, |
244 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)}, | |
245 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)}, | |
246 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)}, | |
247 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)}, | |
248 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)}, | |
249 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)}, | |
b5d3772c MC |
250 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)}, |
251 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)}, | |
d30cdd28 MC |
252 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)}, |
253 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)}, | |
6c7af27c | 254 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)}, |
9936bcf6 MC |
255 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)}, |
256 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)}, | |
c88e668b MC |
257 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761S)}, |
258 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761SE)}, | |
2befdcea MC |
259 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_G)}, |
260 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_F)}, | |
321d32a0 MC |
261 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780)}, |
262 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57760)}, | |
263 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57790)}, | |
5e7ccf20 | 264 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57788)}, |
5001e2f6 MC |
265 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717)}, |
266 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5718)}, | |
267 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5724)}, | |
b0f75221 MC |
268 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57781)}, |
269 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57785)}, | |
270 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57761)}, | |
271 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57765)}, | |
272 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57791)}, | |
273 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57795)}, | |
302b500b | 274 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5719)}, |
13185217 HK |
275 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, |
276 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)}, | |
277 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)}, | |
278 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)}, | |
279 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)}, | |
280 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)}, | |
281 | {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)}, | |
282 | {} | |
1da177e4 LT |
283 | }; |
284 | ||
285 | MODULE_DEVICE_TABLE(pci, tg3_pci_tbl); | |
286 | ||
50da859d | 287 | static const struct { |
1da177e4 LT |
288 | const char string[ETH_GSTRING_LEN]; |
289 | } ethtool_stats_keys[TG3_NUM_STATS] = { | |
290 | { "rx_octets" }, | |
291 | { "rx_fragments" }, | |
292 | { "rx_ucast_packets" }, | |
293 | { "rx_mcast_packets" }, | |
294 | { "rx_bcast_packets" }, | |
295 | { "rx_fcs_errors" }, | |
296 | { "rx_align_errors" }, | |
297 | { "rx_xon_pause_rcvd" }, | |
298 | { "rx_xoff_pause_rcvd" }, | |
299 | { "rx_mac_ctrl_rcvd" }, | |
300 | { "rx_xoff_entered" }, | |
301 | { "rx_frame_too_long_errors" }, | |
302 | { "rx_jabbers" }, | |
303 | { "rx_undersize_packets" }, | |
304 | { "rx_in_length_errors" }, | |
305 | { "rx_out_length_errors" }, | |
306 | { "rx_64_or_less_octet_packets" }, | |
307 | { "rx_65_to_127_octet_packets" }, | |
308 | { "rx_128_to_255_octet_packets" }, | |
309 | { "rx_256_to_511_octet_packets" }, | |
310 | { "rx_512_to_1023_octet_packets" }, | |
311 | { "rx_1024_to_1522_octet_packets" }, | |
312 | { "rx_1523_to_2047_octet_packets" }, | |
313 | { "rx_2048_to_4095_octet_packets" }, | |
314 | { "rx_4096_to_8191_octet_packets" }, | |
315 | { "rx_8192_to_9022_octet_packets" }, | |
316 | ||
317 | { "tx_octets" }, | |
318 | { "tx_collisions" }, | |
319 | ||
320 | { "tx_xon_sent" }, | |
321 | { "tx_xoff_sent" }, | |
322 | { "tx_flow_control" }, | |
323 | { "tx_mac_errors" }, | |
324 | { "tx_single_collisions" }, | |
325 | { "tx_mult_collisions" }, | |
326 | { "tx_deferred" }, | |
327 | { "tx_excessive_collisions" }, | |
328 | { "tx_late_collisions" }, | |
329 | { "tx_collide_2times" }, | |
330 | { "tx_collide_3times" }, | |
331 | { "tx_collide_4times" }, | |
332 | { "tx_collide_5times" }, | |
333 | { "tx_collide_6times" }, | |
334 | { "tx_collide_7times" }, | |
335 | { "tx_collide_8times" }, | |
336 | { "tx_collide_9times" }, | |
337 | { "tx_collide_10times" }, | |
338 | { "tx_collide_11times" }, | |
339 | { "tx_collide_12times" }, | |
340 | { "tx_collide_13times" }, | |
341 | { "tx_collide_14times" }, | |
342 | { "tx_collide_15times" }, | |
343 | { "tx_ucast_packets" }, | |
344 | { "tx_mcast_packets" }, | |
345 | { "tx_bcast_packets" }, | |
346 | { "tx_carrier_sense_errors" }, | |
347 | { "tx_discards" }, | |
348 | { "tx_errors" }, | |
349 | ||
350 | { "dma_writeq_full" }, | |
351 | { "dma_write_prioq_full" }, | |
352 | { "rxbds_empty" }, | |
353 | { "rx_discards" }, | |
354 | { "rx_errors" }, | |
355 | { "rx_threshold_hit" }, | |
356 | ||
357 | { "dma_readq_full" }, | |
358 | { "dma_read_prioq_full" }, | |
359 | { "tx_comp_queue_full" }, | |
360 | ||
361 | { "ring_set_send_prod_index" }, | |
362 | { "ring_status_update" }, | |
363 | { "nic_irqs" }, | |
364 | { "nic_avoided_irqs" }, | |
365 | { "nic_tx_threshold_hit" } | |
366 | }; | |
367 | ||
50da859d | 368 | static const struct { |
4cafd3f5 MC |
369 | const char string[ETH_GSTRING_LEN]; |
370 | } ethtool_test_keys[TG3_NUM_TEST] = { | |
371 | { "nvram test (online) " }, | |
372 | { "link test (online) " }, | |
373 | { "register test (offline)" }, | |
374 | { "memory test (offline)" }, | |
375 | { "loopback test (offline)" }, | |
376 | { "interrupt test (offline)" }, | |
377 | }; | |
378 | ||
b401e9e2 MC |
379 | static void tg3_write32(struct tg3 *tp, u32 off, u32 val) |
380 | { | |
381 | writel(val, tp->regs + off); | |
382 | } | |
383 | ||
384 | static u32 tg3_read32(struct tg3 *tp, u32 off) | |
385 | { | |
de6f31eb | 386 | return readl(tp->regs + off); |
b401e9e2 MC |
387 | } |
388 | ||
0d3031d9 MC |
389 | static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val) |
390 | { | |
391 | writel(val, tp->aperegs + off); | |
392 | } | |
393 | ||
394 | static u32 tg3_ape_read32(struct tg3 *tp, u32 off) | |
395 | { | |
de6f31eb | 396 | return readl(tp->aperegs + off); |
0d3031d9 MC |
397 | } |
398 | ||
1da177e4 LT |
399 | static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val) |
400 | { | |
6892914f MC |
401 | unsigned long flags; |
402 | ||
403 | spin_lock_irqsave(&tp->indirect_lock, flags); | |
1ee582d8 MC |
404 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
405 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); | |
6892914f | 406 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
1ee582d8 MC |
407 | } |
408 | ||
409 | static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val) | |
410 | { | |
411 | writel(val, tp->regs + off); | |
412 | readl(tp->regs + off); | |
1da177e4 LT |
413 | } |
414 | ||
6892914f | 415 | static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off) |
1da177e4 | 416 | { |
6892914f MC |
417 | unsigned long flags; |
418 | u32 val; | |
419 | ||
420 | spin_lock_irqsave(&tp->indirect_lock, flags); | |
421 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); | |
422 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); | |
423 | spin_unlock_irqrestore(&tp->indirect_lock, flags); | |
424 | return val; | |
425 | } | |
426 | ||
427 | static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val) | |
428 | { | |
429 | unsigned long flags; | |
430 | ||
431 | if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) { | |
432 | pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX + | |
433 | TG3_64BIT_REG_LOW, val); | |
434 | return; | |
435 | } | |
66711e66 | 436 | if (off == TG3_RX_STD_PROD_IDX_REG) { |
6892914f MC |
437 | pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX + |
438 | TG3_64BIT_REG_LOW, val); | |
439 | return; | |
1da177e4 | 440 | } |
6892914f MC |
441 | |
442 | spin_lock_irqsave(&tp->indirect_lock, flags); | |
443 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); | |
444 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); | |
445 | spin_unlock_irqrestore(&tp->indirect_lock, flags); | |
446 | ||
447 | /* In indirect mode when disabling interrupts, we also need | |
448 | * to clear the interrupt bit in the GRC local ctrl register. | |
449 | */ | |
450 | if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) && | |
451 | (val == 0x1)) { | |
452 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL, | |
453 | tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT); | |
454 | } | |
455 | } | |
456 | ||
457 | static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off) | |
458 | { | |
459 | unsigned long flags; | |
460 | u32 val; | |
461 | ||
462 | spin_lock_irqsave(&tp->indirect_lock, flags); | |
463 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); | |
464 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); | |
465 | spin_unlock_irqrestore(&tp->indirect_lock, flags); | |
466 | return val; | |
467 | } | |
468 | ||
b401e9e2 MC |
469 | /* usec_wait specifies the wait time in usec when writing to certain registers |
470 | * where it is unsafe to read back the register without some delay. | |
471 | * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power. | |
472 | * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed. | |
473 | */ | |
474 | static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait) | |
6892914f | 475 | { |
b401e9e2 MC |
476 | if ((tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) || |
477 | (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND)) | |
478 | /* Non-posted methods */ | |
479 | tp->write32(tp, off, val); | |
480 | else { | |
481 | /* Posted method */ | |
482 | tg3_write32(tp, off, val); | |
483 | if (usec_wait) | |
484 | udelay(usec_wait); | |
485 | tp->read32(tp, off); | |
486 | } | |
487 | /* Wait again after the read for the posted method to guarantee that | |
488 | * the wait time is met. | |
489 | */ | |
490 | if (usec_wait) | |
491 | udelay(usec_wait); | |
1da177e4 LT |
492 | } |
493 | ||
09ee929c MC |
494 | static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val) |
495 | { | |
496 | tp->write32_mbox(tp, off, val); | |
6892914f MC |
497 | if (!(tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) && |
498 | !(tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND)) | |
499 | tp->read32_mbox(tp, off); | |
09ee929c MC |
500 | } |
501 | ||
20094930 | 502 | static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val) |
1da177e4 LT |
503 | { |
504 | void __iomem *mbox = tp->regs + off; | |
505 | writel(val, mbox); | |
506 | if (tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) | |
507 | writel(val, mbox); | |
508 | if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) | |
509 | readl(mbox); | |
510 | } | |
511 | ||
b5d3772c MC |
512 | static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off) |
513 | { | |
de6f31eb | 514 | return readl(tp->regs + off + GRCMBOX_BASE); |
b5d3772c MC |
515 | } |
516 | ||
517 | static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val) | |
518 | { | |
519 | writel(val, tp->regs + off + GRCMBOX_BASE); | |
520 | } | |
521 | ||
c6cdf436 | 522 | #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val) |
09ee929c | 523 | #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val)) |
c6cdf436 MC |
524 | #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val) |
525 | #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val) | |
526 | #define tr32_mailbox(reg) tp->read32_mbox(tp, reg) | |
20094930 | 527 | |
c6cdf436 MC |
528 | #define tw32(reg, val) tp->write32(tp, reg, val) |
529 | #define tw32_f(reg, val) _tw32_flush(tp, (reg), (val), 0) | |
530 | #define tw32_wait_f(reg, val, us) _tw32_flush(tp, (reg), (val), (us)) | |
531 | #define tr32(reg) tp->read32(tp, reg) | |
1da177e4 LT |
532 | |
533 | static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val) | |
534 | { | |
6892914f MC |
535 | unsigned long flags; |
536 | ||
b5d3772c MC |
537 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) && |
538 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) | |
539 | return; | |
540 | ||
6892914f | 541 | spin_lock_irqsave(&tp->indirect_lock, flags); |
bbadf503 MC |
542 | if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) { |
543 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); | |
544 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); | |
1da177e4 | 545 | |
bbadf503 MC |
546 | /* Always leave this as zero. */ |
547 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
548 | } else { | |
549 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); | |
550 | tw32_f(TG3PCI_MEM_WIN_DATA, val); | |
28fbef78 | 551 | |
bbadf503 MC |
552 | /* Always leave this as zero. */ |
553 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
554 | } | |
555 | spin_unlock_irqrestore(&tp->indirect_lock, flags); | |
758a6139 DM |
556 | } |
557 | ||
1da177e4 LT |
558 | static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val) |
559 | { | |
6892914f MC |
560 | unsigned long flags; |
561 | ||
b5d3772c MC |
562 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) && |
563 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) { | |
564 | *val = 0; | |
565 | return; | |
566 | } | |
567 | ||
6892914f | 568 | spin_lock_irqsave(&tp->indirect_lock, flags); |
bbadf503 MC |
569 | if (tp->tg3_flags & TG3_FLAG_SRAM_USE_CONFIG) { |
570 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); | |
571 | pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); | |
1da177e4 | 572 | |
bbadf503 MC |
573 | /* Always leave this as zero. */ |
574 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
575 | } else { | |
576 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); | |
577 | *val = tr32(TG3PCI_MEM_WIN_DATA); | |
578 | ||
579 | /* Always leave this as zero. */ | |
580 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
581 | } | |
6892914f | 582 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
1da177e4 LT |
583 | } |
584 | ||
0d3031d9 MC |
585 | static void tg3_ape_lock_init(struct tg3 *tp) |
586 | { | |
587 | int i; | |
f92d9dc1 MC |
588 | u32 regbase; |
589 | ||
590 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) | |
591 | regbase = TG3_APE_LOCK_GRANT; | |
592 | else | |
593 | regbase = TG3_APE_PER_LOCK_GRANT; | |
0d3031d9 MC |
594 | |
595 | /* Make sure the driver hasn't any stale locks. */ | |
596 | for (i = 0; i < 8; i++) | |
f92d9dc1 | 597 | tg3_ape_write32(tp, regbase + 4 * i, APE_LOCK_GRANT_DRIVER); |
0d3031d9 MC |
598 | } |
599 | ||
600 | static int tg3_ape_lock(struct tg3 *tp, int locknum) | |
601 | { | |
602 | int i, off; | |
603 | int ret = 0; | |
f92d9dc1 | 604 | u32 status, req, gnt; |
0d3031d9 MC |
605 | |
606 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) | |
607 | return 0; | |
608 | ||
609 | switch (locknum) { | |
33f401ae MC |
610 | case TG3_APE_LOCK_GRC: |
611 | case TG3_APE_LOCK_MEM: | |
612 | break; | |
613 | default: | |
614 | return -EINVAL; | |
0d3031d9 MC |
615 | } |
616 | ||
f92d9dc1 MC |
617 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { |
618 | req = TG3_APE_LOCK_REQ; | |
619 | gnt = TG3_APE_LOCK_GRANT; | |
620 | } else { | |
621 | req = TG3_APE_PER_LOCK_REQ; | |
622 | gnt = TG3_APE_PER_LOCK_GRANT; | |
623 | } | |
624 | ||
0d3031d9 MC |
625 | off = 4 * locknum; |
626 | ||
f92d9dc1 | 627 | tg3_ape_write32(tp, req + off, APE_LOCK_REQ_DRIVER); |
0d3031d9 MC |
628 | |
629 | /* Wait for up to 1 millisecond to acquire lock. */ | |
630 | for (i = 0; i < 100; i++) { | |
f92d9dc1 | 631 | status = tg3_ape_read32(tp, gnt + off); |
0d3031d9 MC |
632 | if (status == APE_LOCK_GRANT_DRIVER) |
633 | break; | |
634 | udelay(10); | |
635 | } | |
636 | ||
637 | if (status != APE_LOCK_GRANT_DRIVER) { | |
638 | /* Revoke the lock request. */ | |
f92d9dc1 | 639 | tg3_ape_write32(tp, gnt + off, |
0d3031d9 MC |
640 | APE_LOCK_GRANT_DRIVER); |
641 | ||
642 | ret = -EBUSY; | |
643 | } | |
644 | ||
645 | return ret; | |
646 | } | |
647 | ||
648 | static void tg3_ape_unlock(struct tg3 *tp, int locknum) | |
649 | { | |
f92d9dc1 | 650 | u32 gnt; |
0d3031d9 MC |
651 | |
652 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) | |
653 | return; | |
654 | ||
655 | switch (locknum) { | |
33f401ae MC |
656 | case TG3_APE_LOCK_GRC: |
657 | case TG3_APE_LOCK_MEM: | |
658 | break; | |
659 | default: | |
660 | return; | |
0d3031d9 MC |
661 | } |
662 | ||
f92d9dc1 MC |
663 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
664 | gnt = TG3_APE_LOCK_GRANT; | |
665 | else | |
666 | gnt = TG3_APE_PER_LOCK_GRANT; | |
667 | ||
668 | tg3_ape_write32(tp, gnt + 4 * locknum, APE_LOCK_GRANT_DRIVER); | |
0d3031d9 MC |
669 | } |
670 | ||
1da177e4 LT |
671 | static void tg3_disable_ints(struct tg3 *tp) |
672 | { | |
89aeb3bc MC |
673 | int i; |
674 | ||
1da177e4 LT |
675 | tw32(TG3PCI_MISC_HOST_CTRL, |
676 | (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT)); | |
89aeb3bc MC |
677 | for (i = 0; i < tp->irq_max; i++) |
678 | tw32_mailbox_f(tp->napi[i].int_mbox, 0x00000001); | |
1da177e4 LT |
679 | } |
680 | ||
1da177e4 LT |
681 | static void tg3_enable_ints(struct tg3 *tp) |
682 | { | |
89aeb3bc | 683 | int i; |
89aeb3bc | 684 | |
bbe832c0 MC |
685 | tp->irq_sync = 0; |
686 | wmb(); | |
687 | ||
1da177e4 LT |
688 | tw32(TG3PCI_MISC_HOST_CTRL, |
689 | (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT)); | |
89aeb3bc | 690 | |
f89f38b8 | 691 | tp->coal_now = tp->coalesce_mode | HOSTCC_MODE_ENABLE; |
89aeb3bc MC |
692 | for (i = 0; i < tp->irq_cnt; i++) { |
693 | struct tg3_napi *tnapi = &tp->napi[i]; | |
c6cdf436 | 694 | |
898a56f8 | 695 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
89aeb3bc MC |
696 | if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) |
697 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); | |
f19af9c2 | 698 | |
f89f38b8 | 699 | tp->coal_now |= tnapi->coal_now; |
89aeb3bc | 700 | } |
f19af9c2 MC |
701 | |
702 | /* Force an initial interrupt */ | |
703 | if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) && | |
704 | (tp->napi[0].hw_status->status & SD_STATUS_UPDATED)) | |
705 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); | |
706 | else | |
f89f38b8 MC |
707 | tw32(HOSTCC_MODE, tp->coal_now); |
708 | ||
709 | tp->coal_now &= ~(tp->napi[0].coal_now | tp->napi[1].coal_now); | |
1da177e4 LT |
710 | } |
711 | ||
17375d25 | 712 | static inline unsigned int tg3_has_work(struct tg3_napi *tnapi) |
04237ddd | 713 | { |
17375d25 | 714 | struct tg3 *tp = tnapi->tp; |
898a56f8 | 715 | struct tg3_hw_status *sblk = tnapi->hw_status; |
04237ddd MC |
716 | unsigned int work_exists = 0; |
717 | ||
718 | /* check for phy events */ | |
719 | if (!(tp->tg3_flags & | |
720 | (TG3_FLAG_USE_LINKCHG_REG | | |
721 | TG3_FLAG_POLL_SERDES))) { | |
722 | if (sblk->status & SD_STATUS_LINK_CHG) | |
723 | work_exists = 1; | |
724 | } | |
725 | /* check for RX/TX work to do */ | |
f3f3f27e | 726 | if (sblk->idx[0].tx_consumer != tnapi->tx_cons || |
8d9d7cfc | 727 | *(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
04237ddd MC |
728 | work_exists = 1; |
729 | ||
730 | return work_exists; | |
731 | } | |
732 | ||
17375d25 | 733 | /* tg3_int_reenable |
04237ddd MC |
734 | * similar to tg3_enable_ints, but it accurately determines whether there |
735 | * is new work pending and can return without flushing the PIO write | |
6aa20a22 | 736 | * which reenables interrupts |
1da177e4 | 737 | */ |
17375d25 | 738 | static void tg3_int_reenable(struct tg3_napi *tnapi) |
1da177e4 | 739 | { |
17375d25 MC |
740 | struct tg3 *tp = tnapi->tp; |
741 | ||
898a56f8 | 742 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
1da177e4 LT |
743 | mmiowb(); |
744 | ||
fac9b83e DM |
745 | /* When doing tagged status, this work check is unnecessary. |
746 | * The last_tag we write above tells the chip which piece of | |
747 | * work we've completed. | |
748 | */ | |
749 | if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) && | |
17375d25 | 750 | tg3_has_work(tnapi)) |
04237ddd | 751 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
fd2ce37f | 752 | HOSTCC_MODE_ENABLE | tnapi->coal_now); |
1da177e4 LT |
753 | } |
754 | ||
fed97810 MC |
755 | static void tg3_napi_disable(struct tg3 *tp) |
756 | { | |
757 | int i; | |
758 | ||
759 | for (i = tp->irq_cnt - 1; i >= 0; i--) | |
760 | napi_disable(&tp->napi[i].napi); | |
761 | } | |
762 | ||
763 | static void tg3_napi_enable(struct tg3 *tp) | |
764 | { | |
765 | int i; | |
766 | ||
767 | for (i = 0; i < tp->irq_cnt; i++) | |
768 | napi_enable(&tp->napi[i].napi); | |
769 | } | |
770 | ||
1da177e4 LT |
771 | static inline void tg3_netif_stop(struct tg3 *tp) |
772 | { | |
bbe832c0 | 773 | tp->dev->trans_start = jiffies; /* prevent tx timeout */ |
fed97810 | 774 | tg3_napi_disable(tp); |
1da177e4 LT |
775 | netif_tx_disable(tp->dev); |
776 | } | |
777 | ||
778 | static inline void tg3_netif_start(struct tg3 *tp) | |
779 | { | |
fe5f5787 MC |
780 | /* NOTE: unconditional netif_tx_wake_all_queues is only |
781 | * appropriate so long as all callers are assured to | |
782 | * have free tx slots (such as after tg3_init_hw) | |
1da177e4 | 783 | */ |
fe5f5787 MC |
784 | netif_tx_wake_all_queues(tp->dev); |
785 | ||
fed97810 MC |
786 | tg3_napi_enable(tp); |
787 | tp->napi[0].hw_status->status |= SD_STATUS_UPDATED; | |
f47c11ee | 788 | tg3_enable_ints(tp); |
1da177e4 LT |
789 | } |
790 | ||
791 | static void tg3_switch_clocks(struct tg3 *tp) | |
792 | { | |
f6eb9b1f | 793 | u32 clock_ctrl; |
1da177e4 LT |
794 | u32 orig_clock_ctrl; |
795 | ||
795d01c5 MC |
796 | if ((tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) || |
797 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) | |
4cf78e4f MC |
798 | return; |
799 | ||
f6eb9b1f MC |
800 | clock_ctrl = tr32(TG3PCI_CLOCK_CTRL); |
801 | ||
1da177e4 LT |
802 | orig_clock_ctrl = clock_ctrl; |
803 | clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN | | |
804 | CLOCK_CTRL_CLKRUN_OENABLE | | |
805 | 0x1f); | |
806 | tp->pci_clock_ctrl = clock_ctrl; | |
807 | ||
808 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { | |
809 | if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) { | |
b401e9e2 MC |
810 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
811 | clock_ctrl | CLOCK_CTRL_625_CORE, 40); | |
1da177e4 LT |
812 | } |
813 | } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) { | |
b401e9e2 MC |
814 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
815 | clock_ctrl | | |
816 | (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK), | |
817 | 40); | |
818 | tw32_wait_f(TG3PCI_CLOCK_CTRL, | |
819 | clock_ctrl | (CLOCK_CTRL_ALTCLK), | |
820 | 40); | |
1da177e4 | 821 | } |
b401e9e2 | 822 | tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40); |
1da177e4 LT |
823 | } |
824 | ||
825 | #define PHY_BUSY_LOOPS 5000 | |
826 | ||
827 | static int tg3_readphy(struct tg3 *tp, int reg, u32 *val) | |
828 | { | |
829 | u32 frame_val; | |
830 | unsigned int loops; | |
831 | int ret; | |
832 | ||
833 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { | |
834 | tw32_f(MAC_MI_MODE, | |
835 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); | |
836 | udelay(80); | |
837 | } | |
838 | ||
839 | *val = 0x0; | |
840 | ||
882e9793 | 841 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
1da177e4 LT |
842 | MI_COM_PHY_ADDR_MASK); |
843 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & | |
844 | MI_COM_REG_ADDR_MASK); | |
845 | frame_val |= (MI_COM_CMD_READ | MI_COM_START); | |
6aa20a22 | 846 | |
1da177e4 LT |
847 | tw32_f(MAC_MI_COM, frame_val); |
848 | ||
849 | loops = PHY_BUSY_LOOPS; | |
850 | while (loops != 0) { | |
851 | udelay(10); | |
852 | frame_val = tr32(MAC_MI_COM); | |
853 | ||
854 | if ((frame_val & MI_COM_BUSY) == 0) { | |
855 | udelay(5); | |
856 | frame_val = tr32(MAC_MI_COM); | |
857 | break; | |
858 | } | |
859 | loops -= 1; | |
860 | } | |
861 | ||
862 | ret = -EBUSY; | |
863 | if (loops != 0) { | |
864 | *val = frame_val & MI_COM_DATA_MASK; | |
865 | ret = 0; | |
866 | } | |
867 | ||
868 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { | |
869 | tw32_f(MAC_MI_MODE, tp->mi_mode); | |
870 | udelay(80); | |
871 | } | |
872 | ||
873 | return ret; | |
874 | } | |
875 | ||
876 | static int tg3_writephy(struct tg3 *tp, int reg, u32 val) | |
877 | { | |
878 | u32 frame_val; | |
879 | unsigned int loops; | |
880 | int ret; | |
881 | ||
f07e9af3 | 882 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
b5d3772c MC |
883 | (reg == MII_TG3_CTRL || reg == MII_TG3_AUX_CTRL)) |
884 | return 0; | |
885 | ||
1da177e4 LT |
886 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
887 | tw32_f(MAC_MI_MODE, | |
888 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); | |
889 | udelay(80); | |
890 | } | |
891 | ||
882e9793 | 892 | frame_val = ((tp->phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
1da177e4 LT |
893 | MI_COM_PHY_ADDR_MASK); |
894 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & | |
895 | MI_COM_REG_ADDR_MASK); | |
896 | frame_val |= (val & MI_COM_DATA_MASK); | |
897 | frame_val |= (MI_COM_CMD_WRITE | MI_COM_START); | |
6aa20a22 | 898 | |
1da177e4 LT |
899 | tw32_f(MAC_MI_COM, frame_val); |
900 | ||
901 | loops = PHY_BUSY_LOOPS; | |
902 | while (loops != 0) { | |
903 | udelay(10); | |
904 | frame_val = tr32(MAC_MI_COM); | |
905 | if ((frame_val & MI_COM_BUSY) == 0) { | |
906 | udelay(5); | |
907 | frame_val = tr32(MAC_MI_COM); | |
908 | break; | |
909 | } | |
910 | loops -= 1; | |
911 | } | |
912 | ||
913 | ret = -EBUSY; | |
914 | if (loops != 0) | |
915 | ret = 0; | |
916 | ||
917 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { | |
918 | tw32_f(MAC_MI_MODE, tp->mi_mode); | |
919 | udelay(80); | |
920 | } | |
921 | ||
922 | return ret; | |
923 | } | |
924 | ||
95e2869a MC |
925 | static int tg3_bmcr_reset(struct tg3 *tp) |
926 | { | |
927 | u32 phy_control; | |
928 | int limit, err; | |
929 | ||
930 | /* OK, reset it, and poll the BMCR_RESET bit until it | |
931 | * clears or we time out. | |
932 | */ | |
933 | phy_control = BMCR_RESET; | |
934 | err = tg3_writephy(tp, MII_BMCR, phy_control); | |
935 | if (err != 0) | |
936 | return -EBUSY; | |
937 | ||
938 | limit = 5000; | |
939 | while (limit--) { | |
940 | err = tg3_readphy(tp, MII_BMCR, &phy_control); | |
941 | if (err != 0) | |
942 | return -EBUSY; | |
943 | ||
944 | if ((phy_control & BMCR_RESET) == 0) { | |
945 | udelay(40); | |
946 | break; | |
947 | } | |
948 | udelay(10); | |
949 | } | |
d4675b52 | 950 | if (limit < 0) |
95e2869a MC |
951 | return -EBUSY; |
952 | ||
953 | return 0; | |
954 | } | |
955 | ||
158d7abd MC |
956 | static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg) |
957 | { | |
3d16543d | 958 | struct tg3 *tp = bp->priv; |
158d7abd MC |
959 | u32 val; |
960 | ||
24bb4fb6 | 961 | spin_lock_bh(&tp->lock); |
158d7abd MC |
962 | |
963 | if (tg3_readphy(tp, reg, &val)) | |
24bb4fb6 MC |
964 | val = -EIO; |
965 | ||
966 | spin_unlock_bh(&tp->lock); | |
158d7abd MC |
967 | |
968 | return val; | |
969 | } | |
970 | ||
971 | static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val) | |
972 | { | |
3d16543d | 973 | struct tg3 *tp = bp->priv; |
24bb4fb6 | 974 | u32 ret = 0; |
158d7abd | 975 | |
24bb4fb6 | 976 | spin_lock_bh(&tp->lock); |
158d7abd MC |
977 | |
978 | if (tg3_writephy(tp, reg, val)) | |
24bb4fb6 | 979 | ret = -EIO; |
158d7abd | 980 | |
24bb4fb6 MC |
981 | spin_unlock_bh(&tp->lock); |
982 | ||
983 | return ret; | |
158d7abd MC |
984 | } |
985 | ||
986 | static int tg3_mdio_reset(struct mii_bus *bp) | |
987 | { | |
988 | return 0; | |
989 | } | |
990 | ||
9c61d6bc | 991 | static void tg3_mdio_config_5785(struct tg3 *tp) |
a9daf367 MC |
992 | { |
993 | u32 val; | |
fcb389df | 994 | struct phy_device *phydev; |
a9daf367 | 995 | |
3f0e3ad7 | 996 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
fcb389df | 997 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
6a443a0f MC |
998 | case PHY_ID_BCM50610: |
999 | case PHY_ID_BCM50610M: | |
fcb389df MC |
1000 | val = MAC_PHYCFG2_50610_LED_MODES; |
1001 | break; | |
6a443a0f | 1002 | case PHY_ID_BCMAC131: |
fcb389df MC |
1003 | val = MAC_PHYCFG2_AC131_LED_MODES; |
1004 | break; | |
6a443a0f | 1005 | case PHY_ID_RTL8211C: |
fcb389df MC |
1006 | val = MAC_PHYCFG2_RTL8211C_LED_MODES; |
1007 | break; | |
6a443a0f | 1008 | case PHY_ID_RTL8201E: |
fcb389df MC |
1009 | val = MAC_PHYCFG2_RTL8201E_LED_MODES; |
1010 | break; | |
1011 | default: | |
a9daf367 | 1012 | return; |
fcb389df MC |
1013 | } |
1014 | ||
1015 | if (phydev->interface != PHY_INTERFACE_MODE_RGMII) { | |
1016 | tw32(MAC_PHYCFG2, val); | |
1017 | ||
1018 | val = tr32(MAC_PHYCFG1); | |
bb85fbb6 MC |
1019 | val &= ~(MAC_PHYCFG1_RGMII_INT | |
1020 | MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK); | |
1021 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT; | |
fcb389df MC |
1022 | tw32(MAC_PHYCFG1, val); |
1023 | ||
1024 | return; | |
1025 | } | |
1026 | ||
14417063 | 1027 | if (!(tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE)) |
fcb389df MC |
1028 | val |= MAC_PHYCFG2_EMODE_MASK_MASK | |
1029 | MAC_PHYCFG2_FMODE_MASK_MASK | | |
1030 | MAC_PHYCFG2_GMODE_MASK_MASK | | |
1031 | MAC_PHYCFG2_ACT_MASK_MASK | | |
1032 | MAC_PHYCFG2_QUAL_MASK_MASK | | |
1033 | MAC_PHYCFG2_INBAND_ENABLE; | |
1034 | ||
1035 | tw32(MAC_PHYCFG2, val); | |
a9daf367 | 1036 | |
bb85fbb6 MC |
1037 | val = tr32(MAC_PHYCFG1); |
1038 | val &= ~(MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK | | |
1039 | MAC_PHYCFG1_RGMII_EXT_RX_DEC | MAC_PHYCFG1_RGMII_SND_STAT_EN); | |
14417063 | 1040 | if (!(tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE)) { |
a9daf367 MC |
1041 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_RX_EN) |
1042 | val |= MAC_PHYCFG1_RGMII_EXT_RX_DEC; | |
1043 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_TX_EN) | |
1044 | val |= MAC_PHYCFG1_RGMII_SND_STAT_EN; | |
1045 | } | |
bb85fbb6 MC |
1046 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT | |
1047 | MAC_PHYCFG1_RGMII_INT | MAC_PHYCFG1_TXC_DRV; | |
1048 | tw32(MAC_PHYCFG1, val); | |
a9daf367 | 1049 | |
a9daf367 MC |
1050 | val = tr32(MAC_EXT_RGMII_MODE); |
1051 | val &= ~(MAC_RGMII_MODE_RX_INT_B | | |
1052 | MAC_RGMII_MODE_RX_QUALITY | | |
1053 | MAC_RGMII_MODE_RX_ACTIVITY | | |
1054 | MAC_RGMII_MODE_RX_ENG_DET | | |
1055 | MAC_RGMII_MODE_TX_ENABLE | | |
1056 | MAC_RGMII_MODE_TX_LOWPWR | | |
1057 | MAC_RGMII_MODE_TX_RESET); | |
14417063 | 1058 | if (!(tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE)) { |
a9daf367 MC |
1059 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_RX_EN) |
1060 | val |= MAC_RGMII_MODE_RX_INT_B | | |
1061 | MAC_RGMII_MODE_RX_QUALITY | | |
1062 | MAC_RGMII_MODE_RX_ACTIVITY | | |
1063 | MAC_RGMII_MODE_RX_ENG_DET; | |
1064 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_TX_EN) | |
1065 | val |= MAC_RGMII_MODE_TX_ENABLE | | |
1066 | MAC_RGMII_MODE_TX_LOWPWR | | |
1067 | MAC_RGMII_MODE_TX_RESET; | |
1068 | } | |
1069 | tw32(MAC_EXT_RGMII_MODE, val); | |
1070 | } | |
1071 | ||
158d7abd MC |
1072 | static void tg3_mdio_start(struct tg3 *tp) |
1073 | { | |
158d7abd MC |
1074 | tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; |
1075 | tw32_f(MAC_MI_MODE, tp->mi_mode); | |
1076 | udelay(80); | |
a9daf367 | 1077 | |
9ea4818d MC |
1078 | if ((tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) && |
1079 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) | |
1080 | tg3_mdio_config_5785(tp); | |
1081 | } | |
1082 | ||
1083 | static int tg3_mdio_init(struct tg3 *tp) | |
1084 | { | |
1085 | int i; | |
1086 | u32 reg; | |
1087 | struct phy_device *phydev; | |
1088 | ||
a50d0796 MC |
1089 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
1090 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) { | |
9c7df915 | 1091 | u32 is_serdes; |
882e9793 | 1092 | |
9c7df915 | 1093 | tp->phy_addr = PCI_FUNC(tp->pdev->devfn) + 1; |
882e9793 | 1094 | |
d1ec96af MC |
1095 | if (tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) |
1096 | is_serdes = tr32(SG_DIG_STATUS) & SG_DIG_IS_SERDES; | |
1097 | else | |
1098 | is_serdes = tr32(TG3_CPMU_PHY_STRAP) & | |
1099 | TG3_CPMU_PHY_STRAP_IS_SERDES; | |
882e9793 MC |
1100 | if (is_serdes) |
1101 | tp->phy_addr += 7; | |
1102 | } else | |
3f0e3ad7 | 1103 | tp->phy_addr = TG3_PHY_MII_ADDR; |
882e9793 | 1104 | |
158d7abd MC |
1105 | tg3_mdio_start(tp); |
1106 | ||
1107 | if (!(tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) || | |
1108 | (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED)) | |
1109 | return 0; | |
1110 | ||
298cf9be LB |
1111 | tp->mdio_bus = mdiobus_alloc(); |
1112 | if (tp->mdio_bus == NULL) | |
1113 | return -ENOMEM; | |
158d7abd | 1114 | |
298cf9be LB |
1115 | tp->mdio_bus->name = "tg3 mdio bus"; |
1116 | snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x", | |
158d7abd | 1117 | (tp->pdev->bus->number << 8) | tp->pdev->devfn); |
298cf9be LB |
1118 | tp->mdio_bus->priv = tp; |
1119 | tp->mdio_bus->parent = &tp->pdev->dev; | |
1120 | tp->mdio_bus->read = &tg3_mdio_read; | |
1121 | tp->mdio_bus->write = &tg3_mdio_write; | |
1122 | tp->mdio_bus->reset = &tg3_mdio_reset; | |
3f0e3ad7 | 1123 | tp->mdio_bus->phy_mask = ~(1 << TG3_PHY_MII_ADDR); |
298cf9be | 1124 | tp->mdio_bus->irq = &tp->mdio_irq[0]; |
158d7abd MC |
1125 | |
1126 | for (i = 0; i < PHY_MAX_ADDR; i++) | |
298cf9be | 1127 | tp->mdio_bus->irq[i] = PHY_POLL; |
158d7abd MC |
1128 | |
1129 | /* The bus registration will look for all the PHYs on the mdio bus. | |
1130 | * Unfortunately, it does not ensure the PHY is powered up before | |
1131 | * accessing the PHY ID registers. A chip reset is the | |
1132 | * quickest way to bring the device back to an operational state.. | |
1133 | */ | |
1134 | if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN)) | |
1135 | tg3_bmcr_reset(tp); | |
1136 | ||
298cf9be | 1137 | i = mdiobus_register(tp->mdio_bus); |
a9daf367 | 1138 | if (i) { |
ab96b241 | 1139 | dev_warn(&tp->pdev->dev, "mdiobus_reg failed (0x%x)\n", i); |
9c61d6bc | 1140 | mdiobus_free(tp->mdio_bus); |
a9daf367 MC |
1141 | return i; |
1142 | } | |
158d7abd | 1143 | |
3f0e3ad7 | 1144 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
a9daf367 | 1145 | |
9c61d6bc | 1146 | if (!phydev || !phydev->drv) { |
ab96b241 | 1147 | dev_warn(&tp->pdev->dev, "No PHY devices\n"); |
9c61d6bc MC |
1148 | mdiobus_unregister(tp->mdio_bus); |
1149 | mdiobus_free(tp->mdio_bus); | |
1150 | return -ENODEV; | |
1151 | } | |
1152 | ||
1153 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { | |
6a443a0f | 1154 | case PHY_ID_BCM57780: |
321d32a0 | 1155 | phydev->interface = PHY_INTERFACE_MODE_GMII; |
c704dc23 | 1156 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
321d32a0 | 1157 | break; |
6a443a0f MC |
1158 | case PHY_ID_BCM50610: |
1159 | case PHY_ID_BCM50610M: | |
32e5a8d6 | 1160 | phydev->dev_flags |= PHY_BRCM_CLEAR_RGMII_MODE | |
c704dc23 | 1161 | PHY_BRCM_RX_REFCLK_UNUSED | |
52fae083 | 1162 | PHY_BRCM_DIS_TXCRXC_NOENRGY | |
c704dc23 | 1163 | PHY_BRCM_AUTO_PWRDWN_ENABLE; |
14417063 | 1164 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_INBAND_DISABLE) |
a9daf367 MC |
1165 | phydev->dev_flags |= PHY_BRCM_STD_IBND_DISABLE; |
1166 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_RX_EN) | |
1167 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_RX_ENABLE; | |
1168 | if (tp->tg3_flags3 & TG3_FLG3_RGMII_EXT_IBND_TX_EN) | |
1169 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_TX_ENABLE; | |
fcb389df | 1170 | /* fallthru */ |
6a443a0f | 1171 | case PHY_ID_RTL8211C: |
fcb389df | 1172 | phydev->interface = PHY_INTERFACE_MODE_RGMII; |
a9daf367 | 1173 | break; |
6a443a0f MC |
1174 | case PHY_ID_RTL8201E: |
1175 | case PHY_ID_BCMAC131: | |
a9daf367 | 1176 | phydev->interface = PHY_INTERFACE_MODE_MII; |
cdd4e09d | 1177 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
f07e9af3 | 1178 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
a9daf367 MC |
1179 | break; |
1180 | } | |
1181 | ||
9c61d6bc MC |
1182 | tp->tg3_flags3 |= TG3_FLG3_MDIOBUS_INITED; |
1183 | ||
1184 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) | |
1185 | tg3_mdio_config_5785(tp); | |
a9daf367 MC |
1186 | |
1187 | return 0; | |
158d7abd MC |
1188 | } |
1189 | ||
1190 | static void tg3_mdio_fini(struct tg3 *tp) | |
1191 | { | |
1192 | if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) { | |
1193 | tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_INITED; | |
298cf9be LB |
1194 | mdiobus_unregister(tp->mdio_bus); |
1195 | mdiobus_free(tp->mdio_bus); | |
158d7abd MC |
1196 | } |
1197 | } | |
1198 | ||
4ba526ce MC |
1199 | /* tp->lock is held. */ |
1200 | static inline void tg3_generate_fw_event(struct tg3 *tp) | |
1201 | { | |
1202 | u32 val; | |
1203 | ||
1204 | val = tr32(GRC_RX_CPU_EVENT); | |
1205 | val |= GRC_RX_CPU_DRIVER_EVENT; | |
1206 | tw32_f(GRC_RX_CPU_EVENT, val); | |
1207 | ||
1208 | tp->last_event_jiffies = jiffies; | |
1209 | } | |
1210 | ||
1211 | #define TG3_FW_EVENT_TIMEOUT_USEC 2500 | |
1212 | ||
95e2869a MC |
1213 | /* tp->lock is held. */ |
1214 | static void tg3_wait_for_event_ack(struct tg3 *tp) | |
1215 | { | |
1216 | int i; | |
4ba526ce MC |
1217 | unsigned int delay_cnt; |
1218 | long time_remain; | |
1219 | ||
1220 | /* If enough time has passed, no wait is necessary. */ | |
1221 | time_remain = (long)(tp->last_event_jiffies + 1 + | |
1222 | usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC)) - | |
1223 | (long)jiffies; | |
1224 | if (time_remain < 0) | |
1225 | return; | |
1226 | ||
1227 | /* Check if we can shorten the wait time. */ | |
1228 | delay_cnt = jiffies_to_usecs(time_remain); | |
1229 | if (delay_cnt > TG3_FW_EVENT_TIMEOUT_USEC) | |
1230 | delay_cnt = TG3_FW_EVENT_TIMEOUT_USEC; | |
1231 | delay_cnt = (delay_cnt >> 3) + 1; | |
95e2869a | 1232 | |
4ba526ce | 1233 | for (i = 0; i < delay_cnt; i++) { |
95e2869a MC |
1234 | if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT)) |
1235 | break; | |
4ba526ce | 1236 | udelay(8); |
95e2869a MC |
1237 | } |
1238 | } | |
1239 | ||
1240 | /* tp->lock is held. */ | |
1241 | static void tg3_ump_link_report(struct tg3 *tp) | |
1242 | { | |
1243 | u32 reg; | |
1244 | u32 val; | |
1245 | ||
1246 | if (!(tp->tg3_flags2 & TG3_FLG2_5780_CLASS) || | |
1247 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) | |
1248 | return; | |
1249 | ||
1250 | tg3_wait_for_event_ack(tp); | |
1251 | ||
1252 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE); | |
1253 | ||
1254 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14); | |
1255 | ||
1256 | val = 0; | |
1257 | if (!tg3_readphy(tp, MII_BMCR, ®)) | |
1258 | val = reg << 16; | |
1259 | if (!tg3_readphy(tp, MII_BMSR, ®)) | |
1260 | val |= (reg & 0xffff); | |
1261 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, val); | |
1262 | ||
1263 | val = 0; | |
1264 | if (!tg3_readphy(tp, MII_ADVERTISE, ®)) | |
1265 | val = reg << 16; | |
1266 | if (!tg3_readphy(tp, MII_LPA, ®)) | |
1267 | val |= (reg & 0xffff); | |
1268 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 4, val); | |
1269 | ||
1270 | val = 0; | |
f07e9af3 | 1271 | if (!(tp->phy_flags & TG3_PHYFLG_MII_SERDES)) { |
95e2869a MC |
1272 | if (!tg3_readphy(tp, MII_CTRL1000, ®)) |
1273 | val = reg << 16; | |
1274 | if (!tg3_readphy(tp, MII_STAT1000, ®)) | |
1275 | val |= (reg & 0xffff); | |
1276 | } | |
1277 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 8, val); | |
1278 | ||
1279 | if (!tg3_readphy(tp, MII_PHYADDR, ®)) | |
1280 | val = reg << 16; | |
1281 | else | |
1282 | val = 0; | |
1283 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 12, val); | |
1284 | ||
4ba526ce | 1285 | tg3_generate_fw_event(tp); |
95e2869a MC |
1286 | } |
1287 | ||
1288 | static void tg3_link_report(struct tg3 *tp) | |
1289 | { | |
1290 | if (!netif_carrier_ok(tp->dev)) { | |
05dbe005 | 1291 | netif_info(tp, link, tp->dev, "Link is down\n"); |
95e2869a MC |
1292 | tg3_ump_link_report(tp); |
1293 | } else if (netif_msg_link(tp)) { | |
05dbe005 JP |
1294 | netdev_info(tp->dev, "Link is up at %d Mbps, %s duplex\n", |
1295 | (tp->link_config.active_speed == SPEED_1000 ? | |
1296 | 1000 : | |
1297 | (tp->link_config.active_speed == SPEED_100 ? | |
1298 | 100 : 10)), | |
1299 | (tp->link_config.active_duplex == DUPLEX_FULL ? | |
1300 | "full" : "half")); | |
1301 | ||
1302 | netdev_info(tp->dev, "Flow control is %s for TX and %s for RX\n", | |
1303 | (tp->link_config.active_flowctrl & FLOW_CTRL_TX) ? | |
1304 | "on" : "off", | |
1305 | (tp->link_config.active_flowctrl & FLOW_CTRL_RX) ? | |
1306 | "on" : "off"); | |
95e2869a MC |
1307 | tg3_ump_link_report(tp); |
1308 | } | |
1309 | } | |
1310 | ||
1311 | static u16 tg3_advert_flowctrl_1000T(u8 flow_ctrl) | |
1312 | { | |
1313 | u16 miireg; | |
1314 | ||
e18ce346 | 1315 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
95e2869a | 1316 | miireg = ADVERTISE_PAUSE_CAP; |
e18ce346 | 1317 | else if (flow_ctrl & FLOW_CTRL_TX) |
95e2869a | 1318 | miireg = ADVERTISE_PAUSE_ASYM; |
e18ce346 | 1319 | else if (flow_ctrl & FLOW_CTRL_RX) |
95e2869a MC |
1320 | miireg = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
1321 | else | |
1322 | miireg = 0; | |
1323 | ||
1324 | return miireg; | |
1325 | } | |
1326 | ||
1327 | static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl) | |
1328 | { | |
1329 | u16 miireg; | |
1330 | ||
e18ce346 | 1331 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
95e2869a | 1332 | miireg = ADVERTISE_1000XPAUSE; |
e18ce346 | 1333 | else if (flow_ctrl & FLOW_CTRL_TX) |
95e2869a | 1334 | miireg = ADVERTISE_1000XPSE_ASYM; |
e18ce346 | 1335 | else if (flow_ctrl & FLOW_CTRL_RX) |
95e2869a MC |
1336 | miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM; |
1337 | else | |
1338 | miireg = 0; | |
1339 | ||
1340 | return miireg; | |
1341 | } | |
1342 | ||
95e2869a MC |
1343 | static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv) |
1344 | { | |
1345 | u8 cap = 0; | |
1346 | ||
1347 | if (lcladv & ADVERTISE_1000XPAUSE) { | |
1348 | if (lcladv & ADVERTISE_1000XPSE_ASYM) { | |
1349 | if (rmtadv & LPA_1000XPAUSE) | |
e18ce346 | 1350 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
95e2869a | 1351 | else if (rmtadv & LPA_1000XPAUSE_ASYM) |
e18ce346 | 1352 | cap = FLOW_CTRL_RX; |
95e2869a MC |
1353 | } else { |
1354 | if (rmtadv & LPA_1000XPAUSE) | |
e18ce346 | 1355 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; |
95e2869a MC |
1356 | } |
1357 | } else if (lcladv & ADVERTISE_1000XPSE_ASYM) { | |
1358 | if ((rmtadv & LPA_1000XPAUSE) && (rmtadv & LPA_1000XPAUSE_ASYM)) | |
e18ce346 | 1359 | cap = FLOW_CTRL_TX; |
95e2869a MC |
1360 | } |
1361 | ||
1362 | return cap; | |
1363 | } | |
1364 | ||
f51f3562 | 1365 | static void tg3_setup_flow_control(struct tg3 *tp, u32 lcladv, u32 rmtadv) |
95e2869a | 1366 | { |
b02fd9e3 | 1367 | u8 autoneg; |
f51f3562 | 1368 | u8 flowctrl = 0; |
95e2869a MC |
1369 | u32 old_rx_mode = tp->rx_mode; |
1370 | u32 old_tx_mode = tp->tx_mode; | |
1371 | ||
b02fd9e3 | 1372 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) |
3f0e3ad7 | 1373 | autoneg = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]->autoneg; |
b02fd9e3 MC |
1374 | else |
1375 | autoneg = tp->link_config.autoneg; | |
1376 | ||
1377 | if (autoneg == AUTONEG_ENABLE && | |
95e2869a | 1378 | (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG)) { |
f07e9af3 | 1379 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
f51f3562 | 1380 | flowctrl = tg3_resolve_flowctrl_1000X(lcladv, rmtadv); |
95e2869a | 1381 | else |
bc02ff95 | 1382 | flowctrl = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
f51f3562 MC |
1383 | } else |
1384 | flowctrl = tp->link_config.flowctrl; | |
95e2869a | 1385 | |
f51f3562 | 1386 | tp->link_config.active_flowctrl = flowctrl; |
95e2869a | 1387 | |
e18ce346 | 1388 | if (flowctrl & FLOW_CTRL_RX) |
95e2869a MC |
1389 | tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE; |
1390 | else | |
1391 | tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE; | |
1392 | ||
f51f3562 | 1393 | if (old_rx_mode != tp->rx_mode) |
95e2869a | 1394 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
95e2869a | 1395 | |
e18ce346 | 1396 | if (flowctrl & FLOW_CTRL_TX) |
95e2869a MC |
1397 | tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE; |
1398 | else | |
1399 | tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE; | |
1400 | ||
f51f3562 | 1401 | if (old_tx_mode != tp->tx_mode) |
95e2869a | 1402 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
95e2869a MC |
1403 | } |
1404 | ||
b02fd9e3 MC |
1405 | static void tg3_adjust_link(struct net_device *dev) |
1406 | { | |
1407 | u8 oldflowctrl, linkmesg = 0; | |
1408 | u32 mac_mode, lcl_adv, rmt_adv; | |
1409 | struct tg3 *tp = netdev_priv(dev); | |
3f0e3ad7 | 1410 | struct phy_device *phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
b02fd9e3 | 1411 | |
24bb4fb6 | 1412 | spin_lock_bh(&tp->lock); |
b02fd9e3 MC |
1413 | |
1414 | mac_mode = tp->mac_mode & ~(MAC_MODE_PORT_MODE_MASK | | |
1415 | MAC_MODE_HALF_DUPLEX); | |
1416 | ||
1417 | oldflowctrl = tp->link_config.active_flowctrl; | |
1418 | ||
1419 | if (phydev->link) { | |
1420 | lcl_adv = 0; | |
1421 | rmt_adv = 0; | |
1422 | ||
1423 | if (phydev->speed == SPEED_100 || phydev->speed == SPEED_10) | |
1424 | mac_mode |= MAC_MODE_PORT_MODE_MII; | |
c3df0748 MC |
1425 | else if (phydev->speed == SPEED_1000 || |
1426 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) | |
b02fd9e3 | 1427 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
c3df0748 MC |
1428 | else |
1429 | mac_mode |= MAC_MODE_PORT_MODE_MII; | |
b02fd9e3 MC |
1430 | |
1431 | if (phydev->duplex == DUPLEX_HALF) | |
1432 | mac_mode |= MAC_MODE_HALF_DUPLEX; | |
1433 | else { | |
1434 | lcl_adv = tg3_advert_flowctrl_1000T( | |
1435 | tp->link_config.flowctrl); | |
1436 | ||
1437 | if (phydev->pause) | |
1438 | rmt_adv = LPA_PAUSE_CAP; | |
1439 | if (phydev->asym_pause) | |
1440 | rmt_adv |= LPA_PAUSE_ASYM; | |
1441 | } | |
1442 | ||
1443 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); | |
1444 | } else | |
1445 | mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
1446 | ||
1447 | if (mac_mode != tp->mac_mode) { | |
1448 | tp->mac_mode = mac_mode; | |
1449 | tw32_f(MAC_MODE, tp->mac_mode); | |
1450 | udelay(40); | |
1451 | } | |
1452 | ||
fcb389df MC |
1453 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
1454 | if (phydev->speed == SPEED_10) | |
1455 | tw32(MAC_MI_STAT, | |
1456 | MAC_MI_STAT_10MBPS_MODE | | |
1457 | MAC_MI_STAT_LNKSTAT_ATTN_ENAB); | |
1458 | else | |
1459 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); | |
1460 | } | |
1461 | ||
b02fd9e3 MC |
1462 | if (phydev->speed == SPEED_1000 && phydev->duplex == DUPLEX_HALF) |
1463 | tw32(MAC_TX_LENGTHS, | |
1464 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | | |
1465 | (6 << TX_LENGTHS_IPG_SHIFT) | | |
1466 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); | |
1467 | else | |
1468 | tw32(MAC_TX_LENGTHS, | |
1469 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | | |
1470 | (6 << TX_LENGTHS_IPG_SHIFT) | | |
1471 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); | |
1472 | ||
1473 | if ((phydev->link && tp->link_config.active_speed == SPEED_INVALID) || | |
1474 | (!phydev->link && tp->link_config.active_speed != SPEED_INVALID) || | |
1475 | phydev->speed != tp->link_config.active_speed || | |
1476 | phydev->duplex != tp->link_config.active_duplex || | |
1477 | oldflowctrl != tp->link_config.active_flowctrl) | |
c6cdf436 | 1478 | linkmesg = 1; |
b02fd9e3 MC |
1479 | |
1480 | tp->link_config.active_speed = phydev->speed; | |
1481 | tp->link_config.active_duplex = phydev->duplex; | |
1482 | ||
24bb4fb6 | 1483 | spin_unlock_bh(&tp->lock); |
b02fd9e3 MC |
1484 | |
1485 | if (linkmesg) | |
1486 | tg3_link_report(tp); | |
1487 | } | |
1488 | ||
1489 | static int tg3_phy_init(struct tg3 *tp) | |
1490 | { | |
1491 | struct phy_device *phydev; | |
1492 | ||
f07e9af3 | 1493 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) |
b02fd9e3 MC |
1494 | return 0; |
1495 | ||
1496 | /* Bring the PHY back to a known state. */ | |
1497 | tg3_bmcr_reset(tp); | |
1498 | ||
3f0e3ad7 | 1499 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
b02fd9e3 MC |
1500 | |
1501 | /* Attach the MAC to the PHY. */ | |
fb28ad35 | 1502 | phydev = phy_connect(tp->dev, dev_name(&phydev->dev), tg3_adjust_link, |
a9daf367 | 1503 | phydev->dev_flags, phydev->interface); |
b02fd9e3 | 1504 | if (IS_ERR(phydev)) { |
ab96b241 | 1505 | dev_err(&tp->pdev->dev, "Could not attach to PHY\n"); |
b02fd9e3 MC |
1506 | return PTR_ERR(phydev); |
1507 | } | |
1508 | ||
b02fd9e3 | 1509 | /* Mask with MAC supported features. */ |
9c61d6bc MC |
1510 | switch (phydev->interface) { |
1511 | case PHY_INTERFACE_MODE_GMII: | |
1512 | case PHY_INTERFACE_MODE_RGMII: | |
f07e9af3 | 1513 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
321d32a0 MC |
1514 | phydev->supported &= (PHY_GBIT_FEATURES | |
1515 | SUPPORTED_Pause | | |
1516 | SUPPORTED_Asym_Pause); | |
1517 | break; | |
1518 | } | |
1519 | /* fallthru */ | |
9c61d6bc MC |
1520 | case PHY_INTERFACE_MODE_MII: |
1521 | phydev->supported &= (PHY_BASIC_FEATURES | | |
1522 | SUPPORTED_Pause | | |
1523 | SUPPORTED_Asym_Pause); | |
1524 | break; | |
1525 | default: | |
3f0e3ad7 | 1526 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
9c61d6bc MC |
1527 | return -EINVAL; |
1528 | } | |
1529 | ||
f07e9af3 | 1530 | tp->phy_flags |= TG3_PHYFLG_IS_CONNECTED; |
b02fd9e3 MC |
1531 | |
1532 | phydev->advertising = phydev->supported; | |
1533 | ||
b02fd9e3 MC |
1534 | return 0; |
1535 | } | |
1536 | ||
1537 | static void tg3_phy_start(struct tg3 *tp) | |
1538 | { | |
1539 | struct phy_device *phydev; | |
1540 | ||
f07e9af3 | 1541 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 MC |
1542 | return; |
1543 | ||
3f0e3ad7 | 1544 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
b02fd9e3 | 1545 | |
80096068 MC |
1546 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
1547 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; | |
b02fd9e3 MC |
1548 | phydev->speed = tp->link_config.orig_speed; |
1549 | phydev->duplex = tp->link_config.orig_duplex; | |
1550 | phydev->autoneg = tp->link_config.orig_autoneg; | |
1551 | phydev->advertising = tp->link_config.orig_advertising; | |
1552 | } | |
1553 | ||
1554 | phy_start(phydev); | |
1555 | ||
1556 | phy_start_aneg(phydev); | |
1557 | } | |
1558 | ||
1559 | static void tg3_phy_stop(struct tg3 *tp) | |
1560 | { | |
f07e9af3 | 1561 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 MC |
1562 | return; |
1563 | ||
3f0e3ad7 | 1564 | phy_stop(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
b02fd9e3 MC |
1565 | } |
1566 | ||
1567 | static void tg3_phy_fini(struct tg3 *tp) | |
1568 | { | |
f07e9af3 | 1569 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
3f0e3ad7 | 1570 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
f07e9af3 | 1571 | tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED; |
b02fd9e3 MC |
1572 | } |
1573 | } | |
1574 | ||
6ee7c0a0 | 1575 | static int tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val) |
b2a5c19c | 1576 | { |
6ee7c0a0 MC |
1577 | int err; |
1578 | ||
1579 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); | |
1580 | if (!err) | |
1581 | err = tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val); | |
1582 | ||
1583 | return err; | |
b2a5c19c MC |
1584 | } |
1585 | ||
7f97a4bd MC |
1586 | static void tg3_phy_fet_toggle_apd(struct tg3 *tp, bool enable) |
1587 | { | |
1588 | u32 phytest; | |
1589 | ||
1590 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { | |
1591 | u32 phy; | |
1592 | ||
1593 | tg3_writephy(tp, MII_TG3_FET_TEST, | |
1594 | phytest | MII_TG3_FET_SHADOW_EN); | |
1595 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXSTAT2, &phy)) { | |
1596 | if (enable) | |
1597 | phy |= MII_TG3_FET_SHDW_AUXSTAT2_APD; | |
1598 | else | |
1599 | phy &= ~MII_TG3_FET_SHDW_AUXSTAT2_APD; | |
1600 | tg3_writephy(tp, MII_TG3_FET_SHDW_AUXSTAT2, phy); | |
1601 | } | |
1602 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); | |
1603 | } | |
1604 | } | |
1605 | ||
6833c043 MC |
1606 | static void tg3_phy_toggle_apd(struct tg3 *tp, bool enable) |
1607 | { | |
1608 | u32 reg; | |
1609 | ||
ecf1410b | 1610 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) || |
a50d0796 MC |
1611 | ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
1612 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) && | |
f07e9af3 | 1613 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
6833c043 MC |
1614 | return; |
1615 | ||
f07e9af3 | 1616 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
7f97a4bd MC |
1617 | tg3_phy_fet_toggle_apd(tp, enable); |
1618 | return; | |
1619 | } | |
1620 | ||
6833c043 MC |
1621 | reg = MII_TG3_MISC_SHDW_WREN | |
1622 | MII_TG3_MISC_SHDW_SCR5_SEL | | |
1623 | MII_TG3_MISC_SHDW_SCR5_LPED | | |
1624 | MII_TG3_MISC_SHDW_SCR5_DLPTLM | | |
1625 | MII_TG3_MISC_SHDW_SCR5_SDTL | | |
1626 | MII_TG3_MISC_SHDW_SCR5_C125OE; | |
1627 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 || !enable) | |
1628 | reg |= MII_TG3_MISC_SHDW_SCR5_DLLAPD; | |
1629 | ||
1630 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); | |
1631 | ||
1632 | ||
1633 | reg = MII_TG3_MISC_SHDW_WREN | | |
1634 | MII_TG3_MISC_SHDW_APD_SEL | | |
1635 | MII_TG3_MISC_SHDW_APD_WKTM_84MS; | |
1636 | if (enable) | |
1637 | reg |= MII_TG3_MISC_SHDW_APD_ENABLE; | |
1638 | ||
1639 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); | |
1640 | } | |
1641 | ||
9ef8ca99 MC |
1642 | static void tg3_phy_toggle_automdix(struct tg3 *tp, int enable) |
1643 | { | |
1644 | u32 phy; | |
1645 | ||
1646 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) || | |
f07e9af3 | 1647 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
9ef8ca99 MC |
1648 | return; |
1649 | ||
f07e9af3 | 1650 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
9ef8ca99 MC |
1651 | u32 ephy; |
1652 | ||
535ef6e1 MC |
1653 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &ephy)) { |
1654 | u32 reg = MII_TG3_FET_SHDW_MISCCTRL; | |
1655 | ||
1656 | tg3_writephy(tp, MII_TG3_FET_TEST, | |
1657 | ephy | MII_TG3_FET_SHADOW_EN); | |
1658 | if (!tg3_readphy(tp, reg, &phy)) { | |
9ef8ca99 | 1659 | if (enable) |
535ef6e1 | 1660 | phy |= MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
9ef8ca99 | 1661 | else |
535ef6e1 MC |
1662 | phy &= ~MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
1663 | tg3_writephy(tp, reg, phy); | |
9ef8ca99 | 1664 | } |
535ef6e1 | 1665 | tg3_writephy(tp, MII_TG3_FET_TEST, ephy); |
9ef8ca99 MC |
1666 | } |
1667 | } else { | |
1668 | phy = MII_TG3_AUXCTL_MISC_RDSEL_MISC | | |
1669 | MII_TG3_AUXCTL_SHDWSEL_MISC; | |
1670 | if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, phy) && | |
1671 | !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy)) { | |
1672 | if (enable) | |
1673 | phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX; | |
1674 | else | |
1675 | phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX; | |
1676 | phy |= MII_TG3_AUXCTL_MISC_WREN; | |
1677 | tg3_writephy(tp, MII_TG3_AUX_CTRL, phy); | |
1678 | } | |
1679 | } | |
1680 | } | |
1681 | ||
1da177e4 LT |
1682 | static void tg3_phy_set_wirespeed(struct tg3 *tp) |
1683 | { | |
1684 | u32 val; | |
1685 | ||
f07e9af3 | 1686 | if (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) |
1da177e4 LT |
1687 | return; |
1688 | ||
1689 | if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x7007) && | |
1690 | !tg3_readphy(tp, MII_TG3_AUX_CTRL, &val)) | |
1691 | tg3_writephy(tp, MII_TG3_AUX_CTRL, | |
1692 | (val | (1 << 15) | (1 << 4))); | |
1693 | } | |
1694 | ||
b2a5c19c MC |
1695 | static void tg3_phy_apply_otp(struct tg3 *tp) |
1696 | { | |
1697 | u32 otp, phy; | |
1698 | ||
1699 | if (!tp->phy_otp) | |
1700 | return; | |
1701 | ||
1702 | otp = tp->phy_otp; | |
1703 | ||
1704 | /* Enable SM_DSP clock and tx 6dB coding. */ | |
1705 | phy = MII_TG3_AUXCTL_SHDWSEL_AUXCTL | | |
1706 | MII_TG3_AUXCTL_ACTL_SMDSP_ENA | | |
1707 | MII_TG3_AUXCTL_ACTL_TX_6DB; | |
1708 | tg3_writephy(tp, MII_TG3_AUX_CTRL, phy); | |
1709 | ||
1710 | phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT); | |
1711 | phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT; | |
1712 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy); | |
1713 | ||
1714 | phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) | | |
1715 | ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT); | |
1716 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy); | |
1717 | ||
1718 | phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT); | |
1719 | phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ; | |
1720 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy); | |
1721 | ||
1722 | phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT); | |
1723 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy); | |
1724 | ||
1725 | phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT); | |
1726 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy); | |
1727 | ||
1728 | phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) | | |
1729 | ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT); | |
1730 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy); | |
1731 | ||
1732 | /* Turn off SM_DSP clock. */ | |
1733 | phy = MII_TG3_AUXCTL_SHDWSEL_AUXCTL | | |
1734 | MII_TG3_AUXCTL_ACTL_TX_6DB; | |
1735 | tg3_writephy(tp, MII_TG3_AUX_CTRL, phy); | |
1736 | } | |
1737 | ||
1da177e4 LT |
1738 | static int tg3_wait_macro_done(struct tg3 *tp) |
1739 | { | |
1740 | int limit = 100; | |
1741 | ||
1742 | while (limit--) { | |
1743 | u32 tmp32; | |
1744 | ||
f08aa1a8 | 1745 | if (!tg3_readphy(tp, MII_TG3_DSP_CONTROL, &tmp32)) { |
1da177e4 LT |
1746 | if ((tmp32 & 0x1000) == 0) |
1747 | break; | |
1748 | } | |
1749 | } | |
d4675b52 | 1750 | if (limit < 0) |
1da177e4 LT |
1751 | return -EBUSY; |
1752 | ||
1753 | return 0; | |
1754 | } | |
1755 | ||
1756 | static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp) | |
1757 | { | |
1758 | static const u32 test_pat[4][6] = { | |
1759 | { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 }, | |
1760 | { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 }, | |
1761 | { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 }, | |
1762 | { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 } | |
1763 | }; | |
1764 | int chan; | |
1765 | ||
1766 | for (chan = 0; chan < 4; chan++) { | |
1767 | int i; | |
1768 | ||
1769 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, | |
1770 | (chan * 0x2000) | 0x0200); | |
f08aa1a8 | 1771 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
1da177e4 LT |
1772 | |
1773 | for (i = 0; i < 6; i++) | |
1774 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, | |
1775 | test_pat[chan][i]); | |
1776 | ||
f08aa1a8 | 1777 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
1da177e4 LT |
1778 | if (tg3_wait_macro_done(tp)) { |
1779 | *resetp = 1; | |
1780 | return -EBUSY; | |
1781 | } | |
1782 | ||
1783 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, | |
1784 | (chan * 0x2000) | 0x0200); | |
f08aa1a8 | 1785 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0082); |
1da177e4 LT |
1786 | if (tg3_wait_macro_done(tp)) { |
1787 | *resetp = 1; | |
1788 | return -EBUSY; | |
1789 | } | |
1790 | ||
f08aa1a8 | 1791 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0802); |
1da177e4 LT |
1792 | if (tg3_wait_macro_done(tp)) { |
1793 | *resetp = 1; | |
1794 | return -EBUSY; | |
1795 | } | |
1796 | ||
1797 | for (i = 0; i < 6; i += 2) { | |
1798 | u32 low, high; | |
1799 | ||
1800 | if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) || | |
1801 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) || | |
1802 | tg3_wait_macro_done(tp)) { | |
1803 | *resetp = 1; | |
1804 | return -EBUSY; | |
1805 | } | |
1806 | low &= 0x7fff; | |
1807 | high &= 0x000f; | |
1808 | if (low != test_pat[chan][i] || | |
1809 | high != test_pat[chan][i+1]) { | |
1810 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b); | |
1811 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001); | |
1812 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005); | |
1813 | ||
1814 | return -EBUSY; | |
1815 | } | |
1816 | } | |
1817 | } | |
1818 | ||
1819 | return 0; | |
1820 | } | |
1821 | ||
1822 | static int tg3_phy_reset_chanpat(struct tg3 *tp) | |
1823 | { | |
1824 | int chan; | |
1825 | ||
1826 | for (chan = 0; chan < 4; chan++) { | |
1827 | int i; | |
1828 | ||
1829 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, | |
1830 | (chan * 0x2000) | 0x0200); | |
f08aa1a8 | 1831 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
1da177e4 LT |
1832 | for (i = 0; i < 6; i++) |
1833 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000); | |
f08aa1a8 | 1834 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
1da177e4 LT |
1835 | if (tg3_wait_macro_done(tp)) |
1836 | return -EBUSY; | |
1837 | } | |
1838 | ||
1839 | return 0; | |
1840 | } | |
1841 | ||
1842 | static int tg3_phy_reset_5703_4_5(struct tg3 *tp) | |
1843 | { | |
1844 | u32 reg32, phy9_orig; | |
1845 | int retries, do_phy_reset, err; | |
1846 | ||
1847 | retries = 10; | |
1848 | do_phy_reset = 1; | |
1849 | do { | |
1850 | if (do_phy_reset) { | |
1851 | err = tg3_bmcr_reset(tp); | |
1852 | if (err) | |
1853 | return err; | |
1854 | do_phy_reset = 0; | |
1855 | } | |
1856 | ||
1857 | /* Disable transmitter and interrupt. */ | |
1858 | if (tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) | |
1859 | continue; | |
1860 | ||
1861 | reg32 |= 0x3000; | |
1862 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); | |
1863 | ||
1864 | /* Set full-duplex, 1000 mbps. */ | |
1865 | tg3_writephy(tp, MII_BMCR, | |
1866 | BMCR_FULLDPLX | TG3_BMCR_SPEED1000); | |
1867 | ||
1868 | /* Set to master mode. */ | |
1869 | if (tg3_readphy(tp, MII_TG3_CTRL, &phy9_orig)) | |
1870 | continue; | |
1871 | ||
1872 | tg3_writephy(tp, MII_TG3_CTRL, | |
1873 | (MII_TG3_CTRL_AS_MASTER | | |
1874 | MII_TG3_CTRL_ENABLE_AS_MASTER)); | |
1875 | ||
1876 | /* Enable SM_DSP_CLOCK and 6dB. */ | |
1877 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); | |
1878 | ||
1879 | /* Block the PHY control access. */ | |
6ee7c0a0 | 1880 | tg3_phydsp_write(tp, 0x8005, 0x0800); |
1da177e4 LT |
1881 | |
1882 | err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset); | |
1883 | if (!err) | |
1884 | break; | |
1885 | } while (--retries); | |
1886 | ||
1887 | err = tg3_phy_reset_chanpat(tp); | |
1888 | if (err) | |
1889 | return err; | |
1890 | ||
6ee7c0a0 | 1891 | tg3_phydsp_write(tp, 0x8005, 0x0000); |
1da177e4 LT |
1892 | |
1893 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200); | |
f08aa1a8 | 1894 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0000); |
1da177e4 LT |
1895 | |
1896 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || | |
1897 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { | |
1898 | /* Set Extended packet length bit for jumbo frames */ | |
1899 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4400); | |
859a5887 | 1900 | } else { |
1da177e4 LT |
1901 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); |
1902 | } | |
1903 | ||
1904 | tg3_writephy(tp, MII_TG3_CTRL, phy9_orig); | |
1905 | ||
1906 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) { | |
1907 | reg32 &= ~0x3000; | |
1908 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); | |
1909 | } else if (!err) | |
1910 | err = -EBUSY; | |
1911 | ||
1912 | return err; | |
1913 | } | |
1914 | ||
1915 | /* This will reset the tigon3 PHY if there is no valid | |
1916 | * link unless the FORCE argument is non-zero. | |
1917 | */ | |
1918 | static int tg3_phy_reset(struct tg3 *tp) | |
1919 | { | |
b2a5c19c | 1920 | u32 cpmuctrl; |
1da177e4 LT |
1921 | u32 phy_status; |
1922 | int err; | |
1923 | ||
60189ddf MC |
1924 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
1925 | u32 val; | |
1926 | ||
1927 | val = tr32(GRC_MISC_CFG); | |
1928 | tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ); | |
1929 | udelay(40); | |
1930 | } | |
1da177e4 LT |
1931 | err = tg3_readphy(tp, MII_BMSR, &phy_status); |
1932 | err |= tg3_readphy(tp, MII_BMSR, &phy_status); | |
1933 | if (err != 0) | |
1934 | return -EBUSY; | |
1935 | ||
c8e1e82b MC |
1936 | if (netif_running(tp->dev) && netif_carrier_ok(tp->dev)) { |
1937 | netif_carrier_off(tp->dev); | |
1938 | tg3_link_report(tp); | |
1939 | } | |
1940 | ||
1da177e4 LT |
1941 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || |
1942 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || | |
1943 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { | |
1944 | err = tg3_phy_reset_5703_4_5(tp); | |
1945 | if (err) | |
1946 | return err; | |
1947 | goto out; | |
1948 | } | |
1949 | ||
b2a5c19c MC |
1950 | cpmuctrl = 0; |
1951 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && | |
1952 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { | |
1953 | cpmuctrl = tr32(TG3_CPMU_CTRL); | |
1954 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) | |
1955 | tw32(TG3_CPMU_CTRL, | |
1956 | cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY); | |
1957 | } | |
1958 | ||
1da177e4 LT |
1959 | err = tg3_bmcr_reset(tp); |
1960 | if (err) | |
1961 | return err; | |
1962 | ||
b2a5c19c MC |
1963 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) { |
1964 | u32 phy; | |
1965 | ||
1966 | phy = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz; | |
1967 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, phy); | |
1968 | ||
1969 | tw32(TG3_CPMU_CTRL, cpmuctrl); | |
1970 | } | |
1971 | ||
bcb37f6c MC |
1972 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
1973 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { | |
ce057f01 MC |
1974 | u32 val; |
1975 | ||
1976 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); | |
1977 | if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) == | |
1978 | CPMU_LSPD_1000MB_MACCLK_12_5) { | |
1979 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; | |
1980 | udelay(40); | |
1981 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); | |
1982 | } | |
1983 | } | |
1984 | ||
a50d0796 MC |
1985 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
1986 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) && | |
f07e9af3 | 1987 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) |
ecf1410b MC |
1988 | return 0; |
1989 | ||
b2a5c19c MC |
1990 | tg3_phy_apply_otp(tp); |
1991 | ||
f07e9af3 | 1992 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
6833c043 MC |
1993 | tg3_phy_toggle_apd(tp, true); |
1994 | else | |
1995 | tg3_phy_toggle_apd(tp, false); | |
1996 | ||
1da177e4 | 1997 | out: |
f07e9af3 | 1998 | if (tp->phy_flags & TG3_PHYFLG_ADC_BUG) { |
1da177e4 | 1999 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); |
6ee7c0a0 MC |
2000 | tg3_phydsp_write(tp, 0x201f, 0x2aaa); |
2001 | tg3_phydsp_write(tp, 0x000a, 0x0323); | |
1da177e4 LT |
2002 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); |
2003 | } | |
f07e9af3 | 2004 | if (tp->phy_flags & TG3_PHYFLG_5704_A0_BUG) { |
f08aa1a8 MC |
2005 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
2006 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); | |
1da177e4 | 2007 | } |
f07e9af3 | 2008 | if (tp->phy_flags & TG3_PHYFLG_BER_BUG) { |
1da177e4 | 2009 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); |
6ee7c0a0 MC |
2010 | tg3_phydsp_write(tp, 0x000a, 0x310b); |
2011 | tg3_phydsp_write(tp, 0x201f, 0x9506); | |
2012 | tg3_phydsp_write(tp, 0x401f, 0x14e2); | |
1da177e4 | 2013 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); |
f07e9af3 | 2014 | } else if (tp->phy_flags & TG3_PHYFLG_JITTER_BUG) { |
c424cb24 MC |
2015 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0c00); |
2016 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); | |
f07e9af3 | 2017 | if (tp->phy_flags & TG3_PHYFLG_ADJUST_TRIM) { |
c1d2a196 MC |
2018 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b); |
2019 | tg3_writephy(tp, MII_TG3_TEST1, | |
2020 | MII_TG3_TEST1_TRIM_EN | 0x4); | |
2021 | } else | |
2022 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b); | |
c424cb24 MC |
2023 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0400); |
2024 | } | |
1da177e4 LT |
2025 | /* Set Extended packet length bit (bit 14) on all chips that */ |
2026 | /* support jumbo frames */ | |
79eb6904 | 2027 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
1da177e4 LT |
2028 | /* Cannot do read-modify-write on 5401 */ |
2029 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20); | |
8f666b07 | 2030 | } else if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) { |
1da177e4 LT |
2031 | u32 phy_reg; |
2032 | ||
2033 | /* Set bit 14 with read-modify-write to preserve other bits */ | |
2034 | if (!tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x0007) && | |
2035 | !tg3_readphy(tp, MII_TG3_AUX_CTRL, &phy_reg)) | |
2036 | tg3_writephy(tp, MII_TG3_AUX_CTRL, phy_reg | 0x4000); | |
2037 | } | |
2038 | ||
2039 | /* Set phy register 0x10 bit 0 to high fifo elasticity to support | |
2040 | * jumbo frames transmission. | |
2041 | */ | |
8f666b07 | 2042 | if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) { |
1da177e4 LT |
2043 | u32 phy_reg; |
2044 | ||
2045 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &phy_reg)) | |
c6cdf436 MC |
2046 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
2047 | phy_reg | MII_TG3_EXT_CTRL_FIFO_ELASTIC); | |
1da177e4 LT |
2048 | } |
2049 | ||
715116a1 | 2050 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
715116a1 | 2051 | /* adjust output voltage */ |
535ef6e1 | 2052 | tg3_writephy(tp, MII_TG3_FET_PTEST, 0x12); |
715116a1 MC |
2053 | } |
2054 | ||
9ef8ca99 | 2055 | tg3_phy_toggle_automdix(tp, 1); |
1da177e4 LT |
2056 | tg3_phy_set_wirespeed(tp); |
2057 | return 0; | |
2058 | } | |
2059 | ||
2060 | static void tg3_frob_aux_power(struct tg3 *tp) | |
2061 | { | |
2062 | struct tg3 *tp_peer = tp; | |
2063 | ||
334355aa MC |
2064 | /* The GPIOs do something completely different on 57765. */ |
2065 | if ((tp->tg3_flags2 & TG3_FLG2_IS_NIC) == 0 || | |
a50d0796 | 2066 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
334355aa | 2067 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
1da177e4 LT |
2068 | return; |
2069 | ||
f6eb9b1f MC |
2070 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
2071 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 || | |
2072 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) { | |
8c2dc7e1 MC |
2073 | struct net_device *dev_peer; |
2074 | ||
2075 | dev_peer = pci_get_drvdata(tp->pdev_peer); | |
bc1c7567 | 2076 | /* remove_one() may have been run on the peer. */ |
8c2dc7e1 | 2077 | if (!dev_peer) |
bc1c7567 MC |
2078 | tp_peer = tp; |
2079 | else | |
2080 | tp_peer = netdev_priv(dev_peer); | |
1da177e4 LT |
2081 | } |
2082 | ||
1da177e4 | 2083 | if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 || |
6921d201 MC |
2084 | (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0 || |
2085 | (tp_peer->tg3_flags & TG3_FLAG_WOL_ENABLE) != 0 || | |
2086 | (tp_peer->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0) { | |
1da177e4 LT |
2087 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
2088 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { | |
b401e9e2 MC |
2089 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2090 | (GRC_LCLCTRL_GPIO_OE0 | | |
2091 | GRC_LCLCTRL_GPIO_OE1 | | |
2092 | GRC_LCLCTRL_GPIO_OE2 | | |
2093 | GRC_LCLCTRL_GPIO_OUTPUT0 | | |
2094 | GRC_LCLCTRL_GPIO_OUTPUT1), | |
2095 | 100); | |
8d519ab2 MC |
2096 | } else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
2097 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { | |
5f0c4a3c MC |
2098 | /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */ |
2099 | u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 | | |
2100 | GRC_LCLCTRL_GPIO_OE1 | | |
2101 | GRC_LCLCTRL_GPIO_OE2 | | |
2102 | GRC_LCLCTRL_GPIO_OUTPUT0 | | |
2103 | GRC_LCLCTRL_GPIO_OUTPUT1 | | |
2104 | tp->grc_local_ctrl; | |
2105 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); | |
2106 | ||
2107 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2; | |
2108 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); | |
2109 | ||
2110 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0; | |
2111 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, 100); | |
1da177e4 LT |
2112 | } else { |
2113 | u32 no_gpio2; | |
dc56b7d4 | 2114 | u32 grc_local_ctrl = 0; |
1da177e4 LT |
2115 | |
2116 | if (tp_peer != tp && | |
2117 | (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0) | |
2118 | return; | |
2119 | ||
dc56b7d4 MC |
2120 | /* Workaround to prevent overdrawing Amps. */ |
2121 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == | |
2122 | ASIC_REV_5714) { | |
2123 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; | |
b401e9e2 MC |
2124 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2125 | grc_local_ctrl, 100); | |
dc56b7d4 MC |
2126 | } |
2127 | ||
1da177e4 LT |
2128 | /* On 5753 and variants, GPIO2 cannot be used. */ |
2129 | no_gpio2 = tp->nic_sram_data_cfg & | |
2130 | NIC_SRAM_DATA_CFG_NO_GPIO2; | |
2131 | ||
dc56b7d4 | 2132 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | |
1da177e4 LT |
2133 | GRC_LCLCTRL_GPIO_OE1 | |
2134 | GRC_LCLCTRL_GPIO_OE2 | | |
2135 | GRC_LCLCTRL_GPIO_OUTPUT1 | | |
2136 | GRC_LCLCTRL_GPIO_OUTPUT2; | |
2137 | if (no_gpio2) { | |
2138 | grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 | | |
2139 | GRC_LCLCTRL_GPIO_OUTPUT2); | |
2140 | } | |
b401e9e2 MC |
2141 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2142 | grc_local_ctrl, 100); | |
1da177e4 LT |
2143 | |
2144 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0; | |
2145 | ||
b401e9e2 MC |
2146 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2147 | grc_local_ctrl, 100); | |
1da177e4 LT |
2148 | |
2149 | if (!no_gpio2) { | |
2150 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2; | |
b401e9e2 MC |
2151 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2152 | grc_local_ctrl, 100); | |
1da177e4 LT |
2153 | } |
2154 | } | |
2155 | } else { | |
2156 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && | |
2157 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { | |
2158 | if (tp_peer != tp && | |
2159 | (tp_peer->tg3_flags & TG3_FLAG_INIT_COMPLETE) != 0) | |
2160 | return; | |
2161 | ||
b401e9e2 MC |
2162 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2163 | (GRC_LCLCTRL_GPIO_OE1 | | |
2164 | GRC_LCLCTRL_GPIO_OUTPUT1), 100); | |
1da177e4 | 2165 | |
b401e9e2 MC |
2166 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2167 | GRC_LCLCTRL_GPIO_OE1, 100); | |
1da177e4 | 2168 | |
b401e9e2 MC |
2169 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2170 | (GRC_LCLCTRL_GPIO_OE1 | | |
2171 | GRC_LCLCTRL_GPIO_OUTPUT1), 100); | |
1da177e4 LT |
2172 | } |
2173 | } | |
2174 | } | |
2175 | ||
e8f3f6ca MC |
2176 | static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed) |
2177 | { | |
2178 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_2) | |
2179 | return 1; | |
79eb6904 | 2180 | else if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411) { |
e8f3f6ca MC |
2181 | if (speed != SPEED_10) |
2182 | return 1; | |
2183 | } else if (speed == SPEED_10) | |
2184 | return 1; | |
2185 | ||
2186 | return 0; | |
2187 | } | |
2188 | ||
1da177e4 LT |
2189 | static int tg3_setup_phy(struct tg3 *, int); |
2190 | ||
2191 | #define RESET_KIND_SHUTDOWN 0 | |
2192 | #define RESET_KIND_INIT 1 | |
2193 | #define RESET_KIND_SUSPEND 2 | |
2194 | ||
2195 | static void tg3_write_sig_post_reset(struct tg3 *, int); | |
2196 | static int tg3_halt_cpu(struct tg3 *, u32); | |
2197 | ||
0a459aac | 2198 | static void tg3_power_down_phy(struct tg3 *tp, bool do_low_power) |
15c3b696 | 2199 | { |
ce057f01 MC |
2200 | u32 val; |
2201 | ||
f07e9af3 | 2202 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
5129724a MC |
2203 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
2204 | u32 sg_dig_ctrl = tr32(SG_DIG_CTRL); | |
2205 | u32 serdes_cfg = tr32(MAC_SERDES_CFG); | |
2206 | ||
2207 | sg_dig_ctrl |= | |
2208 | SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET; | |
2209 | tw32(SG_DIG_CTRL, sg_dig_ctrl); | |
2210 | tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15)); | |
2211 | } | |
3f7045c1 | 2212 | return; |
5129724a | 2213 | } |
3f7045c1 | 2214 | |
60189ddf | 2215 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
60189ddf MC |
2216 | tg3_bmcr_reset(tp); |
2217 | val = tr32(GRC_MISC_CFG); | |
2218 | tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ); | |
2219 | udelay(40); | |
2220 | return; | |
f07e9af3 | 2221 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
0e5f784c MC |
2222 | u32 phytest; |
2223 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { | |
2224 | u32 phy; | |
2225 | ||
2226 | tg3_writephy(tp, MII_ADVERTISE, 0); | |
2227 | tg3_writephy(tp, MII_BMCR, | |
2228 | BMCR_ANENABLE | BMCR_ANRESTART); | |
2229 | ||
2230 | tg3_writephy(tp, MII_TG3_FET_TEST, | |
2231 | phytest | MII_TG3_FET_SHADOW_EN); | |
2232 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXMODE4, &phy)) { | |
2233 | phy |= MII_TG3_FET_SHDW_AUXMODE4_SBPD; | |
2234 | tg3_writephy(tp, | |
2235 | MII_TG3_FET_SHDW_AUXMODE4, | |
2236 | phy); | |
2237 | } | |
2238 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); | |
2239 | } | |
2240 | return; | |
0a459aac | 2241 | } else if (do_low_power) { |
715116a1 MC |
2242 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
2243 | MII_TG3_EXT_CTRL_FORCE_LED_OFF); | |
0a459aac MC |
2244 | |
2245 | tg3_writephy(tp, MII_TG3_AUX_CTRL, | |
2246 | MII_TG3_AUXCTL_SHDWSEL_PWRCTL | | |
2247 | MII_TG3_AUXCTL_PCTL_100TX_LPWR | | |
2248 | MII_TG3_AUXCTL_PCTL_SPR_ISOLATE | | |
2249 | MII_TG3_AUXCTL_PCTL_VREG_11V); | |
715116a1 | 2250 | } |
3f7045c1 | 2251 | |
15c3b696 MC |
2252 | /* The PHY should not be powered down on some chips because |
2253 | * of bugs. | |
2254 | */ | |
2255 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
2256 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || | |
2257 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 && | |
f07e9af3 | 2258 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
15c3b696 | 2259 | return; |
ce057f01 | 2260 | |
bcb37f6c MC |
2261 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX || |
2262 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5761_AX) { | |
ce057f01 MC |
2263 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
2264 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; | |
2265 | val |= CPMU_LSPD_1000MB_MACCLK_12_5; | |
2266 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); | |
2267 | } | |
2268 | ||
15c3b696 MC |
2269 | tg3_writephy(tp, MII_BMCR, BMCR_PDOWN); |
2270 | } | |
2271 | ||
ffbcfed4 MC |
2272 | /* tp->lock is held. */ |
2273 | static int tg3_nvram_lock(struct tg3 *tp) | |
2274 | { | |
2275 | if (tp->tg3_flags & TG3_FLAG_NVRAM) { | |
2276 | int i; | |
2277 | ||
2278 | if (tp->nvram_lock_cnt == 0) { | |
2279 | tw32(NVRAM_SWARB, SWARB_REQ_SET1); | |
2280 | for (i = 0; i < 8000; i++) { | |
2281 | if (tr32(NVRAM_SWARB) & SWARB_GNT1) | |
2282 | break; | |
2283 | udelay(20); | |
2284 | } | |
2285 | if (i == 8000) { | |
2286 | tw32(NVRAM_SWARB, SWARB_REQ_CLR1); | |
2287 | return -ENODEV; | |
2288 | } | |
2289 | } | |
2290 | tp->nvram_lock_cnt++; | |
2291 | } | |
2292 | return 0; | |
2293 | } | |
2294 | ||
2295 | /* tp->lock is held. */ | |
2296 | static void tg3_nvram_unlock(struct tg3 *tp) | |
2297 | { | |
2298 | if (tp->tg3_flags & TG3_FLAG_NVRAM) { | |
2299 | if (tp->nvram_lock_cnt > 0) | |
2300 | tp->nvram_lock_cnt--; | |
2301 | if (tp->nvram_lock_cnt == 0) | |
2302 | tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1); | |
2303 | } | |
2304 | } | |
2305 | ||
2306 | /* tp->lock is held. */ | |
2307 | static void tg3_enable_nvram_access(struct tg3 *tp) | |
2308 | { | |
2309 | if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && | |
f66a29b0 | 2310 | !(tp->tg3_flags3 & TG3_FLG3_PROTECTED_NVRAM)) { |
ffbcfed4 MC |
2311 | u32 nvaccess = tr32(NVRAM_ACCESS); |
2312 | ||
2313 | tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE); | |
2314 | } | |
2315 | } | |
2316 | ||
2317 | /* tp->lock is held. */ | |
2318 | static void tg3_disable_nvram_access(struct tg3 *tp) | |
2319 | { | |
2320 | if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && | |
f66a29b0 | 2321 | !(tp->tg3_flags3 & TG3_FLG3_PROTECTED_NVRAM)) { |
ffbcfed4 MC |
2322 | u32 nvaccess = tr32(NVRAM_ACCESS); |
2323 | ||
2324 | tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE); | |
2325 | } | |
2326 | } | |
2327 | ||
2328 | static int tg3_nvram_read_using_eeprom(struct tg3 *tp, | |
2329 | u32 offset, u32 *val) | |
2330 | { | |
2331 | u32 tmp; | |
2332 | int i; | |
2333 | ||
2334 | if (offset > EEPROM_ADDR_ADDR_MASK || (offset % 4) != 0) | |
2335 | return -EINVAL; | |
2336 | ||
2337 | tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK | | |
2338 | EEPROM_ADDR_DEVID_MASK | | |
2339 | EEPROM_ADDR_READ); | |
2340 | tw32(GRC_EEPROM_ADDR, | |
2341 | tmp | | |
2342 | (0 << EEPROM_ADDR_DEVID_SHIFT) | | |
2343 | ((offset << EEPROM_ADDR_ADDR_SHIFT) & | |
2344 | EEPROM_ADDR_ADDR_MASK) | | |
2345 | EEPROM_ADDR_READ | EEPROM_ADDR_START); | |
2346 | ||
2347 | for (i = 0; i < 1000; i++) { | |
2348 | tmp = tr32(GRC_EEPROM_ADDR); | |
2349 | ||
2350 | if (tmp & EEPROM_ADDR_COMPLETE) | |
2351 | break; | |
2352 | msleep(1); | |
2353 | } | |
2354 | if (!(tmp & EEPROM_ADDR_COMPLETE)) | |
2355 | return -EBUSY; | |
2356 | ||
62cedd11 MC |
2357 | tmp = tr32(GRC_EEPROM_DATA); |
2358 | ||
2359 | /* | |
2360 | * The data will always be opposite the native endian | |
2361 | * format. Perform a blind byteswap to compensate. | |
2362 | */ | |
2363 | *val = swab32(tmp); | |
2364 | ||
ffbcfed4 MC |
2365 | return 0; |
2366 | } | |
2367 | ||
2368 | #define NVRAM_CMD_TIMEOUT 10000 | |
2369 | ||
2370 | static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd) | |
2371 | { | |
2372 | int i; | |
2373 | ||
2374 | tw32(NVRAM_CMD, nvram_cmd); | |
2375 | for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) { | |
2376 | udelay(10); | |
2377 | if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) { | |
2378 | udelay(10); | |
2379 | break; | |
2380 | } | |
2381 | } | |
2382 | ||
2383 | if (i == NVRAM_CMD_TIMEOUT) | |
2384 | return -EBUSY; | |
2385 | ||
2386 | return 0; | |
2387 | } | |
2388 | ||
2389 | static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr) | |
2390 | { | |
2391 | if ((tp->tg3_flags & TG3_FLAG_NVRAM) && | |
2392 | (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) && | |
2393 | (tp->tg3_flags2 & TG3_FLG2_FLASH) && | |
2394 | !(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM_ADDR_TRANS) && | |
2395 | (tp->nvram_jedecnum == JEDEC_ATMEL)) | |
2396 | ||
2397 | addr = ((addr / tp->nvram_pagesize) << | |
2398 | ATMEL_AT45DB0X1B_PAGE_POS) + | |
2399 | (addr % tp->nvram_pagesize); | |
2400 | ||
2401 | return addr; | |
2402 | } | |
2403 | ||
2404 | static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr) | |
2405 | { | |
2406 | if ((tp->tg3_flags & TG3_FLAG_NVRAM) && | |
2407 | (tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) && | |
2408 | (tp->tg3_flags2 & TG3_FLG2_FLASH) && | |
2409 | !(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM_ADDR_TRANS) && | |
2410 | (tp->nvram_jedecnum == JEDEC_ATMEL)) | |
2411 | ||
2412 | addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) * | |
2413 | tp->nvram_pagesize) + | |
2414 | (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1)); | |
2415 | ||
2416 | return addr; | |
2417 | } | |
2418 | ||
e4f34110 MC |
2419 | /* NOTE: Data read in from NVRAM is byteswapped according to |
2420 | * the byteswapping settings for all other register accesses. | |
2421 | * tg3 devices are BE devices, so on a BE machine, the data | |
2422 | * returned will be exactly as it is seen in NVRAM. On a LE | |
2423 | * machine, the 32-bit value will be byteswapped. | |
2424 | */ | |
ffbcfed4 MC |
2425 | static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val) |
2426 | { | |
2427 | int ret; | |
2428 | ||
2429 | if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) | |
2430 | return tg3_nvram_read_using_eeprom(tp, offset, val); | |
2431 | ||
2432 | offset = tg3_nvram_phys_addr(tp, offset); | |
2433 | ||
2434 | if (offset > NVRAM_ADDR_MSK) | |
2435 | return -EINVAL; | |
2436 | ||
2437 | ret = tg3_nvram_lock(tp); | |
2438 | if (ret) | |
2439 | return ret; | |
2440 | ||
2441 | tg3_enable_nvram_access(tp); | |
2442 | ||
2443 | tw32(NVRAM_ADDR, offset); | |
2444 | ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO | | |
2445 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE); | |
2446 | ||
2447 | if (ret == 0) | |
e4f34110 | 2448 | *val = tr32(NVRAM_RDDATA); |
ffbcfed4 MC |
2449 | |
2450 | tg3_disable_nvram_access(tp); | |
2451 | ||
2452 | tg3_nvram_unlock(tp); | |
2453 | ||
2454 | return ret; | |
2455 | } | |
2456 | ||
a9dc529d MC |
2457 | /* Ensures NVRAM data is in bytestream format. */ |
2458 | static int tg3_nvram_read_be32(struct tg3 *tp, u32 offset, __be32 *val) | |
ffbcfed4 MC |
2459 | { |
2460 | u32 v; | |
a9dc529d | 2461 | int res = tg3_nvram_read(tp, offset, &v); |
ffbcfed4 | 2462 | if (!res) |
a9dc529d | 2463 | *val = cpu_to_be32(v); |
ffbcfed4 MC |
2464 | return res; |
2465 | } | |
2466 | ||
3f007891 MC |
2467 | /* tp->lock is held. */ |
2468 | static void __tg3_set_mac_addr(struct tg3 *tp, int skip_mac_1) | |
2469 | { | |
2470 | u32 addr_high, addr_low; | |
2471 | int i; | |
2472 | ||
2473 | addr_high = ((tp->dev->dev_addr[0] << 8) | | |
2474 | tp->dev->dev_addr[1]); | |
2475 | addr_low = ((tp->dev->dev_addr[2] << 24) | | |
2476 | (tp->dev->dev_addr[3] << 16) | | |
2477 | (tp->dev->dev_addr[4] << 8) | | |
2478 | (tp->dev->dev_addr[5] << 0)); | |
2479 | for (i = 0; i < 4; i++) { | |
2480 | if (i == 1 && skip_mac_1) | |
2481 | continue; | |
2482 | tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high); | |
2483 | tw32(MAC_ADDR_0_LOW + (i * 8), addr_low); | |
2484 | } | |
2485 | ||
2486 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || | |
2487 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { | |
2488 | for (i = 0; i < 12; i++) { | |
2489 | tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high); | |
2490 | tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low); | |
2491 | } | |
2492 | } | |
2493 | ||
2494 | addr_high = (tp->dev->dev_addr[0] + | |
2495 | tp->dev->dev_addr[1] + | |
2496 | tp->dev->dev_addr[2] + | |
2497 | tp->dev->dev_addr[3] + | |
2498 | tp->dev->dev_addr[4] + | |
2499 | tp->dev->dev_addr[5]) & | |
2500 | TX_BACKOFF_SEED_MASK; | |
2501 | tw32(MAC_TX_BACKOFF_SEED, addr_high); | |
2502 | } | |
2503 | ||
bc1c7567 | 2504 | static int tg3_set_power_state(struct tg3 *tp, pci_power_t state) |
1da177e4 LT |
2505 | { |
2506 | u32 misc_host_ctrl; | |
0a459aac | 2507 | bool device_should_wake, do_low_power; |
1da177e4 LT |
2508 | |
2509 | /* Make sure register accesses (indirect or otherwise) | |
2510 | * will function correctly. | |
2511 | */ | |
2512 | pci_write_config_dword(tp->pdev, | |
2513 | TG3PCI_MISC_HOST_CTRL, | |
2514 | tp->misc_host_ctrl); | |
2515 | ||
1da177e4 | 2516 | switch (state) { |
bc1c7567 | 2517 | case PCI_D0: |
12dac075 RW |
2518 | pci_enable_wake(tp->pdev, state, false); |
2519 | pci_set_power_state(tp->pdev, PCI_D0); | |
8c6bda1a | 2520 | |
9d26e213 MC |
2521 | /* Switch out of Vaux if it is a NIC */ |
2522 | if (tp->tg3_flags2 & TG3_FLG2_IS_NIC) | |
b401e9e2 | 2523 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, 100); |
1da177e4 LT |
2524 | |
2525 | return 0; | |
2526 | ||
bc1c7567 | 2527 | case PCI_D1: |
bc1c7567 | 2528 | case PCI_D2: |
bc1c7567 | 2529 | case PCI_D3hot: |
1da177e4 LT |
2530 | break; |
2531 | ||
2532 | default: | |
05dbe005 JP |
2533 | netdev_err(tp->dev, "Invalid power state (D%d) requested\n", |
2534 | state); | |
1da177e4 | 2535 | return -EINVAL; |
855e1111 | 2536 | } |
5e7dfd0f MC |
2537 | |
2538 | /* Restore the CLKREQ setting. */ | |
2539 | if (tp->tg3_flags3 & TG3_FLG3_CLKREQ_BUG) { | |
2540 | u16 lnkctl; | |
2541 | ||
2542 | pci_read_config_word(tp->pdev, | |
2543 | tp->pcie_cap + PCI_EXP_LNKCTL, | |
2544 | &lnkctl); | |
2545 | lnkctl |= PCI_EXP_LNKCTL_CLKREQ_EN; | |
2546 | pci_write_config_word(tp->pdev, | |
2547 | tp->pcie_cap + PCI_EXP_LNKCTL, | |
2548 | lnkctl); | |
2549 | } | |
2550 | ||
1da177e4 LT |
2551 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
2552 | tw32(TG3PCI_MISC_HOST_CTRL, | |
2553 | misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT); | |
2554 | ||
05ac4cb7 MC |
2555 | device_should_wake = pci_pme_capable(tp->pdev, state) && |
2556 | device_may_wakeup(&tp->pdev->dev) && | |
2557 | (tp->tg3_flags & TG3_FLAG_WOL_ENABLE); | |
2558 | ||
dd477003 | 2559 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
0a459aac | 2560 | do_low_power = false; |
f07e9af3 | 2561 | if ((tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) && |
80096068 | 2562 | !(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
b02fd9e3 | 2563 | struct phy_device *phydev; |
0a459aac | 2564 | u32 phyid, advertising; |
b02fd9e3 | 2565 | |
3f0e3ad7 | 2566 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
b02fd9e3 | 2567 | |
80096068 | 2568 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
b02fd9e3 MC |
2569 | |
2570 | tp->link_config.orig_speed = phydev->speed; | |
2571 | tp->link_config.orig_duplex = phydev->duplex; | |
2572 | tp->link_config.orig_autoneg = phydev->autoneg; | |
2573 | tp->link_config.orig_advertising = phydev->advertising; | |
2574 | ||
2575 | advertising = ADVERTISED_TP | | |
2576 | ADVERTISED_Pause | | |
2577 | ADVERTISED_Autoneg | | |
2578 | ADVERTISED_10baseT_Half; | |
2579 | ||
2580 | if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || | |
05ac4cb7 | 2581 | device_should_wake) { |
b02fd9e3 MC |
2582 | if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) |
2583 | advertising |= | |
2584 | ADVERTISED_100baseT_Half | | |
2585 | ADVERTISED_100baseT_Full | | |
2586 | ADVERTISED_10baseT_Full; | |
2587 | else | |
2588 | advertising |= ADVERTISED_10baseT_Full; | |
2589 | } | |
2590 | ||
2591 | phydev->advertising = advertising; | |
2592 | ||
2593 | phy_start_aneg(phydev); | |
0a459aac MC |
2594 | |
2595 | phyid = phydev->drv->phy_id & phydev->drv->phy_id_mask; | |
6a443a0f MC |
2596 | if (phyid != PHY_ID_BCMAC131) { |
2597 | phyid &= PHY_BCM_OUI_MASK; | |
2598 | if (phyid == PHY_BCM_OUI_1 || | |
2599 | phyid == PHY_BCM_OUI_2 || | |
2600 | phyid == PHY_BCM_OUI_3) | |
0a459aac MC |
2601 | do_low_power = true; |
2602 | } | |
b02fd9e3 | 2603 | } |
dd477003 | 2604 | } else { |
2023276e | 2605 | do_low_power = true; |
0a459aac | 2606 | |
80096068 MC |
2607 | if (!(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
2608 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; | |
dd477003 MC |
2609 | tp->link_config.orig_speed = tp->link_config.speed; |
2610 | tp->link_config.orig_duplex = tp->link_config.duplex; | |
2611 | tp->link_config.orig_autoneg = tp->link_config.autoneg; | |
2612 | } | |
1da177e4 | 2613 | |
f07e9af3 | 2614 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
dd477003 MC |
2615 | tp->link_config.speed = SPEED_10; |
2616 | tp->link_config.duplex = DUPLEX_HALF; | |
2617 | tp->link_config.autoneg = AUTONEG_ENABLE; | |
2618 | tg3_setup_phy(tp, 0); | |
2619 | } | |
1da177e4 LT |
2620 | } |
2621 | ||
b5d3772c MC |
2622 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
2623 | u32 val; | |
2624 | ||
2625 | val = tr32(GRC_VCPU_EXT_CTRL); | |
2626 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL); | |
2627 | } else if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) { | |
6921d201 MC |
2628 | int i; |
2629 | u32 val; | |
2630 | ||
2631 | for (i = 0; i < 200; i++) { | |
2632 | tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val); | |
2633 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) | |
2634 | break; | |
2635 | msleep(1); | |
2636 | } | |
2637 | } | |
a85feb8c GZ |
2638 | if (tp->tg3_flags & TG3_FLAG_WOL_CAP) |
2639 | tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE | | |
2640 | WOL_DRV_STATE_SHUTDOWN | | |
2641 | WOL_DRV_WOL | | |
2642 | WOL_SET_MAGIC_PKT); | |
6921d201 | 2643 | |
05ac4cb7 | 2644 | if (device_should_wake) { |
1da177e4 LT |
2645 | u32 mac_mode; |
2646 | ||
f07e9af3 | 2647 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
0a459aac | 2648 | if (do_low_power) { |
dd477003 MC |
2649 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a); |
2650 | udelay(40); | |
2651 | } | |
1da177e4 | 2652 | |
f07e9af3 | 2653 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
3f7045c1 MC |
2654 | mac_mode = MAC_MODE_PORT_MODE_GMII; |
2655 | else | |
2656 | mac_mode = MAC_MODE_PORT_MODE_MII; | |
1da177e4 | 2657 | |
e8f3f6ca MC |
2658 | mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY; |
2659 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == | |
2660 | ASIC_REV_5700) { | |
2661 | u32 speed = (tp->tg3_flags & | |
2662 | TG3_FLAG_WOL_SPEED_100MB) ? | |
2663 | SPEED_100 : SPEED_10; | |
2664 | if (tg3_5700_link_polarity(tp, speed)) | |
2665 | mac_mode |= MAC_MODE_LINK_POLARITY; | |
2666 | else | |
2667 | mac_mode &= ~MAC_MODE_LINK_POLARITY; | |
2668 | } | |
1da177e4 LT |
2669 | } else { |
2670 | mac_mode = MAC_MODE_PORT_MODE_TBI; | |
2671 | } | |
2672 | ||
cbf46853 | 2673 | if (!(tp->tg3_flags2 & TG3_FLG2_5750_PLUS)) |
1da177e4 LT |
2674 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
2675 | ||
05ac4cb7 MC |
2676 | mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE; |
2677 | if (((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && | |
2678 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) && | |
2679 | ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || | |
2680 | (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE))) | |
2681 | mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL; | |
1da177e4 | 2682 | |
3bda1258 MC |
2683 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
2684 | mac_mode |= tp->mac_mode & | |
2685 | (MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN); | |
2686 | if (mac_mode & MAC_MODE_APE_TX_EN) | |
2687 | mac_mode |= MAC_MODE_TDE_ENABLE; | |
2688 | } | |
2689 | ||
1da177e4 LT |
2690 | tw32_f(MAC_MODE, mac_mode); |
2691 | udelay(100); | |
2692 | ||
2693 | tw32_f(MAC_RX_MODE, RX_MODE_ENABLE); | |
2694 | udelay(10); | |
2695 | } | |
2696 | ||
2697 | if (!(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) && | |
2698 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
2699 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { | |
2700 | u32 base_val; | |
2701 | ||
2702 | base_val = tp->pci_clock_ctrl; | |
2703 | base_val |= (CLOCK_CTRL_RXCLK_DISABLE | | |
2704 | CLOCK_CTRL_TXCLK_DISABLE); | |
2705 | ||
b401e9e2 MC |
2706 | tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK | |
2707 | CLOCK_CTRL_PWRDOWN_PLL133, 40); | |
d7b0a857 | 2708 | } else if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) || |
795d01c5 | 2709 | (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) || |
d7b0a857 | 2710 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906)) { |
4cf78e4f | 2711 | /* do nothing */ |
85e94ced | 2712 | } else if (!((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && |
1da177e4 LT |
2713 | (tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) { |
2714 | u32 newbits1, newbits2; | |
2715 | ||
2716 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
2717 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { | |
2718 | newbits1 = (CLOCK_CTRL_RXCLK_DISABLE | | |
2719 | CLOCK_CTRL_TXCLK_DISABLE | | |
2720 | CLOCK_CTRL_ALTCLK); | |
2721 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; | |
2722 | } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { | |
2723 | newbits1 = CLOCK_CTRL_625_CORE; | |
2724 | newbits2 = newbits1 | CLOCK_CTRL_ALTCLK; | |
2725 | } else { | |
2726 | newbits1 = CLOCK_CTRL_ALTCLK; | |
2727 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; | |
2728 | } | |
2729 | ||
b401e9e2 MC |
2730 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1, |
2731 | 40); | |
1da177e4 | 2732 | |
b401e9e2 MC |
2733 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2, |
2734 | 40); | |
1da177e4 LT |
2735 | |
2736 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { | |
2737 | u32 newbits3; | |
2738 | ||
2739 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
2740 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { | |
2741 | newbits3 = (CLOCK_CTRL_RXCLK_DISABLE | | |
2742 | CLOCK_CTRL_TXCLK_DISABLE | | |
2743 | CLOCK_CTRL_44MHZ_CORE); | |
2744 | } else { | |
2745 | newbits3 = CLOCK_CTRL_44MHZ_CORE; | |
2746 | } | |
2747 | ||
b401e9e2 MC |
2748 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
2749 | tp->pci_clock_ctrl | newbits3, 40); | |
1da177e4 LT |
2750 | } |
2751 | } | |
2752 | ||
05ac4cb7 | 2753 | if (!(device_should_wake) && |
22435849 | 2754 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) |
0a459aac | 2755 | tg3_power_down_phy(tp, do_low_power); |
6921d201 | 2756 | |
1da177e4 LT |
2757 | tg3_frob_aux_power(tp); |
2758 | ||
2759 | /* Workaround for unstable PLL clock */ | |
2760 | if ((GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX) || | |
2761 | (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX)) { | |
2762 | u32 val = tr32(0x7d00); | |
2763 | ||
2764 | val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1); | |
2765 | tw32(0x7d00, val); | |
6921d201 | 2766 | if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) { |
ec41c7df MC |
2767 | int err; |
2768 | ||
2769 | err = tg3_nvram_lock(tp); | |
1da177e4 | 2770 | tg3_halt_cpu(tp, RX_CPU_BASE); |
ec41c7df MC |
2771 | if (!err) |
2772 | tg3_nvram_unlock(tp); | |
6921d201 | 2773 | } |
1da177e4 LT |
2774 | } |
2775 | ||
bbadf503 MC |
2776 | tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN); |
2777 | ||
05ac4cb7 | 2778 | if (device_should_wake) |
12dac075 RW |
2779 | pci_enable_wake(tp->pdev, state, true); |
2780 | ||
1da177e4 | 2781 | /* Finally, set the new power state. */ |
12dac075 | 2782 | pci_set_power_state(tp->pdev, state); |
1da177e4 | 2783 | |
1da177e4 LT |
2784 | return 0; |
2785 | } | |
2786 | ||
1da177e4 LT |
2787 | static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex) |
2788 | { | |
2789 | switch (val & MII_TG3_AUX_STAT_SPDMASK) { | |
2790 | case MII_TG3_AUX_STAT_10HALF: | |
2791 | *speed = SPEED_10; | |
2792 | *duplex = DUPLEX_HALF; | |
2793 | break; | |
2794 | ||
2795 | case MII_TG3_AUX_STAT_10FULL: | |
2796 | *speed = SPEED_10; | |
2797 | *duplex = DUPLEX_FULL; | |
2798 | break; | |
2799 | ||
2800 | case MII_TG3_AUX_STAT_100HALF: | |
2801 | *speed = SPEED_100; | |
2802 | *duplex = DUPLEX_HALF; | |
2803 | break; | |
2804 | ||
2805 | case MII_TG3_AUX_STAT_100FULL: | |
2806 | *speed = SPEED_100; | |
2807 | *duplex = DUPLEX_FULL; | |
2808 | break; | |
2809 | ||
2810 | case MII_TG3_AUX_STAT_1000HALF: | |
2811 | *speed = SPEED_1000; | |
2812 | *duplex = DUPLEX_HALF; | |
2813 | break; | |
2814 | ||
2815 | case MII_TG3_AUX_STAT_1000FULL: | |
2816 | *speed = SPEED_1000; | |
2817 | *duplex = DUPLEX_FULL; | |
2818 | break; | |
2819 | ||
2820 | default: | |
f07e9af3 | 2821 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
715116a1 MC |
2822 | *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 : |
2823 | SPEED_10; | |
2824 | *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL : | |
2825 | DUPLEX_HALF; | |
2826 | break; | |
2827 | } | |
1da177e4 LT |
2828 | *speed = SPEED_INVALID; |
2829 | *duplex = DUPLEX_INVALID; | |
2830 | break; | |
855e1111 | 2831 | } |
1da177e4 LT |
2832 | } |
2833 | ||
2834 | static void tg3_phy_copper_begin(struct tg3 *tp) | |
2835 | { | |
2836 | u32 new_adv; | |
2837 | int i; | |
2838 | ||
80096068 | 2839 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
1da177e4 LT |
2840 | /* Entering low power mode. Disable gigabit and |
2841 | * 100baseT advertisements. | |
2842 | */ | |
2843 | tg3_writephy(tp, MII_TG3_CTRL, 0); | |
2844 | ||
2845 | new_adv = (ADVERTISE_10HALF | ADVERTISE_10FULL | | |
2846 | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); | |
2847 | if (tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB) | |
2848 | new_adv |= (ADVERTISE_100HALF | ADVERTISE_100FULL); | |
2849 | ||
2850 | tg3_writephy(tp, MII_ADVERTISE, new_adv); | |
2851 | } else if (tp->link_config.speed == SPEED_INVALID) { | |
f07e9af3 | 2852 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
1da177e4 LT |
2853 | tp->link_config.advertising &= |
2854 | ~(ADVERTISED_1000baseT_Half | | |
2855 | ADVERTISED_1000baseT_Full); | |
2856 | ||
ba4d07a8 | 2857 | new_adv = ADVERTISE_CSMA; |
1da177e4 LT |
2858 | if (tp->link_config.advertising & ADVERTISED_10baseT_Half) |
2859 | new_adv |= ADVERTISE_10HALF; | |
2860 | if (tp->link_config.advertising & ADVERTISED_10baseT_Full) | |
2861 | new_adv |= ADVERTISE_10FULL; | |
2862 | if (tp->link_config.advertising & ADVERTISED_100baseT_Half) | |
2863 | new_adv |= ADVERTISE_100HALF; | |
2864 | if (tp->link_config.advertising & ADVERTISED_100baseT_Full) | |
2865 | new_adv |= ADVERTISE_100FULL; | |
ba4d07a8 MC |
2866 | |
2867 | new_adv |= tg3_advert_flowctrl_1000T(tp->link_config.flowctrl); | |
2868 | ||
1da177e4 LT |
2869 | tg3_writephy(tp, MII_ADVERTISE, new_adv); |
2870 | ||
2871 | if (tp->link_config.advertising & | |
2872 | (ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full)) { | |
2873 | new_adv = 0; | |
2874 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Half) | |
2875 | new_adv |= MII_TG3_CTRL_ADV_1000_HALF; | |
2876 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Full) | |
2877 | new_adv |= MII_TG3_CTRL_ADV_1000_FULL; | |
f07e9af3 | 2878 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY) && |
1da177e4 LT |
2879 | (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || |
2880 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0)) | |
2881 | new_adv |= (MII_TG3_CTRL_AS_MASTER | | |
2882 | MII_TG3_CTRL_ENABLE_AS_MASTER); | |
2883 | tg3_writephy(tp, MII_TG3_CTRL, new_adv); | |
2884 | } else { | |
2885 | tg3_writephy(tp, MII_TG3_CTRL, 0); | |
2886 | } | |
2887 | } else { | |
ba4d07a8 MC |
2888 | new_adv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl); |
2889 | new_adv |= ADVERTISE_CSMA; | |
2890 | ||
1da177e4 LT |
2891 | /* Asking for a specific link mode. */ |
2892 | if (tp->link_config.speed == SPEED_1000) { | |
1da177e4 LT |
2893 | tg3_writephy(tp, MII_ADVERTISE, new_adv); |
2894 | ||
2895 | if (tp->link_config.duplex == DUPLEX_FULL) | |
2896 | new_adv = MII_TG3_CTRL_ADV_1000_FULL; | |
2897 | else | |
2898 | new_adv = MII_TG3_CTRL_ADV_1000_HALF; | |
2899 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || | |
2900 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) | |
2901 | new_adv |= (MII_TG3_CTRL_AS_MASTER | | |
2902 | MII_TG3_CTRL_ENABLE_AS_MASTER); | |
1da177e4 | 2903 | } else { |
1da177e4 LT |
2904 | if (tp->link_config.speed == SPEED_100) { |
2905 | if (tp->link_config.duplex == DUPLEX_FULL) | |
2906 | new_adv |= ADVERTISE_100FULL; | |
2907 | else | |
2908 | new_adv |= ADVERTISE_100HALF; | |
2909 | } else { | |
2910 | if (tp->link_config.duplex == DUPLEX_FULL) | |
2911 | new_adv |= ADVERTISE_10FULL; | |
2912 | else | |
2913 | new_adv |= ADVERTISE_10HALF; | |
2914 | } | |
2915 | tg3_writephy(tp, MII_ADVERTISE, new_adv); | |
ba4d07a8 MC |
2916 | |
2917 | new_adv = 0; | |
1da177e4 | 2918 | } |
ba4d07a8 MC |
2919 | |
2920 | tg3_writephy(tp, MII_TG3_CTRL, new_adv); | |
1da177e4 LT |
2921 | } |
2922 | ||
2923 | if (tp->link_config.autoneg == AUTONEG_DISABLE && | |
2924 | tp->link_config.speed != SPEED_INVALID) { | |
2925 | u32 bmcr, orig_bmcr; | |
2926 | ||
2927 | tp->link_config.active_speed = tp->link_config.speed; | |
2928 | tp->link_config.active_duplex = tp->link_config.duplex; | |
2929 | ||
2930 | bmcr = 0; | |
2931 | switch (tp->link_config.speed) { | |
2932 | default: | |
2933 | case SPEED_10: | |
2934 | break; | |
2935 | ||
2936 | case SPEED_100: | |
2937 | bmcr |= BMCR_SPEED100; | |
2938 | break; | |
2939 | ||
2940 | case SPEED_1000: | |
2941 | bmcr |= TG3_BMCR_SPEED1000; | |
2942 | break; | |
855e1111 | 2943 | } |
1da177e4 LT |
2944 | |
2945 | if (tp->link_config.duplex == DUPLEX_FULL) | |
2946 | bmcr |= BMCR_FULLDPLX; | |
2947 | ||
2948 | if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) && | |
2949 | (bmcr != orig_bmcr)) { | |
2950 | tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK); | |
2951 | for (i = 0; i < 1500; i++) { | |
2952 | u32 tmp; | |
2953 | ||
2954 | udelay(10); | |
2955 | if (tg3_readphy(tp, MII_BMSR, &tmp) || | |
2956 | tg3_readphy(tp, MII_BMSR, &tmp)) | |
2957 | continue; | |
2958 | if (!(tmp & BMSR_LSTATUS)) { | |
2959 | udelay(40); | |
2960 | break; | |
2961 | } | |
2962 | } | |
2963 | tg3_writephy(tp, MII_BMCR, bmcr); | |
2964 | udelay(40); | |
2965 | } | |
2966 | } else { | |
2967 | tg3_writephy(tp, MII_BMCR, | |
2968 | BMCR_ANENABLE | BMCR_ANRESTART); | |
2969 | } | |
2970 | } | |
2971 | ||
2972 | static int tg3_init_5401phy_dsp(struct tg3 *tp) | |
2973 | { | |
2974 | int err; | |
2975 | ||
2976 | /* Turn off tap power management. */ | |
2977 | /* Set Extended packet length bit */ | |
2978 | err = tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4c20); | |
2979 | ||
6ee7c0a0 MC |
2980 | err |= tg3_phydsp_write(tp, 0x0012, 0x1804); |
2981 | err |= tg3_phydsp_write(tp, 0x0013, 0x1204); | |
2982 | err |= tg3_phydsp_write(tp, 0x8006, 0x0132); | |
2983 | err |= tg3_phydsp_write(tp, 0x8006, 0x0232); | |
2984 | err |= tg3_phydsp_write(tp, 0x201f, 0x0a20); | |
1da177e4 LT |
2985 | |
2986 | udelay(40); | |
2987 | ||
2988 | return err; | |
2989 | } | |
2990 | ||
3600d918 | 2991 | static int tg3_copper_is_advertising_all(struct tg3 *tp, u32 mask) |
1da177e4 | 2992 | { |
3600d918 MC |
2993 | u32 adv_reg, all_mask = 0; |
2994 | ||
2995 | if (mask & ADVERTISED_10baseT_Half) | |
2996 | all_mask |= ADVERTISE_10HALF; | |
2997 | if (mask & ADVERTISED_10baseT_Full) | |
2998 | all_mask |= ADVERTISE_10FULL; | |
2999 | if (mask & ADVERTISED_100baseT_Half) | |
3000 | all_mask |= ADVERTISE_100HALF; | |
3001 | if (mask & ADVERTISED_100baseT_Full) | |
3002 | all_mask |= ADVERTISE_100FULL; | |
1da177e4 LT |
3003 | |
3004 | if (tg3_readphy(tp, MII_ADVERTISE, &adv_reg)) | |
3005 | return 0; | |
3006 | ||
1da177e4 LT |
3007 | if ((adv_reg & all_mask) != all_mask) |
3008 | return 0; | |
f07e9af3 | 3009 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
1da177e4 LT |
3010 | u32 tg3_ctrl; |
3011 | ||
3600d918 MC |
3012 | all_mask = 0; |
3013 | if (mask & ADVERTISED_1000baseT_Half) | |
3014 | all_mask |= ADVERTISE_1000HALF; | |
3015 | if (mask & ADVERTISED_1000baseT_Full) | |
3016 | all_mask |= ADVERTISE_1000FULL; | |
3017 | ||
1da177e4 LT |
3018 | if (tg3_readphy(tp, MII_TG3_CTRL, &tg3_ctrl)) |
3019 | return 0; | |
3020 | ||
1da177e4 LT |
3021 | if ((tg3_ctrl & all_mask) != all_mask) |
3022 | return 0; | |
3023 | } | |
3024 | return 1; | |
3025 | } | |
3026 | ||
ef167e27 MC |
3027 | static int tg3_adv_1000T_flowctrl_ok(struct tg3 *tp, u32 *lcladv, u32 *rmtadv) |
3028 | { | |
3029 | u32 curadv, reqadv; | |
3030 | ||
3031 | if (tg3_readphy(tp, MII_ADVERTISE, lcladv)) | |
3032 | return 1; | |
3033 | ||
3034 | curadv = *lcladv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM); | |
3035 | reqadv = tg3_advert_flowctrl_1000T(tp->link_config.flowctrl); | |
3036 | ||
3037 | if (tp->link_config.active_duplex == DUPLEX_FULL) { | |
3038 | if (curadv != reqadv) | |
3039 | return 0; | |
3040 | ||
3041 | if (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) | |
3042 | tg3_readphy(tp, MII_LPA, rmtadv); | |
3043 | } else { | |
3044 | /* Reprogram the advertisement register, even if it | |
3045 | * does not affect the current link. If the link | |
3046 | * gets renegotiated in the future, we can save an | |
3047 | * additional renegotiation cycle by advertising | |
3048 | * it correctly in the first place. | |
3049 | */ | |
3050 | if (curadv != reqadv) { | |
3051 | *lcladv &= ~(ADVERTISE_PAUSE_CAP | | |
3052 | ADVERTISE_PAUSE_ASYM); | |
3053 | tg3_writephy(tp, MII_ADVERTISE, *lcladv | reqadv); | |
3054 | } | |
3055 | } | |
3056 | ||
3057 | return 1; | |
3058 | } | |
3059 | ||
1da177e4 LT |
3060 | static int tg3_setup_copper_phy(struct tg3 *tp, int force_reset) |
3061 | { | |
3062 | int current_link_up; | |
3063 | u32 bmsr, dummy; | |
ef167e27 | 3064 | u32 lcl_adv, rmt_adv; |
1da177e4 LT |
3065 | u16 current_speed; |
3066 | u8 current_duplex; | |
3067 | int i, err; | |
3068 | ||
3069 | tw32(MAC_EVENT, 0); | |
3070 | ||
3071 | tw32_f(MAC_STATUS, | |
3072 | (MAC_STATUS_SYNC_CHANGED | | |
3073 | MAC_STATUS_CFG_CHANGED | | |
3074 | MAC_STATUS_MI_COMPLETION | | |
3075 | MAC_STATUS_LNKSTATE_CHANGED)); | |
3076 | udelay(40); | |
3077 | ||
8ef21428 MC |
3078 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
3079 | tw32_f(MAC_MI_MODE, | |
3080 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); | |
3081 | udelay(80); | |
3082 | } | |
1da177e4 LT |
3083 | |
3084 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x02); | |
3085 | ||
3086 | /* Some third-party PHYs need to be reset on link going | |
3087 | * down. | |
3088 | */ | |
3089 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || | |
3090 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || | |
3091 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && | |
3092 | netif_carrier_ok(tp->dev)) { | |
3093 | tg3_readphy(tp, MII_BMSR, &bmsr); | |
3094 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && | |
3095 | !(bmsr & BMSR_LSTATUS)) | |
3096 | force_reset = 1; | |
3097 | } | |
3098 | if (force_reset) | |
3099 | tg3_phy_reset(tp); | |
3100 | ||
79eb6904 | 3101 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
1da177e4 LT |
3102 | tg3_readphy(tp, MII_BMSR, &bmsr); |
3103 | if (tg3_readphy(tp, MII_BMSR, &bmsr) || | |
3104 | !(tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) | |
3105 | bmsr = 0; | |
3106 | ||
3107 | if (!(bmsr & BMSR_LSTATUS)) { | |
3108 | err = tg3_init_5401phy_dsp(tp); | |
3109 | if (err) | |
3110 | return err; | |
3111 | ||
3112 | tg3_readphy(tp, MII_BMSR, &bmsr); | |
3113 | for (i = 0; i < 1000; i++) { | |
3114 | udelay(10); | |
3115 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && | |
3116 | (bmsr & BMSR_LSTATUS)) { | |
3117 | udelay(40); | |
3118 | break; | |
3119 | } | |
3120 | } | |
3121 | ||
79eb6904 MC |
3122 | if ((tp->phy_id & TG3_PHY_ID_REV_MASK) == |
3123 | TG3_PHY_REV_BCM5401_B0 && | |
1da177e4 LT |
3124 | !(bmsr & BMSR_LSTATUS) && |
3125 | tp->link_config.active_speed == SPEED_1000) { | |
3126 | err = tg3_phy_reset(tp); | |
3127 | if (!err) | |
3128 | err = tg3_init_5401phy_dsp(tp); | |
3129 | if (err) | |
3130 | return err; | |
3131 | } | |
3132 | } | |
3133 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || | |
3134 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) { | |
3135 | /* 5701 {A0,B0} CRC bug workaround */ | |
3136 | tg3_writephy(tp, 0x15, 0x0a75); | |
f08aa1a8 MC |
3137 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
3138 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); | |
3139 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); | |
1da177e4 LT |
3140 | } |
3141 | ||
3142 | /* Clear pending interrupts... */ | |
3143 | tg3_readphy(tp, MII_TG3_ISTAT, &dummy); | |
3144 | tg3_readphy(tp, MII_TG3_ISTAT, &dummy); | |
3145 | ||
f07e9af3 | 3146 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) |
1da177e4 | 3147 | tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG); |
f07e9af3 | 3148 | else if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) |
1da177e4 LT |
3149 | tg3_writephy(tp, MII_TG3_IMASK, ~0); |
3150 | ||
3151 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
3152 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { | |
3153 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_1) | |
3154 | tg3_writephy(tp, MII_TG3_EXT_CTRL, | |
3155 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); | |
3156 | else | |
3157 | tg3_writephy(tp, MII_TG3_EXT_CTRL, 0); | |
3158 | } | |
3159 | ||
3160 | current_link_up = 0; | |
3161 | current_speed = SPEED_INVALID; | |
3162 | current_duplex = DUPLEX_INVALID; | |
3163 | ||
f07e9af3 | 3164 | if (tp->phy_flags & TG3_PHYFLG_CAPACITIVE_COUPLING) { |
1da177e4 LT |
3165 | u32 val; |
3166 | ||
3167 | tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x4007); | |
3168 | tg3_readphy(tp, MII_TG3_AUX_CTRL, &val); | |
3169 | if (!(val & (1 << 10))) { | |
3170 | val |= (1 << 10); | |
3171 | tg3_writephy(tp, MII_TG3_AUX_CTRL, val); | |
3172 | goto relink; | |
3173 | } | |
3174 | } | |
3175 | ||
3176 | bmsr = 0; | |
3177 | for (i = 0; i < 100; i++) { | |
3178 | tg3_readphy(tp, MII_BMSR, &bmsr); | |
3179 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && | |
3180 | (bmsr & BMSR_LSTATUS)) | |
3181 | break; | |
3182 | udelay(40); | |
3183 | } | |
3184 | ||
3185 | if (bmsr & BMSR_LSTATUS) { | |
3186 | u32 aux_stat, bmcr; | |
3187 | ||
3188 | tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat); | |
3189 | for (i = 0; i < 2000; i++) { | |
3190 | udelay(10); | |
3191 | if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) && | |
3192 | aux_stat) | |
3193 | break; | |
3194 | } | |
3195 | ||
3196 | tg3_aux_stat_to_speed_duplex(tp, aux_stat, | |
3197 | ¤t_speed, | |
3198 | ¤t_duplex); | |
3199 | ||
3200 | bmcr = 0; | |
3201 | for (i = 0; i < 200; i++) { | |
3202 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
3203 | if (tg3_readphy(tp, MII_BMCR, &bmcr)) | |
3204 | continue; | |
3205 | if (bmcr && bmcr != 0x7fff) | |
3206 | break; | |
3207 | udelay(10); | |
3208 | } | |
3209 | ||
ef167e27 MC |
3210 | lcl_adv = 0; |
3211 | rmt_adv = 0; | |
1da177e4 | 3212 | |
ef167e27 MC |
3213 | tp->link_config.active_speed = current_speed; |
3214 | tp->link_config.active_duplex = current_duplex; | |
3215 | ||
3216 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { | |
3217 | if ((bmcr & BMCR_ANENABLE) && | |
3218 | tg3_copper_is_advertising_all(tp, | |
3219 | tp->link_config.advertising)) { | |
3220 | if (tg3_adv_1000T_flowctrl_ok(tp, &lcl_adv, | |
3221 | &rmt_adv)) | |
3222 | current_link_up = 1; | |
1da177e4 LT |
3223 | } |
3224 | } else { | |
3225 | if (!(bmcr & BMCR_ANENABLE) && | |
3226 | tp->link_config.speed == current_speed && | |
ef167e27 MC |
3227 | tp->link_config.duplex == current_duplex && |
3228 | tp->link_config.flowctrl == | |
3229 | tp->link_config.active_flowctrl) { | |
1da177e4 | 3230 | current_link_up = 1; |
1da177e4 LT |
3231 | } |
3232 | } | |
3233 | ||
ef167e27 MC |
3234 | if (current_link_up == 1 && |
3235 | tp->link_config.active_duplex == DUPLEX_FULL) | |
3236 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); | |
1da177e4 LT |
3237 | } |
3238 | ||
1da177e4 | 3239 | relink: |
80096068 | 3240 | if (current_link_up == 0 || (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
1da177e4 LT |
3241 | u32 tmp; |
3242 | ||
3243 | tg3_phy_copper_begin(tp); | |
3244 | ||
3245 | tg3_readphy(tp, MII_BMSR, &tmp); | |
3246 | if (!tg3_readphy(tp, MII_BMSR, &tmp) && | |
3247 | (tmp & BMSR_LSTATUS)) | |
3248 | current_link_up = 1; | |
3249 | } | |
3250 | ||
3251 | tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; | |
3252 | if (current_link_up == 1) { | |
3253 | if (tp->link_config.active_speed == SPEED_100 || | |
3254 | tp->link_config.active_speed == SPEED_10) | |
3255 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; | |
3256 | else | |
3257 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
f07e9af3 | 3258 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
7f97a4bd MC |
3259 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
3260 | else | |
1da177e4 LT |
3261 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
3262 | ||
3263 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; | |
3264 | if (tp->link_config.active_duplex == DUPLEX_HALF) | |
3265 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; | |
3266 | ||
1da177e4 | 3267 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
e8f3f6ca MC |
3268 | if (current_link_up == 1 && |
3269 | tg3_5700_link_polarity(tp, tp->link_config.active_speed)) | |
1da177e4 | 3270 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
e8f3f6ca MC |
3271 | else |
3272 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; | |
1da177e4 LT |
3273 | } |
3274 | ||
3275 | /* ??? Without this setting Netgear GA302T PHY does not | |
3276 | * ??? send/receive packets... | |
3277 | */ | |
79eb6904 | 3278 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411 && |
1da177e4 LT |
3279 | tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) { |
3280 | tp->mi_mode |= MAC_MI_MODE_AUTO_POLL; | |
3281 | tw32_f(MAC_MI_MODE, tp->mi_mode); | |
3282 | udelay(80); | |
3283 | } | |
3284 | ||
3285 | tw32_f(MAC_MODE, tp->mac_mode); | |
3286 | udelay(40); | |
3287 | ||
3288 | if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) { | |
3289 | /* Polled via timer. */ | |
3290 | tw32_f(MAC_EVENT, 0); | |
3291 | } else { | |
3292 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); | |
3293 | } | |
3294 | udelay(40); | |
3295 | ||
3296 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 && | |
3297 | current_link_up == 1 && | |
3298 | tp->link_config.active_speed == SPEED_1000 && | |
3299 | ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) || | |
3300 | (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED))) { | |
3301 | udelay(120); | |
3302 | tw32_f(MAC_STATUS, | |
3303 | (MAC_STATUS_SYNC_CHANGED | | |
3304 | MAC_STATUS_CFG_CHANGED)); | |
3305 | udelay(40); | |
3306 | tg3_write_mem(tp, | |
3307 | NIC_SRAM_FIRMWARE_MBOX, | |
3308 | NIC_SRAM_FIRMWARE_MBOX_MAGIC2); | |
3309 | } | |
3310 | ||
5e7dfd0f MC |
3311 | /* Prevent send BD corruption. */ |
3312 | if (tp->tg3_flags3 & TG3_FLG3_CLKREQ_BUG) { | |
3313 | u16 oldlnkctl, newlnkctl; | |
3314 | ||
3315 | pci_read_config_word(tp->pdev, | |
3316 | tp->pcie_cap + PCI_EXP_LNKCTL, | |
3317 | &oldlnkctl); | |
3318 | if (tp->link_config.active_speed == SPEED_100 || | |
3319 | tp->link_config.active_speed == SPEED_10) | |
3320 | newlnkctl = oldlnkctl & ~PCI_EXP_LNKCTL_CLKREQ_EN; | |
3321 | else | |
3322 | newlnkctl = oldlnkctl | PCI_EXP_LNKCTL_CLKREQ_EN; | |
3323 | if (newlnkctl != oldlnkctl) | |
3324 | pci_write_config_word(tp->pdev, | |
3325 | tp->pcie_cap + PCI_EXP_LNKCTL, | |
3326 | newlnkctl); | |
3327 | } | |
3328 | ||
1da177e4 LT |
3329 | if (current_link_up != netif_carrier_ok(tp->dev)) { |
3330 | if (current_link_up) | |
3331 | netif_carrier_on(tp->dev); | |
3332 | else | |
3333 | netif_carrier_off(tp->dev); | |
3334 | tg3_link_report(tp); | |
3335 | } | |
3336 | ||
3337 | return 0; | |
3338 | } | |
3339 | ||
3340 | struct tg3_fiber_aneginfo { | |
3341 | int state; | |
3342 | #define ANEG_STATE_UNKNOWN 0 | |
3343 | #define ANEG_STATE_AN_ENABLE 1 | |
3344 | #define ANEG_STATE_RESTART_INIT 2 | |
3345 | #define ANEG_STATE_RESTART 3 | |
3346 | #define ANEG_STATE_DISABLE_LINK_OK 4 | |
3347 | #define ANEG_STATE_ABILITY_DETECT_INIT 5 | |
3348 | #define ANEG_STATE_ABILITY_DETECT 6 | |
3349 | #define ANEG_STATE_ACK_DETECT_INIT 7 | |
3350 | #define ANEG_STATE_ACK_DETECT 8 | |
3351 | #define ANEG_STATE_COMPLETE_ACK_INIT 9 | |
3352 | #define ANEG_STATE_COMPLETE_ACK 10 | |
3353 | #define ANEG_STATE_IDLE_DETECT_INIT 11 | |
3354 | #define ANEG_STATE_IDLE_DETECT 12 | |
3355 | #define ANEG_STATE_LINK_OK 13 | |
3356 | #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14 | |
3357 | #define ANEG_STATE_NEXT_PAGE_WAIT 15 | |
3358 | ||
3359 | u32 flags; | |
3360 | #define MR_AN_ENABLE 0x00000001 | |
3361 | #define MR_RESTART_AN 0x00000002 | |
3362 | #define MR_AN_COMPLETE 0x00000004 | |
3363 | #define MR_PAGE_RX 0x00000008 | |
3364 | #define MR_NP_LOADED 0x00000010 | |
3365 | #define MR_TOGGLE_TX 0x00000020 | |
3366 | #define MR_LP_ADV_FULL_DUPLEX 0x00000040 | |
3367 | #define MR_LP_ADV_HALF_DUPLEX 0x00000080 | |
3368 | #define MR_LP_ADV_SYM_PAUSE 0x00000100 | |
3369 | #define MR_LP_ADV_ASYM_PAUSE 0x00000200 | |
3370 | #define MR_LP_ADV_REMOTE_FAULT1 0x00000400 | |
3371 | #define MR_LP_ADV_REMOTE_FAULT2 0x00000800 | |
3372 | #define MR_LP_ADV_NEXT_PAGE 0x00001000 | |
3373 | #define MR_TOGGLE_RX 0x00002000 | |
3374 | #define MR_NP_RX 0x00004000 | |
3375 | ||
3376 | #define MR_LINK_OK 0x80000000 | |
3377 | ||
3378 | unsigned long link_time, cur_time; | |
3379 | ||
3380 | u32 ability_match_cfg; | |
3381 | int ability_match_count; | |
3382 | ||
3383 | char ability_match, idle_match, ack_match; | |
3384 | ||
3385 | u32 txconfig, rxconfig; | |
3386 | #define ANEG_CFG_NP 0x00000080 | |
3387 | #define ANEG_CFG_ACK 0x00000040 | |
3388 | #define ANEG_CFG_RF2 0x00000020 | |
3389 | #define ANEG_CFG_RF1 0x00000010 | |
3390 | #define ANEG_CFG_PS2 0x00000001 | |
3391 | #define ANEG_CFG_PS1 0x00008000 | |
3392 | #define ANEG_CFG_HD 0x00004000 | |
3393 | #define ANEG_CFG_FD 0x00002000 | |
3394 | #define ANEG_CFG_INVAL 0x00001f06 | |
3395 | ||
3396 | }; | |
3397 | #define ANEG_OK 0 | |
3398 | #define ANEG_DONE 1 | |
3399 | #define ANEG_TIMER_ENAB 2 | |
3400 | #define ANEG_FAILED -1 | |
3401 | ||
3402 | #define ANEG_STATE_SETTLE_TIME 10000 | |
3403 | ||
3404 | static int tg3_fiber_aneg_smachine(struct tg3 *tp, | |
3405 | struct tg3_fiber_aneginfo *ap) | |
3406 | { | |
5be73b47 | 3407 | u16 flowctrl; |
1da177e4 LT |
3408 | unsigned long delta; |
3409 | u32 rx_cfg_reg; | |
3410 | int ret; | |
3411 | ||
3412 | if (ap->state == ANEG_STATE_UNKNOWN) { | |
3413 | ap->rxconfig = 0; | |
3414 | ap->link_time = 0; | |
3415 | ap->cur_time = 0; | |
3416 | ap->ability_match_cfg = 0; | |
3417 | ap->ability_match_count = 0; | |
3418 | ap->ability_match = 0; | |
3419 | ap->idle_match = 0; | |
3420 | ap->ack_match = 0; | |
3421 | } | |
3422 | ap->cur_time++; | |
3423 | ||
3424 | if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) { | |
3425 | rx_cfg_reg = tr32(MAC_RX_AUTO_NEG); | |
3426 | ||
3427 | if (rx_cfg_reg != ap->ability_match_cfg) { | |
3428 | ap->ability_match_cfg = rx_cfg_reg; | |
3429 | ap->ability_match = 0; | |
3430 | ap->ability_match_count = 0; | |
3431 | } else { | |
3432 | if (++ap->ability_match_count > 1) { | |
3433 | ap->ability_match = 1; | |
3434 | ap->ability_match_cfg = rx_cfg_reg; | |
3435 | } | |
3436 | } | |
3437 | if (rx_cfg_reg & ANEG_CFG_ACK) | |
3438 | ap->ack_match = 1; | |
3439 | else | |
3440 | ap->ack_match = 0; | |
3441 | ||
3442 | ap->idle_match = 0; | |
3443 | } else { | |
3444 | ap->idle_match = 1; | |
3445 | ap->ability_match_cfg = 0; | |
3446 | ap->ability_match_count = 0; | |
3447 | ap->ability_match = 0; | |
3448 | ap->ack_match = 0; | |
3449 | ||
3450 | rx_cfg_reg = 0; | |
3451 | } | |
3452 | ||
3453 | ap->rxconfig = rx_cfg_reg; | |
3454 | ret = ANEG_OK; | |
3455 | ||
33f401ae | 3456 | switch (ap->state) { |
1da177e4 LT |
3457 | case ANEG_STATE_UNKNOWN: |
3458 | if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN)) | |
3459 | ap->state = ANEG_STATE_AN_ENABLE; | |
3460 | ||
3461 | /* fallthru */ | |
3462 | case ANEG_STATE_AN_ENABLE: | |
3463 | ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX); | |
3464 | if (ap->flags & MR_AN_ENABLE) { | |
3465 | ap->link_time = 0; | |
3466 | ap->cur_time = 0; | |
3467 | ap->ability_match_cfg = 0; | |
3468 | ap->ability_match_count = 0; | |
3469 | ap->ability_match = 0; | |
3470 | ap->idle_match = 0; | |
3471 | ap->ack_match = 0; | |
3472 | ||
3473 | ap->state = ANEG_STATE_RESTART_INIT; | |
3474 | } else { | |
3475 | ap->state = ANEG_STATE_DISABLE_LINK_OK; | |
3476 | } | |
3477 | break; | |
3478 | ||
3479 | case ANEG_STATE_RESTART_INIT: | |
3480 | ap->link_time = ap->cur_time; | |
3481 | ap->flags &= ~(MR_NP_LOADED); | |
3482 | ap->txconfig = 0; | |
3483 | tw32(MAC_TX_AUTO_NEG, 0); | |
3484 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; | |
3485 | tw32_f(MAC_MODE, tp->mac_mode); | |
3486 | udelay(40); | |
3487 | ||
3488 | ret = ANEG_TIMER_ENAB; | |
3489 | ap->state = ANEG_STATE_RESTART; | |
3490 | ||
3491 | /* fallthru */ | |
3492 | case ANEG_STATE_RESTART: | |
3493 | delta = ap->cur_time - ap->link_time; | |
859a5887 | 3494 | if (delta > ANEG_STATE_SETTLE_TIME) |
1da177e4 | 3495 | ap->state = ANEG_STATE_ABILITY_DETECT_INIT; |
859a5887 | 3496 | else |
1da177e4 | 3497 | ret = ANEG_TIMER_ENAB; |
1da177e4 LT |
3498 | break; |
3499 | ||
3500 | case ANEG_STATE_DISABLE_LINK_OK: | |
3501 | ret = ANEG_DONE; | |
3502 | break; | |
3503 | ||
3504 | case ANEG_STATE_ABILITY_DETECT_INIT: | |
3505 | ap->flags &= ~(MR_TOGGLE_TX); | |
5be73b47 MC |
3506 | ap->txconfig = ANEG_CFG_FD; |
3507 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); | |
3508 | if (flowctrl & ADVERTISE_1000XPAUSE) | |
3509 | ap->txconfig |= ANEG_CFG_PS1; | |
3510 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) | |
3511 | ap->txconfig |= ANEG_CFG_PS2; | |
1da177e4 LT |
3512 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
3513 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; | |
3514 | tw32_f(MAC_MODE, tp->mac_mode); | |
3515 | udelay(40); | |
3516 | ||
3517 | ap->state = ANEG_STATE_ABILITY_DETECT; | |
3518 | break; | |
3519 | ||
3520 | case ANEG_STATE_ABILITY_DETECT: | |
859a5887 | 3521 | if (ap->ability_match != 0 && ap->rxconfig != 0) |
1da177e4 | 3522 | ap->state = ANEG_STATE_ACK_DETECT_INIT; |
1da177e4 LT |
3523 | break; |
3524 | ||
3525 | case ANEG_STATE_ACK_DETECT_INIT: | |
3526 | ap->txconfig |= ANEG_CFG_ACK; | |
3527 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); | |
3528 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; | |
3529 | tw32_f(MAC_MODE, tp->mac_mode); | |
3530 | udelay(40); | |
3531 | ||
3532 | ap->state = ANEG_STATE_ACK_DETECT; | |
3533 | ||
3534 | /* fallthru */ | |
3535 | case ANEG_STATE_ACK_DETECT: | |
3536 | if (ap->ack_match != 0) { | |
3537 | if ((ap->rxconfig & ~ANEG_CFG_ACK) == | |
3538 | (ap->ability_match_cfg & ~ANEG_CFG_ACK)) { | |
3539 | ap->state = ANEG_STATE_COMPLETE_ACK_INIT; | |
3540 | } else { | |
3541 | ap->state = ANEG_STATE_AN_ENABLE; | |
3542 | } | |
3543 | } else if (ap->ability_match != 0 && | |
3544 | ap->rxconfig == 0) { | |
3545 | ap->state = ANEG_STATE_AN_ENABLE; | |
3546 | } | |
3547 | break; | |
3548 | ||
3549 | case ANEG_STATE_COMPLETE_ACK_INIT: | |
3550 | if (ap->rxconfig & ANEG_CFG_INVAL) { | |
3551 | ret = ANEG_FAILED; | |
3552 | break; | |
3553 | } | |
3554 | ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX | | |
3555 | MR_LP_ADV_HALF_DUPLEX | | |
3556 | MR_LP_ADV_SYM_PAUSE | | |
3557 | MR_LP_ADV_ASYM_PAUSE | | |
3558 | MR_LP_ADV_REMOTE_FAULT1 | | |
3559 | MR_LP_ADV_REMOTE_FAULT2 | | |
3560 | MR_LP_ADV_NEXT_PAGE | | |
3561 | MR_TOGGLE_RX | | |
3562 | MR_NP_RX); | |
3563 | if (ap->rxconfig & ANEG_CFG_FD) | |
3564 | ap->flags |= MR_LP_ADV_FULL_DUPLEX; | |
3565 | if (ap->rxconfig & ANEG_CFG_HD) | |
3566 | ap->flags |= MR_LP_ADV_HALF_DUPLEX; | |
3567 | if (ap->rxconfig & ANEG_CFG_PS1) | |
3568 | ap->flags |= MR_LP_ADV_SYM_PAUSE; | |
3569 | if (ap->rxconfig & ANEG_CFG_PS2) | |
3570 | ap->flags |= MR_LP_ADV_ASYM_PAUSE; | |
3571 | if (ap->rxconfig & ANEG_CFG_RF1) | |
3572 | ap->flags |= MR_LP_ADV_REMOTE_FAULT1; | |
3573 | if (ap->rxconfig & ANEG_CFG_RF2) | |
3574 | ap->flags |= MR_LP_ADV_REMOTE_FAULT2; | |
3575 | if (ap->rxconfig & ANEG_CFG_NP) | |
3576 | ap->flags |= MR_LP_ADV_NEXT_PAGE; | |
3577 | ||
3578 | ap->link_time = ap->cur_time; | |
3579 | ||
3580 | ap->flags ^= (MR_TOGGLE_TX); | |
3581 | if (ap->rxconfig & 0x0008) | |
3582 | ap->flags |= MR_TOGGLE_RX; | |
3583 | if (ap->rxconfig & ANEG_CFG_NP) | |
3584 | ap->flags |= MR_NP_RX; | |
3585 | ap->flags |= MR_PAGE_RX; | |
3586 | ||
3587 | ap->state = ANEG_STATE_COMPLETE_ACK; | |
3588 | ret = ANEG_TIMER_ENAB; | |
3589 | break; | |
3590 | ||
3591 | case ANEG_STATE_COMPLETE_ACK: | |
3592 | if (ap->ability_match != 0 && | |
3593 | ap->rxconfig == 0) { | |
3594 | ap->state = ANEG_STATE_AN_ENABLE; | |
3595 | break; | |
3596 | } | |
3597 | delta = ap->cur_time - ap->link_time; | |
3598 | if (delta > ANEG_STATE_SETTLE_TIME) { | |
3599 | if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) { | |
3600 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; | |
3601 | } else { | |
3602 | if ((ap->txconfig & ANEG_CFG_NP) == 0 && | |
3603 | !(ap->flags & MR_NP_RX)) { | |
3604 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; | |
3605 | } else { | |
3606 | ret = ANEG_FAILED; | |
3607 | } | |
3608 | } | |
3609 | } | |
3610 | break; | |
3611 | ||
3612 | case ANEG_STATE_IDLE_DETECT_INIT: | |
3613 | ap->link_time = ap->cur_time; | |
3614 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; | |
3615 | tw32_f(MAC_MODE, tp->mac_mode); | |
3616 | udelay(40); | |
3617 | ||
3618 | ap->state = ANEG_STATE_IDLE_DETECT; | |
3619 | ret = ANEG_TIMER_ENAB; | |
3620 | break; | |
3621 | ||
3622 | case ANEG_STATE_IDLE_DETECT: | |
3623 | if (ap->ability_match != 0 && | |
3624 | ap->rxconfig == 0) { | |
3625 | ap->state = ANEG_STATE_AN_ENABLE; | |
3626 | break; | |
3627 | } | |
3628 | delta = ap->cur_time - ap->link_time; | |
3629 | if (delta > ANEG_STATE_SETTLE_TIME) { | |
3630 | /* XXX another gem from the Broadcom driver :( */ | |
3631 | ap->state = ANEG_STATE_LINK_OK; | |
3632 | } | |
3633 | break; | |
3634 | ||
3635 | case ANEG_STATE_LINK_OK: | |
3636 | ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK); | |
3637 | ret = ANEG_DONE; | |
3638 | break; | |
3639 | ||
3640 | case ANEG_STATE_NEXT_PAGE_WAIT_INIT: | |
3641 | /* ??? unimplemented */ | |
3642 | break; | |
3643 | ||
3644 | case ANEG_STATE_NEXT_PAGE_WAIT: | |
3645 | /* ??? unimplemented */ | |
3646 | break; | |
3647 | ||
3648 | default: | |
3649 | ret = ANEG_FAILED; | |
3650 | break; | |
855e1111 | 3651 | } |
1da177e4 LT |
3652 | |
3653 | return ret; | |
3654 | } | |
3655 | ||
5be73b47 | 3656 | static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags) |
1da177e4 LT |
3657 | { |
3658 | int res = 0; | |
3659 | struct tg3_fiber_aneginfo aninfo; | |
3660 | int status = ANEG_FAILED; | |
3661 | unsigned int tick; | |
3662 | u32 tmp; | |
3663 | ||
3664 | tw32_f(MAC_TX_AUTO_NEG, 0); | |
3665 | ||
3666 | tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; | |
3667 | tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII); | |
3668 | udelay(40); | |
3669 | ||
3670 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS); | |
3671 | udelay(40); | |
3672 | ||
3673 | memset(&aninfo, 0, sizeof(aninfo)); | |
3674 | aninfo.flags |= MR_AN_ENABLE; | |
3675 | aninfo.state = ANEG_STATE_UNKNOWN; | |
3676 | aninfo.cur_time = 0; | |
3677 | tick = 0; | |
3678 | while (++tick < 195000) { | |
3679 | status = tg3_fiber_aneg_smachine(tp, &aninfo); | |
3680 | if (status == ANEG_DONE || status == ANEG_FAILED) | |
3681 | break; | |
3682 | ||
3683 | udelay(1); | |
3684 | } | |
3685 | ||
3686 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; | |
3687 | tw32_f(MAC_MODE, tp->mac_mode); | |
3688 | udelay(40); | |
3689 | ||
5be73b47 MC |
3690 | *txflags = aninfo.txconfig; |
3691 | *rxflags = aninfo.flags; | |
1da177e4 LT |
3692 | |
3693 | if (status == ANEG_DONE && | |
3694 | (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK | | |
3695 | MR_LP_ADV_FULL_DUPLEX))) | |
3696 | res = 1; | |
3697 | ||
3698 | return res; | |
3699 | } | |
3700 | ||
3701 | static void tg3_init_bcm8002(struct tg3 *tp) | |
3702 | { | |
3703 | u32 mac_status = tr32(MAC_STATUS); | |
3704 | int i; | |
3705 | ||
3706 | /* Reset when initting first time or we have a link. */ | |
3707 | if ((tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) && | |
3708 | !(mac_status & MAC_STATUS_PCS_SYNCED)) | |
3709 | return; | |
3710 | ||
3711 | /* Set PLL lock range. */ | |
3712 | tg3_writephy(tp, 0x16, 0x8007); | |
3713 | ||
3714 | /* SW reset */ | |
3715 | tg3_writephy(tp, MII_BMCR, BMCR_RESET); | |
3716 | ||
3717 | /* Wait for reset to complete. */ | |
3718 | /* XXX schedule_timeout() ... */ | |
3719 | for (i = 0; i < 500; i++) | |
3720 | udelay(10); | |
3721 | ||
3722 | /* Config mode; select PMA/Ch 1 regs. */ | |
3723 | tg3_writephy(tp, 0x10, 0x8411); | |
3724 | ||
3725 | /* Enable auto-lock and comdet, select txclk for tx. */ | |
3726 | tg3_writephy(tp, 0x11, 0x0a10); | |
3727 | ||
3728 | tg3_writephy(tp, 0x18, 0x00a0); | |
3729 | tg3_writephy(tp, 0x16, 0x41ff); | |
3730 | ||
3731 | /* Assert and deassert POR. */ | |
3732 | tg3_writephy(tp, 0x13, 0x0400); | |
3733 | udelay(40); | |
3734 | tg3_writephy(tp, 0x13, 0x0000); | |
3735 | ||
3736 | tg3_writephy(tp, 0x11, 0x0a50); | |
3737 | udelay(40); | |
3738 | tg3_writephy(tp, 0x11, 0x0a10); | |
3739 | ||
3740 | /* Wait for signal to stabilize */ | |
3741 | /* XXX schedule_timeout() ... */ | |
3742 | for (i = 0; i < 15000; i++) | |
3743 | udelay(10); | |
3744 | ||
3745 | /* Deselect the channel register so we can read the PHYID | |
3746 | * later. | |
3747 | */ | |
3748 | tg3_writephy(tp, 0x10, 0x8011); | |
3749 | } | |
3750 | ||
3751 | static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status) | |
3752 | { | |
82cd3d11 | 3753 | u16 flowctrl; |
1da177e4 LT |
3754 | u32 sg_dig_ctrl, sg_dig_status; |
3755 | u32 serdes_cfg, expected_sg_dig_ctrl; | |
3756 | int workaround, port_a; | |
3757 | int current_link_up; | |
3758 | ||
3759 | serdes_cfg = 0; | |
3760 | expected_sg_dig_ctrl = 0; | |
3761 | workaround = 0; | |
3762 | port_a = 1; | |
3763 | current_link_up = 0; | |
3764 | ||
3765 | if (tp->pci_chip_rev_id != CHIPREV_ID_5704_A0 && | |
3766 | tp->pci_chip_rev_id != CHIPREV_ID_5704_A1) { | |
3767 | workaround = 1; | |
3768 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) | |
3769 | port_a = 0; | |
3770 | ||
3771 | /* preserve bits 0-11,13,14 for signal pre-emphasis */ | |
3772 | /* preserve bits 20-23 for voltage regulator */ | |
3773 | serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff; | |
3774 | } | |
3775 | ||
3776 | sg_dig_ctrl = tr32(SG_DIG_CTRL); | |
3777 | ||
3778 | if (tp->link_config.autoneg != AUTONEG_ENABLE) { | |
c98f6e3b | 3779 | if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) { |
1da177e4 LT |
3780 | if (workaround) { |
3781 | u32 val = serdes_cfg; | |
3782 | ||
3783 | if (port_a) | |
3784 | val |= 0xc010000; | |
3785 | else | |
3786 | val |= 0x4010000; | |
3787 | tw32_f(MAC_SERDES_CFG, val); | |
3788 | } | |
c98f6e3b MC |
3789 | |
3790 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); | |
1da177e4 LT |
3791 | } |
3792 | if (mac_status & MAC_STATUS_PCS_SYNCED) { | |
3793 | tg3_setup_flow_control(tp, 0, 0); | |
3794 | current_link_up = 1; | |
3795 | } | |
3796 | goto out; | |
3797 | } | |
3798 | ||
3799 | /* Want auto-negotiation. */ | |
c98f6e3b | 3800 | expected_sg_dig_ctrl = SG_DIG_USING_HW_AUTONEG | SG_DIG_COMMON_SETUP; |
1da177e4 | 3801 | |
82cd3d11 MC |
3802 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
3803 | if (flowctrl & ADVERTISE_1000XPAUSE) | |
3804 | expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP; | |
3805 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) | |
3806 | expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE; | |
1da177e4 LT |
3807 | |
3808 | if (sg_dig_ctrl != expected_sg_dig_ctrl) { | |
f07e9af3 | 3809 | if ((tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT) && |
3d3ebe74 MC |
3810 | tp->serdes_counter && |
3811 | ((mac_status & (MAC_STATUS_PCS_SYNCED | | |
3812 | MAC_STATUS_RCVD_CFG)) == | |
3813 | MAC_STATUS_PCS_SYNCED)) { | |
3814 | tp->serdes_counter--; | |
3815 | current_link_up = 1; | |
3816 | goto out; | |
3817 | } | |
3818 | restart_autoneg: | |
1da177e4 LT |
3819 | if (workaround) |
3820 | tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000); | |
c98f6e3b | 3821 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | SG_DIG_SOFT_RESET); |
1da177e4 LT |
3822 | udelay(5); |
3823 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl); | |
3824 | ||
3d3ebe74 | 3825 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
f07e9af3 | 3826 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
1da177e4 LT |
3827 | } else if (mac_status & (MAC_STATUS_PCS_SYNCED | |
3828 | MAC_STATUS_SIGNAL_DET)) { | |
3d3ebe74 | 3829 | sg_dig_status = tr32(SG_DIG_STATUS); |
1da177e4 LT |
3830 | mac_status = tr32(MAC_STATUS); |
3831 | ||
c98f6e3b | 3832 | if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) && |
1da177e4 | 3833 | (mac_status & MAC_STATUS_PCS_SYNCED)) { |
82cd3d11 MC |
3834 | u32 local_adv = 0, remote_adv = 0; |
3835 | ||
3836 | if (sg_dig_ctrl & SG_DIG_PAUSE_CAP) | |
3837 | local_adv |= ADVERTISE_1000XPAUSE; | |
3838 | if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE) | |
3839 | local_adv |= ADVERTISE_1000XPSE_ASYM; | |
1da177e4 | 3840 | |
c98f6e3b | 3841 | if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE) |
82cd3d11 | 3842 | remote_adv |= LPA_1000XPAUSE; |
c98f6e3b | 3843 | if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE) |
82cd3d11 | 3844 | remote_adv |= LPA_1000XPAUSE_ASYM; |
1da177e4 LT |
3845 | |
3846 | tg3_setup_flow_control(tp, local_adv, remote_adv); | |
3847 | current_link_up = 1; | |
3d3ebe74 | 3848 | tp->serdes_counter = 0; |
f07e9af3 | 3849 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
c98f6e3b | 3850 | } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) { |
3d3ebe74 MC |
3851 | if (tp->serdes_counter) |
3852 | tp->serdes_counter--; | |
1da177e4 LT |
3853 | else { |
3854 | if (workaround) { | |
3855 | u32 val = serdes_cfg; | |
3856 | ||
3857 | if (port_a) | |
3858 | val |= 0xc010000; | |
3859 | else | |
3860 | val |= 0x4010000; | |
3861 | ||
3862 | tw32_f(MAC_SERDES_CFG, val); | |
3863 | } | |
3864 | ||
c98f6e3b | 3865 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
1da177e4 LT |
3866 | udelay(40); |
3867 | ||
3868 | /* Link parallel detection - link is up */ | |
3869 | /* only if we have PCS_SYNC and not */ | |
3870 | /* receiving config code words */ | |
3871 | mac_status = tr32(MAC_STATUS); | |
3872 | if ((mac_status & MAC_STATUS_PCS_SYNCED) && | |
3873 | !(mac_status & MAC_STATUS_RCVD_CFG)) { | |
3874 | tg3_setup_flow_control(tp, 0, 0); | |
3875 | current_link_up = 1; | |
f07e9af3 MC |
3876 | tp->phy_flags |= |
3877 | TG3_PHYFLG_PARALLEL_DETECT; | |
3d3ebe74 MC |
3878 | tp->serdes_counter = |
3879 | SERDES_PARALLEL_DET_TIMEOUT; | |
3880 | } else | |
3881 | goto restart_autoneg; | |
1da177e4 LT |
3882 | } |
3883 | } | |
3d3ebe74 MC |
3884 | } else { |
3885 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; | |
f07e9af3 | 3886 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
1da177e4 LT |
3887 | } |
3888 | ||
3889 | out: | |
3890 | return current_link_up; | |
3891 | } | |
3892 | ||
3893 | static int tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status) | |
3894 | { | |
3895 | int current_link_up = 0; | |
3896 | ||
5cf64b8a | 3897 | if (!(mac_status & MAC_STATUS_PCS_SYNCED)) |
1da177e4 | 3898 | goto out; |
1da177e4 LT |
3899 | |
3900 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { | |
5be73b47 | 3901 | u32 txflags, rxflags; |
1da177e4 | 3902 | int i; |
6aa20a22 | 3903 | |
5be73b47 MC |
3904 | if (fiber_autoneg(tp, &txflags, &rxflags)) { |
3905 | u32 local_adv = 0, remote_adv = 0; | |
1da177e4 | 3906 | |
5be73b47 MC |
3907 | if (txflags & ANEG_CFG_PS1) |
3908 | local_adv |= ADVERTISE_1000XPAUSE; | |
3909 | if (txflags & ANEG_CFG_PS2) | |
3910 | local_adv |= ADVERTISE_1000XPSE_ASYM; | |
3911 | ||
3912 | if (rxflags & MR_LP_ADV_SYM_PAUSE) | |
3913 | remote_adv |= LPA_1000XPAUSE; | |
3914 | if (rxflags & MR_LP_ADV_ASYM_PAUSE) | |
3915 | remote_adv |= LPA_1000XPAUSE_ASYM; | |
1da177e4 LT |
3916 | |
3917 | tg3_setup_flow_control(tp, local_adv, remote_adv); | |
3918 | ||
1da177e4 LT |
3919 | current_link_up = 1; |
3920 | } | |
3921 | for (i = 0; i < 30; i++) { | |
3922 | udelay(20); | |
3923 | tw32_f(MAC_STATUS, | |
3924 | (MAC_STATUS_SYNC_CHANGED | | |
3925 | MAC_STATUS_CFG_CHANGED)); | |
3926 | udelay(40); | |
3927 | if ((tr32(MAC_STATUS) & | |
3928 | (MAC_STATUS_SYNC_CHANGED | | |
3929 | MAC_STATUS_CFG_CHANGED)) == 0) | |
3930 | break; | |
3931 | } | |
3932 | ||
3933 | mac_status = tr32(MAC_STATUS); | |
3934 | if (current_link_up == 0 && | |
3935 | (mac_status & MAC_STATUS_PCS_SYNCED) && | |
3936 | !(mac_status & MAC_STATUS_RCVD_CFG)) | |
3937 | current_link_up = 1; | |
3938 | } else { | |
5be73b47 MC |
3939 | tg3_setup_flow_control(tp, 0, 0); |
3940 | ||
1da177e4 LT |
3941 | /* Forcing 1000FD link up. */ |
3942 | current_link_up = 1; | |
1da177e4 LT |
3943 | |
3944 | tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS)); | |
3945 | udelay(40); | |
e8f3f6ca MC |
3946 | |
3947 | tw32_f(MAC_MODE, tp->mac_mode); | |
3948 | udelay(40); | |
1da177e4 LT |
3949 | } |
3950 | ||
3951 | out: | |
3952 | return current_link_up; | |
3953 | } | |
3954 | ||
3955 | static int tg3_setup_fiber_phy(struct tg3 *tp, int force_reset) | |
3956 | { | |
3957 | u32 orig_pause_cfg; | |
3958 | u16 orig_active_speed; | |
3959 | u8 orig_active_duplex; | |
3960 | u32 mac_status; | |
3961 | int current_link_up; | |
3962 | int i; | |
3963 | ||
8d018621 | 3964 | orig_pause_cfg = tp->link_config.active_flowctrl; |
1da177e4 LT |
3965 | orig_active_speed = tp->link_config.active_speed; |
3966 | orig_active_duplex = tp->link_config.active_duplex; | |
3967 | ||
3968 | if (!(tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) && | |
3969 | netif_carrier_ok(tp->dev) && | |
3970 | (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE)) { | |
3971 | mac_status = tr32(MAC_STATUS); | |
3972 | mac_status &= (MAC_STATUS_PCS_SYNCED | | |
3973 | MAC_STATUS_SIGNAL_DET | | |
3974 | MAC_STATUS_CFG_CHANGED | | |
3975 | MAC_STATUS_RCVD_CFG); | |
3976 | if (mac_status == (MAC_STATUS_PCS_SYNCED | | |
3977 | MAC_STATUS_SIGNAL_DET)) { | |
3978 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | | |
3979 | MAC_STATUS_CFG_CHANGED)); | |
3980 | return 0; | |
3981 | } | |
3982 | } | |
3983 | ||
3984 | tw32_f(MAC_TX_AUTO_NEG, 0); | |
3985 | ||
3986 | tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); | |
3987 | tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; | |
3988 | tw32_f(MAC_MODE, tp->mac_mode); | |
3989 | udelay(40); | |
3990 | ||
79eb6904 | 3991 | if (tp->phy_id == TG3_PHY_ID_BCM8002) |
1da177e4 LT |
3992 | tg3_init_bcm8002(tp); |
3993 | ||
3994 | /* Enable link change event even when serdes polling. */ | |
3995 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); | |
3996 | udelay(40); | |
3997 | ||
3998 | current_link_up = 0; | |
3999 | mac_status = tr32(MAC_STATUS); | |
4000 | ||
4001 | if (tp->tg3_flags2 & TG3_FLG2_HW_AUTONEG) | |
4002 | current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status); | |
4003 | else | |
4004 | current_link_up = tg3_setup_fiber_by_hand(tp, mac_status); | |
4005 | ||
898a56f8 | 4006 | tp->napi[0].hw_status->status = |
1da177e4 | 4007 | (SD_STATUS_UPDATED | |
898a56f8 | 4008 | (tp->napi[0].hw_status->status & ~SD_STATUS_LINK_CHG)); |
1da177e4 LT |
4009 | |
4010 | for (i = 0; i < 100; i++) { | |
4011 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | | |
4012 | MAC_STATUS_CFG_CHANGED)); | |
4013 | udelay(5); | |
4014 | if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED | | |
3d3ebe74 MC |
4015 | MAC_STATUS_CFG_CHANGED | |
4016 | MAC_STATUS_LNKSTATE_CHANGED)) == 0) | |
1da177e4 LT |
4017 | break; |
4018 | } | |
4019 | ||
4020 | mac_status = tr32(MAC_STATUS); | |
4021 | if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) { | |
4022 | current_link_up = 0; | |
3d3ebe74 MC |
4023 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
4024 | tp->serdes_counter == 0) { | |
1da177e4 LT |
4025 | tw32_f(MAC_MODE, (tp->mac_mode | |
4026 | MAC_MODE_SEND_CONFIGS)); | |
4027 | udelay(1); | |
4028 | tw32_f(MAC_MODE, tp->mac_mode); | |
4029 | } | |
4030 | } | |
4031 | ||
4032 | if (current_link_up == 1) { | |
4033 | tp->link_config.active_speed = SPEED_1000; | |
4034 | tp->link_config.active_duplex = DUPLEX_FULL; | |
4035 | tw32(MAC_LED_CTRL, (tp->led_ctrl | | |
4036 | LED_CTRL_LNKLED_OVERRIDE | | |
4037 | LED_CTRL_1000MBPS_ON)); | |
4038 | } else { | |
4039 | tp->link_config.active_speed = SPEED_INVALID; | |
4040 | tp->link_config.active_duplex = DUPLEX_INVALID; | |
4041 | tw32(MAC_LED_CTRL, (tp->led_ctrl | | |
4042 | LED_CTRL_LNKLED_OVERRIDE | | |
4043 | LED_CTRL_TRAFFIC_OVERRIDE)); | |
4044 | } | |
4045 | ||
4046 | if (current_link_up != netif_carrier_ok(tp->dev)) { | |
4047 | if (current_link_up) | |
4048 | netif_carrier_on(tp->dev); | |
4049 | else | |
4050 | netif_carrier_off(tp->dev); | |
4051 | tg3_link_report(tp); | |
4052 | } else { | |
8d018621 | 4053 | u32 now_pause_cfg = tp->link_config.active_flowctrl; |
1da177e4 LT |
4054 | if (orig_pause_cfg != now_pause_cfg || |
4055 | orig_active_speed != tp->link_config.active_speed || | |
4056 | orig_active_duplex != tp->link_config.active_duplex) | |
4057 | tg3_link_report(tp); | |
4058 | } | |
4059 | ||
4060 | return 0; | |
4061 | } | |
4062 | ||
747e8f8b MC |
4063 | static int tg3_setup_fiber_mii_phy(struct tg3 *tp, int force_reset) |
4064 | { | |
4065 | int current_link_up, err = 0; | |
4066 | u32 bmsr, bmcr; | |
4067 | u16 current_speed; | |
4068 | u8 current_duplex; | |
ef167e27 | 4069 | u32 local_adv, remote_adv; |
747e8f8b MC |
4070 | |
4071 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
4072 | tw32_f(MAC_MODE, tp->mac_mode); | |
4073 | udelay(40); | |
4074 | ||
4075 | tw32(MAC_EVENT, 0); | |
4076 | ||
4077 | tw32_f(MAC_STATUS, | |
4078 | (MAC_STATUS_SYNC_CHANGED | | |
4079 | MAC_STATUS_CFG_CHANGED | | |
4080 | MAC_STATUS_MI_COMPLETION | | |
4081 | MAC_STATUS_LNKSTATE_CHANGED)); | |
4082 | udelay(40); | |
4083 | ||
4084 | if (force_reset) | |
4085 | tg3_phy_reset(tp); | |
4086 | ||
4087 | current_link_up = 0; | |
4088 | current_speed = SPEED_INVALID; | |
4089 | current_duplex = DUPLEX_INVALID; | |
4090 | ||
4091 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); | |
4092 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); | |
d4d2c558 MC |
4093 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
4094 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) | |
4095 | bmsr |= BMSR_LSTATUS; | |
4096 | else | |
4097 | bmsr &= ~BMSR_LSTATUS; | |
4098 | } | |
747e8f8b MC |
4099 | |
4100 | err |= tg3_readphy(tp, MII_BMCR, &bmcr); | |
4101 | ||
4102 | if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset && | |
f07e9af3 | 4103 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
747e8f8b MC |
4104 | /* do nothing, just check for link up at the end */ |
4105 | } else if (tp->link_config.autoneg == AUTONEG_ENABLE) { | |
4106 | u32 adv, new_adv; | |
4107 | ||
4108 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); | |
4109 | new_adv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF | | |
4110 | ADVERTISE_1000XPAUSE | | |
4111 | ADVERTISE_1000XPSE_ASYM | | |
4112 | ADVERTISE_SLCT); | |
4113 | ||
ba4d07a8 | 4114 | new_adv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
747e8f8b MC |
4115 | |
4116 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Half) | |
4117 | new_adv |= ADVERTISE_1000XHALF; | |
4118 | if (tp->link_config.advertising & ADVERTISED_1000baseT_Full) | |
4119 | new_adv |= ADVERTISE_1000XFULL; | |
4120 | ||
4121 | if ((new_adv != adv) || !(bmcr & BMCR_ANENABLE)) { | |
4122 | tg3_writephy(tp, MII_ADVERTISE, new_adv); | |
4123 | bmcr |= BMCR_ANENABLE | BMCR_ANRESTART; | |
4124 | tg3_writephy(tp, MII_BMCR, bmcr); | |
4125 | ||
4126 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); | |
3d3ebe74 | 4127 | tp->serdes_counter = SERDES_AN_TIMEOUT_5714S; |
f07e9af3 | 4128 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
4129 | |
4130 | return err; | |
4131 | } | |
4132 | } else { | |
4133 | u32 new_bmcr; | |
4134 | ||
4135 | bmcr &= ~BMCR_SPEED1000; | |
4136 | new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX); | |
4137 | ||
4138 | if (tp->link_config.duplex == DUPLEX_FULL) | |
4139 | new_bmcr |= BMCR_FULLDPLX; | |
4140 | ||
4141 | if (new_bmcr != bmcr) { | |
4142 | /* BMCR_SPEED1000 is a reserved bit that needs | |
4143 | * to be set on write. | |
4144 | */ | |
4145 | new_bmcr |= BMCR_SPEED1000; | |
4146 | ||
4147 | /* Force a linkdown */ | |
4148 | if (netif_carrier_ok(tp->dev)) { | |
4149 | u32 adv; | |
4150 | ||
4151 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); | |
4152 | adv &= ~(ADVERTISE_1000XFULL | | |
4153 | ADVERTISE_1000XHALF | | |
4154 | ADVERTISE_SLCT); | |
4155 | tg3_writephy(tp, MII_ADVERTISE, adv); | |
4156 | tg3_writephy(tp, MII_BMCR, bmcr | | |
4157 | BMCR_ANRESTART | | |
4158 | BMCR_ANENABLE); | |
4159 | udelay(10); | |
4160 | netif_carrier_off(tp->dev); | |
4161 | } | |
4162 | tg3_writephy(tp, MII_BMCR, new_bmcr); | |
4163 | bmcr = new_bmcr; | |
4164 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); | |
4165 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); | |
d4d2c558 MC |
4166 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == |
4167 | ASIC_REV_5714) { | |
4168 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) | |
4169 | bmsr |= BMSR_LSTATUS; | |
4170 | else | |
4171 | bmsr &= ~BMSR_LSTATUS; | |
4172 | } | |
f07e9af3 | 4173 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
4174 | } |
4175 | } | |
4176 | ||
4177 | if (bmsr & BMSR_LSTATUS) { | |
4178 | current_speed = SPEED_1000; | |
4179 | current_link_up = 1; | |
4180 | if (bmcr & BMCR_FULLDPLX) | |
4181 | current_duplex = DUPLEX_FULL; | |
4182 | else | |
4183 | current_duplex = DUPLEX_HALF; | |
4184 | ||
ef167e27 MC |
4185 | local_adv = 0; |
4186 | remote_adv = 0; | |
4187 | ||
747e8f8b | 4188 | if (bmcr & BMCR_ANENABLE) { |
ef167e27 | 4189 | u32 common; |
747e8f8b MC |
4190 | |
4191 | err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv); | |
4192 | err |= tg3_readphy(tp, MII_LPA, &remote_adv); | |
4193 | common = local_adv & remote_adv; | |
4194 | if (common & (ADVERTISE_1000XHALF | | |
4195 | ADVERTISE_1000XFULL)) { | |
4196 | if (common & ADVERTISE_1000XFULL) | |
4197 | current_duplex = DUPLEX_FULL; | |
4198 | else | |
4199 | current_duplex = DUPLEX_HALF; | |
57d8b880 MC |
4200 | } else if (!(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
4201 | /* Link is up via parallel detect */ | |
859a5887 | 4202 | } else { |
747e8f8b | 4203 | current_link_up = 0; |
859a5887 | 4204 | } |
747e8f8b MC |
4205 | } |
4206 | } | |
4207 | ||
ef167e27 MC |
4208 | if (current_link_up == 1 && current_duplex == DUPLEX_FULL) |
4209 | tg3_setup_flow_control(tp, local_adv, remote_adv); | |
4210 | ||
747e8f8b MC |
4211 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
4212 | if (tp->link_config.active_duplex == DUPLEX_HALF) | |
4213 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; | |
4214 | ||
4215 | tw32_f(MAC_MODE, tp->mac_mode); | |
4216 | udelay(40); | |
4217 | ||
4218 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); | |
4219 | ||
4220 | tp->link_config.active_speed = current_speed; | |
4221 | tp->link_config.active_duplex = current_duplex; | |
4222 | ||
4223 | if (current_link_up != netif_carrier_ok(tp->dev)) { | |
4224 | if (current_link_up) | |
4225 | netif_carrier_on(tp->dev); | |
4226 | else { | |
4227 | netif_carrier_off(tp->dev); | |
f07e9af3 | 4228 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
4229 | } |
4230 | tg3_link_report(tp); | |
4231 | } | |
4232 | return err; | |
4233 | } | |
4234 | ||
4235 | static void tg3_serdes_parallel_detect(struct tg3 *tp) | |
4236 | { | |
3d3ebe74 | 4237 | if (tp->serdes_counter) { |
747e8f8b | 4238 | /* Give autoneg time to complete. */ |
3d3ebe74 | 4239 | tp->serdes_counter--; |
747e8f8b MC |
4240 | return; |
4241 | } | |
c6cdf436 | 4242 | |
747e8f8b MC |
4243 | if (!netif_carrier_ok(tp->dev) && |
4244 | (tp->link_config.autoneg == AUTONEG_ENABLE)) { | |
4245 | u32 bmcr; | |
4246 | ||
4247 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
4248 | if (bmcr & BMCR_ANENABLE) { | |
4249 | u32 phy1, phy2; | |
4250 | ||
4251 | /* Select shadow register 0x1f */ | |
f08aa1a8 MC |
4252 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x7c00); |
4253 | tg3_readphy(tp, MII_TG3_MISC_SHDW, &phy1); | |
747e8f8b MC |
4254 | |
4255 | /* Select expansion interrupt status register */ | |
f08aa1a8 MC |
4256 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
4257 | MII_TG3_DSP_EXP1_INT_STAT); | |
4258 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); | |
4259 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); | |
747e8f8b MC |
4260 | |
4261 | if ((phy1 & 0x10) && !(phy2 & 0x20)) { | |
4262 | /* We have signal detect and not receiving | |
4263 | * config code words, link is up by parallel | |
4264 | * detection. | |
4265 | */ | |
4266 | ||
4267 | bmcr &= ~BMCR_ANENABLE; | |
4268 | bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX; | |
4269 | tg3_writephy(tp, MII_BMCR, bmcr); | |
f07e9af3 | 4270 | tp->phy_flags |= TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
4271 | } |
4272 | } | |
859a5887 MC |
4273 | } else if (netif_carrier_ok(tp->dev) && |
4274 | (tp->link_config.autoneg == AUTONEG_ENABLE) && | |
f07e9af3 | 4275 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
747e8f8b MC |
4276 | u32 phy2; |
4277 | ||
4278 | /* Select expansion interrupt status register */ | |
f08aa1a8 MC |
4279 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
4280 | MII_TG3_DSP_EXP1_INT_STAT); | |
4281 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); | |
747e8f8b MC |
4282 | if (phy2 & 0x20) { |
4283 | u32 bmcr; | |
4284 | ||
4285 | /* Config code words received, turn on autoneg. */ | |
4286 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
4287 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE); | |
4288 | ||
f07e9af3 | 4289 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
4290 | |
4291 | } | |
4292 | } | |
4293 | } | |
4294 | ||
1da177e4 LT |
4295 | static int tg3_setup_phy(struct tg3 *tp, int force_reset) |
4296 | { | |
4297 | int err; | |
4298 | ||
f07e9af3 | 4299 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
1da177e4 | 4300 | err = tg3_setup_fiber_phy(tp, force_reset); |
f07e9af3 | 4301 | else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
747e8f8b | 4302 | err = tg3_setup_fiber_mii_phy(tp, force_reset); |
859a5887 | 4303 | else |
1da177e4 | 4304 | err = tg3_setup_copper_phy(tp, force_reset); |
1da177e4 | 4305 | |
bcb37f6c | 4306 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
aa6c91fe MC |
4307 | u32 val, scale; |
4308 | ||
4309 | val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK; | |
4310 | if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5) | |
4311 | scale = 65; | |
4312 | else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25) | |
4313 | scale = 6; | |
4314 | else | |
4315 | scale = 12; | |
4316 | ||
4317 | val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK; | |
4318 | val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT); | |
4319 | tw32(GRC_MISC_CFG, val); | |
4320 | } | |
4321 | ||
1da177e4 LT |
4322 | if (tp->link_config.active_speed == SPEED_1000 && |
4323 | tp->link_config.active_duplex == DUPLEX_HALF) | |
4324 | tw32(MAC_TX_LENGTHS, | |
4325 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | | |
4326 | (6 << TX_LENGTHS_IPG_SHIFT) | | |
4327 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); | |
4328 | else | |
4329 | tw32(MAC_TX_LENGTHS, | |
4330 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | | |
4331 | (6 << TX_LENGTHS_IPG_SHIFT) | | |
4332 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); | |
4333 | ||
4334 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { | |
4335 | if (netif_carrier_ok(tp->dev)) { | |
4336 | tw32(HOSTCC_STAT_COAL_TICKS, | |
15f9850d | 4337 | tp->coal.stats_block_coalesce_usecs); |
1da177e4 LT |
4338 | } else { |
4339 | tw32(HOSTCC_STAT_COAL_TICKS, 0); | |
4340 | } | |
4341 | } | |
4342 | ||
8ed5d97e MC |
4343 | if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND) { |
4344 | u32 val = tr32(PCIE_PWR_MGMT_THRESH); | |
4345 | if (!netif_carrier_ok(tp->dev)) | |
4346 | val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) | | |
4347 | tp->pwrmgmt_thresh; | |
4348 | else | |
4349 | val |= PCIE_PWR_MGMT_L1_THRESH_MSK; | |
4350 | tw32(PCIE_PWR_MGMT_THRESH, val); | |
4351 | } | |
4352 | ||
1da177e4 LT |
4353 | return err; |
4354 | } | |
4355 | ||
df3e6548 MC |
4356 | /* This is called whenever we suspect that the system chipset is re- |
4357 | * ordering the sequence of MMIO to the tx send mailbox. The symptom | |
4358 | * is bogus tx completions. We try to recover by setting the | |
4359 | * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later | |
4360 | * in the workqueue. | |
4361 | */ | |
4362 | static void tg3_tx_recover(struct tg3 *tp) | |
4363 | { | |
4364 | BUG_ON((tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) || | |
4365 | tp->write32_tx_mbox == tg3_write_indirect_mbox); | |
4366 | ||
5129c3a3 MC |
4367 | netdev_warn(tp->dev, |
4368 | "The system may be re-ordering memory-mapped I/O " | |
4369 | "cycles to the network device, attempting to recover. " | |
4370 | "Please report the problem to the driver maintainer " | |
4371 | "and include system chipset information.\n"); | |
df3e6548 MC |
4372 | |
4373 | spin_lock(&tp->lock); | |
df3e6548 | 4374 | tp->tg3_flags |= TG3_FLAG_TX_RECOVERY_PENDING; |
df3e6548 MC |
4375 | spin_unlock(&tp->lock); |
4376 | } | |
4377 | ||
f3f3f27e | 4378 | static inline u32 tg3_tx_avail(struct tg3_napi *tnapi) |
1b2a7205 | 4379 | { |
f65aac16 MC |
4380 | /* Tell compiler to fetch tx indices from memory. */ |
4381 | barrier(); | |
f3f3f27e MC |
4382 | return tnapi->tx_pending - |
4383 | ((tnapi->tx_prod - tnapi->tx_cons) & (TG3_TX_RING_SIZE - 1)); | |
1b2a7205 MC |
4384 | } |
4385 | ||
1da177e4 LT |
4386 | /* Tigon3 never reports partial packet sends. So we do not |
4387 | * need special logic to handle SKBs that have not had all | |
4388 | * of their frags sent yet, like SunGEM does. | |
4389 | */ | |
17375d25 | 4390 | static void tg3_tx(struct tg3_napi *tnapi) |
1da177e4 | 4391 | { |
17375d25 | 4392 | struct tg3 *tp = tnapi->tp; |
898a56f8 | 4393 | u32 hw_idx = tnapi->hw_status->idx[0].tx_consumer; |
f3f3f27e | 4394 | u32 sw_idx = tnapi->tx_cons; |
fe5f5787 MC |
4395 | struct netdev_queue *txq; |
4396 | int index = tnapi - tp->napi; | |
4397 | ||
19cfaecc | 4398 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
fe5f5787 MC |
4399 | index--; |
4400 | ||
4401 | txq = netdev_get_tx_queue(tp->dev, index); | |
1da177e4 LT |
4402 | |
4403 | while (sw_idx != hw_idx) { | |
f4188d8a | 4404 | struct ring_info *ri = &tnapi->tx_buffers[sw_idx]; |
1da177e4 | 4405 | struct sk_buff *skb = ri->skb; |
df3e6548 MC |
4406 | int i, tx_bug = 0; |
4407 | ||
4408 | if (unlikely(skb == NULL)) { | |
4409 | tg3_tx_recover(tp); | |
4410 | return; | |
4411 | } | |
1da177e4 | 4412 | |
f4188d8a | 4413 | pci_unmap_single(tp->pdev, |
4e5e4f0d | 4414 | dma_unmap_addr(ri, mapping), |
f4188d8a AD |
4415 | skb_headlen(skb), |
4416 | PCI_DMA_TODEVICE); | |
1da177e4 LT |
4417 | |
4418 | ri->skb = NULL; | |
4419 | ||
4420 | sw_idx = NEXT_TX(sw_idx); | |
4421 | ||
4422 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { | |
f3f3f27e | 4423 | ri = &tnapi->tx_buffers[sw_idx]; |
df3e6548 MC |
4424 | if (unlikely(ri->skb != NULL || sw_idx == hw_idx)) |
4425 | tx_bug = 1; | |
f4188d8a AD |
4426 | |
4427 | pci_unmap_page(tp->pdev, | |
4e5e4f0d | 4428 | dma_unmap_addr(ri, mapping), |
f4188d8a AD |
4429 | skb_shinfo(skb)->frags[i].size, |
4430 | PCI_DMA_TODEVICE); | |
1da177e4 LT |
4431 | sw_idx = NEXT_TX(sw_idx); |
4432 | } | |
4433 | ||
f47c11ee | 4434 | dev_kfree_skb(skb); |
df3e6548 MC |
4435 | |
4436 | if (unlikely(tx_bug)) { | |
4437 | tg3_tx_recover(tp); | |
4438 | return; | |
4439 | } | |
1da177e4 LT |
4440 | } |
4441 | ||
f3f3f27e | 4442 | tnapi->tx_cons = sw_idx; |
1da177e4 | 4443 | |
1b2a7205 MC |
4444 | /* Need to make the tx_cons update visible to tg3_start_xmit() |
4445 | * before checking for netif_queue_stopped(). Without the | |
4446 | * memory barrier, there is a small possibility that tg3_start_xmit() | |
4447 | * will miss it and cause the queue to be stopped forever. | |
4448 | */ | |
4449 | smp_mb(); | |
4450 | ||
fe5f5787 | 4451 | if (unlikely(netif_tx_queue_stopped(txq) && |
f3f3f27e | 4452 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)))) { |
fe5f5787 MC |
4453 | __netif_tx_lock(txq, smp_processor_id()); |
4454 | if (netif_tx_queue_stopped(txq) && | |
f3f3f27e | 4455 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi))) |
fe5f5787 MC |
4456 | netif_tx_wake_queue(txq); |
4457 | __netif_tx_unlock(txq); | |
51b91468 | 4458 | } |
1da177e4 LT |
4459 | } |
4460 | ||
2b2cdb65 MC |
4461 | static void tg3_rx_skb_free(struct tg3 *tp, struct ring_info *ri, u32 map_sz) |
4462 | { | |
4463 | if (!ri->skb) | |
4464 | return; | |
4465 | ||
4e5e4f0d | 4466 | pci_unmap_single(tp->pdev, dma_unmap_addr(ri, mapping), |
2b2cdb65 MC |
4467 | map_sz, PCI_DMA_FROMDEVICE); |
4468 | dev_kfree_skb_any(ri->skb); | |
4469 | ri->skb = NULL; | |
4470 | } | |
4471 | ||
1da177e4 LT |
4472 | /* Returns size of skb allocated or < 0 on error. |
4473 | * | |
4474 | * We only need to fill in the address because the other members | |
4475 | * of the RX descriptor are invariant, see tg3_init_rings. | |
4476 | * | |
4477 | * Note the purposeful assymetry of cpu vs. chip accesses. For | |
4478 | * posting buffers we only dirty the first cache line of the RX | |
4479 | * descriptor (containing the address). Whereas for the RX status | |
4480 | * buffers the cpu only reads the last cacheline of the RX descriptor | |
4481 | * (to fetch the error flags, vlan tag, checksum, and opaque cookie). | |
4482 | */ | |
86b21e59 | 4483 | static int tg3_alloc_rx_skb(struct tg3 *tp, struct tg3_rx_prodring_set *tpr, |
a3896167 | 4484 | u32 opaque_key, u32 dest_idx_unmasked) |
1da177e4 LT |
4485 | { |
4486 | struct tg3_rx_buffer_desc *desc; | |
4487 | struct ring_info *map, *src_map; | |
4488 | struct sk_buff *skb; | |
4489 | dma_addr_t mapping; | |
4490 | int skb_size, dest_idx; | |
4491 | ||
4492 | src_map = NULL; | |
4493 | switch (opaque_key) { | |
4494 | case RXD_OPAQUE_RING_STD: | |
4495 | dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE; | |
21f581a5 MC |
4496 | desc = &tpr->rx_std[dest_idx]; |
4497 | map = &tpr->rx_std_buffers[dest_idx]; | |
287be12e | 4498 | skb_size = tp->rx_pkt_map_sz; |
1da177e4 LT |
4499 | break; |
4500 | ||
4501 | case RXD_OPAQUE_RING_JUMBO: | |
4502 | dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE; | |
79ed5ac7 | 4503 | desc = &tpr->rx_jmb[dest_idx].std; |
21f581a5 | 4504 | map = &tpr->rx_jmb_buffers[dest_idx]; |
287be12e | 4505 | skb_size = TG3_RX_JMB_MAP_SZ; |
1da177e4 LT |
4506 | break; |
4507 | ||
4508 | default: | |
4509 | return -EINVAL; | |
855e1111 | 4510 | } |
1da177e4 LT |
4511 | |
4512 | /* Do not overwrite any of the map or rp information | |
4513 | * until we are sure we can commit to a new buffer. | |
4514 | * | |
4515 | * Callers depend upon this behavior and assume that | |
4516 | * we leave everything unchanged if we fail. | |
4517 | */ | |
287be12e | 4518 | skb = netdev_alloc_skb(tp->dev, skb_size + tp->rx_offset); |
1da177e4 LT |
4519 | if (skb == NULL) |
4520 | return -ENOMEM; | |
4521 | ||
1da177e4 LT |
4522 | skb_reserve(skb, tp->rx_offset); |
4523 | ||
287be12e | 4524 | mapping = pci_map_single(tp->pdev, skb->data, skb_size, |
1da177e4 | 4525 | PCI_DMA_FROMDEVICE); |
a21771dd MC |
4526 | if (pci_dma_mapping_error(tp->pdev, mapping)) { |
4527 | dev_kfree_skb(skb); | |
4528 | return -EIO; | |
4529 | } | |
1da177e4 LT |
4530 | |
4531 | map->skb = skb; | |
4e5e4f0d | 4532 | dma_unmap_addr_set(map, mapping, mapping); |
1da177e4 | 4533 | |
1da177e4 LT |
4534 | desc->addr_hi = ((u64)mapping >> 32); |
4535 | desc->addr_lo = ((u64)mapping & 0xffffffff); | |
4536 | ||
4537 | return skb_size; | |
4538 | } | |
4539 | ||
4540 | /* We only need to move over in the address because the other | |
4541 | * members of the RX descriptor are invariant. See notes above | |
4542 | * tg3_alloc_rx_skb for full details. | |
4543 | */ | |
a3896167 MC |
4544 | static void tg3_recycle_rx(struct tg3_napi *tnapi, |
4545 | struct tg3_rx_prodring_set *dpr, | |
4546 | u32 opaque_key, int src_idx, | |
4547 | u32 dest_idx_unmasked) | |
1da177e4 | 4548 | { |
17375d25 | 4549 | struct tg3 *tp = tnapi->tp; |
1da177e4 LT |
4550 | struct tg3_rx_buffer_desc *src_desc, *dest_desc; |
4551 | struct ring_info *src_map, *dest_map; | |
a3896167 | 4552 | struct tg3_rx_prodring_set *spr = &tp->prodring[0]; |
c6cdf436 | 4553 | int dest_idx; |
1da177e4 LT |
4554 | |
4555 | switch (opaque_key) { | |
4556 | case RXD_OPAQUE_RING_STD: | |
4557 | dest_idx = dest_idx_unmasked % TG3_RX_RING_SIZE; | |
a3896167 MC |
4558 | dest_desc = &dpr->rx_std[dest_idx]; |
4559 | dest_map = &dpr->rx_std_buffers[dest_idx]; | |
4560 | src_desc = &spr->rx_std[src_idx]; | |
4561 | src_map = &spr->rx_std_buffers[src_idx]; | |
1da177e4 LT |
4562 | break; |
4563 | ||
4564 | case RXD_OPAQUE_RING_JUMBO: | |
4565 | dest_idx = dest_idx_unmasked % TG3_RX_JUMBO_RING_SIZE; | |
a3896167 MC |
4566 | dest_desc = &dpr->rx_jmb[dest_idx].std; |
4567 | dest_map = &dpr->rx_jmb_buffers[dest_idx]; | |
4568 | src_desc = &spr->rx_jmb[src_idx].std; | |
4569 | src_map = &spr->rx_jmb_buffers[src_idx]; | |
1da177e4 LT |
4570 | break; |
4571 | ||
4572 | default: | |
4573 | return; | |
855e1111 | 4574 | } |
1da177e4 LT |
4575 | |
4576 | dest_map->skb = src_map->skb; | |
4e5e4f0d FT |
4577 | dma_unmap_addr_set(dest_map, mapping, |
4578 | dma_unmap_addr(src_map, mapping)); | |
1da177e4 LT |
4579 | dest_desc->addr_hi = src_desc->addr_hi; |
4580 | dest_desc->addr_lo = src_desc->addr_lo; | |
e92967bf MC |
4581 | |
4582 | /* Ensure that the update to the skb happens after the physical | |
4583 | * addresses have been transferred to the new BD location. | |
4584 | */ | |
4585 | smp_wmb(); | |
4586 | ||
1da177e4 LT |
4587 | src_map->skb = NULL; |
4588 | } | |
4589 | ||
1da177e4 LT |
4590 | /* The RX ring scheme is composed of multiple rings which post fresh |
4591 | * buffers to the chip, and one special ring the chip uses to report | |
4592 | * status back to the host. | |
4593 | * | |
4594 | * The special ring reports the status of received packets to the | |
4595 | * host. The chip does not write into the original descriptor the | |
4596 | * RX buffer was obtained from. The chip simply takes the original | |
4597 | * descriptor as provided by the host, updates the status and length | |
4598 | * field, then writes this into the next status ring entry. | |
4599 | * | |
4600 | * Each ring the host uses to post buffers to the chip is described | |
4601 | * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives, | |
4602 | * it is first placed into the on-chip ram. When the packet's length | |
4603 | * is known, it walks down the TG3_BDINFO entries to select the ring. | |
4604 | * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO | |
4605 | * which is within the range of the new packet's length is chosen. | |
4606 | * | |
4607 | * The "separate ring for rx status" scheme may sound queer, but it makes | |
4608 | * sense from a cache coherency perspective. If only the host writes | |
4609 | * to the buffer post rings, and only the chip writes to the rx status | |
4610 | * rings, then cache lines never move beyond shared-modified state. | |
4611 | * If both the host and chip were to write into the same ring, cache line | |
4612 | * eviction could occur since both entities want it in an exclusive state. | |
4613 | */ | |
17375d25 | 4614 | static int tg3_rx(struct tg3_napi *tnapi, int budget) |
1da177e4 | 4615 | { |
17375d25 | 4616 | struct tg3 *tp = tnapi->tp; |
f92905de | 4617 | u32 work_mask, rx_std_posted = 0; |
4361935a | 4618 | u32 std_prod_idx, jmb_prod_idx; |
72334482 | 4619 | u32 sw_idx = tnapi->rx_rcb_ptr; |
483ba50b | 4620 | u16 hw_idx; |
1da177e4 | 4621 | int received; |
b196c7e4 | 4622 | struct tg3_rx_prodring_set *tpr = tnapi->prodring; |
1da177e4 | 4623 | |
8d9d7cfc | 4624 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
1da177e4 LT |
4625 | /* |
4626 | * We need to order the read of hw_idx and the read of | |
4627 | * the opaque cookie. | |
4628 | */ | |
4629 | rmb(); | |
1da177e4 LT |
4630 | work_mask = 0; |
4631 | received = 0; | |
4361935a MC |
4632 | std_prod_idx = tpr->rx_std_prod_idx; |
4633 | jmb_prod_idx = tpr->rx_jmb_prod_idx; | |
1da177e4 | 4634 | while (sw_idx != hw_idx && budget > 0) { |
afc081f8 | 4635 | struct ring_info *ri; |
72334482 | 4636 | struct tg3_rx_buffer_desc *desc = &tnapi->rx_rcb[sw_idx]; |
1da177e4 LT |
4637 | unsigned int len; |
4638 | struct sk_buff *skb; | |
4639 | dma_addr_t dma_addr; | |
4640 | u32 opaque_key, desc_idx, *post_ptr; | |
9dc7a113 MC |
4641 | bool hw_vlan __maybe_unused = false; |
4642 | u16 vtag __maybe_unused = 0; | |
1da177e4 LT |
4643 | |
4644 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; | |
4645 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; | |
4646 | if (opaque_key == RXD_OPAQUE_RING_STD) { | |
b196c7e4 | 4647 | ri = &tp->prodring[0].rx_std_buffers[desc_idx]; |
4e5e4f0d | 4648 | dma_addr = dma_unmap_addr(ri, mapping); |
21f581a5 | 4649 | skb = ri->skb; |
4361935a | 4650 | post_ptr = &std_prod_idx; |
f92905de | 4651 | rx_std_posted++; |
1da177e4 | 4652 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
b196c7e4 | 4653 | ri = &tp->prodring[0].rx_jmb_buffers[desc_idx]; |
4e5e4f0d | 4654 | dma_addr = dma_unmap_addr(ri, mapping); |
21f581a5 | 4655 | skb = ri->skb; |
4361935a | 4656 | post_ptr = &jmb_prod_idx; |
21f581a5 | 4657 | } else |
1da177e4 | 4658 | goto next_pkt_nopost; |
1da177e4 LT |
4659 | |
4660 | work_mask |= opaque_key; | |
4661 | ||
4662 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && | |
4663 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) { | |
4664 | drop_it: | |
a3896167 | 4665 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
1da177e4 LT |
4666 | desc_idx, *post_ptr); |
4667 | drop_it_no_recycle: | |
4668 | /* Other statistics kept track of by card. */ | |
4669 | tp->net_stats.rx_dropped++; | |
4670 | goto next_pkt; | |
4671 | } | |
4672 | ||
ad829268 MC |
4673 | len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - |
4674 | ETH_FCS_LEN; | |
1da177e4 | 4675 | |
d2757fc4 | 4676 | if (len > TG3_RX_COPY_THRESH(tp)) { |
1da177e4 LT |
4677 | int skb_size; |
4678 | ||
86b21e59 | 4679 | skb_size = tg3_alloc_rx_skb(tp, tpr, opaque_key, |
afc081f8 | 4680 | *post_ptr); |
1da177e4 LT |
4681 | if (skb_size < 0) |
4682 | goto drop_it; | |
4683 | ||
287be12e | 4684 | pci_unmap_single(tp->pdev, dma_addr, skb_size, |
1da177e4 LT |
4685 | PCI_DMA_FROMDEVICE); |
4686 | ||
61e800cf MC |
4687 | /* Ensure that the update to the skb happens |
4688 | * after the usage of the old DMA mapping. | |
4689 | */ | |
4690 | smp_wmb(); | |
4691 | ||
4692 | ri->skb = NULL; | |
4693 | ||
1da177e4 LT |
4694 | skb_put(skb, len); |
4695 | } else { | |
4696 | struct sk_buff *copy_skb; | |
4697 | ||
a3896167 | 4698 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
1da177e4 LT |
4699 | desc_idx, *post_ptr); |
4700 | ||
9dc7a113 MC |
4701 | copy_skb = netdev_alloc_skb(tp->dev, len + VLAN_HLEN + |
4702 | TG3_RAW_IP_ALIGN); | |
1da177e4 LT |
4703 | if (copy_skb == NULL) |
4704 | goto drop_it_no_recycle; | |
4705 | ||
9dc7a113 | 4706 | skb_reserve(copy_skb, TG3_RAW_IP_ALIGN + VLAN_HLEN); |
1da177e4 LT |
4707 | skb_put(copy_skb, len); |
4708 | pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); | |
d626f62b | 4709 | skb_copy_from_linear_data(skb, copy_skb->data, len); |
1da177e4 LT |
4710 | pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); |
4711 | ||
4712 | /* We'll reuse the original ring buffer. */ | |
4713 | skb = copy_skb; | |
4714 | } | |
4715 | ||
4716 | if ((tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) && | |
4717 | (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && | |
4718 | (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK) | |
4719 | >> RXD_TCPCSUM_SHIFT) == 0xffff)) | |
4720 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
4721 | else | |
4722 | skb->ip_summed = CHECKSUM_NONE; | |
4723 | ||
4724 | skb->protocol = eth_type_trans(skb, tp->dev); | |
f7b493e0 MC |
4725 | |
4726 | if (len > (tp->dev->mtu + ETH_HLEN) && | |
4727 | skb->protocol != htons(ETH_P_8021Q)) { | |
4728 | dev_kfree_skb(skb); | |
4729 | goto next_pkt; | |
4730 | } | |
4731 | ||
9dc7a113 MC |
4732 | if (desc->type_flags & RXD_FLAG_VLAN && |
4733 | !(tp->rx_mode & RX_MODE_KEEP_VLAN_TAG)) { | |
4734 | vtag = desc->err_vlan & RXD_VLAN_MASK; | |
1da177e4 | 4735 | #if TG3_VLAN_TAG_USED |
9dc7a113 MC |
4736 | if (tp->vlgrp) |
4737 | hw_vlan = true; | |
4738 | else | |
4739 | #endif | |
4740 | { | |
4741 | struct vlan_ethhdr *ve = (struct vlan_ethhdr *) | |
4742 | __skb_push(skb, VLAN_HLEN); | |
4743 | ||
4744 | memmove(ve, skb->data + VLAN_HLEN, | |
4745 | ETH_ALEN * 2); | |
4746 | ve->h_vlan_proto = htons(ETH_P_8021Q); | |
4747 | ve->h_vlan_TCI = htons(vtag); | |
4748 | } | |
4749 | } | |
4750 | ||
4751 | #if TG3_VLAN_TAG_USED | |
4752 | if (hw_vlan) | |
4753 | vlan_gro_receive(&tnapi->napi, tp->vlgrp, vtag, skb); | |
4754 | else | |
1da177e4 | 4755 | #endif |
17375d25 | 4756 | napi_gro_receive(&tnapi->napi, skb); |
1da177e4 | 4757 | |
1da177e4 LT |
4758 | received++; |
4759 | budget--; | |
4760 | ||
4761 | next_pkt: | |
4762 | (*post_ptr)++; | |
f92905de MC |
4763 | |
4764 | if (unlikely(rx_std_posted >= tp->rx_std_max_post)) { | |
86cfe4ff MC |
4765 | tpr->rx_std_prod_idx = std_prod_idx % TG3_RX_RING_SIZE; |
4766 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, | |
4767 | tpr->rx_std_prod_idx); | |
f92905de MC |
4768 | work_mask &= ~RXD_OPAQUE_RING_STD; |
4769 | rx_std_posted = 0; | |
4770 | } | |
1da177e4 | 4771 | next_pkt_nopost: |
483ba50b | 4772 | sw_idx++; |
6b31a515 | 4773 | sw_idx &= (TG3_RX_RCB_RING_SIZE(tp) - 1); |
52f6d697 MC |
4774 | |
4775 | /* Refresh hw_idx to see if there is new work */ | |
4776 | if (sw_idx == hw_idx) { | |
8d9d7cfc | 4777 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
52f6d697 MC |
4778 | rmb(); |
4779 | } | |
1da177e4 LT |
4780 | } |
4781 | ||
4782 | /* ACK the status ring. */ | |
72334482 MC |
4783 | tnapi->rx_rcb_ptr = sw_idx; |
4784 | tw32_rx_mbox(tnapi->consmbox, sw_idx); | |
1da177e4 LT |
4785 | |
4786 | /* Refill RX ring(s). */ | |
e4af1af9 | 4787 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS)) { |
b196c7e4 MC |
4788 | if (work_mask & RXD_OPAQUE_RING_STD) { |
4789 | tpr->rx_std_prod_idx = std_prod_idx % TG3_RX_RING_SIZE; | |
4790 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, | |
4791 | tpr->rx_std_prod_idx); | |
4792 | } | |
4793 | if (work_mask & RXD_OPAQUE_RING_JUMBO) { | |
4794 | tpr->rx_jmb_prod_idx = jmb_prod_idx % | |
4795 | TG3_RX_JUMBO_RING_SIZE; | |
4796 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, | |
4797 | tpr->rx_jmb_prod_idx); | |
4798 | } | |
4799 | mmiowb(); | |
4800 | } else if (work_mask) { | |
4801 | /* rx_std_buffers[] and rx_jmb_buffers[] entries must be | |
4802 | * updated before the producer indices can be updated. | |
4803 | */ | |
4804 | smp_wmb(); | |
4805 | ||
4361935a | 4806 | tpr->rx_std_prod_idx = std_prod_idx % TG3_RX_RING_SIZE; |
4361935a | 4807 | tpr->rx_jmb_prod_idx = jmb_prod_idx % TG3_RX_JUMBO_RING_SIZE; |
b196c7e4 | 4808 | |
e4af1af9 MC |
4809 | if (tnapi != &tp->napi[1]) |
4810 | napi_schedule(&tp->napi[1].napi); | |
1da177e4 | 4811 | } |
1da177e4 LT |
4812 | |
4813 | return received; | |
4814 | } | |
4815 | ||
35f2d7d0 | 4816 | static void tg3_poll_link(struct tg3 *tp) |
1da177e4 | 4817 | { |
1da177e4 LT |
4818 | /* handle link change and other phy events */ |
4819 | if (!(tp->tg3_flags & | |
4820 | (TG3_FLAG_USE_LINKCHG_REG | | |
4821 | TG3_FLAG_POLL_SERDES))) { | |
35f2d7d0 MC |
4822 | struct tg3_hw_status *sblk = tp->napi[0].hw_status; |
4823 | ||
1da177e4 LT |
4824 | if (sblk->status & SD_STATUS_LINK_CHG) { |
4825 | sblk->status = SD_STATUS_UPDATED | | |
35f2d7d0 | 4826 | (sblk->status & ~SD_STATUS_LINK_CHG); |
f47c11ee | 4827 | spin_lock(&tp->lock); |
dd477003 MC |
4828 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
4829 | tw32_f(MAC_STATUS, | |
4830 | (MAC_STATUS_SYNC_CHANGED | | |
4831 | MAC_STATUS_CFG_CHANGED | | |
4832 | MAC_STATUS_MI_COMPLETION | | |
4833 | MAC_STATUS_LNKSTATE_CHANGED)); | |
4834 | udelay(40); | |
4835 | } else | |
4836 | tg3_setup_phy(tp, 0); | |
f47c11ee | 4837 | spin_unlock(&tp->lock); |
1da177e4 LT |
4838 | } |
4839 | } | |
35f2d7d0 MC |
4840 | } |
4841 | ||
f89f38b8 MC |
4842 | static int tg3_rx_prodring_xfer(struct tg3 *tp, |
4843 | struct tg3_rx_prodring_set *dpr, | |
4844 | struct tg3_rx_prodring_set *spr) | |
b196c7e4 MC |
4845 | { |
4846 | u32 si, di, cpycnt, src_prod_idx; | |
f89f38b8 | 4847 | int i, err = 0; |
b196c7e4 MC |
4848 | |
4849 | while (1) { | |
4850 | src_prod_idx = spr->rx_std_prod_idx; | |
4851 | ||
4852 | /* Make sure updates to the rx_std_buffers[] entries and the | |
4853 | * standard producer index are seen in the correct order. | |
4854 | */ | |
4855 | smp_rmb(); | |
4856 | ||
4857 | if (spr->rx_std_cons_idx == src_prod_idx) | |
4858 | break; | |
4859 | ||
4860 | if (spr->rx_std_cons_idx < src_prod_idx) | |
4861 | cpycnt = src_prod_idx - spr->rx_std_cons_idx; | |
4862 | else | |
4863 | cpycnt = TG3_RX_RING_SIZE - spr->rx_std_cons_idx; | |
4864 | ||
4865 | cpycnt = min(cpycnt, TG3_RX_RING_SIZE - dpr->rx_std_prod_idx); | |
4866 | ||
4867 | si = spr->rx_std_cons_idx; | |
4868 | di = dpr->rx_std_prod_idx; | |
4869 | ||
e92967bf MC |
4870 | for (i = di; i < di + cpycnt; i++) { |
4871 | if (dpr->rx_std_buffers[i].skb) { | |
4872 | cpycnt = i - di; | |
f89f38b8 | 4873 | err = -ENOSPC; |
e92967bf MC |
4874 | break; |
4875 | } | |
4876 | } | |
4877 | ||
4878 | if (!cpycnt) | |
4879 | break; | |
4880 | ||
4881 | /* Ensure that updates to the rx_std_buffers ring and the | |
4882 | * shadowed hardware producer ring from tg3_recycle_skb() are | |
4883 | * ordered correctly WRT the skb check above. | |
4884 | */ | |
4885 | smp_rmb(); | |
4886 | ||
b196c7e4 MC |
4887 | memcpy(&dpr->rx_std_buffers[di], |
4888 | &spr->rx_std_buffers[si], | |
4889 | cpycnt * sizeof(struct ring_info)); | |
4890 | ||
4891 | for (i = 0; i < cpycnt; i++, di++, si++) { | |
4892 | struct tg3_rx_buffer_desc *sbd, *dbd; | |
4893 | sbd = &spr->rx_std[si]; | |
4894 | dbd = &dpr->rx_std[di]; | |
4895 | dbd->addr_hi = sbd->addr_hi; | |
4896 | dbd->addr_lo = sbd->addr_lo; | |
4897 | } | |
4898 | ||
4899 | spr->rx_std_cons_idx = (spr->rx_std_cons_idx + cpycnt) % | |
4900 | TG3_RX_RING_SIZE; | |
4901 | dpr->rx_std_prod_idx = (dpr->rx_std_prod_idx + cpycnt) % | |
4902 | TG3_RX_RING_SIZE; | |
4903 | } | |
4904 | ||
4905 | while (1) { | |
4906 | src_prod_idx = spr->rx_jmb_prod_idx; | |
4907 | ||
4908 | /* Make sure updates to the rx_jmb_buffers[] entries and | |
4909 | * the jumbo producer index are seen in the correct order. | |
4910 | */ | |
4911 | smp_rmb(); | |
4912 | ||
4913 | if (spr->rx_jmb_cons_idx == src_prod_idx) | |
4914 | break; | |
4915 | ||
4916 | if (spr->rx_jmb_cons_idx < src_prod_idx) | |
4917 | cpycnt = src_prod_idx - spr->rx_jmb_cons_idx; | |
4918 | else | |
4919 | cpycnt = TG3_RX_JUMBO_RING_SIZE - spr->rx_jmb_cons_idx; | |
4920 | ||
4921 | cpycnt = min(cpycnt, | |
4922 | TG3_RX_JUMBO_RING_SIZE - dpr->rx_jmb_prod_idx); | |
4923 | ||
4924 | si = spr->rx_jmb_cons_idx; | |
4925 | di = dpr->rx_jmb_prod_idx; | |
4926 | ||
e92967bf MC |
4927 | for (i = di; i < di + cpycnt; i++) { |
4928 | if (dpr->rx_jmb_buffers[i].skb) { | |
4929 | cpycnt = i - di; | |
f89f38b8 | 4930 | err = -ENOSPC; |
e92967bf MC |
4931 | break; |
4932 | } | |
4933 | } | |
4934 | ||
4935 | if (!cpycnt) | |
4936 | break; | |
4937 | ||
4938 | /* Ensure that updates to the rx_jmb_buffers ring and the | |
4939 | * shadowed hardware producer ring from tg3_recycle_skb() are | |
4940 | * ordered correctly WRT the skb check above. | |
4941 | */ | |
4942 | smp_rmb(); | |
4943 | ||
b196c7e4 MC |
4944 | memcpy(&dpr->rx_jmb_buffers[di], |
4945 | &spr->rx_jmb_buffers[si], | |
4946 | cpycnt * sizeof(struct ring_info)); | |
4947 | ||
4948 | for (i = 0; i < cpycnt; i++, di++, si++) { | |
4949 | struct tg3_rx_buffer_desc *sbd, *dbd; | |
4950 | sbd = &spr->rx_jmb[si].std; | |
4951 | dbd = &dpr->rx_jmb[di].std; | |
4952 | dbd->addr_hi = sbd->addr_hi; | |
4953 | dbd->addr_lo = sbd->addr_lo; | |
4954 | } | |
4955 | ||
4956 | spr->rx_jmb_cons_idx = (spr->rx_jmb_cons_idx + cpycnt) % | |
4957 | TG3_RX_JUMBO_RING_SIZE; | |
4958 | dpr->rx_jmb_prod_idx = (dpr->rx_jmb_prod_idx + cpycnt) % | |
4959 | TG3_RX_JUMBO_RING_SIZE; | |
4960 | } | |
f89f38b8 MC |
4961 | |
4962 | return err; | |
b196c7e4 MC |
4963 | } |
4964 | ||
35f2d7d0 MC |
4965 | static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget) |
4966 | { | |
4967 | struct tg3 *tp = tnapi->tp; | |
1da177e4 LT |
4968 | |
4969 | /* run TX completion thread */ | |
f3f3f27e | 4970 | if (tnapi->hw_status->idx[0].tx_consumer != tnapi->tx_cons) { |
17375d25 | 4971 | tg3_tx(tnapi); |
6f535763 | 4972 | if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) |
4fd7ab59 | 4973 | return work_done; |
1da177e4 LT |
4974 | } |
4975 | ||
1da177e4 LT |
4976 | /* run RX thread, within the bounds set by NAPI. |
4977 | * All RX "locking" is done by ensuring outside | |
bea3348e | 4978 | * code synchronizes with tg3->napi.poll() |
1da177e4 | 4979 | */ |
8d9d7cfc | 4980 | if (*(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
17375d25 | 4981 | work_done += tg3_rx(tnapi, budget - work_done); |
1da177e4 | 4982 | |
b196c7e4 | 4983 | if ((tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS) && tnapi == &tp->napi[1]) { |
e4af1af9 | 4984 | struct tg3_rx_prodring_set *dpr = &tp->prodring[0]; |
f89f38b8 | 4985 | int i, err = 0; |
e4af1af9 MC |
4986 | u32 std_prod_idx = dpr->rx_std_prod_idx; |
4987 | u32 jmb_prod_idx = dpr->rx_jmb_prod_idx; | |
b196c7e4 | 4988 | |
e4af1af9 | 4989 | for (i = 1; i < tp->irq_cnt; i++) |
f89f38b8 MC |
4990 | err |= tg3_rx_prodring_xfer(tp, dpr, |
4991 | tp->napi[i].prodring); | |
b196c7e4 MC |
4992 | |
4993 | wmb(); | |
4994 | ||
e4af1af9 MC |
4995 | if (std_prod_idx != dpr->rx_std_prod_idx) |
4996 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, | |
4997 | dpr->rx_std_prod_idx); | |
b196c7e4 | 4998 | |
e4af1af9 MC |
4999 | if (jmb_prod_idx != dpr->rx_jmb_prod_idx) |
5000 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, | |
5001 | dpr->rx_jmb_prod_idx); | |
b196c7e4 MC |
5002 | |
5003 | mmiowb(); | |
f89f38b8 MC |
5004 | |
5005 | if (err) | |
5006 | tw32_f(HOSTCC_MODE, tp->coal_now); | |
b196c7e4 MC |
5007 | } |
5008 | ||
6f535763 DM |
5009 | return work_done; |
5010 | } | |
5011 | ||
35f2d7d0 MC |
5012 | static int tg3_poll_msix(struct napi_struct *napi, int budget) |
5013 | { | |
5014 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); | |
5015 | struct tg3 *tp = tnapi->tp; | |
5016 | int work_done = 0; | |
5017 | struct tg3_hw_status *sblk = tnapi->hw_status; | |
5018 | ||
5019 | while (1) { | |
5020 | work_done = tg3_poll_work(tnapi, work_done, budget); | |
5021 | ||
5022 | if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) | |
5023 | goto tx_recovery; | |
5024 | ||
5025 | if (unlikely(work_done >= budget)) | |
5026 | break; | |
5027 | ||
c6cdf436 | 5028 | /* tp->last_tag is used in tg3_int_reenable() below |
35f2d7d0 MC |
5029 | * to tell the hw how much work has been processed, |
5030 | * so we must read it before checking for more work. | |
5031 | */ | |
5032 | tnapi->last_tag = sblk->status_tag; | |
5033 | tnapi->last_irq_tag = tnapi->last_tag; | |
5034 | rmb(); | |
5035 | ||
5036 | /* check for RX/TX work to do */ | |
6d40db7b MC |
5037 | if (likely(sblk->idx[0].tx_consumer == tnapi->tx_cons && |
5038 | *(tnapi->rx_rcb_prod_idx) == tnapi->rx_rcb_ptr)) { | |
35f2d7d0 MC |
5039 | napi_complete(napi); |
5040 | /* Reenable interrupts. */ | |
5041 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); | |
5042 | mmiowb(); | |
5043 | break; | |
5044 | } | |
5045 | } | |
5046 | ||
5047 | return work_done; | |
5048 | ||
5049 | tx_recovery: | |
5050 | /* work_done is guaranteed to be less than budget. */ | |
5051 | napi_complete(napi); | |
5052 | schedule_work(&tp->reset_task); | |
5053 | return work_done; | |
5054 | } | |
5055 | ||
6f535763 DM |
5056 | static int tg3_poll(struct napi_struct *napi, int budget) |
5057 | { | |
8ef0442f MC |
5058 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
5059 | struct tg3 *tp = tnapi->tp; | |
6f535763 | 5060 | int work_done = 0; |
898a56f8 | 5061 | struct tg3_hw_status *sblk = tnapi->hw_status; |
6f535763 DM |
5062 | |
5063 | while (1) { | |
35f2d7d0 MC |
5064 | tg3_poll_link(tp); |
5065 | ||
17375d25 | 5066 | work_done = tg3_poll_work(tnapi, work_done, budget); |
6f535763 DM |
5067 | |
5068 | if (unlikely(tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING)) | |
5069 | goto tx_recovery; | |
5070 | ||
5071 | if (unlikely(work_done >= budget)) | |
5072 | break; | |
5073 | ||
4fd7ab59 | 5074 | if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) { |
17375d25 | 5075 | /* tp->last_tag is used in tg3_int_reenable() below |
4fd7ab59 MC |
5076 | * to tell the hw how much work has been processed, |
5077 | * so we must read it before checking for more work. | |
5078 | */ | |
898a56f8 MC |
5079 | tnapi->last_tag = sblk->status_tag; |
5080 | tnapi->last_irq_tag = tnapi->last_tag; | |
4fd7ab59 MC |
5081 | rmb(); |
5082 | } else | |
5083 | sblk->status &= ~SD_STATUS_UPDATED; | |
6f535763 | 5084 | |
17375d25 | 5085 | if (likely(!tg3_has_work(tnapi))) { |
288379f0 | 5086 | napi_complete(napi); |
17375d25 | 5087 | tg3_int_reenable(tnapi); |
6f535763 DM |
5088 | break; |
5089 | } | |
1da177e4 LT |
5090 | } |
5091 | ||
bea3348e | 5092 | return work_done; |
6f535763 DM |
5093 | |
5094 | tx_recovery: | |
4fd7ab59 | 5095 | /* work_done is guaranteed to be less than budget. */ |
288379f0 | 5096 | napi_complete(napi); |
6f535763 | 5097 | schedule_work(&tp->reset_task); |
4fd7ab59 | 5098 | return work_done; |
1da177e4 LT |
5099 | } |
5100 | ||
f47c11ee DM |
5101 | static void tg3_irq_quiesce(struct tg3 *tp) |
5102 | { | |
4f125f42 MC |
5103 | int i; |
5104 | ||
f47c11ee DM |
5105 | BUG_ON(tp->irq_sync); |
5106 | ||
5107 | tp->irq_sync = 1; | |
5108 | smp_mb(); | |
5109 | ||
4f125f42 MC |
5110 | for (i = 0; i < tp->irq_cnt; i++) |
5111 | synchronize_irq(tp->napi[i].irq_vec); | |
f47c11ee DM |
5112 | } |
5113 | ||
5114 | static inline int tg3_irq_sync(struct tg3 *tp) | |
5115 | { | |
5116 | return tp->irq_sync; | |
5117 | } | |
5118 | ||
5119 | /* Fully shutdown all tg3 driver activity elsewhere in the system. | |
5120 | * If irq_sync is non-zero, then the IRQ handler must be synchronized | |
5121 | * with as well. Most of the time, this is not necessary except when | |
5122 | * shutting down the device. | |
5123 | */ | |
5124 | static inline void tg3_full_lock(struct tg3 *tp, int irq_sync) | |
5125 | { | |
46966545 | 5126 | spin_lock_bh(&tp->lock); |
f47c11ee DM |
5127 | if (irq_sync) |
5128 | tg3_irq_quiesce(tp); | |
f47c11ee DM |
5129 | } |
5130 | ||
5131 | static inline void tg3_full_unlock(struct tg3 *tp) | |
5132 | { | |
f47c11ee DM |
5133 | spin_unlock_bh(&tp->lock); |
5134 | } | |
5135 | ||
fcfa0a32 MC |
5136 | /* One-shot MSI handler - Chip automatically disables interrupt |
5137 | * after sending MSI so driver doesn't have to do it. | |
5138 | */ | |
7d12e780 | 5139 | static irqreturn_t tg3_msi_1shot(int irq, void *dev_id) |
fcfa0a32 | 5140 | { |
09943a18 MC |
5141 | struct tg3_napi *tnapi = dev_id; |
5142 | struct tg3 *tp = tnapi->tp; | |
fcfa0a32 | 5143 | |
898a56f8 | 5144 | prefetch(tnapi->hw_status); |
0c1d0e2b MC |
5145 | if (tnapi->rx_rcb) |
5146 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); | |
fcfa0a32 MC |
5147 | |
5148 | if (likely(!tg3_irq_sync(tp))) | |
09943a18 | 5149 | napi_schedule(&tnapi->napi); |
fcfa0a32 MC |
5150 | |
5151 | return IRQ_HANDLED; | |
5152 | } | |
5153 | ||
88b06bc2 MC |
5154 | /* MSI ISR - No need to check for interrupt sharing and no need to |
5155 | * flush status block and interrupt mailbox. PCI ordering rules | |
5156 | * guarantee that MSI will arrive after the status block. | |
5157 | */ | |
7d12e780 | 5158 | static irqreturn_t tg3_msi(int irq, void *dev_id) |
88b06bc2 | 5159 | { |
09943a18 MC |
5160 | struct tg3_napi *tnapi = dev_id; |
5161 | struct tg3 *tp = tnapi->tp; | |
88b06bc2 | 5162 | |
898a56f8 | 5163 | prefetch(tnapi->hw_status); |
0c1d0e2b MC |
5164 | if (tnapi->rx_rcb) |
5165 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); | |
88b06bc2 | 5166 | /* |
fac9b83e | 5167 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
88b06bc2 | 5168 | * chip-internal interrupt pending events. |
fac9b83e | 5169 | * Writing non-zero to intr-mbox-0 additional tells the |
88b06bc2 MC |
5170 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
5171 | * event coalescing. | |
5172 | */ | |
5173 | tw32_mailbox(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); | |
61487480 | 5174 | if (likely(!tg3_irq_sync(tp))) |
09943a18 | 5175 | napi_schedule(&tnapi->napi); |
61487480 | 5176 | |
88b06bc2 MC |
5177 | return IRQ_RETVAL(1); |
5178 | } | |
5179 | ||
7d12e780 | 5180 | static irqreturn_t tg3_interrupt(int irq, void *dev_id) |
1da177e4 | 5181 | { |
09943a18 MC |
5182 | struct tg3_napi *tnapi = dev_id; |
5183 | struct tg3 *tp = tnapi->tp; | |
898a56f8 | 5184 | struct tg3_hw_status *sblk = tnapi->hw_status; |
1da177e4 LT |
5185 | unsigned int handled = 1; |
5186 | ||
1da177e4 LT |
5187 | /* In INTx mode, it is possible for the interrupt to arrive at |
5188 | * the CPU before the status block posted prior to the interrupt. | |
5189 | * Reading the PCI State register will confirm whether the | |
5190 | * interrupt is ours and will flush the status block. | |
5191 | */ | |
d18edcb2 MC |
5192 | if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) { |
5193 | if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) || | |
5194 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { | |
5195 | handled = 0; | |
f47c11ee | 5196 | goto out; |
fac9b83e | 5197 | } |
d18edcb2 MC |
5198 | } |
5199 | ||
5200 | /* | |
5201 | * Writing any value to intr-mbox-0 clears PCI INTA# and | |
5202 | * chip-internal interrupt pending events. | |
5203 | * Writing non-zero to intr-mbox-0 additional tells the | |
5204 | * NIC to stop sending us irqs, engaging "in-intr-handler" | |
5205 | * event coalescing. | |
c04cb347 MC |
5206 | * |
5207 | * Flush the mailbox to de-assert the IRQ immediately to prevent | |
5208 | * spurious interrupts. The flush impacts performance but | |
5209 | * excessive spurious interrupts can be worse in some cases. | |
d18edcb2 | 5210 | */ |
c04cb347 | 5211 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
d18edcb2 MC |
5212 | if (tg3_irq_sync(tp)) |
5213 | goto out; | |
5214 | sblk->status &= ~SD_STATUS_UPDATED; | |
17375d25 | 5215 | if (likely(tg3_has_work(tnapi))) { |
72334482 | 5216 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
09943a18 | 5217 | napi_schedule(&tnapi->napi); |
d18edcb2 MC |
5218 | } else { |
5219 | /* No work, shared interrupt perhaps? re-enable | |
5220 | * interrupts, and flush that PCI write | |
5221 | */ | |
5222 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, | |
5223 | 0x00000000); | |
fac9b83e | 5224 | } |
f47c11ee | 5225 | out: |
fac9b83e DM |
5226 | return IRQ_RETVAL(handled); |
5227 | } | |
5228 | ||
7d12e780 | 5229 | static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id) |
fac9b83e | 5230 | { |
09943a18 MC |
5231 | struct tg3_napi *tnapi = dev_id; |
5232 | struct tg3 *tp = tnapi->tp; | |
898a56f8 | 5233 | struct tg3_hw_status *sblk = tnapi->hw_status; |
fac9b83e DM |
5234 | unsigned int handled = 1; |
5235 | ||
fac9b83e DM |
5236 | /* In INTx mode, it is possible for the interrupt to arrive at |
5237 | * the CPU before the status block posted prior to the interrupt. | |
5238 | * Reading the PCI State register will confirm whether the | |
5239 | * interrupt is ours and will flush the status block. | |
5240 | */ | |
898a56f8 | 5241 | if (unlikely(sblk->status_tag == tnapi->last_irq_tag)) { |
d18edcb2 MC |
5242 | if ((tp->tg3_flags & TG3_FLAG_CHIP_RESETTING) || |
5243 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { | |
5244 | handled = 0; | |
f47c11ee | 5245 | goto out; |
1da177e4 | 5246 | } |
d18edcb2 MC |
5247 | } |
5248 | ||
5249 | /* | |
5250 | * writing any value to intr-mbox-0 clears PCI INTA# and | |
5251 | * chip-internal interrupt pending events. | |
5252 | * writing non-zero to intr-mbox-0 additional tells the | |
5253 | * NIC to stop sending us irqs, engaging "in-intr-handler" | |
5254 | * event coalescing. | |
c04cb347 MC |
5255 | * |
5256 | * Flush the mailbox to de-assert the IRQ immediately to prevent | |
5257 | * spurious interrupts. The flush impacts performance but | |
5258 | * excessive spurious interrupts can be worse in some cases. | |
d18edcb2 | 5259 | */ |
c04cb347 | 5260 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
624f8e50 MC |
5261 | |
5262 | /* | |
5263 | * In a shared interrupt configuration, sometimes other devices' | |
5264 | * interrupts will scream. We record the current status tag here | |
5265 | * so that the above check can report that the screaming interrupts | |
5266 | * are unhandled. Eventually they will be silenced. | |
5267 | */ | |
898a56f8 | 5268 | tnapi->last_irq_tag = sblk->status_tag; |
624f8e50 | 5269 | |
d18edcb2 MC |
5270 | if (tg3_irq_sync(tp)) |
5271 | goto out; | |
624f8e50 | 5272 | |
72334482 | 5273 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
624f8e50 | 5274 | |
09943a18 | 5275 | napi_schedule(&tnapi->napi); |
624f8e50 | 5276 | |
f47c11ee | 5277 | out: |
1da177e4 LT |
5278 | return IRQ_RETVAL(handled); |
5279 | } | |
5280 | ||
7938109f | 5281 | /* ISR for interrupt test */ |
7d12e780 | 5282 | static irqreturn_t tg3_test_isr(int irq, void *dev_id) |
7938109f | 5283 | { |
09943a18 MC |
5284 | struct tg3_napi *tnapi = dev_id; |
5285 | struct tg3 *tp = tnapi->tp; | |
898a56f8 | 5286 | struct tg3_hw_status *sblk = tnapi->hw_status; |
7938109f | 5287 | |
f9804ddb MC |
5288 | if ((sblk->status & SD_STATUS_UPDATED) || |
5289 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { | |
b16250e3 | 5290 | tg3_disable_ints(tp); |
7938109f MC |
5291 | return IRQ_RETVAL(1); |
5292 | } | |
5293 | return IRQ_RETVAL(0); | |
5294 | } | |
5295 | ||
8e7a22e3 | 5296 | static int tg3_init_hw(struct tg3 *, int); |
944d980e | 5297 | static int tg3_halt(struct tg3 *, int, int); |
1da177e4 | 5298 | |
b9ec6c1b MC |
5299 | /* Restart hardware after configuration changes, self-test, etc. |
5300 | * Invoked with tp->lock held. | |
5301 | */ | |
5302 | static int tg3_restart_hw(struct tg3 *tp, int reset_phy) | |
78c6146f ED |
5303 | __releases(tp->lock) |
5304 | __acquires(tp->lock) | |
b9ec6c1b MC |
5305 | { |
5306 | int err; | |
5307 | ||
5308 | err = tg3_init_hw(tp, reset_phy); | |
5309 | if (err) { | |
5129c3a3 MC |
5310 | netdev_err(tp->dev, |
5311 | "Failed to re-initialize device, aborting\n"); | |
b9ec6c1b MC |
5312 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
5313 | tg3_full_unlock(tp); | |
5314 | del_timer_sync(&tp->timer); | |
5315 | tp->irq_sync = 0; | |
fed97810 | 5316 | tg3_napi_enable(tp); |
b9ec6c1b MC |
5317 | dev_close(tp->dev); |
5318 | tg3_full_lock(tp, 0); | |
5319 | } | |
5320 | return err; | |
5321 | } | |
5322 | ||
1da177e4 LT |
5323 | #ifdef CONFIG_NET_POLL_CONTROLLER |
5324 | static void tg3_poll_controller(struct net_device *dev) | |
5325 | { | |
4f125f42 | 5326 | int i; |
88b06bc2 MC |
5327 | struct tg3 *tp = netdev_priv(dev); |
5328 | ||
4f125f42 | 5329 | for (i = 0; i < tp->irq_cnt; i++) |
fe234f0e | 5330 | tg3_interrupt(tp->napi[i].irq_vec, &tp->napi[i]); |
1da177e4 LT |
5331 | } |
5332 | #endif | |
5333 | ||
c4028958 | 5334 | static void tg3_reset_task(struct work_struct *work) |
1da177e4 | 5335 | { |
c4028958 | 5336 | struct tg3 *tp = container_of(work, struct tg3, reset_task); |
b02fd9e3 | 5337 | int err; |
1da177e4 LT |
5338 | unsigned int restart_timer; |
5339 | ||
7faa006f | 5340 | tg3_full_lock(tp, 0); |
7faa006f MC |
5341 | |
5342 | if (!netif_running(tp->dev)) { | |
7faa006f MC |
5343 | tg3_full_unlock(tp); |
5344 | return; | |
5345 | } | |
5346 | ||
5347 | tg3_full_unlock(tp); | |
5348 | ||
b02fd9e3 MC |
5349 | tg3_phy_stop(tp); |
5350 | ||
1da177e4 LT |
5351 | tg3_netif_stop(tp); |
5352 | ||
f47c11ee | 5353 | tg3_full_lock(tp, 1); |
1da177e4 LT |
5354 | |
5355 | restart_timer = tp->tg3_flags2 & TG3_FLG2_RESTART_TIMER; | |
5356 | tp->tg3_flags2 &= ~TG3_FLG2_RESTART_TIMER; | |
5357 | ||
df3e6548 MC |
5358 | if (tp->tg3_flags & TG3_FLAG_TX_RECOVERY_PENDING) { |
5359 | tp->write32_tx_mbox = tg3_write32_tx_mbox; | |
5360 | tp->write32_rx_mbox = tg3_write_flush_reg32; | |
5361 | tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER; | |
5362 | tp->tg3_flags &= ~TG3_FLAG_TX_RECOVERY_PENDING; | |
5363 | } | |
5364 | ||
944d980e | 5365 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); |
b02fd9e3 MC |
5366 | err = tg3_init_hw(tp, 1); |
5367 | if (err) | |
b9ec6c1b | 5368 | goto out; |
1da177e4 LT |
5369 | |
5370 | tg3_netif_start(tp); | |
5371 | ||
1da177e4 LT |
5372 | if (restart_timer) |
5373 | mod_timer(&tp->timer, jiffies + 1); | |
7faa006f | 5374 | |
b9ec6c1b | 5375 | out: |
7faa006f | 5376 | tg3_full_unlock(tp); |
b02fd9e3 MC |
5377 | |
5378 | if (!err) | |
5379 | tg3_phy_start(tp); | |
1da177e4 LT |
5380 | } |
5381 | ||
b0408751 MC |
5382 | static void tg3_dump_short_state(struct tg3 *tp) |
5383 | { | |
05dbe005 JP |
5384 | netdev_err(tp->dev, "DEBUG: MAC_TX_STATUS[%08x] MAC_RX_STATUS[%08x]\n", |
5385 | tr32(MAC_TX_STATUS), tr32(MAC_RX_STATUS)); | |
5386 | netdev_err(tp->dev, "DEBUG: RDMAC_STATUS[%08x] WDMAC_STATUS[%08x]\n", | |
5387 | tr32(RDMAC_STATUS), tr32(WDMAC_STATUS)); | |
b0408751 MC |
5388 | } |
5389 | ||
1da177e4 LT |
5390 | static void tg3_tx_timeout(struct net_device *dev) |
5391 | { | |
5392 | struct tg3 *tp = netdev_priv(dev); | |
5393 | ||
b0408751 | 5394 | if (netif_msg_tx_err(tp)) { |
05dbe005 | 5395 | netdev_err(dev, "transmit timed out, resetting\n"); |
b0408751 MC |
5396 | tg3_dump_short_state(tp); |
5397 | } | |
1da177e4 LT |
5398 | |
5399 | schedule_work(&tp->reset_task); | |
5400 | } | |
5401 | ||
c58ec932 MC |
5402 | /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */ |
5403 | static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len) | |
5404 | { | |
5405 | u32 base = (u32) mapping & 0xffffffff; | |
5406 | ||
5407 | return ((base > 0xffffdcc0) && | |
5408 | (base + len + 8 < base)); | |
5409 | } | |
5410 | ||
72f2afb8 MC |
5411 | /* Test for DMA addresses > 40-bit */ |
5412 | static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping, | |
5413 | int len) | |
5414 | { | |
5415 | #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64) | |
6728a8e2 | 5416 | if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) |
50cf156a | 5417 | return (((u64) mapping + len) > DMA_BIT_MASK(40)); |
72f2afb8 MC |
5418 | return 0; |
5419 | #else | |
5420 | return 0; | |
5421 | #endif | |
5422 | } | |
5423 | ||
f3f3f27e | 5424 | static void tg3_set_txd(struct tg3_napi *, int, dma_addr_t, int, u32, u32); |
1da177e4 | 5425 | |
72f2afb8 | 5426 | /* Workaround 4GB and 40-bit hardware DMA bugs. */ |
24f4efd4 MC |
5427 | static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi, |
5428 | struct sk_buff *skb, u32 last_plus_one, | |
5429 | u32 *start, u32 base_flags, u32 mss) | |
1da177e4 | 5430 | { |
24f4efd4 | 5431 | struct tg3 *tp = tnapi->tp; |
41588ba1 | 5432 | struct sk_buff *new_skb; |
c58ec932 | 5433 | dma_addr_t new_addr = 0; |
1da177e4 | 5434 | u32 entry = *start; |
c58ec932 | 5435 | int i, ret = 0; |
1da177e4 | 5436 | |
41588ba1 MC |
5437 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) |
5438 | new_skb = skb_copy(skb, GFP_ATOMIC); | |
5439 | else { | |
5440 | int more_headroom = 4 - ((unsigned long)skb->data & 3); | |
5441 | ||
5442 | new_skb = skb_copy_expand(skb, | |
5443 | skb_headroom(skb) + more_headroom, | |
5444 | skb_tailroom(skb), GFP_ATOMIC); | |
5445 | } | |
5446 | ||
1da177e4 | 5447 | if (!new_skb) { |
c58ec932 MC |
5448 | ret = -1; |
5449 | } else { | |
5450 | /* New SKB is guaranteed to be linear. */ | |
5451 | entry = *start; | |
f4188d8a AD |
5452 | new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len, |
5453 | PCI_DMA_TODEVICE); | |
5454 | /* Make sure the mapping succeeded */ | |
5455 | if (pci_dma_mapping_error(tp->pdev, new_addr)) { | |
5456 | ret = -1; | |
5457 | dev_kfree_skb(new_skb); | |
5458 | new_skb = NULL; | |
90079ce8 | 5459 | |
c58ec932 MC |
5460 | /* Make sure new skb does not cross any 4G boundaries. |
5461 | * Drop the packet if it does. | |
5462 | */ | |
f4188d8a AD |
5463 | } else if ((tp->tg3_flags3 & TG3_FLG3_4G_DMA_BNDRY_BUG) && |
5464 | tg3_4g_overflow_test(new_addr, new_skb->len)) { | |
5465 | pci_unmap_single(tp->pdev, new_addr, new_skb->len, | |
5466 | PCI_DMA_TODEVICE); | |
c58ec932 MC |
5467 | ret = -1; |
5468 | dev_kfree_skb(new_skb); | |
5469 | new_skb = NULL; | |
5470 | } else { | |
f3f3f27e | 5471 | tg3_set_txd(tnapi, entry, new_addr, new_skb->len, |
c58ec932 MC |
5472 | base_flags, 1 | (mss << 1)); |
5473 | *start = NEXT_TX(entry); | |
5474 | } | |
1da177e4 LT |
5475 | } |
5476 | ||
1da177e4 LT |
5477 | /* Now clean up the sw ring entries. */ |
5478 | i = 0; | |
5479 | while (entry != last_plus_one) { | |
f4188d8a AD |
5480 | int len; |
5481 | ||
f3f3f27e | 5482 | if (i == 0) |
f4188d8a | 5483 | len = skb_headlen(skb); |
f3f3f27e | 5484 | else |
f4188d8a AD |
5485 | len = skb_shinfo(skb)->frags[i-1].size; |
5486 | ||
5487 | pci_unmap_single(tp->pdev, | |
4e5e4f0d | 5488 | dma_unmap_addr(&tnapi->tx_buffers[entry], |
f4188d8a AD |
5489 | mapping), |
5490 | len, PCI_DMA_TODEVICE); | |
5491 | if (i == 0) { | |
5492 | tnapi->tx_buffers[entry].skb = new_skb; | |
4e5e4f0d | 5493 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
f4188d8a AD |
5494 | new_addr); |
5495 | } else { | |
f3f3f27e | 5496 | tnapi->tx_buffers[entry].skb = NULL; |
f4188d8a | 5497 | } |
1da177e4 LT |
5498 | entry = NEXT_TX(entry); |
5499 | i++; | |
5500 | } | |
5501 | ||
5502 | dev_kfree_skb(skb); | |
5503 | ||
c58ec932 | 5504 | return ret; |
1da177e4 LT |
5505 | } |
5506 | ||
f3f3f27e | 5507 | static void tg3_set_txd(struct tg3_napi *tnapi, int entry, |
1da177e4 LT |
5508 | dma_addr_t mapping, int len, u32 flags, |
5509 | u32 mss_and_is_end) | |
5510 | { | |
f3f3f27e | 5511 | struct tg3_tx_buffer_desc *txd = &tnapi->tx_ring[entry]; |
1da177e4 LT |
5512 | int is_end = (mss_and_is_end & 0x1); |
5513 | u32 mss = (mss_and_is_end >> 1); | |
5514 | u32 vlan_tag = 0; | |
5515 | ||
5516 | if (is_end) | |
5517 | flags |= TXD_FLAG_END; | |
5518 | if (flags & TXD_FLAG_VLAN) { | |
5519 | vlan_tag = flags >> 16; | |
5520 | flags &= 0xffff; | |
5521 | } | |
5522 | vlan_tag |= (mss << TXD_MSS_SHIFT); | |
5523 | ||
5524 | txd->addr_hi = ((u64) mapping >> 32); | |
5525 | txd->addr_lo = ((u64) mapping & 0xffffffff); | |
5526 | txd->len_flags = (len << TXD_LEN_SHIFT) | flags; | |
5527 | txd->vlan_tag = vlan_tag << TXD_VLAN_TAG_SHIFT; | |
5528 | } | |
5529 | ||
5a6f3074 | 5530 | /* hard_start_xmit for devices that don't have any bugs and |
e849cdc3 | 5531 | * support TG3_FLG2_HW_TSO_2 and TG3_FLG2_HW_TSO_3 only. |
5a6f3074 | 5532 | */ |
61357325 SH |
5533 | static netdev_tx_t tg3_start_xmit(struct sk_buff *skb, |
5534 | struct net_device *dev) | |
5a6f3074 MC |
5535 | { |
5536 | struct tg3 *tp = netdev_priv(dev); | |
5a6f3074 | 5537 | u32 len, entry, base_flags, mss; |
90079ce8 | 5538 | dma_addr_t mapping; |
fe5f5787 MC |
5539 | struct tg3_napi *tnapi; |
5540 | struct netdev_queue *txq; | |
f4188d8a AD |
5541 | unsigned int i, last; |
5542 | ||
fe5f5787 MC |
5543 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
5544 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; | |
19cfaecc | 5545 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
fe5f5787 | 5546 | tnapi++; |
5a6f3074 | 5547 | |
00b70504 | 5548 | /* We are running in BH disabled context with netif_tx_lock |
bea3348e | 5549 | * and TX reclaim runs via tp->napi.poll inside of a software |
5a6f3074 MC |
5550 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
5551 | * no IRQ context deadlocks to worry about either. Rejoice! | |
5552 | */ | |
f3f3f27e | 5553 | if (unlikely(tg3_tx_avail(tnapi) <= (skb_shinfo(skb)->nr_frags + 1))) { |
fe5f5787 MC |
5554 | if (!netif_tx_queue_stopped(txq)) { |
5555 | netif_tx_stop_queue(txq); | |
5a6f3074 MC |
5556 | |
5557 | /* This is a hard error, log it. */ | |
5129c3a3 MC |
5558 | netdev_err(dev, |
5559 | "BUG! Tx Ring full when queue awake!\n"); | |
5a6f3074 | 5560 | } |
5a6f3074 MC |
5561 | return NETDEV_TX_BUSY; |
5562 | } | |
5563 | ||
f3f3f27e | 5564 | entry = tnapi->tx_prod; |
5a6f3074 | 5565 | base_flags = 0; |
be98da6a MC |
5566 | mss = skb_shinfo(skb)->gso_size; |
5567 | if (mss) { | |
5a6f3074 | 5568 | int tcp_opt_len, ip_tcp_len; |
f6eb9b1f | 5569 | u32 hdrlen; |
5a6f3074 MC |
5570 | |
5571 | if (skb_header_cloned(skb) && | |
5572 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) { | |
5573 | dev_kfree_skb(skb); | |
5574 | goto out_unlock; | |
5575 | } | |
5576 | ||
b0026624 | 5577 | if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) |
f6eb9b1f | 5578 | hdrlen = skb_headlen(skb) - ETH_HLEN; |
b0026624 | 5579 | else { |
eddc9ec5 ACM |
5580 | struct iphdr *iph = ip_hdr(skb); |
5581 | ||
ab6a5bb6 | 5582 | tcp_opt_len = tcp_optlen(skb); |
c9bdd4b5 | 5583 | ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr); |
b0026624 | 5584 | |
eddc9ec5 ACM |
5585 | iph->check = 0; |
5586 | iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len); | |
f6eb9b1f | 5587 | hdrlen = ip_tcp_len + tcp_opt_len; |
b0026624 | 5588 | } |
5a6f3074 | 5589 | |
e849cdc3 | 5590 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) { |
f6eb9b1f MC |
5591 | mss |= (hdrlen & 0xc) << 12; |
5592 | if (hdrlen & 0x10) | |
5593 | base_flags |= 0x00000010; | |
5594 | base_flags |= (hdrlen & 0x3e0) << 5; | |
5595 | } else | |
5596 | mss |= hdrlen << 9; | |
5597 | ||
5a6f3074 MC |
5598 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
5599 | TXD_FLAG_CPU_POST_DMA); | |
5600 | ||
aa8223c7 | 5601 | tcp_hdr(skb)->check = 0; |
5a6f3074 | 5602 | |
859a5887 | 5603 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
5a6f3074 | 5604 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
859a5887 MC |
5605 | } |
5606 | ||
5a6f3074 MC |
5607 | #if TG3_VLAN_TAG_USED |
5608 | if (tp->vlgrp != NULL && vlan_tx_tag_present(skb)) | |
5609 | base_flags |= (TXD_FLAG_VLAN | | |
5610 | (vlan_tx_tag_get(skb) << 16)); | |
5611 | #endif | |
5612 | ||
f4188d8a AD |
5613 | len = skb_headlen(skb); |
5614 | ||
5615 | /* Queue skb data, a.k.a. the main skb fragment. */ | |
5616 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); | |
5617 | if (pci_dma_mapping_error(tp->pdev, mapping)) { | |
90079ce8 DM |
5618 | dev_kfree_skb(skb); |
5619 | goto out_unlock; | |
5620 | } | |
5621 | ||
f3f3f27e | 5622 | tnapi->tx_buffers[entry].skb = skb; |
4e5e4f0d | 5623 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
fe5f5787 | 5624 | |
b703df6f | 5625 | if ((tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG) && |
f6eb9b1f MC |
5626 | !mss && skb->len > ETH_DATA_LEN) |
5627 | base_flags |= TXD_FLAG_JMB_PKT; | |
5628 | ||
f3f3f27e | 5629 | tg3_set_txd(tnapi, entry, mapping, len, base_flags, |
5a6f3074 MC |
5630 | (skb_shinfo(skb)->nr_frags == 0) | (mss << 1)); |
5631 | ||
5632 | entry = NEXT_TX(entry); | |
5633 | ||
5634 | /* Now loop through additional data fragments, and queue them. */ | |
5635 | if (skb_shinfo(skb)->nr_frags > 0) { | |
5a6f3074 MC |
5636 | last = skb_shinfo(skb)->nr_frags - 1; |
5637 | for (i = 0; i <= last; i++) { | |
5638 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | |
5639 | ||
5640 | len = frag->size; | |
f4188d8a AD |
5641 | mapping = pci_map_page(tp->pdev, |
5642 | frag->page, | |
5643 | frag->page_offset, | |
5644 | len, PCI_DMA_TODEVICE); | |
5645 | if (pci_dma_mapping_error(tp->pdev, mapping)) | |
5646 | goto dma_error; | |
5647 | ||
f3f3f27e | 5648 | tnapi->tx_buffers[entry].skb = NULL; |
4e5e4f0d | 5649 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
f4188d8a | 5650 | mapping); |
5a6f3074 | 5651 | |
f3f3f27e | 5652 | tg3_set_txd(tnapi, entry, mapping, len, |
5a6f3074 MC |
5653 | base_flags, (i == last) | (mss << 1)); |
5654 | ||
5655 | entry = NEXT_TX(entry); | |
5656 | } | |
5657 | } | |
5658 | ||
5659 | /* Packets are ready, update Tx producer idx local and on card. */ | |
f3f3f27e | 5660 | tw32_tx_mbox(tnapi->prodmbox, entry); |
5a6f3074 | 5661 | |
f3f3f27e MC |
5662 | tnapi->tx_prod = entry; |
5663 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { | |
fe5f5787 | 5664 | netif_tx_stop_queue(txq); |
f65aac16 MC |
5665 | |
5666 | /* netif_tx_stop_queue() must be done before checking | |
5667 | * checking tx index in tg3_tx_avail() below, because in | |
5668 | * tg3_tx(), we update tx index before checking for | |
5669 | * netif_tx_queue_stopped(). | |
5670 | */ | |
5671 | smp_mb(); | |
f3f3f27e | 5672 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
fe5f5787 | 5673 | netif_tx_wake_queue(txq); |
5a6f3074 MC |
5674 | } |
5675 | ||
5676 | out_unlock: | |
cdd0db05 | 5677 | mmiowb(); |
5a6f3074 MC |
5678 | |
5679 | return NETDEV_TX_OK; | |
f4188d8a AD |
5680 | |
5681 | dma_error: | |
5682 | last = i; | |
5683 | entry = tnapi->tx_prod; | |
5684 | tnapi->tx_buffers[entry].skb = NULL; | |
5685 | pci_unmap_single(tp->pdev, | |
4e5e4f0d | 5686 | dma_unmap_addr(&tnapi->tx_buffers[entry], mapping), |
f4188d8a AD |
5687 | skb_headlen(skb), |
5688 | PCI_DMA_TODEVICE); | |
5689 | for (i = 0; i <= last; i++) { | |
5690 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | |
5691 | entry = NEXT_TX(entry); | |
5692 | ||
5693 | pci_unmap_page(tp->pdev, | |
4e5e4f0d | 5694 | dma_unmap_addr(&tnapi->tx_buffers[entry], |
f4188d8a AD |
5695 | mapping), |
5696 | frag->size, PCI_DMA_TODEVICE); | |
5697 | } | |
5698 | ||
5699 | dev_kfree_skb(skb); | |
5700 | return NETDEV_TX_OK; | |
5a6f3074 MC |
5701 | } |
5702 | ||
61357325 SH |
5703 | static netdev_tx_t tg3_start_xmit_dma_bug(struct sk_buff *, |
5704 | struct net_device *); | |
52c0fd83 MC |
5705 | |
5706 | /* Use GSO to workaround a rare TSO bug that may be triggered when the | |
5707 | * TSO header is greater than 80 bytes. | |
5708 | */ | |
5709 | static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb) | |
5710 | { | |
5711 | struct sk_buff *segs, *nskb; | |
f3f3f27e | 5712 | u32 frag_cnt_est = skb_shinfo(skb)->gso_segs * 3; |
52c0fd83 MC |
5713 | |
5714 | /* Estimate the number of fragments in the worst case */ | |
f3f3f27e | 5715 | if (unlikely(tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est)) { |
52c0fd83 | 5716 | netif_stop_queue(tp->dev); |
f65aac16 MC |
5717 | |
5718 | /* netif_tx_stop_queue() must be done before checking | |
5719 | * checking tx index in tg3_tx_avail() below, because in | |
5720 | * tg3_tx(), we update tx index before checking for | |
5721 | * netif_tx_queue_stopped(). | |
5722 | */ | |
5723 | smp_mb(); | |
f3f3f27e | 5724 | if (tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est) |
7f62ad5d MC |
5725 | return NETDEV_TX_BUSY; |
5726 | ||
5727 | netif_wake_queue(tp->dev); | |
52c0fd83 MC |
5728 | } |
5729 | ||
5730 | segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO); | |
801678c5 | 5731 | if (IS_ERR(segs)) |
52c0fd83 MC |
5732 | goto tg3_tso_bug_end; |
5733 | ||
5734 | do { | |
5735 | nskb = segs; | |
5736 | segs = segs->next; | |
5737 | nskb->next = NULL; | |
5738 | tg3_start_xmit_dma_bug(nskb, tp->dev); | |
5739 | } while (segs); | |
5740 | ||
5741 | tg3_tso_bug_end: | |
5742 | dev_kfree_skb(skb); | |
5743 | ||
5744 | return NETDEV_TX_OK; | |
5745 | } | |
52c0fd83 | 5746 | |
5a6f3074 MC |
5747 | /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and |
5748 | * support TG3_FLG2_HW_TSO_1 or firmware TSO only. | |
5749 | */ | |
61357325 SH |
5750 | static netdev_tx_t tg3_start_xmit_dma_bug(struct sk_buff *skb, |
5751 | struct net_device *dev) | |
1da177e4 LT |
5752 | { |
5753 | struct tg3 *tp = netdev_priv(dev); | |
1da177e4 LT |
5754 | u32 len, entry, base_flags, mss; |
5755 | int would_hit_hwbug; | |
90079ce8 | 5756 | dma_addr_t mapping; |
24f4efd4 MC |
5757 | struct tg3_napi *tnapi; |
5758 | struct netdev_queue *txq; | |
f4188d8a AD |
5759 | unsigned int i, last; |
5760 | ||
24f4efd4 MC |
5761 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
5762 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; | |
19cfaecc | 5763 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
24f4efd4 | 5764 | tnapi++; |
1da177e4 | 5765 | |
00b70504 | 5766 | /* We are running in BH disabled context with netif_tx_lock |
bea3348e | 5767 | * and TX reclaim runs via tp->napi.poll inside of a software |
f47c11ee DM |
5768 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
5769 | * no IRQ context deadlocks to worry about either. Rejoice! | |
1da177e4 | 5770 | */ |
f3f3f27e | 5771 | if (unlikely(tg3_tx_avail(tnapi) <= (skb_shinfo(skb)->nr_frags + 1))) { |
24f4efd4 MC |
5772 | if (!netif_tx_queue_stopped(txq)) { |
5773 | netif_tx_stop_queue(txq); | |
1f064a87 SH |
5774 | |
5775 | /* This is a hard error, log it. */ | |
5129c3a3 MC |
5776 | netdev_err(dev, |
5777 | "BUG! Tx Ring full when queue awake!\n"); | |
1f064a87 | 5778 | } |
1da177e4 LT |
5779 | return NETDEV_TX_BUSY; |
5780 | } | |
5781 | ||
f3f3f27e | 5782 | entry = tnapi->tx_prod; |
1da177e4 | 5783 | base_flags = 0; |
84fa7933 | 5784 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
1da177e4 | 5785 | base_flags |= TXD_FLAG_TCPUDP_CSUM; |
24f4efd4 | 5786 | |
be98da6a MC |
5787 | mss = skb_shinfo(skb)->gso_size; |
5788 | if (mss) { | |
eddc9ec5 | 5789 | struct iphdr *iph; |
34195c3d | 5790 | u32 tcp_opt_len, hdr_len; |
1da177e4 LT |
5791 | |
5792 | if (skb_header_cloned(skb) && | |
5793 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) { | |
5794 | dev_kfree_skb(skb); | |
5795 | goto out_unlock; | |
5796 | } | |
5797 | ||
34195c3d | 5798 | iph = ip_hdr(skb); |
ab6a5bb6 | 5799 | tcp_opt_len = tcp_optlen(skb); |
1da177e4 | 5800 | |
34195c3d MC |
5801 | if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) { |
5802 | hdr_len = skb_headlen(skb) - ETH_HLEN; | |
5803 | } else { | |
5804 | u32 ip_tcp_len; | |
5805 | ||
5806 | ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr); | |
5807 | hdr_len = ip_tcp_len + tcp_opt_len; | |
5808 | ||
5809 | iph->check = 0; | |
5810 | iph->tot_len = htons(mss + hdr_len); | |
5811 | } | |
5812 | ||
52c0fd83 | 5813 | if (unlikely((ETH_HLEN + hdr_len) > 80) && |
7f62ad5d | 5814 | (tp->tg3_flags2 & TG3_FLG2_TSO_BUG)) |
de6f31eb | 5815 | return tg3_tso_bug(tp, skb); |
52c0fd83 | 5816 | |
1da177e4 LT |
5817 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
5818 | TXD_FLAG_CPU_POST_DMA); | |
5819 | ||
1da177e4 | 5820 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) { |
aa8223c7 | 5821 | tcp_hdr(skb)->check = 0; |
1da177e4 | 5822 | base_flags &= ~TXD_FLAG_TCPUDP_CSUM; |
aa8223c7 ACM |
5823 | } else |
5824 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, | |
5825 | iph->daddr, 0, | |
5826 | IPPROTO_TCP, | |
5827 | 0); | |
1da177e4 | 5828 | |
615774fe MC |
5829 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) { |
5830 | mss |= (hdr_len & 0xc) << 12; | |
5831 | if (hdr_len & 0x10) | |
5832 | base_flags |= 0x00000010; | |
5833 | base_flags |= (hdr_len & 0x3e0) << 5; | |
5834 | } else if (tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) | |
92c6b8d1 MC |
5835 | mss |= hdr_len << 9; |
5836 | else if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_1) || | |
5837 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { | |
eddc9ec5 | 5838 | if (tcp_opt_len || iph->ihl > 5) { |
1da177e4 LT |
5839 | int tsflags; |
5840 | ||
eddc9ec5 | 5841 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
1da177e4 LT |
5842 | mss |= (tsflags << 11); |
5843 | } | |
5844 | } else { | |
eddc9ec5 | 5845 | if (tcp_opt_len || iph->ihl > 5) { |
1da177e4 LT |
5846 | int tsflags; |
5847 | ||
eddc9ec5 | 5848 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
1da177e4 LT |
5849 | base_flags |= tsflags << 12; |
5850 | } | |
5851 | } | |
5852 | } | |
1da177e4 LT |
5853 | #if TG3_VLAN_TAG_USED |
5854 | if (tp->vlgrp != NULL && vlan_tx_tag_present(skb)) | |
5855 | base_flags |= (TXD_FLAG_VLAN | | |
5856 | (vlan_tx_tag_get(skb) << 16)); | |
5857 | #endif | |
5858 | ||
b703df6f | 5859 | if ((tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG) && |
615774fe MC |
5860 | !mss && skb->len > ETH_DATA_LEN) |
5861 | base_flags |= TXD_FLAG_JMB_PKT; | |
5862 | ||
f4188d8a AD |
5863 | len = skb_headlen(skb); |
5864 | ||
5865 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); | |
5866 | if (pci_dma_mapping_error(tp->pdev, mapping)) { | |
90079ce8 DM |
5867 | dev_kfree_skb(skb); |
5868 | goto out_unlock; | |
5869 | } | |
5870 | ||
f3f3f27e | 5871 | tnapi->tx_buffers[entry].skb = skb; |
4e5e4f0d | 5872 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
1da177e4 LT |
5873 | |
5874 | would_hit_hwbug = 0; | |
5875 | ||
92c6b8d1 MC |
5876 | if ((tp->tg3_flags3 & TG3_FLG3_SHORT_DMA_BUG) && len <= 8) |
5877 | would_hit_hwbug = 1; | |
5878 | ||
0e1406dd MC |
5879 | if ((tp->tg3_flags3 & TG3_FLG3_4G_DMA_BNDRY_BUG) && |
5880 | tg3_4g_overflow_test(mapping, len)) | |
5881 | would_hit_hwbug = 1; | |
5882 | ||
5883 | if ((tp->tg3_flags3 & TG3_FLG3_40BIT_DMA_LIMIT_BUG) && | |
5884 | tg3_40bit_overflow_test(tp, mapping, len)) | |
41588ba1 | 5885 | would_hit_hwbug = 1; |
0e1406dd MC |
5886 | |
5887 | if (tp->tg3_flags3 & TG3_FLG3_5701_DMA_BUG) | |
c58ec932 | 5888 | would_hit_hwbug = 1; |
1da177e4 | 5889 | |
f3f3f27e | 5890 | tg3_set_txd(tnapi, entry, mapping, len, base_flags, |
1da177e4 LT |
5891 | (skb_shinfo(skb)->nr_frags == 0) | (mss << 1)); |
5892 | ||
5893 | entry = NEXT_TX(entry); | |
5894 | ||
5895 | /* Now loop through additional data fragments, and queue them. */ | |
5896 | if (skb_shinfo(skb)->nr_frags > 0) { | |
1da177e4 LT |
5897 | last = skb_shinfo(skb)->nr_frags - 1; |
5898 | for (i = 0; i <= last; i++) { | |
5899 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | |
5900 | ||
5901 | len = frag->size; | |
f4188d8a AD |
5902 | mapping = pci_map_page(tp->pdev, |
5903 | frag->page, | |
5904 | frag->page_offset, | |
5905 | len, PCI_DMA_TODEVICE); | |
1da177e4 | 5906 | |
f3f3f27e | 5907 | tnapi->tx_buffers[entry].skb = NULL; |
4e5e4f0d | 5908 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
f4188d8a AD |
5909 | mapping); |
5910 | if (pci_dma_mapping_error(tp->pdev, mapping)) | |
5911 | goto dma_error; | |
1da177e4 | 5912 | |
92c6b8d1 MC |
5913 | if ((tp->tg3_flags3 & TG3_FLG3_SHORT_DMA_BUG) && |
5914 | len <= 8) | |
5915 | would_hit_hwbug = 1; | |
5916 | ||
0e1406dd MC |
5917 | if ((tp->tg3_flags3 & TG3_FLG3_4G_DMA_BNDRY_BUG) && |
5918 | tg3_4g_overflow_test(mapping, len)) | |
c58ec932 | 5919 | would_hit_hwbug = 1; |
1da177e4 | 5920 | |
0e1406dd MC |
5921 | if ((tp->tg3_flags3 & TG3_FLG3_40BIT_DMA_LIMIT_BUG) && |
5922 | tg3_40bit_overflow_test(tp, mapping, len)) | |
72f2afb8 MC |
5923 | would_hit_hwbug = 1; |
5924 | ||
1da177e4 | 5925 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) |
f3f3f27e | 5926 | tg3_set_txd(tnapi, entry, mapping, len, |
1da177e4 LT |
5927 | base_flags, (i == last)|(mss << 1)); |
5928 | else | |
f3f3f27e | 5929 | tg3_set_txd(tnapi, entry, mapping, len, |
1da177e4 LT |
5930 | base_flags, (i == last)); |
5931 | ||
5932 | entry = NEXT_TX(entry); | |
5933 | } | |
5934 | } | |
5935 | ||
5936 | if (would_hit_hwbug) { | |
5937 | u32 last_plus_one = entry; | |
5938 | u32 start; | |
1da177e4 | 5939 | |
c58ec932 MC |
5940 | start = entry - 1 - skb_shinfo(skb)->nr_frags; |
5941 | start &= (TG3_TX_RING_SIZE - 1); | |
1da177e4 LT |
5942 | |
5943 | /* If the workaround fails due to memory/mapping | |
5944 | * failure, silently drop this packet. | |
5945 | */ | |
24f4efd4 | 5946 | if (tigon3_dma_hwbug_workaround(tnapi, skb, last_plus_one, |
c58ec932 | 5947 | &start, base_flags, mss)) |
1da177e4 LT |
5948 | goto out_unlock; |
5949 | ||
5950 | entry = start; | |
5951 | } | |
5952 | ||
5953 | /* Packets are ready, update Tx producer idx local and on card. */ | |
24f4efd4 | 5954 | tw32_tx_mbox(tnapi->prodmbox, entry); |
1da177e4 | 5955 | |
f3f3f27e MC |
5956 | tnapi->tx_prod = entry; |
5957 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { | |
24f4efd4 | 5958 | netif_tx_stop_queue(txq); |
f65aac16 MC |
5959 | |
5960 | /* netif_tx_stop_queue() must be done before checking | |
5961 | * checking tx index in tg3_tx_avail() below, because in | |
5962 | * tg3_tx(), we update tx index before checking for | |
5963 | * netif_tx_queue_stopped(). | |
5964 | */ | |
5965 | smp_mb(); | |
f3f3f27e | 5966 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
24f4efd4 | 5967 | netif_tx_wake_queue(txq); |
51b91468 | 5968 | } |
1da177e4 LT |
5969 | |
5970 | out_unlock: | |
cdd0db05 | 5971 | mmiowb(); |
1da177e4 LT |
5972 | |
5973 | return NETDEV_TX_OK; | |
f4188d8a AD |
5974 | |
5975 | dma_error: | |
5976 | last = i; | |
5977 | entry = tnapi->tx_prod; | |
5978 | tnapi->tx_buffers[entry].skb = NULL; | |
5979 | pci_unmap_single(tp->pdev, | |
4e5e4f0d | 5980 | dma_unmap_addr(&tnapi->tx_buffers[entry], mapping), |
f4188d8a AD |
5981 | skb_headlen(skb), |
5982 | PCI_DMA_TODEVICE); | |
5983 | for (i = 0; i <= last; i++) { | |
5984 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | |
5985 | entry = NEXT_TX(entry); | |
5986 | ||
5987 | pci_unmap_page(tp->pdev, | |
4e5e4f0d | 5988 | dma_unmap_addr(&tnapi->tx_buffers[entry], |
f4188d8a AD |
5989 | mapping), |
5990 | frag->size, PCI_DMA_TODEVICE); | |
5991 | } | |
5992 | ||
5993 | dev_kfree_skb(skb); | |
5994 | return NETDEV_TX_OK; | |
1da177e4 LT |
5995 | } |
5996 | ||
5997 | static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp, | |
5998 | int new_mtu) | |
5999 | { | |
6000 | dev->mtu = new_mtu; | |
6001 | ||
ef7f5ec0 | 6002 | if (new_mtu > ETH_DATA_LEN) { |
a4e2b347 | 6003 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) { |
ef7f5ec0 MC |
6004 | tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE; |
6005 | ethtool_op_set_tso(dev, 0); | |
859a5887 | 6006 | } else { |
ef7f5ec0 | 6007 | tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE; |
859a5887 | 6008 | } |
ef7f5ec0 | 6009 | } else { |
a4e2b347 | 6010 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) |
ef7f5ec0 | 6011 | tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE; |
0f893dc6 | 6012 | tp->tg3_flags &= ~TG3_FLAG_JUMBO_RING_ENABLE; |
ef7f5ec0 | 6013 | } |
1da177e4 LT |
6014 | } |
6015 | ||
6016 | static int tg3_change_mtu(struct net_device *dev, int new_mtu) | |
6017 | { | |
6018 | struct tg3 *tp = netdev_priv(dev); | |
b9ec6c1b | 6019 | int err; |
1da177e4 LT |
6020 | |
6021 | if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp)) | |
6022 | return -EINVAL; | |
6023 | ||
6024 | if (!netif_running(dev)) { | |
6025 | /* We'll just catch it later when the | |
6026 | * device is up'd. | |
6027 | */ | |
6028 | tg3_set_mtu(dev, tp, new_mtu); | |
6029 | return 0; | |
6030 | } | |
6031 | ||
b02fd9e3 MC |
6032 | tg3_phy_stop(tp); |
6033 | ||
1da177e4 | 6034 | tg3_netif_stop(tp); |
f47c11ee DM |
6035 | |
6036 | tg3_full_lock(tp, 1); | |
1da177e4 | 6037 | |
944d980e | 6038 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
1da177e4 LT |
6039 | |
6040 | tg3_set_mtu(dev, tp, new_mtu); | |
6041 | ||
b9ec6c1b | 6042 | err = tg3_restart_hw(tp, 0); |
1da177e4 | 6043 | |
b9ec6c1b MC |
6044 | if (!err) |
6045 | tg3_netif_start(tp); | |
1da177e4 | 6046 | |
f47c11ee | 6047 | tg3_full_unlock(tp); |
1da177e4 | 6048 | |
b02fd9e3 MC |
6049 | if (!err) |
6050 | tg3_phy_start(tp); | |
6051 | ||
b9ec6c1b | 6052 | return err; |
1da177e4 LT |
6053 | } |
6054 | ||
21f581a5 MC |
6055 | static void tg3_rx_prodring_free(struct tg3 *tp, |
6056 | struct tg3_rx_prodring_set *tpr) | |
1da177e4 | 6057 | { |
1da177e4 LT |
6058 | int i; |
6059 | ||
b196c7e4 MC |
6060 | if (tpr != &tp->prodring[0]) { |
6061 | for (i = tpr->rx_std_cons_idx; i != tpr->rx_std_prod_idx; | |
6062 | i = (i + 1) % TG3_RX_RING_SIZE) | |
6063 | tg3_rx_skb_free(tp, &tpr->rx_std_buffers[i], | |
6064 | tp->rx_pkt_map_sz); | |
6065 | ||
6066 | if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) { | |
6067 | for (i = tpr->rx_jmb_cons_idx; | |
6068 | i != tpr->rx_jmb_prod_idx; | |
6069 | i = (i + 1) % TG3_RX_JUMBO_RING_SIZE) { | |
6070 | tg3_rx_skb_free(tp, &tpr->rx_jmb_buffers[i], | |
6071 | TG3_RX_JMB_MAP_SZ); | |
6072 | } | |
6073 | } | |
6074 | ||
2b2cdb65 | 6075 | return; |
b196c7e4 | 6076 | } |
1da177e4 | 6077 | |
2b2cdb65 MC |
6078 | for (i = 0; i < TG3_RX_RING_SIZE; i++) |
6079 | tg3_rx_skb_free(tp, &tpr->rx_std_buffers[i], | |
6080 | tp->rx_pkt_map_sz); | |
1da177e4 | 6081 | |
cf7a7298 | 6082 | if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) { |
2b2cdb65 MC |
6083 | for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) |
6084 | tg3_rx_skb_free(tp, &tpr->rx_jmb_buffers[i], | |
6085 | TG3_RX_JMB_MAP_SZ); | |
1da177e4 LT |
6086 | } |
6087 | } | |
6088 | ||
c6cdf436 | 6089 | /* Initialize rx rings for packet processing. |
1da177e4 LT |
6090 | * |
6091 | * The chip has been shut down and the driver detached from | |
6092 | * the networking, so no interrupts or new tx packets will | |
6093 | * end up in the driver. tp->{tx,}lock are held and thus | |
6094 | * we may not sleep. | |
6095 | */ | |
21f581a5 MC |
6096 | static int tg3_rx_prodring_alloc(struct tg3 *tp, |
6097 | struct tg3_rx_prodring_set *tpr) | |
1da177e4 | 6098 | { |
287be12e | 6099 | u32 i, rx_pkt_dma_sz; |
1da177e4 | 6100 | |
b196c7e4 MC |
6101 | tpr->rx_std_cons_idx = 0; |
6102 | tpr->rx_std_prod_idx = 0; | |
6103 | tpr->rx_jmb_cons_idx = 0; | |
6104 | tpr->rx_jmb_prod_idx = 0; | |
6105 | ||
2b2cdb65 MC |
6106 | if (tpr != &tp->prodring[0]) { |
6107 | memset(&tpr->rx_std_buffers[0], 0, TG3_RX_STD_BUFF_RING_SIZE); | |
6108 | if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) | |
6109 | memset(&tpr->rx_jmb_buffers[0], 0, | |
6110 | TG3_RX_JMB_BUFF_RING_SIZE); | |
6111 | goto done; | |
6112 | } | |
6113 | ||
1da177e4 | 6114 | /* Zero out all descriptors. */ |
21f581a5 | 6115 | memset(tpr->rx_std, 0, TG3_RX_RING_BYTES); |
1da177e4 | 6116 | |
287be12e | 6117 | rx_pkt_dma_sz = TG3_RX_STD_DMA_SZ; |
a4e2b347 | 6118 | if ((tp->tg3_flags2 & TG3_FLG2_5780_CLASS) && |
287be12e MC |
6119 | tp->dev->mtu > ETH_DATA_LEN) |
6120 | rx_pkt_dma_sz = TG3_RX_JMB_DMA_SZ; | |
6121 | tp->rx_pkt_map_sz = TG3_RX_DMA_TO_MAP_SZ(rx_pkt_dma_sz); | |
7e72aad4 | 6122 | |
1da177e4 LT |
6123 | /* Initialize invariants of the rings, we only set this |
6124 | * stuff once. This works because the card does not | |
6125 | * write into the rx buffer posting rings. | |
6126 | */ | |
6127 | for (i = 0; i < TG3_RX_RING_SIZE; i++) { | |
6128 | struct tg3_rx_buffer_desc *rxd; | |
6129 | ||
21f581a5 | 6130 | rxd = &tpr->rx_std[i]; |
287be12e | 6131 | rxd->idx_len = rx_pkt_dma_sz << RXD_LEN_SHIFT; |
1da177e4 LT |
6132 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT); |
6133 | rxd->opaque = (RXD_OPAQUE_RING_STD | | |
6134 | (i << RXD_OPAQUE_INDEX_SHIFT)); | |
6135 | } | |
6136 | ||
1da177e4 LT |
6137 | /* Now allocate fresh SKBs for each rx ring. */ |
6138 | for (i = 0; i < tp->rx_pending; i++) { | |
86b21e59 | 6139 | if (tg3_alloc_rx_skb(tp, tpr, RXD_OPAQUE_RING_STD, i) < 0) { |
5129c3a3 MC |
6140 | netdev_warn(tp->dev, |
6141 | "Using a smaller RX standard ring. Only " | |
6142 | "%d out of %d buffers were allocated " | |
6143 | "successfully\n", i, tp->rx_pending); | |
32d8c572 | 6144 | if (i == 0) |
cf7a7298 | 6145 | goto initfail; |
32d8c572 | 6146 | tp->rx_pending = i; |
1da177e4 | 6147 | break; |
32d8c572 | 6148 | } |
1da177e4 LT |
6149 | } |
6150 | ||
cf7a7298 MC |
6151 | if (!(tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE)) |
6152 | goto done; | |
6153 | ||
21f581a5 | 6154 | memset(tpr->rx_jmb, 0, TG3_RX_JUMBO_RING_BYTES); |
cf7a7298 | 6155 | |
0d86df80 MC |
6156 | if (!(tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE)) |
6157 | goto done; | |
cf7a7298 | 6158 | |
0d86df80 MC |
6159 | for (i = 0; i < TG3_RX_JUMBO_RING_SIZE; i++) { |
6160 | struct tg3_rx_buffer_desc *rxd; | |
6161 | ||
6162 | rxd = &tpr->rx_jmb[i].std; | |
6163 | rxd->idx_len = TG3_RX_JMB_DMA_SZ << RXD_LEN_SHIFT; | |
6164 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) | | |
6165 | RXD_FLAG_JUMBO; | |
6166 | rxd->opaque = (RXD_OPAQUE_RING_JUMBO | | |
6167 | (i << RXD_OPAQUE_INDEX_SHIFT)); | |
6168 | } | |
6169 | ||
6170 | for (i = 0; i < tp->rx_jumbo_pending; i++) { | |
6171 | if (tg3_alloc_rx_skb(tp, tpr, RXD_OPAQUE_RING_JUMBO, i) < 0) { | |
5129c3a3 MC |
6172 | netdev_warn(tp->dev, |
6173 | "Using a smaller RX jumbo ring. Only %d " | |
6174 | "out of %d buffers were allocated " | |
6175 | "successfully\n", i, tp->rx_jumbo_pending); | |
0d86df80 MC |
6176 | if (i == 0) |
6177 | goto initfail; | |
6178 | tp->rx_jumbo_pending = i; | |
6179 | break; | |
1da177e4 LT |
6180 | } |
6181 | } | |
cf7a7298 MC |
6182 | |
6183 | done: | |
32d8c572 | 6184 | return 0; |
cf7a7298 MC |
6185 | |
6186 | initfail: | |
21f581a5 | 6187 | tg3_rx_prodring_free(tp, tpr); |
cf7a7298 | 6188 | return -ENOMEM; |
1da177e4 LT |
6189 | } |
6190 | ||
21f581a5 MC |
6191 | static void tg3_rx_prodring_fini(struct tg3 *tp, |
6192 | struct tg3_rx_prodring_set *tpr) | |
1da177e4 | 6193 | { |
21f581a5 MC |
6194 | kfree(tpr->rx_std_buffers); |
6195 | tpr->rx_std_buffers = NULL; | |
6196 | kfree(tpr->rx_jmb_buffers); | |
6197 | tpr->rx_jmb_buffers = NULL; | |
6198 | if (tpr->rx_std) { | |
1da177e4 | 6199 | pci_free_consistent(tp->pdev, TG3_RX_RING_BYTES, |
21f581a5 MC |
6200 | tpr->rx_std, tpr->rx_std_mapping); |
6201 | tpr->rx_std = NULL; | |
1da177e4 | 6202 | } |
21f581a5 | 6203 | if (tpr->rx_jmb) { |
1da177e4 | 6204 | pci_free_consistent(tp->pdev, TG3_RX_JUMBO_RING_BYTES, |
21f581a5 MC |
6205 | tpr->rx_jmb, tpr->rx_jmb_mapping); |
6206 | tpr->rx_jmb = NULL; | |
1da177e4 | 6207 | } |
cf7a7298 MC |
6208 | } |
6209 | ||
21f581a5 MC |
6210 | static int tg3_rx_prodring_init(struct tg3 *tp, |
6211 | struct tg3_rx_prodring_set *tpr) | |
cf7a7298 | 6212 | { |
2b2cdb65 | 6213 | tpr->rx_std_buffers = kzalloc(TG3_RX_STD_BUFF_RING_SIZE, GFP_KERNEL); |
21f581a5 | 6214 | if (!tpr->rx_std_buffers) |
cf7a7298 MC |
6215 | return -ENOMEM; |
6216 | ||
21f581a5 MC |
6217 | tpr->rx_std = pci_alloc_consistent(tp->pdev, TG3_RX_RING_BYTES, |
6218 | &tpr->rx_std_mapping); | |
6219 | if (!tpr->rx_std) | |
cf7a7298 MC |
6220 | goto err_out; |
6221 | ||
6222 | if (tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) { | |
2b2cdb65 | 6223 | tpr->rx_jmb_buffers = kzalloc(TG3_RX_JMB_BUFF_RING_SIZE, |
21f581a5 MC |
6224 | GFP_KERNEL); |
6225 | if (!tpr->rx_jmb_buffers) | |
cf7a7298 MC |
6226 | goto err_out; |
6227 | ||
21f581a5 MC |
6228 | tpr->rx_jmb = pci_alloc_consistent(tp->pdev, |
6229 | TG3_RX_JUMBO_RING_BYTES, | |
6230 | &tpr->rx_jmb_mapping); | |
6231 | if (!tpr->rx_jmb) | |
cf7a7298 MC |
6232 | goto err_out; |
6233 | } | |
6234 | ||
6235 | return 0; | |
6236 | ||
6237 | err_out: | |
21f581a5 | 6238 | tg3_rx_prodring_fini(tp, tpr); |
cf7a7298 MC |
6239 | return -ENOMEM; |
6240 | } | |
6241 | ||
6242 | /* Free up pending packets in all rx/tx rings. | |
6243 | * | |
6244 | * The chip has been shut down and the driver detached from | |
6245 | * the networking, so no interrupts or new tx packets will | |
6246 | * end up in the driver. tp->{tx,}lock is not held and we are not | |
6247 | * in an interrupt context and thus may sleep. | |
6248 | */ | |
6249 | static void tg3_free_rings(struct tg3 *tp) | |
6250 | { | |
f77a6a8e | 6251 | int i, j; |
cf7a7298 | 6252 | |
f77a6a8e MC |
6253 | for (j = 0; j < tp->irq_cnt; j++) { |
6254 | struct tg3_napi *tnapi = &tp->napi[j]; | |
cf7a7298 | 6255 | |
b28f6428 MC |
6256 | tg3_rx_prodring_free(tp, &tp->prodring[j]); |
6257 | ||
0c1d0e2b MC |
6258 | if (!tnapi->tx_buffers) |
6259 | continue; | |
6260 | ||
f77a6a8e | 6261 | for (i = 0; i < TG3_TX_RING_SIZE; ) { |
f4188d8a | 6262 | struct ring_info *txp; |
f77a6a8e | 6263 | struct sk_buff *skb; |
f4188d8a | 6264 | unsigned int k; |
cf7a7298 | 6265 | |
f77a6a8e MC |
6266 | txp = &tnapi->tx_buffers[i]; |
6267 | skb = txp->skb; | |
cf7a7298 | 6268 | |
f77a6a8e MC |
6269 | if (skb == NULL) { |
6270 | i++; | |
6271 | continue; | |
6272 | } | |
cf7a7298 | 6273 | |
f4188d8a | 6274 | pci_unmap_single(tp->pdev, |
4e5e4f0d | 6275 | dma_unmap_addr(txp, mapping), |
f4188d8a AD |
6276 | skb_headlen(skb), |
6277 | PCI_DMA_TODEVICE); | |
f77a6a8e | 6278 | txp->skb = NULL; |
cf7a7298 | 6279 | |
f4188d8a AD |
6280 | i++; |
6281 | ||
6282 | for (k = 0; k < skb_shinfo(skb)->nr_frags; k++) { | |
6283 | txp = &tnapi->tx_buffers[i & (TG3_TX_RING_SIZE - 1)]; | |
6284 | pci_unmap_page(tp->pdev, | |
4e5e4f0d | 6285 | dma_unmap_addr(txp, mapping), |
f4188d8a AD |
6286 | skb_shinfo(skb)->frags[k].size, |
6287 | PCI_DMA_TODEVICE); | |
6288 | i++; | |
6289 | } | |
f77a6a8e MC |
6290 | |
6291 | dev_kfree_skb_any(skb); | |
6292 | } | |
2b2cdb65 | 6293 | } |
cf7a7298 MC |
6294 | } |
6295 | ||
6296 | /* Initialize tx/rx rings for packet processing. | |
6297 | * | |
6298 | * The chip has been shut down and the driver detached from | |
6299 | * the networking, so no interrupts or new tx packets will | |
6300 | * end up in the driver. tp->{tx,}lock are held and thus | |
6301 | * we may not sleep. | |
6302 | */ | |
6303 | static int tg3_init_rings(struct tg3 *tp) | |
6304 | { | |
f77a6a8e | 6305 | int i; |
72334482 | 6306 | |
cf7a7298 MC |
6307 | /* Free up all the SKBs. */ |
6308 | tg3_free_rings(tp); | |
6309 | ||
f77a6a8e MC |
6310 | for (i = 0; i < tp->irq_cnt; i++) { |
6311 | struct tg3_napi *tnapi = &tp->napi[i]; | |
6312 | ||
6313 | tnapi->last_tag = 0; | |
6314 | tnapi->last_irq_tag = 0; | |
6315 | tnapi->hw_status->status = 0; | |
6316 | tnapi->hw_status->status_tag = 0; | |
6317 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); | |
cf7a7298 | 6318 | |
f77a6a8e MC |
6319 | tnapi->tx_prod = 0; |
6320 | tnapi->tx_cons = 0; | |
0c1d0e2b MC |
6321 | if (tnapi->tx_ring) |
6322 | memset(tnapi->tx_ring, 0, TG3_TX_RING_BYTES); | |
f77a6a8e MC |
6323 | |
6324 | tnapi->rx_rcb_ptr = 0; | |
0c1d0e2b MC |
6325 | if (tnapi->rx_rcb) |
6326 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); | |
2b2cdb65 | 6327 | |
e4af1af9 MC |
6328 | if (tg3_rx_prodring_alloc(tp, &tp->prodring[i])) { |
6329 | tg3_free_rings(tp); | |
2b2cdb65 | 6330 | return -ENOMEM; |
e4af1af9 | 6331 | } |
f77a6a8e | 6332 | } |
72334482 | 6333 | |
2b2cdb65 | 6334 | return 0; |
cf7a7298 MC |
6335 | } |
6336 | ||
6337 | /* | |
6338 | * Must not be invoked with interrupt sources disabled and | |
6339 | * the hardware shutdown down. | |
6340 | */ | |
6341 | static void tg3_free_consistent(struct tg3 *tp) | |
6342 | { | |
f77a6a8e | 6343 | int i; |
898a56f8 | 6344 | |
f77a6a8e MC |
6345 | for (i = 0; i < tp->irq_cnt; i++) { |
6346 | struct tg3_napi *tnapi = &tp->napi[i]; | |
6347 | ||
6348 | if (tnapi->tx_ring) { | |
6349 | pci_free_consistent(tp->pdev, TG3_TX_RING_BYTES, | |
6350 | tnapi->tx_ring, tnapi->tx_desc_mapping); | |
6351 | tnapi->tx_ring = NULL; | |
6352 | } | |
6353 | ||
6354 | kfree(tnapi->tx_buffers); | |
6355 | tnapi->tx_buffers = NULL; | |
6356 | ||
6357 | if (tnapi->rx_rcb) { | |
6358 | pci_free_consistent(tp->pdev, TG3_RX_RCB_RING_BYTES(tp), | |
6359 | tnapi->rx_rcb, | |
6360 | tnapi->rx_rcb_mapping); | |
6361 | tnapi->rx_rcb = NULL; | |
6362 | } | |
6363 | ||
6364 | if (tnapi->hw_status) { | |
6365 | pci_free_consistent(tp->pdev, TG3_HW_STATUS_SIZE, | |
6366 | tnapi->hw_status, | |
6367 | tnapi->status_mapping); | |
6368 | tnapi->hw_status = NULL; | |
6369 | } | |
1da177e4 | 6370 | } |
f77a6a8e | 6371 | |
1da177e4 LT |
6372 | if (tp->hw_stats) { |
6373 | pci_free_consistent(tp->pdev, sizeof(struct tg3_hw_stats), | |
6374 | tp->hw_stats, tp->stats_mapping); | |
6375 | tp->hw_stats = NULL; | |
6376 | } | |
f77a6a8e | 6377 | |
e4af1af9 | 6378 | for (i = 0; i < tp->irq_cnt; i++) |
2b2cdb65 | 6379 | tg3_rx_prodring_fini(tp, &tp->prodring[i]); |
1da177e4 LT |
6380 | } |
6381 | ||
6382 | /* | |
6383 | * Must not be invoked with interrupt sources disabled and | |
6384 | * the hardware shutdown down. Can sleep. | |
6385 | */ | |
6386 | static int tg3_alloc_consistent(struct tg3 *tp) | |
6387 | { | |
f77a6a8e | 6388 | int i; |
898a56f8 | 6389 | |
e4af1af9 | 6390 | for (i = 0; i < tp->irq_cnt; i++) { |
2b2cdb65 MC |
6391 | if (tg3_rx_prodring_init(tp, &tp->prodring[i])) |
6392 | goto err_out; | |
6393 | } | |
1da177e4 | 6394 | |
f77a6a8e MC |
6395 | tp->hw_stats = pci_alloc_consistent(tp->pdev, |
6396 | sizeof(struct tg3_hw_stats), | |
6397 | &tp->stats_mapping); | |
6398 | if (!tp->hw_stats) | |
1da177e4 LT |
6399 | goto err_out; |
6400 | ||
f77a6a8e | 6401 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); |
1da177e4 | 6402 | |
f77a6a8e MC |
6403 | for (i = 0; i < tp->irq_cnt; i++) { |
6404 | struct tg3_napi *tnapi = &tp->napi[i]; | |
8d9d7cfc | 6405 | struct tg3_hw_status *sblk; |
1da177e4 | 6406 | |
f77a6a8e MC |
6407 | tnapi->hw_status = pci_alloc_consistent(tp->pdev, |
6408 | TG3_HW_STATUS_SIZE, | |
6409 | &tnapi->status_mapping); | |
6410 | if (!tnapi->hw_status) | |
6411 | goto err_out; | |
898a56f8 | 6412 | |
f77a6a8e | 6413 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); |
8d9d7cfc MC |
6414 | sblk = tnapi->hw_status; |
6415 | ||
19cfaecc MC |
6416 | /* If multivector TSS is enabled, vector 0 does not handle |
6417 | * tx interrupts. Don't allocate any resources for it. | |
6418 | */ | |
6419 | if ((!i && !(tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)) || | |
6420 | (i && (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS))) { | |
6421 | tnapi->tx_buffers = kzalloc(sizeof(struct ring_info) * | |
6422 | TG3_TX_RING_SIZE, | |
6423 | GFP_KERNEL); | |
6424 | if (!tnapi->tx_buffers) | |
6425 | goto err_out; | |
6426 | ||
6427 | tnapi->tx_ring = pci_alloc_consistent(tp->pdev, | |
6428 | TG3_TX_RING_BYTES, | |
6429 | &tnapi->tx_desc_mapping); | |
6430 | if (!tnapi->tx_ring) | |
6431 | goto err_out; | |
6432 | } | |
6433 | ||
8d9d7cfc MC |
6434 | /* |
6435 | * When RSS is enabled, the status block format changes | |
6436 | * slightly. The "rx_jumbo_consumer", "reserved", | |
6437 | * and "rx_mini_consumer" members get mapped to the | |
6438 | * other three rx return ring producer indexes. | |
6439 | */ | |
6440 | switch (i) { | |
6441 | default: | |
6442 | tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer; | |
6443 | break; | |
6444 | case 2: | |
6445 | tnapi->rx_rcb_prod_idx = &sblk->rx_jumbo_consumer; | |
6446 | break; | |
6447 | case 3: | |
6448 | tnapi->rx_rcb_prod_idx = &sblk->reserved; | |
6449 | break; | |
6450 | case 4: | |
6451 | tnapi->rx_rcb_prod_idx = &sblk->rx_mini_consumer; | |
6452 | break; | |
6453 | } | |
72334482 | 6454 | |
e4af1af9 | 6455 | tnapi->prodring = &tp->prodring[i]; |
b196c7e4 | 6456 | |
0c1d0e2b MC |
6457 | /* |
6458 | * If multivector RSS is enabled, vector 0 does not handle | |
6459 | * rx or tx interrupts. Don't allocate any resources for it. | |
6460 | */ | |
6461 | if (!i && (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS)) | |
6462 | continue; | |
6463 | ||
f77a6a8e MC |
6464 | tnapi->rx_rcb = pci_alloc_consistent(tp->pdev, |
6465 | TG3_RX_RCB_RING_BYTES(tp), | |
6466 | &tnapi->rx_rcb_mapping); | |
6467 | if (!tnapi->rx_rcb) | |
6468 | goto err_out; | |
72334482 | 6469 | |
f77a6a8e | 6470 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); |
f77a6a8e | 6471 | } |
1da177e4 LT |
6472 | |
6473 | return 0; | |
6474 | ||
6475 | err_out: | |
6476 | tg3_free_consistent(tp); | |
6477 | return -ENOMEM; | |
6478 | } | |
6479 | ||
6480 | #define MAX_WAIT_CNT 1000 | |
6481 | ||
6482 | /* To stop a block, clear the enable bit and poll till it | |
6483 | * clears. tp->lock is held. | |
6484 | */ | |
b3b7d6be | 6485 | static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, int silent) |
1da177e4 LT |
6486 | { |
6487 | unsigned int i; | |
6488 | u32 val; | |
6489 | ||
6490 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { | |
6491 | switch (ofs) { | |
6492 | case RCVLSC_MODE: | |
6493 | case DMAC_MODE: | |
6494 | case MBFREE_MODE: | |
6495 | case BUFMGR_MODE: | |
6496 | case MEMARB_MODE: | |
6497 | /* We can't enable/disable these bits of the | |
6498 | * 5705/5750, just say success. | |
6499 | */ | |
6500 | return 0; | |
6501 | ||
6502 | default: | |
6503 | break; | |
855e1111 | 6504 | } |
1da177e4 LT |
6505 | } |
6506 | ||
6507 | val = tr32(ofs); | |
6508 | val &= ~enable_bit; | |
6509 | tw32_f(ofs, val); | |
6510 | ||
6511 | for (i = 0; i < MAX_WAIT_CNT; i++) { | |
6512 | udelay(100); | |
6513 | val = tr32(ofs); | |
6514 | if ((val & enable_bit) == 0) | |
6515 | break; | |
6516 | } | |
6517 | ||
b3b7d6be | 6518 | if (i == MAX_WAIT_CNT && !silent) { |
2445e461 MC |
6519 | dev_err(&tp->pdev->dev, |
6520 | "tg3_stop_block timed out, ofs=%lx enable_bit=%x\n", | |
6521 | ofs, enable_bit); | |
1da177e4 LT |
6522 | return -ENODEV; |
6523 | } | |
6524 | ||
6525 | return 0; | |
6526 | } | |
6527 | ||
6528 | /* tp->lock is held. */ | |
b3b7d6be | 6529 | static int tg3_abort_hw(struct tg3 *tp, int silent) |
1da177e4 LT |
6530 | { |
6531 | int i, err; | |
6532 | ||
6533 | tg3_disable_ints(tp); | |
6534 | ||
6535 | tp->rx_mode &= ~RX_MODE_ENABLE; | |
6536 | tw32_f(MAC_RX_MODE, tp->rx_mode); | |
6537 | udelay(10); | |
6538 | ||
b3b7d6be DM |
6539 | err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent); |
6540 | err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent); | |
6541 | err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent); | |
6542 | err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent); | |
6543 | err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent); | |
6544 | err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent); | |
6545 | ||
6546 | err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent); | |
6547 | err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent); | |
6548 | err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent); | |
6549 | err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent); | |
6550 | err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent); | |
6551 | err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent); | |
6552 | err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent); | |
1da177e4 LT |
6553 | |
6554 | tp->mac_mode &= ~MAC_MODE_TDE_ENABLE; | |
6555 | tw32_f(MAC_MODE, tp->mac_mode); | |
6556 | udelay(40); | |
6557 | ||
6558 | tp->tx_mode &= ~TX_MODE_ENABLE; | |
6559 | tw32_f(MAC_TX_MODE, tp->tx_mode); | |
6560 | ||
6561 | for (i = 0; i < MAX_WAIT_CNT; i++) { | |
6562 | udelay(100); | |
6563 | if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE)) | |
6564 | break; | |
6565 | } | |
6566 | if (i >= MAX_WAIT_CNT) { | |
ab96b241 MC |
6567 | dev_err(&tp->pdev->dev, |
6568 | "%s timed out, TX_MODE_ENABLE will not clear " | |
6569 | "MAC_TX_MODE=%08x\n", __func__, tr32(MAC_TX_MODE)); | |
e6de8ad1 | 6570 | err |= -ENODEV; |
1da177e4 LT |
6571 | } |
6572 | ||
e6de8ad1 | 6573 | err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent); |
b3b7d6be DM |
6574 | err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent); |
6575 | err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent); | |
1da177e4 LT |
6576 | |
6577 | tw32(FTQ_RESET, 0xffffffff); | |
6578 | tw32(FTQ_RESET, 0x00000000); | |
6579 | ||
b3b7d6be DM |
6580 | err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent); |
6581 | err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent); | |
1da177e4 | 6582 | |
f77a6a8e MC |
6583 | for (i = 0; i < tp->irq_cnt; i++) { |
6584 | struct tg3_napi *tnapi = &tp->napi[i]; | |
6585 | if (tnapi->hw_status) | |
6586 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); | |
6587 | } | |
1da177e4 LT |
6588 | if (tp->hw_stats) |
6589 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); | |
6590 | ||
1da177e4 LT |
6591 | return err; |
6592 | } | |
6593 | ||
0d3031d9 MC |
6594 | static void tg3_ape_send_event(struct tg3 *tp, u32 event) |
6595 | { | |
6596 | int i; | |
6597 | u32 apedata; | |
6598 | ||
6599 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); | |
6600 | if (apedata != APE_SEG_SIG_MAGIC) | |
6601 | return; | |
6602 | ||
6603 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); | |
731fd79c | 6604 | if (!(apedata & APE_FW_STATUS_READY)) |
0d3031d9 MC |
6605 | return; |
6606 | ||
6607 | /* Wait for up to 1 millisecond for APE to service previous event. */ | |
6608 | for (i = 0; i < 10; i++) { | |
6609 | if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM)) | |
6610 | return; | |
6611 | ||
6612 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); | |
6613 | ||
6614 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) | |
6615 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, | |
6616 | event | APE_EVENT_STATUS_EVENT_PENDING); | |
6617 | ||
6618 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); | |
6619 | ||
6620 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) | |
6621 | break; | |
6622 | ||
6623 | udelay(100); | |
6624 | } | |
6625 | ||
6626 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) | |
6627 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); | |
6628 | } | |
6629 | ||
6630 | static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) | |
6631 | { | |
6632 | u32 event; | |
6633 | u32 apedata; | |
6634 | ||
6635 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) | |
6636 | return; | |
6637 | ||
6638 | switch (kind) { | |
33f401ae MC |
6639 | case RESET_KIND_INIT: |
6640 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, | |
6641 | APE_HOST_SEG_SIG_MAGIC); | |
6642 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN, | |
6643 | APE_HOST_SEG_LEN_MAGIC); | |
6644 | apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT); | |
6645 | tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata); | |
6646 | tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID, | |
6867c843 | 6647 | APE_HOST_DRIVER_ID_MAGIC(TG3_MAJ_NUM, TG3_MIN_NUM)); |
33f401ae MC |
6648 | tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR, |
6649 | APE_HOST_BEHAV_NO_PHYLOCK); | |
6650 | ||
6651 | event = APE_EVENT_STATUS_STATE_START; | |
6652 | break; | |
6653 | case RESET_KIND_SHUTDOWN: | |
6654 | /* With the interface we are currently using, | |
6655 | * APE does not track driver state. Wiping | |
6656 | * out the HOST SEGMENT SIGNATURE forces | |
6657 | * the APE to assume OS absent status. | |
6658 | */ | |
6659 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 0x0); | |
b2aee154 | 6660 | |
33f401ae MC |
6661 | event = APE_EVENT_STATUS_STATE_UNLOAD; |
6662 | break; | |
6663 | case RESET_KIND_SUSPEND: | |
6664 | event = APE_EVENT_STATUS_STATE_SUSPEND; | |
6665 | break; | |
6666 | default: | |
6667 | return; | |
0d3031d9 MC |
6668 | } |
6669 | ||
6670 | event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE; | |
6671 | ||
6672 | tg3_ape_send_event(tp, event); | |
6673 | } | |
6674 | ||
1da177e4 LT |
6675 | /* tp->lock is held. */ |
6676 | static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind) | |
6677 | { | |
f49639e6 DM |
6678 | tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX, |
6679 | NIC_SRAM_FIRMWARE_MBOX_MAGIC1); | |
1da177e4 LT |
6680 | |
6681 | if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) { | |
6682 | switch (kind) { | |
6683 | case RESET_KIND_INIT: | |
6684 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
6685 | DRV_STATE_START); | |
6686 | break; | |
6687 | ||
6688 | case RESET_KIND_SHUTDOWN: | |
6689 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
6690 | DRV_STATE_UNLOAD); | |
6691 | break; | |
6692 | ||
6693 | case RESET_KIND_SUSPEND: | |
6694 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
6695 | DRV_STATE_SUSPEND); | |
6696 | break; | |
6697 | ||
6698 | default: | |
6699 | break; | |
855e1111 | 6700 | } |
1da177e4 | 6701 | } |
0d3031d9 MC |
6702 | |
6703 | if (kind == RESET_KIND_INIT || | |
6704 | kind == RESET_KIND_SUSPEND) | |
6705 | tg3_ape_driver_state_change(tp, kind); | |
1da177e4 LT |
6706 | } |
6707 | ||
6708 | /* tp->lock is held. */ | |
6709 | static void tg3_write_sig_post_reset(struct tg3 *tp, int kind) | |
6710 | { | |
6711 | if (tp->tg3_flags2 & TG3_FLG2_ASF_NEW_HANDSHAKE) { | |
6712 | switch (kind) { | |
6713 | case RESET_KIND_INIT: | |
6714 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
6715 | DRV_STATE_START_DONE); | |
6716 | break; | |
6717 | ||
6718 | case RESET_KIND_SHUTDOWN: | |
6719 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
6720 | DRV_STATE_UNLOAD_DONE); | |
6721 | break; | |
6722 | ||
6723 | default: | |
6724 | break; | |
855e1111 | 6725 | } |
1da177e4 | 6726 | } |
0d3031d9 MC |
6727 | |
6728 | if (kind == RESET_KIND_SHUTDOWN) | |
6729 | tg3_ape_driver_state_change(tp, kind); | |
1da177e4 LT |
6730 | } |
6731 | ||
6732 | /* tp->lock is held. */ | |
6733 | static void tg3_write_sig_legacy(struct tg3 *tp, int kind) | |
6734 | { | |
6735 | if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) { | |
6736 | switch (kind) { | |
6737 | case RESET_KIND_INIT: | |
6738 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
6739 | DRV_STATE_START); | |
6740 | break; | |
6741 | ||
6742 | case RESET_KIND_SHUTDOWN: | |
6743 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
6744 | DRV_STATE_UNLOAD); | |
6745 | break; | |
6746 | ||
6747 | case RESET_KIND_SUSPEND: | |
6748 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
6749 | DRV_STATE_SUSPEND); | |
6750 | break; | |
6751 | ||
6752 | default: | |
6753 | break; | |
855e1111 | 6754 | } |
1da177e4 LT |
6755 | } |
6756 | } | |
6757 | ||
7a6f4369 MC |
6758 | static int tg3_poll_fw(struct tg3 *tp) |
6759 | { | |
6760 | int i; | |
6761 | u32 val; | |
6762 | ||
b5d3772c | 6763 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
0ccead18 GZ |
6764 | /* Wait up to 20ms for init done. */ |
6765 | for (i = 0; i < 200; i++) { | |
b5d3772c MC |
6766 | if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE) |
6767 | return 0; | |
0ccead18 | 6768 | udelay(100); |
b5d3772c MC |
6769 | } |
6770 | return -ENODEV; | |
6771 | } | |
6772 | ||
7a6f4369 MC |
6773 | /* Wait for firmware initialization to complete. */ |
6774 | for (i = 0; i < 100000; i++) { | |
6775 | tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val); | |
6776 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) | |
6777 | break; | |
6778 | udelay(10); | |
6779 | } | |
6780 | ||
6781 | /* Chip might not be fitted with firmware. Some Sun onboard | |
6782 | * parts are configured like that. So don't signal the timeout | |
6783 | * of the above loop as an error, but do report the lack of | |
6784 | * running firmware once. | |
6785 | */ | |
6786 | if (i >= 100000 && | |
6787 | !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) { | |
6788 | tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED; | |
6789 | ||
05dbe005 | 6790 | netdev_info(tp->dev, "No firmware running\n"); |
7a6f4369 MC |
6791 | } |
6792 | ||
6b10c165 MC |
6793 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
6794 | /* The 57765 A0 needs a little more | |
6795 | * time to do some important work. | |
6796 | */ | |
6797 | mdelay(10); | |
6798 | } | |
6799 | ||
7a6f4369 MC |
6800 | return 0; |
6801 | } | |
6802 | ||
ee6a99b5 MC |
6803 | /* Save PCI command register before chip reset */ |
6804 | static void tg3_save_pci_state(struct tg3 *tp) | |
6805 | { | |
8a6eac90 | 6806 | pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd); |
ee6a99b5 MC |
6807 | } |
6808 | ||
6809 | /* Restore PCI state after chip reset */ | |
6810 | static void tg3_restore_pci_state(struct tg3 *tp) | |
6811 | { | |
6812 | u32 val; | |
6813 | ||
6814 | /* Re-enable indirect register accesses. */ | |
6815 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
6816 | tp->misc_host_ctrl); | |
6817 | ||
6818 | /* Set MAX PCI retry to zero. */ | |
6819 | val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE); | |
6820 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && | |
6821 | (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) | |
6822 | val |= PCISTATE_RETRY_SAME_DMA; | |
0d3031d9 MC |
6823 | /* Allow reads and writes to the APE register and memory space. */ |
6824 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) | |
6825 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | | |
f92d9dc1 MC |
6826 | PCISTATE_ALLOW_APE_SHMEM_WR | |
6827 | PCISTATE_ALLOW_APE_PSPACE_WR; | |
ee6a99b5 MC |
6828 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); |
6829 | ||
8a6eac90 | 6830 | pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd); |
ee6a99b5 | 6831 | |
fcb389df MC |
6832 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785) { |
6833 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) | |
6834 | pcie_set_readrq(tp->pdev, 4096); | |
6835 | else { | |
6836 | pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, | |
6837 | tp->pci_cacheline_sz); | |
6838 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, | |
6839 | tp->pci_lat_timer); | |
6840 | } | |
114342f2 | 6841 | } |
5f5c51e3 | 6842 | |
ee6a99b5 | 6843 | /* Make sure PCI-X relaxed ordering bit is clear. */ |
52f4490c | 6844 | if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) { |
9974a356 MC |
6845 | u16 pcix_cmd; |
6846 | ||
6847 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, | |
6848 | &pcix_cmd); | |
6849 | pcix_cmd &= ~PCI_X_CMD_ERO; | |
6850 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, | |
6851 | pcix_cmd); | |
6852 | } | |
ee6a99b5 MC |
6853 | |
6854 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) { | |
ee6a99b5 MC |
6855 | |
6856 | /* Chip reset on 5780 will reset MSI enable bit, | |
6857 | * so need to restore it. | |
6858 | */ | |
6859 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) { | |
6860 | u16 ctrl; | |
6861 | ||
6862 | pci_read_config_word(tp->pdev, | |
6863 | tp->msi_cap + PCI_MSI_FLAGS, | |
6864 | &ctrl); | |
6865 | pci_write_config_word(tp->pdev, | |
6866 | tp->msi_cap + PCI_MSI_FLAGS, | |
6867 | ctrl | PCI_MSI_FLAGS_ENABLE); | |
6868 | val = tr32(MSGINT_MODE); | |
6869 | tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE); | |
6870 | } | |
6871 | } | |
6872 | } | |
6873 | ||
1da177e4 LT |
6874 | static void tg3_stop_fw(struct tg3 *); |
6875 | ||
6876 | /* tp->lock is held. */ | |
6877 | static int tg3_chip_reset(struct tg3 *tp) | |
6878 | { | |
6879 | u32 val; | |
1ee582d8 | 6880 | void (*write_op)(struct tg3 *, u32, u32); |
4f125f42 | 6881 | int i, err; |
1da177e4 | 6882 | |
f49639e6 DM |
6883 | tg3_nvram_lock(tp); |
6884 | ||
77b483f1 MC |
6885 | tg3_ape_lock(tp, TG3_APE_LOCK_GRC); |
6886 | ||
f49639e6 DM |
6887 | /* No matching tg3_nvram_unlock() after this because |
6888 | * chip reset below will undo the nvram lock. | |
6889 | */ | |
6890 | tp->nvram_lock_cnt = 0; | |
1da177e4 | 6891 | |
ee6a99b5 MC |
6892 | /* GRC_MISC_CFG core clock reset will clear the memory |
6893 | * enable bit in PCI register 4 and the MSI enable bit | |
6894 | * on some chips, so we save relevant registers here. | |
6895 | */ | |
6896 | tg3_save_pci_state(tp); | |
6897 | ||
d9ab5ad1 | 6898 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || |
321d32a0 | 6899 | (tp->tg3_flags3 & TG3_FLG3_5755_PLUS)) |
d9ab5ad1 MC |
6900 | tw32(GRC_FASTBOOT_PC, 0); |
6901 | ||
1da177e4 LT |
6902 | /* |
6903 | * We must avoid the readl() that normally takes place. | |
6904 | * It locks machines, causes machine checks, and other | |
6905 | * fun things. So, temporarily disable the 5701 | |
6906 | * hardware workaround, while we do the reset. | |
6907 | */ | |
1ee582d8 MC |
6908 | write_op = tp->write32; |
6909 | if (write_op == tg3_write_flush_reg32) | |
6910 | tp->write32 = tg3_write32; | |
1da177e4 | 6911 | |
d18edcb2 MC |
6912 | /* Prevent the irq handler from reading or writing PCI registers |
6913 | * during chip reset when the memory enable bit in the PCI command | |
6914 | * register may be cleared. The chip does not generate interrupt | |
6915 | * at this time, but the irq handler may still be called due to irq | |
6916 | * sharing or irqpoll. | |
6917 | */ | |
6918 | tp->tg3_flags |= TG3_FLAG_CHIP_RESETTING; | |
f77a6a8e MC |
6919 | for (i = 0; i < tp->irq_cnt; i++) { |
6920 | struct tg3_napi *tnapi = &tp->napi[i]; | |
6921 | if (tnapi->hw_status) { | |
6922 | tnapi->hw_status->status = 0; | |
6923 | tnapi->hw_status->status_tag = 0; | |
6924 | } | |
6925 | tnapi->last_tag = 0; | |
6926 | tnapi->last_irq_tag = 0; | |
b8fa2f3a | 6927 | } |
d18edcb2 | 6928 | smp_mb(); |
4f125f42 MC |
6929 | |
6930 | for (i = 0; i < tp->irq_cnt; i++) | |
6931 | synchronize_irq(tp->napi[i].irq_vec); | |
d18edcb2 | 6932 | |
255ca311 MC |
6933 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
6934 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; | |
6935 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); | |
6936 | } | |
6937 | ||
1da177e4 LT |
6938 | /* do the reset */ |
6939 | val = GRC_MISC_CFG_CORECLK_RESET; | |
6940 | ||
6941 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { | |
88075d91 MC |
6942 | /* Force PCIe 1.0a mode */ |
6943 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && | |
6944 | !(tp->tg3_flags3 & TG3_FLG3_5717_PLUS) && | |
6945 | tr32(TG3_PCIE_PHY_TSTCTL) == | |
6946 | (TG3_PCIE_PHY_TSTCTL_PCIE10 | TG3_PCIE_PHY_TSTCTL_PSCRAM)) | |
6947 | tw32(TG3_PCIE_PHY_TSTCTL, TG3_PCIE_PHY_TSTCTL_PSCRAM); | |
6948 | ||
1da177e4 LT |
6949 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) { |
6950 | tw32(GRC_MISC_CFG, (1 << 29)); | |
6951 | val |= (1 << 29); | |
6952 | } | |
6953 | } | |
6954 | ||
b5d3772c MC |
6955 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
6956 | tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET); | |
6957 | tw32(GRC_VCPU_EXT_CTRL, | |
6958 | tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU); | |
6959 | } | |
6960 | ||
f37500d3 MC |
6961 | /* Manage gphy power for all CPMU absent PCIe devices. */ |
6962 | if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && | |
6963 | !(tp->tg3_flags & TG3_FLAG_CPMU_PRESENT)) | |
1da177e4 | 6964 | val |= GRC_MISC_CFG_KEEP_GPHY_POWER; |
f37500d3 | 6965 | |
1da177e4 LT |
6966 | tw32(GRC_MISC_CFG, val); |
6967 | ||
1ee582d8 MC |
6968 | /* restore 5701 hardware bug workaround write method */ |
6969 | tp->write32 = write_op; | |
1da177e4 LT |
6970 | |
6971 | /* Unfortunately, we have to delay before the PCI read back. | |
6972 | * Some 575X chips even will not respond to a PCI cfg access | |
6973 | * when the reset command is given to the chip. | |
6974 | * | |
6975 | * How do these hardware designers expect things to work | |
6976 | * properly if the PCI write is posted for a long period | |
6977 | * of time? It is always necessary to have some method by | |
6978 | * which a register read back can occur to push the write | |
6979 | * out which does the reset. | |
6980 | * | |
6981 | * For most tg3 variants the trick below was working. | |
6982 | * Ho hum... | |
6983 | */ | |
6984 | udelay(120); | |
6985 | ||
6986 | /* Flush PCI posted writes. The normal MMIO registers | |
6987 | * are inaccessible at this time so this is the only | |
6988 | * way to make this reliably (actually, this is no longer | |
6989 | * the case, see above). I tried to use indirect | |
6990 | * register read/write but this upset some 5701 variants. | |
6991 | */ | |
6992 | pci_read_config_dword(tp->pdev, PCI_COMMAND, &val); | |
6993 | ||
6994 | udelay(120); | |
6995 | ||
5e7dfd0f | 6996 | if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && tp->pcie_cap) { |
e7126997 MC |
6997 | u16 val16; |
6998 | ||
1da177e4 LT |
6999 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A0) { |
7000 | int i; | |
7001 | u32 cfg_val; | |
7002 | ||
7003 | /* Wait for link training to complete. */ | |
7004 | for (i = 0; i < 5000; i++) | |
7005 | udelay(100); | |
7006 | ||
7007 | pci_read_config_dword(tp->pdev, 0xc4, &cfg_val); | |
7008 | pci_write_config_dword(tp->pdev, 0xc4, | |
7009 | cfg_val | (1 << 15)); | |
7010 | } | |
5e7dfd0f | 7011 | |
e7126997 MC |
7012 | /* Clear the "no snoop" and "relaxed ordering" bits. */ |
7013 | pci_read_config_word(tp->pdev, | |
7014 | tp->pcie_cap + PCI_EXP_DEVCTL, | |
7015 | &val16); | |
7016 | val16 &= ~(PCI_EXP_DEVCTL_RELAX_EN | | |
7017 | PCI_EXP_DEVCTL_NOSNOOP_EN); | |
7018 | /* | |
7019 | * Older PCIe devices only support the 128 byte | |
7020 | * MPS setting. Enforce the restriction. | |
5e7dfd0f | 7021 | */ |
6de34cb9 | 7022 | if (!(tp->tg3_flags & TG3_FLAG_CPMU_PRESENT)) |
e7126997 | 7023 | val16 &= ~PCI_EXP_DEVCTL_PAYLOAD; |
5e7dfd0f MC |
7024 | pci_write_config_word(tp->pdev, |
7025 | tp->pcie_cap + PCI_EXP_DEVCTL, | |
e7126997 | 7026 | val16); |
5e7dfd0f MC |
7027 | |
7028 | pcie_set_readrq(tp->pdev, 4096); | |
7029 | ||
7030 | /* Clear error status */ | |
7031 | pci_write_config_word(tp->pdev, | |
7032 | tp->pcie_cap + PCI_EXP_DEVSTA, | |
7033 | PCI_EXP_DEVSTA_CED | | |
7034 | PCI_EXP_DEVSTA_NFED | | |
7035 | PCI_EXP_DEVSTA_FED | | |
7036 | PCI_EXP_DEVSTA_URD); | |
1da177e4 LT |
7037 | } |
7038 | ||
ee6a99b5 | 7039 | tg3_restore_pci_state(tp); |
1da177e4 | 7040 | |
d18edcb2 MC |
7041 | tp->tg3_flags &= ~TG3_FLAG_CHIP_RESETTING; |
7042 | ||
ee6a99b5 MC |
7043 | val = 0; |
7044 | if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) | |
4cf78e4f | 7045 | val = tr32(MEMARB_MODE); |
ee6a99b5 | 7046 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
1da177e4 LT |
7047 | |
7048 | if (tp->pci_chip_rev_id == CHIPREV_ID_5750_A3) { | |
7049 | tg3_stop_fw(tp); | |
7050 | tw32(0x5000, 0x400); | |
7051 | } | |
7052 | ||
7053 | tw32(GRC_MODE, tp->grc_mode); | |
7054 | ||
7055 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) { | |
ab0049b4 | 7056 | val = tr32(0xc4); |
1da177e4 LT |
7057 | |
7058 | tw32(0xc4, val | (1 << 15)); | |
7059 | } | |
7060 | ||
7061 | if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 && | |
7062 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { | |
7063 | tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE; | |
7064 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A0) | |
7065 | tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN; | |
7066 | tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); | |
7067 | } | |
7068 | ||
f07e9af3 | 7069 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
1da177e4 LT |
7070 | tp->mac_mode = MAC_MODE_PORT_MODE_TBI; |
7071 | tw32_f(MAC_MODE, tp->mac_mode); | |
f07e9af3 | 7072 | } else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
747e8f8b MC |
7073 | tp->mac_mode = MAC_MODE_PORT_MODE_GMII; |
7074 | tw32_f(MAC_MODE, tp->mac_mode); | |
3bda1258 MC |
7075 | } else if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
7076 | tp->mac_mode &= (MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN); | |
7077 | if (tp->mac_mode & MAC_MODE_APE_TX_EN) | |
7078 | tp->mac_mode |= MAC_MODE_TDE_ENABLE; | |
7079 | tw32_f(MAC_MODE, tp->mac_mode); | |
1da177e4 LT |
7080 | } else |
7081 | tw32_f(MAC_MODE, 0); | |
7082 | udelay(40); | |
7083 | ||
77b483f1 MC |
7084 | tg3_ape_unlock(tp, TG3_APE_LOCK_GRC); |
7085 | ||
7a6f4369 MC |
7086 | err = tg3_poll_fw(tp); |
7087 | if (err) | |
7088 | return err; | |
1da177e4 | 7089 | |
0a9140cf MC |
7090 | tg3_mdio_start(tp); |
7091 | ||
1da177e4 | 7092 | if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && |
f6eb9b1f MC |
7093 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && |
7094 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && | |
c885e824 | 7095 | !(tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) { |
ab0049b4 | 7096 | val = tr32(0x7c00); |
1da177e4 LT |
7097 | |
7098 | tw32(0x7c00, val | (1 << 25)); | |
7099 | } | |
7100 | ||
7101 | /* Reprobe ASF enable state. */ | |
7102 | tp->tg3_flags &= ~TG3_FLAG_ENABLE_ASF; | |
7103 | tp->tg3_flags2 &= ~TG3_FLG2_ASF_NEW_HANDSHAKE; | |
7104 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); | |
7105 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { | |
7106 | u32 nic_cfg; | |
7107 | ||
7108 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); | |
7109 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { | |
7110 | tp->tg3_flags |= TG3_FLAG_ENABLE_ASF; | |
4ba526ce | 7111 | tp->last_event_jiffies = jiffies; |
cbf46853 | 7112 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) |
1da177e4 LT |
7113 | tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE; |
7114 | } | |
7115 | } | |
7116 | ||
7117 | return 0; | |
7118 | } | |
7119 | ||
7120 | /* tp->lock is held. */ | |
7121 | static void tg3_stop_fw(struct tg3 *tp) | |
7122 | { | |
0d3031d9 MC |
7123 | if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) && |
7124 | !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) { | |
7c5026aa MC |
7125 | /* Wait for RX cpu to ACK the previous event. */ |
7126 | tg3_wait_for_event_ack(tp); | |
1da177e4 LT |
7127 | |
7128 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW); | |
4ba526ce MC |
7129 | |
7130 | tg3_generate_fw_event(tp); | |
1da177e4 | 7131 | |
7c5026aa MC |
7132 | /* Wait for RX cpu to ACK this event. */ |
7133 | tg3_wait_for_event_ack(tp); | |
1da177e4 LT |
7134 | } |
7135 | } | |
7136 | ||
7137 | /* tp->lock is held. */ | |
944d980e | 7138 | static int tg3_halt(struct tg3 *tp, int kind, int silent) |
1da177e4 LT |
7139 | { |
7140 | int err; | |
7141 | ||
7142 | tg3_stop_fw(tp); | |
7143 | ||
944d980e | 7144 | tg3_write_sig_pre_reset(tp, kind); |
1da177e4 | 7145 | |
b3b7d6be | 7146 | tg3_abort_hw(tp, silent); |
1da177e4 LT |
7147 | err = tg3_chip_reset(tp); |
7148 | ||
daba2a63 MC |
7149 | __tg3_set_mac_addr(tp, 0); |
7150 | ||
944d980e MC |
7151 | tg3_write_sig_legacy(tp, kind); |
7152 | tg3_write_sig_post_reset(tp, kind); | |
1da177e4 LT |
7153 | |
7154 | if (err) | |
7155 | return err; | |
7156 | ||
7157 | return 0; | |
7158 | } | |
7159 | ||
1da177e4 LT |
7160 | #define RX_CPU_SCRATCH_BASE 0x30000 |
7161 | #define RX_CPU_SCRATCH_SIZE 0x04000 | |
7162 | #define TX_CPU_SCRATCH_BASE 0x34000 | |
7163 | #define TX_CPU_SCRATCH_SIZE 0x04000 | |
7164 | ||
7165 | /* tp->lock is held. */ | |
7166 | static int tg3_halt_cpu(struct tg3 *tp, u32 offset) | |
7167 | { | |
7168 | int i; | |
7169 | ||
5d9428de ES |
7170 | BUG_ON(offset == TX_CPU_BASE && |
7171 | (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)); | |
1da177e4 | 7172 | |
b5d3772c MC |
7173 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
7174 | u32 val = tr32(GRC_VCPU_EXT_CTRL); | |
7175 | ||
7176 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU); | |
7177 | return 0; | |
7178 | } | |
1da177e4 LT |
7179 | if (offset == RX_CPU_BASE) { |
7180 | for (i = 0; i < 10000; i++) { | |
7181 | tw32(offset + CPU_STATE, 0xffffffff); | |
7182 | tw32(offset + CPU_MODE, CPU_MODE_HALT); | |
7183 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) | |
7184 | break; | |
7185 | } | |
7186 | ||
7187 | tw32(offset + CPU_STATE, 0xffffffff); | |
7188 | tw32_f(offset + CPU_MODE, CPU_MODE_HALT); | |
7189 | udelay(10); | |
7190 | } else { | |
7191 | for (i = 0; i < 10000; i++) { | |
7192 | tw32(offset + CPU_STATE, 0xffffffff); | |
7193 | tw32(offset + CPU_MODE, CPU_MODE_HALT); | |
7194 | if (tr32(offset + CPU_MODE) & CPU_MODE_HALT) | |
7195 | break; | |
7196 | } | |
7197 | } | |
7198 | ||
7199 | if (i >= 10000) { | |
05dbe005 JP |
7200 | netdev_err(tp->dev, "%s timed out, %s CPU\n", |
7201 | __func__, offset == RX_CPU_BASE ? "RX" : "TX"); | |
1da177e4 LT |
7202 | return -ENODEV; |
7203 | } | |
ec41c7df MC |
7204 | |
7205 | /* Clear firmware's nvram arbitration. */ | |
7206 | if (tp->tg3_flags & TG3_FLAG_NVRAM) | |
7207 | tw32(NVRAM_SWARB, SWARB_REQ_CLR0); | |
1da177e4 LT |
7208 | return 0; |
7209 | } | |
7210 | ||
7211 | struct fw_info { | |
077f849d JSR |
7212 | unsigned int fw_base; |
7213 | unsigned int fw_len; | |
7214 | const __be32 *fw_data; | |
1da177e4 LT |
7215 | }; |
7216 | ||
7217 | /* tp->lock is held. */ | |
7218 | static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, u32 cpu_scratch_base, | |
7219 | int cpu_scratch_size, struct fw_info *info) | |
7220 | { | |
ec41c7df | 7221 | int err, lock_err, i; |
1da177e4 LT |
7222 | void (*write_op)(struct tg3 *, u32, u32); |
7223 | ||
7224 | if (cpu_base == TX_CPU_BASE && | |
7225 | (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { | |
5129c3a3 MC |
7226 | netdev_err(tp->dev, |
7227 | "%s: Trying to load TX cpu firmware which is 5705\n", | |
05dbe005 | 7228 | __func__); |
1da177e4 LT |
7229 | return -EINVAL; |
7230 | } | |
7231 | ||
7232 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) | |
7233 | write_op = tg3_write_mem; | |
7234 | else | |
7235 | write_op = tg3_write_indirect_reg32; | |
7236 | ||
1b628151 MC |
7237 | /* It is possible that bootcode is still loading at this point. |
7238 | * Get the nvram lock first before halting the cpu. | |
7239 | */ | |
ec41c7df | 7240 | lock_err = tg3_nvram_lock(tp); |
1da177e4 | 7241 | err = tg3_halt_cpu(tp, cpu_base); |
ec41c7df MC |
7242 | if (!lock_err) |
7243 | tg3_nvram_unlock(tp); | |
1da177e4 LT |
7244 | if (err) |
7245 | goto out; | |
7246 | ||
7247 | for (i = 0; i < cpu_scratch_size; i += sizeof(u32)) | |
7248 | write_op(tp, cpu_scratch_base + i, 0); | |
7249 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
7250 | tw32(cpu_base + CPU_MODE, tr32(cpu_base+CPU_MODE)|CPU_MODE_HALT); | |
077f849d | 7251 | for (i = 0; i < (info->fw_len / sizeof(u32)); i++) |
1da177e4 | 7252 | write_op(tp, (cpu_scratch_base + |
077f849d | 7253 | (info->fw_base & 0xffff) + |
1da177e4 | 7254 | (i * sizeof(u32))), |
077f849d | 7255 | be32_to_cpu(info->fw_data[i])); |
1da177e4 LT |
7256 | |
7257 | err = 0; | |
7258 | ||
7259 | out: | |
1da177e4 LT |
7260 | return err; |
7261 | } | |
7262 | ||
7263 | /* tp->lock is held. */ | |
7264 | static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp) | |
7265 | { | |
7266 | struct fw_info info; | |
077f849d | 7267 | const __be32 *fw_data; |
1da177e4 LT |
7268 | int err, i; |
7269 | ||
077f849d JSR |
7270 | fw_data = (void *)tp->fw->data; |
7271 | ||
7272 | /* Firmware blob starts with version numbers, followed by | |
7273 | start address and length. We are setting complete length. | |
7274 | length = end_address_of_bss - start_address_of_text. | |
7275 | Remainder is the blob to be loaded contiguously | |
7276 | from start address. */ | |
7277 | ||
7278 | info.fw_base = be32_to_cpu(fw_data[1]); | |
7279 | info.fw_len = tp->fw->size - 12; | |
7280 | info.fw_data = &fw_data[3]; | |
1da177e4 LT |
7281 | |
7282 | err = tg3_load_firmware_cpu(tp, RX_CPU_BASE, | |
7283 | RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE, | |
7284 | &info); | |
7285 | if (err) | |
7286 | return err; | |
7287 | ||
7288 | err = tg3_load_firmware_cpu(tp, TX_CPU_BASE, | |
7289 | TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE, | |
7290 | &info); | |
7291 | if (err) | |
7292 | return err; | |
7293 | ||
7294 | /* Now startup only the RX cpu. */ | |
7295 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); | |
077f849d | 7296 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
1da177e4 LT |
7297 | |
7298 | for (i = 0; i < 5; i++) { | |
077f849d | 7299 | if (tr32(RX_CPU_BASE + CPU_PC) == info.fw_base) |
1da177e4 LT |
7300 | break; |
7301 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); | |
7302 | tw32(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT); | |
077f849d | 7303 | tw32_f(RX_CPU_BASE + CPU_PC, info.fw_base); |
1da177e4 LT |
7304 | udelay(1000); |
7305 | } | |
7306 | if (i >= 5) { | |
5129c3a3 MC |
7307 | netdev_err(tp->dev, "%s fails to set RX CPU PC, is %08x " |
7308 | "should be %08x\n", __func__, | |
05dbe005 | 7309 | tr32(RX_CPU_BASE + CPU_PC), info.fw_base); |
1da177e4 LT |
7310 | return -ENODEV; |
7311 | } | |
7312 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); | |
7313 | tw32_f(RX_CPU_BASE + CPU_MODE, 0x00000000); | |
7314 | ||
7315 | return 0; | |
7316 | } | |
7317 | ||
1da177e4 | 7318 | /* 5705 needs a special version of the TSO firmware. */ |
1da177e4 LT |
7319 | |
7320 | /* tp->lock is held. */ | |
7321 | static int tg3_load_tso_firmware(struct tg3 *tp) | |
7322 | { | |
7323 | struct fw_info info; | |
077f849d | 7324 | const __be32 *fw_data; |
1da177e4 LT |
7325 | unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size; |
7326 | int err, i; | |
7327 | ||
7328 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) | |
7329 | return 0; | |
7330 | ||
077f849d JSR |
7331 | fw_data = (void *)tp->fw->data; |
7332 | ||
7333 | /* Firmware blob starts with version numbers, followed by | |
7334 | start address and length. We are setting complete length. | |
7335 | length = end_address_of_bss - start_address_of_text. | |
7336 | Remainder is the blob to be loaded contiguously | |
7337 | from start address. */ | |
7338 | ||
7339 | info.fw_base = be32_to_cpu(fw_data[1]); | |
7340 | cpu_scratch_size = tp->fw_len; | |
7341 | info.fw_len = tp->fw->size - 12; | |
7342 | info.fw_data = &fw_data[3]; | |
7343 | ||
1da177e4 | 7344 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
1da177e4 LT |
7345 | cpu_base = RX_CPU_BASE; |
7346 | cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705; | |
1da177e4 | 7347 | } else { |
1da177e4 LT |
7348 | cpu_base = TX_CPU_BASE; |
7349 | cpu_scratch_base = TX_CPU_SCRATCH_BASE; | |
7350 | cpu_scratch_size = TX_CPU_SCRATCH_SIZE; | |
7351 | } | |
7352 | ||
7353 | err = tg3_load_firmware_cpu(tp, cpu_base, | |
7354 | cpu_scratch_base, cpu_scratch_size, | |
7355 | &info); | |
7356 | if (err) | |
7357 | return err; | |
7358 | ||
7359 | /* Now startup the cpu. */ | |
7360 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
077f849d | 7361 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
1da177e4 LT |
7362 | |
7363 | for (i = 0; i < 5; i++) { | |
077f849d | 7364 | if (tr32(cpu_base + CPU_PC) == info.fw_base) |
1da177e4 LT |
7365 | break; |
7366 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
7367 | tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); | |
077f849d | 7368 | tw32_f(cpu_base + CPU_PC, info.fw_base); |
1da177e4 LT |
7369 | udelay(1000); |
7370 | } | |
7371 | if (i >= 5) { | |
5129c3a3 MC |
7372 | netdev_err(tp->dev, |
7373 | "%s fails to set CPU PC, is %08x should be %08x\n", | |
05dbe005 | 7374 | __func__, tr32(cpu_base + CPU_PC), info.fw_base); |
1da177e4 LT |
7375 | return -ENODEV; |
7376 | } | |
7377 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
7378 | tw32_f(cpu_base + CPU_MODE, 0x00000000); | |
7379 | return 0; | |
7380 | } | |
7381 | ||
1da177e4 | 7382 | |
1da177e4 LT |
7383 | static int tg3_set_mac_addr(struct net_device *dev, void *p) |
7384 | { | |
7385 | struct tg3 *tp = netdev_priv(dev); | |
7386 | struct sockaddr *addr = p; | |
986e0aeb | 7387 | int err = 0, skip_mac_1 = 0; |
1da177e4 | 7388 | |
f9804ddb MC |
7389 | if (!is_valid_ether_addr(addr->sa_data)) |
7390 | return -EINVAL; | |
7391 | ||
1da177e4 LT |
7392 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
7393 | ||
e75f7c90 MC |
7394 | if (!netif_running(dev)) |
7395 | return 0; | |
7396 | ||
58712ef9 | 7397 | if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) { |
986e0aeb | 7398 | u32 addr0_high, addr0_low, addr1_high, addr1_low; |
58712ef9 | 7399 | |
986e0aeb MC |
7400 | addr0_high = tr32(MAC_ADDR_0_HIGH); |
7401 | addr0_low = tr32(MAC_ADDR_0_LOW); | |
7402 | addr1_high = tr32(MAC_ADDR_1_HIGH); | |
7403 | addr1_low = tr32(MAC_ADDR_1_LOW); | |
7404 | ||
7405 | /* Skip MAC addr 1 if ASF is using it. */ | |
7406 | if ((addr0_high != addr1_high || addr0_low != addr1_low) && | |
7407 | !(addr1_high == 0 && addr1_low == 0)) | |
7408 | skip_mac_1 = 1; | |
58712ef9 | 7409 | } |
986e0aeb MC |
7410 | spin_lock_bh(&tp->lock); |
7411 | __tg3_set_mac_addr(tp, skip_mac_1); | |
7412 | spin_unlock_bh(&tp->lock); | |
1da177e4 | 7413 | |
b9ec6c1b | 7414 | return err; |
1da177e4 LT |
7415 | } |
7416 | ||
7417 | /* tp->lock is held. */ | |
7418 | static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr, | |
7419 | dma_addr_t mapping, u32 maxlen_flags, | |
7420 | u32 nic_addr) | |
7421 | { | |
7422 | tg3_write_mem(tp, | |
7423 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH), | |
7424 | ((u64) mapping >> 32)); | |
7425 | tg3_write_mem(tp, | |
7426 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW), | |
7427 | ((u64) mapping & 0xffffffff)); | |
7428 | tg3_write_mem(tp, | |
7429 | (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS), | |
7430 | maxlen_flags); | |
7431 | ||
7432 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) | |
7433 | tg3_write_mem(tp, | |
7434 | (bdinfo_addr + TG3_BDINFO_NIC_ADDR), | |
7435 | nic_addr); | |
7436 | } | |
7437 | ||
7438 | static void __tg3_set_rx_mode(struct net_device *); | |
d244c892 | 7439 | static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec) |
15f9850d | 7440 | { |
b6080e12 MC |
7441 | int i; |
7442 | ||
19cfaecc | 7443 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)) { |
b6080e12 MC |
7444 | tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs); |
7445 | tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames); | |
7446 | tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq); | |
b6080e12 MC |
7447 | } else { |
7448 | tw32(HOSTCC_TXCOL_TICKS, 0); | |
7449 | tw32(HOSTCC_TXMAX_FRAMES, 0); | |
7450 | tw32(HOSTCC_TXCOAL_MAXF_INT, 0); | |
19cfaecc | 7451 | } |
b6080e12 | 7452 | |
20d7375c | 7453 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS)) { |
19cfaecc MC |
7454 | tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs); |
7455 | tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames); | |
7456 | tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq); | |
7457 | } else { | |
b6080e12 MC |
7458 | tw32(HOSTCC_RXCOL_TICKS, 0); |
7459 | tw32(HOSTCC_RXMAX_FRAMES, 0); | |
7460 | tw32(HOSTCC_RXCOAL_MAXF_INT, 0); | |
15f9850d | 7461 | } |
b6080e12 | 7462 | |
15f9850d DM |
7463 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
7464 | u32 val = ec->stats_block_coalesce_usecs; | |
7465 | ||
b6080e12 MC |
7466 | tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq); |
7467 | tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq); | |
7468 | ||
15f9850d DM |
7469 | if (!netif_carrier_ok(tp->dev)) |
7470 | val = 0; | |
7471 | ||
7472 | tw32(HOSTCC_STAT_COAL_TICKS, val); | |
7473 | } | |
b6080e12 MC |
7474 | |
7475 | for (i = 0; i < tp->irq_cnt - 1; i++) { | |
7476 | u32 reg; | |
7477 | ||
7478 | reg = HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18; | |
7479 | tw32(reg, ec->rx_coalesce_usecs); | |
b6080e12 MC |
7480 | reg = HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18; |
7481 | tw32(reg, ec->rx_max_coalesced_frames); | |
b6080e12 MC |
7482 | reg = HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18; |
7483 | tw32(reg, ec->rx_max_coalesced_frames_irq); | |
19cfaecc MC |
7484 | |
7485 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) { | |
7486 | reg = HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18; | |
7487 | tw32(reg, ec->tx_coalesce_usecs); | |
7488 | reg = HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18; | |
7489 | tw32(reg, ec->tx_max_coalesced_frames); | |
7490 | reg = HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18; | |
7491 | tw32(reg, ec->tx_max_coalesced_frames_irq); | |
7492 | } | |
b6080e12 MC |
7493 | } |
7494 | ||
7495 | for (; i < tp->irq_max - 1; i++) { | |
7496 | tw32(HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18, 0); | |
b6080e12 | 7497 | tw32(HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18, 0); |
b6080e12 | 7498 | tw32(HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
19cfaecc MC |
7499 | |
7500 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) { | |
7501 | tw32(HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18, 0); | |
7502 | tw32(HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18, 0); | |
7503 | tw32(HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); | |
7504 | } | |
b6080e12 | 7505 | } |
15f9850d | 7506 | } |
1da177e4 | 7507 | |
2d31ecaf MC |
7508 | /* tp->lock is held. */ |
7509 | static void tg3_rings_reset(struct tg3 *tp) | |
7510 | { | |
7511 | int i; | |
f77a6a8e | 7512 | u32 stblk, txrcb, rxrcb, limit; |
2d31ecaf MC |
7513 | struct tg3_napi *tnapi = &tp->napi[0]; |
7514 | ||
7515 | /* Disable all transmit rings but the first. */ | |
7516 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) | |
7517 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 16; | |
b703df6f MC |
7518 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
7519 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 2; | |
2d31ecaf MC |
7520 | else |
7521 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; | |
7522 | ||
7523 | for (txrcb = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; | |
7524 | txrcb < limit; txrcb += TG3_BDINFO_SIZE) | |
7525 | tg3_write_mem(tp, txrcb + TG3_BDINFO_MAXLEN_FLAGS, | |
7526 | BDINFO_FLAGS_DISABLED); | |
7527 | ||
7528 | ||
7529 | /* Disable all receive return rings but the first. */ | |
a50d0796 MC |
7530 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
7531 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) | |
f6eb9b1f MC |
7532 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 17; |
7533 | else if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) | |
2d31ecaf | 7534 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 16; |
b703df6f MC |
7535 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
7536 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) | |
2d31ecaf MC |
7537 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 4; |
7538 | else | |
7539 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; | |
7540 | ||
7541 | for (rxrcb = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; | |
7542 | rxrcb < limit; rxrcb += TG3_BDINFO_SIZE) | |
7543 | tg3_write_mem(tp, rxrcb + TG3_BDINFO_MAXLEN_FLAGS, | |
7544 | BDINFO_FLAGS_DISABLED); | |
7545 | ||
7546 | /* Disable interrupts */ | |
7547 | tw32_mailbox_f(tp->napi[0].int_mbox, 1); | |
7548 | ||
7549 | /* Zero mailbox registers. */ | |
f77a6a8e MC |
7550 | if (tp->tg3_flags & TG3_FLAG_SUPPORT_MSIX) { |
7551 | for (i = 1; i < TG3_IRQ_MAX_VECS; i++) { | |
7552 | tp->napi[i].tx_prod = 0; | |
7553 | tp->napi[i].tx_cons = 0; | |
c2353a32 MC |
7554 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
7555 | tw32_mailbox(tp->napi[i].prodmbox, 0); | |
f77a6a8e MC |
7556 | tw32_rx_mbox(tp->napi[i].consmbox, 0); |
7557 | tw32_mailbox_f(tp->napi[i].int_mbox, 1); | |
7558 | } | |
c2353a32 MC |
7559 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS)) |
7560 | tw32_mailbox(tp->napi[0].prodmbox, 0); | |
f77a6a8e MC |
7561 | } else { |
7562 | tp->napi[0].tx_prod = 0; | |
7563 | tp->napi[0].tx_cons = 0; | |
7564 | tw32_mailbox(tp->napi[0].prodmbox, 0); | |
7565 | tw32_rx_mbox(tp->napi[0].consmbox, 0); | |
7566 | } | |
2d31ecaf MC |
7567 | |
7568 | /* Make sure the NIC-based send BD rings are disabled. */ | |
7569 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { | |
7570 | u32 mbox = MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW; | |
7571 | for (i = 0; i < 16; i++) | |
7572 | tw32_tx_mbox(mbox + i * 8, 0); | |
7573 | } | |
7574 | ||
7575 | txrcb = NIC_SRAM_SEND_RCB; | |
7576 | rxrcb = NIC_SRAM_RCV_RET_RCB; | |
7577 | ||
7578 | /* Clear status block in ram. */ | |
7579 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); | |
7580 | ||
7581 | /* Set status block DMA address */ | |
7582 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, | |
7583 | ((u64) tnapi->status_mapping >> 32)); | |
7584 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, | |
7585 | ((u64) tnapi->status_mapping & 0xffffffff)); | |
7586 | ||
f77a6a8e MC |
7587 | if (tnapi->tx_ring) { |
7588 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, | |
7589 | (TG3_TX_RING_SIZE << | |
7590 | BDINFO_FLAGS_MAXLEN_SHIFT), | |
7591 | NIC_SRAM_TX_BUFFER_DESC); | |
7592 | txrcb += TG3_BDINFO_SIZE; | |
7593 | } | |
7594 | ||
7595 | if (tnapi->rx_rcb) { | |
7596 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, | |
7597 | (TG3_RX_RCB_RING_SIZE(tp) << | |
7598 | BDINFO_FLAGS_MAXLEN_SHIFT), 0); | |
7599 | rxrcb += TG3_BDINFO_SIZE; | |
7600 | } | |
7601 | ||
7602 | stblk = HOSTCC_STATBLCK_RING1; | |
2d31ecaf | 7603 | |
f77a6a8e MC |
7604 | for (i = 1, tnapi++; i < tp->irq_cnt; i++, tnapi++) { |
7605 | u64 mapping = (u64)tnapi->status_mapping; | |
7606 | tw32(stblk + TG3_64BIT_REG_HIGH, mapping >> 32); | |
7607 | tw32(stblk + TG3_64BIT_REG_LOW, mapping & 0xffffffff); | |
7608 | ||
7609 | /* Clear status block in ram. */ | |
7610 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); | |
7611 | ||
19cfaecc MC |
7612 | if (tnapi->tx_ring) { |
7613 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, | |
7614 | (TG3_TX_RING_SIZE << | |
7615 | BDINFO_FLAGS_MAXLEN_SHIFT), | |
7616 | NIC_SRAM_TX_BUFFER_DESC); | |
7617 | txrcb += TG3_BDINFO_SIZE; | |
7618 | } | |
f77a6a8e MC |
7619 | |
7620 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, | |
7621 | (TG3_RX_RCB_RING_SIZE(tp) << | |
7622 | BDINFO_FLAGS_MAXLEN_SHIFT), 0); | |
7623 | ||
7624 | stblk += 8; | |
f77a6a8e MC |
7625 | rxrcb += TG3_BDINFO_SIZE; |
7626 | } | |
2d31ecaf MC |
7627 | } |
7628 | ||
1da177e4 | 7629 | /* tp->lock is held. */ |
8e7a22e3 | 7630 | static int tg3_reset_hw(struct tg3 *tp, int reset_phy) |
1da177e4 LT |
7631 | { |
7632 | u32 val, rdmac_mode; | |
7633 | int i, err, limit; | |
21f581a5 | 7634 | struct tg3_rx_prodring_set *tpr = &tp->prodring[0]; |
1da177e4 LT |
7635 | |
7636 | tg3_disable_ints(tp); | |
7637 | ||
7638 | tg3_stop_fw(tp); | |
7639 | ||
7640 | tg3_write_sig_pre_reset(tp, RESET_KIND_INIT); | |
7641 | ||
859a5887 | 7642 | if (tp->tg3_flags & TG3_FLAG_INIT_COMPLETE) |
e6de8ad1 | 7643 | tg3_abort_hw(tp, 1); |
1da177e4 | 7644 | |
603f1173 | 7645 | if (reset_phy) |
d4d2c558 MC |
7646 | tg3_phy_reset(tp); |
7647 | ||
1da177e4 LT |
7648 | err = tg3_chip_reset(tp); |
7649 | if (err) | |
7650 | return err; | |
7651 | ||
7652 | tg3_write_sig_legacy(tp, RESET_KIND_INIT); | |
7653 | ||
bcb37f6c | 7654 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) { |
d30cdd28 MC |
7655 | val = tr32(TG3_CPMU_CTRL); |
7656 | val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE); | |
7657 | tw32(TG3_CPMU_CTRL, val); | |
9acb961e MC |
7658 | |
7659 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); | |
7660 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; | |
7661 | val |= CPMU_LSPD_10MB_MACCLK_6_25; | |
7662 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); | |
7663 | ||
7664 | val = tr32(TG3_CPMU_LNK_AWARE_PWRMD); | |
7665 | val &= ~CPMU_LNK_AWARE_MACCLK_MASK; | |
7666 | val |= CPMU_LNK_AWARE_MACCLK_6_25; | |
7667 | tw32(TG3_CPMU_LNK_AWARE_PWRMD, val); | |
7668 | ||
7669 | val = tr32(TG3_CPMU_HST_ACC); | |
7670 | val &= ~CPMU_HST_ACC_MACCLK_MASK; | |
7671 | val |= CPMU_HST_ACC_MACCLK_6_25; | |
7672 | tw32(TG3_CPMU_HST_ACC, val); | |
d30cdd28 MC |
7673 | } |
7674 | ||
33466d93 MC |
7675 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
7676 | val = tr32(PCIE_PWR_MGMT_THRESH) & ~PCIE_PWR_MGMT_L1_THRESH_MSK; | |
7677 | val |= PCIE_PWR_MGMT_EXT_ASPM_TMR_EN | | |
7678 | PCIE_PWR_MGMT_L1_THRESH_4MS; | |
7679 | tw32(PCIE_PWR_MGMT_THRESH, val); | |
521e6b90 MC |
7680 | |
7681 | val = tr32(TG3_PCIE_EIDLE_DELAY) & ~TG3_PCIE_EIDLE_DELAY_MASK; | |
7682 | tw32(TG3_PCIE_EIDLE_DELAY, val | TG3_PCIE_EIDLE_DELAY_13_CLKS); | |
7683 | ||
7684 | tw32(TG3_CORR_ERR_STAT, TG3_CORR_ERR_STAT_CLEAR); | |
33466d93 | 7685 | |
f40386c8 MC |
7686 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
7687 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); | |
255ca311 MC |
7688 | } |
7689 | ||
614b0590 MC |
7690 | if (tp->tg3_flags3 & TG3_FLG3_L1PLLPD_EN) { |
7691 | u32 grc_mode = tr32(GRC_MODE); | |
7692 | ||
7693 | /* Access the lower 1K of PL PCIE block registers. */ | |
7694 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; | |
7695 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); | |
7696 | ||
7697 | val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1); | |
7698 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1, | |
7699 | val | TG3_PCIE_PL_LO_PHYCTL1_L1PLLPD_EN); | |
7700 | ||
7701 | tw32(GRC_MODE, grc_mode); | |
7702 | } | |
7703 | ||
cea46462 MC |
7704 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) { |
7705 | u32 grc_mode = tr32(GRC_MODE); | |
7706 | ||
7707 | /* Access the lower 1K of PL PCIE block registers. */ | |
7708 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; | |
7709 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); | |
7710 | ||
7711 | val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL5); | |
7712 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL5, | |
7713 | val | TG3_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ); | |
7714 | ||
7715 | tw32(GRC_MODE, grc_mode); | |
a977dbe8 MC |
7716 | |
7717 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); | |
7718 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; | |
7719 | val |= CPMU_LSPD_10MB_MACCLK_6_25; | |
7720 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); | |
cea46462 MC |
7721 | } |
7722 | ||
1da177e4 LT |
7723 | /* This works around an issue with Athlon chipsets on |
7724 | * B3 tigon3 silicon. This bit has no effect on any | |
7725 | * other revision. But do not set this on PCI Express | |
795d01c5 | 7726 | * chips and don't even touch the clocks if the CPMU is present. |
1da177e4 | 7727 | */ |
795d01c5 MC |
7728 | if (!(tp->tg3_flags & TG3_FLAG_CPMU_PRESENT)) { |
7729 | if (!(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) | |
7730 | tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT; | |
7731 | tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); | |
7732 | } | |
1da177e4 LT |
7733 | |
7734 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0 && | |
7735 | (tp->tg3_flags & TG3_FLAG_PCIX_MODE)) { | |
7736 | val = tr32(TG3PCI_PCISTATE); | |
7737 | val |= PCISTATE_RETRY_SAME_DMA; | |
7738 | tw32(TG3PCI_PCISTATE, val); | |
7739 | } | |
7740 | ||
0d3031d9 MC |
7741 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
7742 | /* Allow reads and writes to the | |
7743 | * APE register and memory space. | |
7744 | */ | |
7745 | val = tr32(TG3PCI_PCISTATE); | |
7746 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | | |
f92d9dc1 MC |
7747 | PCISTATE_ALLOW_APE_SHMEM_WR | |
7748 | PCISTATE_ALLOW_APE_PSPACE_WR; | |
0d3031d9 MC |
7749 | tw32(TG3PCI_PCISTATE, val); |
7750 | } | |
7751 | ||
1da177e4 LT |
7752 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_BX) { |
7753 | /* Enable some hw fixes. */ | |
7754 | val = tr32(TG3PCI_MSI_DATA); | |
7755 | val |= (1 << 26) | (1 << 28) | (1 << 29); | |
7756 | tw32(TG3PCI_MSI_DATA, val); | |
7757 | } | |
7758 | ||
7759 | /* Descriptor ring init may make accesses to the | |
7760 | * NIC SRAM area to setup the TX descriptors, so we | |
7761 | * can only do this after the hardware has been | |
7762 | * successfully reset. | |
7763 | */ | |
32d8c572 MC |
7764 | err = tg3_init_rings(tp); |
7765 | if (err) | |
7766 | return err; | |
1da177e4 | 7767 | |
c885e824 | 7768 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
cbf9ca6c MC |
7769 | val = tr32(TG3PCI_DMA_RW_CTRL) & |
7770 | ~DMA_RWCTRL_DIS_CACHE_ALIGNMENT; | |
1a319025 MC |
7771 | if (tp->pci_chip_rev_id == CHIPREV_ID_57765_A0) |
7772 | val &= ~DMA_RWCTRL_CRDRDR_RDMA_MRRS_MSK; | |
cbf9ca6c MC |
7773 | tw32(TG3PCI_DMA_RW_CTRL, val | tp->dma_rwctrl); |
7774 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5784 && | |
7775 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5761) { | |
d30cdd28 MC |
7776 | /* This value is determined during the probe time DMA |
7777 | * engine test, tg3_test_dma. | |
7778 | */ | |
7779 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); | |
7780 | } | |
1da177e4 LT |
7781 | |
7782 | tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS | | |
7783 | GRC_MODE_4X_NIC_SEND_RINGS | | |
7784 | GRC_MODE_NO_TX_PHDR_CSUM | | |
7785 | GRC_MODE_NO_RX_PHDR_CSUM); | |
7786 | tp->grc_mode |= GRC_MODE_HOST_SENDBDS; | |
d2d746f8 MC |
7787 | |
7788 | /* Pseudo-header checksum is done by hardware logic and not | |
7789 | * the offload processers, so make the chip do the pseudo- | |
7790 | * header checksums on receive. For transmit it is more | |
7791 | * convenient to do the pseudo-header checksum in software | |
7792 | * as Linux does that on transmit for us in all cases. | |
7793 | */ | |
7794 | tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM; | |
1da177e4 LT |
7795 | |
7796 | tw32(GRC_MODE, | |
7797 | tp->grc_mode | | |
7798 | (GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP)); | |
7799 | ||
7800 | /* Setup the timer prescalar register. Clock is always 66Mhz. */ | |
7801 | val = tr32(GRC_MISC_CFG); | |
7802 | val &= ~0xff; | |
7803 | val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT); | |
7804 | tw32(GRC_MISC_CFG, val); | |
7805 | ||
7806 | /* Initialize MBUF/DESC pool. */ | |
cbf46853 | 7807 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { |
1da177e4 LT |
7808 | /* Do nothing. */ |
7809 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5705) { | |
7810 | tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE); | |
7811 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) | |
7812 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64); | |
7813 | else | |
7814 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96); | |
7815 | tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE); | |
7816 | tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE); | |
859a5887 | 7817 | } else if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) { |
1da177e4 LT |
7818 | int fw_len; |
7819 | ||
077f849d | 7820 | fw_len = tp->fw_len; |
1da177e4 LT |
7821 | fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1); |
7822 | tw32(BUFMGR_MB_POOL_ADDR, | |
7823 | NIC_SRAM_MBUF_POOL_BASE5705 + fw_len); | |
7824 | tw32(BUFMGR_MB_POOL_SIZE, | |
7825 | NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00); | |
7826 | } | |
1da177e4 | 7827 | |
0f893dc6 | 7828 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
1da177e4 LT |
7829 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
7830 | tp->bufmgr_config.mbuf_read_dma_low_water); | |
7831 | tw32(BUFMGR_MB_MACRX_LOW_WATER, | |
7832 | tp->bufmgr_config.mbuf_mac_rx_low_water); | |
7833 | tw32(BUFMGR_MB_HIGH_WATER, | |
7834 | tp->bufmgr_config.mbuf_high_water); | |
7835 | } else { | |
7836 | tw32(BUFMGR_MB_RDMA_LOW_WATER, | |
7837 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo); | |
7838 | tw32(BUFMGR_MB_MACRX_LOW_WATER, | |
7839 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo); | |
7840 | tw32(BUFMGR_MB_HIGH_WATER, | |
7841 | tp->bufmgr_config.mbuf_high_water_jumbo); | |
7842 | } | |
7843 | tw32(BUFMGR_DMA_LOW_WATER, | |
7844 | tp->bufmgr_config.dma_low_water); | |
7845 | tw32(BUFMGR_DMA_HIGH_WATER, | |
7846 | tp->bufmgr_config.dma_high_water); | |
7847 | ||
7848 | tw32(BUFMGR_MODE, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE); | |
7849 | for (i = 0; i < 2000; i++) { | |
7850 | if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE) | |
7851 | break; | |
7852 | udelay(10); | |
7853 | } | |
7854 | if (i >= 2000) { | |
05dbe005 | 7855 | netdev_err(tp->dev, "%s cannot enable BUFMGR\n", __func__); |
1da177e4 LT |
7856 | return -ENODEV; |
7857 | } | |
7858 | ||
7859 | /* Setup replenish threshold. */ | |
f92905de MC |
7860 | val = tp->rx_pending / 8; |
7861 | if (val == 0) | |
7862 | val = 1; | |
7863 | else if (val > tp->rx_std_max_post) | |
7864 | val = tp->rx_std_max_post; | |
b5d3772c MC |
7865 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
7866 | if (tp->pci_chip_rev_id == CHIPREV_ID_5906_A1) | |
7867 | tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2); | |
7868 | ||
7869 | if (val > (TG3_RX_INTERNAL_RING_SZ_5906 / 2)) | |
7870 | val = TG3_RX_INTERNAL_RING_SZ_5906 / 2; | |
7871 | } | |
f92905de MC |
7872 | |
7873 | tw32(RCVBDI_STD_THRESH, val); | |
1da177e4 LT |
7874 | |
7875 | /* Initialize TG3_BDINFO's at: | |
7876 | * RCVDBDI_STD_BD: standard eth size rx ring | |
7877 | * RCVDBDI_JUMBO_BD: jumbo frame rx ring | |
7878 | * RCVDBDI_MINI_BD: small frame rx ring (??? does not work) | |
7879 | * | |
7880 | * like so: | |
7881 | * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring | |
7882 | * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) | | |
7883 | * ring attribute flags | |
7884 | * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM | |
7885 | * | |
7886 | * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries. | |
7887 | * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries. | |
7888 | * | |
7889 | * The size of each ring is fixed in the firmware, but the location is | |
7890 | * configurable. | |
7891 | */ | |
7892 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, | |
21f581a5 | 7893 | ((u64) tpr->rx_std_mapping >> 32)); |
1da177e4 | 7894 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
21f581a5 | 7895 | ((u64) tpr->rx_std_mapping & 0xffffffff)); |
a50d0796 MC |
7896 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5717 && |
7897 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5719) | |
87668d35 MC |
7898 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR, |
7899 | NIC_SRAM_RX_BUFFER_DESC); | |
1da177e4 | 7900 | |
fdb72b38 MC |
7901 | /* Disable the mini ring */ |
7902 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) | |
1da177e4 LT |
7903 | tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS, |
7904 | BDINFO_FLAGS_DISABLED); | |
7905 | ||
fdb72b38 MC |
7906 | /* Program the jumbo buffer descriptor ring control |
7907 | * blocks on those devices that have them. | |
7908 | */ | |
8f666b07 | 7909 | if ((tp->tg3_flags & TG3_FLAG_JUMBO_CAPABLE) && |
fdb72b38 | 7910 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
1da177e4 LT |
7911 | /* Setup replenish threshold. */ |
7912 | tw32(RCVBDI_JUMBO_THRESH, tp->rx_jumbo_pending / 8); | |
7913 | ||
0f893dc6 | 7914 | if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) { |
1da177e4 | 7915 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
21f581a5 | 7916 | ((u64) tpr->rx_jmb_mapping >> 32)); |
1da177e4 | 7917 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
21f581a5 | 7918 | ((u64) tpr->rx_jmb_mapping & 0xffffffff)); |
1da177e4 | 7919 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
79ed5ac7 MC |
7920 | (RX_JUMBO_MAX_SIZE << BDINFO_FLAGS_MAXLEN_SHIFT) | |
7921 | BDINFO_FLAGS_USE_EXT_RECV); | |
a50d0796 MC |
7922 | if (!(tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG) || |
7923 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) | |
87668d35 MC |
7924 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR, |
7925 | NIC_SRAM_RX_JUMBO_BUFFER_DESC); | |
1da177e4 LT |
7926 | } else { |
7927 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, | |
7928 | BDINFO_FLAGS_DISABLED); | |
7929 | } | |
7930 | ||
c885e824 | 7931 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) |
f6eb9b1f | 7932 | val = (RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT) | |
04380d40 | 7933 | (TG3_RX_STD_DMA_SZ << 2); |
f6eb9b1f | 7934 | else |
04380d40 | 7935 | val = TG3_RX_STD_DMA_SZ << BDINFO_FLAGS_MAXLEN_SHIFT; |
fdb72b38 MC |
7936 | } else |
7937 | val = RX_STD_MAX_SIZE_5705 << BDINFO_FLAGS_MAXLEN_SHIFT; | |
7938 | ||
7939 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS, val); | |
1da177e4 | 7940 | |
411da640 | 7941 | tpr->rx_std_prod_idx = tp->rx_pending; |
66711e66 | 7942 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, tpr->rx_std_prod_idx); |
1da177e4 | 7943 | |
411da640 | 7944 | tpr->rx_jmb_prod_idx = (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) ? |
21f581a5 | 7945 | tp->rx_jumbo_pending : 0; |
66711e66 | 7946 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, tpr->rx_jmb_prod_idx); |
1da177e4 | 7947 | |
c885e824 | 7948 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
f6eb9b1f MC |
7949 | tw32(STD_REPLENISH_LWM, 32); |
7950 | tw32(JMB_REPLENISH_LWM, 16); | |
7951 | } | |
7952 | ||
2d31ecaf MC |
7953 | tg3_rings_reset(tp); |
7954 | ||
1da177e4 | 7955 | /* Initialize MAC address and backoff seed. */ |
986e0aeb | 7956 | __tg3_set_mac_addr(tp, 0); |
1da177e4 LT |
7957 | |
7958 | /* MTU + ethernet header + FCS + optional VLAN tag */ | |
f7b493e0 MC |
7959 | tw32(MAC_RX_MTU_SIZE, |
7960 | tp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); | |
1da177e4 LT |
7961 | |
7962 | /* The slot time is changed by tg3_setup_phy if we | |
7963 | * run at gigabit with half duplex. | |
7964 | */ | |
7965 | tw32(MAC_TX_LENGTHS, | |
7966 | (2 << TX_LENGTHS_IPG_CRS_SHIFT) | | |
7967 | (6 << TX_LENGTHS_IPG_SHIFT) | | |
7968 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT)); | |
7969 | ||
7970 | /* Receive rules. */ | |
7971 | tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS); | |
7972 | tw32(RCVLPC_CONFIG, 0x0181); | |
7973 | ||
7974 | /* Calculate RDMAC_MODE setting early, we need it to determine | |
7975 | * the RCVLPC_STATE_ENABLE mask. | |
7976 | */ | |
7977 | rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB | | |
7978 | RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB | | |
7979 | RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB | | |
7980 | RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB | | |
7981 | RDMAC_MODE_LNGREAD_ENAB); | |
85e94ced | 7982 | |
a50d0796 MC |
7983 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
7984 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) | |
0339e4e3 MC |
7985 | rdmac_mode |= RDMAC_MODE_MULT_DMA_RD_DIS; |
7986 | ||
57e6983c | 7987 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
321d32a0 MC |
7988 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
7989 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) | |
d30cdd28 MC |
7990 | rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB | |
7991 | RDMAC_MODE_MBUF_RBD_CRPT_ENAB | | |
7992 | RDMAC_MODE_MBUF_SBD_CRPT_ENAB; | |
7993 | ||
85e94ced MC |
7994 | /* If statement applies to 5705 and 5750 PCI devices only */ |
7995 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && | |
7996 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) || | |
7997 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750)) { | |
1da177e4 | 7998 | if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE && |
c13e3713 | 7999 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) { |
1da177e4 LT |
8000 | rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128; |
8001 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && | |
8002 | !(tp->tg3_flags2 & TG3_FLG2_IS_5788)) { | |
8003 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; | |
8004 | } | |
8005 | } | |
8006 | ||
85e94ced MC |
8007 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) |
8008 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; | |
8009 | ||
1da177e4 | 8010 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) |
027455ad MC |
8011 | rdmac_mode |= RDMAC_MODE_IPV4_LSO_EN; |
8012 | ||
e849cdc3 MC |
8013 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) || |
8014 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || | |
027455ad MC |
8015 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
8016 | rdmac_mode |= RDMAC_MODE_IPV6_LSO_EN; | |
1da177e4 LT |
8017 | |
8018 | /* Receive/send statistics. */ | |
1661394e MC |
8019 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { |
8020 | val = tr32(RCVLPC_STATS_ENABLE); | |
8021 | val &= ~RCVLPC_STATSENAB_DACK_FIX; | |
8022 | tw32(RCVLPC_STATS_ENABLE, val); | |
8023 | } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) && | |
8024 | (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) { | |
1da177e4 LT |
8025 | val = tr32(RCVLPC_STATS_ENABLE); |
8026 | val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX; | |
8027 | tw32(RCVLPC_STATS_ENABLE, val); | |
8028 | } else { | |
8029 | tw32(RCVLPC_STATS_ENABLE, 0xffffff); | |
8030 | } | |
8031 | tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE); | |
8032 | tw32(SNDDATAI_STATSENAB, 0xffffff); | |
8033 | tw32(SNDDATAI_STATSCTRL, | |
8034 | (SNDDATAI_SCTRL_ENABLE | | |
8035 | SNDDATAI_SCTRL_FASTUPD)); | |
8036 | ||
8037 | /* Setup host coalescing engine. */ | |
8038 | tw32(HOSTCC_MODE, 0); | |
8039 | for (i = 0; i < 2000; i++) { | |
8040 | if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE)) | |
8041 | break; | |
8042 | udelay(10); | |
8043 | } | |
8044 | ||
d244c892 | 8045 | __tg3_set_coalesce(tp, &tp->coal); |
1da177e4 | 8046 | |
1da177e4 LT |
8047 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
8048 | /* Status/statistics block address. See tg3_timer, | |
8049 | * the tg3_periodic_fetch_stats call there, and | |
8050 | * tg3_get_stats to see how this works for 5705/5750 chips. | |
8051 | */ | |
1da177e4 LT |
8052 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
8053 | ((u64) tp->stats_mapping >> 32)); | |
8054 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, | |
8055 | ((u64) tp->stats_mapping & 0xffffffff)); | |
8056 | tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK); | |
2d31ecaf | 8057 | |
1da177e4 | 8058 | tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK); |
2d31ecaf MC |
8059 | |
8060 | /* Clear statistics and status block memory areas */ | |
8061 | for (i = NIC_SRAM_STATS_BLK; | |
8062 | i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE; | |
8063 | i += sizeof(u32)) { | |
8064 | tg3_write_mem(tp, i, 0); | |
8065 | udelay(40); | |
8066 | } | |
1da177e4 LT |
8067 | } |
8068 | ||
8069 | tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode); | |
8070 | ||
8071 | tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE); | |
8072 | tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE); | |
8073 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) | |
8074 | tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE); | |
8075 | ||
f07e9af3 MC |
8076 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
8077 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; | |
c94e3941 MC |
8078 | /* reset to prevent losing 1st rx packet intermittently */ |
8079 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); | |
8080 | udelay(10); | |
8081 | } | |
8082 | ||
3bda1258 MC |
8083 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) |
8084 | tp->mac_mode &= MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; | |
8085 | else | |
8086 | tp->mac_mode = 0; | |
8087 | tp->mac_mode |= MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE | | |
1da177e4 | 8088 | MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | MAC_MODE_FHDE_ENABLE; |
e8f3f6ca | 8089 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
f07e9af3 | 8090 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
e8f3f6ca MC |
8091 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) |
8092 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; | |
1da177e4 LT |
8093 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR); |
8094 | udelay(40); | |
8095 | ||
314fba34 | 8096 | /* tp->grc_local_ctrl is partially set up during tg3_get_invariants(). |
9d26e213 | 8097 | * If TG3_FLG2_IS_NIC is zero, we should read the |
314fba34 MC |
8098 | * register to preserve the GPIO settings for LOMs. The GPIOs, |
8099 | * whether used as inputs or outputs, are set by boot code after | |
8100 | * reset. | |
8101 | */ | |
9d26e213 | 8102 | if (!(tp->tg3_flags2 & TG3_FLG2_IS_NIC)) { |
314fba34 MC |
8103 | u32 gpio_mask; |
8104 | ||
9d26e213 MC |
8105 | gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 | |
8106 | GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 | | |
8107 | GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2; | |
3e7d83bc MC |
8108 | |
8109 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) | |
8110 | gpio_mask |= GRC_LCLCTRL_GPIO_OE3 | | |
8111 | GRC_LCLCTRL_GPIO_OUTPUT3; | |
8112 | ||
af36e6b6 MC |
8113 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
8114 | gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL; | |
8115 | ||
aaf84465 | 8116 | tp->grc_local_ctrl &= ~gpio_mask; |
314fba34 MC |
8117 | tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask; |
8118 | ||
8119 | /* GPIO1 must be driven high for eeprom write protect */ | |
9d26e213 MC |
8120 | if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) |
8121 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | | |
8122 | GRC_LCLCTRL_GPIO_OUTPUT1); | |
314fba34 | 8123 | } |
1da177e4 LT |
8124 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
8125 | udelay(100); | |
8126 | ||
baf8a94a MC |
8127 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSIX) { |
8128 | val = tr32(MSGINT_MODE); | |
8129 | val |= MSGINT_MODE_MULTIVEC_EN | MSGINT_MODE_ENABLE; | |
8130 | tw32(MSGINT_MODE, val); | |
8131 | } | |
8132 | ||
1da177e4 LT |
8133 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { |
8134 | tw32_f(DMAC_MODE, DMAC_MODE_ENABLE); | |
8135 | udelay(40); | |
8136 | } | |
8137 | ||
8138 | val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB | | |
8139 | WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB | | |
8140 | WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB | | |
8141 | WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB | | |
8142 | WDMAC_MODE_LNGREAD_ENAB); | |
8143 | ||
85e94ced MC |
8144 | /* If statement applies to 5705 and 5750 PCI devices only */ |
8145 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && | |
8146 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) || | |
8147 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) { | |
29ea095f | 8148 | if ((tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) && |
1da177e4 LT |
8149 | (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 || |
8150 | tp->pci_chip_rev_id == CHIPREV_ID_5705_A2)) { | |
8151 | /* nothing */ | |
8152 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && | |
8153 | !(tp->tg3_flags2 & TG3_FLG2_IS_5788) && | |
8154 | !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) { | |
8155 | val |= WDMAC_MODE_RX_ACCEL; | |
8156 | } | |
8157 | } | |
8158 | ||
d9ab5ad1 | 8159 | /* Enable host coalescing bug fix */ |
321d32a0 | 8160 | if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
f51f3562 | 8161 | val |= WDMAC_MODE_STATUS_TAG_FIX; |
d9ab5ad1 | 8162 | |
788a035e MC |
8163 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
8164 | val |= WDMAC_MODE_BURST_ALL_DATA; | |
8165 | ||
1da177e4 LT |
8166 | tw32_f(WDMAC_MODE, val); |
8167 | udelay(40); | |
8168 | ||
9974a356 MC |
8169 | if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) { |
8170 | u16 pcix_cmd; | |
8171 | ||
8172 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, | |
8173 | &pcix_cmd); | |
1da177e4 | 8174 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) { |
9974a356 MC |
8175 | pcix_cmd &= ~PCI_X_CMD_MAX_READ; |
8176 | pcix_cmd |= PCI_X_CMD_READ_2K; | |
1da177e4 | 8177 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { |
9974a356 MC |
8178 | pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ); |
8179 | pcix_cmd |= PCI_X_CMD_READ_2K; | |
1da177e4 | 8180 | } |
9974a356 MC |
8181 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
8182 | pcix_cmd); | |
1da177e4 LT |
8183 | } |
8184 | ||
8185 | tw32_f(RDMAC_MODE, rdmac_mode); | |
8186 | udelay(40); | |
8187 | ||
8188 | tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE); | |
8189 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) | |
8190 | tw32(MBFREE_MODE, MBFREE_MODE_ENABLE); | |
9936bcf6 MC |
8191 | |
8192 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) | |
8193 | tw32(SNDDATAC_MODE, | |
8194 | SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY); | |
8195 | else | |
8196 | tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE); | |
8197 | ||
1da177e4 LT |
8198 | tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE); |
8199 | tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB); | |
8200 | tw32(RCVDBDI_MODE, RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ); | |
8201 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE); | |
1da177e4 LT |
8202 | if (tp->tg3_flags2 & TG3_FLG2_HW_TSO) |
8203 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8); | |
baf8a94a | 8204 | val = SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE; |
19cfaecc | 8205 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
baf8a94a MC |
8206 | val |= SNDBDI_MODE_MULTI_TXQ_EN; |
8207 | tw32(SNDBDI_MODE, val); | |
1da177e4 LT |
8208 | tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE); |
8209 | ||
8210 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { | |
8211 | err = tg3_load_5701_a0_firmware_fix(tp); | |
8212 | if (err) | |
8213 | return err; | |
8214 | } | |
8215 | ||
1da177e4 LT |
8216 | if (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) { |
8217 | err = tg3_load_tso_firmware(tp); | |
8218 | if (err) | |
8219 | return err; | |
8220 | } | |
1da177e4 LT |
8221 | |
8222 | tp->tx_mode = TX_MODE_ENABLE; | |
b1d05210 MC |
8223 | if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) || |
8224 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) | |
8225 | tp->tx_mode |= TX_MODE_MBUF_LOCKUP_FIX; | |
1da177e4 LT |
8226 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
8227 | udelay(100); | |
8228 | ||
baf8a94a MC |
8229 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS) { |
8230 | u32 reg = MAC_RSS_INDIR_TBL_0; | |
8231 | u8 *ent = (u8 *)&val; | |
8232 | ||
8233 | /* Setup the indirection table */ | |
8234 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) { | |
8235 | int idx = i % sizeof(val); | |
8236 | ||
5efeeea1 | 8237 | ent[idx] = i % (tp->irq_cnt - 1); |
baf8a94a MC |
8238 | if (idx == sizeof(val) - 1) { |
8239 | tw32(reg, val); | |
8240 | reg += 4; | |
8241 | } | |
8242 | } | |
8243 | ||
8244 | /* Setup the "secret" hash key. */ | |
8245 | tw32(MAC_RSS_HASH_KEY_0, 0x5f865437); | |
8246 | tw32(MAC_RSS_HASH_KEY_1, 0xe4ac62cc); | |
8247 | tw32(MAC_RSS_HASH_KEY_2, 0x50103a45); | |
8248 | tw32(MAC_RSS_HASH_KEY_3, 0x36621985); | |
8249 | tw32(MAC_RSS_HASH_KEY_4, 0xbf14c0e8); | |
8250 | tw32(MAC_RSS_HASH_KEY_5, 0x1bc27a1e); | |
8251 | tw32(MAC_RSS_HASH_KEY_6, 0x84f4b556); | |
8252 | tw32(MAC_RSS_HASH_KEY_7, 0x094ea6fe); | |
8253 | tw32(MAC_RSS_HASH_KEY_8, 0x7dda01e7); | |
8254 | tw32(MAC_RSS_HASH_KEY_9, 0xc04d7481); | |
8255 | } | |
8256 | ||
1da177e4 | 8257 | tp->rx_mode = RX_MODE_ENABLE; |
321d32a0 | 8258 | if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
af36e6b6 MC |
8259 | tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE; |
8260 | ||
baf8a94a MC |
8261 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_RSS) |
8262 | tp->rx_mode |= RX_MODE_RSS_ENABLE | | |
8263 | RX_MODE_RSS_ITBL_HASH_BITS_7 | | |
8264 | RX_MODE_RSS_IPV6_HASH_EN | | |
8265 | RX_MODE_RSS_TCP_IPV6_HASH_EN | | |
8266 | RX_MODE_RSS_IPV4_HASH_EN | | |
8267 | RX_MODE_RSS_TCP_IPV4_HASH_EN; | |
8268 | ||
1da177e4 LT |
8269 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
8270 | udelay(10); | |
8271 | ||
1da177e4 LT |
8272 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
8273 | ||
8274 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); | |
f07e9af3 | 8275 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
1da177e4 LT |
8276 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
8277 | udelay(10); | |
8278 | } | |
8279 | tw32_f(MAC_RX_MODE, tp->rx_mode); | |
8280 | udelay(10); | |
8281 | ||
f07e9af3 | 8282 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
1da177e4 | 8283 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) && |
f07e9af3 | 8284 | !(tp->phy_flags & TG3_PHYFLG_SERDES_PREEMPHASIS)) { |
1da177e4 LT |
8285 | /* Set drive transmission level to 1.2V */ |
8286 | /* only if the signal pre-emphasis bit is not set */ | |
8287 | val = tr32(MAC_SERDES_CFG); | |
8288 | val &= 0xfffff000; | |
8289 | val |= 0x880; | |
8290 | tw32(MAC_SERDES_CFG, val); | |
8291 | } | |
8292 | if (tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) | |
8293 | tw32(MAC_SERDES_CFG, 0x616000); | |
8294 | } | |
8295 | ||
8296 | /* Prevent chip from dropping frames when flow control | |
8297 | * is enabled. | |
8298 | */ | |
666bc831 MC |
8299 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) |
8300 | val = 1; | |
8301 | else | |
8302 | val = 2; | |
8303 | tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, val); | |
1da177e4 LT |
8304 | |
8305 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 && | |
f07e9af3 | 8306 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
1da177e4 LT |
8307 | /* Use hardware link auto-negotiation */ |
8308 | tp->tg3_flags2 |= TG3_FLG2_HW_AUTONEG; | |
8309 | } | |
8310 | ||
f07e9af3 | 8311 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
d4d2c558 MC |
8312 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714)) { |
8313 | u32 tmp; | |
8314 | ||
8315 | tmp = tr32(SERDES_RX_CTRL); | |
8316 | tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT); | |
8317 | tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT; | |
8318 | tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT; | |
8319 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl); | |
8320 | } | |
8321 | ||
dd477003 | 8322 | if (!(tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB)) { |
80096068 MC |
8323 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
8324 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; | |
dd477003 MC |
8325 | tp->link_config.speed = tp->link_config.orig_speed; |
8326 | tp->link_config.duplex = tp->link_config.orig_duplex; | |
8327 | tp->link_config.autoneg = tp->link_config.orig_autoneg; | |
8328 | } | |
1da177e4 | 8329 | |
dd477003 MC |
8330 | err = tg3_setup_phy(tp, 0); |
8331 | if (err) | |
8332 | return err; | |
1da177e4 | 8333 | |
f07e9af3 MC |
8334 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
8335 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { | |
dd477003 MC |
8336 | u32 tmp; |
8337 | ||
8338 | /* Clear CRC stats. */ | |
8339 | if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) { | |
8340 | tg3_writephy(tp, MII_TG3_TEST1, | |
8341 | tmp | MII_TG3_TEST1_CRC_EN); | |
f08aa1a8 | 8342 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &tmp); |
dd477003 | 8343 | } |
1da177e4 LT |
8344 | } |
8345 | } | |
8346 | ||
8347 | __tg3_set_rx_mode(tp->dev); | |
8348 | ||
8349 | /* Initialize receive rules. */ | |
8350 | tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK); | |
8351 | tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK); | |
8352 | tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK); | |
8353 | tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK); | |
8354 | ||
4cf78e4f | 8355 | if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
a4e2b347 | 8356 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
1da177e4 LT |
8357 | limit = 8; |
8358 | else | |
8359 | limit = 16; | |
8360 | if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) | |
8361 | limit -= 4; | |
8362 | switch (limit) { | |
8363 | case 16: | |
8364 | tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0); | |
8365 | case 15: | |
8366 | tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0); | |
8367 | case 14: | |
8368 | tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0); | |
8369 | case 13: | |
8370 | tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0); | |
8371 | case 12: | |
8372 | tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0); | |
8373 | case 11: | |
8374 | tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0); | |
8375 | case 10: | |
8376 | tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0); | |
8377 | case 9: | |
8378 | tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0); | |
8379 | case 8: | |
8380 | tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0); | |
8381 | case 7: | |
8382 | tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0); | |
8383 | case 6: | |
8384 | tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0); | |
8385 | case 5: | |
8386 | tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0); | |
8387 | case 4: | |
8388 | /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */ | |
8389 | case 3: | |
8390 | /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */ | |
8391 | case 2: | |
8392 | case 1: | |
8393 | ||
8394 | default: | |
8395 | break; | |
855e1111 | 8396 | } |
1da177e4 | 8397 | |
9ce768ea MC |
8398 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) |
8399 | /* Write our heartbeat update interval to APE. */ | |
8400 | tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS, | |
8401 | APE_HOST_HEARTBEAT_INT_DISABLE); | |
0d3031d9 | 8402 | |
1da177e4 LT |
8403 | tg3_write_sig_post_reset(tp, RESET_KIND_INIT); |
8404 | ||
1da177e4 LT |
8405 | return 0; |
8406 | } | |
8407 | ||
8408 | /* Called at device open time to get the chip ready for | |
8409 | * packet processing. Invoked with tp->lock held. | |
8410 | */ | |
8e7a22e3 | 8411 | static int tg3_init_hw(struct tg3 *tp, int reset_phy) |
1da177e4 | 8412 | { |
1da177e4 LT |
8413 | tg3_switch_clocks(tp); |
8414 | ||
8415 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
8416 | ||
2f751b67 | 8417 | return tg3_reset_hw(tp, reset_phy); |
1da177e4 LT |
8418 | } |
8419 | ||
8420 | #define TG3_STAT_ADD32(PSTAT, REG) \ | |
8421 | do { u32 __val = tr32(REG); \ | |
8422 | (PSTAT)->low += __val; \ | |
8423 | if ((PSTAT)->low < __val) \ | |
8424 | (PSTAT)->high += 1; \ | |
8425 | } while (0) | |
8426 | ||
8427 | static void tg3_periodic_fetch_stats(struct tg3 *tp) | |
8428 | { | |
8429 | struct tg3_hw_stats *sp = tp->hw_stats; | |
8430 | ||
8431 | if (!netif_carrier_ok(tp->dev)) | |
8432 | return; | |
8433 | ||
8434 | TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS); | |
8435 | TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS); | |
8436 | TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT); | |
8437 | TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT); | |
8438 | TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS); | |
8439 | TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS); | |
8440 | TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS); | |
8441 | TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED); | |
8442 | TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL); | |
8443 | TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL); | |
8444 | TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST); | |
8445 | TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST); | |
8446 | TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST); | |
8447 | ||
8448 | TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS); | |
8449 | TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS); | |
8450 | TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST); | |
8451 | TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST); | |
8452 | TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST); | |
8453 | TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS); | |
8454 | TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS); | |
8455 | TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD); | |
8456 | TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD); | |
8457 | TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD); | |
8458 | TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED); | |
8459 | TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG); | |
8460 | TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS); | |
8461 | TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE); | |
463d305b MC |
8462 | |
8463 | TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT); | |
8464 | TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT); | |
8465 | TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT); | |
1da177e4 LT |
8466 | } |
8467 | ||
8468 | static void tg3_timer(unsigned long __opaque) | |
8469 | { | |
8470 | struct tg3 *tp = (struct tg3 *) __opaque; | |
1da177e4 | 8471 | |
f475f163 MC |
8472 | if (tp->irq_sync) |
8473 | goto restart_timer; | |
8474 | ||
f47c11ee | 8475 | spin_lock(&tp->lock); |
1da177e4 | 8476 | |
fac9b83e DM |
8477 | if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) { |
8478 | /* All of this garbage is because when using non-tagged | |
8479 | * IRQ status the mailbox/status_block protocol the chip | |
8480 | * uses with the cpu is race prone. | |
8481 | */ | |
898a56f8 | 8482 | if (tp->napi[0].hw_status->status & SD_STATUS_UPDATED) { |
fac9b83e DM |
8483 | tw32(GRC_LOCAL_CTRL, |
8484 | tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); | |
8485 | } else { | |
8486 | tw32(HOSTCC_MODE, tp->coalesce_mode | | |
fd2ce37f | 8487 | HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW); |
fac9b83e | 8488 | } |
1da177e4 | 8489 | |
fac9b83e DM |
8490 | if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
8491 | tp->tg3_flags2 |= TG3_FLG2_RESTART_TIMER; | |
f47c11ee | 8492 | spin_unlock(&tp->lock); |
fac9b83e DM |
8493 | schedule_work(&tp->reset_task); |
8494 | return; | |
8495 | } | |
1da177e4 LT |
8496 | } |
8497 | ||
1da177e4 LT |
8498 | /* This part only runs once per second. */ |
8499 | if (!--tp->timer_counter) { | |
fac9b83e DM |
8500 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) |
8501 | tg3_periodic_fetch_stats(tp); | |
8502 | ||
1da177e4 LT |
8503 | if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) { |
8504 | u32 mac_stat; | |
8505 | int phy_event; | |
8506 | ||
8507 | mac_stat = tr32(MAC_STATUS); | |
8508 | ||
8509 | phy_event = 0; | |
f07e9af3 | 8510 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) { |
1da177e4 LT |
8511 | if (mac_stat & MAC_STATUS_MI_INTERRUPT) |
8512 | phy_event = 1; | |
8513 | } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED) | |
8514 | phy_event = 1; | |
8515 | ||
8516 | if (phy_event) | |
8517 | tg3_setup_phy(tp, 0); | |
8518 | } else if (tp->tg3_flags & TG3_FLAG_POLL_SERDES) { | |
8519 | u32 mac_stat = tr32(MAC_STATUS); | |
8520 | int need_setup = 0; | |
8521 | ||
8522 | if (netif_carrier_ok(tp->dev) && | |
8523 | (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) { | |
8524 | need_setup = 1; | |
8525 | } | |
be98da6a | 8526 | if (!netif_carrier_ok(tp->dev) && |
1da177e4 LT |
8527 | (mac_stat & (MAC_STATUS_PCS_SYNCED | |
8528 | MAC_STATUS_SIGNAL_DET))) { | |
8529 | need_setup = 1; | |
8530 | } | |
8531 | if (need_setup) { | |
3d3ebe74 MC |
8532 | if (!tp->serdes_counter) { |
8533 | tw32_f(MAC_MODE, | |
8534 | (tp->mac_mode & | |
8535 | ~MAC_MODE_PORT_MODE_MASK)); | |
8536 | udelay(40); | |
8537 | tw32_f(MAC_MODE, tp->mac_mode); | |
8538 | udelay(40); | |
8539 | } | |
1da177e4 LT |
8540 | tg3_setup_phy(tp, 0); |
8541 | } | |
f07e9af3 | 8542 | } else if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
2138c002 | 8543 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
747e8f8b | 8544 | tg3_serdes_parallel_detect(tp); |
57d8b880 | 8545 | } |
1da177e4 LT |
8546 | |
8547 | tp->timer_counter = tp->timer_multiplier; | |
8548 | } | |
8549 | ||
130b8e4d MC |
8550 | /* Heartbeat is only sent once every 2 seconds. |
8551 | * | |
8552 | * The heartbeat is to tell the ASF firmware that the host | |
8553 | * driver is still alive. In the event that the OS crashes, | |
8554 | * ASF needs to reset the hardware to free up the FIFO space | |
8555 | * that may be filled with rx packets destined for the host. | |
8556 | * If the FIFO is full, ASF will no longer function properly. | |
8557 | * | |
8558 | * Unintended resets have been reported on real time kernels | |
8559 | * where the timer doesn't run on time. Netpoll will also have | |
8560 | * same problem. | |
8561 | * | |
8562 | * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware | |
8563 | * to check the ring condition when the heartbeat is expiring | |
8564 | * before doing the reset. This will prevent most unintended | |
8565 | * resets. | |
8566 | */ | |
1da177e4 | 8567 | if (!--tp->asf_counter) { |
bc7959b2 MC |
8568 | if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) && |
8569 | !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) { | |
7c5026aa MC |
8570 | tg3_wait_for_event_ack(tp); |
8571 | ||
bbadf503 | 8572 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, |
130b8e4d | 8573 | FWCMD_NICDRV_ALIVE3); |
bbadf503 | 8574 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); |
c6cdf436 MC |
8575 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, |
8576 | TG3_FW_UPDATE_TIMEOUT_SEC); | |
4ba526ce MC |
8577 | |
8578 | tg3_generate_fw_event(tp); | |
1da177e4 LT |
8579 | } |
8580 | tp->asf_counter = tp->asf_multiplier; | |
8581 | } | |
8582 | ||
f47c11ee | 8583 | spin_unlock(&tp->lock); |
1da177e4 | 8584 | |
f475f163 | 8585 | restart_timer: |
1da177e4 LT |
8586 | tp->timer.expires = jiffies + tp->timer_offset; |
8587 | add_timer(&tp->timer); | |
8588 | } | |
8589 | ||
4f125f42 | 8590 | static int tg3_request_irq(struct tg3 *tp, int irq_num) |
fcfa0a32 | 8591 | { |
7d12e780 | 8592 | irq_handler_t fn; |
fcfa0a32 | 8593 | unsigned long flags; |
4f125f42 MC |
8594 | char *name; |
8595 | struct tg3_napi *tnapi = &tp->napi[irq_num]; | |
8596 | ||
8597 | if (tp->irq_cnt == 1) | |
8598 | name = tp->dev->name; | |
8599 | else { | |
8600 | name = &tnapi->irq_lbl[0]; | |
8601 | snprintf(name, IFNAMSIZ, "%s-%d", tp->dev->name, irq_num); | |
8602 | name[IFNAMSIZ-1] = 0; | |
8603 | } | |
fcfa0a32 | 8604 | |
679563f4 | 8605 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI_OR_MSIX) { |
fcfa0a32 MC |
8606 | fn = tg3_msi; |
8607 | if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI) | |
8608 | fn = tg3_msi_1shot; | |
1fb9df5d | 8609 | flags = IRQF_SAMPLE_RANDOM; |
fcfa0a32 MC |
8610 | } else { |
8611 | fn = tg3_interrupt; | |
8612 | if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) | |
8613 | fn = tg3_interrupt_tagged; | |
1fb9df5d | 8614 | flags = IRQF_SHARED | IRQF_SAMPLE_RANDOM; |
fcfa0a32 | 8615 | } |
4f125f42 MC |
8616 | |
8617 | return request_irq(tnapi->irq_vec, fn, flags, name, tnapi); | |
fcfa0a32 MC |
8618 | } |
8619 | ||
7938109f MC |
8620 | static int tg3_test_interrupt(struct tg3 *tp) |
8621 | { | |
09943a18 | 8622 | struct tg3_napi *tnapi = &tp->napi[0]; |
7938109f | 8623 | struct net_device *dev = tp->dev; |
b16250e3 | 8624 | int err, i, intr_ok = 0; |
f6eb9b1f | 8625 | u32 val; |
7938109f | 8626 | |
d4bc3927 MC |
8627 | if (!netif_running(dev)) |
8628 | return -ENODEV; | |
8629 | ||
7938109f MC |
8630 | tg3_disable_ints(tp); |
8631 | ||
4f125f42 | 8632 | free_irq(tnapi->irq_vec, tnapi); |
7938109f | 8633 | |
f6eb9b1f MC |
8634 | /* |
8635 | * Turn off MSI one shot mode. Otherwise this test has no | |
8636 | * observable way to know whether the interrupt was delivered. | |
8637 | */ | |
c885e824 | 8638 | if ((tp->tg3_flags3 & TG3_FLG3_5717_PLUS) && |
f6eb9b1f MC |
8639 | (tp->tg3_flags2 & TG3_FLG2_USING_MSI)) { |
8640 | val = tr32(MSGINT_MODE) | MSGINT_MODE_ONE_SHOT_DISABLE; | |
8641 | tw32(MSGINT_MODE, val); | |
8642 | } | |
8643 | ||
4f125f42 | 8644 | err = request_irq(tnapi->irq_vec, tg3_test_isr, |
09943a18 | 8645 | IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, tnapi); |
7938109f MC |
8646 | if (err) |
8647 | return err; | |
8648 | ||
898a56f8 | 8649 | tnapi->hw_status->status &= ~SD_STATUS_UPDATED; |
7938109f MC |
8650 | tg3_enable_ints(tp); |
8651 | ||
8652 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | | |
fd2ce37f | 8653 | tnapi->coal_now); |
7938109f MC |
8654 | |
8655 | for (i = 0; i < 5; i++) { | |
b16250e3 MC |
8656 | u32 int_mbox, misc_host_ctrl; |
8657 | ||
898a56f8 | 8658 | int_mbox = tr32_mailbox(tnapi->int_mbox); |
b16250e3 MC |
8659 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
8660 | ||
8661 | if ((int_mbox != 0) || | |
8662 | (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) { | |
8663 | intr_ok = 1; | |
7938109f | 8664 | break; |
b16250e3 MC |
8665 | } |
8666 | ||
7938109f MC |
8667 | msleep(10); |
8668 | } | |
8669 | ||
8670 | tg3_disable_ints(tp); | |
8671 | ||
4f125f42 | 8672 | free_irq(tnapi->irq_vec, tnapi); |
6aa20a22 | 8673 | |
4f125f42 | 8674 | err = tg3_request_irq(tp, 0); |
7938109f MC |
8675 | |
8676 | if (err) | |
8677 | return err; | |
8678 | ||
f6eb9b1f MC |
8679 | if (intr_ok) { |
8680 | /* Reenable MSI one shot mode. */ | |
c885e824 | 8681 | if ((tp->tg3_flags3 & TG3_FLG3_5717_PLUS) && |
f6eb9b1f MC |
8682 | (tp->tg3_flags2 & TG3_FLG2_USING_MSI)) { |
8683 | val = tr32(MSGINT_MODE) & ~MSGINT_MODE_ONE_SHOT_DISABLE; | |
8684 | tw32(MSGINT_MODE, val); | |
8685 | } | |
7938109f | 8686 | return 0; |
f6eb9b1f | 8687 | } |
7938109f MC |
8688 | |
8689 | return -EIO; | |
8690 | } | |
8691 | ||
8692 | /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is | |
8693 | * successfully restored | |
8694 | */ | |
8695 | static int tg3_test_msi(struct tg3 *tp) | |
8696 | { | |
7938109f MC |
8697 | int err; |
8698 | u16 pci_cmd; | |
8699 | ||
8700 | if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSI)) | |
8701 | return 0; | |
8702 | ||
8703 | /* Turn off SERR reporting in case MSI terminates with Master | |
8704 | * Abort. | |
8705 | */ | |
8706 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); | |
8707 | pci_write_config_word(tp->pdev, PCI_COMMAND, | |
8708 | pci_cmd & ~PCI_COMMAND_SERR); | |
8709 | ||
8710 | err = tg3_test_interrupt(tp); | |
8711 | ||
8712 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); | |
8713 | ||
8714 | if (!err) | |
8715 | return 0; | |
8716 | ||
8717 | /* other failures */ | |
8718 | if (err != -EIO) | |
8719 | return err; | |
8720 | ||
8721 | /* MSI test failed, go back to INTx mode */ | |
5129c3a3 MC |
8722 | netdev_warn(tp->dev, "No interrupt was generated using MSI. Switching " |
8723 | "to INTx mode. Please report this failure to the PCI " | |
8724 | "maintainer and include system chipset information\n"); | |
7938109f | 8725 | |
4f125f42 | 8726 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
09943a18 | 8727 | |
7938109f MC |
8728 | pci_disable_msi(tp->pdev); |
8729 | ||
8730 | tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI; | |
dc8bf1b1 | 8731 | tp->napi[0].irq_vec = tp->pdev->irq; |
7938109f | 8732 | |
4f125f42 | 8733 | err = tg3_request_irq(tp, 0); |
7938109f MC |
8734 | if (err) |
8735 | return err; | |
8736 | ||
8737 | /* Need to reset the chip because the MSI cycle may have terminated | |
8738 | * with Master Abort. | |
8739 | */ | |
f47c11ee | 8740 | tg3_full_lock(tp, 1); |
7938109f | 8741 | |
944d980e | 8742 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
8e7a22e3 | 8743 | err = tg3_init_hw(tp, 1); |
7938109f | 8744 | |
f47c11ee | 8745 | tg3_full_unlock(tp); |
7938109f MC |
8746 | |
8747 | if (err) | |
4f125f42 | 8748 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
7938109f MC |
8749 | |
8750 | return err; | |
8751 | } | |
8752 | ||
9e9fd12d MC |
8753 | static int tg3_request_firmware(struct tg3 *tp) |
8754 | { | |
8755 | const __be32 *fw_data; | |
8756 | ||
8757 | if (request_firmware(&tp->fw, tp->fw_needed, &tp->pdev->dev)) { | |
05dbe005 JP |
8758 | netdev_err(tp->dev, "Failed to load firmware \"%s\"\n", |
8759 | tp->fw_needed); | |
9e9fd12d MC |
8760 | return -ENOENT; |
8761 | } | |
8762 | ||
8763 | fw_data = (void *)tp->fw->data; | |
8764 | ||
8765 | /* Firmware blob starts with version numbers, followed by | |
8766 | * start address and _full_ length including BSS sections | |
8767 | * (which must be longer than the actual data, of course | |
8768 | */ | |
8769 | ||
8770 | tp->fw_len = be32_to_cpu(fw_data[2]); /* includes bss */ | |
8771 | if (tp->fw_len < (tp->fw->size - 12)) { | |
05dbe005 JP |
8772 | netdev_err(tp->dev, "bogus length %d in \"%s\"\n", |
8773 | tp->fw_len, tp->fw_needed); | |
9e9fd12d MC |
8774 | release_firmware(tp->fw); |
8775 | tp->fw = NULL; | |
8776 | return -EINVAL; | |
8777 | } | |
8778 | ||
8779 | /* We no longer need firmware; we have it. */ | |
8780 | tp->fw_needed = NULL; | |
8781 | return 0; | |
8782 | } | |
8783 | ||
679563f4 MC |
8784 | static bool tg3_enable_msix(struct tg3 *tp) |
8785 | { | |
8786 | int i, rc, cpus = num_online_cpus(); | |
8787 | struct msix_entry msix_ent[tp->irq_max]; | |
8788 | ||
8789 | if (cpus == 1) | |
8790 | /* Just fallback to the simpler MSI mode. */ | |
8791 | return false; | |
8792 | ||
8793 | /* | |
8794 | * We want as many rx rings enabled as there are cpus. | |
8795 | * The first MSIX vector only deals with link interrupts, etc, | |
8796 | * so we add one to the number of vectors we are requesting. | |
8797 | */ | |
8798 | tp->irq_cnt = min_t(unsigned, cpus + 1, tp->irq_max); | |
8799 | ||
8800 | for (i = 0; i < tp->irq_max; i++) { | |
8801 | msix_ent[i].entry = i; | |
8802 | msix_ent[i].vector = 0; | |
8803 | } | |
8804 | ||
8805 | rc = pci_enable_msix(tp->pdev, msix_ent, tp->irq_cnt); | |
2430b031 MC |
8806 | if (rc < 0) { |
8807 | return false; | |
8808 | } else if (rc != 0) { | |
679563f4 MC |
8809 | if (pci_enable_msix(tp->pdev, msix_ent, rc)) |
8810 | return false; | |
05dbe005 JP |
8811 | netdev_notice(tp->dev, "Requested %d MSI-X vectors, received %d\n", |
8812 | tp->irq_cnt, rc); | |
679563f4 MC |
8813 | tp->irq_cnt = rc; |
8814 | } | |
8815 | ||
8816 | for (i = 0; i < tp->irq_max; i++) | |
8817 | tp->napi[i].irq_vec = msix_ent[i].vector; | |
8818 | ||
2430b031 MC |
8819 | tp->dev->real_num_tx_queues = 1; |
8820 | if (tp->irq_cnt > 1) { | |
8821 | tp->tg3_flags3 |= TG3_FLG3_ENABLE_RSS; | |
8822 | ||
a50d0796 MC |
8823 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
8824 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) { | |
2430b031 MC |
8825 | tp->tg3_flags3 |= TG3_FLG3_ENABLE_TSS; |
8826 | tp->dev->real_num_tx_queues = tp->irq_cnt - 1; | |
8827 | } | |
8828 | } | |
fe5f5787 | 8829 | |
679563f4 MC |
8830 | return true; |
8831 | } | |
8832 | ||
07b0173c MC |
8833 | static void tg3_ints_init(struct tg3 *tp) |
8834 | { | |
679563f4 MC |
8835 | if ((tp->tg3_flags & TG3_FLAG_SUPPORT_MSI_OR_MSIX) && |
8836 | !(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)) { | |
07b0173c MC |
8837 | /* All MSI supporting chips should support tagged |
8838 | * status. Assert that this is the case. | |
8839 | */ | |
5129c3a3 MC |
8840 | netdev_warn(tp->dev, |
8841 | "MSI without TAGGED_STATUS? Not using MSI\n"); | |
679563f4 | 8842 | goto defcfg; |
07b0173c | 8843 | } |
4f125f42 | 8844 | |
679563f4 MC |
8845 | if ((tp->tg3_flags & TG3_FLAG_SUPPORT_MSIX) && tg3_enable_msix(tp)) |
8846 | tp->tg3_flags2 |= TG3_FLG2_USING_MSIX; | |
8847 | else if ((tp->tg3_flags & TG3_FLAG_SUPPORT_MSI) && | |
8848 | pci_enable_msi(tp->pdev) == 0) | |
8849 | tp->tg3_flags2 |= TG3_FLG2_USING_MSI; | |
8850 | ||
8851 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI_OR_MSIX) { | |
8852 | u32 msi_mode = tr32(MSGINT_MODE); | |
baf8a94a MC |
8853 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSIX) |
8854 | msi_mode |= MSGINT_MODE_MULTIVEC_EN; | |
679563f4 MC |
8855 | tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE); |
8856 | } | |
8857 | defcfg: | |
8858 | if (!(tp->tg3_flags2 & TG3_FLG2_USING_MSIX)) { | |
8859 | tp->irq_cnt = 1; | |
8860 | tp->napi[0].irq_vec = tp->pdev->irq; | |
fe5f5787 | 8861 | tp->dev->real_num_tx_queues = 1; |
679563f4 | 8862 | } |
07b0173c MC |
8863 | } |
8864 | ||
8865 | static void tg3_ints_fini(struct tg3 *tp) | |
8866 | { | |
679563f4 MC |
8867 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSIX) |
8868 | pci_disable_msix(tp->pdev); | |
8869 | else if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) | |
8870 | pci_disable_msi(tp->pdev); | |
8871 | tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI_OR_MSIX; | |
774ee752 | 8872 | tp->tg3_flags3 &= ~(TG3_FLG3_ENABLE_RSS | TG3_FLG3_ENABLE_TSS); |
07b0173c MC |
8873 | } |
8874 | ||
1da177e4 LT |
8875 | static int tg3_open(struct net_device *dev) |
8876 | { | |
8877 | struct tg3 *tp = netdev_priv(dev); | |
4f125f42 | 8878 | int i, err; |
1da177e4 | 8879 | |
9e9fd12d MC |
8880 | if (tp->fw_needed) { |
8881 | err = tg3_request_firmware(tp); | |
8882 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) { | |
8883 | if (err) | |
8884 | return err; | |
8885 | } else if (err) { | |
05dbe005 | 8886 | netdev_warn(tp->dev, "TSO capability disabled\n"); |
9e9fd12d MC |
8887 | tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE; |
8888 | } else if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) { | |
05dbe005 | 8889 | netdev_notice(tp->dev, "TSO capability restored\n"); |
9e9fd12d MC |
8890 | tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE; |
8891 | } | |
8892 | } | |
8893 | ||
c49a1561 MC |
8894 | netif_carrier_off(tp->dev); |
8895 | ||
bc1c7567 | 8896 | err = tg3_set_power_state(tp, PCI_D0); |
2f751b67 | 8897 | if (err) |
bc1c7567 | 8898 | return err; |
2f751b67 MC |
8899 | |
8900 | tg3_full_lock(tp, 0); | |
bc1c7567 | 8901 | |
1da177e4 LT |
8902 | tg3_disable_ints(tp); |
8903 | tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE; | |
8904 | ||
f47c11ee | 8905 | tg3_full_unlock(tp); |
1da177e4 | 8906 | |
679563f4 MC |
8907 | /* |
8908 | * Setup interrupts first so we know how | |
8909 | * many NAPI resources to allocate | |
8910 | */ | |
8911 | tg3_ints_init(tp); | |
8912 | ||
1da177e4 LT |
8913 | /* The placement of this call is tied |
8914 | * to the setup and use of Host TX descriptors. | |
8915 | */ | |
8916 | err = tg3_alloc_consistent(tp); | |
8917 | if (err) | |
679563f4 | 8918 | goto err_out1; |
88b06bc2 | 8919 | |
fed97810 | 8920 | tg3_napi_enable(tp); |
1da177e4 | 8921 | |
4f125f42 MC |
8922 | for (i = 0; i < tp->irq_cnt; i++) { |
8923 | struct tg3_napi *tnapi = &tp->napi[i]; | |
8924 | err = tg3_request_irq(tp, i); | |
8925 | if (err) { | |
8926 | for (i--; i >= 0; i--) | |
8927 | free_irq(tnapi->irq_vec, tnapi); | |
8928 | break; | |
8929 | } | |
8930 | } | |
1da177e4 | 8931 | |
07b0173c | 8932 | if (err) |
679563f4 | 8933 | goto err_out2; |
bea3348e | 8934 | |
f47c11ee | 8935 | tg3_full_lock(tp, 0); |
1da177e4 | 8936 | |
8e7a22e3 | 8937 | err = tg3_init_hw(tp, 1); |
1da177e4 | 8938 | if (err) { |
944d980e | 8939 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
1da177e4 LT |
8940 | tg3_free_rings(tp); |
8941 | } else { | |
fac9b83e DM |
8942 | if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) |
8943 | tp->timer_offset = HZ; | |
8944 | else | |
8945 | tp->timer_offset = HZ / 10; | |
8946 | ||
8947 | BUG_ON(tp->timer_offset > HZ); | |
8948 | tp->timer_counter = tp->timer_multiplier = | |
8949 | (HZ / tp->timer_offset); | |
8950 | tp->asf_counter = tp->asf_multiplier = | |
28fbef78 | 8951 | ((HZ / tp->timer_offset) * 2); |
1da177e4 LT |
8952 | |
8953 | init_timer(&tp->timer); | |
8954 | tp->timer.expires = jiffies + tp->timer_offset; | |
8955 | tp->timer.data = (unsigned long) tp; | |
8956 | tp->timer.function = tg3_timer; | |
1da177e4 LT |
8957 | } |
8958 | ||
f47c11ee | 8959 | tg3_full_unlock(tp); |
1da177e4 | 8960 | |
07b0173c | 8961 | if (err) |
679563f4 | 8962 | goto err_out3; |
1da177e4 | 8963 | |
7938109f MC |
8964 | if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) { |
8965 | err = tg3_test_msi(tp); | |
fac9b83e | 8966 | |
7938109f | 8967 | if (err) { |
f47c11ee | 8968 | tg3_full_lock(tp, 0); |
944d980e | 8969 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
7938109f | 8970 | tg3_free_rings(tp); |
f47c11ee | 8971 | tg3_full_unlock(tp); |
7938109f | 8972 | |
679563f4 | 8973 | goto err_out2; |
7938109f | 8974 | } |
fcfa0a32 | 8975 | |
c885e824 MC |
8976 | if (!(tp->tg3_flags3 & TG3_FLG3_5717_PLUS) && |
8977 | (tp->tg3_flags2 & TG3_FLG2_USING_MSI)) { | |
f6eb9b1f | 8978 | u32 val = tr32(PCIE_TRANSACTION_CFG); |
fcfa0a32 | 8979 | |
f6eb9b1f MC |
8980 | tw32(PCIE_TRANSACTION_CFG, |
8981 | val | PCIE_TRANS_CFG_1SHOT_MSI); | |
fcfa0a32 | 8982 | } |
7938109f MC |
8983 | } |
8984 | ||
b02fd9e3 MC |
8985 | tg3_phy_start(tp); |
8986 | ||
f47c11ee | 8987 | tg3_full_lock(tp, 0); |
1da177e4 | 8988 | |
7938109f MC |
8989 | add_timer(&tp->timer); |
8990 | tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; | |
1da177e4 LT |
8991 | tg3_enable_ints(tp); |
8992 | ||
f47c11ee | 8993 | tg3_full_unlock(tp); |
1da177e4 | 8994 | |
fe5f5787 | 8995 | netif_tx_start_all_queues(dev); |
1da177e4 LT |
8996 | |
8997 | return 0; | |
07b0173c | 8998 | |
679563f4 | 8999 | err_out3: |
4f125f42 MC |
9000 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
9001 | struct tg3_napi *tnapi = &tp->napi[i]; | |
9002 | free_irq(tnapi->irq_vec, tnapi); | |
9003 | } | |
07b0173c | 9004 | |
679563f4 | 9005 | err_out2: |
fed97810 | 9006 | tg3_napi_disable(tp); |
07b0173c | 9007 | tg3_free_consistent(tp); |
679563f4 MC |
9008 | |
9009 | err_out1: | |
9010 | tg3_ints_fini(tp); | |
07b0173c | 9011 | return err; |
1da177e4 LT |
9012 | } |
9013 | ||
511d2224 ED |
9014 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *, |
9015 | struct rtnl_link_stats64 *); | |
1da177e4 LT |
9016 | static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *); |
9017 | ||
9018 | static int tg3_close(struct net_device *dev) | |
9019 | { | |
4f125f42 | 9020 | int i; |
1da177e4 LT |
9021 | struct tg3 *tp = netdev_priv(dev); |
9022 | ||
fed97810 | 9023 | tg3_napi_disable(tp); |
28e53bdd | 9024 | cancel_work_sync(&tp->reset_task); |
7faa006f | 9025 | |
fe5f5787 | 9026 | netif_tx_stop_all_queues(dev); |
1da177e4 LT |
9027 | |
9028 | del_timer_sync(&tp->timer); | |
9029 | ||
24bb4fb6 MC |
9030 | tg3_phy_stop(tp); |
9031 | ||
f47c11ee | 9032 | tg3_full_lock(tp, 1); |
1da177e4 LT |
9033 | |
9034 | tg3_disable_ints(tp); | |
9035 | ||
944d980e | 9036 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
1da177e4 | 9037 | tg3_free_rings(tp); |
5cf64b8a | 9038 | tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE; |
1da177e4 | 9039 | |
f47c11ee | 9040 | tg3_full_unlock(tp); |
1da177e4 | 9041 | |
4f125f42 MC |
9042 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
9043 | struct tg3_napi *tnapi = &tp->napi[i]; | |
9044 | free_irq(tnapi->irq_vec, tnapi); | |
9045 | } | |
07b0173c MC |
9046 | |
9047 | tg3_ints_fini(tp); | |
1da177e4 | 9048 | |
511d2224 ED |
9049 | tg3_get_stats64(tp->dev, &tp->net_stats_prev); |
9050 | ||
1da177e4 LT |
9051 | memcpy(&tp->estats_prev, tg3_get_estats(tp), |
9052 | sizeof(tp->estats_prev)); | |
9053 | ||
9054 | tg3_free_consistent(tp); | |
9055 | ||
bc1c7567 MC |
9056 | tg3_set_power_state(tp, PCI_D3hot); |
9057 | ||
9058 | netif_carrier_off(tp->dev); | |
9059 | ||
1da177e4 LT |
9060 | return 0; |
9061 | } | |
9062 | ||
511d2224 | 9063 | static inline u64 get_stat64(tg3_stat64_t *val) |
816f8b86 SB |
9064 | { |
9065 | return ((u64)val->high << 32) | ((u64)val->low); | |
9066 | } | |
9067 | ||
511d2224 | 9068 | static u64 calc_crc_errors(struct tg3 *tp) |
1da177e4 LT |
9069 | { |
9070 | struct tg3_hw_stats *hw_stats = tp->hw_stats; | |
9071 | ||
f07e9af3 | 9072 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
1da177e4 LT |
9073 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || |
9074 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { | |
1da177e4 LT |
9075 | u32 val; |
9076 | ||
f47c11ee | 9077 | spin_lock_bh(&tp->lock); |
569a5df8 MC |
9078 | if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) { |
9079 | tg3_writephy(tp, MII_TG3_TEST1, | |
9080 | val | MII_TG3_TEST1_CRC_EN); | |
f08aa1a8 | 9081 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &val); |
1da177e4 LT |
9082 | } else |
9083 | val = 0; | |
f47c11ee | 9084 | spin_unlock_bh(&tp->lock); |
1da177e4 LT |
9085 | |
9086 | tp->phy_crc_errors += val; | |
9087 | ||
9088 | return tp->phy_crc_errors; | |
9089 | } | |
9090 | ||
9091 | return get_stat64(&hw_stats->rx_fcs_errors); | |
9092 | } | |
9093 | ||
9094 | #define ESTAT_ADD(member) \ | |
9095 | estats->member = old_estats->member + \ | |
511d2224 | 9096 | get_stat64(&hw_stats->member) |
1da177e4 LT |
9097 | |
9098 | static struct tg3_ethtool_stats *tg3_get_estats(struct tg3 *tp) | |
9099 | { | |
9100 | struct tg3_ethtool_stats *estats = &tp->estats; | |
9101 | struct tg3_ethtool_stats *old_estats = &tp->estats_prev; | |
9102 | struct tg3_hw_stats *hw_stats = tp->hw_stats; | |
9103 | ||
9104 | if (!hw_stats) | |
9105 | return old_estats; | |
9106 | ||
9107 | ESTAT_ADD(rx_octets); | |
9108 | ESTAT_ADD(rx_fragments); | |
9109 | ESTAT_ADD(rx_ucast_packets); | |
9110 | ESTAT_ADD(rx_mcast_packets); | |
9111 | ESTAT_ADD(rx_bcast_packets); | |
9112 | ESTAT_ADD(rx_fcs_errors); | |
9113 | ESTAT_ADD(rx_align_errors); | |
9114 | ESTAT_ADD(rx_xon_pause_rcvd); | |
9115 | ESTAT_ADD(rx_xoff_pause_rcvd); | |
9116 | ESTAT_ADD(rx_mac_ctrl_rcvd); | |
9117 | ESTAT_ADD(rx_xoff_entered); | |
9118 | ESTAT_ADD(rx_frame_too_long_errors); | |
9119 | ESTAT_ADD(rx_jabbers); | |
9120 | ESTAT_ADD(rx_undersize_packets); | |
9121 | ESTAT_ADD(rx_in_length_errors); | |
9122 | ESTAT_ADD(rx_out_length_errors); | |
9123 | ESTAT_ADD(rx_64_or_less_octet_packets); | |
9124 | ESTAT_ADD(rx_65_to_127_octet_packets); | |
9125 | ESTAT_ADD(rx_128_to_255_octet_packets); | |
9126 | ESTAT_ADD(rx_256_to_511_octet_packets); | |
9127 | ESTAT_ADD(rx_512_to_1023_octet_packets); | |
9128 | ESTAT_ADD(rx_1024_to_1522_octet_packets); | |
9129 | ESTAT_ADD(rx_1523_to_2047_octet_packets); | |
9130 | ESTAT_ADD(rx_2048_to_4095_octet_packets); | |
9131 | ESTAT_ADD(rx_4096_to_8191_octet_packets); | |
9132 | ESTAT_ADD(rx_8192_to_9022_octet_packets); | |
9133 | ||
9134 | ESTAT_ADD(tx_octets); | |
9135 | ESTAT_ADD(tx_collisions); | |
9136 | ESTAT_ADD(tx_xon_sent); | |
9137 | ESTAT_ADD(tx_xoff_sent); | |
9138 | ESTAT_ADD(tx_flow_control); | |
9139 | ESTAT_ADD(tx_mac_errors); | |
9140 | ESTAT_ADD(tx_single_collisions); | |
9141 | ESTAT_ADD(tx_mult_collisions); | |
9142 | ESTAT_ADD(tx_deferred); | |
9143 | ESTAT_ADD(tx_excessive_collisions); | |
9144 | ESTAT_ADD(tx_late_collisions); | |
9145 | ESTAT_ADD(tx_collide_2times); | |
9146 | ESTAT_ADD(tx_collide_3times); | |
9147 | ESTAT_ADD(tx_collide_4times); | |
9148 | ESTAT_ADD(tx_collide_5times); | |
9149 | ESTAT_ADD(tx_collide_6times); | |
9150 | ESTAT_ADD(tx_collide_7times); | |
9151 | ESTAT_ADD(tx_collide_8times); | |
9152 | ESTAT_ADD(tx_collide_9times); | |
9153 | ESTAT_ADD(tx_collide_10times); | |
9154 | ESTAT_ADD(tx_collide_11times); | |
9155 | ESTAT_ADD(tx_collide_12times); | |
9156 | ESTAT_ADD(tx_collide_13times); | |
9157 | ESTAT_ADD(tx_collide_14times); | |
9158 | ESTAT_ADD(tx_collide_15times); | |
9159 | ESTAT_ADD(tx_ucast_packets); | |
9160 | ESTAT_ADD(tx_mcast_packets); | |
9161 | ESTAT_ADD(tx_bcast_packets); | |
9162 | ESTAT_ADD(tx_carrier_sense_errors); | |
9163 | ESTAT_ADD(tx_discards); | |
9164 | ESTAT_ADD(tx_errors); | |
9165 | ||
9166 | ESTAT_ADD(dma_writeq_full); | |
9167 | ESTAT_ADD(dma_write_prioq_full); | |
9168 | ESTAT_ADD(rxbds_empty); | |
9169 | ESTAT_ADD(rx_discards); | |
9170 | ESTAT_ADD(rx_errors); | |
9171 | ESTAT_ADD(rx_threshold_hit); | |
9172 | ||
9173 | ESTAT_ADD(dma_readq_full); | |
9174 | ESTAT_ADD(dma_read_prioq_full); | |
9175 | ESTAT_ADD(tx_comp_queue_full); | |
9176 | ||
9177 | ESTAT_ADD(ring_set_send_prod_index); | |
9178 | ESTAT_ADD(ring_status_update); | |
9179 | ESTAT_ADD(nic_irqs); | |
9180 | ESTAT_ADD(nic_avoided_irqs); | |
9181 | ESTAT_ADD(nic_tx_threshold_hit); | |
9182 | ||
9183 | return estats; | |
9184 | } | |
9185 | ||
511d2224 ED |
9186 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *dev, |
9187 | struct rtnl_link_stats64 *stats) | |
1da177e4 LT |
9188 | { |
9189 | struct tg3 *tp = netdev_priv(dev); | |
511d2224 | 9190 | struct rtnl_link_stats64 *old_stats = &tp->net_stats_prev; |
1da177e4 LT |
9191 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
9192 | ||
9193 | if (!hw_stats) | |
9194 | return old_stats; | |
9195 | ||
9196 | stats->rx_packets = old_stats->rx_packets + | |
9197 | get_stat64(&hw_stats->rx_ucast_packets) + | |
9198 | get_stat64(&hw_stats->rx_mcast_packets) + | |
9199 | get_stat64(&hw_stats->rx_bcast_packets); | |
6aa20a22 | 9200 | |
1da177e4 LT |
9201 | stats->tx_packets = old_stats->tx_packets + |
9202 | get_stat64(&hw_stats->tx_ucast_packets) + | |
9203 | get_stat64(&hw_stats->tx_mcast_packets) + | |
9204 | get_stat64(&hw_stats->tx_bcast_packets); | |
9205 | ||
9206 | stats->rx_bytes = old_stats->rx_bytes + | |
9207 | get_stat64(&hw_stats->rx_octets); | |
9208 | stats->tx_bytes = old_stats->tx_bytes + | |
9209 | get_stat64(&hw_stats->tx_octets); | |
9210 | ||
9211 | stats->rx_errors = old_stats->rx_errors + | |
4f63b877 | 9212 | get_stat64(&hw_stats->rx_errors); |
1da177e4 LT |
9213 | stats->tx_errors = old_stats->tx_errors + |
9214 | get_stat64(&hw_stats->tx_errors) + | |
9215 | get_stat64(&hw_stats->tx_mac_errors) + | |
9216 | get_stat64(&hw_stats->tx_carrier_sense_errors) + | |
9217 | get_stat64(&hw_stats->tx_discards); | |
9218 | ||
9219 | stats->multicast = old_stats->multicast + | |
9220 | get_stat64(&hw_stats->rx_mcast_packets); | |
9221 | stats->collisions = old_stats->collisions + | |
9222 | get_stat64(&hw_stats->tx_collisions); | |
9223 | ||
9224 | stats->rx_length_errors = old_stats->rx_length_errors + | |
9225 | get_stat64(&hw_stats->rx_frame_too_long_errors) + | |
9226 | get_stat64(&hw_stats->rx_undersize_packets); | |
9227 | ||
9228 | stats->rx_over_errors = old_stats->rx_over_errors + | |
9229 | get_stat64(&hw_stats->rxbds_empty); | |
9230 | stats->rx_frame_errors = old_stats->rx_frame_errors + | |
9231 | get_stat64(&hw_stats->rx_align_errors); | |
9232 | stats->tx_aborted_errors = old_stats->tx_aborted_errors + | |
9233 | get_stat64(&hw_stats->tx_discards); | |
9234 | stats->tx_carrier_errors = old_stats->tx_carrier_errors + | |
9235 | get_stat64(&hw_stats->tx_carrier_sense_errors); | |
9236 | ||
9237 | stats->rx_crc_errors = old_stats->rx_crc_errors + | |
9238 | calc_crc_errors(tp); | |
9239 | ||
4f63b877 JL |
9240 | stats->rx_missed_errors = old_stats->rx_missed_errors + |
9241 | get_stat64(&hw_stats->rx_discards); | |
9242 | ||
1da177e4 LT |
9243 | return stats; |
9244 | } | |
9245 | ||
9246 | static inline u32 calc_crc(unsigned char *buf, int len) | |
9247 | { | |
9248 | u32 reg; | |
9249 | u32 tmp; | |
9250 | int j, k; | |
9251 | ||
9252 | reg = 0xffffffff; | |
9253 | ||
9254 | for (j = 0; j < len; j++) { | |
9255 | reg ^= buf[j]; | |
9256 | ||
9257 | for (k = 0; k < 8; k++) { | |
9258 | tmp = reg & 0x01; | |
9259 | ||
9260 | reg >>= 1; | |
9261 | ||
859a5887 | 9262 | if (tmp) |
1da177e4 | 9263 | reg ^= 0xedb88320; |
1da177e4 LT |
9264 | } |
9265 | } | |
9266 | ||
9267 | return ~reg; | |
9268 | } | |
9269 | ||
9270 | static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all) | |
9271 | { | |
9272 | /* accept or reject all multicast frames */ | |
9273 | tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0); | |
9274 | tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0); | |
9275 | tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0); | |
9276 | tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0); | |
9277 | } | |
9278 | ||
9279 | static void __tg3_set_rx_mode(struct net_device *dev) | |
9280 | { | |
9281 | struct tg3 *tp = netdev_priv(dev); | |
9282 | u32 rx_mode; | |
9283 | ||
9284 | rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC | | |
9285 | RX_MODE_KEEP_VLAN_TAG); | |
9286 | ||
9287 | /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG | |
9288 | * flag clear. | |
9289 | */ | |
9290 | #if TG3_VLAN_TAG_USED | |
9291 | if (!tp->vlgrp && | |
9292 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) | |
9293 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; | |
9294 | #else | |
9295 | /* By definition, VLAN is disabled always in this | |
9296 | * case. | |
9297 | */ | |
9298 | if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) | |
9299 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; | |
9300 | #endif | |
9301 | ||
9302 | if (dev->flags & IFF_PROMISC) { | |
9303 | /* Promiscuous mode. */ | |
9304 | rx_mode |= RX_MODE_PROMISC; | |
9305 | } else if (dev->flags & IFF_ALLMULTI) { | |
9306 | /* Accept all multicast. */ | |
de6f31eb | 9307 | tg3_set_multi(tp, 1); |
4cd24eaf | 9308 | } else if (netdev_mc_empty(dev)) { |
1da177e4 | 9309 | /* Reject all multicast. */ |
de6f31eb | 9310 | tg3_set_multi(tp, 0); |
1da177e4 LT |
9311 | } else { |
9312 | /* Accept one or more multicast(s). */ | |
22bedad3 | 9313 | struct netdev_hw_addr *ha; |
1da177e4 LT |
9314 | u32 mc_filter[4] = { 0, }; |
9315 | u32 regidx; | |
9316 | u32 bit; | |
9317 | u32 crc; | |
9318 | ||
22bedad3 JP |
9319 | netdev_for_each_mc_addr(ha, dev) { |
9320 | crc = calc_crc(ha->addr, ETH_ALEN); | |
1da177e4 LT |
9321 | bit = ~crc & 0x7f; |
9322 | regidx = (bit & 0x60) >> 5; | |
9323 | bit &= 0x1f; | |
9324 | mc_filter[regidx] |= (1 << bit); | |
9325 | } | |
9326 | ||
9327 | tw32(MAC_HASH_REG_0, mc_filter[0]); | |
9328 | tw32(MAC_HASH_REG_1, mc_filter[1]); | |
9329 | tw32(MAC_HASH_REG_2, mc_filter[2]); | |
9330 | tw32(MAC_HASH_REG_3, mc_filter[3]); | |
9331 | } | |
9332 | ||
9333 | if (rx_mode != tp->rx_mode) { | |
9334 | tp->rx_mode = rx_mode; | |
9335 | tw32_f(MAC_RX_MODE, rx_mode); | |
9336 | udelay(10); | |
9337 | } | |
9338 | } | |
9339 | ||
9340 | static void tg3_set_rx_mode(struct net_device *dev) | |
9341 | { | |
9342 | struct tg3 *tp = netdev_priv(dev); | |
9343 | ||
e75f7c90 MC |
9344 | if (!netif_running(dev)) |
9345 | return; | |
9346 | ||
f47c11ee | 9347 | tg3_full_lock(tp, 0); |
1da177e4 | 9348 | __tg3_set_rx_mode(dev); |
f47c11ee | 9349 | tg3_full_unlock(tp); |
1da177e4 LT |
9350 | } |
9351 | ||
9352 | #define TG3_REGDUMP_LEN (32 * 1024) | |
9353 | ||
9354 | static int tg3_get_regs_len(struct net_device *dev) | |
9355 | { | |
9356 | return TG3_REGDUMP_LEN; | |
9357 | } | |
9358 | ||
9359 | static void tg3_get_regs(struct net_device *dev, | |
9360 | struct ethtool_regs *regs, void *_p) | |
9361 | { | |
9362 | u32 *p = _p; | |
9363 | struct tg3 *tp = netdev_priv(dev); | |
9364 | u8 *orig_p = _p; | |
9365 | int i; | |
9366 | ||
9367 | regs->version = 0; | |
9368 | ||
9369 | memset(p, 0, TG3_REGDUMP_LEN); | |
9370 | ||
80096068 | 9371 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
bc1c7567 MC |
9372 | return; |
9373 | ||
f47c11ee | 9374 | tg3_full_lock(tp, 0); |
1da177e4 LT |
9375 | |
9376 | #define __GET_REG32(reg) (*(p)++ = tr32(reg)) | |
be98da6a | 9377 | #define GET_REG32_LOOP(base, len) \ |
1da177e4 LT |
9378 | do { p = (u32 *)(orig_p + (base)); \ |
9379 | for (i = 0; i < len; i += 4) \ | |
9380 | __GET_REG32((base) + i); \ | |
9381 | } while (0) | |
9382 | #define GET_REG32_1(reg) \ | |
9383 | do { p = (u32 *)(orig_p + (reg)); \ | |
9384 | __GET_REG32((reg)); \ | |
9385 | } while (0) | |
9386 | ||
9387 | GET_REG32_LOOP(TG3PCI_VENDOR, 0xb0); | |
9388 | GET_REG32_LOOP(MAILBOX_INTERRUPT_0, 0x200); | |
9389 | GET_REG32_LOOP(MAC_MODE, 0x4f0); | |
9390 | GET_REG32_LOOP(SNDDATAI_MODE, 0xe0); | |
9391 | GET_REG32_1(SNDDATAC_MODE); | |
9392 | GET_REG32_LOOP(SNDBDS_MODE, 0x80); | |
9393 | GET_REG32_LOOP(SNDBDI_MODE, 0x48); | |
9394 | GET_REG32_1(SNDBDC_MODE); | |
9395 | GET_REG32_LOOP(RCVLPC_MODE, 0x20); | |
9396 | GET_REG32_LOOP(RCVLPC_SELLST_BASE, 0x15c); | |
9397 | GET_REG32_LOOP(RCVDBDI_MODE, 0x0c); | |
9398 | GET_REG32_LOOP(RCVDBDI_JUMBO_BD, 0x3c); | |
9399 | GET_REG32_LOOP(RCVDBDI_BD_PROD_IDX_0, 0x44); | |
9400 | GET_REG32_1(RCVDCC_MODE); | |
9401 | GET_REG32_LOOP(RCVBDI_MODE, 0x20); | |
9402 | GET_REG32_LOOP(RCVCC_MODE, 0x14); | |
9403 | GET_REG32_LOOP(RCVLSC_MODE, 0x08); | |
9404 | GET_REG32_1(MBFREE_MODE); | |
9405 | GET_REG32_LOOP(HOSTCC_MODE, 0x100); | |
9406 | GET_REG32_LOOP(MEMARB_MODE, 0x10); | |
9407 | GET_REG32_LOOP(BUFMGR_MODE, 0x58); | |
9408 | GET_REG32_LOOP(RDMAC_MODE, 0x08); | |
9409 | GET_REG32_LOOP(WDMAC_MODE, 0x08); | |
091465d7 CE |
9410 | GET_REG32_1(RX_CPU_MODE); |
9411 | GET_REG32_1(RX_CPU_STATE); | |
9412 | GET_REG32_1(RX_CPU_PGMCTR); | |
9413 | GET_REG32_1(RX_CPU_HWBKPT); | |
9414 | GET_REG32_1(TX_CPU_MODE); | |
9415 | GET_REG32_1(TX_CPU_STATE); | |
9416 | GET_REG32_1(TX_CPU_PGMCTR); | |
1da177e4 LT |
9417 | GET_REG32_LOOP(GRCMBOX_INTERRUPT_0, 0x110); |
9418 | GET_REG32_LOOP(FTQ_RESET, 0x120); | |
9419 | GET_REG32_LOOP(MSGINT_MODE, 0x0c); | |
9420 | GET_REG32_1(DMAC_MODE); | |
9421 | GET_REG32_LOOP(GRC_MODE, 0x4c); | |
9422 | if (tp->tg3_flags & TG3_FLAG_NVRAM) | |
9423 | GET_REG32_LOOP(NVRAM_CMD, 0x24); | |
9424 | ||
9425 | #undef __GET_REG32 | |
9426 | #undef GET_REG32_LOOP | |
9427 | #undef GET_REG32_1 | |
9428 | ||
f47c11ee | 9429 | tg3_full_unlock(tp); |
1da177e4 LT |
9430 | } |
9431 | ||
9432 | static int tg3_get_eeprom_len(struct net_device *dev) | |
9433 | { | |
9434 | struct tg3 *tp = netdev_priv(dev); | |
9435 | ||
9436 | return tp->nvram_size; | |
9437 | } | |
9438 | ||
1da177e4 LT |
9439 | static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
9440 | { | |
9441 | struct tg3 *tp = netdev_priv(dev); | |
9442 | int ret; | |
9443 | u8 *pd; | |
b9fc7dc5 | 9444 | u32 i, offset, len, b_offset, b_count; |
a9dc529d | 9445 | __be32 val; |
1da177e4 | 9446 | |
df259d8c MC |
9447 | if (tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) |
9448 | return -EINVAL; | |
9449 | ||
80096068 | 9450 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
bc1c7567 MC |
9451 | return -EAGAIN; |
9452 | ||
1da177e4 LT |
9453 | offset = eeprom->offset; |
9454 | len = eeprom->len; | |
9455 | eeprom->len = 0; | |
9456 | ||
9457 | eeprom->magic = TG3_EEPROM_MAGIC; | |
9458 | ||
9459 | if (offset & 3) { | |
9460 | /* adjustments to start on required 4 byte boundary */ | |
9461 | b_offset = offset & 3; | |
9462 | b_count = 4 - b_offset; | |
9463 | if (b_count > len) { | |
9464 | /* i.e. offset=1 len=2 */ | |
9465 | b_count = len; | |
9466 | } | |
a9dc529d | 9467 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &val); |
1da177e4 LT |
9468 | if (ret) |
9469 | return ret; | |
be98da6a | 9470 | memcpy(data, ((char *)&val) + b_offset, b_count); |
1da177e4 LT |
9471 | len -= b_count; |
9472 | offset += b_count; | |
c6cdf436 | 9473 | eeprom->len += b_count; |
1da177e4 LT |
9474 | } |
9475 | ||
9476 | /* read bytes upto the last 4 byte boundary */ | |
9477 | pd = &data[eeprom->len]; | |
9478 | for (i = 0; i < (len - (len & 3)); i += 4) { | |
a9dc529d | 9479 | ret = tg3_nvram_read_be32(tp, offset + i, &val); |
1da177e4 LT |
9480 | if (ret) { |
9481 | eeprom->len += i; | |
9482 | return ret; | |
9483 | } | |
1da177e4 LT |
9484 | memcpy(pd + i, &val, 4); |
9485 | } | |
9486 | eeprom->len += i; | |
9487 | ||
9488 | if (len & 3) { | |
9489 | /* read last bytes not ending on 4 byte boundary */ | |
9490 | pd = &data[eeprom->len]; | |
9491 | b_count = len & 3; | |
9492 | b_offset = offset + len - b_count; | |
a9dc529d | 9493 | ret = tg3_nvram_read_be32(tp, b_offset, &val); |
1da177e4 LT |
9494 | if (ret) |
9495 | return ret; | |
b9fc7dc5 | 9496 | memcpy(pd, &val, b_count); |
1da177e4 LT |
9497 | eeprom->len += b_count; |
9498 | } | |
9499 | return 0; | |
9500 | } | |
9501 | ||
6aa20a22 | 9502 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf); |
1da177e4 LT |
9503 | |
9504 | static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) | |
9505 | { | |
9506 | struct tg3 *tp = netdev_priv(dev); | |
9507 | int ret; | |
b9fc7dc5 | 9508 | u32 offset, len, b_offset, odd_len; |
1da177e4 | 9509 | u8 *buf; |
a9dc529d | 9510 | __be32 start, end; |
1da177e4 | 9511 | |
80096068 | 9512 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
bc1c7567 MC |
9513 | return -EAGAIN; |
9514 | ||
df259d8c MC |
9515 | if ((tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) || |
9516 | eeprom->magic != TG3_EEPROM_MAGIC) | |
1da177e4 LT |
9517 | return -EINVAL; |
9518 | ||
9519 | offset = eeprom->offset; | |
9520 | len = eeprom->len; | |
9521 | ||
9522 | if ((b_offset = (offset & 3))) { | |
9523 | /* adjustments to start on required 4 byte boundary */ | |
a9dc529d | 9524 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &start); |
1da177e4 LT |
9525 | if (ret) |
9526 | return ret; | |
1da177e4 LT |
9527 | len += b_offset; |
9528 | offset &= ~3; | |
1c8594b4 MC |
9529 | if (len < 4) |
9530 | len = 4; | |
1da177e4 LT |
9531 | } |
9532 | ||
9533 | odd_len = 0; | |
1c8594b4 | 9534 | if (len & 3) { |
1da177e4 LT |
9535 | /* adjustments to end on required 4 byte boundary */ |
9536 | odd_len = 1; | |
9537 | len = (len + 3) & ~3; | |
a9dc529d | 9538 | ret = tg3_nvram_read_be32(tp, offset+len-4, &end); |
1da177e4 LT |
9539 | if (ret) |
9540 | return ret; | |
1da177e4 LT |
9541 | } |
9542 | ||
9543 | buf = data; | |
9544 | if (b_offset || odd_len) { | |
9545 | buf = kmalloc(len, GFP_KERNEL); | |
ab0049b4 | 9546 | if (!buf) |
1da177e4 LT |
9547 | return -ENOMEM; |
9548 | if (b_offset) | |
9549 | memcpy(buf, &start, 4); | |
9550 | if (odd_len) | |
9551 | memcpy(buf+len-4, &end, 4); | |
9552 | memcpy(buf + b_offset, data, eeprom->len); | |
9553 | } | |
9554 | ||
9555 | ret = tg3_nvram_write_block(tp, offset, len, buf); | |
9556 | ||
9557 | if (buf != data) | |
9558 | kfree(buf); | |
9559 | ||
9560 | return ret; | |
9561 | } | |
9562 | ||
9563 | static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) | |
9564 | { | |
b02fd9e3 MC |
9565 | struct tg3 *tp = netdev_priv(dev); |
9566 | ||
9567 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { | |
3f0e3ad7 | 9568 | struct phy_device *phydev; |
f07e9af3 | 9569 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 | 9570 | return -EAGAIN; |
3f0e3ad7 MC |
9571 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
9572 | return phy_ethtool_gset(phydev, cmd); | |
b02fd9e3 | 9573 | } |
6aa20a22 | 9574 | |
1da177e4 LT |
9575 | cmd->supported = (SUPPORTED_Autoneg); |
9576 | ||
f07e9af3 | 9577 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
1da177e4 LT |
9578 | cmd->supported |= (SUPPORTED_1000baseT_Half | |
9579 | SUPPORTED_1000baseT_Full); | |
9580 | ||
f07e9af3 | 9581 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
1da177e4 LT |
9582 | cmd->supported |= (SUPPORTED_100baseT_Half | |
9583 | SUPPORTED_100baseT_Full | | |
9584 | SUPPORTED_10baseT_Half | | |
9585 | SUPPORTED_10baseT_Full | | |
3bebab59 | 9586 | SUPPORTED_TP); |
ef348144 KK |
9587 | cmd->port = PORT_TP; |
9588 | } else { | |
1da177e4 | 9589 | cmd->supported |= SUPPORTED_FIBRE; |
ef348144 KK |
9590 | cmd->port = PORT_FIBRE; |
9591 | } | |
6aa20a22 | 9592 | |
1da177e4 LT |
9593 | cmd->advertising = tp->link_config.advertising; |
9594 | if (netif_running(dev)) { | |
9595 | cmd->speed = tp->link_config.active_speed; | |
9596 | cmd->duplex = tp->link_config.active_duplex; | |
9597 | } | |
882e9793 | 9598 | cmd->phy_address = tp->phy_addr; |
7e5856bd | 9599 | cmd->transceiver = XCVR_INTERNAL; |
1da177e4 LT |
9600 | cmd->autoneg = tp->link_config.autoneg; |
9601 | cmd->maxtxpkt = 0; | |
9602 | cmd->maxrxpkt = 0; | |
9603 | return 0; | |
9604 | } | |
6aa20a22 | 9605 | |
1da177e4 LT |
9606 | static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
9607 | { | |
9608 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 9609 | |
b02fd9e3 | 9610 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
3f0e3ad7 | 9611 | struct phy_device *phydev; |
f07e9af3 | 9612 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 | 9613 | return -EAGAIN; |
3f0e3ad7 MC |
9614 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
9615 | return phy_ethtool_sset(phydev, cmd); | |
b02fd9e3 MC |
9616 | } |
9617 | ||
7e5856bd MC |
9618 | if (cmd->autoneg != AUTONEG_ENABLE && |
9619 | cmd->autoneg != AUTONEG_DISABLE) | |
37ff238d | 9620 | return -EINVAL; |
7e5856bd MC |
9621 | |
9622 | if (cmd->autoneg == AUTONEG_DISABLE && | |
9623 | cmd->duplex != DUPLEX_FULL && | |
9624 | cmd->duplex != DUPLEX_HALF) | |
37ff238d | 9625 | return -EINVAL; |
1da177e4 | 9626 | |
7e5856bd MC |
9627 | if (cmd->autoneg == AUTONEG_ENABLE) { |
9628 | u32 mask = ADVERTISED_Autoneg | | |
9629 | ADVERTISED_Pause | | |
9630 | ADVERTISED_Asym_Pause; | |
9631 | ||
f07e9af3 | 9632 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
7e5856bd MC |
9633 | mask |= ADVERTISED_1000baseT_Half | |
9634 | ADVERTISED_1000baseT_Full; | |
9635 | ||
f07e9af3 | 9636 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
7e5856bd MC |
9637 | mask |= ADVERTISED_100baseT_Half | |
9638 | ADVERTISED_100baseT_Full | | |
9639 | ADVERTISED_10baseT_Half | | |
9640 | ADVERTISED_10baseT_Full | | |
9641 | ADVERTISED_TP; | |
9642 | else | |
9643 | mask |= ADVERTISED_FIBRE; | |
9644 | ||
9645 | if (cmd->advertising & ~mask) | |
9646 | return -EINVAL; | |
9647 | ||
9648 | mask &= (ADVERTISED_1000baseT_Half | | |
9649 | ADVERTISED_1000baseT_Full | | |
9650 | ADVERTISED_100baseT_Half | | |
9651 | ADVERTISED_100baseT_Full | | |
9652 | ADVERTISED_10baseT_Half | | |
9653 | ADVERTISED_10baseT_Full); | |
9654 | ||
9655 | cmd->advertising &= mask; | |
9656 | } else { | |
f07e9af3 | 9657 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) { |
7e5856bd MC |
9658 | if (cmd->speed != SPEED_1000) |
9659 | return -EINVAL; | |
9660 | ||
9661 | if (cmd->duplex != DUPLEX_FULL) | |
9662 | return -EINVAL; | |
9663 | } else { | |
9664 | if (cmd->speed != SPEED_100 && | |
9665 | cmd->speed != SPEED_10) | |
9666 | return -EINVAL; | |
9667 | } | |
9668 | } | |
9669 | ||
f47c11ee | 9670 | tg3_full_lock(tp, 0); |
1da177e4 LT |
9671 | |
9672 | tp->link_config.autoneg = cmd->autoneg; | |
9673 | if (cmd->autoneg == AUTONEG_ENABLE) { | |
405d8e5c AG |
9674 | tp->link_config.advertising = (cmd->advertising | |
9675 | ADVERTISED_Autoneg); | |
1da177e4 LT |
9676 | tp->link_config.speed = SPEED_INVALID; |
9677 | tp->link_config.duplex = DUPLEX_INVALID; | |
9678 | } else { | |
9679 | tp->link_config.advertising = 0; | |
9680 | tp->link_config.speed = cmd->speed; | |
9681 | tp->link_config.duplex = cmd->duplex; | |
b02fd9e3 | 9682 | } |
6aa20a22 | 9683 | |
24fcad6b MC |
9684 | tp->link_config.orig_speed = tp->link_config.speed; |
9685 | tp->link_config.orig_duplex = tp->link_config.duplex; | |
9686 | tp->link_config.orig_autoneg = tp->link_config.autoneg; | |
9687 | ||
1da177e4 LT |
9688 | if (netif_running(dev)) |
9689 | tg3_setup_phy(tp, 1); | |
9690 | ||
f47c11ee | 9691 | tg3_full_unlock(tp); |
6aa20a22 | 9692 | |
1da177e4 LT |
9693 | return 0; |
9694 | } | |
6aa20a22 | 9695 | |
1da177e4 LT |
9696 | static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
9697 | { | |
9698 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 9699 | |
1da177e4 LT |
9700 | strcpy(info->driver, DRV_MODULE_NAME); |
9701 | strcpy(info->version, DRV_MODULE_VERSION); | |
c4e6575c | 9702 | strcpy(info->fw_version, tp->fw_ver); |
1da177e4 LT |
9703 | strcpy(info->bus_info, pci_name(tp->pdev)); |
9704 | } | |
6aa20a22 | 9705 | |
1da177e4 LT |
9706 | static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
9707 | { | |
9708 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 9709 | |
12dac075 RW |
9710 | if ((tp->tg3_flags & TG3_FLAG_WOL_CAP) && |
9711 | device_can_wakeup(&tp->pdev->dev)) | |
a85feb8c GZ |
9712 | wol->supported = WAKE_MAGIC; |
9713 | else | |
9714 | wol->supported = 0; | |
1da177e4 | 9715 | wol->wolopts = 0; |
05ac4cb7 MC |
9716 | if ((tp->tg3_flags & TG3_FLAG_WOL_ENABLE) && |
9717 | device_can_wakeup(&tp->pdev->dev)) | |
1da177e4 LT |
9718 | wol->wolopts = WAKE_MAGIC; |
9719 | memset(&wol->sopass, 0, sizeof(wol->sopass)); | |
9720 | } | |
6aa20a22 | 9721 | |
1da177e4 LT |
9722 | static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
9723 | { | |
9724 | struct tg3 *tp = netdev_priv(dev); | |
12dac075 | 9725 | struct device *dp = &tp->pdev->dev; |
6aa20a22 | 9726 | |
1da177e4 LT |
9727 | if (wol->wolopts & ~WAKE_MAGIC) |
9728 | return -EINVAL; | |
9729 | if ((wol->wolopts & WAKE_MAGIC) && | |
12dac075 | 9730 | !((tp->tg3_flags & TG3_FLAG_WOL_CAP) && device_can_wakeup(dp))) |
1da177e4 | 9731 | return -EINVAL; |
6aa20a22 | 9732 | |
f47c11ee | 9733 | spin_lock_bh(&tp->lock); |
12dac075 | 9734 | if (wol->wolopts & WAKE_MAGIC) { |
1da177e4 | 9735 | tp->tg3_flags |= TG3_FLAG_WOL_ENABLE; |
12dac075 RW |
9736 | device_set_wakeup_enable(dp, true); |
9737 | } else { | |
1da177e4 | 9738 | tp->tg3_flags &= ~TG3_FLAG_WOL_ENABLE; |
12dac075 RW |
9739 | device_set_wakeup_enable(dp, false); |
9740 | } | |
f47c11ee | 9741 | spin_unlock_bh(&tp->lock); |
6aa20a22 | 9742 | |
1da177e4 LT |
9743 | return 0; |
9744 | } | |
6aa20a22 | 9745 | |
1da177e4 LT |
9746 | static u32 tg3_get_msglevel(struct net_device *dev) |
9747 | { | |
9748 | struct tg3 *tp = netdev_priv(dev); | |
9749 | return tp->msg_enable; | |
9750 | } | |
6aa20a22 | 9751 | |
1da177e4 LT |
9752 | static void tg3_set_msglevel(struct net_device *dev, u32 value) |
9753 | { | |
9754 | struct tg3 *tp = netdev_priv(dev); | |
9755 | tp->msg_enable = value; | |
9756 | } | |
6aa20a22 | 9757 | |
1da177e4 LT |
9758 | static int tg3_set_tso(struct net_device *dev, u32 value) |
9759 | { | |
9760 | struct tg3 *tp = netdev_priv(dev); | |
9761 | ||
9762 | if (!(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE)) { | |
9763 | if (value) | |
9764 | return -EINVAL; | |
9765 | return 0; | |
9766 | } | |
027455ad | 9767 | if ((dev->features & NETIF_F_IPV6_CSUM) && |
e849cdc3 MC |
9768 | ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) || |
9769 | (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3))) { | |
9936bcf6 | 9770 | if (value) { |
b0026624 | 9771 | dev->features |= NETIF_F_TSO6; |
e849cdc3 MC |
9772 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) || |
9773 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || | |
57e6983c MC |
9774 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
9775 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) || | |
321d32a0 | 9776 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
e849cdc3 | 9777 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) |
9936bcf6 MC |
9778 | dev->features |= NETIF_F_TSO_ECN; |
9779 | } else | |
9780 | dev->features &= ~(NETIF_F_TSO6 | NETIF_F_TSO_ECN); | |
b0026624 | 9781 | } |
1da177e4 LT |
9782 | return ethtool_op_set_tso(dev, value); |
9783 | } | |
6aa20a22 | 9784 | |
1da177e4 LT |
9785 | static int tg3_nway_reset(struct net_device *dev) |
9786 | { | |
9787 | struct tg3 *tp = netdev_priv(dev); | |
1da177e4 | 9788 | int r; |
6aa20a22 | 9789 | |
1da177e4 LT |
9790 | if (!netif_running(dev)) |
9791 | return -EAGAIN; | |
9792 | ||
f07e9af3 | 9793 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
c94e3941 MC |
9794 | return -EINVAL; |
9795 | ||
b02fd9e3 | 9796 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
f07e9af3 | 9797 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 | 9798 | return -EAGAIN; |
3f0e3ad7 | 9799 | r = phy_start_aneg(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
b02fd9e3 MC |
9800 | } else { |
9801 | u32 bmcr; | |
9802 | ||
9803 | spin_lock_bh(&tp->lock); | |
9804 | r = -EINVAL; | |
9805 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
9806 | if (!tg3_readphy(tp, MII_BMCR, &bmcr) && | |
9807 | ((bmcr & BMCR_ANENABLE) || | |
f07e9af3 | 9808 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT))) { |
b02fd9e3 MC |
9809 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART | |
9810 | BMCR_ANENABLE); | |
9811 | r = 0; | |
9812 | } | |
9813 | spin_unlock_bh(&tp->lock); | |
1da177e4 | 9814 | } |
6aa20a22 | 9815 | |
1da177e4 LT |
9816 | return r; |
9817 | } | |
6aa20a22 | 9818 | |
1da177e4 LT |
9819 | static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
9820 | { | |
9821 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 9822 | |
1da177e4 LT |
9823 | ering->rx_max_pending = TG3_RX_RING_SIZE - 1; |
9824 | ering->rx_mini_max_pending = 0; | |
4f81c32b MC |
9825 | if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) |
9826 | ering->rx_jumbo_max_pending = TG3_RX_JUMBO_RING_SIZE - 1; | |
9827 | else | |
9828 | ering->rx_jumbo_max_pending = 0; | |
9829 | ||
9830 | ering->tx_max_pending = TG3_TX_RING_SIZE - 1; | |
1da177e4 LT |
9831 | |
9832 | ering->rx_pending = tp->rx_pending; | |
9833 | ering->rx_mini_pending = 0; | |
4f81c32b MC |
9834 | if (tp->tg3_flags & TG3_FLAG_JUMBO_RING_ENABLE) |
9835 | ering->rx_jumbo_pending = tp->rx_jumbo_pending; | |
9836 | else | |
9837 | ering->rx_jumbo_pending = 0; | |
9838 | ||
f3f3f27e | 9839 | ering->tx_pending = tp->napi[0].tx_pending; |
1da177e4 | 9840 | } |
6aa20a22 | 9841 | |
1da177e4 LT |
9842 | static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
9843 | { | |
9844 | struct tg3 *tp = netdev_priv(dev); | |
646c9edd | 9845 | int i, irq_sync = 0, err = 0; |
6aa20a22 | 9846 | |
1da177e4 LT |
9847 | if ((ering->rx_pending > TG3_RX_RING_SIZE - 1) || |
9848 | (ering->rx_jumbo_pending > TG3_RX_JUMBO_RING_SIZE - 1) || | |
bc3a9254 MC |
9849 | (ering->tx_pending > TG3_TX_RING_SIZE - 1) || |
9850 | (ering->tx_pending <= MAX_SKB_FRAGS) || | |
7f62ad5d | 9851 | ((tp->tg3_flags2 & TG3_FLG2_TSO_BUG) && |
bc3a9254 | 9852 | (ering->tx_pending <= (MAX_SKB_FRAGS * 3)))) |
1da177e4 | 9853 | return -EINVAL; |
6aa20a22 | 9854 | |
bbe832c0 | 9855 | if (netif_running(dev)) { |
b02fd9e3 | 9856 | tg3_phy_stop(tp); |
1da177e4 | 9857 | tg3_netif_stop(tp); |
bbe832c0 MC |
9858 | irq_sync = 1; |
9859 | } | |
1da177e4 | 9860 | |
bbe832c0 | 9861 | tg3_full_lock(tp, irq_sync); |
6aa20a22 | 9862 | |
1da177e4 LT |
9863 | tp->rx_pending = ering->rx_pending; |
9864 | ||
9865 | if ((tp->tg3_flags2 & TG3_FLG2_MAX_RXPEND_64) && | |
9866 | tp->rx_pending > 63) | |
9867 | tp->rx_pending = 63; | |
9868 | tp->rx_jumbo_pending = ering->rx_jumbo_pending; | |
646c9edd MC |
9869 | |
9870 | for (i = 0; i < TG3_IRQ_MAX_VECS; i++) | |
9871 | tp->napi[i].tx_pending = ering->tx_pending; | |
1da177e4 LT |
9872 | |
9873 | if (netif_running(dev)) { | |
944d980e | 9874 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
b9ec6c1b MC |
9875 | err = tg3_restart_hw(tp, 1); |
9876 | if (!err) | |
9877 | tg3_netif_start(tp); | |
1da177e4 LT |
9878 | } |
9879 | ||
f47c11ee | 9880 | tg3_full_unlock(tp); |
6aa20a22 | 9881 | |
b02fd9e3 MC |
9882 | if (irq_sync && !err) |
9883 | tg3_phy_start(tp); | |
9884 | ||
b9ec6c1b | 9885 | return err; |
1da177e4 | 9886 | } |
6aa20a22 | 9887 | |
1da177e4 LT |
9888 | static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
9889 | { | |
9890 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 9891 | |
1da177e4 | 9892 | epause->autoneg = (tp->tg3_flags & TG3_FLAG_PAUSE_AUTONEG) != 0; |
8d018621 | 9893 | |
e18ce346 | 9894 | if (tp->link_config.active_flowctrl & FLOW_CTRL_RX) |
8d018621 MC |
9895 | epause->rx_pause = 1; |
9896 | else | |
9897 | epause->rx_pause = 0; | |
9898 | ||
e18ce346 | 9899 | if (tp->link_config.active_flowctrl & FLOW_CTRL_TX) |
8d018621 MC |
9900 | epause->tx_pause = 1; |
9901 | else | |
9902 | epause->tx_pause = 0; | |
1da177e4 | 9903 | } |
6aa20a22 | 9904 | |
1da177e4 LT |
9905 | static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
9906 | { | |
9907 | struct tg3 *tp = netdev_priv(dev); | |
b02fd9e3 | 9908 | int err = 0; |
6aa20a22 | 9909 | |
b02fd9e3 | 9910 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
2712168f MC |
9911 | u32 newadv; |
9912 | struct phy_device *phydev; | |
1da177e4 | 9913 | |
2712168f | 9914 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
f47c11ee | 9915 | |
2712168f MC |
9916 | if (!(phydev->supported & SUPPORTED_Pause) || |
9917 | (!(phydev->supported & SUPPORTED_Asym_Pause) && | |
9918 | ((epause->rx_pause && !epause->tx_pause) || | |
9919 | (!epause->rx_pause && epause->tx_pause)))) | |
9920 | return -EINVAL; | |
1da177e4 | 9921 | |
2712168f MC |
9922 | tp->link_config.flowctrl = 0; |
9923 | if (epause->rx_pause) { | |
9924 | tp->link_config.flowctrl |= FLOW_CTRL_RX; | |
9925 | ||
9926 | if (epause->tx_pause) { | |
9927 | tp->link_config.flowctrl |= FLOW_CTRL_TX; | |
9928 | newadv = ADVERTISED_Pause; | |
b02fd9e3 | 9929 | } else |
2712168f MC |
9930 | newadv = ADVERTISED_Pause | |
9931 | ADVERTISED_Asym_Pause; | |
9932 | } else if (epause->tx_pause) { | |
9933 | tp->link_config.flowctrl |= FLOW_CTRL_TX; | |
9934 | newadv = ADVERTISED_Asym_Pause; | |
9935 | } else | |
9936 | newadv = 0; | |
9937 | ||
9938 | if (epause->autoneg) | |
9939 | tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG; | |
9940 | else | |
9941 | tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG; | |
9942 | ||
f07e9af3 | 9943 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
2712168f MC |
9944 | u32 oldadv = phydev->advertising & |
9945 | (ADVERTISED_Pause | ADVERTISED_Asym_Pause); | |
9946 | if (oldadv != newadv) { | |
9947 | phydev->advertising &= | |
9948 | ~(ADVERTISED_Pause | | |
9949 | ADVERTISED_Asym_Pause); | |
9950 | phydev->advertising |= newadv; | |
9951 | if (phydev->autoneg) { | |
9952 | /* | |
9953 | * Always renegotiate the link to | |
9954 | * inform our link partner of our | |
9955 | * flow control settings, even if the | |
9956 | * flow control is forced. Let | |
9957 | * tg3_adjust_link() do the final | |
9958 | * flow control setup. | |
9959 | */ | |
9960 | return phy_start_aneg(phydev); | |
b02fd9e3 | 9961 | } |
b02fd9e3 | 9962 | } |
b02fd9e3 | 9963 | |
2712168f | 9964 | if (!epause->autoneg) |
b02fd9e3 | 9965 | tg3_setup_flow_control(tp, 0, 0); |
2712168f MC |
9966 | } else { |
9967 | tp->link_config.orig_advertising &= | |
9968 | ~(ADVERTISED_Pause | | |
9969 | ADVERTISED_Asym_Pause); | |
9970 | tp->link_config.orig_advertising |= newadv; | |
b02fd9e3 MC |
9971 | } |
9972 | } else { | |
9973 | int irq_sync = 0; | |
9974 | ||
9975 | if (netif_running(dev)) { | |
9976 | tg3_netif_stop(tp); | |
9977 | irq_sync = 1; | |
9978 | } | |
9979 | ||
9980 | tg3_full_lock(tp, irq_sync); | |
9981 | ||
9982 | if (epause->autoneg) | |
9983 | tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG; | |
9984 | else | |
9985 | tp->tg3_flags &= ~TG3_FLAG_PAUSE_AUTONEG; | |
9986 | if (epause->rx_pause) | |
e18ce346 | 9987 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
b02fd9e3 | 9988 | else |
e18ce346 | 9989 | tp->link_config.flowctrl &= ~FLOW_CTRL_RX; |
b02fd9e3 | 9990 | if (epause->tx_pause) |
e18ce346 | 9991 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
b02fd9e3 | 9992 | else |
e18ce346 | 9993 | tp->link_config.flowctrl &= ~FLOW_CTRL_TX; |
b02fd9e3 MC |
9994 | |
9995 | if (netif_running(dev)) { | |
9996 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); | |
9997 | err = tg3_restart_hw(tp, 1); | |
9998 | if (!err) | |
9999 | tg3_netif_start(tp); | |
10000 | } | |
10001 | ||
10002 | tg3_full_unlock(tp); | |
10003 | } | |
6aa20a22 | 10004 | |
b9ec6c1b | 10005 | return err; |
1da177e4 | 10006 | } |
6aa20a22 | 10007 | |
1da177e4 LT |
10008 | static u32 tg3_get_rx_csum(struct net_device *dev) |
10009 | { | |
10010 | struct tg3 *tp = netdev_priv(dev); | |
10011 | return (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0; | |
10012 | } | |
6aa20a22 | 10013 | |
1da177e4 LT |
10014 | static int tg3_set_rx_csum(struct net_device *dev, u32 data) |
10015 | { | |
10016 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 10017 | |
1da177e4 LT |
10018 | if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) { |
10019 | if (data != 0) | |
10020 | return -EINVAL; | |
c6cdf436 MC |
10021 | return 0; |
10022 | } | |
6aa20a22 | 10023 | |
f47c11ee | 10024 | spin_lock_bh(&tp->lock); |
1da177e4 LT |
10025 | if (data) |
10026 | tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS; | |
10027 | else | |
10028 | tp->tg3_flags &= ~TG3_FLAG_RX_CHECKSUMS; | |
f47c11ee | 10029 | spin_unlock_bh(&tp->lock); |
6aa20a22 | 10030 | |
1da177e4 LT |
10031 | return 0; |
10032 | } | |
6aa20a22 | 10033 | |
1da177e4 LT |
10034 | static int tg3_set_tx_csum(struct net_device *dev, u32 data) |
10035 | { | |
10036 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 10037 | |
1da177e4 LT |
10038 | if (tp->tg3_flags & TG3_FLAG_BROKEN_CHECKSUMS) { |
10039 | if (data != 0) | |
10040 | return -EINVAL; | |
c6cdf436 MC |
10041 | return 0; |
10042 | } | |
6aa20a22 | 10043 | |
321d32a0 | 10044 | if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
6460d948 | 10045 | ethtool_op_set_tx_ipv6_csum(dev, data); |
1da177e4 | 10046 | else |
9c27dbdf | 10047 | ethtool_op_set_tx_csum(dev, data); |
1da177e4 LT |
10048 | |
10049 | return 0; | |
10050 | } | |
10051 | ||
de6f31eb | 10052 | static int tg3_get_sset_count(struct net_device *dev, int sset) |
1da177e4 | 10053 | { |
b9f2c044 JG |
10054 | switch (sset) { |
10055 | case ETH_SS_TEST: | |
10056 | return TG3_NUM_TEST; | |
10057 | case ETH_SS_STATS: | |
10058 | return TG3_NUM_STATS; | |
10059 | default: | |
10060 | return -EOPNOTSUPP; | |
10061 | } | |
4cafd3f5 MC |
10062 | } |
10063 | ||
de6f31eb | 10064 | static void tg3_get_strings(struct net_device *dev, u32 stringset, u8 *buf) |
1da177e4 LT |
10065 | { |
10066 | switch (stringset) { | |
10067 | case ETH_SS_STATS: | |
10068 | memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys)); | |
10069 | break; | |
4cafd3f5 MC |
10070 | case ETH_SS_TEST: |
10071 | memcpy(buf, ðtool_test_keys, sizeof(ethtool_test_keys)); | |
10072 | break; | |
1da177e4 LT |
10073 | default: |
10074 | WARN_ON(1); /* we need a WARN() */ | |
10075 | break; | |
10076 | } | |
10077 | } | |
10078 | ||
4009a93d MC |
10079 | static int tg3_phys_id(struct net_device *dev, u32 data) |
10080 | { | |
10081 | struct tg3 *tp = netdev_priv(dev); | |
10082 | int i; | |
10083 | ||
10084 | if (!netif_running(tp->dev)) | |
10085 | return -EAGAIN; | |
10086 | ||
10087 | if (data == 0) | |
759afc31 | 10088 | data = UINT_MAX / 2; |
4009a93d MC |
10089 | |
10090 | for (i = 0; i < (data * 2); i++) { | |
10091 | if ((i % 2) == 0) | |
10092 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | | |
10093 | LED_CTRL_1000MBPS_ON | | |
10094 | LED_CTRL_100MBPS_ON | | |
10095 | LED_CTRL_10MBPS_ON | | |
10096 | LED_CTRL_TRAFFIC_OVERRIDE | | |
10097 | LED_CTRL_TRAFFIC_BLINK | | |
10098 | LED_CTRL_TRAFFIC_LED); | |
6aa20a22 | 10099 | |
4009a93d MC |
10100 | else |
10101 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | | |
10102 | LED_CTRL_TRAFFIC_OVERRIDE); | |
10103 | ||
10104 | if (msleep_interruptible(500)) | |
10105 | break; | |
10106 | } | |
10107 | tw32(MAC_LED_CTRL, tp->led_ctrl); | |
10108 | return 0; | |
10109 | } | |
10110 | ||
de6f31eb | 10111 | static void tg3_get_ethtool_stats(struct net_device *dev, |
1da177e4 LT |
10112 | struct ethtool_stats *estats, u64 *tmp_stats) |
10113 | { | |
10114 | struct tg3 *tp = netdev_priv(dev); | |
10115 | memcpy(tmp_stats, tg3_get_estats(tp), sizeof(tp->estats)); | |
10116 | } | |
10117 | ||
566f86ad | 10118 | #define NVRAM_TEST_SIZE 0x100 |
a5767dec MC |
10119 | #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14 |
10120 | #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18 | |
10121 | #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c | |
b16250e3 MC |
10122 | #define NVRAM_SELFBOOT_HW_SIZE 0x20 |
10123 | #define NVRAM_SELFBOOT_DATA_SIZE 0x1c | |
566f86ad MC |
10124 | |
10125 | static int tg3_test_nvram(struct tg3 *tp) | |
10126 | { | |
b9fc7dc5 | 10127 | u32 csum, magic; |
a9dc529d | 10128 | __be32 *buf; |
ab0049b4 | 10129 | int i, j, k, err = 0, size; |
566f86ad | 10130 | |
df259d8c MC |
10131 | if (tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) |
10132 | return 0; | |
10133 | ||
e4f34110 | 10134 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
1b27777a MC |
10135 | return -EIO; |
10136 | ||
1b27777a MC |
10137 | if (magic == TG3_EEPROM_MAGIC) |
10138 | size = NVRAM_TEST_SIZE; | |
b16250e3 | 10139 | else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) { |
a5767dec MC |
10140 | if ((magic & TG3_EEPROM_SB_FORMAT_MASK) == |
10141 | TG3_EEPROM_SB_FORMAT_1) { | |
10142 | switch (magic & TG3_EEPROM_SB_REVISION_MASK) { | |
10143 | case TG3_EEPROM_SB_REVISION_0: | |
10144 | size = NVRAM_SELFBOOT_FORMAT1_0_SIZE; | |
10145 | break; | |
10146 | case TG3_EEPROM_SB_REVISION_2: | |
10147 | size = NVRAM_SELFBOOT_FORMAT1_2_SIZE; | |
10148 | break; | |
10149 | case TG3_EEPROM_SB_REVISION_3: | |
10150 | size = NVRAM_SELFBOOT_FORMAT1_3_SIZE; | |
10151 | break; | |
10152 | default: | |
10153 | return 0; | |
10154 | } | |
10155 | } else | |
1b27777a | 10156 | return 0; |
b16250e3 MC |
10157 | } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
10158 | size = NVRAM_SELFBOOT_HW_SIZE; | |
10159 | else | |
1b27777a MC |
10160 | return -EIO; |
10161 | ||
10162 | buf = kmalloc(size, GFP_KERNEL); | |
566f86ad MC |
10163 | if (buf == NULL) |
10164 | return -ENOMEM; | |
10165 | ||
1b27777a MC |
10166 | err = -EIO; |
10167 | for (i = 0, j = 0; i < size; i += 4, j++) { | |
a9dc529d MC |
10168 | err = tg3_nvram_read_be32(tp, i, &buf[j]); |
10169 | if (err) | |
566f86ad | 10170 | break; |
566f86ad | 10171 | } |
1b27777a | 10172 | if (i < size) |
566f86ad MC |
10173 | goto out; |
10174 | ||
1b27777a | 10175 | /* Selfboot format */ |
a9dc529d | 10176 | magic = be32_to_cpu(buf[0]); |
b9fc7dc5 | 10177 | if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == |
b16250e3 | 10178 | TG3_EEPROM_MAGIC_FW) { |
1b27777a MC |
10179 | u8 *buf8 = (u8 *) buf, csum8 = 0; |
10180 | ||
b9fc7dc5 | 10181 | if ((magic & TG3_EEPROM_SB_REVISION_MASK) == |
a5767dec MC |
10182 | TG3_EEPROM_SB_REVISION_2) { |
10183 | /* For rev 2, the csum doesn't include the MBA. */ | |
10184 | for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++) | |
10185 | csum8 += buf8[i]; | |
10186 | for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++) | |
10187 | csum8 += buf8[i]; | |
10188 | } else { | |
10189 | for (i = 0; i < size; i++) | |
10190 | csum8 += buf8[i]; | |
10191 | } | |
1b27777a | 10192 | |
ad96b485 AB |
10193 | if (csum8 == 0) { |
10194 | err = 0; | |
10195 | goto out; | |
10196 | } | |
10197 | ||
10198 | err = -EIO; | |
10199 | goto out; | |
1b27777a | 10200 | } |
566f86ad | 10201 | |
b9fc7dc5 | 10202 | if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == |
b16250e3 MC |
10203 | TG3_EEPROM_MAGIC_HW) { |
10204 | u8 data[NVRAM_SELFBOOT_DATA_SIZE]; | |
a9dc529d | 10205 | u8 parity[NVRAM_SELFBOOT_DATA_SIZE]; |
b16250e3 | 10206 | u8 *buf8 = (u8 *) buf; |
b16250e3 MC |
10207 | |
10208 | /* Separate the parity bits and the data bytes. */ | |
10209 | for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) { | |
10210 | if ((i == 0) || (i == 8)) { | |
10211 | int l; | |
10212 | u8 msk; | |
10213 | ||
10214 | for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1) | |
10215 | parity[k++] = buf8[i] & msk; | |
10216 | i++; | |
859a5887 | 10217 | } else if (i == 16) { |
b16250e3 MC |
10218 | int l; |
10219 | u8 msk; | |
10220 | ||
10221 | for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1) | |
10222 | parity[k++] = buf8[i] & msk; | |
10223 | i++; | |
10224 | ||
10225 | for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1) | |
10226 | parity[k++] = buf8[i] & msk; | |
10227 | i++; | |
10228 | } | |
10229 | data[j++] = buf8[i]; | |
10230 | } | |
10231 | ||
10232 | err = -EIO; | |
10233 | for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) { | |
10234 | u8 hw8 = hweight8(data[i]); | |
10235 | ||
10236 | if ((hw8 & 0x1) && parity[i]) | |
10237 | goto out; | |
10238 | else if (!(hw8 & 0x1) && !parity[i]) | |
10239 | goto out; | |
10240 | } | |
10241 | err = 0; | |
10242 | goto out; | |
10243 | } | |
10244 | ||
566f86ad MC |
10245 | /* Bootstrap checksum at offset 0x10 */ |
10246 | csum = calc_crc((unsigned char *) buf, 0x10); | |
a9dc529d | 10247 | if (csum != be32_to_cpu(buf[0x10/4])) |
566f86ad MC |
10248 | goto out; |
10249 | ||
10250 | /* Manufacturing block starts at offset 0x74, checksum at 0xfc */ | |
10251 | csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88); | |
a9dc529d MC |
10252 | if (csum != be32_to_cpu(buf[0xfc/4])) |
10253 | goto out; | |
566f86ad MC |
10254 | |
10255 | err = 0; | |
10256 | ||
10257 | out: | |
10258 | kfree(buf); | |
10259 | return err; | |
10260 | } | |
10261 | ||
ca43007a MC |
10262 | #define TG3_SERDES_TIMEOUT_SEC 2 |
10263 | #define TG3_COPPER_TIMEOUT_SEC 6 | |
10264 | ||
10265 | static int tg3_test_link(struct tg3 *tp) | |
10266 | { | |
10267 | int i, max; | |
10268 | ||
10269 | if (!netif_running(tp->dev)) | |
10270 | return -ENODEV; | |
10271 | ||
f07e9af3 | 10272 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
ca43007a MC |
10273 | max = TG3_SERDES_TIMEOUT_SEC; |
10274 | else | |
10275 | max = TG3_COPPER_TIMEOUT_SEC; | |
10276 | ||
10277 | for (i = 0; i < max; i++) { | |
10278 | if (netif_carrier_ok(tp->dev)) | |
10279 | return 0; | |
10280 | ||
10281 | if (msleep_interruptible(1000)) | |
10282 | break; | |
10283 | } | |
10284 | ||
10285 | return -EIO; | |
10286 | } | |
10287 | ||
a71116d1 | 10288 | /* Only test the commonly used registers */ |
30ca3e37 | 10289 | static int tg3_test_registers(struct tg3 *tp) |
a71116d1 | 10290 | { |
b16250e3 | 10291 | int i, is_5705, is_5750; |
a71116d1 MC |
10292 | u32 offset, read_mask, write_mask, val, save_val, read_val; |
10293 | static struct { | |
10294 | u16 offset; | |
10295 | u16 flags; | |
10296 | #define TG3_FL_5705 0x1 | |
10297 | #define TG3_FL_NOT_5705 0x2 | |
10298 | #define TG3_FL_NOT_5788 0x4 | |
b16250e3 | 10299 | #define TG3_FL_NOT_5750 0x8 |
a71116d1 MC |
10300 | u32 read_mask; |
10301 | u32 write_mask; | |
10302 | } reg_tbl[] = { | |
10303 | /* MAC Control Registers */ | |
10304 | { MAC_MODE, TG3_FL_NOT_5705, | |
10305 | 0x00000000, 0x00ef6f8c }, | |
10306 | { MAC_MODE, TG3_FL_5705, | |
10307 | 0x00000000, 0x01ef6b8c }, | |
10308 | { MAC_STATUS, TG3_FL_NOT_5705, | |
10309 | 0x03800107, 0x00000000 }, | |
10310 | { MAC_STATUS, TG3_FL_5705, | |
10311 | 0x03800100, 0x00000000 }, | |
10312 | { MAC_ADDR_0_HIGH, 0x0000, | |
10313 | 0x00000000, 0x0000ffff }, | |
10314 | { MAC_ADDR_0_LOW, 0x0000, | |
c6cdf436 | 10315 | 0x00000000, 0xffffffff }, |
a71116d1 MC |
10316 | { MAC_RX_MTU_SIZE, 0x0000, |
10317 | 0x00000000, 0x0000ffff }, | |
10318 | { MAC_TX_MODE, 0x0000, | |
10319 | 0x00000000, 0x00000070 }, | |
10320 | { MAC_TX_LENGTHS, 0x0000, | |
10321 | 0x00000000, 0x00003fff }, | |
10322 | { MAC_RX_MODE, TG3_FL_NOT_5705, | |
10323 | 0x00000000, 0x000007fc }, | |
10324 | { MAC_RX_MODE, TG3_FL_5705, | |
10325 | 0x00000000, 0x000007dc }, | |
10326 | { MAC_HASH_REG_0, 0x0000, | |
10327 | 0x00000000, 0xffffffff }, | |
10328 | { MAC_HASH_REG_1, 0x0000, | |
10329 | 0x00000000, 0xffffffff }, | |
10330 | { MAC_HASH_REG_2, 0x0000, | |
10331 | 0x00000000, 0xffffffff }, | |
10332 | { MAC_HASH_REG_3, 0x0000, | |
10333 | 0x00000000, 0xffffffff }, | |
10334 | ||
10335 | /* Receive Data and Receive BD Initiator Control Registers. */ | |
10336 | { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705, | |
10337 | 0x00000000, 0xffffffff }, | |
10338 | { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705, | |
10339 | 0x00000000, 0xffffffff }, | |
10340 | { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705, | |
10341 | 0x00000000, 0x00000003 }, | |
10342 | { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705, | |
10343 | 0x00000000, 0xffffffff }, | |
10344 | { RCVDBDI_STD_BD+0, 0x0000, | |
10345 | 0x00000000, 0xffffffff }, | |
10346 | { RCVDBDI_STD_BD+4, 0x0000, | |
10347 | 0x00000000, 0xffffffff }, | |
10348 | { RCVDBDI_STD_BD+8, 0x0000, | |
10349 | 0x00000000, 0xffff0002 }, | |
10350 | { RCVDBDI_STD_BD+0xc, 0x0000, | |
10351 | 0x00000000, 0xffffffff }, | |
6aa20a22 | 10352 | |
a71116d1 MC |
10353 | /* Receive BD Initiator Control Registers. */ |
10354 | { RCVBDI_STD_THRESH, TG3_FL_NOT_5705, | |
10355 | 0x00000000, 0xffffffff }, | |
10356 | { RCVBDI_STD_THRESH, TG3_FL_5705, | |
10357 | 0x00000000, 0x000003ff }, | |
10358 | { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705, | |
10359 | 0x00000000, 0xffffffff }, | |
6aa20a22 | 10360 | |
a71116d1 MC |
10361 | /* Host Coalescing Control Registers. */ |
10362 | { HOSTCC_MODE, TG3_FL_NOT_5705, | |
10363 | 0x00000000, 0x00000004 }, | |
10364 | { HOSTCC_MODE, TG3_FL_5705, | |
10365 | 0x00000000, 0x000000f6 }, | |
10366 | { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705, | |
10367 | 0x00000000, 0xffffffff }, | |
10368 | { HOSTCC_RXCOL_TICKS, TG3_FL_5705, | |
10369 | 0x00000000, 0x000003ff }, | |
10370 | { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705, | |
10371 | 0x00000000, 0xffffffff }, | |
10372 | { HOSTCC_TXCOL_TICKS, TG3_FL_5705, | |
10373 | 0x00000000, 0x000003ff }, | |
10374 | { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705, | |
10375 | 0x00000000, 0xffffffff }, | |
10376 | { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, | |
10377 | 0x00000000, 0x000000ff }, | |
10378 | { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705, | |
10379 | 0x00000000, 0xffffffff }, | |
10380 | { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, | |
10381 | 0x00000000, 0x000000ff }, | |
10382 | { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705, | |
10383 | 0x00000000, 0xffffffff }, | |
10384 | { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705, | |
10385 | 0x00000000, 0xffffffff }, | |
10386 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705, | |
10387 | 0x00000000, 0xffffffff }, | |
10388 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, | |
10389 | 0x00000000, 0x000000ff }, | |
10390 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705, | |
10391 | 0x00000000, 0xffffffff }, | |
10392 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, | |
10393 | 0x00000000, 0x000000ff }, | |
10394 | { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705, | |
10395 | 0x00000000, 0xffffffff }, | |
10396 | { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705, | |
10397 | 0x00000000, 0xffffffff }, | |
10398 | { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705, | |
10399 | 0x00000000, 0xffffffff }, | |
10400 | { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000, | |
10401 | 0x00000000, 0xffffffff }, | |
10402 | { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000, | |
10403 | 0x00000000, 0xffffffff }, | |
10404 | { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000, | |
10405 | 0xffffffff, 0x00000000 }, | |
10406 | { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000, | |
10407 | 0xffffffff, 0x00000000 }, | |
10408 | ||
10409 | /* Buffer Manager Control Registers. */ | |
b16250e3 | 10410 | { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750, |
a71116d1 | 10411 | 0x00000000, 0x007fff80 }, |
b16250e3 | 10412 | { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750, |
a71116d1 MC |
10413 | 0x00000000, 0x007fffff }, |
10414 | { BUFMGR_MB_RDMA_LOW_WATER, 0x0000, | |
10415 | 0x00000000, 0x0000003f }, | |
10416 | { BUFMGR_MB_MACRX_LOW_WATER, 0x0000, | |
10417 | 0x00000000, 0x000001ff }, | |
10418 | { BUFMGR_MB_HIGH_WATER, 0x0000, | |
10419 | 0x00000000, 0x000001ff }, | |
10420 | { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705, | |
10421 | 0xffffffff, 0x00000000 }, | |
10422 | { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705, | |
10423 | 0xffffffff, 0x00000000 }, | |
6aa20a22 | 10424 | |
a71116d1 MC |
10425 | /* Mailbox Registers */ |
10426 | { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000, | |
10427 | 0x00000000, 0x000001ff }, | |
10428 | { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705, | |
10429 | 0x00000000, 0x000001ff }, | |
10430 | { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000, | |
10431 | 0x00000000, 0x000007ff }, | |
10432 | { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000, | |
10433 | 0x00000000, 0x000001ff }, | |
10434 | ||
10435 | { 0xffff, 0x0000, 0x00000000, 0x00000000 }, | |
10436 | }; | |
10437 | ||
b16250e3 MC |
10438 | is_5705 = is_5750 = 0; |
10439 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { | |
a71116d1 | 10440 | is_5705 = 1; |
b16250e3 MC |
10441 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) |
10442 | is_5750 = 1; | |
10443 | } | |
a71116d1 MC |
10444 | |
10445 | for (i = 0; reg_tbl[i].offset != 0xffff; i++) { | |
10446 | if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705)) | |
10447 | continue; | |
10448 | ||
10449 | if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705)) | |
10450 | continue; | |
10451 | ||
10452 | if ((tp->tg3_flags2 & TG3_FLG2_IS_5788) && | |
10453 | (reg_tbl[i].flags & TG3_FL_NOT_5788)) | |
10454 | continue; | |
10455 | ||
b16250e3 MC |
10456 | if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750)) |
10457 | continue; | |
10458 | ||
a71116d1 MC |
10459 | offset = (u32) reg_tbl[i].offset; |
10460 | read_mask = reg_tbl[i].read_mask; | |
10461 | write_mask = reg_tbl[i].write_mask; | |
10462 | ||
10463 | /* Save the original register content */ | |
10464 | save_val = tr32(offset); | |
10465 | ||
10466 | /* Determine the read-only value. */ | |
10467 | read_val = save_val & read_mask; | |
10468 | ||
10469 | /* Write zero to the register, then make sure the read-only bits | |
10470 | * are not changed and the read/write bits are all zeros. | |
10471 | */ | |
10472 | tw32(offset, 0); | |
10473 | ||
10474 | val = tr32(offset); | |
10475 | ||
10476 | /* Test the read-only and read/write bits. */ | |
10477 | if (((val & read_mask) != read_val) || (val & write_mask)) | |
10478 | goto out; | |
10479 | ||
10480 | /* Write ones to all the bits defined by RdMask and WrMask, then | |
10481 | * make sure the read-only bits are not changed and the | |
10482 | * read/write bits are all ones. | |
10483 | */ | |
10484 | tw32(offset, read_mask | write_mask); | |
10485 | ||
10486 | val = tr32(offset); | |
10487 | ||
10488 | /* Test the read-only bits. */ | |
10489 | if ((val & read_mask) != read_val) | |
10490 | goto out; | |
10491 | ||
10492 | /* Test the read/write bits. */ | |
10493 | if ((val & write_mask) != write_mask) | |
10494 | goto out; | |
10495 | ||
10496 | tw32(offset, save_val); | |
10497 | } | |
10498 | ||
10499 | return 0; | |
10500 | ||
10501 | out: | |
9f88f29f | 10502 | if (netif_msg_hw(tp)) |
2445e461 MC |
10503 | netdev_err(tp->dev, |
10504 | "Register test failed at offset %x\n", offset); | |
a71116d1 MC |
10505 | tw32(offset, save_val); |
10506 | return -EIO; | |
10507 | } | |
10508 | ||
7942e1db MC |
10509 | static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len) |
10510 | { | |
f71e1309 | 10511 | static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a }; |
7942e1db MC |
10512 | int i; |
10513 | u32 j; | |
10514 | ||
e9edda69 | 10515 | for (i = 0; i < ARRAY_SIZE(test_pattern); i++) { |
7942e1db MC |
10516 | for (j = 0; j < len; j += 4) { |
10517 | u32 val; | |
10518 | ||
10519 | tg3_write_mem(tp, offset + j, test_pattern[i]); | |
10520 | tg3_read_mem(tp, offset + j, &val); | |
10521 | if (val != test_pattern[i]) | |
10522 | return -EIO; | |
10523 | } | |
10524 | } | |
10525 | return 0; | |
10526 | } | |
10527 | ||
10528 | static int tg3_test_memory(struct tg3 *tp) | |
10529 | { | |
10530 | static struct mem_entry { | |
10531 | u32 offset; | |
10532 | u32 len; | |
10533 | } mem_tbl_570x[] = { | |
38690194 | 10534 | { 0x00000000, 0x00b50}, |
7942e1db MC |
10535 | { 0x00002000, 0x1c000}, |
10536 | { 0xffffffff, 0x00000} | |
10537 | }, mem_tbl_5705[] = { | |
10538 | { 0x00000100, 0x0000c}, | |
10539 | { 0x00000200, 0x00008}, | |
7942e1db MC |
10540 | { 0x00004000, 0x00800}, |
10541 | { 0x00006000, 0x01000}, | |
10542 | { 0x00008000, 0x02000}, | |
10543 | { 0x00010000, 0x0e000}, | |
10544 | { 0xffffffff, 0x00000} | |
79f4d13a MC |
10545 | }, mem_tbl_5755[] = { |
10546 | { 0x00000200, 0x00008}, | |
10547 | { 0x00004000, 0x00800}, | |
10548 | { 0x00006000, 0x00800}, | |
10549 | { 0x00008000, 0x02000}, | |
10550 | { 0x00010000, 0x0c000}, | |
10551 | { 0xffffffff, 0x00000} | |
b16250e3 MC |
10552 | }, mem_tbl_5906[] = { |
10553 | { 0x00000200, 0x00008}, | |
10554 | { 0x00004000, 0x00400}, | |
10555 | { 0x00006000, 0x00400}, | |
10556 | { 0x00008000, 0x01000}, | |
10557 | { 0x00010000, 0x01000}, | |
10558 | { 0xffffffff, 0x00000} | |
8b5a6c42 MC |
10559 | }, mem_tbl_5717[] = { |
10560 | { 0x00000200, 0x00008}, | |
10561 | { 0x00010000, 0x0a000}, | |
10562 | { 0x00020000, 0x13c00}, | |
10563 | { 0xffffffff, 0x00000} | |
10564 | }, mem_tbl_57765[] = { | |
10565 | { 0x00000200, 0x00008}, | |
10566 | { 0x00004000, 0x00800}, | |
10567 | { 0x00006000, 0x09800}, | |
10568 | { 0x00010000, 0x0a000}, | |
10569 | { 0xffffffff, 0x00000} | |
7942e1db MC |
10570 | }; |
10571 | struct mem_entry *mem_tbl; | |
10572 | int err = 0; | |
10573 | int i; | |
10574 | ||
a50d0796 MC |
10575 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
10576 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) | |
8b5a6c42 MC |
10577 | mem_tbl = mem_tbl_5717; |
10578 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) | |
10579 | mem_tbl = mem_tbl_57765; | |
10580 | else if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) | |
321d32a0 MC |
10581 | mem_tbl = mem_tbl_5755; |
10582 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) | |
10583 | mem_tbl = mem_tbl_5906; | |
10584 | else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) | |
10585 | mem_tbl = mem_tbl_5705; | |
10586 | else | |
7942e1db MC |
10587 | mem_tbl = mem_tbl_570x; |
10588 | ||
10589 | for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) { | |
be98da6a MC |
10590 | err = tg3_do_mem_test(tp, mem_tbl[i].offset, mem_tbl[i].len); |
10591 | if (err) | |
7942e1db MC |
10592 | break; |
10593 | } | |
6aa20a22 | 10594 | |
7942e1db MC |
10595 | return err; |
10596 | } | |
10597 | ||
9f40dead MC |
10598 | #define TG3_MAC_LOOPBACK 0 |
10599 | #define TG3_PHY_LOOPBACK 1 | |
10600 | ||
10601 | static int tg3_run_loopback(struct tg3 *tp, int loopback_mode) | |
c76949a6 | 10602 | { |
9f40dead | 10603 | u32 mac_mode, rx_start_idx, rx_idx, tx_idx, opaque_key; |
fd2ce37f | 10604 | u32 desc_idx, coal_now; |
c76949a6 MC |
10605 | struct sk_buff *skb, *rx_skb; |
10606 | u8 *tx_data; | |
10607 | dma_addr_t map; | |
10608 | int num_pkts, tx_len, rx_len, i, err; | |
10609 | struct tg3_rx_buffer_desc *desc; | |
898a56f8 | 10610 | struct tg3_napi *tnapi, *rnapi; |
21f581a5 | 10611 | struct tg3_rx_prodring_set *tpr = &tp->prodring[0]; |
c76949a6 | 10612 | |
c8873405 MC |
10613 | tnapi = &tp->napi[0]; |
10614 | rnapi = &tp->napi[0]; | |
0c1d0e2b | 10615 | if (tp->irq_cnt > 1) { |
0c1d0e2b | 10616 | rnapi = &tp->napi[1]; |
c8873405 MC |
10617 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_TSS) |
10618 | tnapi = &tp->napi[1]; | |
0c1d0e2b | 10619 | } |
fd2ce37f | 10620 | coal_now = tnapi->coal_now | rnapi->coal_now; |
898a56f8 | 10621 | |
9f40dead | 10622 | if (loopback_mode == TG3_MAC_LOOPBACK) { |
c94e3941 MC |
10623 | /* HW errata - mac loopback fails in some cases on 5780. |
10624 | * Normal traffic and PHY loopback are not affected by | |
10625 | * errata. | |
10626 | */ | |
10627 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) | |
10628 | return 0; | |
10629 | ||
9f40dead | 10630 | mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) | |
e8f3f6ca MC |
10631 | MAC_MODE_PORT_INT_LPBACK; |
10632 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) | |
10633 | mac_mode |= MAC_MODE_LINK_POLARITY; | |
f07e9af3 | 10634 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
3f7045c1 MC |
10635 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
10636 | else | |
10637 | mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
9f40dead MC |
10638 | tw32(MAC_MODE, mac_mode); |
10639 | } else if (loopback_mode == TG3_PHY_LOOPBACK) { | |
3f7045c1 MC |
10640 | u32 val; |
10641 | ||
f07e9af3 | 10642 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
7f97a4bd | 10643 | tg3_phy_fet_toggle_apd(tp, false); |
5d64ad34 MC |
10644 | val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED100; |
10645 | } else | |
10646 | val = BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000; | |
3f7045c1 | 10647 | |
9ef8ca99 MC |
10648 | tg3_phy_toggle_automdix(tp, 0); |
10649 | ||
3f7045c1 | 10650 | tg3_writephy(tp, MII_BMCR, val); |
c94e3941 | 10651 | udelay(40); |
5d64ad34 | 10652 | |
e8f3f6ca | 10653 | mac_mode = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; |
f07e9af3 | 10654 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
1061b7c5 MC |
10655 | tg3_writephy(tp, MII_TG3_FET_PTEST, |
10656 | MII_TG3_FET_PTEST_FRC_TX_LINK | | |
10657 | MII_TG3_FET_PTEST_FRC_TX_LOCK); | |
10658 | /* The write needs to be flushed for the AC131 */ | |
10659 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) | |
10660 | tg3_readphy(tp, MII_TG3_FET_PTEST, &val); | |
5d64ad34 MC |
10661 | mac_mode |= MAC_MODE_PORT_MODE_MII; |
10662 | } else | |
10663 | mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
b16250e3 | 10664 | |
c94e3941 | 10665 | /* reset to prevent losing 1st rx packet intermittently */ |
f07e9af3 | 10666 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
c94e3941 MC |
10667 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
10668 | udelay(10); | |
10669 | tw32_f(MAC_RX_MODE, tp->rx_mode); | |
10670 | } | |
e8f3f6ca | 10671 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) { |
79eb6904 MC |
10672 | u32 masked_phy_id = tp->phy_id & TG3_PHY_ID_MASK; |
10673 | if (masked_phy_id == TG3_PHY_ID_BCM5401) | |
e8f3f6ca | 10674 | mac_mode &= ~MAC_MODE_LINK_POLARITY; |
79eb6904 | 10675 | else if (masked_phy_id == TG3_PHY_ID_BCM5411) |
e8f3f6ca | 10676 | mac_mode |= MAC_MODE_LINK_POLARITY; |
ff18ff02 MC |
10677 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
10678 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); | |
10679 | } | |
9f40dead | 10680 | tw32(MAC_MODE, mac_mode); |
859a5887 | 10681 | } else { |
9f40dead | 10682 | return -EINVAL; |
859a5887 | 10683 | } |
c76949a6 MC |
10684 | |
10685 | err = -EIO; | |
10686 | ||
c76949a6 | 10687 | tx_len = 1514; |
a20e9c62 | 10688 | skb = netdev_alloc_skb(tp->dev, tx_len); |
a50bb7b9 JJ |
10689 | if (!skb) |
10690 | return -ENOMEM; | |
10691 | ||
c76949a6 MC |
10692 | tx_data = skb_put(skb, tx_len); |
10693 | memcpy(tx_data, tp->dev->dev_addr, 6); | |
10694 | memset(tx_data + 6, 0x0, 8); | |
10695 | ||
10696 | tw32(MAC_RX_MTU_SIZE, tx_len + 4); | |
10697 | ||
10698 | for (i = 14; i < tx_len; i++) | |
10699 | tx_data[i] = (u8) (i & 0xff); | |
10700 | ||
f4188d8a AD |
10701 | map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE); |
10702 | if (pci_dma_mapping_error(tp->pdev, map)) { | |
a21771dd MC |
10703 | dev_kfree_skb(skb); |
10704 | return -EIO; | |
10705 | } | |
c76949a6 MC |
10706 | |
10707 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | | |
fd2ce37f | 10708 | rnapi->coal_now); |
c76949a6 MC |
10709 | |
10710 | udelay(10); | |
10711 | ||
898a56f8 | 10712 | rx_start_idx = rnapi->hw_status->idx[0].rx_producer; |
c76949a6 | 10713 | |
c76949a6 MC |
10714 | num_pkts = 0; |
10715 | ||
f4188d8a | 10716 | tg3_set_txd(tnapi, tnapi->tx_prod, map, tx_len, 0, 1); |
c76949a6 | 10717 | |
f3f3f27e | 10718 | tnapi->tx_prod++; |
c76949a6 MC |
10719 | num_pkts++; |
10720 | ||
f3f3f27e MC |
10721 | tw32_tx_mbox(tnapi->prodmbox, tnapi->tx_prod); |
10722 | tr32_mailbox(tnapi->prodmbox); | |
c76949a6 MC |
10723 | |
10724 | udelay(10); | |
10725 | ||
303fc921 MC |
10726 | /* 350 usec to allow enough time on some 10/100 Mbps devices. */ |
10727 | for (i = 0; i < 35; i++) { | |
c76949a6 | 10728 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
fd2ce37f | 10729 | coal_now); |
c76949a6 MC |
10730 | |
10731 | udelay(10); | |
10732 | ||
898a56f8 MC |
10733 | tx_idx = tnapi->hw_status->idx[0].tx_consumer; |
10734 | rx_idx = rnapi->hw_status->idx[0].rx_producer; | |
f3f3f27e | 10735 | if ((tx_idx == tnapi->tx_prod) && |
c76949a6 MC |
10736 | (rx_idx == (rx_start_idx + num_pkts))) |
10737 | break; | |
10738 | } | |
10739 | ||
f4188d8a | 10740 | pci_unmap_single(tp->pdev, map, tx_len, PCI_DMA_TODEVICE); |
c76949a6 MC |
10741 | dev_kfree_skb(skb); |
10742 | ||
f3f3f27e | 10743 | if (tx_idx != tnapi->tx_prod) |
c76949a6 MC |
10744 | goto out; |
10745 | ||
10746 | if (rx_idx != rx_start_idx + num_pkts) | |
10747 | goto out; | |
10748 | ||
72334482 | 10749 | desc = &rnapi->rx_rcb[rx_start_idx]; |
c76949a6 MC |
10750 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; |
10751 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; | |
10752 | if (opaque_key != RXD_OPAQUE_RING_STD) | |
10753 | goto out; | |
10754 | ||
10755 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && | |
10756 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) | |
10757 | goto out; | |
10758 | ||
10759 | rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - 4; | |
10760 | if (rx_len != tx_len) | |
10761 | goto out; | |
10762 | ||
21f581a5 | 10763 | rx_skb = tpr->rx_std_buffers[desc_idx].skb; |
c76949a6 | 10764 | |
4e5e4f0d | 10765 | map = dma_unmap_addr(&tpr->rx_std_buffers[desc_idx], mapping); |
c76949a6 MC |
10766 | pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, PCI_DMA_FROMDEVICE); |
10767 | ||
10768 | for (i = 14; i < tx_len; i++) { | |
10769 | if (*(rx_skb->data + i) != (u8) (i & 0xff)) | |
10770 | goto out; | |
10771 | } | |
10772 | err = 0; | |
6aa20a22 | 10773 | |
c76949a6 MC |
10774 | /* tg3_free_rings will unmap and free the rx_skb */ |
10775 | out: | |
10776 | return err; | |
10777 | } | |
10778 | ||
9f40dead MC |
10779 | #define TG3_MAC_LOOPBACK_FAILED 1 |
10780 | #define TG3_PHY_LOOPBACK_FAILED 2 | |
10781 | #define TG3_LOOPBACK_FAILED (TG3_MAC_LOOPBACK_FAILED | \ | |
10782 | TG3_PHY_LOOPBACK_FAILED) | |
10783 | ||
10784 | static int tg3_test_loopback(struct tg3 *tp) | |
10785 | { | |
10786 | int err = 0; | |
9936bcf6 | 10787 | u32 cpmuctrl = 0; |
9f40dead MC |
10788 | |
10789 | if (!netif_running(tp->dev)) | |
10790 | return TG3_LOOPBACK_FAILED; | |
10791 | ||
b9ec6c1b MC |
10792 | err = tg3_reset_hw(tp, 1); |
10793 | if (err) | |
10794 | return TG3_LOOPBACK_FAILED; | |
9f40dead | 10795 | |
6833c043 | 10796 | /* Turn off gphy autopowerdown. */ |
f07e9af3 | 10797 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
6833c043 MC |
10798 | tg3_phy_toggle_apd(tp, false); |
10799 | ||
321d32a0 | 10800 | if (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) { |
9936bcf6 MC |
10801 | int i; |
10802 | u32 status; | |
10803 | ||
10804 | tw32(TG3_CPMU_MUTEX_REQ, CPMU_MUTEX_REQ_DRIVER); | |
10805 | ||
10806 | /* Wait for up to 40 microseconds to acquire lock. */ | |
10807 | for (i = 0; i < 4; i++) { | |
10808 | status = tr32(TG3_CPMU_MUTEX_GNT); | |
10809 | if (status == CPMU_MUTEX_GNT_DRIVER) | |
10810 | break; | |
10811 | udelay(10); | |
10812 | } | |
10813 | ||
10814 | if (status != CPMU_MUTEX_GNT_DRIVER) | |
10815 | return TG3_LOOPBACK_FAILED; | |
10816 | ||
b2a5c19c | 10817 | /* Turn off link-based power management. */ |
e875093c | 10818 | cpmuctrl = tr32(TG3_CPMU_CTRL); |
109115e1 MC |
10819 | tw32(TG3_CPMU_CTRL, |
10820 | cpmuctrl & ~(CPMU_CTRL_LINK_SPEED_MODE | | |
10821 | CPMU_CTRL_LINK_AWARE_MODE)); | |
9936bcf6 MC |
10822 | } |
10823 | ||
9f40dead MC |
10824 | if (tg3_run_loopback(tp, TG3_MAC_LOOPBACK)) |
10825 | err |= TG3_MAC_LOOPBACK_FAILED; | |
9936bcf6 | 10826 | |
321d32a0 | 10827 | if (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) { |
9936bcf6 MC |
10828 | tw32(TG3_CPMU_CTRL, cpmuctrl); |
10829 | ||
10830 | /* Release the mutex */ | |
10831 | tw32(TG3_CPMU_MUTEX_GNT, CPMU_MUTEX_GNT_DRIVER); | |
10832 | } | |
10833 | ||
f07e9af3 | 10834 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
dd477003 | 10835 | !(tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB)) { |
9f40dead MC |
10836 | if (tg3_run_loopback(tp, TG3_PHY_LOOPBACK)) |
10837 | err |= TG3_PHY_LOOPBACK_FAILED; | |
10838 | } | |
10839 | ||
6833c043 | 10840 | /* Re-enable gphy autopowerdown. */ |
f07e9af3 | 10841 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
6833c043 MC |
10842 | tg3_phy_toggle_apd(tp, true); |
10843 | ||
9f40dead MC |
10844 | return err; |
10845 | } | |
10846 | ||
4cafd3f5 MC |
10847 | static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, |
10848 | u64 *data) | |
10849 | { | |
566f86ad MC |
10850 | struct tg3 *tp = netdev_priv(dev); |
10851 | ||
80096068 | 10852 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
bc1c7567 MC |
10853 | tg3_set_power_state(tp, PCI_D0); |
10854 | ||
566f86ad MC |
10855 | memset(data, 0, sizeof(u64) * TG3_NUM_TEST); |
10856 | ||
10857 | if (tg3_test_nvram(tp) != 0) { | |
10858 | etest->flags |= ETH_TEST_FL_FAILED; | |
10859 | data[0] = 1; | |
10860 | } | |
ca43007a MC |
10861 | if (tg3_test_link(tp) != 0) { |
10862 | etest->flags |= ETH_TEST_FL_FAILED; | |
10863 | data[1] = 1; | |
10864 | } | |
a71116d1 | 10865 | if (etest->flags & ETH_TEST_FL_OFFLINE) { |
b02fd9e3 | 10866 | int err, err2 = 0, irq_sync = 0; |
bbe832c0 MC |
10867 | |
10868 | if (netif_running(dev)) { | |
b02fd9e3 | 10869 | tg3_phy_stop(tp); |
a71116d1 | 10870 | tg3_netif_stop(tp); |
bbe832c0 MC |
10871 | irq_sync = 1; |
10872 | } | |
a71116d1 | 10873 | |
bbe832c0 | 10874 | tg3_full_lock(tp, irq_sync); |
a71116d1 MC |
10875 | |
10876 | tg3_halt(tp, RESET_KIND_SUSPEND, 1); | |
ec41c7df | 10877 | err = tg3_nvram_lock(tp); |
a71116d1 MC |
10878 | tg3_halt_cpu(tp, RX_CPU_BASE); |
10879 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) | |
10880 | tg3_halt_cpu(tp, TX_CPU_BASE); | |
ec41c7df MC |
10881 | if (!err) |
10882 | tg3_nvram_unlock(tp); | |
a71116d1 | 10883 | |
f07e9af3 | 10884 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
d9ab5ad1 MC |
10885 | tg3_phy_reset(tp); |
10886 | ||
a71116d1 MC |
10887 | if (tg3_test_registers(tp) != 0) { |
10888 | etest->flags |= ETH_TEST_FL_FAILED; | |
10889 | data[2] = 1; | |
10890 | } | |
7942e1db MC |
10891 | if (tg3_test_memory(tp) != 0) { |
10892 | etest->flags |= ETH_TEST_FL_FAILED; | |
10893 | data[3] = 1; | |
10894 | } | |
9f40dead | 10895 | if ((data[4] = tg3_test_loopback(tp)) != 0) |
c76949a6 | 10896 | etest->flags |= ETH_TEST_FL_FAILED; |
a71116d1 | 10897 | |
f47c11ee DM |
10898 | tg3_full_unlock(tp); |
10899 | ||
d4bc3927 MC |
10900 | if (tg3_test_interrupt(tp) != 0) { |
10901 | etest->flags |= ETH_TEST_FL_FAILED; | |
10902 | data[5] = 1; | |
10903 | } | |
f47c11ee DM |
10904 | |
10905 | tg3_full_lock(tp, 0); | |
d4bc3927 | 10906 | |
a71116d1 MC |
10907 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
10908 | if (netif_running(dev)) { | |
10909 | tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; | |
b02fd9e3 MC |
10910 | err2 = tg3_restart_hw(tp, 1); |
10911 | if (!err2) | |
b9ec6c1b | 10912 | tg3_netif_start(tp); |
a71116d1 | 10913 | } |
f47c11ee DM |
10914 | |
10915 | tg3_full_unlock(tp); | |
b02fd9e3 MC |
10916 | |
10917 | if (irq_sync && !err2) | |
10918 | tg3_phy_start(tp); | |
a71116d1 | 10919 | } |
80096068 | 10920 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
bc1c7567 MC |
10921 | tg3_set_power_state(tp, PCI_D3hot); |
10922 | ||
4cafd3f5 MC |
10923 | } |
10924 | ||
1da177e4 LT |
10925 | static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
10926 | { | |
10927 | struct mii_ioctl_data *data = if_mii(ifr); | |
10928 | struct tg3 *tp = netdev_priv(dev); | |
10929 | int err; | |
10930 | ||
b02fd9e3 | 10931 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
3f0e3ad7 | 10932 | struct phy_device *phydev; |
f07e9af3 | 10933 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 | 10934 | return -EAGAIN; |
3f0e3ad7 | 10935 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
28b04113 | 10936 | return phy_mii_ioctl(phydev, ifr, cmd); |
b02fd9e3 MC |
10937 | } |
10938 | ||
33f401ae | 10939 | switch (cmd) { |
1da177e4 | 10940 | case SIOCGMIIPHY: |
882e9793 | 10941 | data->phy_id = tp->phy_addr; |
1da177e4 LT |
10942 | |
10943 | /* fallthru */ | |
10944 | case SIOCGMIIREG: { | |
10945 | u32 mii_regval; | |
10946 | ||
f07e9af3 | 10947 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
1da177e4 LT |
10948 | break; /* We have no PHY */ |
10949 | ||
80096068 | 10950 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
bc1c7567 MC |
10951 | return -EAGAIN; |
10952 | ||
f47c11ee | 10953 | spin_lock_bh(&tp->lock); |
1da177e4 | 10954 | err = tg3_readphy(tp, data->reg_num & 0x1f, &mii_regval); |
f47c11ee | 10955 | spin_unlock_bh(&tp->lock); |
1da177e4 LT |
10956 | |
10957 | data->val_out = mii_regval; | |
10958 | ||
10959 | return err; | |
10960 | } | |
10961 | ||
10962 | case SIOCSMIIREG: | |
f07e9af3 | 10963 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
1da177e4 LT |
10964 | break; /* We have no PHY */ |
10965 | ||
80096068 | 10966 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
bc1c7567 MC |
10967 | return -EAGAIN; |
10968 | ||
f47c11ee | 10969 | spin_lock_bh(&tp->lock); |
1da177e4 | 10970 | err = tg3_writephy(tp, data->reg_num & 0x1f, data->val_in); |
f47c11ee | 10971 | spin_unlock_bh(&tp->lock); |
1da177e4 LT |
10972 | |
10973 | return err; | |
10974 | ||
10975 | default: | |
10976 | /* do nothing */ | |
10977 | break; | |
10978 | } | |
10979 | return -EOPNOTSUPP; | |
10980 | } | |
10981 | ||
10982 | #if TG3_VLAN_TAG_USED | |
10983 | static void tg3_vlan_rx_register(struct net_device *dev, struct vlan_group *grp) | |
10984 | { | |
10985 | struct tg3 *tp = netdev_priv(dev); | |
10986 | ||
844b3eed MC |
10987 | if (!netif_running(dev)) { |
10988 | tp->vlgrp = grp; | |
10989 | return; | |
10990 | } | |
10991 | ||
10992 | tg3_netif_stop(tp); | |
29315e87 | 10993 | |
f47c11ee | 10994 | tg3_full_lock(tp, 0); |
1da177e4 LT |
10995 | |
10996 | tp->vlgrp = grp; | |
10997 | ||
10998 | /* Update RX_MODE_KEEP_VLAN_TAG bit in RX_MODE register. */ | |
10999 | __tg3_set_rx_mode(dev); | |
11000 | ||
844b3eed | 11001 | tg3_netif_start(tp); |
46966545 MC |
11002 | |
11003 | tg3_full_unlock(tp); | |
1da177e4 | 11004 | } |
1da177e4 LT |
11005 | #endif |
11006 | ||
15f9850d DM |
11007 | static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
11008 | { | |
11009 | struct tg3 *tp = netdev_priv(dev); | |
11010 | ||
11011 | memcpy(ec, &tp->coal, sizeof(*ec)); | |
11012 | return 0; | |
11013 | } | |
11014 | ||
d244c892 MC |
11015 | static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
11016 | { | |
11017 | struct tg3 *tp = netdev_priv(dev); | |
11018 | u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0; | |
11019 | u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0; | |
11020 | ||
11021 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) { | |
11022 | max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT; | |
11023 | max_txcoal_tick_int = MAX_TXCOAL_TICK_INT; | |
11024 | max_stat_coal_ticks = MAX_STAT_COAL_TICKS; | |
11025 | min_stat_coal_ticks = MIN_STAT_COAL_TICKS; | |
11026 | } | |
11027 | ||
11028 | if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) || | |
11029 | (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) || | |
11030 | (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) || | |
11031 | (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) || | |
11032 | (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) || | |
11033 | (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) || | |
11034 | (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) || | |
11035 | (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) || | |
11036 | (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) || | |
11037 | (ec->stats_block_coalesce_usecs < min_stat_coal_ticks)) | |
11038 | return -EINVAL; | |
11039 | ||
11040 | /* No rx interrupts will be generated if both are zero */ | |
11041 | if ((ec->rx_coalesce_usecs == 0) && | |
11042 | (ec->rx_max_coalesced_frames == 0)) | |
11043 | return -EINVAL; | |
11044 | ||
11045 | /* No tx interrupts will be generated if both are zero */ | |
11046 | if ((ec->tx_coalesce_usecs == 0) && | |
11047 | (ec->tx_max_coalesced_frames == 0)) | |
11048 | return -EINVAL; | |
11049 | ||
11050 | /* Only copy relevant parameters, ignore all others. */ | |
11051 | tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs; | |
11052 | tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs; | |
11053 | tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames; | |
11054 | tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames; | |
11055 | tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; | |
11056 | tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; | |
11057 | tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; | |
11058 | tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; | |
11059 | tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs; | |
11060 | ||
11061 | if (netif_running(dev)) { | |
11062 | tg3_full_lock(tp, 0); | |
11063 | __tg3_set_coalesce(tp, &tp->coal); | |
11064 | tg3_full_unlock(tp); | |
11065 | } | |
11066 | return 0; | |
11067 | } | |
11068 | ||
7282d491 | 11069 | static const struct ethtool_ops tg3_ethtool_ops = { |
1da177e4 LT |
11070 | .get_settings = tg3_get_settings, |
11071 | .set_settings = tg3_set_settings, | |
11072 | .get_drvinfo = tg3_get_drvinfo, | |
11073 | .get_regs_len = tg3_get_regs_len, | |
11074 | .get_regs = tg3_get_regs, | |
11075 | .get_wol = tg3_get_wol, | |
11076 | .set_wol = tg3_set_wol, | |
11077 | .get_msglevel = tg3_get_msglevel, | |
11078 | .set_msglevel = tg3_set_msglevel, | |
11079 | .nway_reset = tg3_nway_reset, | |
11080 | .get_link = ethtool_op_get_link, | |
11081 | .get_eeprom_len = tg3_get_eeprom_len, | |
11082 | .get_eeprom = tg3_get_eeprom, | |
11083 | .set_eeprom = tg3_set_eeprom, | |
11084 | .get_ringparam = tg3_get_ringparam, | |
11085 | .set_ringparam = tg3_set_ringparam, | |
11086 | .get_pauseparam = tg3_get_pauseparam, | |
11087 | .set_pauseparam = tg3_set_pauseparam, | |
11088 | .get_rx_csum = tg3_get_rx_csum, | |
11089 | .set_rx_csum = tg3_set_rx_csum, | |
1da177e4 | 11090 | .set_tx_csum = tg3_set_tx_csum, |
1da177e4 | 11091 | .set_sg = ethtool_op_set_sg, |
1da177e4 | 11092 | .set_tso = tg3_set_tso, |
4cafd3f5 | 11093 | .self_test = tg3_self_test, |
1da177e4 | 11094 | .get_strings = tg3_get_strings, |
4009a93d | 11095 | .phys_id = tg3_phys_id, |
1da177e4 | 11096 | .get_ethtool_stats = tg3_get_ethtool_stats, |
15f9850d | 11097 | .get_coalesce = tg3_get_coalesce, |
d244c892 | 11098 | .set_coalesce = tg3_set_coalesce, |
b9f2c044 | 11099 | .get_sset_count = tg3_get_sset_count, |
1da177e4 LT |
11100 | }; |
11101 | ||
11102 | static void __devinit tg3_get_eeprom_size(struct tg3 *tp) | |
11103 | { | |
1b27777a | 11104 | u32 cursize, val, magic; |
1da177e4 LT |
11105 | |
11106 | tp->nvram_size = EEPROM_CHIP_SIZE; | |
11107 | ||
e4f34110 | 11108 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
1da177e4 LT |
11109 | return; |
11110 | ||
b16250e3 MC |
11111 | if ((magic != TG3_EEPROM_MAGIC) && |
11112 | ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) && | |
11113 | ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW)) | |
1da177e4 LT |
11114 | return; |
11115 | ||
11116 | /* | |
11117 | * Size the chip by reading offsets at increasing powers of two. | |
11118 | * When we encounter our validation signature, we know the addressing | |
11119 | * has wrapped around, and thus have our chip size. | |
11120 | */ | |
1b27777a | 11121 | cursize = 0x10; |
1da177e4 LT |
11122 | |
11123 | while (cursize < tp->nvram_size) { | |
e4f34110 | 11124 | if (tg3_nvram_read(tp, cursize, &val) != 0) |
1da177e4 LT |
11125 | return; |
11126 | ||
1820180b | 11127 | if (val == magic) |
1da177e4 LT |
11128 | break; |
11129 | ||
11130 | cursize <<= 1; | |
11131 | } | |
11132 | ||
11133 | tp->nvram_size = cursize; | |
11134 | } | |
6aa20a22 | 11135 | |
1da177e4 LT |
11136 | static void __devinit tg3_get_nvram_size(struct tg3 *tp) |
11137 | { | |
11138 | u32 val; | |
11139 | ||
df259d8c MC |
11140 | if ((tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) || |
11141 | tg3_nvram_read(tp, 0, &val) != 0) | |
1b27777a MC |
11142 | return; |
11143 | ||
11144 | /* Selfboot format */ | |
1820180b | 11145 | if (val != TG3_EEPROM_MAGIC) { |
1b27777a MC |
11146 | tg3_get_eeprom_size(tp); |
11147 | return; | |
11148 | } | |
11149 | ||
6d348f2c | 11150 | if (tg3_nvram_read(tp, 0xf0, &val) == 0) { |
1da177e4 | 11151 | if (val != 0) { |
6d348f2c MC |
11152 | /* This is confusing. We want to operate on the |
11153 | * 16-bit value at offset 0xf2. The tg3_nvram_read() | |
11154 | * call will read from NVRAM and byteswap the data | |
11155 | * according to the byteswapping settings for all | |
11156 | * other register accesses. This ensures the data we | |
11157 | * want will always reside in the lower 16-bits. | |
11158 | * However, the data in NVRAM is in LE format, which | |
11159 | * means the data from the NVRAM read will always be | |
11160 | * opposite the endianness of the CPU. The 16-bit | |
11161 | * byteswap then brings the data to CPU endianness. | |
11162 | */ | |
11163 | tp->nvram_size = swab16((u16)(val & 0x0000ffff)) * 1024; | |
1da177e4 LT |
11164 | return; |
11165 | } | |
11166 | } | |
fd1122a2 | 11167 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
1da177e4 LT |
11168 | } |
11169 | ||
11170 | static void __devinit tg3_get_nvram_info(struct tg3 *tp) | |
11171 | { | |
11172 | u32 nvcfg1; | |
11173 | ||
11174 | nvcfg1 = tr32(NVRAM_CFG1); | |
11175 | if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) { | |
11176 | tp->tg3_flags2 |= TG3_FLG2_FLASH; | |
8590a603 | 11177 | } else { |
1da177e4 LT |
11178 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
11179 | tw32(NVRAM_CFG1, nvcfg1); | |
11180 | } | |
11181 | ||
4c987487 | 11182 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) || |
a4e2b347 | 11183 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
1da177e4 | 11184 | switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { |
8590a603 MC |
11185 | case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: |
11186 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11187 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; | |
11188 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11189 | break; | |
11190 | case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED: | |
11191 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11192 | tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE; | |
11193 | break; | |
11194 | case FLASH_VENDOR_ATMEL_EEPROM: | |
11195 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11196 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; | |
11197 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11198 | break; | |
11199 | case FLASH_VENDOR_ST: | |
11200 | tp->nvram_jedecnum = JEDEC_ST; | |
11201 | tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE; | |
11202 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11203 | break; | |
11204 | case FLASH_VENDOR_SAIFUN: | |
11205 | tp->nvram_jedecnum = JEDEC_SAIFUN; | |
11206 | tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE; | |
11207 | break; | |
11208 | case FLASH_VENDOR_SST_SMALL: | |
11209 | case FLASH_VENDOR_SST_LARGE: | |
11210 | tp->nvram_jedecnum = JEDEC_SST; | |
11211 | tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE; | |
11212 | break; | |
1da177e4 | 11213 | } |
8590a603 | 11214 | } else { |
1da177e4 LT |
11215 | tp->nvram_jedecnum = JEDEC_ATMEL; |
11216 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; | |
11217 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11218 | } | |
11219 | } | |
11220 | ||
a1b950d5 MC |
11221 | static void __devinit tg3_nvram_get_pagesize(struct tg3 *tp, u32 nvmcfg1) |
11222 | { | |
11223 | switch (nvmcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) { | |
11224 | case FLASH_5752PAGE_SIZE_256: | |
11225 | tp->nvram_pagesize = 256; | |
11226 | break; | |
11227 | case FLASH_5752PAGE_SIZE_512: | |
11228 | tp->nvram_pagesize = 512; | |
11229 | break; | |
11230 | case FLASH_5752PAGE_SIZE_1K: | |
11231 | tp->nvram_pagesize = 1024; | |
11232 | break; | |
11233 | case FLASH_5752PAGE_SIZE_2K: | |
11234 | tp->nvram_pagesize = 2048; | |
11235 | break; | |
11236 | case FLASH_5752PAGE_SIZE_4K: | |
11237 | tp->nvram_pagesize = 4096; | |
11238 | break; | |
11239 | case FLASH_5752PAGE_SIZE_264: | |
11240 | tp->nvram_pagesize = 264; | |
11241 | break; | |
11242 | case FLASH_5752PAGE_SIZE_528: | |
11243 | tp->nvram_pagesize = 528; | |
11244 | break; | |
11245 | } | |
11246 | } | |
11247 | ||
361b4ac2 MC |
11248 | static void __devinit tg3_get_5752_nvram_info(struct tg3 *tp) |
11249 | { | |
11250 | u32 nvcfg1; | |
11251 | ||
11252 | nvcfg1 = tr32(NVRAM_CFG1); | |
11253 | ||
e6af301b MC |
11254 | /* NVRAM protection for TPM */ |
11255 | if (nvcfg1 & (1 << 27)) | |
f66a29b0 | 11256 | tp->tg3_flags3 |= TG3_FLG3_PROTECTED_NVRAM; |
e6af301b | 11257 | |
361b4ac2 | 11258 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
8590a603 MC |
11259 | case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ: |
11260 | case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ: | |
11261 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11262 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11263 | break; | |
11264 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: | |
11265 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11266 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11267 | tp->tg3_flags2 |= TG3_FLG2_FLASH; | |
11268 | break; | |
11269 | case FLASH_5752VENDOR_ST_M45PE10: | |
11270 | case FLASH_5752VENDOR_ST_M45PE20: | |
11271 | case FLASH_5752VENDOR_ST_M45PE40: | |
11272 | tp->nvram_jedecnum = JEDEC_ST; | |
11273 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11274 | tp->tg3_flags2 |= TG3_FLG2_FLASH; | |
11275 | break; | |
361b4ac2 MC |
11276 | } |
11277 | ||
11278 | if (tp->tg3_flags2 & TG3_FLG2_FLASH) { | |
a1b950d5 | 11279 | tg3_nvram_get_pagesize(tp, nvcfg1); |
8590a603 | 11280 | } else { |
361b4ac2 MC |
11281 | /* For eeprom, set pagesize to maximum eeprom size */ |
11282 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; | |
11283 | ||
11284 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; | |
11285 | tw32(NVRAM_CFG1, nvcfg1); | |
11286 | } | |
11287 | } | |
11288 | ||
d3c7b886 MC |
11289 | static void __devinit tg3_get_5755_nvram_info(struct tg3 *tp) |
11290 | { | |
989a9d23 | 11291 | u32 nvcfg1, protect = 0; |
d3c7b886 MC |
11292 | |
11293 | nvcfg1 = tr32(NVRAM_CFG1); | |
11294 | ||
11295 | /* NVRAM protection for TPM */ | |
989a9d23 | 11296 | if (nvcfg1 & (1 << 27)) { |
f66a29b0 | 11297 | tp->tg3_flags3 |= TG3_FLG3_PROTECTED_NVRAM; |
989a9d23 MC |
11298 | protect = 1; |
11299 | } | |
d3c7b886 | 11300 | |
989a9d23 MC |
11301 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
11302 | switch (nvcfg1) { | |
8590a603 MC |
11303 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
11304 | case FLASH_5755VENDOR_ATMEL_FLASH_2: | |
11305 | case FLASH_5755VENDOR_ATMEL_FLASH_3: | |
11306 | case FLASH_5755VENDOR_ATMEL_FLASH_5: | |
11307 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11308 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11309 | tp->tg3_flags2 |= TG3_FLG2_FLASH; | |
11310 | tp->nvram_pagesize = 264; | |
11311 | if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 || | |
11312 | nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5) | |
11313 | tp->nvram_size = (protect ? 0x3e200 : | |
11314 | TG3_NVRAM_SIZE_512KB); | |
11315 | else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) | |
11316 | tp->nvram_size = (protect ? 0x1f200 : | |
11317 | TG3_NVRAM_SIZE_256KB); | |
11318 | else | |
11319 | tp->nvram_size = (protect ? 0x1f200 : | |
11320 | TG3_NVRAM_SIZE_128KB); | |
11321 | break; | |
11322 | case FLASH_5752VENDOR_ST_M45PE10: | |
11323 | case FLASH_5752VENDOR_ST_M45PE20: | |
11324 | case FLASH_5752VENDOR_ST_M45PE40: | |
11325 | tp->nvram_jedecnum = JEDEC_ST; | |
11326 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11327 | tp->tg3_flags2 |= TG3_FLG2_FLASH; | |
11328 | tp->nvram_pagesize = 256; | |
11329 | if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10) | |
11330 | tp->nvram_size = (protect ? | |
11331 | TG3_NVRAM_SIZE_64KB : | |
11332 | TG3_NVRAM_SIZE_128KB); | |
11333 | else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20) | |
11334 | tp->nvram_size = (protect ? | |
11335 | TG3_NVRAM_SIZE_64KB : | |
11336 | TG3_NVRAM_SIZE_256KB); | |
11337 | else | |
11338 | tp->nvram_size = (protect ? | |
11339 | TG3_NVRAM_SIZE_128KB : | |
11340 | TG3_NVRAM_SIZE_512KB); | |
11341 | break; | |
d3c7b886 MC |
11342 | } |
11343 | } | |
11344 | ||
1b27777a MC |
11345 | static void __devinit tg3_get_5787_nvram_info(struct tg3 *tp) |
11346 | { | |
11347 | u32 nvcfg1; | |
11348 | ||
11349 | nvcfg1 = tr32(NVRAM_CFG1); | |
11350 | ||
11351 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
8590a603 MC |
11352 | case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ: |
11353 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: | |
11354 | case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ: | |
11355 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: | |
11356 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11357 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11358 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; | |
1b27777a | 11359 | |
8590a603 MC |
11360 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
11361 | tw32(NVRAM_CFG1, nvcfg1); | |
11362 | break; | |
11363 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: | |
11364 | case FLASH_5755VENDOR_ATMEL_FLASH_1: | |
11365 | case FLASH_5755VENDOR_ATMEL_FLASH_2: | |
11366 | case FLASH_5755VENDOR_ATMEL_FLASH_3: | |
11367 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11368 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11369 | tp->tg3_flags2 |= TG3_FLG2_FLASH; | |
11370 | tp->nvram_pagesize = 264; | |
11371 | break; | |
11372 | case FLASH_5752VENDOR_ST_M45PE10: | |
11373 | case FLASH_5752VENDOR_ST_M45PE20: | |
11374 | case FLASH_5752VENDOR_ST_M45PE40: | |
11375 | tp->nvram_jedecnum = JEDEC_ST; | |
11376 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11377 | tp->tg3_flags2 |= TG3_FLG2_FLASH; | |
11378 | tp->nvram_pagesize = 256; | |
11379 | break; | |
1b27777a MC |
11380 | } |
11381 | } | |
11382 | ||
6b91fa02 MC |
11383 | static void __devinit tg3_get_5761_nvram_info(struct tg3 *tp) |
11384 | { | |
11385 | u32 nvcfg1, protect = 0; | |
11386 | ||
11387 | nvcfg1 = tr32(NVRAM_CFG1); | |
11388 | ||
11389 | /* NVRAM protection for TPM */ | |
11390 | if (nvcfg1 & (1 << 27)) { | |
f66a29b0 | 11391 | tp->tg3_flags3 |= TG3_FLG3_PROTECTED_NVRAM; |
6b91fa02 MC |
11392 | protect = 1; |
11393 | } | |
11394 | ||
11395 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; | |
11396 | switch (nvcfg1) { | |
8590a603 MC |
11397 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
11398 | case FLASH_5761VENDOR_ATMEL_ADB041D: | |
11399 | case FLASH_5761VENDOR_ATMEL_ADB081D: | |
11400 | case FLASH_5761VENDOR_ATMEL_ADB161D: | |
11401 | case FLASH_5761VENDOR_ATMEL_MDB021D: | |
11402 | case FLASH_5761VENDOR_ATMEL_MDB041D: | |
11403 | case FLASH_5761VENDOR_ATMEL_MDB081D: | |
11404 | case FLASH_5761VENDOR_ATMEL_MDB161D: | |
11405 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11406 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11407 | tp->tg3_flags2 |= TG3_FLG2_FLASH; | |
11408 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS; | |
11409 | tp->nvram_pagesize = 256; | |
11410 | break; | |
11411 | case FLASH_5761VENDOR_ST_A_M45PE20: | |
11412 | case FLASH_5761VENDOR_ST_A_M45PE40: | |
11413 | case FLASH_5761VENDOR_ST_A_M45PE80: | |
11414 | case FLASH_5761VENDOR_ST_A_M45PE16: | |
11415 | case FLASH_5761VENDOR_ST_M_M45PE20: | |
11416 | case FLASH_5761VENDOR_ST_M_M45PE40: | |
11417 | case FLASH_5761VENDOR_ST_M_M45PE80: | |
11418 | case FLASH_5761VENDOR_ST_M_M45PE16: | |
11419 | tp->nvram_jedecnum = JEDEC_ST; | |
11420 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11421 | tp->tg3_flags2 |= TG3_FLG2_FLASH; | |
11422 | tp->nvram_pagesize = 256; | |
11423 | break; | |
6b91fa02 MC |
11424 | } |
11425 | ||
11426 | if (protect) { | |
11427 | tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT); | |
11428 | } else { | |
11429 | switch (nvcfg1) { | |
8590a603 MC |
11430 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
11431 | case FLASH_5761VENDOR_ATMEL_MDB161D: | |
11432 | case FLASH_5761VENDOR_ST_A_M45PE16: | |
11433 | case FLASH_5761VENDOR_ST_M_M45PE16: | |
11434 | tp->nvram_size = TG3_NVRAM_SIZE_2MB; | |
11435 | break; | |
11436 | case FLASH_5761VENDOR_ATMEL_ADB081D: | |
11437 | case FLASH_5761VENDOR_ATMEL_MDB081D: | |
11438 | case FLASH_5761VENDOR_ST_A_M45PE80: | |
11439 | case FLASH_5761VENDOR_ST_M_M45PE80: | |
11440 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; | |
11441 | break; | |
11442 | case FLASH_5761VENDOR_ATMEL_ADB041D: | |
11443 | case FLASH_5761VENDOR_ATMEL_MDB041D: | |
11444 | case FLASH_5761VENDOR_ST_A_M45PE40: | |
11445 | case FLASH_5761VENDOR_ST_M_M45PE40: | |
11446 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
11447 | break; | |
11448 | case FLASH_5761VENDOR_ATMEL_ADB021D: | |
11449 | case FLASH_5761VENDOR_ATMEL_MDB021D: | |
11450 | case FLASH_5761VENDOR_ST_A_M45PE20: | |
11451 | case FLASH_5761VENDOR_ST_M_M45PE20: | |
11452 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
11453 | break; | |
6b91fa02 MC |
11454 | } |
11455 | } | |
11456 | } | |
11457 | ||
b5d3772c MC |
11458 | static void __devinit tg3_get_5906_nvram_info(struct tg3 *tp) |
11459 | { | |
11460 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11461 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11462 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; | |
11463 | } | |
11464 | ||
321d32a0 MC |
11465 | static void __devinit tg3_get_57780_nvram_info(struct tg3 *tp) |
11466 | { | |
11467 | u32 nvcfg1; | |
11468 | ||
11469 | nvcfg1 = tr32(NVRAM_CFG1); | |
11470 | ||
11471 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
11472 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: | |
11473 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: | |
11474 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11475 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11476 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; | |
11477 | ||
11478 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; | |
11479 | tw32(NVRAM_CFG1, nvcfg1); | |
11480 | return; | |
11481 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: | |
11482 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: | |
11483 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: | |
11484 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: | |
11485 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: | |
11486 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: | |
11487 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: | |
11488 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11489 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11490 | tp->tg3_flags2 |= TG3_FLG2_FLASH; | |
11491 | ||
11492 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
11493 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: | |
11494 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: | |
11495 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: | |
11496 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
11497 | break; | |
11498 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: | |
11499 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: | |
11500 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
11501 | break; | |
11502 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: | |
11503 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: | |
11504 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
11505 | break; | |
11506 | } | |
11507 | break; | |
11508 | case FLASH_5752VENDOR_ST_M45PE10: | |
11509 | case FLASH_5752VENDOR_ST_M45PE20: | |
11510 | case FLASH_5752VENDOR_ST_M45PE40: | |
11511 | tp->nvram_jedecnum = JEDEC_ST; | |
11512 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11513 | tp->tg3_flags2 |= TG3_FLG2_FLASH; | |
11514 | ||
11515 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
11516 | case FLASH_5752VENDOR_ST_M45PE10: | |
11517 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
11518 | break; | |
11519 | case FLASH_5752VENDOR_ST_M45PE20: | |
11520 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
11521 | break; | |
11522 | case FLASH_5752VENDOR_ST_M45PE40: | |
11523 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
11524 | break; | |
11525 | } | |
11526 | break; | |
11527 | default: | |
df259d8c | 11528 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM; |
321d32a0 MC |
11529 | return; |
11530 | } | |
11531 | ||
a1b950d5 MC |
11532 | tg3_nvram_get_pagesize(tp, nvcfg1); |
11533 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) | |
321d32a0 | 11534 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS; |
a1b950d5 MC |
11535 | } |
11536 | ||
11537 | ||
11538 | static void __devinit tg3_get_5717_nvram_info(struct tg3 *tp) | |
11539 | { | |
11540 | u32 nvcfg1; | |
11541 | ||
11542 | nvcfg1 = tr32(NVRAM_CFG1); | |
11543 | ||
11544 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
11545 | case FLASH_5717VENDOR_ATMEL_EEPROM: | |
11546 | case FLASH_5717VENDOR_MICRO_EEPROM: | |
11547 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11548 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11549 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; | |
11550 | ||
11551 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; | |
11552 | tw32(NVRAM_CFG1, nvcfg1); | |
11553 | return; | |
11554 | case FLASH_5717VENDOR_ATMEL_MDB011D: | |
11555 | case FLASH_5717VENDOR_ATMEL_ADB011B: | |
11556 | case FLASH_5717VENDOR_ATMEL_ADB011D: | |
11557 | case FLASH_5717VENDOR_ATMEL_MDB021D: | |
11558 | case FLASH_5717VENDOR_ATMEL_ADB021B: | |
11559 | case FLASH_5717VENDOR_ATMEL_ADB021D: | |
11560 | case FLASH_5717VENDOR_ATMEL_45USPT: | |
11561 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
11562 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11563 | tp->tg3_flags2 |= TG3_FLG2_FLASH; | |
11564 | ||
11565 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
11566 | case FLASH_5717VENDOR_ATMEL_MDB021D: | |
11567 | case FLASH_5717VENDOR_ATMEL_ADB021B: | |
11568 | case FLASH_5717VENDOR_ATMEL_ADB021D: | |
11569 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
11570 | break; | |
11571 | default: | |
11572 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
11573 | break; | |
11574 | } | |
321d32a0 | 11575 | break; |
a1b950d5 MC |
11576 | case FLASH_5717VENDOR_ST_M_M25PE10: |
11577 | case FLASH_5717VENDOR_ST_A_M25PE10: | |
11578 | case FLASH_5717VENDOR_ST_M_M45PE10: | |
11579 | case FLASH_5717VENDOR_ST_A_M45PE10: | |
11580 | case FLASH_5717VENDOR_ST_M_M25PE20: | |
11581 | case FLASH_5717VENDOR_ST_A_M25PE20: | |
11582 | case FLASH_5717VENDOR_ST_M_M45PE20: | |
11583 | case FLASH_5717VENDOR_ST_A_M45PE20: | |
11584 | case FLASH_5717VENDOR_ST_25USPT: | |
11585 | case FLASH_5717VENDOR_ST_45USPT: | |
11586 | tp->nvram_jedecnum = JEDEC_ST; | |
11587 | tp->tg3_flags |= TG3_FLAG_NVRAM_BUFFERED; | |
11588 | tp->tg3_flags2 |= TG3_FLG2_FLASH; | |
11589 | ||
11590 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
11591 | case FLASH_5717VENDOR_ST_M_M25PE20: | |
11592 | case FLASH_5717VENDOR_ST_A_M25PE20: | |
11593 | case FLASH_5717VENDOR_ST_M_M45PE20: | |
11594 | case FLASH_5717VENDOR_ST_A_M45PE20: | |
11595 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
11596 | break; | |
11597 | default: | |
11598 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
11599 | break; | |
11600 | } | |
321d32a0 | 11601 | break; |
a1b950d5 MC |
11602 | default: |
11603 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM; | |
11604 | return; | |
321d32a0 | 11605 | } |
a1b950d5 MC |
11606 | |
11607 | tg3_nvram_get_pagesize(tp, nvcfg1); | |
11608 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) | |
11609 | tp->tg3_flags3 |= TG3_FLG3_NO_NVRAM_ADDR_TRANS; | |
321d32a0 MC |
11610 | } |
11611 | ||
1da177e4 LT |
11612 | /* Chips other than 5700/5701 use the NVRAM for fetching info. */ |
11613 | static void __devinit tg3_nvram_init(struct tg3 *tp) | |
11614 | { | |
1da177e4 LT |
11615 | tw32_f(GRC_EEPROM_ADDR, |
11616 | (EEPROM_ADDR_FSM_RESET | | |
11617 | (EEPROM_DEFAULT_CLOCK_PERIOD << | |
11618 | EEPROM_ADDR_CLKPERD_SHIFT))); | |
11619 | ||
9d57f01c | 11620 | msleep(1); |
1da177e4 LT |
11621 | |
11622 | /* Enable seeprom accesses. */ | |
11623 | tw32_f(GRC_LOCAL_CTRL, | |
11624 | tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM); | |
11625 | udelay(100); | |
11626 | ||
11627 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && | |
11628 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) { | |
11629 | tp->tg3_flags |= TG3_FLAG_NVRAM; | |
11630 | ||
ec41c7df | 11631 | if (tg3_nvram_lock(tp)) { |
5129c3a3 MC |
11632 | netdev_warn(tp->dev, |
11633 | "Cannot get nvram lock, %s failed\n", | |
05dbe005 | 11634 | __func__); |
ec41c7df MC |
11635 | return; |
11636 | } | |
e6af301b | 11637 | tg3_enable_nvram_access(tp); |
1da177e4 | 11638 | |
989a9d23 MC |
11639 | tp->nvram_size = 0; |
11640 | ||
361b4ac2 MC |
11641 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) |
11642 | tg3_get_5752_nvram_info(tp); | |
d3c7b886 MC |
11643 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) |
11644 | tg3_get_5755_nvram_info(tp); | |
d30cdd28 | 11645 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
57e6983c MC |
11646 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
11647 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) | |
1b27777a | 11648 | tg3_get_5787_nvram_info(tp); |
6b91fa02 MC |
11649 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) |
11650 | tg3_get_5761_nvram_info(tp); | |
b5d3772c MC |
11651 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
11652 | tg3_get_5906_nvram_info(tp); | |
b703df6f MC |
11653 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
11654 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) | |
321d32a0 | 11655 | tg3_get_57780_nvram_info(tp); |
a50d0796 MC |
11656 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
11657 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) | |
a1b950d5 | 11658 | tg3_get_5717_nvram_info(tp); |
361b4ac2 MC |
11659 | else |
11660 | tg3_get_nvram_info(tp); | |
11661 | ||
989a9d23 MC |
11662 | if (tp->nvram_size == 0) |
11663 | tg3_get_nvram_size(tp); | |
1da177e4 | 11664 | |
e6af301b | 11665 | tg3_disable_nvram_access(tp); |
381291b7 | 11666 | tg3_nvram_unlock(tp); |
1da177e4 LT |
11667 | |
11668 | } else { | |
11669 | tp->tg3_flags &= ~(TG3_FLAG_NVRAM | TG3_FLAG_NVRAM_BUFFERED); | |
11670 | ||
11671 | tg3_get_eeprom_size(tp); | |
11672 | } | |
11673 | } | |
11674 | ||
1da177e4 LT |
11675 | static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp, |
11676 | u32 offset, u32 len, u8 *buf) | |
11677 | { | |
11678 | int i, j, rc = 0; | |
11679 | u32 val; | |
11680 | ||
11681 | for (i = 0; i < len; i += 4) { | |
b9fc7dc5 | 11682 | u32 addr; |
a9dc529d | 11683 | __be32 data; |
1da177e4 LT |
11684 | |
11685 | addr = offset + i; | |
11686 | ||
11687 | memcpy(&data, buf + i, 4); | |
11688 | ||
62cedd11 MC |
11689 | /* |
11690 | * The SEEPROM interface expects the data to always be opposite | |
11691 | * the native endian format. We accomplish this by reversing | |
11692 | * all the operations that would have been performed on the | |
11693 | * data from a call to tg3_nvram_read_be32(). | |
11694 | */ | |
11695 | tw32(GRC_EEPROM_DATA, swab32(be32_to_cpu(data))); | |
1da177e4 LT |
11696 | |
11697 | val = tr32(GRC_EEPROM_ADDR); | |
11698 | tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE); | |
11699 | ||
11700 | val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK | | |
11701 | EEPROM_ADDR_READ); | |
11702 | tw32(GRC_EEPROM_ADDR, val | | |
11703 | (0 << EEPROM_ADDR_DEVID_SHIFT) | | |
11704 | (addr & EEPROM_ADDR_ADDR_MASK) | | |
11705 | EEPROM_ADDR_START | | |
11706 | EEPROM_ADDR_WRITE); | |
6aa20a22 | 11707 | |
9d57f01c | 11708 | for (j = 0; j < 1000; j++) { |
1da177e4 LT |
11709 | val = tr32(GRC_EEPROM_ADDR); |
11710 | ||
11711 | if (val & EEPROM_ADDR_COMPLETE) | |
11712 | break; | |
9d57f01c | 11713 | msleep(1); |
1da177e4 LT |
11714 | } |
11715 | if (!(val & EEPROM_ADDR_COMPLETE)) { | |
11716 | rc = -EBUSY; | |
11717 | break; | |
11718 | } | |
11719 | } | |
11720 | ||
11721 | return rc; | |
11722 | } | |
11723 | ||
11724 | /* offset and length are dword aligned */ | |
11725 | static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, | |
11726 | u8 *buf) | |
11727 | { | |
11728 | int ret = 0; | |
11729 | u32 pagesize = tp->nvram_pagesize; | |
11730 | u32 pagemask = pagesize - 1; | |
11731 | u32 nvram_cmd; | |
11732 | u8 *tmp; | |
11733 | ||
11734 | tmp = kmalloc(pagesize, GFP_KERNEL); | |
11735 | if (tmp == NULL) | |
11736 | return -ENOMEM; | |
11737 | ||
11738 | while (len) { | |
11739 | int j; | |
e6af301b | 11740 | u32 phy_addr, page_off, size; |
1da177e4 LT |
11741 | |
11742 | phy_addr = offset & ~pagemask; | |
6aa20a22 | 11743 | |
1da177e4 | 11744 | for (j = 0; j < pagesize; j += 4) { |
a9dc529d MC |
11745 | ret = tg3_nvram_read_be32(tp, phy_addr + j, |
11746 | (__be32 *) (tmp + j)); | |
11747 | if (ret) | |
1da177e4 LT |
11748 | break; |
11749 | } | |
11750 | if (ret) | |
11751 | break; | |
11752 | ||
c6cdf436 | 11753 | page_off = offset & pagemask; |
1da177e4 LT |
11754 | size = pagesize; |
11755 | if (len < size) | |
11756 | size = len; | |
11757 | ||
11758 | len -= size; | |
11759 | ||
11760 | memcpy(tmp + page_off, buf, size); | |
11761 | ||
11762 | offset = offset + (pagesize - page_off); | |
11763 | ||
e6af301b | 11764 | tg3_enable_nvram_access(tp); |
1da177e4 LT |
11765 | |
11766 | /* | |
11767 | * Before we can erase the flash page, we need | |
11768 | * to issue a special "write enable" command. | |
11769 | */ | |
11770 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; | |
11771 | ||
11772 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) | |
11773 | break; | |
11774 | ||
11775 | /* Erase the target page */ | |
11776 | tw32(NVRAM_ADDR, phy_addr); | |
11777 | ||
11778 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR | | |
11779 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE; | |
11780 | ||
c6cdf436 | 11781 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) |
1da177e4 LT |
11782 | break; |
11783 | ||
11784 | /* Issue another write enable to start the write. */ | |
11785 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; | |
11786 | ||
11787 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) | |
11788 | break; | |
11789 | ||
11790 | for (j = 0; j < pagesize; j += 4) { | |
b9fc7dc5 | 11791 | __be32 data; |
1da177e4 | 11792 | |
b9fc7dc5 | 11793 | data = *((__be32 *) (tmp + j)); |
a9dc529d | 11794 | |
b9fc7dc5 | 11795 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
1da177e4 LT |
11796 | |
11797 | tw32(NVRAM_ADDR, phy_addr + j); | |
11798 | ||
11799 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | | |
11800 | NVRAM_CMD_WR; | |
11801 | ||
11802 | if (j == 0) | |
11803 | nvram_cmd |= NVRAM_CMD_FIRST; | |
11804 | else if (j == (pagesize - 4)) | |
11805 | nvram_cmd |= NVRAM_CMD_LAST; | |
11806 | ||
11807 | if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd))) | |
11808 | break; | |
11809 | } | |
11810 | if (ret) | |
11811 | break; | |
11812 | } | |
11813 | ||
11814 | nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE; | |
11815 | tg3_nvram_exec_cmd(tp, nvram_cmd); | |
11816 | ||
11817 | kfree(tmp); | |
11818 | ||
11819 | return ret; | |
11820 | } | |
11821 | ||
11822 | /* offset and length are dword aligned */ | |
11823 | static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len, | |
11824 | u8 *buf) | |
11825 | { | |
11826 | int i, ret = 0; | |
11827 | ||
11828 | for (i = 0; i < len; i += 4, offset += 4) { | |
b9fc7dc5 AV |
11829 | u32 page_off, phy_addr, nvram_cmd; |
11830 | __be32 data; | |
1da177e4 LT |
11831 | |
11832 | memcpy(&data, buf + i, 4); | |
b9fc7dc5 | 11833 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); |
1da177e4 | 11834 | |
c6cdf436 | 11835 | page_off = offset % tp->nvram_pagesize; |
1da177e4 | 11836 | |
1820180b | 11837 | phy_addr = tg3_nvram_phys_addr(tp, offset); |
1da177e4 LT |
11838 | |
11839 | tw32(NVRAM_ADDR, phy_addr); | |
11840 | ||
11841 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR; | |
11842 | ||
c6cdf436 | 11843 | if (page_off == 0 || i == 0) |
1da177e4 | 11844 | nvram_cmd |= NVRAM_CMD_FIRST; |
f6d9a256 | 11845 | if (page_off == (tp->nvram_pagesize - 4)) |
1da177e4 LT |
11846 | nvram_cmd |= NVRAM_CMD_LAST; |
11847 | ||
11848 | if (i == (len - 4)) | |
11849 | nvram_cmd |= NVRAM_CMD_LAST; | |
11850 | ||
321d32a0 MC |
11851 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5752 && |
11852 | !(tp->tg3_flags3 & TG3_FLG3_5755_PLUS) && | |
4c987487 MC |
11853 | (tp->nvram_jedecnum == JEDEC_ST) && |
11854 | (nvram_cmd & NVRAM_CMD_FIRST)) { | |
1da177e4 LT |
11855 | |
11856 | if ((ret = tg3_nvram_exec_cmd(tp, | |
11857 | NVRAM_CMD_WREN | NVRAM_CMD_GO | | |
11858 | NVRAM_CMD_DONE))) | |
11859 | ||
11860 | break; | |
11861 | } | |
11862 | if (!(tp->tg3_flags2 & TG3_FLG2_FLASH)) { | |
11863 | /* We always do complete word writes to eeprom. */ | |
11864 | nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST); | |
11865 | } | |
11866 | ||
11867 | if ((ret = tg3_nvram_exec_cmd(tp, nvram_cmd))) | |
11868 | break; | |
11869 | } | |
11870 | return ret; | |
11871 | } | |
11872 | ||
11873 | /* offset and length are dword aligned */ | |
11874 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf) | |
11875 | { | |
11876 | int ret; | |
11877 | ||
1da177e4 | 11878 | if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) { |
314fba34 MC |
11879 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl & |
11880 | ~GRC_LCLCTRL_GPIO_OUTPUT1); | |
1da177e4 LT |
11881 | udelay(40); |
11882 | } | |
11883 | ||
11884 | if (!(tp->tg3_flags & TG3_FLAG_NVRAM)) { | |
11885 | ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf); | |
859a5887 | 11886 | } else { |
1da177e4 LT |
11887 | u32 grc_mode; |
11888 | ||
ec41c7df MC |
11889 | ret = tg3_nvram_lock(tp); |
11890 | if (ret) | |
11891 | return ret; | |
1da177e4 | 11892 | |
e6af301b MC |
11893 | tg3_enable_nvram_access(tp); |
11894 | if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) && | |
f66a29b0 | 11895 | !(tp->tg3_flags3 & TG3_FLG3_PROTECTED_NVRAM)) |
1da177e4 | 11896 | tw32(NVRAM_WRITE1, 0x406); |
1da177e4 LT |
11897 | |
11898 | grc_mode = tr32(GRC_MODE); | |
11899 | tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE); | |
11900 | ||
11901 | if ((tp->tg3_flags & TG3_FLAG_NVRAM_BUFFERED) || | |
11902 | !(tp->tg3_flags2 & TG3_FLG2_FLASH)) { | |
11903 | ||
11904 | ret = tg3_nvram_write_block_buffered(tp, offset, len, | |
11905 | buf); | |
859a5887 | 11906 | } else { |
1da177e4 LT |
11907 | ret = tg3_nvram_write_block_unbuffered(tp, offset, len, |
11908 | buf); | |
11909 | } | |
11910 | ||
11911 | grc_mode = tr32(GRC_MODE); | |
11912 | tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE); | |
11913 | ||
e6af301b | 11914 | tg3_disable_nvram_access(tp); |
1da177e4 LT |
11915 | tg3_nvram_unlock(tp); |
11916 | } | |
11917 | ||
11918 | if (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT) { | |
314fba34 | 11919 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
1da177e4 LT |
11920 | udelay(40); |
11921 | } | |
11922 | ||
11923 | return ret; | |
11924 | } | |
11925 | ||
11926 | struct subsys_tbl_ent { | |
11927 | u16 subsys_vendor, subsys_devid; | |
11928 | u32 phy_id; | |
11929 | }; | |
11930 | ||
24daf2b0 | 11931 | static struct subsys_tbl_ent subsys_id_to_phy_id[] __devinitdata = { |
1da177e4 | 11932 | /* Broadcom boards. */ |
24daf2b0 | 11933 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 11934 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A6, TG3_PHY_ID_BCM5401 }, |
24daf2b0 | 11935 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 11936 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A5, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 11937 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 11938 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700T6, TG3_PHY_ID_BCM8002 }, |
24daf2b0 MC |
11939 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
11940 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A9, 0 }, | |
11941 | { TG3PCI_SUBVENDOR_ID_BROADCOM, | |
79eb6904 | 11942 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T1, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 11943 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 11944 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T8, TG3_PHY_ID_BCM5701 }, |
24daf2b0 MC |
11945 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
11946 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A7, 0 }, | |
11947 | { TG3PCI_SUBVENDOR_ID_BROADCOM, | |
79eb6904 | 11948 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A10, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 11949 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 11950 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A12, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 11951 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 11952 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX1, TG3_PHY_ID_BCM5703 }, |
24daf2b0 | 11953 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 11954 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX2, TG3_PHY_ID_BCM5703 }, |
1da177e4 LT |
11955 | |
11956 | /* 3com boards. */ | |
24daf2b0 | 11957 | { TG3PCI_SUBVENDOR_ID_3COM, |
79eb6904 | 11958 | TG3PCI_SUBDEVICE_ID_3COM_3C996T, TG3_PHY_ID_BCM5401 }, |
24daf2b0 | 11959 | { TG3PCI_SUBVENDOR_ID_3COM, |
79eb6904 | 11960 | TG3PCI_SUBDEVICE_ID_3COM_3C996BT, TG3_PHY_ID_BCM5701 }, |
24daf2b0 MC |
11961 | { TG3PCI_SUBVENDOR_ID_3COM, |
11962 | TG3PCI_SUBDEVICE_ID_3COM_3C996SX, 0 }, | |
11963 | { TG3PCI_SUBVENDOR_ID_3COM, | |
79eb6904 | 11964 | TG3PCI_SUBDEVICE_ID_3COM_3C1000T, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 11965 | { TG3PCI_SUBVENDOR_ID_3COM, |
79eb6904 | 11966 | TG3PCI_SUBDEVICE_ID_3COM_3C940BR01, TG3_PHY_ID_BCM5701 }, |
1da177e4 LT |
11967 | |
11968 | /* DELL boards. */ | |
24daf2b0 | 11969 | { TG3PCI_SUBVENDOR_ID_DELL, |
79eb6904 | 11970 | TG3PCI_SUBDEVICE_ID_DELL_VIPER, TG3_PHY_ID_BCM5401 }, |
24daf2b0 | 11971 | { TG3PCI_SUBVENDOR_ID_DELL, |
79eb6904 | 11972 | TG3PCI_SUBDEVICE_ID_DELL_JAGUAR, TG3_PHY_ID_BCM5401 }, |
24daf2b0 | 11973 | { TG3PCI_SUBVENDOR_ID_DELL, |
79eb6904 | 11974 | TG3PCI_SUBDEVICE_ID_DELL_MERLOT, TG3_PHY_ID_BCM5411 }, |
24daf2b0 | 11975 | { TG3PCI_SUBVENDOR_ID_DELL, |
79eb6904 | 11976 | TG3PCI_SUBDEVICE_ID_DELL_SLIM_MERLOT, TG3_PHY_ID_BCM5411 }, |
1da177e4 LT |
11977 | |
11978 | /* Compaq boards. */ | |
24daf2b0 | 11979 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
79eb6904 | 11980 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 11981 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
79eb6904 | 11982 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE_2, TG3_PHY_ID_BCM5701 }, |
24daf2b0 MC |
11983 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
11984 | TG3PCI_SUBDEVICE_ID_COMPAQ_CHANGELING, 0 }, | |
11985 | { TG3PCI_SUBVENDOR_ID_COMPAQ, | |
79eb6904 | 11986 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 11987 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
79eb6904 | 11988 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780_2, TG3_PHY_ID_BCM5701 }, |
1da177e4 LT |
11989 | |
11990 | /* IBM boards. */ | |
24daf2b0 MC |
11991 | { TG3PCI_SUBVENDOR_ID_IBM, |
11992 | TG3PCI_SUBDEVICE_ID_IBM_5703SAX2, 0 } | |
1da177e4 LT |
11993 | }; |
11994 | ||
24daf2b0 | 11995 | static struct subsys_tbl_ent * __devinit tg3_lookup_by_subsys(struct tg3 *tp) |
1da177e4 LT |
11996 | { |
11997 | int i; | |
11998 | ||
11999 | for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) { | |
12000 | if ((subsys_id_to_phy_id[i].subsys_vendor == | |
12001 | tp->pdev->subsystem_vendor) && | |
12002 | (subsys_id_to_phy_id[i].subsys_devid == | |
12003 | tp->pdev->subsystem_device)) | |
12004 | return &subsys_id_to_phy_id[i]; | |
12005 | } | |
12006 | return NULL; | |
12007 | } | |
12008 | ||
7d0c41ef | 12009 | static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp) |
1da177e4 | 12010 | { |
1da177e4 | 12011 | u32 val; |
caf636c7 MC |
12012 | u16 pmcsr; |
12013 | ||
12014 | /* On some early chips the SRAM cannot be accessed in D3hot state, | |
12015 | * so need make sure we're in D0. | |
12016 | */ | |
12017 | pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr); | |
12018 | pmcsr &= ~PCI_PM_CTRL_STATE_MASK; | |
12019 | pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr); | |
12020 | msleep(1); | |
7d0c41ef MC |
12021 | |
12022 | /* Make sure register accesses (indirect or otherwise) | |
12023 | * will function correctly. | |
12024 | */ | |
12025 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
12026 | tp->misc_host_ctrl); | |
1da177e4 | 12027 | |
f49639e6 DM |
12028 | /* The memory arbiter has to be enabled in order for SRAM accesses |
12029 | * to succeed. Normally on powerup the tg3 chip firmware will make | |
12030 | * sure it is enabled, but other entities such as system netboot | |
12031 | * code might disable it. | |
12032 | */ | |
12033 | val = tr32(MEMARB_MODE); | |
12034 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); | |
12035 | ||
79eb6904 | 12036 | tp->phy_id = TG3_PHY_ID_INVALID; |
7d0c41ef MC |
12037 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
12038 | ||
a85feb8c GZ |
12039 | /* Assume an onboard device and WOL capable by default. */ |
12040 | tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT | TG3_FLAG_WOL_CAP; | |
72b845e0 | 12041 | |
b5d3772c | 12042 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
9d26e213 | 12043 | if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) { |
b5d3772c | 12044 | tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT; |
9d26e213 MC |
12045 | tp->tg3_flags2 |= TG3_FLG2_IS_NIC; |
12046 | } | |
0527ba35 MC |
12047 | val = tr32(VCPU_CFGSHDW); |
12048 | if (val & VCPU_CFGSHDW_ASPM_DBNC) | |
8ed5d97e | 12049 | tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND; |
0527ba35 | 12050 | if ((val & VCPU_CFGSHDW_WOL_ENABLE) && |
2023276e | 12051 | (val & VCPU_CFGSHDW_WOL_MAGPKT)) |
0527ba35 | 12052 | tp->tg3_flags |= TG3_FLAG_WOL_ENABLE; |
05ac4cb7 | 12053 | goto done; |
b5d3772c MC |
12054 | } |
12055 | ||
1da177e4 LT |
12056 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
12057 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { | |
12058 | u32 nic_cfg, led_cfg; | |
a9daf367 | 12059 | u32 nic_phy_id, ver, cfg2 = 0, cfg4 = 0, eeprom_phy_id; |
7d0c41ef | 12060 | int eeprom_phy_serdes = 0; |
1da177e4 LT |
12061 | |
12062 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); | |
12063 | tp->nic_sram_data_cfg = nic_cfg; | |
12064 | ||
12065 | tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver); | |
12066 | ver >>= NIC_SRAM_DATA_VER_SHIFT; | |
12067 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700) && | |
12068 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) && | |
12069 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5703) && | |
12070 | (ver > 0) && (ver < 0x100)) | |
12071 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2); | |
12072 | ||
a9daf367 MC |
12073 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) |
12074 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_4, &cfg4); | |
12075 | ||
1da177e4 LT |
12076 | if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) == |
12077 | NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER) | |
12078 | eeprom_phy_serdes = 1; | |
12079 | ||
12080 | tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id); | |
12081 | if (nic_phy_id != 0) { | |
12082 | u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK; | |
12083 | u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK; | |
12084 | ||
12085 | eeprom_phy_id = (id1 >> 16) << 10; | |
12086 | eeprom_phy_id |= (id2 & 0xfc00) << 16; | |
12087 | eeprom_phy_id |= (id2 & 0x03ff) << 0; | |
12088 | } else | |
12089 | eeprom_phy_id = 0; | |
12090 | ||
7d0c41ef | 12091 | tp->phy_id = eeprom_phy_id; |
747e8f8b | 12092 | if (eeprom_phy_serdes) { |
a50d0796 | 12093 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) |
f07e9af3 | 12094 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
a50d0796 | 12095 | else |
f07e9af3 | 12096 | tp->phy_flags |= TG3_PHYFLG_MII_SERDES; |
747e8f8b | 12097 | } |
7d0c41ef | 12098 | |
cbf46853 | 12099 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) |
1da177e4 LT |
12100 | led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK | |
12101 | SHASTA_EXT_LED_MODE_MASK); | |
cbf46853 | 12102 | else |
1da177e4 LT |
12103 | led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK; |
12104 | ||
12105 | switch (led_cfg) { | |
12106 | default: | |
12107 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1: | |
12108 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; | |
12109 | break; | |
12110 | ||
12111 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2: | |
12112 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; | |
12113 | break; | |
12114 | ||
12115 | case NIC_SRAM_DATA_CFG_LED_MODE_MAC: | |
12116 | tp->led_ctrl = LED_CTRL_MODE_MAC; | |
9ba27794 MC |
12117 | |
12118 | /* Default to PHY_1_MODE if 0 (MAC_MODE) is | |
12119 | * read on some older 5700/5701 bootcode. | |
12120 | */ | |
12121 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == | |
12122 | ASIC_REV_5700 || | |
12123 | GET_ASIC_REV(tp->pci_chip_rev_id) == | |
12124 | ASIC_REV_5701) | |
12125 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; | |
12126 | ||
1da177e4 LT |
12127 | break; |
12128 | ||
12129 | case SHASTA_EXT_LED_SHARED: | |
12130 | tp->led_ctrl = LED_CTRL_MODE_SHARED; | |
12131 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0 && | |
12132 | tp->pci_chip_rev_id != CHIPREV_ID_5750_A1) | |
12133 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | | |
12134 | LED_CTRL_MODE_PHY_2); | |
12135 | break; | |
12136 | ||
12137 | case SHASTA_EXT_LED_MAC: | |
12138 | tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC; | |
12139 | break; | |
12140 | ||
12141 | case SHASTA_EXT_LED_COMBO: | |
12142 | tp->led_ctrl = LED_CTRL_MODE_COMBO; | |
12143 | if (tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) | |
12144 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | | |
12145 | LED_CTRL_MODE_PHY_2); | |
12146 | break; | |
12147 | ||
855e1111 | 12148 | } |
1da177e4 LT |
12149 | |
12150 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
12151 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) && | |
12152 | tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL) | |
12153 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; | |
12154 | ||
b2a5c19c MC |
12155 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5784_AX) |
12156 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; | |
5f60891b | 12157 | |
9d26e213 | 12158 | if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) { |
1da177e4 | 12159 | tp->tg3_flags |= TG3_FLAG_EEPROM_WRITE_PROT; |
9d26e213 MC |
12160 | if ((tp->pdev->subsystem_vendor == |
12161 | PCI_VENDOR_ID_ARIMA) && | |
12162 | (tp->pdev->subsystem_device == 0x205a || | |
12163 | tp->pdev->subsystem_device == 0x2063)) | |
12164 | tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT; | |
12165 | } else { | |
f49639e6 | 12166 | tp->tg3_flags &= ~TG3_FLAG_EEPROM_WRITE_PROT; |
9d26e213 MC |
12167 | tp->tg3_flags2 |= TG3_FLG2_IS_NIC; |
12168 | } | |
1da177e4 LT |
12169 | |
12170 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { | |
12171 | tp->tg3_flags |= TG3_FLAG_ENABLE_ASF; | |
cbf46853 | 12172 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) |
1da177e4 LT |
12173 | tp->tg3_flags2 |= TG3_FLG2_ASF_NEW_HANDSHAKE; |
12174 | } | |
b2b98d4a MC |
12175 | |
12176 | if ((nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE) && | |
12177 | (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)) | |
0d3031d9 | 12178 | tp->tg3_flags3 |= TG3_FLG3_ENABLE_APE; |
b2b98d4a | 12179 | |
f07e9af3 | 12180 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES && |
a85feb8c GZ |
12181 | !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)) |
12182 | tp->tg3_flags &= ~TG3_FLAG_WOL_CAP; | |
1da177e4 | 12183 | |
12dac075 | 12184 | if ((tp->tg3_flags & TG3_FLAG_WOL_CAP) && |
05ac4cb7 | 12185 | (nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)) |
0527ba35 MC |
12186 | tp->tg3_flags |= TG3_FLAG_WOL_ENABLE; |
12187 | ||
1da177e4 | 12188 | if (cfg2 & (1 << 17)) |
f07e9af3 | 12189 | tp->phy_flags |= TG3_PHYFLG_CAPACITIVE_COUPLING; |
1da177e4 LT |
12190 | |
12191 | /* serdes signal pre-emphasis in register 0x590 set by */ | |
12192 | /* bootcode if bit 18 is set */ | |
12193 | if (cfg2 & (1 << 18)) | |
f07e9af3 | 12194 | tp->phy_flags |= TG3_PHYFLG_SERDES_PREEMPHASIS; |
8ed5d97e | 12195 | |
321d32a0 MC |
12196 | if (((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
12197 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX)) && | |
6833c043 | 12198 | (cfg2 & NIC_SRAM_DATA_CFG_2_APD_EN)) |
f07e9af3 | 12199 | tp->phy_flags |= TG3_PHYFLG_ENABLE_APD; |
6833c043 | 12200 | |
8c69b1e7 MC |
12201 | if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && |
12202 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && | |
12203 | !(tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) { | |
8ed5d97e MC |
12204 | u32 cfg3; |
12205 | ||
12206 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3); | |
12207 | if (cfg3 & NIC_SRAM_ASPM_DEBOUNCE) | |
12208 | tp->tg3_flags |= TG3_FLAG_ASPM_WORKAROUND; | |
12209 | } | |
a9daf367 | 12210 | |
14417063 MC |
12211 | if (cfg4 & NIC_SRAM_RGMII_INBAND_DISABLE) |
12212 | tp->tg3_flags3 |= TG3_FLG3_RGMII_INBAND_DISABLE; | |
a9daf367 MC |
12213 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_RX_EN) |
12214 | tp->tg3_flags3 |= TG3_FLG3_RGMII_EXT_IBND_RX_EN; | |
12215 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_TX_EN) | |
12216 | tp->tg3_flags3 |= TG3_FLG3_RGMII_EXT_IBND_TX_EN; | |
1da177e4 | 12217 | } |
05ac4cb7 MC |
12218 | done: |
12219 | device_init_wakeup(&tp->pdev->dev, tp->tg3_flags & TG3_FLAG_WOL_CAP); | |
12220 | device_set_wakeup_enable(&tp->pdev->dev, | |
12221 | tp->tg3_flags & TG3_FLAG_WOL_ENABLE); | |
7d0c41ef MC |
12222 | } |
12223 | ||
b2a5c19c MC |
12224 | static int __devinit tg3_issue_otp_command(struct tg3 *tp, u32 cmd) |
12225 | { | |
12226 | int i; | |
12227 | u32 val; | |
12228 | ||
12229 | tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START); | |
12230 | tw32(OTP_CTRL, cmd); | |
12231 | ||
12232 | /* Wait for up to 1 ms for command to execute. */ | |
12233 | for (i = 0; i < 100; i++) { | |
12234 | val = tr32(OTP_STATUS); | |
12235 | if (val & OTP_STATUS_CMD_DONE) | |
12236 | break; | |
12237 | udelay(10); | |
12238 | } | |
12239 | ||
12240 | return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY; | |
12241 | } | |
12242 | ||
12243 | /* Read the gphy configuration from the OTP region of the chip. The gphy | |
12244 | * configuration is a 32-bit value that straddles the alignment boundary. | |
12245 | * We do two 32-bit reads and then shift and merge the results. | |
12246 | */ | |
12247 | static u32 __devinit tg3_read_otp_phycfg(struct tg3 *tp) | |
12248 | { | |
12249 | u32 bhalf_otp, thalf_otp; | |
12250 | ||
12251 | tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC); | |
12252 | ||
12253 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT)) | |
12254 | return 0; | |
12255 | ||
12256 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1); | |
12257 | ||
12258 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) | |
12259 | return 0; | |
12260 | ||
12261 | thalf_otp = tr32(OTP_READ_DATA); | |
12262 | ||
12263 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2); | |
12264 | ||
12265 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) | |
12266 | return 0; | |
12267 | ||
12268 | bhalf_otp = tr32(OTP_READ_DATA); | |
12269 | ||
12270 | return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16); | |
12271 | } | |
12272 | ||
7d0c41ef MC |
12273 | static int __devinit tg3_phy_probe(struct tg3 *tp) |
12274 | { | |
12275 | u32 hw_phy_id_1, hw_phy_id_2; | |
12276 | u32 hw_phy_id, hw_phy_id_masked; | |
12277 | int err; | |
1da177e4 | 12278 | |
b02fd9e3 MC |
12279 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) |
12280 | return tg3_phy_init(tp); | |
12281 | ||
1da177e4 | 12282 | /* Reading the PHY ID register can conflict with ASF |
877d0310 | 12283 | * firmware access to the PHY hardware. |
1da177e4 LT |
12284 | */ |
12285 | err = 0; | |
0d3031d9 MC |
12286 | if ((tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || |
12287 | (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE)) { | |
79eb6904 | 12288 | hw_phy_id = hw_phy_id_masked = TG3_PHY_ID_INVALID; |
1da177e4 LT |
12289 | } else { |
12290 | /* Now read the physical PHY_ID from the chip and verify | |
12291 | * that it is sane. If it doesn't look good, we fall back | |
12292 | * to either the hard-coded table based PHY_ID and failing | |
12293 | * that the value found in the eeprom area. | |
12294 | */ | |
12295 | err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1); | |
12296 | err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2); | |
12297 | ||
12298 | hw_phy_id = (hw_phy_id_1 & 0xffff) << 10; | |
12299 | hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16; | |
12300 | hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0; | |
12301 | ||
79eb6904 | 12302 | hw_phy_id_masked = hw_phy_id & TG3_PHY_ID_MASK; |
1da177e4 LT |
12303 | } |
12304 | ||
79eb6904 | 12305 | if (!err && TG3_KNOWN_PHY_ID(hw_phy_id_masked)) { |
1da177e4 | 12306 | tp->phy_id = hw_phy_id; |
79eb6904 | 12307 | if (hw_phy_id_masked == TG3_PHY_ID_BCM8002) |
f07e9af3 | 12308 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
da6b2d01 | 12309 | else |
f07e9af3 | 12310 | tp->phy_flags &= ~TG3_PHYFLG_PHY_SERDES; |
1da177e4 | 12311 | } else { |
79eb6904 | 12312 | if (tp->phy_id != TG3_PHY_ID_INVALID) { |
7d0c41ef MC |
12313 | /* Do nothing, phy ID already set up in |
12314 | * tg3_get_eeprom_hw_cfg(). | |
12315 | */ | |
1da177e4 LT |
12316 | } else { |
12317 | struct subsys_tbl_ent *p; | |
12318 | ||
12319 | /* No eeprom signature? Try the hardcoded | |
12320 | * subsys device table. | |
12321 | */ | |
24daf2b0 | 12322 | p = tg3_lookup_by_subsys(tp); |
1da177e4 LT |
12323 | if (!p) |
12324 | return -ENODEV; | |
12325 | ||
12326 | tp->phy_id = p->phy_id; | |
12327 | if (!tp->phy_id || | |
79eb6904 | 12328 | tp->phy_id == TG3_PHY_ID_BCM8002) |
f07e9af3 | 12329 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
1da177e4 LT |
12330 | } |
12331 | } | |
12332 | ||
f07e9af3 | 12333 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
0d3031d9 | 12334 | !(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) && |
1da177e4 | 12335 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) { |
3600d918 | 12336 | u32 bmsr, adv_reg, tg3_ctrl, mask; |
1da177e4 LT |
12337 | |
12338 | tg3_readphy(tp, MII_BMSR, &bmsr); | |
12339 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && | |
12340 | (bmsr & BMSR_LSTATUS)) | |
12341 | goto skip_phy_reset; | |
6aa20a22 | 12342 | |
1da177e4 LT |
12343 | err = tg3_phy_reset(tp); |
12344 | if (err) | |
12345 | return err; | |
12346 | ||
12347 | adv_reg = (ADVERTISE_10HALF | ADVERTISE_10FULL | | |
12348 | ADVERTISE_100HALF | ADVERTISE_100FULL | | |
12349 | ADVERTISE_CSMA | ADVERTISE_PAUSE_CAP); | |
12350 | tg3_ctrl = 0; | |
f07e9af3 | 12351 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
1da177e4 LT |
12352 | tg3_ctrl = (MII_TG3_CTRL_ADV_1000_HALF | |
12353 | MII_TG3_CTRL_ADV_1000_FULL); | |
12354 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || | |
12355 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0) | |
12356 | tg3_ctrl |= (MII_TG3_CTRL_AS_MASTER | | |
12357 | MII_TG3_CTRL_ENABLE_AS_MASTER); | |
12358 | } | |
12359 | ||
3600d918 MC |
12360 | mask = (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
12361 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | | |
12362 | ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full); | |
12363 | if (!tg3_copper_is_advertising_all(tp, mask)) { | |
1da177e4 LT |
12364 | tg3_writephy(tp, MII_ADVERTISE, adv_reg); |
12365 | ||
f07e9af3 | 12366 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
1da177e4 LT |
12367 | tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl); |
12368 | ||
12369 | tg3_writephy(tp, MII_BMCR, | |
12370 | BMCR_ANENABLE | BMCR_ANRESTART); | |
12371 | } | |
12372 | tg3_phy_set_wirespeed(tp); | |
12373 | ||
12374 | tg3_writephy(tp, MII_ADVERTISE, adv_reg); | |
f07e9af3 | 12375 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
1da177e4 LT |
12376 | tg3_writephy(tp, MII_TG3_CTRL, tg3_ctrl); |
12377 | } | |
12378 | ||
12379 | skip_phy_reset: | |
79eb6904 | 12380 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
1da177e4 LT |
12381 | err = tg3_init_5401phy_dsp(tp); |
12382 | if (err) | |
12383 | return err; | |
1da177e4 | 12384 | |
1da177e4 LT |
12385 | err = tg3_init_5401phy_dsp(tp); |
12386 | } | |
12387 | ||
f07e9af3 | 12388 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
1da177e4 LT |
12389 | tp->link_config.advertising = |
12390 | (ADVERTISED_1000baseT_Half | | |
12391 | ADVERTISED_1000baseT_Full | | |
12392 | ADVERTISED_Autoneg | | |
12393 | ADVERTISED_FIBRE); | |
f07e9af3 | 12394 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) |
1da177e4 LT |
12395 | tp->link_config.advertising &= |
12396 | ~(ADVERTISED_1000baseT_Half | | |
12397 | ADVERTISED_1000baseT_Full); | |
12398 | ||
12399 | return err; | |
12400 | } | |
12401 | ||
184b8904 | 12402 | static void __devinit tg3_read_vpd(struct tg3 *tp) |
1da177e4 | 12403 | { |
184b8904 | 12404 | u8 vpd_data[TG3_NVM_VPD_LEN]; |
4181b2c8 | 12405 | unsigned int block_end, rosize, len; |
184b8904 | 12406 | int j, i = 0; |
1b27777a | 12407 | u32 magic; |
1da177e4 | 12408 | |
df259d8c MC |
12409 | if ((tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) || |
12410 | tg3_nvram_read(tp, 0x0, &magic)) | |
f49639e6 | 12411 | goto out_not_found; |
1da177e4 | 12412 | |
1820180b | 12413 | if (magic == TG3_EEPROM_MAGIC) { |
141518c9 | 12414 | for (i = 0; i < TG3_NVM_VPD_LEN; i += 4) { |
1b27777a | 12415 | u32 tmp; |
1da177e4 | 12416 | |
6d348f2c MC |
12417 | /* The data is in little-endian format in NVRAM. |
12418 | * Use the big-endian read routines to preserve | |
12419 | * the byte order as it exists in NVRAM. | |
12420 | */ | |
141518c9 | 12421 | if (tg3_nvram_read_be32(tp, TG3_NVM_VPD_OFF + i, &tmp)) |
1b27777a MC |
12422 | goto out_not_found; |
12423 | ||
6d348f2c | 12424 | memcpy(&vpd_data[i], &tmp, sizeof(tmp)); |
1b27777a MC |
12425 | } |
12426 | } else { | |
94c982bd | 12427 | ssize_t cnt; |
4181b2c8 | 12428 | unsigned int pos = 0; |
94c982bd MC |
12429 | |
12430 | for (; pos < TG3_NVM_VPD_LEN && i < 3; i++, pos += cnt) { | |
12431 | cnt = pci_read_vpd(tp->pdev, pos, | |
12432 | TG3_NVM_VPD_LEN - pos, | |
12433 | &vpd_data[pos]); | |
12434 | if (cnt == -ETIMEDOUT || -EINTR) | |
12435 | cnt = 0; | |
12436 | else if (cnt < 0) | |
f49639e6 | 12437 | goto out_not_found; |
1b27777a | 12438 | } |
94c982bd MC |
12439 | if (pos != TG3_NVM_VPD_LEN) |
12440 | goto out_not_found; | |
1da177e4 LT |
12441 | } |
12442 | ||
4181b2c8 MC |
12443 | i = pci_vpd_find_tag(vpd_data, 0, TG3_NVM_VPD_LEN, |
12444 | PCI_VPD_LRDT_RO_DATA); | |
12445 | if (i < 0) | |
12446 | goto out_not_found; | |
1da177e4 | 12447 | |
4181b2c8 MC |
12448 | rosize = pci_vpd_lrdt_size(&vpd_data[i]); |
12449 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize; | |
12450 | i += PCI_VPD_LRDT_TAG_SIZE; | |
1da177e4 | 12451 | |
4181b2c8 MC |
12452 | if (block_end > TG3_NVM_VPD_LEN) |
12453 | goto out_not_found; | |
af2c6a4a | 12454 | |
184b8904 MC |
12455 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
12456 | PCI_VPD_RO_KEYWORD_MFR_ID); | |
12457 | if (j > 0) { | |
12458 | len = pci_vpd_info_field_size(&vpd_data[j]); | |
12459 | ||
12460 | j += PCI_VPD_INFO_FLD_HDR_SIZE; | |
12461 | if (j + len > block_end || len != 4 || | |
12462 | memcmp(&vpd_data[j], "1028", 4)) | |
12463 | goto partno; | |
12464 | ||
12465 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, | |
12466 | PCI_VPD_RO_KEYWORD_VENDOR0); | |
12467 | if (j < 0) | |
12468 | goto partno; | |
12469 | ||
12470 | len = pci_vpd_info_field_size(&vpd_data[j]); | |
12471 | ||
12472 | j += PCI_VPD_INFO_FLD_HDR_SIZE; | |
12473 | if (j + len > block_end) | |
12474 | goto partno; | |
12475 | ||
12476 | memcpy(tp->fw_ver, &vpd_data[j], len); | |
12477 | strncat(tp->fw_ver, " bc ", TG3_NVM_VPD_LEN - len - 1); | |
12478 | } | |
12479 | ||
12480 | partno: | |
4181b2c8 MC |
12481 | i = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
12482 | PCI_VPD_RO_KEYWORD_PARTNO); | |
12483 | if (i < 0) | |
12484 | goto out_not_found; | |
af2c6a4a | 12485 | |
4181b2c8 | 12486 | len = pci_vpd_info_field_size(&vpd_data[i]); |
1da177e4 | 12487 | |
4181b2c8 MC |
12488 | i += PCI_VPD_INFO_FLD_HDR_SIZE; |
12489 | if (len > TG3_BPN_SIZE || | |
12490 | (len + i) > TG3_NVM_VPD_LEN) | |
12491 | goto out_not_found; | |
1da177e4 | 12492 | |
4181b2c8 | 12493 | memcpy(tp->board_part_number, &vpd_data[i], len); |
1da177e4 | 12494 | |
4181b2c8 | 12495 | return; |
1da177e4 LT |
12496 | |
12497 | out_not_found: | |
b5d3772c MC |
12498 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
12499 | strcpy(tp->board_part_number, "BCM95906"); | |
df259d8c MC |
12500 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 && |
12501 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57780) | |
12502 | strcpy(tp->board_part_number, "BCM57780"); | |
12503 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 && | |
12504 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57760) | |
12505 | strcpy(tp->board_part_number, "BCM57760"); | |
12506 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 && | |
12507 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790) | |
12508 | strcpy(tp->board_part_number, "BCM57790"); | |
5e7ccf20 MC |
12509 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 && |
12510 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57788) | |
12511 | strcpy(tp->board_part_number, "BCM57788"); | |
b474eca7 MC |
12512 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && |
12513 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761) | |
12514 | strcpy(tp->board_part_number, "BCM57761"); | |
12515 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && | |
12516 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765) | |
b703df6f | 12517 | strcpy(tp->board_part_number, "BCM57765"); |
b474eca7 MC |
12518 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && |
12519 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781) | |
12520 | strcpy(tp->board_part_number, "BCM57781"); | |
12521 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && | |
12522 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785) | |
12523 | strcpy(tp->board_part_number, "BCM57785"); | |
12524 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && | |
12525 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791) | |
12526 | strcpy(tp->board_part_number, "BCM57791"); | |
12527 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765 && | |
12528 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) | |
12529 | strcpy(tp->board_part_number, "BCM57795"); | |
b5d3772c MC |
12530 | else |
12531 | strcpy(tp->board_part_number, "none"); | |
1da177e4 LT |
12532 | } |
12533 | ||
9c8a620e MC |
12534 | static int __devinit tg3_fw_img_is_valid(struct tg3 *tp, u32 offset) |
12535 | { | |
12536 | u32 val; | |
12537 | ||
e4f34110 | 12538 | if (tg3_nvram_read(tp, offset, &val) || |
9c8a620e | 12539 | (val & 0xfc000000) != 0x0c000000 || |
e4f34110 | 12540 | tg3_nvram_read(tp, offset + 4, &val) || |
9c8a620e MC |
12541 | val != 0) |
12542 | return 0; | |
12543 | ||
12544 | return 1; | |
12545 | } | |
12546 | ||
acd9c119 MC |
12547 | static void __devinit tg3_read_bc_ver(struct tg3 *tp) |
12548 | { | |
ff3a7cb2 | 12549 | u32 val, offset, start, ver_offset; |
75f9936e | 12550 | int i, dst_off; |
ff3a7cb2 | 12551 | bool newver = false; |
acd9c119 MC |
12552 | |
12553 | if (tg3_nvram_read(tp, 0xc, &offset) || | |
12554 | tg3_nvram_read(tp, 0x4, &start)) | |
12555 | return; | |
12556 | ||
12557 | offset = tg3_nvram_logical_addr(tp, offset); | |
12558 | ||
ff3a7cb2 | 12559 | if (tg3_nvram_read(tp, offset, &val)) |
acd9c119 MC |
12560 | return; |
12561 | ||
ff3a7cb2 MC |
12562 | if ((val & 0xfc000000) == 0x0c000000) { |
12563 | if (tg3_nvram_read(tp, offset + 4, &val)) | |
acd9c119 MC |
12564 | return; |
12565 | ||
ff3a7cb2 MC |
12566 | if (val == 0) |
12567 | newver = true; | |
12568 | } | |
12569 | ||
75f9936e MC |
12570 | dst_off = strlen(tp->fw_ver); |
12571 | ||
ff3a7cb2 | 12572 | if (newver) { |
75f9936e MC |
12573 | if (TG3_VER_SIZE - dst_off < 16 || |
12574 | tg3_nvram_read(tp, offset + 8, &ver_offset)) | |
ff3a7cb2 MC |
12575 | return; |
12576 | ||
12577 | offset = offset + ver_offset - start; | |
12578 | for (i = 0; i < 16; i += 4) { | |
12579 | __be32 v; | |
12580 | if (tg3_nvram_read_be32(tp, offset + i, &v)) | |
12581 | return; | |
12582 | ||
75f9936e | 12583 | memcpy(tp->fw_ver + dst_off + i, &v, sizeof(v)); |
ff3a7cb2 MC |
12584 | } |
12585 | } else { | |
12586 | u32 major, minor; | |
12587 | ||
12588 | if (tg3_nvram_read(tp, TG3_NVM_PTREV_BCVER, &ver_offset)) | |
12589 | return; | |
12590 | ||
12591 | major = (ver_offset & TG3_NVM_BCVER_MAJMSK) >> | |
12592 | TG3_NVM_BCVER_MAJSFT; | |
12593 | minor = ver_offset & TG3_NVM_BCVER_MINMSK; | |
75f9936e MC |
12594 | snprintf(&tp->fw_ver[dst_off], TG3_VER_SIZE - dst_off, |
12595 | "v%d.%02d", major, minor); | |
acd9c119 MC |
12596 | } |
12597 | } | |
12598 | ||
a6f6cb1c MC |
12599 | static void __devinit tg3_read_hwsb_ver(struct tg3 *tp) |
12600 | { | |
12601 | u32 val, major, minor; | |
12602 | ||
12603 | /* Use native endian representation */ | |
12604 | if (tg3_nvram_read(tp, TG3_NVM_HWSB_CFG1, &val)) | |
12605 | return; | |
12606 | ||
12607 | major = (val & TG3_NVM_HWSB_CFG1_MAJMSK) >> | |
12608 | TG3_NVM_HWSB_CFG1_MAJSFT; | |
12609 | minor = (val & TG3_NVM_HWSB_CFG1_MINMSK) >> | |
12610 | TG3_NVM_HWSB_CFG1_MINSFT; | |
12611 | ||
12612 | snprintf(&tp->fw_ver[0], 32, "sb v%d.%02d", major, minor); | |
12613 | } | |
12614 | ||
dfe00d7d MC |
12615 | static void __devinit tg3_read_sb_ver(struct tg3 *tp, u32 val) |
12616 | { | |
12617 | u32 offset, major, minor, build; | |
12618 | ||
75f9936e | 12619 | strncat(tp->fw_ver, "sb", TG3_VER_SIZE - strlen(tp->fw_ver) - 1); |
dfe00d7d MC |
12620 | |
12621 | if ((val & TG3_EEPROM_SB_FORMAT_MASK) != TG3_EEPROM_SB_FORMAT_1) | |
12622 | return; | |
12623 | ||
12624 | switch (val & TG3_EEPROM_SB_REVISION_MASK) { | |
12625 | case TG3_EEPROM_SB_REVISION_0: | |
12626 | offset = TG3_EEPROM_SB_F1R0_EDH_OFF; | |
12627 | break; | |
12628 | case TG3_EEPROM_SB_REVISION_2: | |
12629 | offset = TG3_EEPROM_SB_F1R2_EDH_OFF; | |
12630 | break; | |
12631 | case TG3_EEPROM_SB_REVISION_3: | |
12632 | offset = TG3_EEPROM_SB_F1R3_EDH_OFF; | |
12633 | break; | |
a4153d40 MC |
12634 | case TG3_EEPROM_SB_REVISION_4: |
12635 | offset = TG3_EEPROM_SB_F1R4_EDH_OFF; | |
12636 | break; | |
12637 | case TG3_EEPROM_SB_REVISION_5: | |
12638 | offset = TG3_EEPROM_SB_F1R5_EDH_OFF; | |
12639 | break; | |
dfe00d7d MC |
12640 | default: |
12641 | return; | |
12642 | } | |
12643 | ||
e4f34110 | 12644 | if (tg3_nvram_read(tp, offset, &val)) |
dfe00d7d MC |
12645 | return; |
12646 | ||
12647 | build = (val & TG3_EEPROM_SB_EDH_BLD_MASK) >> | |
12648 | TG3_EEPROM_SB_EDH_BLD_SHFT; | |
12649 | major = (val & TG3_EEPROM_SB_EDH_MAJ_MASK) >> | |
12650 | TG3_EEPROM_SB_EDH_MAJ_SHFT; | |
12651 | minor = val & TG3_EEPROM_SB_EDH_MIN_MASK; | |
12652 | ||
12653 | if (minor > 99 || build > 26) | |
12654 | return; | |
12655 | ||
75f9936e MC |
12656 | offset = strlen(tp->fw_ver); |
12657 | snprintf(&tp->fw_ver[offset], TG3_VER_SIZE - offset, | |
12658 | " v%d.%02d", major, minor); | |
dfe00d7d MC |
12659 | |
12660 | if (build > 0) { | |
75f9936e MC |
12661 | offset = strlen(tp->fw_ver); |
12662 | if (offset < TG3_VER_SIZE - 1) | |
12663 | tp->fw_ver[offset] = 'a' + build - 1; | |
dfe00d7d MC |
12664 | } |
12665 | } | |
12666 | ||
acd9c119 | 12667 | static void __devinit tg3_read_mgmtfw_ver(struct tg3 *tp) |
c4e6575c MC |
12668 | { |
12669 | u32 val, offset, start; | |
acd9c119 | 12670 | int i, vlen; |
9c8a620e MC |
12671 | |
12672 | for (offset = TG3_NVM_DIR_START; | |
12673 | offset < TG3_NVM_DIR_END; | |
12674 | offset += TG3_NVM_DIRENT_SIZE) { | |
e4f34110 | 12675 | if (tg3_nvram_read(tp, offset, &val)) |
c4e6575c MC |
12676 | return; |
12677 | ||
9c8a620e MC |
12678 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI) |
12679 | break; | |
12680 | } | |
12681 | ||
12682 | if (offset == TG3_NVM_DIR_END) | |
12683 | return; | |
12684 | ||
12685 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS)) | |
12686 | start = 0x08000000; | |
e4f34110 | 12687 | else if (tg3_nvram_read(tp, offset - 4, &start)) |
9c8a620e MC |
12688 | return; |
12689 | ||
e4f34110 | 12690 | if (tg3_nvram_read(tp, offset + 4, &offset) || |
9c8a620e | 12691 | !tg3_fw_img_is_valid(tp, offset) || |
e4f34110 | 12692 | tg3_nvram_read(tp, offset + 8, &val)) |
9c8a620e MC |
12693 | return; |
12694 | ||
12695 | offset += val - start; | |
12696 | ||
acd9c119 | 12697 | vlen = strlen(tp->fw_ver); |
9c8a620e | 12698 | |
acd9c119 MC |
12699 | tp->fw_ver[vlen++] = ','; |
12700 | tp->fw_ver[vlen++] = ' '; | |
9c8a620e MC |
12701 | |
12702 | for (i = 0; i < 4; i++) { | |
a9dc529d MC |
12703 | __be32 v; |
12704 | if (tg3_nvram_read_be32(tp, offset, &v)) | |
c4e6575c MC |
12705 | return; |
12706 | ||
b9fc7dc5 | 12707 | offset += sizeof(v); |
c4e6575c | 12708 | |
acd9c119 MC |
12709 | if (vlen > TG3_VER_SIZE - sizeof(v)) { |
12710 | memcpy(&tp->fw_ver[vlen], &v, TG3_VER_SIZE - vlen); | |
9c8a620e | 12711 | break; |
c4e6575c | 12712 | } |
9c8a620e | 12713 | |
acd9c119 MC |
12714 | memcpy(&tp->fw_ver[vlen], &v, sizeof(v)); |
12715 | vlen += sizeof(v); | |
c4e6575c | 12716 | } |
acd9c119 MC |
12717 | } |
12718 | ||
7fd76445 MC |
12719 | static void __devinit tg3_read_dash_ver(struct tg3 *tp) |
12720 | { | |
12721 | int vlen; | |
12722 | u32 apedata; | |
ecc79648 | 12723 | char *fwtype; |
7fd76445 MC |
12724 | |
12725 | if (!(tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) || | |
12726 | !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) | |
12727 | return; | |
12728 | ||
12729 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); | |
12730 | if (apedata != APE_SEG_SIG_MAGIC) | |
12731 | return; | |
12732 | ||
12733 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); | |
12734 | if (!(apedata & APE_FW_STATUS_READY)) | |
12735 | return; | |
12736 | ||
12737 | apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION); | |
12738 | ||
ecc79648 MC |
12739 | if (tg3_ape_read32(tp, TG3_APE_FW_FEATURES) & TG3_APE_FW_FEATURE_NCSI) |
12740 | fwtype = "NCSI"; | |
12741 | else | |
12742 | fwtype = "DASH"; | |
12743 | ||
7fd76445 MC |
12744 | vlen = strlen(tp->fw_ver); |
12745 | ||
ecc79648 MC |
12746 | snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " %s v%d.%d.%d.%d", |
12747 | fwtype, | |
7fd76445 MC |
12748 | (apedata & APE_FW_VERSION_MAJMSK) >> APE_FW_VERSION_MAJSFT, |
12749 | (apedata & APE_FW_VERSION_MINMSK) >> APE_FW_VERSION_MINSFT, | |
12750 | (apedata & APE_FW_VERSION_REVMSK) >> APE_FW_VERSION_REVSFT, | |
12751 | (apedata & APE_FW_VERSION_BLDMSK)); | |
12752 | } | |
12753 | ||
acd9c119 MC |
12754 | static void __devinit tg3_read_fw_ver(struct tg3 *tp) |
12755 | { | |
12756 | u32 val; | |
75f9936e | 12757 | bool vpd_vers = false; |
acd9c119 | 12758 | |
75f9936e MC |
12759 | if (tp->fw_ver[0] != 0) |
12760 | vpd_vers = true; | |
df259d8c | 12761 | |
75f9936e MC |
12762 | if (tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) { |
12763 | strcat(tp->fw_ver, "sb"); | |
df259d8c MC |
12764 | return; |
12765 | } | |
12766 | ||
acd9c119 MC |
12767 | if (tg3_nvram_read(tp, 0, &val)) |
12768 | return; | |
12769 | ||
12770 | if (val == TG3_EEPROM_MAGIC) | |
12771 | tg3_read_bc_ver(tp); | |
12772 | else if ((val & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) | |
12773 | tg3_read_sb_ver(tp, val); | |
a6f6cb1c MC |
12774 | else if ((val & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
12775 | tg3_read_hwsb_ver(tp); | |
acd9c119 MC |
12776 | else |
12777 | return; | |
12778 | ||
12779 | if (!(tp->tg3_flags & TG3_FLAG_ENABLE_ASF) || | |
75f9936e MC |
12780 | (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) || vpd_vers) |
12781 | goto done; | |
acd9c119 MC |
12782 | |
12783 | tg3_read_mgmtfw_ver(tp); | |
9c8a620e | 12784 | |
75f9936e | 12785 | done: |
9c8a620e | 12786 | tp->fw_ver[TG3_VER_SIZE - 1] = 0; |
c4e6575c MC |
12787 | } |
12788 | ||
7544b097 MC |
12789 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *); |
12790 | ||
7fe876af ED |
12791 | static void inline vlan_features_add(struct net_device *dev, unsigned long flags) |
12792 | { | |
12793 | #if TG3_VLAN_TAG_USED | |
12794 | dev->vlan_features |= flags; | |
12795 | #endif | |
12796 | } | |
12797 | ||
1da177e4 LT |
12798 | static int __devinit tg3_get_invariants(struct tg3 *tp) |
12799 | { | |
12800 | static struct pci_device_id write_reorder_chipsets[] = { | |
1da177e4 | 12801 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, |
c6cdf436 | 12802 | PCI_DEVICE_ID_AMD_FE_GATE_700C) }, |
c165b004 | 12803 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, |
c6cdf436 | 12804 | PCI_DEVICE_ID_AMD_8131_BRIDGE) }, |
399de50b MC |
12805 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, |
12806 | PCI_DEVICE_ID_VIA_8385_0) }, | |
1da177e4 LT |
12807 | { }, |
12808 | }; | |
12809 | u32 misc_ctrl_reg; | |
1da177e4 LT |
12810 | u32 pci_state_reg, grc_misc_cfg; |
12811 | u32 val; | |
12812 | u16 pci_cmd; | |
5e7dfd0f | 12813 | int err; |
1da177e4 | 12814 | |
1da177e4 LT |
12815 | /* Force memory write invalidate off. If we leave it on, |
12816 | * then on 5700_BX chips we have to enable a workaround. | |
12817 | * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary | |
12818 | * to match the cacheline size. The Broadcom driver have this | |
12819 | * workaround but turns MWI off all the times so never uses | |
12820 | * it. This seems to suggest that the workaround is insufficient. | |
12821 | */ | |
12822 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); | |
12823 | pci_cmd &= ~PCI_COMMAND_INVALIDATE; | |
12824 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); | |
12825 | ||
12826 | /* It is absolutely critical that TG3PCI_MISC_HOST_CTRL | |
12827 | * has the register indirect write enable bit set before | |
12828 | * we try to access any of the MMIO registers. It is also | |
12829 | * critical that the PCI-X hw workaround situation is decided | |
12830 | * before that as well. | |
12831 | */ | |
12832 | pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
12833 | &misc_ctrl_reg); | |
12834 | ||
12835 | tp->pci_chip_rev_id = (misc_ctrl_reg >> | |
12836 | MISC_HOST_CTRL_CHIPREV_SHIFT); | |
795d01c5 MC |
12837 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_USE_PROD_ID_REG) { |
12838 | u32 prod_id_asic_rev; | |
12839 | ||
5001e2f6 MC |
12840 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
12841 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || | |
a50d0796 MC |
12842 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5724 || |
12843 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719) | |
f6eb9b1f MC |
12844 | pci_read_config_dword(tp->pdev, |
12845 | TG3PCI_GEN2_PRODID_ASICREV, | |
12846 | &prod_id_asic_rev); | |
b703df6f MC |
12847 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781 || |
12848 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785 || | |
12849 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761 || | |
12850 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765 || | |
12851 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || | |
12852 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) | |
12853 | pci_read_config_dword(tp->pdev, | |
12854 | TG3PCI_GEN15_PRODID_ASICREV, | |
12855 | &prod_id_asic_rev); | |
f6eb9b1f MC |
12856 | else |
12857 | pci_read_config_dword(tp->pdev, TG3PCI_PRODID_ASICREV, | |
12858 | &prod_id_asic_rev); | |
12859 | ||
321d32a0 | 12860 | tp->pci_chip_rev_id = prod_id_asic_rev; |
795d01c5 | 12861 | } |
1da177e4 | 12862 | |
ff645bec MC |
12863 | /* Wrong chip ID in 5752 A0. This code can be removed later |
12864 | * as A0 is not in production. | |
12865 | */ | |
12866 | if (tp->pci_chip_rev_id == CHIPREV_ID_5752_A0_HW) | |
12867 | tp->pci_chip_rev_id = CHIPREV_ID_5752_A0; | |
12868 | ||
6892914f MC |
12869 | /* If we have 5702/03 A1 or A2 on certain ICH chipsets, |
12870 | * we need to disable memory and use config. cycles | |
12871 | * only to access all registers. The 5702/03 chips | |
12872 | * can mistakenly decode the special cycles from the | |
12873 | * ICH chipsets as memory write cycles, causing corruption | |
12874 | * of register and memory space. Only certain ICH bridges | |
12875 | * will drive special cycles with non-zero data during the | |
12876 | * address phase which can fall within the 5703's address | |
12877 | * range. This is not an ICH bug as the PCI spec allows | |
12878 | * non-zero address during special cycles. However, only | |
12879 | * these ICH bridges are known to drive non-zero addresses | |
12880 | * during special cycles. | |
12881 | * | |
12882 | * Since special cycles do not cross PCI bridges, we only | |
12883 | * enable this workaround if the 5703 is on the secondary | |
12884 | * bus of these ICH bridges. | |
12885 | */ | |
12886 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5703_A1) || | |
12887 | (tp->pci_chip_rev_id == CHIPREV_ID_5703_A2)) { | |
12888 | static struct tg3_dev_id { | |
12889 | u32 vendor; | |
12890 | u32 device; | |
12891 | u32 rev; | |
12892 | } ich_chipsets[] = { | |
12893 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8, | |
12894 | PCI_ANY_ID }, | |
12895 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8, | |
12896 | PCI_ANY_ID }, | |
12897 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11, | |
12898 | 0xa }, | |
12899 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6, | |
12900 | PCI_ANY_ID }, | |
12901 | { }, | |
12902 | }; | |
12903 | struct tg3_dev_id *pci_id = &ich_chipsets[0]; | |
12904 | struct pci_dev *bridge = NULL; | |
12905 | ||
12906 | while (pci_id->vendor != 0) { | |
12907 | bridge = pci_get_device(pci_id->vendor, pci_id->device, | |
12908 | bridge); | |
12909 | if (!bridge) { | |
12910 | pci_id++; | |
12911 | continue; | |
12912 | } | |
12913 | if (pci_id->rev != PCI_ANY_ID) { | |
44c10138 | 12914 | if (bridge->revision > pci_id->rev) |
6892914f MC |
12915 | continue; |
12916 | } | |
12917 | if (bridge->subordinate && | |
12918 | (bridge->subordinate->number == | |
12919 | tp->pdev->bus->number)) { | |
12920 | ||
12921 | tp->tg3_flags2 |= TG3_FLG2_ICH_WORKAROUND; | |
12922 | pci_dev_put(bridge); | |
12923 | break; | |
12924 | } | |
12925 | } | |
12926 | } | |
12927 | ||
41588ba1 MC |
12928 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701)) { |
12929 | static struct tg3_dev_id { | |
12930 | u32 vendor; | |
12931 | u32 device; | |
12932 | } bridge_chipsets[] = { | |
12933 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 }, | |
12934 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 }, | |
12935 | { }, | |
12936 | }; | |
12937 | struct tg3_dev_id *pci_id = &bridge_chipsets[0]; | |
12938 | struct pci_dev *bridge = NULL; | |
12939 | ||
12940 | while (pci_id->vendor != 0) { | |
12941 | bridge = pci_get_device(pci_id->vendor, | |
12942 | pci_id->device, | |
12943 | bridge); | |
12944 | if (!bridge) { | |
12945 | pci_id++; | |
12946 | continue; | |
12947 | } | |
12948 | if (bridge->subordinate && | |
12949 | (bridge->subordinate->number <= | |
12950 | tp->pdev->bus->number) && | |
12951 | (bridge->subordinate->subordinate >= | |
12952 | tp->pdev->bus->number)) { | |
12953 | tp->tg3_flags3 |= TG3_FLG3_5701_DMA_BUG; | |
12954 | pci_dev_put(bridge); | |
12955 | break; | |
12956 | } | |
12957 | } | |
12958 | } | |
12959 | ||
4a29cc2e MC |
12960 | /* The EPB bridge inside 5714, 5715, and 5780 cannot support |
12961 | * DMA addresses > 40-bit. This bridge may have other additional | |
12962 | * 57xx devices behind it in some 4-port NIC designs for example. | |
12963 | * Any tg3 device found behind the bridge will also need the 40-bit | |
12964 | * DMA workaround. | |
12965 | */ | |
a4e2b347 MC |
12966 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780 || |
12967 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { | |
12968 | tp->tg3_flags2 |= TG3_FLG2_5780_CLASS; | |
4a29cc2e | 12969 | tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG; |
4cf78e4f | 12970 | tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI); |
859a5887 | 12971 | } else { |
4a29cc2e MC |
12972 | struct pci_dev *bridge = NULL; |
12973 | ||
12974 | do { | |
12975 | bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, | |
12976 | PCI_DEVICE_ID_SERVERWORKS_EPB, | |
12977 | bridge); | |
12978 | if (bridge && bridge->subordinate && | |
12979 | (bridge->subordinate->number <= | |
12980 | tp->pdev->bus->number) && | |
12981 | (bridge->subordinate->subordinate >= | |
12982 | tp->pdev->bus->number)) { | |
12983 | tp->tg3_flags |= TG3_FLAG_40BIT_DMA_BUG; | |
12984 | pci_dev_put(bridge); | |
12985 | break; | |
12986 | } | |
12987 | } while (bridge); | |
12988 | } | |
4cf78e4f | 12989 | |
1da177e4 LT |
12990 | /* Initialize misc host control in PCI block. */ |
12991 | tp->misc_host_ctrl |= (misc_ctrl_reg & | |
12992 | MISC_HOST_CTRL_CHIPREV); | |
12993 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
12994 | tp->misc_host_ctrl); | |
12995 | ||
f6eb9b1f MC |
12996 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704 || |
12997 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 || | |
12998 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717) | |
7544b097 MC |
12999 | tp->pdev_peer = tg3_find_peer(tp); |
13000 | ||
c885e824 MC |
13001 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
13002 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || | |
13003 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) | |
13004 | tp->tg3_flags3 |= TG3_FLG3_5717_PLUS; | |
13005 | ||
321d32a0 MC |
13006 | /* Intentionally exclude ASIC_REV_5906 */ |
13007 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || | |
d9ab5ad1 | 13008 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
d30cdd28 | 13009 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
9936bcf6 | 13010 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
57e6983c | 13011 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
f6eb9b1f | 13012 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
c885e824 | 13013 | (tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) |
321d32a0 MC |
13014 | tp->tg3_flags3 |= TG3_FLG3_5755_PLUS; |
13015 | ||
13016 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || | |
13017 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || | |
b5d3772c | 13018 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906 || |
321d32a0 | 13019 | (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) || |
a4e2b347 | 13020 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
6708e5cc JL |
13021 | tp->tg3_flags2 |= TG3_FLG2_5750_PLUS; |
13022 | ||
1b440c56 JL |
13023 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) || |
13024 | (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)) | |
13025 | tp->tg3_flags2 |= TG3_FLG2_5705_PLUS; | |
13026 | ||
027455ad MC |
13027 | /* 5700 B0 chips do not support checksumming correctly due |
13028 | * to hardware bugs. | |
13029 | */ | |
13030 | if (tp->pci_chip_rev_id == CHIPREV_ID_5700_B0) | |
13031 | tp->tg3_flags |= TG3_FLAG_BROKEN_CHECKSUMS; | |
13032 | else { | |
7fe876af ED |
13033 | unsigned long features = NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_GRO; |
13034 | ||
027455ad | 13035 | tp->tg3_flags |= TG3_FLAG_RX_CHECKSUMS; |
027455ad | 13036 | if (tp->tg3_flags3 & TG3_FLG3_5755_PLUS) |
7fe876af ED |
13037 | features |= NETIF_F_IPV6_CSUM; |
13038 | tp->dev->features |= features; | |
13039 | vlan_features_add(tp->dev, features); | |
027455ad MC |
13040 | } |
13041 | ||
507399f1 | 13042 | /* Determine TSO capabilities */ |
c885e824 | 13043 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) |
e849cdc3 MC |
13044 | tp->tg3_flags2 |= TG3_FLG2_HW_TSO_3; |
13045 | else if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) || | |
13046 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) | |
507399f1 MC |
13047 | tp->tg3_flags2 |= TG3_FLG2_HW_TSO_2; |
13048 | else if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { | |
13049 | tp->tg3_flags2 |= TG3_FLG2_HW_TSO_1 | TG3_FLG2_TSO_BUG; | |
13050 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 && | |
13051 | tp->pci_chip_rev_id >= CHIPREV_ID_5750_C2) | |
13052 | tp->tg3_flags2 &= ~TG3_FLG2_TSO_BUG; | |
13053 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && | |
13054 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && | |
13055 | tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) { | |
13056 | tp->tg3_flags2 |= TG3_FLG2_TSO_BUG; | |
13057 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) | |
13058 | tp->fw_needed = FIRMWARE_TG3TSO5; | |
13059 | else | |
13060 | tp->fw_needed = FIRMWARE_TG3TSO; | |
13061 | } | |
13062 | ||
13063 | tp->irq_max = 1; | |
13064 | ||
5a6f3074 | 13065 | if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS) { |
7544b097 MC |
13066 | tp->tg3_flags |= TG3_FLAG_SUPPORT_MSI; |
13067 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_AX || | |
13068 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5750_BX || | |
13069 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714 && | |
13070 | tp->pci_chip_rev_id <= CHIPREV_ID_5714_A2 && | |
13071 | tp->pdev_peer == tp->pdev)) | |
13072 | tp->tg3_flags &= ~TG3_FLAG_SUPPORT_MSI; | |
13073 | ||
321d32a0 | 13074 | if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) || |
b5d3772c | 13075 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
fcfa0a32 | 13076 | tp->tg3_flags2 |= TG3_FLG2_1SHOT_MSI; |
52c0fd83 | 13077 | } |
4f125f42 | 13078 | |
c885e824 | 13079 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
507399f1 MC |
13080 | tp->tg3_flags |= TG3_FLAG_SUPPORT_MSIX; |
13081 | tp->irq_max = TG3_IRQ_MAX_VECS; | |
13082 | } | |
f6eb9b1f | 13083 | } |
0e1406dd | 13084 | |
615774fe | 13085 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
a50d0796 | 13086 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719 || |
615774fe MC |
13087 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
13088 | tp->tg3_flags3 |= TG3_FLG3_SHORT_DMA_BUG; | |
13089 | else if (!(tp->tg3_flags3 & TG3_FLG3_5755_PLUS)) { | |
13090 | tp->tg3_flags3 |= TG3_FLG3_4G_DMA_BNDRY_BUG; | |
13091 | tp->tg3_flags3 |= TG3_FLG3_40BIT_DMA_LIMIT_BUG; | |
0e1406dd | 13092 | } |
f6eb9b1f | 13093 | |
c885e824 | 13094 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) |
b703df6f MC |
13095 | tp->tg3_flags3 |= TG3_FLG3_USE_JUMBO_BDFLAG; |
13096 | ||
f51f3562 | 13097 | if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) || |
c6cdf436 MC |
13098 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) || |
13099 | (tp->tg3_flags3 & TG3_FLG3_USE_JUMBO_BDFLAG)) | |
8f666b07 | 13100 | tp->tg3_flags |= TG3_FLAG_JUMBO_CAPABLE; |
0f893dc6 | 13101 | |
52f4490c MC |
13102 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
13103 | &pci_state_reg); | |
13104 | ||
5e7dfd0f MC |
13105 | tp->pcie_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_EXP); |
13106 | if (tp->pcie_cap != 0) { | |
13107 | u16 lnkctl; | |
13108 | ||
1da177e4 | 13109 | tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS; |
5f5c51e3 MC |
13110 | |
13111 | pcie_set_readrq(tp->pdev, 4096); | |
13112 | ||
5e7dfd0f MC |
13113 | pci_read_config_word(tp->pdev, |
13114 | tp->pcie_cap + PCI_EXP_LNKCTL, | |
13115 | &lnkctl); | |
13116 | if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) { | |
13117 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) | |
c7835a77 | 13118 | tp->tg3_flags2 &= ~TG3_FLG2_HW_TSO_2; |
5e7dfd0f | 13119 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
321d32a0 | 13120 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
9cf74ebb MC |
13121 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A0 || |
13122 | tp->pci_chip_rev_id == CHIPREV_ID_57780_A1) | |
5e7dfd0f | 13123 | tp->tg3_flags3 |= TG3_FLG3_CLKREQ_BUG; |
614b0590 MC |
13124 | } else if (tp->pci_chip_rev_id == CHIPREV_ID_5717_A0) { |
13125 | tp->tg3_flags3 |= TG3_FLG3_L1PLLPD_EN; | |
c7835a77 | 13126 | } |
52f4490c | 13127 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785) { |
fcb389df | 13128 | tp->tg3_flags2 |= TG3_FLG2_PCI_EXPRESS; |
52f4490c MC |
13129 | } else if (!(tp->tg3_flags2 & TG3_FLG2_5705_PLUS) || |
13130 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { | |
13131 | tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX); | |
13132 | if (!tp->pcix_cap) { | |
2445e461 MC |
13133 | dev_err(&tp->pdev->dev, |
13134 | "Cannot find PCI-X capability, aborting\n"); | |
52f4490c MC |
13135 | return -EIO; |
13136 | } | |
13137 | ||
13138 | if (!(pci_state_reg & PCISTATE_CONV_PCI_MODE)) | |
13139 | tp->tg3_flags |= TG3_FLAG_PCIX_MODE; | |
13140 | } | |
1da177e4 | 13141 | |
399de50b MC |
13142 | /* If we have an AMD 762 or VIA K8T800 chipset, write |
13143 | * reordering to the mailbox registers done by the host | |
13144 | * controller can cause major troubles. We read back from | |
13145 | * every mailbox register write to force the writes to be | |
13146 | * posted to the chip in order. | |
13147 | */ | |
13148 | if (pci_dev_present(write_reorder_chipsets) && | |
13149 | !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) | |
13150 | tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER; | |
13151 | ||
69fc4053 MC |
13152 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
13153 | &tp->pci_cacheline_sz); | |
13154 | pci_read_config_byte(tp->pdev, PCI_LATENCY_TIMER, | |
13155 | &tp->pci_lat_timer); | |
1da177e4 LT |
13156 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && |
13157 | tp->pci_lat_timer < 64) { | |
13158 | tp->pci_lat_timer = 64; | |
69fc4053 MC |
13159 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
13160 | tp->pci_lat_timer); | |
1da177e4 LT |
13161 | } |
13162 | ||
52f4490c MC |
13163 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5700_BX) { |
13164 | /* 5700 BX chips need to have their TX producer index | |
13165 | * mailboxes written twice to workaround a bug. | |
13166 | */ | |
13167 | tp->tg3_flags |= TG3_FLAG_TXD_MBOX_HWBUG; | |
1da177e4 | 13168 | |
52f4490c | 13169 | /* If we are in PCI-X mode, enable register write workaround. |
1da177e4 LT |
13170 | * |
13171 | * The workaround is to use indirect register accesses | |
13172 | * for all chip writes not to mailbox registers. | |
13173 | */ | |
52f4490c | 13174 | if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) { |
1da177e4 | 13175 | u32 pm_reg; |
1da177e4 LT |
13176 | |
13177 | tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG; | |
13178 | ||
13179 | /* The chip can have it's power management PCI config | |
13180 | * space registers clobbered due to this bug. | |
13181 | * So explicitly force the chip into D0 here. | |
13182 | */ | |
9974a356 MC |
13183 | pci_read_config_dword(tp->pdev, |
13184 | tp->pm_cap + PCI_PM_CTRL, | |
1da177e4 LT |
13185 | &pm_reg); |
13186 | pm_reg &= ~PCI_PM_CTRL_STATE_MASK; | |
13187 | pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */; | |
9974a356 MC |
13188 | pci_write_config_dword(tp->pdev, |
13189 | tp->pm_cap + PCI_PM_CTRL, | |
1da177e4 LT |
13190 | pm_reg); |
13191 | ||
13192 | /* Also, force SERR#/PERR# in PCI command. */ | |
13193 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); | |
13194 | pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; | |
13195 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); | |
13196 | } | |
13197 | } | |
13198 | ||
1da177e4 LT |
13199 | if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0) |
13200 | tp->tg3_flags |= TG3_FLAG_PCI_HIGH_SPEED; | |
13201 | if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0) | |
13202 | tp->tg3_flags |= TG3_FLAG_PCI_32BIT; | |
13203 | ||
13204 | /* Chip-specific fixup from Broadcom driver */ | |
13205 | if ((tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) && | |
13206 | (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) { | |
13207 | pci_state_reg |= PCISTATE_RETRY_SAME_DMA; | |
13208 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg); | |
13209 | } | |
13210 | ||
1ee582d8 | 13211 | /* Default fast path register access methods */ |
20094930 | 13212 | tp->read32 = tg3_read32; |
1ee582d8 | 13213 | tp->write32 = tg3_write32; |
09ee929c | 13214 | tp->read32_mbox = tg3_read32; |
20094930 | 13215 | tp->write32_mbox = tg3_write32; |
1ee582d8 MC |
13216 | tp->write32_tx_mbox = tg3_write32; |
13217 | tp->write32_rx_mbox = tg3_write32; | |
13218 | ||
13219 | /* Various workaround register access methods */ | |
13220 | if (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) | |
13221 | tp->write32 = tg3_write_indirect_reg32; | |
98efd8a6 MC |
13222 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 || |
13223 | ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) && | |
13224 | tp->pci_chip_rev_id == CHIPREV_ID_5750_A0)) { | |
13225 | /* | |
13226 | * Back to back register writes can cause problems on these | |
13227 | * chips, the workaround is to read back all reg writes | |
13228 | * except those to mailbox regs. | |
13229 | * | |
13230 | * See tg3_write_indirect_reg32(). | |
13231 | */ | |
1ee582d8 | 13232 | tp->write32 = tg3_write_flush_reg32; |
98efd8a6 MC |
13233 | } |
13234 | ||
1ee582d8 MC |
13235 | if ((tp->tg3_flags & TG3_FLAG_TXD_MBOX_HWBUG) || |
13236 | (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER)) { | |
13237 | tp->write32_tx_mbox = tg3_write32_tx_mbox; | |
13238 | if (tp->tg3_flags & TG3_FLAG_MBOX_WRITE_REORDER) | |
13239 | tp->write32_rx_mbox = tg3_write_flush_reg32; | |
13240 | } | |
20094930 | 13241 | |
6892914f MC |
13242 | if (tp->tg3_flags2 & TG3_FLG2_ICH_WORKAROUND) { |
13243 | tp->read32 = tg3_read_indirect_reg32; | |
13244 | tp->write32 = tg3_write_indirect_reg32; | |
13245 | tp->read32_mbox = tg3_read_indirect_mbox; | |
13246 | tp->write32_mbox = tg3_write_indirect_mbox; | |
13247 | tp->write32_tx_mbox = tg3_write_indirect_mbox; | |
13248 | tp->write32_rx_mbox = tg3_write_indirect_mbox; | |
13249 | ||
13250 | iounmap(tp->regs); | |
22abe310 | 13251 | tp->regs = NULL; |
6892914f MC |
13252 | |
13253 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); | |
13254 | pci_cmd &= ~PCI_COMMAND_MEMORY; | |
13255 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); | |
13256 | } | |
b5d3772c MC |
13257 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
13258 | tp->read32_mbox = tg3_read32_mbox_5906; | |
13259 | tp->write32_mbox = tg3_write32_mbox_5906; | |
13260 | tp->write32_tx_mbox = tg3_write32_mbox_5906; | |
13261 | tp->write32_rx_mbox = tg3_write32_mbox_5906; | |
13262 | } | |
6892914f | 13263 | |
bbadf503 MC |
13264 | if (tp->write32 == tg3_write_indirect_reg32 || |
13265 | ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) && | |
13266 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
f49639e6 | 13267 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701))) |
bbadf503 MC |
13268 | tp->tg3_flags |= TG3_FLAG_SRAM_USE_CONFIG; |
13269 | ||
7d0c41ef | 13270 | /* Get eeprom hw config before calling tg3_set_power_state(). |
9d26e213 | 13271 | * In particular, the TG3_FLG2_IS_NIC flag must be |
7d0c41ef MC |
13272 | * determined before calling tg3_set_power_state() so that |
13273 | * we know whether or not to switch out of Vaux power. | |
13274 | * When the flag is set, it means that GPIO1 is used for eeprom | |
13275 | * write protect and also implies that it is a LOM where GPIOs | |
13276 | * are not used to switch power. | |
6aa20a22 | 13277 | */ |
7d0c41ef MC |
13278 | tg3_get_eeprom_hw_cfg(tp); |
13279 | ||
0d3031d9 MC |
13280 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
13281 | /* Allow reads and writes to the | |
13282 | * APE register and memory space. | |
13283 | */ | |
13284 | pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR | | |
f92d9dc1 MC |
13285 | PCISTATE_ALLOW_APE_SHMEM_WR | |
13286 | PCISTATE_ALLOW_APE_PSPACE_WR; | |
0d3031d9 MC |
13287 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, |
13288 | pci_state_reg); | |
13289 | } | |
13290 | ||
9936bcf6 | 13291 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
57e6983c | 13292 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || |
321d32a0 | 13293 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
f6eb9b1f | 13294 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
c885e824 | 13295 | (tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) |
d30cdd28 MC |
13296 | tp->tg3_flags |= TG3_FLAG_CPMU_PRESENT; |
13297 | ||
314fba34 MC |
13298 | /* Set up tp->grc_local_ctrl before calling tg3_set_power_state(). |
13299 | * GPIO1 driven high will bring 5700's external PHY out of reset. | |
13300 | * It is also used as eeprom write protect on LOMs. | |
13301 | */ | |
13302 | tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM; | |
13303 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) || | |
13304 | (tp->tg3_flags & TG3_FLAG_EEPROM_WRITE_PROT)) | |
13305 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | | |
13306 | GRC_LCLCTRL_GPIO_OUTPUT1); | |
3e7d83bc MC |
13307 | /* Unused GPIO3 must be driven as output on 5752 because there |
13308 | * are no pull-up resistors on unused GPIO pins. | |
13309 | */ | |
13310 | else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752) | |
13311 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; | |
314fba34 | 13312 | |
321d32a0 | 13313 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
cb4ed1fd MC |
13314 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780 || |
13315 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57765) | |
af36e6b6 MC |
13316 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
13317 | ||
8d519ab2 MC |
13318 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
13319 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { | |
5f0c4a3c MC |
13320 | /* Turn off the debug UART. */ |
13321 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; | |
13322 | if (tp->tg3_flags2 & TG3_FLG2_IS_NIC) | |
13323 | /* Keep VMain power. */ | |
13324 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | | |
13325 | GRC_LCLCTRL_GPIO_OUTPUT0; | |
13326 | } | |
13327 | ||
1da177e4 | 13328 | /* Force the chip into D0. */ |
bc1c7567 | 13329 | err = tg3_set_power_state(tp, PCI_D0); |
1da177e4 | 13330 | if (err) { |
2445e461 | 13331 | dev_err(&tp->pdev->dev, "Transition to D0 failed\n"); |
1da177e4 LT |
13332 | return err; |
13333 | } | |
13334 | ||
1da177e4 LT |
13335 | /* Derive initial jumbo mode from MTU assigned in |
13336 | * ether_setup() via the alloc_etherdev() call | |
13337 | */ | |
0f893dc6 | 13338 | if (tp->dev->mtu > ETH_DATA_LEN && |
a4e2b347 | 13339 | !(tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) |
0f893dc6 | 13340 | tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE; |
1da177e4 LT |
13341 | |
13342 | /* Determine WakeOnLan speed to use. */ | |
13343 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
13344 | tp->pci_chip_rev_id == CHIPREV_ID_5701_A0 || | |
13345 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B0 || | |
13346 | tp->pci_chip_rev_id == CHIPREV_ID_5701_B2) { | |
13347 | tp->tg3_flags &= ~(TG3_FLAG_WOL_SPEED_100MB); | |
13348 | } else { | |
13349 | tp->tg3_flags |= TG3_FLAG_WOL_SPEED_100MB; | |
13350 | } | |
13351 | ||
7f97a4bd | 13352 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
f07e9af3 | 13353 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
7f97a4bd | 13354 | |
1da177e4 LT |
13355 | /* A few boards don't want Ethernet@WireSpeed phy feature */ |
13356 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) || | |
13357 | ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705) && | |
13358 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A0) && | |
747e8f8b | 13359 | (tp->pci_chip_rev_id != CHIPREV_ID_5705_A1)) || |
f07e9af3 MC |
13360 | (tp->phy_flags & TG3_PHYFLG_IS_FET) || |
13361 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) | |
13362 | tp->phy_flags |= TG3_PHYFLG_NO_ETH_WIRE_SPEED; | |
1da177e4 LT |
13363 | |
13364 | if (GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5703_AX || | |
13365 | GET_CHIP_REV(tp->pci_chip_rev_id) == CHIPREV_5704_AX) | |
f07e9af3 | 13366 | tp->phy_flags |= TG3_PHYFLG_ADC_BUG; |
1da177e4 | 13367 | if (tp->pci_chip_rev_id == CHIPREV_ID_5704_A0) |
f07e9af3 | 13368 | tp->phy_flags |= TG3_PHYFLG_5704_A0_BUG; |
1da177e4 | 13369 | |
321d32a0 | 13370 | if ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) && |
f07e9af3 | 13371 | !(tp->phy_flags & TG3_PHYFLG_IS_FET) && |
321d32a0 | 13372 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5785 && |
f6eb9b1f | 13373 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_57780 && |
c885e824 | 13374 | !(tp->tg3_flags3 & TG3_FLG3_5717_PLUS)) { |
c424cb24 | 13375 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 || |
d30cdd28 | 13376 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787 || |
9936bcf6 MC |
13377 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 || |
13378 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761) { | |
d4011ada MC |
13379 | if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 && |
13380 | tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722) | |
f07e9af3 | 13381 | tp->phy_flags |= TG3_PHYFLG_JITTER_BUG; |
c1d2a196 | 13382 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M) |
f07e9af3 | 13383 | tp->phy_flags |= TG3_PHYFLG_ADJUST_TRIM; |
321d32a0 | 13384 | } else |
f07e9af3 | 13385 | tp->phy_flags |= TG3_PHYFLG_BER_BUG; |
c424cb24 | 13386 | } |
1da177e4 | 13387 | |
b2a5c19c MC |
13388 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
13389 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) { | |
13390 | tp->phy_otp = tg3_read_otp_phycfg(tp); | |
13391 | if (tp->phy_otp == 0) | |
13392 | tp->phy_otp = TG3_OTP_DEFAULT; | |
13393 | } | |
13394 | ||
f51f3562 | 13395 | if (tp->tg3_flags & TG3_FLAG_CPMU_PRESENT) |
8ef21428 MC |
13396 | tp->mi_mode = MAC_MI_MODE_500KHZ_CONST; |
13397 | else | |
13398 | tp->mi_mode = MAC_MI_MODE_BASE; | |
13399 | ||
1da177e4 | 13400 | tp->coalesce_mode = 0; |
1da177e4 LT |
13401 | if (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_AX && |
13402 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5700_BX) | |
13403 | tp->coalesce_mode |= HOSTCC_MODE_32BYTE; | |
13404 | ||
321d32a0 MC |
13405 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
13406 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) | |
57e6983c MC |
13407 | tp->tg3_flags3 |= TG3_FLG3_USE_PHYLIB; |
13408 | ||
158d7abd MC |
13409 | err = tg3_mdio_init(tp); |
13410 | if (err) | |
13411 | return err; | |
1da177e4 | 13412 | |
55dffe79 | 13413 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 && |
2138c002 | 13414 | tp->pci_chip_rev_id != CHIPREV_ID_5717_A0) |
55dffe79 MC |
13415 | return -ENOTSUPP; |
13416 | ||
1da177e4 LT |
13417 | /* Initialize data/descriptor byte/word swapping. */ |
13418 | val = tr32(GRC_MODE); | |
13419 | val &= GRC_MODE_HOST_STACKUP; | |
13420 | tw32(GRC_MODE, val | tp->grc_mode); | |
13421 | ||
13422 | tg3_switch_clocks(tp); | |
13423 | ||
13424 | /* Clear this out for sanity. */ | |
13425 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
13426 | ||
13427 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, | |
13428 | &pci_state_reg); | |
13429 | if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 && | |
13430 | (tp->tg3_flags & TG3_FLAG_PCIX_TARGET_HWBUG) == 0) { | |
13431 | u32 chiprevid = GET_CHIP_REV_ID(tp->misc_host_ctrl); | |
13432 | ||
13433 | if (chiprevid == CHIPREV_ID_5701_A0 || | |
13434 | chiprevid == CHIPREV_ID_5701_B0 || | |
13435 | chiprevid == CHIPREV_ID_5701_B2 || | |
13436 | chiprevid == CHIPREV_ID_5701_B5) { | |
13437 | void __iomem *sram_base; | |
13438 | ||
13439 | /* Write some dummy words into the SRAM status block | |
13440 | * area, see if it reads back correctly. If the return | |
13441 | * value is bad, force enable the PCIX workaround. | |
13442 | */ | |
13443 | sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK; | |
13444 | ||
13445 | writel(0x00000000, sram_base); | |
13446 | writel(0x00000000, sram_base + 4); | |
13447 | writel(0xffffffff, sram_base + 4); | |
13448 | if (readl(sram_base) != 0x00000000) | |
13449 | tp->tg3_flags |= TG3_FLAG_PCIX_TARGET_HWBUG; | |
13450 | } | |
13451 | } | |
13452 | ||
13453 | udelay(50); | |
13454 | tg3_nvram_init(tp); | |
13455 | ||
13456 | grc_misc_cfg = tr32(GRC_MISC_CFG); | |
13457 | grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK; | |
13458 | ||
1da177e4 LT |
13459 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && |
13460 | (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 || | |
13461 | grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M)) | |
13462 | tp->tg3_flags2 |= TG3_FLG2_IS_5788; | |
13463 | ||
fac9b83e DM |
13464 | if (!(tp->tg3_flags2 & TG3_FLG2_IS_5788) && |
13465 | (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700)) | |
13466 | tp->tg3_flags |= TG3_FLAG_TAGGED_STATUS; | |
13467 | if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) { | |
13468 | tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD | | |
13469 | HOSTCC_MODE_CLRTICK_TXBD); | |
13470 | ||
13471 | tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS; | |
13472 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
13473 | tp->misc_host_ctrl); | |
13474 | } | |
13475 | ||
3bda1258 MC |
13476 | /* Preserve the APE MAC_MODE bits */ |
13477 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) | |
13478 | tp->mac_mode = tr32(MAC_MODE) | | |
13479 | MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; | |
13480 | else | |
13481 | tp->mac_mode = TG3_DEF_MAC_MODE; | |
13482 | ||
1da177e4 LT |
13483 | /* these are limited to 10/100 only */ |
13484 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 && | |
13485 | (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) || | |
13486 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 && | |
13487 | tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && | |
13488 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901 || | |
13489 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5901_2 || | |
13490 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5705F)) || | |
13491 | (tp->pdev->vendor == PCI_VENDOR_ID_BROADCOM && | |
13492 | (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5751F || | |
676917d4 MC |
13493 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5753F || |
13494 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5787F)) || | |
321d32a0 | 13495 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790 || |
d1101142 MC |
13496 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || |
13497 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 || | |
f07e9af3 MC |
13498 | (tp->phy_flags & TG3_PHYFLG_IS_FET)) |
13499 | tp->phy_flags |= TG3_PHYFLG_10_100_ONLY; | |
1da177e4 LT |
13500 | |
13501 | err = tg3_phy_probe(tp); | |
13502 | if (err) { | |
2445e461 | 13503 | dev_err(&tp->pdev->dev, "phy probe failed, err %d\n", err); |
1da177e4 | 13504 | /* ... but do not return immediately ... */ |
b02fd9e3 | 13505 | tg3_mdio_fini(tp); |
1da177e4 LT |
13506 | } |
13507 | ||
184b8904 | 13508 | tg3_read_vpd(tp); |
c4e6575c | 13509 | tg3_read_fw_ver(tp); |
1da177e4 | 13510 | |
f07e9af3 MC |
13511 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
13512 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; | |
1da177e4 LT |
13513 | } else { |
13514 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) | |
f07e9af3 | 13515 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
1da177e4 | 13516 | else |
f07e9af3 | 13517 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
1da177e4 LT |
13518 | } |
13519 | ||
13520 | /* 5700 {AX,BX} chips have a broken status block link | |
13521 | * change bit implementation, so we must use the | |
13522 | * status register in those cases. | |
13523 | */ | |
13524 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700) | |
13525 | tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG; | |
13526 | else | |
13527 | tp->tg3_flags &= ~TG3_FLAG_USE_LINKCHG_REG; | |
13528 | ||
13529 | /* The led_ctrl is set during tg3_phy_probe, here we might | |
13530 | * have to force the link status polling mechanism based | |
13531 | * upon subsystem IDs. | |
13532 | */ | |
13533 | if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL && | |
007a880d | 13534 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
f07e9af3 MC |
13535 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
13536 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; | |
13537 | tp->tg3_flags |= TG3_FLAG_USE_LINKCHG_REG; | |
1da177e4 LT |
13538 | } |
13539 | ||
13540 | /* For all SERDES we poll the MAC status register. */ | |
f07e9af3 | 13541 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
1da177e4 LT |
13542 | tp->tg3_flags |= TG3_FLAG_POLL_SERDES; |
13543 | else | |
13544 | tp->tg3_flags &= ~TG3_FLAG_POLL_SERDES; | |
13545 | ||
9dc7a113 | 13546 | tp->rx_offset = NET_IP_ALIGN + TG3_RX_HEADROOM; |
d2757fc4 | 13547 | tp->rx_copy_thresh = TG3_RX_COPY_THRESHOLD; |
1da177e4 | 13548 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701 && |
d2757fc4 | 13549 | (tp->tg3_flags & TG3_FLAG_PCIX_MODE) != 0) { |
9dc7a113 | 13550 | tp->rx_offset -= NET_IP_ALIGN; |
d2757fc4 | 13551 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
9dc7a113 | 13552 | tp->rx_copy_thresh = ~(u16)0; |
d2757fc4 MC |
13553 | #endif |
13554 | } | |
1da177e4 | 13555 | |
f92905de MC |
13556 | tp->rx_std_max_post = TG3_RX_RING_SIZE; |
13557 | ||
13558 | /* Increment the rx prod index on the rx std ring by at most | |
13559 | * 8 for these chips to workaround hw errata. | |
13560 | */ | |
13561 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750 || | |
13562 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5752 || | |
13563 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755) | |
13564 | tp->rx_std_max_post = 8; | |
13565 | ||
8ed5d97e MC |
13566 | if (tp->tg3_flags & TG3_FLAG_ASPM_WORKAROUND) |
13567 | tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) & | |
13568 | PCIE_PWR_MGMT_L1_THRESH_MSK; | |
13569 | ||
1da177e4 LT |
13570 | return err; |
13571 | } | |
13572 | ||
49b6e95f | 13573 | #ifdef CONFIG_SPARC |
1da177e4 LT |
13574 | static int __devinit tg3_get_macaddr_sparc(struct tg3 *tp) |
13575 | { | |
13576 | struct net_device *dev = tp->dev; | |
13577 | struct pci_dev *pdev = tp->pdev; | |
49b6e95f | 13578 | struct device_node *dp = pci_device_to_OF_node(pdev); |
374d4cac | 13579 | const unsigned char *addr; |
49b6e95f DM |
13580 | int len; |
13581 | ||
13582 | addr = of_get_property(dp, "local-mac-address", &len); | |
13583 | if (addr && len == 6) { | |
13584 | memcpy(dev->dev_addr, addr, 6); | |
13585 | memcpy(dev->perm_addr, dev->dev_addr, 6); | |
13586 | return 0; | |
1da177e4 LT |
13587 | } |
13588 | return -ENODEV; | |
13589 | } | |
13590 | ||
13591 | static int __devinit tg3_get_default_macaddr_sparc(struct tg3 *tp) | |
13592 | { | |
13593 | struct net_device *dev = tp->dev; | |
13594 | ||
13595 | memcpy(dev->dev_addr, idprom->id_ethaddr, 6); | |
2ff43697 | 13596 | memcpy(dev->perm_addr, idprom->id_ethaddr, 6); |
1da177e4 LT |
13597 | return 0; |
13598 | } | |
13599 | #endif | |
13600 | ||
13601 | static int __devinit tg3_get_device_address(struct tg3 *tp) | |
13602 | { | |
13603 | struct net_device *dev = tp->dev; | |
13604 | u32 hi, lo, mac_offset; | |
008652b3 | 13605 | int addr_ok = 0; |
1da177e4 | 13606 | |
49b6e95f | 13607 | #ifdef CONFIG_SPARC |
1da177e4 LT |
13608 | if (!tg3_get_macaddr_sparc(tp)) |
13609 | return 0; | |
13610 | #endif | |
13611 | ||
13612 | mac_offset = 0x7c; | |
f49639e6 | 13613 | if ((GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) || |
a4e2b347 | 13614 | (tp->tg3_flags2 & TG3_FLG2_5780_CLASS)) { |
1da177e4 LT |
13615 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
13616 | mac_offset = 0xcc; | |
13617 | if (tg3_nvram_lock(tp)) | |
13618 | tw32_f(NVRAM_CMD, NVRAM_CMD_RESET); | |
13619 | else | |
13620 | tg3_nvram_unlock(tp); | |
a50d0796 MC |
13621 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5717 || |
13622 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5719) { | |
13623 | if (PCI_FUNC(tp->pdev->devfn) & 1) | |
a1b950d5 | 13624 | mac_offset = 0xcc; |
a50d0796 MC |
13625 | if (PCI_FUNC(tp->pdev->devfn) > 1) |
13626 | mac_offset += 0x18c; | |
a1b950d5 | 13627 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) |
b5d3772c | 13628 | mac_offset = 0x10; |
1da177e4 LT |
13629 | |
13630 | /* First try to get it from MAC address mailbox. */ | |
13631 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi); | |
13632 | if ((hi >> 16) == 0x484b) { | |
13633 | dev->dev_addr[0] = (hi >> 8) & 0xff; | |
13634 | dev->dev_addr[1] = (hi >> 0) & 0xff; | |
13635 | ||
13636 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo); | |
13637 | dev->dev_addr[2] = (lo >> 24) & 0xff; | |
13638 | dev->dev_addr[3] = (lo >> 16) & 0xff; | |
13639 | dev->dev_addr[4] = (lo >> 8) & 0xff; | |
13640 | dev->dev_addr[5] = (lo >> 0) & 0xff; | |
1da177e4 | 13641 | |
008652b3 MC |
13642 | /* Some old bootcode may report a 0 MAC address in SRAM */ |
13643 | addr_ok = is_valid_ether_addr(&dev->dev_addr[0]); | |
13644 | } | |
13645 | if (!addr_ok) { | |
13646 | /* Next, try NVRAM. */ | |
df259d8c MC |
13647 | if (!(tp->tg3_flags3 & TG3_FLG3_NO_NVRAM) && |
13648 | !tg3_nvram_read_be32(tp, mac_offset + 0, &hi) && | |
6d348f2c | 13649 | !tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) { |
62cedd11 MC |
13650 | memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2); |
13651 | memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo)); | |
008652b3 MC |
13652 | } |
13653 | /* Finally just fetch it out of the MAC control regs. */ | |
13654 | else { | |
13655 | hi = tr32(MAC_ADDR_0_HIGH); | |
13656 | lo = tr32(MAC_ADDR_0_LOW); | |
13657 | ||
13658 | dev->dev_addr[5] = lo & 0xff; | |
13659 | dev->dev_addr[4] = (lo >> 8) & 0xff; | |
13660 | dev->dev_addr[3] = (lo >> 16) & 0xff; | |
13661 | dev->dev_addr[2] = (lo >> 24) & 0xff; | |
13662 | dev->dev_addr[1] = hi & 0xff; | |
13663 | dev->dev_addr[0] = (hi >> 8) & 0xff; | |
13664 | } | |
1da177e4 LT |
13665 | } |
13666 | ||
13667 | if (!is_valid_ether_addr(&dev->dev_addr[0])) { | |
7582a335 | 13668 | #ifdef CONFIG_SPARC |
1da177e4 LT |
13669 | if (!tg3_get_default_macaddr_sparc(tp)) |
13670 | return 0; | |
13671 | #endif | |
13672 | return -EINVAL; | |
13673 | } | |
2ff43697 | 13674 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
1da177e4 LT |
13675 | return 0; |
13676 | } | |
13677 | ||
59e6b434 DM |
13678 | #define BOUNDARY_SINGLE_CACHELINE 1 |
13679 | #define BOUNDARY_MULTI_CACHELINE 2 | |
13680 | ||
13681 | static u32 __devinit tg3_calc_dma_bndry(struct tg3 *tp, u32 val) | |
13682 | { | |
13683 | int cacheline_size; | |
13684 | u8 byte; | |
13685 | int goal; | |
13686 | ||
13687 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte); | |
13688 | if (byte == 0) | |
13689 | cacheline_size = 1024; | |
13690 | else | |
13691 | cacheline_size = (int) byte * 4; | |
13692 | ||
13693 | /* On 5703 and later chips, the boundary bits have no | |
13694 | * effect. | |
13695 | */ | |
13696 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && | |
13697 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701 && | |
13698 | !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) | |
13699 | goto out; | |
13700 | ||
13701 | #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC) | |
13702 | goal = BOUNDARY_MULTI_CACHELINE; | |
13703 | #else | |
13704 | #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA) | |
13705 | goal = BOUNDARY_SINGLE_CACHELINE; | |
13706 | #else | |
13707 | goal = 0; | |
13708 | #endif | |
13709 | #endif | |
13710 | ||
c885e824 | 13711 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
cbf9ca6c MC |
13712 | val = goal ? 0 : DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
13713 | goto out; | |
13714 | } | |
13715 | ||
59e6b434 DM |
13716 | if (!goal) |
13717 | goto out; | |
13718 | ||
13719 | /* PCI controllers on most RISC systems tend to disconnect | |
13720 | * when a device tries to burst across a cache-line boundary. | |
13721 | * Therefore, letting tg3 do so just wastes PCI bandwidth. | |
13722 | * | |
13723 | * Unfortunately, for PCI-E there are only limited | |
13724 | * write-side controls for this, and thus for reads | |
13725 | * we will still get the disconnects. We'll also waste | |
13726 | * these PCI cycles for both read and write for chips | |
13727 | * other than 5700 and 5701 which do not implement the | |
13728 | * boundary bits. | |
13729 | */ | |
13730 | if ((tp->tg3_flags & TG3_FLAG_PCIX_MODE) && | |
13731 | !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS)) { | |
13732 | switch (cacheline_size) { | |
13733 | case 16: | |
13734 | case 32: | |
13735 | case 64: | |
13736 | case 128: | |
13737 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
13738 | val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX | | |
13739 | DMA_RWCTRL_WRITE_BNDRY_128_PCIX); | |
13740 | } else { | |
13741 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | | |
13742 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); | |
13743 | } | |
13744 | break; | |
13745 | ||
13746 | case 256: | |
13747 | val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX | | |
13748 | DMA_RWCTRL_WRITE_BNDRY_256_PCIX); | |
13749 | break; | |
13750 | ||
13751 | default: | |
13752 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | | |
13753 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); | |
13754 | break; | |
855e1111 | 13755 | } |
59e6b434 DM |
13756 | } else if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { |
13757 | switch (cacheline_size) { | |
13758 | case 16: | |
13759 | case 32: | |
13760 | case 64: | |
13761 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
13762 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; | |
13763 | val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE; | |
13764 | break; | |
13765 | } | |
13766 | /* fallthrough */ | |
13767 | case 128: | |
13768 | default: | |
13769 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; | |
13770 | val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE; | |
13771 | break; | |
855e1111 | 13772 | } |
59e6b434 DM |
13773 | } else { |
13774 | switch (cacheline_size) { | |
13775 | case 16: | |
13776 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
13777 | val |= (DMA_RWCTRL_READ_BNDRY_16 | | |
13778 | DMA_RWCTRL_WRITE_BNDRY_16); | |
13779 | break; | |
13780 | } | |
13781 | /* fallthrough */ | |
13782 | case 32: | |
13783 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
13784 | val |= (DMA_RWCTRL_READ_BNDRY_32 | | |
13785 | DMA_RWCTRL_WRITE_BNDRY_32); | |
13786 | break; | |
13787 | } | |
13788 | /* fallthrough */ | |
13789 | case 64: | |
13790 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
13791 | val |= (DMA_RWCTRL_READ_BNDRY_64 | | |
13792 | DMA_RWCTRL_WRITE_BNDRY_64); | |
13793 | break; | |
13794 | } | |
13795 | /* fallthrough */ | |
13796 | case 128: | |
13797 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
13798 | val |= (DMA_RWCTRL_READ_BNDRY_128 | | |
13799 | DMA_RWCTRL_WRITE_BNDRY_128); | |
13800 | break; | |
13801 | } | |
13802 | /* fallthrough */ | |
13803 | case 256: | |
13804 | val |= (DMA_RWCTRL_READ_BNDRY_256 | | |
13805 | DMA_RWCTRL_WRITE_BNDRY_256); | |
13806 | break; | |
13807 | case 512: | |
13808 | val |= (DMA_RWCTRL_READ_BNDRY_512 | | |
13809 | DMA_RWCTRL_WRITE_BNDRY_512); | |
13810 | break; | |
13811 | case 1024: | |
13812 | default: | |
13813 | val |= (DMA_RWCTRL_READ_BNDRY_1024 | | |
13814 | DMA_RWCTRL_WRITE_BNDRY_1024); | |
13815 | break; | |
855e1111 | 13816 | } |
59e6b434 DM |
13817 | } |
13818 | ||
13819 | out: | |
13820 | return val; | |
13821 | } | |
13822 | ||
1da177e4 LT |
13823 | static int __devinit tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, int size, int to_device) |
13824 | { | |
13825 | struct tg3_internal_buffer_desc test_desc; | |
13826 | u32 sram_dma_descs; | |
13827 | int i, ret; | |
13828 | ||
13829 | sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE; | |
13830 | ||
13831 | tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0); | |
13832 | tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0); | |
13833 | tw32(RDMAC_STATUS, 0); | |
13834 | tw32(WDMAC_STATUS, 0); | |
13835 | ||
13836 | tw32(BUFMGR_MODE, 0); | |
13837 | tw32(FTQ_RESET, 0); | |
13838 | ||
13839 | test_desc.addr_hi = ((u64) buf_dma) >> 32; | |
13840 | test_desc.addr_lo = buf_dma & 0xffffffff; | |
13841 | test_desc.nic_mbuf = 0x00002100; | |
13842 | test_desc.len = size; | |
13843 | ||
13844 | /* | |
13845 | * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz | |
13846 | * the *second* time the tg3 driver was getting loaded after an | |
13847 | * initial scan. | |
13848 | * | |
13849 | * Broadcom tells me: | |
13850 | * ...the DMA engine is connected to the GRC block and a DMA | |
13851 | * reset may affect the GRC block in some unpredictable way... | |
13852 | * The behavior of resets to individual blocks has not been tested. | |
13853 | * | |
13854 | * Broadcom noted the GRC reset will also reset all sub-components. | |
13855 | */ | |
13856 | if (to_device) { | |
13857 | test_desc.cqid_sqid = (13 << 8) | 2; | |
13858 | ||
13859 | tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE); | |
13860 | udelay(40); | |
13861 | } else { | |
13862 | test_desc.cqid_sqid = (16 << 8) | 7; | |
13863 | ||
13864 | tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE); | |
13865 | udelay(40); | |
13866 | } | |
13867 | test_desc.flags = 0x00000005; | |
13868 | ||
13869 | for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) { | |
13870 | u32 val; | |
13871 | ||
13872 | val = *(((u32 *)&test_desc) + i); | |
13873 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, | |
13874 | sram_dma_descs + (i * sizeof(u32))); | |
13875 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); | |
13876 | } | |
13877 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
13878 | ||
859a5887 | 13879 | if (to_device) |
1da177e4 | 13880 | tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs); |
859a5887 | 13881 | else |
1da177e4 | 13882 | tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs); |
1da177e4 LT |
13883 | |
13884 | ret = -ENODEV; | |
13885 | for (i = 0; i < 40; i++) { | |
13886 | u32 val; | |
13887 | ||
13888 | if (to_device) | |
13889 | val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ); | |
13890 | else | |
13891 | val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ); | |
13892 | if ((val & 0xffff) == sram_dma_descs) { | |
13893 | ret = 0; | |
13894 | break; | |
13895 | } | |
13896 | ||
13897 | udelay(100); | |
13898 | } | |
13899 | ||
13900 | return ret; | |
13901 | } | |
13902 | ||
ded7340d | 13903 | #define TEST_BUFFER_SIZE 0x2000 |
1da177e4 LT |
13904 | |
13905 | static int __devinit tg3_test_dma(struct tg3 *tp) | |
13906 | { | |
13907 | dma_addr_t buf_dma; | |
59e6b434 | 13908 | u32 *buf, saved_dma_rwctrl; |
cbf9ca6c | 13909 | int ret = 0; |
1da177e4 LT |
13910 | |
13911 | buf = pci_alloc_consistent(tp->pdev, TEST_BUFFER_SIZE, &buf_dma); | |
13912 | if (!buf) { | |
13913 | ret = -ENOMEM; | |
13914 | goto out_nofree; | |
13915 | } | |
13916 | ||
13917 | tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) | | |
13918 | (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT)); | |
13919 | ||
59e6b434 | 13920 | tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl); |
1da177e4 | 13921 | |
c885e824 | 13922 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) |
cbf9ca6c MC |
13923 | goto out; |
13924 | ||
1da177e4 LT |
13925 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { |
13926 | /* DMA read watermark not used on PCIE */ | |
13927 | tp->dma_rwctrl |= 0x00180000; | |
13928 | } else if (!(tp->tg3_flags & TG3_FLAG_PCIX_MODE)) { | |
85e94ced MC |
13929 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5705 || |
13930 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5750) | |
1da177e4 LT |
13931 | tp->dma_rwctrl |= 0x003f0000; |
13932 | else | |
13933 | tp->dma_rwctrl |= 0x003f000f; | |
13934 | } else { | |
13935 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || | |
13936 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) { | |
13937 | u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f); | |
49afdeb6 | 13938 | u32 read_water = 0x7; |
1da177e4 | 13939 | |
4a29cc2e MC |
13940 | /* If the 5704 is behind the EPB bridge, we can |
13941 | * do the less restrictive ONE_DMA workaround for | |
13942 | * better performance. | |
13943 | */ | |
13944 | if ((tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) && | |
13945 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) | |
13946 | tp->dma_rwctrl |= 0x8000; | |
13947 | else if (ccval == 0x6 || ccval == 0x7) | |
1da177e4 LT |
13948 | tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; |
13949 | ||
49afdeb6 MC |
13950 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703) |
13951 | read_water = 4; | |
59e6b434 | 13952 | /* Set bit 23 to enable PCIX hw bug fix */ |
49afdeb6 MC |
13953 | tp->dma_rwctrl |= |
13954 | (read_water << DMA_RWCTRL_READ_WATER_SHIFT) | | |
13955 | (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) | | |
13956 | (1 << 23); | |
4cf78e4f MC |
13957 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5780) { |
13958 | /* 5780 always in PCIX mode */ | |
13959 | tp->dma_rwctrl |= 0x00144000; | |
a4e2b347 MC |
13960 | } else if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5714) { |
13961 | /* 5714 always in PCIX mode */ | |
13962 | tp->dma_rwctrl |= 0x00148000; | |
1da177e4 LT |
13963 | } else { |
13964 | tp->dma_rwctrl |= 0x001b000f; | |
13965 | } | |
13966 | } | |
13967 | ||
13968 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5703 || | |
13969 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5704) | |
13970 | tp->dma_rwctrl &= 0xfffffff0; | |
13971 | ||
13972 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5700 || | |
13973 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5701) { | |
13974 | /* Remove this if it causes problems for some boards. */ | |
13975 | tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT; | |
13976 | ||
13977 | /* On 5700/5701 chips, we need to set this bit. | |
13978 | * Otherwise the chip will issue cacheline transactions | |
13979 | * to streamable DMA memory with not all the byte | |
13980 | * enables turned on. This is an error on several | |
13981 | * RISC PCI controllers, in particular sparc64. | |
13982 | * | |
13983 | * On 5703/5704 chips, this bit has been reassigned | |
13984 | * a different meaning. In particular, it is used | |
13985 | * on those chips to enable a PCI-X workaround. | |
13986 | */ | |
13987 | tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE; | |
13988 | } | |
13989 | ||
13990 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); | |
13991 | ||
13992 | #if 0 | |
13993 | /* Unneeded, already done by tg3_get_invariants. */ | |
13994 | tg3_switch_clocks(tp); | |
13995 | #endif | |
13996 | ||
1da177e4 LT |
13997 | if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 && |
13998 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5701) | |
13999 | goto out; | |
14000 | ||
59e6b434 DM |
14001 | /* It is best to perform DMA test with maximum write burst size |
14002 | * to expose the 5700/5701 write DMA bug. | |
14003 | */ | |
14004 | saved_dma_rwctrl = tp->dma_rwctrl; | |
14005 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; | |
14006 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); | |
14007 | ||
1da177e4 LT |
14008 | while (1) { |
14009 | u32 *p = buf, i; | |
14010 | ||
14011 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) | |
14012 | p[i] = i; | |
14013 | ||
14014 | /* Send the buffer to the chip. */ | |
14015 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 1); | |
14016 | if (ret) { | |
2445e461 MC |
14017 | dev_err(&tp->pdev->dev, |
14018 | "%s: Buffer write failed. err = %d\n", | |
14019 | __func__, ret); | |
1da177e4 LT |
14020 | break; |
14021 | } | |
14022 | ||
14023 | #if 0 | |
14024 | /* validate data reached card RAM correctly. */ | |
14025 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { | |
14026 | u32 val; | |
14027 | tg3_read_mem(tp, 0x2100 + (i*4), &val); | |
14028 | if (le32_to_cpu(val) != p[i]) { | |
2445e461 MC |
14029 | dev_err(&tp->pdev->dev, |
14030 | "%s: Buffer corrupted on device! " | |
14031 | "(%d != %d)\n", __func__, val, i); | |
1da177e4 LT |
14032 | /* ret = -ENODEV here? */ |
14033 | } | |
14034 | p[i] = 0; | |
14035 | } | |
14036 | #endif | |
14037 | /* Now read it back. */ | |
14038 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, 0); | |
14039 | if (ret) { | |
5129c3a3 MC |
14040 | dev_err(&tp->pdev->dev, "%s: Buffer read failed. " |
14041 | "err = %d\n", __func__, ret); | |
1da177e4 LT |
14042 | break; |
14043 | } | |
14044 | ||
14045 | /* Verify it. */ | |
14046 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { | |
14047 | if (p[i] == i) | |
14048 | continue; | |
14049 | ||
59e6b434 DM |
14050 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
14051 | DMA_RWCTRL_WRITE_BNDRY_16) { | |
14052 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; | |
1da177e4 LT |
14053 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
14054 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); | |
14055 | break; | |
14056 | } else { | |
2445e461 MC |
14057 | dev_err(&tp->pdev->dev, |
14058 | "%s: Buffer corrupted on read back! " | |
14059 | "(%d != %d)\n", __func__, p[i], i); | |
1da177e4 LT |
14060 | ret = -ENODEV; |
14061 | goto out; | |
14062 | } | |
14063 | } | |
14064 | ||
14065 | if (i == (TEST_BUFFER_SIZE / sizeof(u32))) { | |
14066 | /* Success. */ | |
14067 | ret = 0; | |
14068 | break; | |
14069 | } | |
14070 | } | |
59e6b434 DM |
14071 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
14072 | DMA_RWCTRL_WRITE_BNDRY_16) { | |
6d1cfbab MC |
14073 | static struct pci_device_id dma_wait_state_chipsets[] = { |
14074 | { PCI_DEVICE(PCI_VENDOR_ID_APPLE, | |
14075 | PCI_DEVICE_ID_APPLE_UNI_N_PCI15) }, | |
14076 | { }, | |
14077 | }; | |
14078 | ||
59e6b434 | 14079 | /* DMA test passed without adjusting DMA boundary, |
6d1cfbab MC |
14080 | * now look for chipsets that are known to expose the |
14081 | * DMA bug without failing the test. | |
59e6b434 | 14082 | */ |
6d1cfbab MC |
14083 | if (pci_dev_present(dma_wait_state_chipsets)) { |
14084 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; | |
14085 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; | |
859a5887 | 14086 | } else { |
6d1cfbab MC |
14087 | /* Safe to use the calculated DMA boundary. */ |
14088 | tp->dma_rwctrl = saved_dma_rwctrl; | |
859a5887 | 14089 | } |
6d1cfbab | 14090 | |
59e6b434 DM |
14091 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
14092 | } | |
1da177e4 LT |
14093 | |
14094 | out: | |
14095 | pci_free_consistent(tp->pdev, TEST_BUFFER_SIZE, buf, buf_dma); | |
14096 | out_nofree: | |
14097 | return ret; | |
14098 | } | |
14099 | ||
14100 | static void __devinit tg3_init_link_config(struct tg3 *tp) | |
14101 | { | |
14102 | tp->link_config.advertising = | |
14103 | (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | | |
14104 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | | |
14105 | ADVERTISED_1000baseT_Half | ADVERTISED_1000baseT_Full | | |
14106 | ADVERTISED_Autoneg | ADVERTISED_MII); | |
14107 | tp->link_config.speed = SPEED_INVALID; | |
14108 | tp->link_config.duplex = DUPLEX_INVALID; | |
14109 | tp->link_config.autoneg = AUTONEG_ENABLE; | |
1da177e4 LT |
14110 | tp->link_config.active_speed = SPEED_INVALID; |
14111 | tp->link_config.active_duplex = DUPLEX_INVALID; | |
1da177e4 LT |
14112 | tp->link_config.orig_speed = SPEED_INVALID; |
14113 | tp->link_config.orig_duplex = DUPLEX_INVALID; | |
14114 | tp->link_config.orig_autoneg = AUTONEG_INVALID; | |
14115 | } | |
14116 | ||
14117 | static void __devinit tg3_init_bufmgr_config(struct tg3 *tp) | |
14118 | { | |
c885e824 | 14119 | if (tp->tg3_flags3 & TG3_FLG3_5717_PLUS) { |
666bc831 MC |
14120 | tp->bufmgr_config.mbuf_read_dma_low_water = |
14121 | DEFAULT_MB_RDMA_LOW_WATER_5705; | |
14122 | tp->bufmgr_config.mbuf_mac_rx_low_water = | |
14123 | DEFAULT_MB_MACRX_LOW_WATER_57765; | |
14124 | tp->bufmgr_config.mbuf_high_water = | |
14125 | DEFAULT_MB_HIGH_WATER_57765; | |
14126 | ||
14127 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = | |
14128 | DEFAULT_MB_RDMA_LOW_WATER_5705; | |
14129 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = | |
14130 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_57765; | |
14131 | tp->bufmgr_config.mbuf_high_water_jumbo = | |
14132 | DEFAULT_MB_HIGH_WATER_JUMBO_57765; | |
14133 | } else if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { | |
fdfec172 MC |
14134 | tp->bufmgr_config.mbuf_read_dma_low_water = |
14135 | DEFAULT_MB_RDMA_LOW_WATER_5705; | |
14136 | tp->bufmgr_config.mbuf_mac_rx_low_water = | |
14137 | DEFAULT_MB_MACRX_LOW_WATER_5705; | |
14138 | tp->bufmgr_config.mbuf_high_water = | |
14139 | DEFAULT_MB_HIGH_WATER_5705; | |
b5d3772c MC |
14140 | if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) { |
14141 | tp->bufmgr_config.mbuf_mac_rx_low_water = | |
14142 | DEFAULT_MB_MACRX_LOW_WATER_5906; | |
14143 | tp->bufmgr_config.mbuf_high_water = | |
14144 | DEFAULT_MB_HIGH_WATER_5906; | |
14145 | } | |
fdfec172 MC |
14146 | |
14147 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = | |
14148 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780; | |
14149 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = | |
14150 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780; | |
14151 | tp->bufmgr_config.mbuf_high_water_jumbo = | |
14152 | DEFAULT_MB_HIGH_WATER_JUMBO_5780; | |
14153 | } else { | |
14154 | tp->bufmgr_config.mbuf_read_dma_low_water = | |
14155 | DEFAULT_MB_RDMA_LOW_WATER; | |
14156 | tp->bufmgr_config.mbuf_mac_rx_low_water = | |
14157 | DEFAULT_MB_MACRX_LOW_WATER; | |
14158 | tp->bufmgr_config.mbuf_high_water = | |
14159 | DEFAULT_MB_HIGH_WATER; | |
14160 | ||
14161 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = | |
14162 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO; | |
14163 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = | |
14164 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO; | |
14165 | tp->bufmgr_config.mbuf_high_water_jumbo = | |
14166 | DEFAULT_MB_HIGH_WATER_JUMBO; | |
14167 | } | |
1da177e4 LT |
14168 | |
14169 | tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER; | |
14170 | tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER; | |
14171 | } | |
14172 | ||
14173 | static char * __devinit tg3_phy_string(struct tg3 *tp) | |
14174 | { | |
79eb6904 MC |
14175 | switch (tp->phy_id & TG3_PHY_ID_MASK) { |
14176 | case TG3_PHY_ID_BCM5400: return "5400"; | |
14177 | case TG3_PHY_ID_BCM5401: return "5401"; | |
14178 | case TG3_PHY_ID_BCM5411: return "5411"; | |
14179 | case TG3_PHY_ID_BCM5701: return "5701"; | |
14180 | case TG3_PHY_ID_BCM5703: return "5703"; | |
14181 | case TG3_PHY_ID_BCM5704: return "5704"; | |
14182 | case TG3_PHY_ID_BCM5705: return "5705"; | |
14183 | case TG3_PHY_ID_BCM5750: return "5750"; | |
14184 | case TG3_PHY_ID_BCM5752: return "5752"; | |
14185 | case TG3_PHY_ID_BCM5714: return "5714"; | |
14186 | case TG3_PHY_ID_BCM5780: return "5780"; | |
14187 | case TG3_PHY_ID_BCM5755: return "5755"; | |
14188 | case TG3_PHY_ID_BCM5787: return "5787"; | |
14189 | case TG3_PHY_ID_BCM5784: return "5784"; | |
14190 | case TG3_PHY_ID_BCM5756: return "5722/5756"; | |
14191 | case TG3_PHY_ID_BCM5906: return "5906"; | |
14192 | case TG3_PHY_ID_BCM5761: return "5761"; | |
14193 | case TG3_PHY_ID_BCM5718C: return "5718C"; | |
14194 | case TG3_PHY_ID_BCM5718S: return "5718S"; | |
14195 | case TG3_PHY_ID_BCM57765: return "57765"; | |
302b500b | 14196 | case TG3_PHY_ID_BCM5719C: return "5719C"; |
79eb6904 | 14197 | case TG3_PHY_ID_BCM8002: return "8002/serdes"; |
1da177e4 LT |
14198 | case 0: return "serdes"; |
14199 | default: return "unknown"; | |
855e1111 | 14200 | } |
1da177e4 LT |
14201 | } |
14202 | ||
f9804ddb MC |
14203 | static char * __devinit tg3_bus_string(struct tg3 *tp, char *str) |
14204 | { | |
14205 | if (tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) { | |
14206 | strcpy(str, "PCI Express"); | |
14207 | return str; | |
14208 | } else if (tp->tg3_flags & TG3_FLAG_PCIX_MODE) { | |
14209 | u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f; | |
14210 | ||
14211 | strcpy(str, "PCIX:"); | |
14212 | ||
14213 | if ((clock_ctrl == 7) || | |
14214 | ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) == | |
14215 | GRC_MISC_CFG_BOARD_ID_5704CIOBE)) | |
14216 | strcat(str, "133MHz"); | |
14217 | else if (clock_ctrl == 0) | |
14218 | strcat(str, "33MHz"); | |
14219 | else if (clock_ctrl == 2) | |
14220 | strcat(str, "50MHz"); | |
14221 | else if (clock_ctrl == 4) | |
14222 | strcat(str, "66MHz"); | |
14223 | else if (clock_ctrl == 6) | |
14224 | strcat(str, "100MHz"); | |
f9804ddb MC |
14225 | } else { |
14226 | strcpy(str, "PCI:"); | |
14227 | if (tp->tg3_flags & TG3_FLAG_PCI_HIGH_SPEED) | |
14228 | strcat(str, "66MHz"); | |
14229 | else | |
14230 | strcat(str, "33MHz"); | |
14231 | } | |
14232 | if (tp->tg3_flags & TG3_FLAG_PCI_32BIT) | |
14233 | strcat(str, ":32-bit"); | |
14234 | else | |
14235 | strcat(str, ":64-bit"); | |
14236 | return str; | |
14237 | } | |
14238 | ||
8c2dc7e1 | 14239 | static struct pci_dev * __devinit tg3_find_peer(struct tg3 *tp) |
1da177e4 LT |
14240 | { |
14241 | struct pci_dev *peer; | |
14242 | unsigned int func, devnr = tp->pdev->devfn & ~7; | |
14243 | ||
14244 | for (func = 0; func < 8; func++) { | |
14245 | peer = pci_get_slot(tp->pdev->bus, devnr | func); | |
14246 | if (peer && peer != tp->pdev) | |
14247 | break; | |
14248 | pci_dev_put(peer); | |
14249 | } | |
16fe9d74 MC |
14250 | /* 5704 can be configured in single-port mode, set peer to |
14251 | * tp->pdev in that case. | |
14252 | */ | |
14253 | if (!peer) { | |
14254 | peer = tp->pdev; | |
14255 | return peer; | |
14256 | } | |
1da177e4 LT |
14257 | |
14258 | /* | |
14259 | * We don't need to keep the refcount elevated; there's no way | |
14260 | * to remove one half of this device without removing the other | |
14261 | */ | |
14262 | pci_dev_put(peer); | |
14263 | ||
14264 | return peer; | |
14265 | } | |
14266 | ||
15f9850d DM |
14267 | static void __devinit tg3_init_coal(struct tg3 *tp) |
14268 | { | |
14269 | struct ethtool_coalesce *ec = &tp->coal; | |
14270 | ||
14271 | memset(ec, 0, sizeof(*ec)); | |
14272 | ec->cmd = ETHTOOL_GCOALESCE; | |
14273 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS; | |
14274 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS; | |
14275 | ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES; | |
14276 | ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES; | |
14277 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT; | |
14278 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT; | |
14279 | ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT; | |
14280 | ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT; | |
14281 | ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS; | |
14282 | ||
14283 | if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD | | |
14284 | HOSTCC_MODE_CLRTICK_TXBD)) { | |
14285 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS; | |
14286 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS; | |
14287 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS; | |
14288 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS; | |
14289 | } | |
d244c892 MC |
14290 | |
14291 | if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) { | |
14292 | ec->rx_coalesce_usecs_irq = 0; | |
14293 | ec->tx_coalesce_usecs_irq = 0; | |
14294 | ec->stats_block_coalesce_usecs = 0; | |
14295 | } | |
15f9850d DM |
14296 | } |
14297 | ||
7c7d64b8 SH |
14298 | static const struct net_device_ops tg3_netdev_ops = { |
14299 | .ndo_open = tg3_open, | |
14300 | .ndo_stop = tg3_close, | |
00829823 | 14301 | .ndo_start_xmit = tg3_start_xmit, |
511d2224 | 14302 | .ndo_get_stats64 = tg3_get_stats64, |
00829823 SH |
14303 | .ndo_validate_addr = eth_validate_addr, |
14304 | .ndo_set_multicast_list = tg3_set_rx_mode, | |
14305 | .ndo_set_mac_address = tg3_set_mac_addr, | |
14306 | .ndo_do_ioctl = tg3_ioctl, | |
14307 | .ndo_tx_timeout = tg3_tx_timeout, | |
14308 | .ndo_change_mtu = tg3_change_mtu, | |
14309 | #if TG3_VLAN_TAG_USED | |
14310 | .ndo_vlan_rx_register = tg3_vlan_rx_register, | |
14311 | #endif | |
14312 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
14313 | .ndo_poll_controller = tg3_poll_controller, | |
14314 | #endif | |
14315 | }; | |
14316 | ||
14317 | static const struct net_device_ops tg3_netdev_ops_dma_bug = { | |
14318 | .ndo_open = tg3_open, | |
14319 | .ndo_stop = tg3_close, | |
14320 | .ndo_start_xmit = tg3_start_xmit_dma_bug, | |
511d2224 | 14321 | .ndo_get_stats64 = tg3_get_stats64, |
7c7d64b8 SH |
14322 | .ndo_validate_addr = eth_validate_addr, |
14323 | .ndo_set_multicast_list = tg3_set_rx_mode, | |
14324 | .ndo_set_mac_address = tg3_set_mac_addr, | |
14325 | .ndo_do_ioctl = tg3_ioctl, | |
14326 | .ndo_tx_timeout = tg3_tx_timeout, | |
14327 | .ndo_change_mtu = tg3_change_mtu, | |
14328 | #if TG3_VLAN_TAG_USED | |
14329 | .ndo_vlan_rx_register = tg3_vlan_rx_register, | |
14330 | #endif | |
14331 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
14332 | .ndo_poll_controller = tg3_poll_controller, | |
14333 | #endif | |
14334 | }; | |
14335 | ||
1da177e4 LT |
14336 | static int __devinit tg3_init_one(struct pci_dev *pdev, |
14337 | const struct pci_device_id *ent) | |
14338 | { | |
1da177e4 LT |
14339 | struct net_device *dev; |
14340 | struct tg3 *tp; | |
646c9edd MC |
14341 | int i, err, pm_cap; |
14342 | u32 sndmbx, rcvmbx, intmbx; | |
f9804ddb | 14343 | char str[40]; |
72f2afb8 | 14344 | u64 dma_mask, persist_dma_mask; |
1da177e4 | 14345 | |
05dbe005 | 14346 | printk_once(KERN_INFO "%s\n", version); |
1da177e4 LT |
14347 | |
14348 | err = pci_enable_device(pdev); | |
14349 | if (err) { | |
2445e461 | 14350 | dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
1da177e4 LT |
14351 | return err; |
14352 | } | |
14353 | ||
1da177e4 LT |
14354 | err = pci_request_regions(pdev, DRV_MODULE_NAME); |
14355 | if (err) { | |
2445e461 | 14356 | dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
1da177e4 LT |
14357 | goto err_out_disable_pdev; |
14358 | } | |
14359 | ||
14360 | pci_set_master(pdev); | |
14361 | ||
14362 | /* Find power-management capability. */ | |
14363 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); | |
14364 | if (pm_cap == 0) { | |
2445e461 MC |
14365 | dev_err(&pdev->dev, |
14366 | "Cannot find Power Management capability, aborting\n"); | |
1da177e4 LT |
14367 | err = -EIO; |
14368 | goto err_out_free_res; | |
14369 | } | |
14370 | ||
fe5f5787 | 14371 | dev = alloc_etherdev_mq(sizeof(*tp), TG3_IRQ_MAX_VECS); |
1da177e4 | 14372 | if (!dev) { |
2445e461 | 14373 | dev_err(&pdev->dev, "Etherdev alloc failed, aborting\n"); |
1da177e4 LT |
14374 | err = -ENOMEM; |
14375 | goto err_out_free_res; | |
14376 | } | |
14377 | ||
1da177e4 LT |
14378 | SET_NETDEV_DEV(dev, &pdev->dev); |
14379 | ||
1da177e4 LT |
14380 | #if TG3_VLAN_TAG_USED |
14381 | dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; | |
1da177e4 LT |
14382 | #endif |
14383 | ||
14384 | tp = netdev_priv(dev); | |
14385 | tp->pdev = pdev; | |
14386 | tp->dev = dev; | |
14387 | tp->pm_cap = pm_cap; | |
1da177e4 LT |
14388 | tp->rx_mode = TG3_DEF_RX_MODE; |
14389 | tp->tx_mode = TG3_DEF_TX_MODE; | |
8ef21428 | 14390 | |
1da177e4 LT |
14391 | if (tg3_debug > 0) |
14392 | tp->msg_enable = tg3_debug; | |
14393 | else | |
14394 | tp->msg_enable = TG3_DEF_MSG_ENABLE; | |
14395 | ||
14396 | /* The word/byte swap controls here control register access byte | |
14397 | * swapping. DMA data byte swapping is controlled in the GRC_MODE | |
14398 | * setting below. | |
14399 | */ | |
14400 | tp->misc_host_ctrl = | |
14401 | MISC_HOST_CTRL_MASK_PCI_INT | | |
14402 | MISC_HOST_CTRL_WORD_SWAP | | |
14403 | MISC_HOST_CTRL_INDIR_ACCESS | | |
14404 | MISC_HOST_CTRL_PCISTATE_RW; | |
14405 | ||
14406 | /* The NONFRM (non-frame) byte/word swap controls take effect | |
14407 | * on descriptor entries, anything which isn't packet data. | |
14408 | * | |
14409 | * The StrongARM chips on the board (one for tx, one for rx) | |
14410 | * are running in big-endian mode. | |
14411 | */ | |
14412 | tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA | | |
14413 | GRC_MODE_WSWAP_NONFRM_DATA); | |
14414 | #ifdef __BIG_ENDIAN | |
14415 | tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA; | |
14416 | #endif | |
14417 | spin_lock_init(&tp->lock); | |
1da177e4 | 14418 | spin_lock_init(&tp->indirect_lock); |
c4028958 | 14419 | INIT_WORK(&tp->reset_task, tg3_reset_task); |
1da177e4 | 14420 | |
d5fe488a | 14421 | tp->regs = pci_ioremap_bar(pdev, BAR_0); |
ab0049b4 | 14422 | if (!tp->regs) { |
ab96b241 | 14423 | dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
1da177e4 LT |
14424 | err = -ENOMEM; |
14425 | goto err_out_free_dev; | |
14426 | } | |
14427 | ||
14428 | tg3_init_link_config(tp); | |
14429 | ||
1da177e4 LT |
14430 | tp->rx_pending = TG3_DEF_RX_RING_PENDING; |
14431 | tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING; | |
1da177e4 | 14432 | |
1da177e4 | 14433 | dev->ethtool_ops = &tg3_ethtool_ops; |
1da177e4 | 14434 | dev->watchdog_timeo = TG3_TX_TIMEOUT; |
1da177e4 | 14435 | dev->irq = pdev->irq; |
1da177e4 LT |
14436 | |
14437 | err = tg3_get_invariants(tp); | |
14438 | if (err) { | |
ab96b241 MC |
14439 | dev_err(&pdev->dev, |
14440 | "Problem fetching invariants of chip, aborting\n"); | |
1da177e4 LT |
14441 | goto err_out_iounmap; |
14442 | } | |
14443 | ||
615774fe | 14444 | if ((tp->tg3_flags3 & TG3_FLG3_5755_PLUS) && |
a50d0796 MC |
14445 | tp->pci_chip_rev_id != CHIPREV_ID_5717_A0 && |
14446 | GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5719) | |
00829823 SH |
14447 | dev->netdev_ops = &tg3_netdev_ops; |
14448 | else | |
14449 | dev->netdev_ops = &tg3_netdev_ops_dma_bug; | |
14450 | ||
14451 | ||
4a29cc2e MC |
14452 | /* The EPB bridge inside 5714, 5715, and 5780 and any |
14453 | * device behind the EPB cannot support DMA addresses > 40-bit. | |
72f2afb8 MC |
14454 | * On 64-bit systems with IOMMU, use 40-bit dma_mask. |
14455 | * On 64-bit systems without IOMMU, use 64-bit dma_mask and | |
14456 | * do DMA address check in tg3_start_xmit(). | |
14457 | */ | |
4a29cc2e | 14458 | if (tp->tg3_flags2 & TG3_FLG2_IS_5788) |
284901a9 | 14459 | persist_dma_mask = dma_mask = DMA_BIT_MASK(32); |
4a29cc2e | 14460 | else if (tp->tg3_flags & TG3_FLAG_40BIT_DMA_BUG) { |
50cf156a | 14461 | persist_dma_mask = dma_mask = DMA_BIT_MASK(40); |
72f2afb8 | 14462 | #ifdef CONFIG_HIGHMEM |
6a35528a | 14463 | dma_mask = DMA_BIT_MASK(64); |
72f2afb8 | 14464 | #endif |
4a29cc2e | 14465 | } else |
6a35528a | 14466 | persist_dma_mask = dma_mask = DMA_BIT_MASK(64); |
72f2afb8 MC |
14467 | |
14468 | /* Configure DMA attributes. */ | |
284901a9 | 14469 | if (dma_mask > DMA_BIT_MASK(32)) { |
72f2afb8 MC |
14470 | err = pci_set_dma_mask(pdev, dma_mask); |
14471 | if (!err) { | |
14472 | dev->features |= NETIF_F_HIGHDMA; | |
14473 | err = pci_set_consistent_dma_mask(pdev, | |
14474 | persist_dma_mask); | |
14475 | if (err < 0) { | |
ab96b241 MC |
14476 | dev_err(&pdev->dev, "Unable to obtain 64 bit " |
14477 | "DMA for consistent allocations\n"); | |
72f2afb8 MC |
14478 | goto err_out_iounmap; |
14479 | } | |
14480 | } | |
14481 | } | |
284901a9 YH |
14482 | if (err || dma_mask == DMA_BIT_MASK(32)) { |
14483 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); | |
72f2afb8 | 14484 | if (err) { |
ab96b241 MC |
14485 | dev_err(&pdev->dev, |
14486 | "No usable DMA configuration, aborting\n"); | |
72f2afb8 MC |
14487 | goto err_out_iounmap; |
14488 | } | |
14489 | } | |
14490 | ||
fdfec172 | 14491 | tg3_init_bufmgr_config(tp); |
1da177e4 | 14492 | |
507399f1 MC |
14493 | /* Selectively allow TSO based on operating conditions */ |
14494 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) || | |
14495 | (tp->fw_needed && !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))) | |
1da177e4 | 14496 | tp->tg3_flags2 |= TG3_FLG2_TSO_CAPABLE; |
507399f1 MC |
14497 | else { |
14498 | tp->tg3_flags2 &= ~(TG3_FLG2_TSO_CAPABLE | TG3_FLG2_TSO_BUG); | |
14499 | tp->fw_needed = NULL; | |
1da177e4 | 14500 | } |
507399f1 MC |
14501 | |
14502 | if (tp->pci_chip_rev_id == CHIPREV_ID_5701_A0) | |
14503 | tp->fw_needed = FIRMWARE_TG3; | |
1da177e4 | 14504 | |
4e3a7aaa MC |
14505 | /* TSO is on by default on chips that support hardware TSO. |
14506 | * Firmware TSO on older chips gives lower performance, so it | |
14507 | * is off by default, but can be enabled using ethtool. | |
14508 | */ | |
e849cdc3 | 14509 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO) && |
7fe876af | 14510 | (dev->features & NETIF_F_IP_CSUM)) { |
e849cdc3 | 14511 | dev->features |= NETIF_F_TSO; |
7fe876af ED |
14512 | vlan_features_add(dev, NETIF_F_TSO); |
14513 | } | |
e849cdc3 MC |
14514 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_2) || |
14515 | (tp->tg3_flags2 & TG3_FLG2_HW_TSO_3)) { | |
7fe876af | 14516 | if (dev->features & NETIF_F_IPV6_CSUM) { |
b0026624 | 14517 | dev->features |= NETIF_F_TSO6; |
7fe876af ED |
14518 | vlan_features_add(dev, NETIF_F_TSO6); |
14519 | } | |
e849cdc3 MC |
14520 | if ((tp->tg3_flags2 & TG3_FLG2_HW_TSO_3) || |
14521 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5761 || | |
57e6983c MC |
14522 | (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5784 && |
14523 | GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5784_AX) || | |
321d32a0 | 14524 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5785 || |
7fe876af | 14525 | GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_57780) { |
9936bcf6 | 14526 | dev->features |= NETIF_F_TSO_ECN; |
7fe876af ED |
14527 | vlan_features_add(dev, NETIF_F_TSO_ECN); |
14528 | } | |
b0026624 | 14529 | } |
1da177e4 | 14530 | |
1da177e4 LT |
14531 | if (tp->pci_chip_rev_id == CHIPREV_ID_5705_A1 && |
14532 | !(tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) && | |
14533 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) { | |
14534 | tp->tg3_flags2 |= TG3_FLG2_MAX_RXPEND_64; | |
14535 | tp->rx_pending = 63; | |
14536 | } | |
14537 | ||
1da177e4 LT |
14538 | err = tg3_get_device_address(tp); |
14539 | if (err) { | |
ab96b241 MC |
14540 | dev_err(&pdev->dev, |
14541 | "Could not obtain valid ethernet address, aborting\n"); | |
026a6c21 | 14542 | goto err_out_iounmap; |
1da177e4 LT |
14543 | } |
14544 | ||
c88864df | 14545 | if (tp->tg3_flags3 & TG3_FLG3_ENABLE_APE) { |
63532394 | 14546 | tp->aperegs = pci_ioremap_bar(pdev, BAR_2); |
79ea13ce | 14547 | if (!tp->aperegs) { |
ab96b241 MC |
14548 | dev_err(&pdev->dev, |
14549 | "Cannot map APE registers, aborting\n"); | |
c88864df | 14550 | err = -ENOMEM; |
026a6c21 | 14551 | goto err_out_iounmap; |
c88864df MC |
14552 | } |
14553 | ||
14554 | tg3_ape_lock_init(tp); | |
7fd76445 MC |
14555 | |
14556 | if (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) | |
14557 | tg3_read_dash_ver(tp); | |
c88864df MC |
14558 | } |
14559 | ||
1da177e4 LT |
14560 | /* |
14561 | * Reset chip in case UNDI or EFI driver did not shutdown | |
14562 | * DMA self test will enable WDMAC and we'll see (spurious) | |
14563 | * pending DMA on the PCI bus at that point. | |
14564 | */ | |
14565 | if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) || | |
14566 | (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { | |
1da177e4 | 14567 | tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); |
944d980e | 14568 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
1da177e4 LT |
14569 | } |
14570 | ||
14571 | err = tg3_test_dma(tp); | |
14572 | if (err) { | |
ab96b241 | 14573 | dev_err(&pdev->dev, "DMA engine test failed, aborting\n"); |
c88864df | 14574 | goto err_out_apeunmap; |
1da177e4 LT |
14575 | } |
14576 | ||
1da177e4 LT |
14577 | /* flow control autonegotiation is default behavior */ |
14578 | tp->tg3_flags |= TG3_FLAG_PAUSE_AUTONEG; | |
e18ce346 | 14579 | tp->link_config.flowctrl = FLOW_CTRL_TX | FLOW_CTRL_RX; |
1da177e4 | 14580 | |
78f90dcf MC |
14581 | intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW; |
14582 | rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW; | |
14583 | sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW; | |
14584 | for (i = 0; i < TG3_IRQ_MAX_VECS; i++) { | |
14585 | struct tg3_napi *tnapi = &tp->napi[i]; | |
14586 | ||
14587 | tnapi->tp = tp; | |
14588 | tnapi->tx_pending = TG3_DEF_TX_RING_PENDING; | |
14589 | ||
14590 | tnapi->int_mbox = intmbx; | |
14591 | if (i < 4) | |
14592 | intmbx += 0x8; | |
14593 | else | |
14594 | intmbx += 0x4; | |
14595 | ||
14596 | tnapi->consmbox = rcvmbx; | |
14597 | tnapi->prodmbox = sndmbx; | |
14598 | ||
14599 | if (i) { | |
14600 | tnapi->coal_now = HOSTCC_MODE_COAL_VEC1_NOW << (i - 1); | |
14601 | netif_napi_add(dev, &tnapi->napi, tg3_poll_msix, 64); | |
14602 | } else { | |
14603 | tnapi->coal_now = HOSTCC_MODE_NOW; | |
14604 | netif_napi_add(dev, &tnapi->napi, tg3_poll, 64); | |
14605 | } | |
14606 | ||
14607 | if (!(tp->tg3_flags & TG3_FLAG_SUPPORT_MSIX)) | |
14608 | break; | |
14609 | ||
14610 | /* | |
14611 | * If we support MSIX, we'll be using RSS. If we're using | |
14612 | * RSS, the first vector only handles link interrupts and the | |
14613 | * remaining vectors handle rx and tx interrupts. Reuse the | |
14614 | * mailbox values for the next iteration. The values we setup | |
14615 | * above are still useful for the single vectored mode. | |
14616 | */ | |
14617 | if (!i) | |
14618 | continue; | |
14619 | ||
14620 | rcvmbx += 0x8; | |
14621 | ||
14622 | if (sndmbx & 0x4) | |
14623 | sndmbx -= 0x4; | |
14624 | else | |
14625 | sndmbx += 0xc; | |
14626 | } | |
14627 | ||
15f9850d DM |
14628 | tg3_init_coal(tp); |
14629 | ||
c49a1561 MC |
14630 | pci_set_drvdata(pdev, dev); |
14631 | ||
1da177e4 LT |
14632 | err = register_netdev(dev); |
14633 | if (err) { | |
ab96b241 | 14634 | dev_err(&pdev->dev, "Cannot register net device, aborting\n"); |
0d3031d9 | 14635 | goto err_out_apeunmap; |
1da177e4 LT |
14636 | } |
14637 | ||
05dbe005 JP |
14638 | netdev_info(dev, "Tigon3 [partno(%s) rev %04x] (%s) MAC address %pM\n", |
14639 | tp->board_part_number, | |
14640 | tp->pci_chip_rev_id, | |
14641 | tg3_bus_string(tp, str), | |
14642 | dev->dev_addr); | |
1da177e4 | 14643 | |
f07e9af3 | 14644 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
3f0e3ad7 MC |
14645 | struct phy_device *phydev; |
14646 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; | |
5129c3a3 MC |
14647 | netdev_info(dev, |
14648 | "attached PHY driver [%s] (mii_bus:phy_addr=%s)\n", | |
05dbe005 | 14649 | phydev->drv->name, dev_name(&phydev->dev)); |
f07e9af3 MC |
14650 | } else { |
14651 | char *ethtype; | |
14652 | ||
14653 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) | |
14654 | ethtype = "10/100Base-TX"; | |
14655 | else if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) | |
14656 | ethtype = "1000Base-SX"; | |
14657 | else | |
14658 | ethtype = "10/100/1000Base-T"; | |
14659 | ||
5129c3a3 | 14660 | netdev_info(dev, "attached PHY is %s (%s Ethernet) " |
f07e9af3 MC |
14661 | "(WireSpeed[%d])\n", tg3_phy_string(tp), ethtype, |
14662 | (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) == 0); | |
14663 | } | |
05dbe005 JP |
14664 | |
14665 | netdev_info(dev, "RXcsums[%d] LinkChgREG[%d] MIirq[%d] ASF[%d] TSOcap[%d]\n", | |
14666 | (tp->tg3_flags & TG3_FLAG_RX_CHECKSUMS) != 0, | |
14667 | (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) != 0, | |
f07e9af3 | 14668 | (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) != 0, |
05dbe005 JP |
14669 | (tp->tg3_flags & TG3_FLAG_ENABLE_ASF) != 0, |
14670 | (tp->tg3_flags2 & TG3_FLG2_TSO_CAPABLE) != 0); | |
14671 | netdev_info(dev, "dma_rwctrl[%08x] dma_mask[%d-bit]\n", | |
14672 | tp->dma_rwctrl, | |
14673 | pdev->dma_mask == DMA_BIT_MASK(32) ? 32 : | |
14674 | ((u64)pdev->dma_mask) == DMA_BIT_MASK(40) ? 40 : 64); | |
1da177e4 LT |
14675 | |
14676 | return 0; | |
14677 | ||
0d3031d9 MC |
14678 | err_out_apeunmap: |
14679 | if (tp->aperegs) { | |
14680 | iounmap(tp->aperegs); | |
14681 | tp->aperegs = NULL; | |
14682 | } | |
14683 | ||
1da177e4 | 14684 | err_out_iounmap: |
6892914f MC |
14685 | if (tp->regs) { |
14686 | iounmap(tp->regs); | |
22abe310 | 14687 | tp->regs = NULL; |
6892914f | 14688 | } |
1da177e4 LT |
14689 | |
14690 | err_out_free_dev: | |
14691 | free_netdev(dev); | |
14692 | ||
14693 | err_out_free_res: | |
14694 | pci_release_regions(pdev); | |
14695 | ||
14696 | err_out_disable_pdev: | |
14697 | pci_disable_device(pdev); | |
14698 | pci_set_drvdata(pdev, NULL); | |
14699 | return err; | |
14700 | } | |
14701 | ||
14702 | static void __devexit tg3_remove_one(struct pci_dev *pdev) | |
14703 | { | |
14704 | struct net_device *dev = pci_get_drvdata(pdev); | |
14705 | ||
14706 | if (dev) { | |
14707 | struct tg3 *tp = netdev_priv(dev); | |
14708 | ||
077f849d JSR |
14709 | if (tp->fw) |
14710 | release_firmware(tp->fw); | |
14711 | ||
7faa006f | 14712 | flush_scheduled_work(); |
158d7abd | 14713 | |
b02fd9e3 MC |
14714 | if (tp->tg3_flags3 & TG3_FLG3_USE_PHYLIB) { |
14715 | tg3_phy_fini(tp); | |
158d7abd | 14716 | tg3_mdio_fini(tp); |
b02fd9e3 | 14717 | } |
158d7abd | 14718 | |
1da177e4 | 14719 | unregister_netdev(dev); |
0d3031d9 MC |
14720 | if (tp->aperegs) { |
14721 | iounmap(tp->aperegs); | |
14722 | tp->aperegs = NULL; | |
14723 | } | |
6892914f MC |
14724 | if (tp->regs) { |
14725 | iounmap(tp->regs); | |
22abe310 | 14726 | tp->regs = NULL; |
6892914f | 14727 | } |
1da177e4 LT |
14728 | free_netdev(dev); |
14729 | pci_release_regions(pdev); | |
14730 | pci_disable_device(pdev); | |
14731 | pci_set_drvdata(pdev, NULL); | |
14732 | } | |
14733 | } | |
14734 | ||
14735 | static int tg3_suspend(struct pci_dev *pdev, pm_message_t state) | |
14736 | { | |
14737 | struct net_device *dev = pci_get_drvdata(pdev); | |
14738 | struct tg3 *tp = netdev_priv(dev); | |
12dac075 | 14739 | pci_power_t target_state; |
1da177e4 LT |
14740 | int err; |
14741 | ||
3e0c95fd MC |
14742 | /* PCI register 4 needs to be saved whether netif_running() or not. |
14743 | * MSI address and data need to be saved if using MSI and | |
14744 | * netif_running(). | |
14745 | */ | |
14746 | pci_save_state(pdev); | |
14747 | ||
1da177e4 LT |
14748 | if (!netif_running(dev)) |
14749 | return 0; | |
14750 | ||
7faa006f | 14751 | flush_scheduled_work(); |
b02fd9e3 | 14752 | tg3_phy_stop(tp); |
1da177e4 LT |
14753 | tg3_netif_stop(tp); |
14754 | ||
14755 | del_timer_sync(&tp->timer); | |
14756 | ||
f47c11ee | 14757 | tg3_full_lock(tp, 1); |
1da177e4 | 14758 | tg3_disable_ints(tp); |
f47c11ee | 14759 | tg3_full_unlock(tp); |
1da177e4 LT |
14760 | |
14761 | netif_device_detach(dev); | |
14762 | ||
f47c11ee | 14763 | tg3_full_lock(tp, 0); |
944d980e | 14764 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
6a9eba15 | 14765 | tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE; |
f47c11ee | 14766 | tg3_full_unlock(tp); |
1da177e4 | 14767 | |
12dac075 RW |
14768 | target_state = pdev->pm_cap ? pci_target_state(pdev) : PCI_D3hot; |
14769 | ||
14770 | err = tg3_set_power_state(tp, target_state); | |
1da177e4 | 14771 | if (err) { |
b02fd9e3 MC |
14772 | int err2; |
14773 | ||
f47c11ee | 14774 | tg3_full_lock(tp, 0); |
1da177e4 | 14775 | |
6a9eba15 | 14776 | tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; |
b02fd9e3 MC |
14777 | err2 = tg3_restart_hw(tp, 1); |
14778 | if (err2) | |
b9ec6c1b | 14779 | goto out; |
1da177e4 LT |
14780 | |
14781 | tp->timer.expires = jiffies + tp->timer_offset; | |
14782 | add_timer(&tp->timer); | |
14783 | ||
14784 | netif_device_attach(dev); | |
14785 | tg3_netif_start(tp); | |
14786 | ||
b9ec6c1b | 14787 | out: |
f47c11ee | 14788 | tg3_full_unlock(tp); |
b02fd9e3 MC |
14789 | |
14790 | if (!err2) | |
14791 | tg3_phy_start(tp); | |
1da177e4 LT |
14792 | } |
14793 | ||
14794 | return err; | |
14795 | } | |
14796 | ||
14797 | static int tg3_resume(struct pci_dev *pdev) | |
14798 | { | |
14799 | struct net_device *dev = pci_get_drvdata(pdev); | |
14800 | struct tg3 *tp = netdev_priv(dev); | |
14801 | int err; | |
14802 | ||
3e0c95fd MC |
14803 | pci_restore_state(tp->pdev); |
14804 | ||
1da177e4 LT |
14805 | if (!netif_running(dev)) |
14806 | return 0; | |
14807 | ||
bc1c7567 | 14808 | err = tg3_set_power_state(tp, PCI_D0); |
1da177e4 LT |
14809 | if (err) |
14810 | return err; | |
14811 | ||
14812 | netif_device_attach(dev); | |
14813 | ||
f47c11ee | 14814 | tg3_full_lock(tp, 0); |
1da177e4 | 14815 | |
6a9eba15 | 14816 | tp->tg3_flags |= TG3_FLAG_INIT_COMPLETE; |
b9ec6c1b MC |
14817 | err = tg3_restart_hw(tp, 1); |
14818 | if (err) | |
14819 | goto out; | |
1da177e4 LT |
14820 | |
14821 | tp->timer.expires = jiffies + tp->timer_offset; | |
14822 | add_timer(&tp->timer); | |
14823 | ||
1da177e4 LT |
14824 | tg3_netif_start(tp); |
14825 | ||
b9ec6c1b | 14826 | out: |
f47c11ee | 14827 | tg3_full_unlock(tp); |
1da177e4 | 14828 | |
b02fd9e3 MC |
14829 | if (!err) |
14830 | tg3_phy_start(tp); | |
14831 | ||
b9ec6c1b | 14832 | return err; |
1da177e4 LT |
14833 | } |
14834 | ||
14835 | static struct pci_driver tg3_driver = { | |
14836 | .name = DRV_MODULE_NAME, | |
14837 | .id_table = tg3_pci_tbl, | |
14838 | .probe = tg3_init_one, | |
14839 | .remove = __devexit_p(tg3_remove_one), | |
14840 | .suspend = tg3_suspend, | |
14841 | .resume = tg3_resume | |
14842 | }; | |
14843 | ||
14844 | static int __init tg3_init(void) | |
14845 | { | |
29917620 | 14846 | return pci_register_driver(&tg3_driver); |
1da177e4 LT |
14847 | } |
14848 | ||
14849 | static void __exit tg3_cleanup(void) | |
14850 | { | |
14851 | pci_unregister_driver(&tg3_driver); | |
14852 | } | |
14853 | ||
14854 | module_init(tg3_init); | |
14855 | module_exit(tg3_cleanup); |