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. | |
b681b65d | 7 | * Copyright (C) 2005-2013 Broadcom Corporation. |
1da177e4 LT |
8 | * |
9 | * Firmware is: | |
49cabf49 MC |
10 | * Derived from proprietary unpublished source code, |
11 | * Copyright (C) 2000-2003 Broadcom Corporation. | |
12 | * | |
13 | * Permission is hereby granted for the distribution of this firmware | |
14 | * data in hexadecimal or equivalent format, provided this copyright | |
15 | * notice is accompanying it. | |
1da177e4 LT |
16 | */ |
17 | ||
1da177e4 LT |
18 | |
19 | #include <linux/module.h> | |
20 | #include <linux/moduleparam.h> | |
6867c843 | 21 | #include <linux/stringify.h> |
1da177e4 LT |
22 | #include <linux/kernel.h> |
23 | #include <linux/types.h> | |
24 | #include <linux/compiler.h> | |
25 | #include <linux/slab.h> | |
26 | #include <linux/delay.h> | |
14c85021 | 27 | #include <linux/in.h> |
1da177e4 | 28 | #include <linux/init.h> |
a6b7a407 | 29 | #include <linux/interrupt.h> |
1da177e4 LT |
30 | #include <linux/ioport.h> |
31 | #include <linux/pci.h> | |
32 | #include <linux/netdevice.h> | |
33 | #include <linux/etherdevice.h> | |
34 | #include <linux/skbuff.h> | |
35 | #include <linux/ethtool.h> | |
3110f5f5 | 36 | #include <linux/mdio.h> |
1da177e4 | 37 | #include <linux/mii.h> |
158d7abd | 38 | #include <linux/phy.h> |
a9daf367 | 39 | #include <linux/brcmphy.h> |
1da177e4 LT |
40 | #include <linux/if_vlan.h> |
41 | #include <linux/ip.h> | |
42 | #include <linux/tcp.h> | |
43 | #include <linux/workqueue.h> | |
61487480 | 44 | #include <linux/prefetch.h> |
f9a5f7d3 | 45 | #include <linux/dma-mapping.h> |
077f849d | 46 | #include <linux/firmware.h> |
7e6c63f0 | 47 | #include <linux/ssb/ssb_driver_gige.h> |
aed93e0b MC |
48 | #include <linux/hwmon.h> |
49 | #include <linux/hwmon-sysfs.h> | |
1da177e4 LT |
50 | |
51 | #include <net/checksum.h> | |
c9bdd4b5 | 52 | #include <net/ip.h> |
1da177e4 | 53 | |
27fd9de8 | 54 | #include <linux/io.h> |
1da177e4 | 55 | #include <asm/byteorder.h> |
27fd9de8 | 56 | #include <linux/uaccess.h> |
1da177e4 | 57 | |
be947307 MC |
58 | #include <uapi/linux/net_tstamp.h> |
59 | #include <linux/ptp_clock_kernel.h> | |
60 | ||
49b6e95f | 61 | #ifdef CONFIG_SPARC |
1da177e4 | 62 | #include <asm/idprom.h> |
49b6e95f | 63 | #include <asm/prom.h> |
1da177e4 LT |
64 | #endif |
65 | ||
63532394 MC |
66 | #define BAR_0 0 |
67 | #define BAR_2 2 | |
68 | ||
1da177e4 LT |
69 | #include "tg3.h" |
70 | ||
63c3a66f JP |
71 | /* Functions & macros to verify TG3_FLAGS types */ |
72 | ||
73 | static inline int _tg3_flag(enum TG3_FLAGS flag, unsigned long *bits) | |
74 | { | |
75 | return test_bit(flag, bits); | |
76 | } | |
77 | ||
78 | static inline void _tg3_flag_set(enum TG3_FLAGS flag, unsigned long *bits) | |
79 | { | |
80 | set_bit(flag, bits); | |
81 | } | |
82 | ||
83 | static inline void _tg3_flag_clear(enum TG3_FLAGS flag, unsigned long *bits) | |
84 | { | |
85 | clear_bit(flag, bits); | |
86 | } | |
87 | ||
88 | #define tg3_flag(tp, flag) \ | |
89 | _tg3_flag(TG3_FLAG_##flag, (tp)->tg3_flags) | |
90 | #define tg3_flag_set(tp, flag) \ | |
91 | _tg3_flag_set(TG3_FLAG_##flag, (tp)->tg3_flags) | |
92 | #define tg3_flag_clear(tp, flag) \ | |
93 | _tg3_flag_clear(TG3_FLAG_##flag, (tp)->tg3_flags) | |
94 | ||
1da177e4 | 95 | #define DRV_MODULE_NAME "tg3" |
6867c843 | 96 | #define TG3_MAJ_NUM 3 |
c2bba067 | 97 | #define TG3_MIN_NUM 132 |
6867c843 MC |
98 | #define DRV_MODULE_VERSION \ |
99 | __stringify(TG3_MAJ_NUM) "." __stringify(TG3_MIN_NUM) | |
c2bba067 | 100 | #define DRV_MODULE_RELDATE "May 21, 2013" |
1da177e4 | 101 | |
fd6d3f0e MC |
102 | #define RESET_KIND_SHUTDOWN 0 |
103 | #define RESET_KIND_INIT 1 | |
104 | #define RESET_KIND_SUSPEND 2 | |
105 | ||
1da177e4 LT |
106 | #define TG3_DEF_RX_MODE 0 |
107 | #define TG3_DEF_TX_MODE 0 | |
108 | #define TG3_DEF_MSG_ENABLE \ | |
109 | (NETIF_MSG_DRV | \ | |
110 | NETIF_MSG_PROBE | \ | |
111 | NETIF_MSG_LINK | \ | |
112 | NETIF_MSG_TIMER | \ | |
113 | NETIF_MSG_IFDOWN | \ | |
114 | NETIF_MSG_IFUP | \ | |
115 | NETIF_MSG_RX_ERR | \ | |
116 | NETIF_MSG_TX_ERR) | |
117 | ||
520b2756 MC |
118 | #define TG3_GRC_LCLCTL_PWRSW_DELAY 100 |
119 | ||
1da177e4 LT |
120 | /* length of time before we decide the hardware is borked, |
121 | * and dev->tx_timeout() should be called to fix the problem | |
122 | */ | |
63c3a66f | 123 | |
1da177e4 LT |
124 | #define TG3_TX_TIMEOUT (5 * HZ) |
125 | ||
126 | /* hardware minimum and maximum for a single frame's data payload */ | |
127 | #define TG3_MIN_MTU 60 | |
128 | #define TG3_MAX_MTU(tp) \ | |
63c3a66f | 129 | (tg3_flag(tp, JUMBO_CAPABLE) ? 9000 : 1500) |
1da177e4 LT |
130 | |
131 | /* These numbers seem to be hard coded in the NIC firmware somehow. | |
132 | * You can't change the ring sizes, but you can change where you place | |
133 | * them in the NIC onboard memory. | |
134 | */ | |
7cb32cf2 | 135 | #define TG3_RX_STD_RING_SIZE(tp) \ |
63c3a66f | 136 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
de9f5230 | 137 | TG3_RX_STD_MAX_SIZE_5717 : TG3_RX_STD_MAX_SIZE_5700) |
1da177e4 | 138 | #define TG3_DEF_RX_RING_PENDING 200 |
7cb32cf2 | 139 | #define TG3_RX_JMB_RING_SIZE(tp) \ |
63c3a66f | 140 | (tg3_flag(tp, LRG_PROD_RING_CAP) ? \ |
de9f5230 | 141 | TG3_RX_JMB_MAX_SIZE_5717 : TG3_RX_JMB_MAX_SIZE_5700) |
1da177e4 LT |
142 | #define TG3_DEF_RX_JUMBO_RING_PENDING 100 |
143 | ||
144 | /* Do not place this n-ring entries value into the tp struct itself, | |
145 | * we really want to expose these constants to GCC so that modulo et | |
146 | * al. operations are done with shifts and masks instead of with | |
147 | * hw multiply/modulo instructions. Another solution would be to | |
148 | * replace things like '% foo' with '& (foo - 1)'. | |
149 | */ | |
1da177e4 LT |
150 | |
151 | #define TG3_TX_RING_SIZE 512 | |
152 | #define TG3_DEF_TX_RING_PENDING (TG3_TX_RING_SIZE - 1) | |
153 | ||
2c49a44d MC |
154 | #define TG3_RX_STD_RING_BYTES(tp) \ |
155 | (sizeof(struct tg3_rx_buffer_desc) * TG3_RX_STD_RING_SIZE(tp)) | |
156 | #define TG3_RX_JMB_RING_BYTES(tp) \ | |
157 | (sizeof(struct tg3_ext_rx_buffer_desc) * TG3_RX_JMB_RING_SIZE(tp)) | |
158 | #define TG3_RX_RCB_RING_BYTES(tp) \ | |
7cb32cf2 | 159 | (sizeof(struct tg3_rx_buffer_desc) * (tp->rx_ret_ring_mask + 1)) |
1da177e4 LT |
160 | #define TG3_TX_RING_BYTES (sizeof(struct tg3_tx_buffer_desc) * \ |
161 | TG3_TX_RING_SIZE) | |
1da177e4 LT |
162 | #define NEXT_TX(N) (((N) + 1) & (TG3_TX_RING_SIZE - 1)) |
163 | ||
287be12e MC |
164 | #define TG3_DMA_BYTE_ENAB 64 |
165 | ||
166 | #define TG3_RX_STD_DMA_SZ 1536 | |
167 | #define TG3_RX_JMB_DMA_SZ 9046 | |
168 | ||
169 | #define TG3_RX_DMA_TO_MAP_SZ(x) ((x) + TG3_DMA_BYTE_ENAB) | |
170 | ||
171 | #define TG3_RX_STD_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_STD_DMA_SZ) | |
172 | #define TG3_RX_JMB_MAP_SZ TG3_RX_DMA_TO_MAP_SZ(TG3_RX_JMB_DMA_SZ) | |
1da177e4 | 173 | |
2c49a44d MC |
174 | #define TG3_RX_STD_BUFF_RING_SIZE(tp) \ |
175 | (sizeof(struct ring_info) * TG3_RX_STD_RING_SIZE(tp)) | |
2b2cdb65 | 176 | |
2c49a44d MC |
177 | #define TG3_RX_JMB_BUFF_RING_SIZE(tp) \ |
178 | (sizeof(struct ring_info) * TG3_RX_JMB_RING_SIZE(tp)) | |
2b2cdb65 | 179 | |
d2757fc4 MC |
180 | /* Due to a hardware bug, the 5701 can only DMA to memory addresses |
181 | * that are at least dword aligned when used in PCIX mode. The driver | |
182 | * works around this bug by double copying the packet. This workaround | |
183 | * is built into the normal double copy length check for efficiency. | |
184 | * | |
185 | * However, the double copy is only necessary on those architectures | |
186 | * where unaligned memory accesses are inefficient. For those architectures | |
187 | * where unaligned memory accesses incur little penalty, we can reintegrate | |
188 | * the 5701 in the normal rx path. Doing so saves a device structure | |
189 | * dereference by hardcoding the double copy threshold in place. | |
190 | */ | |
191 | #define TG3_RX_COPY_THRESHOLD 256 | |
192 | #if NET_IP_ALIGN == 0 || defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) | |
193 | #define TG3_RX_COPY_THRESH(tp) TG3_RX_COPY_THRESHOLD | |
194 | #else | |
195 | #define TG3_RX_COPY_THRESH(tp) ((tp)->rx_copy_thresh) | |
196 | #endif | |
197 | ||
81389f57 MC |
198 | #if (NET_IP_ALIGN != 0) |
199 | #define TG3_RX_OFFSET(tp) ((tp)->rx_offset) | |
200 | #else | |
9205fd9c | 201 | #define TG3_RX_OFFSET(tp) (NET_SKB_PAD) |
81389f57 MC |
202 | #endif |
203 | ||
1da177e4 | 204 | /* minimum number of free TX descriptors required to wake up TX process */ |
f3f3f27e | 205 | #define TG3_TX_WAKEUP_THRESH(tnapi) ((tnapi)->tx_pending / 4) |
55086ad9 | 206 | #define TG3_TX_BD_DMA_MAX_2K 2048 |
a4cb428d | 207 | #define TG3_TX_BD_DMA_MAX_4K 4096 |
1da177e4 | 208 | |
ad829268 MC |
209 | #define TG3_RAW_IP_ALIGN 2 |
210 | ||
c6cdf436 | 211 | #define TG3_FW_UPDATE_TIMEOUT_SEC 5 |
21f7638e | 212 | #define TG3_FW_UPDATE_FREQ_SEC (TG3_FW_UPDATE_TIMEOUT_SEC / 2) |
c6cdf436 | 213 | |
077f849d | 214 | #define FIRMWARE_TG3 "tigon/tg3.bin" |
c4dab506 | 215 | #define FIRMWARE_TG357766 "tigon/tg357766.bin" |
077f849d JSR |
216 | #define FIRMWARE_TG3TSO "tigon/tg3_tso.bin" |
217 | #define FIRMWARE_TG3TSO5 "tigon/tg3_tso5.bin" | |
218 | ||
229b1ad1 | 219 | static char version[] = |
05dbe005 | 220 | DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")"; |
1da177e4 LT |
221 | |
222 | MODULE_AUTHOR("David S. Miller (davem@redhat.com) and Jeff Garzik (jgarzik@pobox.com)"); | |
223 | MODULE_DESCRIPTION("Broadcom Tigon3 ethernet driver"); | |
224 | MODULE_LICENSE("GPL"); | |
225 | MODULE_VERSION(DRV_MODULE_VERSION); | |
077f849d JSR |
226 | MODULE_FIRMWARE(FIRMWARE_TG3); |
227 | MODULE_FIRMWARE(FIRMWARE_TG3TSO); | |
228 | MODULE_FIRMWARE(FIRMWARE_TG3TSO5); | |
229 | ||
1da177e4 LT |
230 | static int tg3_debug = -1; /* -1 == use TG3_DEF_MSG_ENABLE as value */ |
231 | module_param(tg3_debug, int, 0); | |
232 | MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value"); | |
233 | ||
3d567e0e NNS |
234 | #define TG3_DRV_DATA_FLAG_10_100_ONLY 0x0001 |
235 | #define TG3_DRV_DATA_FLAG_5705_10_100 0x0002 | |
236 | ||
a3aa1884 | 237 | static DEFINE_PCI_DEVICE_TABLE(tg3_pci_tbl) = { |
13185217 HK |
238 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700)}, |
239 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5701)}, | |
240 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702)}, | |
241 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703)}, | |
242 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704)}, | |
243 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702FE)}, | |
244 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705)}, | |
245 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705_2)}, | |
246 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M)}, | |
247 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705M_2)}, | |
248 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702X)}, | |
249 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703X)}, | |
250 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S)}, | |
251 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5702A3)}, | |
252 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5703A3)}, | |
253 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5782)}, | |
254 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5788)}, | |
255 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5789)}, | |
3d567e0e NNS |
256 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901), |
257 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY | | |
258 | TG3_DRV_DATA_FLAG_5705_10_100}, | |
259 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5901_2), | |
260 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY | | |
261 | TG3_DRV_DATA_FLAG_5705_10_100}, | |
13185217 | 262 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5704S_2)}, |
3d567e0e NNS |
263 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5705F), |
264 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY | | |
265 | TG3_DRV_DATA_FLAG_5705_10_100}, | |
13185217 | 266 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5721)}, |
126a3368 | 267 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5722)}, |
7e6c63f0 | 268 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5750)}, |
13185217 | 269 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751)}, |
13185217 | 270 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751M)}, |
3d567e0e NNS |
271 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5751F), |
272 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, | |
13185217 HK |
273 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752)}, |
274 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5752M)}, | |
275 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753)}, | |
276 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753M)}, | |
3d567e0e NNS |
277 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5753F), |
278 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, | |
13185217 HK |
279 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754)}, |
280 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5754M)}, | |
281 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755)}, | |
282 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5755M)}, | |
126a3368 | 283 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5756)}, |
13185217 HK |
284 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5786)}, |
285 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787)}, | |
3d567e0e NNS |
286 | {PCI_DEVICE_SUB(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5787M, |
287 | PCI_VENDOR_ID_LENOVO, | |
288 | TG3PCI_SUBDEVICE_ID_LENOVO_5787M), | |
289 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, | |
13185217 | 290 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787M)}, |
3d567e0e NNS |
291 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5787F), |
292 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, | |
13185217 HK |
293 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714)}, |
294 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5714S)}, | |
295 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715)}, | |
296 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5715S)}, | |
297 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780)}, | |
298 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5780S)}, | |
299 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5781)}, | |
b5d3772c MC |
300 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906)}, |
301 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5906M)}, | |
d30cdd28 MC |
302 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5784)}, |
303 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5764)}, | |
6c7af27c | 304 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5723)}, |
9936bcf6 MC |
305 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761)}, |
306 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5761E)}, | |
c88e668b MC |
307 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761S)}, |
308 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5761SE)}, | |
2befdcea MC |
309 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_G)}, |
310 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5785_F)}, | |
3d567e0e NNS |
311 | {PCI_DEVICE_SUB(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780, |
312 | PCI_VENDOR_ID_AI, TG3PCI_SUBDEVICE_ID_ACER_57780_A), | |
313 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, | |
314 | {PCI_DEVICE_SUB(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780, | |
315 | PCI_VENDOR_ID_AI, TG3PCI_SUBDEVICE_ID_ACER_57780_B), | |
316 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, | |
321d32a0 MC |
317 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57780)}, |
318 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57760)}, | |
3d567e0e NNS |
319 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57790), |
320 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, | |
5e7ccf20 | 321 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57788)}, |
5001e2f6 | 322 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717)}, |
79d49695 | 323 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5717_C)}, |
5001e2f6 | 324 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5718)}, |
b0f75221 MC |
325 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57781)}, |
326 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57785)}, | |
327 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57761)}, | |
328 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57765)}, | |
3d567e0e NNS |
329 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57791), |
330 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, | |
331 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57795), | |
332 | .driver_data = TG3_DRV_DATA_FLAG_10_100_ONLY}, | |
302b500b | 333 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5719)}, |
ba1f3c76 | 334 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5720)}, |
02eca3f5 | 335 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57762)}, |
d3f677af | 336 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_57766)}, |
c86a8560 MC |
337 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5762)}, |
338 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5725)}, | |
339 | {PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, TG3PCI_DEVICE_TIGON3_5727)}, | |
13185217 HK |
340 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9DXX)}, |
341 | {PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_9MXX)}, | |
342 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000)}, | |
343 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1001)}, | |
344 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1003)}, | |
345 | {PCI_DEVICE(PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100)}, | |
346 | {PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_TIGON3)}, | |
1dcb14d9 | 347 | {PCI_DEVICE(0x10cf, 0x11a2)}, /* Fujitsu 1000base-SX with BCM5703SKHB */ |
13185217 | 348 | {} |
1da177e4 LT |
349 | }; |
350 | ||
351 | MODULE_DEVICE_TABLE(pci, tg3_pci_tbl); | |
352 | ||
50da859d | 353 | static const struct { |
1da177e4 | 354 | const char string[ETH_GSTRING_LEN]; |
48fa55a0 | 355 | } ethtool_stats_keys[] = { |
1da177e4 LT |
356 | { "rx_octets" }, |
357 | { "rx_fragments" }, | |
358 | { "rx_ucast_packets" }, | |
359 | { "rx_mcast_packets" }, | |
360 | { "rx_bcast_packets" }, | |
361 | { "rx_fcs_errors" }, | |
362 | { "rx_align_errors" }, | |
363 | { "rx_xon_pause_rcvd" }, | |
364 | { "rx_xoff_pause_rcvd" }, | |
365 | { "rx_mac_ctrl_rcvd" }, | |
366 | { "rx_xoff_entered" }, | |
367 | { "rx_frame_too_long_errors" }, | |
368 | { "rx_jabbers" }, | |
369 | { "rx_undersize_packets" }, | |
370 | { "rx_in_length_errors" }, | |
371 | { "rx_out_length_errors" }, | |
372 | { "rx_64_or_less_octet_packets" }, | |
373 | { "rx_65_to_127_octet_packets" }, | |
374 | { "rx_128_to_255_octet_packets" }, | |
375 | { "rx_256_to_511_octet_packets" }, | |
376 | { "rx_512_to_1023_octet_packets" }, | |
377 | { "rx_1024_to_1522_octet_packets" }, | |
378 | { "rx_1523_to_2047_octet_packets" }, | |
379 | { "rx_2048_to_4095_octet_packets" }, | |
380 | { "rx_4096_to_8191_octet_packets" }, | |
381 | { "rx_8192_to_9022_octet_packets" }, | |
382 | ||
383 | { "tx_octets" }, | |
384 | { "tx_collisions" }, | |
385 | ||
386 | { "tx_xon_sent" }, | |
387 | { "tx_xoff_sent" }, | |
388 | { "tx_flow_control" }, | |
389 | { "tx_mac_errors" }, | |
390 | { "tx_single_collisions" }, | |
391 | { "tx_mult_collisions" }, | |
392 | { "tx_deferred" }, | |
393 | { "tx_excessive_collisions" }, | |
394 | { "tx_late_collisions" }, | |
395 | { "tx_collide_2times" }, | |
396 | { "tx_collide_3times" }, | |
397 | { "tx_collide_4times" }, | |
398 | { "tx_collide_5times" }, | |
399 | { "tx_collide_6times" }, | |
400 | { "tx_collide_7times" }, | |
401 | { "tx_collide_8times" }, | |
402 | { "tx_collide_9times" }, | |
403 | { "tx_collide_10times" }, | |
404 | { "tx_collide_11times" }, | |
405 | { "tx_collide_12times" }, | |
406 | { "tx_collide_13times" }, | |
407 | { "tx_collide_14times" }, | |
408 | { "tx_collide_15times" }, | |
409 | { "tx_ucast_packets" }, | |
410 | { "tx_mcast_packets" }, | |
411 | { "tx_bcast_packets" }, | |
412 | { "tx_carrier_sense_errors" }, | |
413 | { "tx_discards" }, | |
414 | { "tx_errors" }, | |
415 | ||
416 | { "dma_writeq_full" }, | |
417 | { "dma_write_prioq_full" }, | |
418 | { "rxbds_empty" }, | |
419 | { "rx_discards" }, | |
420 | { "rx_errors" }, | |
421 | { "rx_threshold_hit" }, | |
422 | ||
423 | { "dma_readq_full" }, | |
424 | { "dma_read_prioq_full" }, | |
425 | { "tx_comp_queue_full" }, | |
426 | ||
427 | { "ring_set_send_prod_index" }, | |
428 | { "ring_status_update" }, | |
429 | { "nic_irqs" }, | |
430 | { "nic_avoided_irqs" }, | |
4452d099 MC |
431 | { "nic_tx_threshold_hit" }, |
432 | ||
433 | { "mbuf_lwm_thresh_hit" }, | |
1da177e4 LT |
434 | }; |
435 | ||
48fa55a0 | 436 | #define TG3_NUM_STATS ARRAY_SIZE(ethtool_stats_keys) |
93df8b8f NNS |
437 | #define TG3_NVRAM_TEST 0 |
438 | #define TG3_LINK_TEST 1 | |
439 | #define TG3_REGISTER_TEST 2 | |
440 | #define TG3_MEMORY_TEST 3 | |
441 | #define TG3_MAC_LOOPB_TEST 4 | |
442 | #define TG3_PHY_LOOPB_TEST 5 | |
443 | #define TG3_EXT_LOOPB_TEST 6 | |
444 | #define TG3_INTERRUPT_TEST 7 | |
48fa55a0 MC |
445 | |
446 | ||
50da859d | 447 | static const struct { |
4cafd3f5 | 448 | const char string[ETH_GSTRING_LEN]; |
48fa55a0 | 449 | } ethtool_test_keys[] = { |
93df8b8f NNS |
450 | [TG3_NVRAM_TEST] = { "nvram test (online) " }, |
451 | [TG3_LINK_TEST] = { "link test (online) " }, | |
452 | [TG3_REGISTER_TEST] = { "register test (offline)" }, | |
453 | [TG3_MEMORY_TEST] = { "memory test (offline)" }, | |
454 | [TG3_MAC_LOOPB_TEST] = { "mac loopback test (offline)" }, | |
455 | [TG3_PHY_LOOPB_TEST] = { "phy loopback test (offline)" }, | |
456 | [TG3_EXT_LOOPB_TEST] = { "ext loopback test (offline)" }, | |
457 | [TG3_INTERRUPT_TEST] = { "interrupt test (offline)" }, | |
4cafd3f5 MC |
458 | }; |
459 | ||
48fa55a0 MC |
460 | #define TG3_NUM_TEST ARRAY_SIZE(ethtool_test_keys) |
461 | ||
462 | ||
b401e9e2 MC |
463 | static void tg3_write32(struct tg3 *tp, u32 off, u32 val) |
464 | { | |
465 | writel(val, tp->regs + off); | |
466 | } | |
467 | ||
468 | static u32 tg3_read32(struct tg3 *tp, u32 off) | |
469 | { | |
de6f31eb | 470 | return readl(tp->regs + off); |
b401e9e2 MC |
471 | } |
472 | ||
0d3031d9 MC |
473 | static void tg3_ape_write32(struct tg3 *tp, u32 off, u32 val) |
474 | { | |
475 | writel(val, tp->aperegs + off); | |
476 | } | |
477 | ||
478 | static u32 tg3_ape_read32(struct tg3 *tp, u32 off) | |
479 | { | |
de6f31eb | 480 | return readl(tp->aperegs + off); |
0d3031d9 MC |
481 | } |
482 | ||
1da177e4 LT |
483 | static void tg3_write_indirect_reg32(struct tg3 *tp, u32 off, u32 val) |
484 | { | |
6892914f MC |
485 | unsigned long flags; |
486 | ||
487 | spin_lock_irqsave(&tp->indirect_lock, flags); | |
1ee582d8 MC |
488 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); |
489 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); | |
6892914f | 490 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
1ee582d8 MC |
491 | } |
492 | ||
493 | static void tg3_write_flush_reg32(struct tg3 *tp, u32 off, u32 val) | |
494 | { | |
495 | writel(val, tp->regs + off); | |
496 | readl(tp->regs + off); | |
1da177e4 LT |
497 | } |
498 | ||
6892914f | 499 | static u32 tg3_read_indirect_reg32(struct tg3 *tp, u32 off) |
1da177e4 | 500 | { |
6892914f MC |
501 | unsigned long flags; |
502 | u32 val; | |
503 | ||
504 | spin_lock_irqsave(&tp->indirect_lock, flags); | |
505 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off); | |
506 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); | |
507 | spin_unlock_irqrestore(&tp->indirect_lock, flags); | |
508 | return val; | |
509 | } | |
510 | ||
511 | static void tg3_write_indirect_mbox(struct tg3 *tp, u32 off, u32 val) | |
512 | { | |
513 | unsigned long flags; | |
514 | ||
515 | if (off == (MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW)) { | |
516 | pci_write_config_dword(tp->pdev, TG3PCI_RCV_RET_RING_CON_IDX + | |
517 | TG3_64BIT_REG_LOW, val); | |
518 | return; | |
519 | } | |
66711e66 | 520 | if (off == TG3_RX_STD_PROD_IDX_REG) { |
6892914f MC |
521 | pci_write_config_dword(tp->pdev, TG3PCI_STD_RING_PROD_IDX + |
522 | TG3_64BIT_REG_LOW, val); | |
523 | return; | |
1da177e4 | 524 | } |
6892914f MC |
525 | |
526 | spin_lock_irqsave(&tp->indirect_lock, flags); | |
527 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); | |
528 | pci_write_config_dword(tp->pdev, TG3PCI_REG_DATA, val); | |
529 | spin_unlock_irqrestore(&tp->indirect_lock, flags); | |
530 | ||
531 | /* In indirect mode when disabling interrupts, we also need | |
532 | * to clear the interrupt bit in the GRC local ctrl register. | |
533 | */ | |
534 | if ((off == (MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW)) && | |
535 | (val == 0x1)) { | |
536 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_LOCAL_CTRL, | |
537 | tp->grc_local_ctrl|GRC_LCLCTRL_CLEARINT); | |
538 | } | |
539 | } | |
540 | ||
541 | static u32 tg3_read_indirect_mbox(struct tg3 *tp, u32 off) | |
542 | { | |
543 | unsigned long flags; | |
544 | u32 val; | |
545 | ||
546 | spin_lock_irqsave(&tp->indirect_lock, flags); | |
547 | pci_write_config_dword(tp->pdev, TG3PCI_REG_BASE_ADDR, off + 0x5600); | |
548 | pci_read_config_dword(tp->pdev, TG3PCI_REG_DATA, &val); | |
549 | spin_unlock_irqrestore(&tp->indirect_lock, flags); | |
550 | return val; | |
551 | } | |
552 | ||
b401e9e2 MC |
553 | /* usec_wait specifies the wait time in usec when writing to certain registers |
554 | * where it is unsafe to read back the register without some delay. | |
555 | * GRC_LOCAL_CTRL is one example if the GPIOs are toggled to switch power. | |
556 | * TG3PCI_CLOCK_CTRL is another example if the clock frequencies are changed. | |
557 | */ | |
558 | static void _tw32_flush(struct tg3 *tp, u32 off, u32 val, u32 usec_wait) | |
6892914f | 559 | { |
63c3a66f | 560 | if (tg3_flag(tp, PCIX_TARGET_HWBUG) || tg3_flag(tp, ICH_WORKAROUND)) |
b401e9e2 MC |
561 | /* Non-posted methods */ |
562 | tp->write32(tp, off, val); | |
563 | else { | |
564 | /* Posted method */ | |
565 | tg3_write32(tp, off, val); | |
566 | if (usec_wait) | |
567 | udelay(usec_wait); | |
568 | tp->read32(tp, off); | |
569 | } | |
570 | /* Wait again after the read for the posted method to guarantee that | |
571 | * the wait time is met. | |
572 | */ | |
573 | if (usec_wait) | |
574 | udelay(usec_wait); | |
1da177e4 LT |
575 | } |
576 | ||
09ee929c MC |
577 | static inline void tw32_mailbox_flush(struct tg3 *tp, u32 off, u32 val) |
578 | { | |
579 | tp->write32_mbox(tp, off, val); | |
7e6c63f0 HM |
580 | if (tg3_flag(tp, FLUSH_POSTED_WRITES) || |
581 | (!tg3_flag(tp, MBOX_WRITE_REORDER) && | |
582 | !tg3_flag(tp, ICH_WORKAROUND))) | |
6892914f | 583 | tp->read32_mbox(tp, off); |
09ee929c MC |
584 | } |
585 | ||
20094930 | 586 | static void tg3_write32_tx_mbox(struct tg3 *tp, u32 off, u32 val) |
1da177e4 LT |
587 | { |
588 | void __iomem *mbox = tp->regs + off; | |
589 | writel(val, mbox); | |
63c3a66f | 590 | if (tg3_flag(tp, TXD_MBOX_HWBUG)) |
1da177e4 | 591 | writel(val, mbox); |
7e6c63f0 HM |
592 | if (tg3_flag(tp, MBOX_WRITE_REORDER) || |
593 | tg3_flag(tp, FLUSH_POSTED_WRITES)) | |
1da177e4 LT |
594 | readl(mbox); |
595 | } | |
596 | ||
b5d3772c MC |
597 | static u32 tg3_read32_mbox_5906(struct tg3 *tp, u32 off) |
598 | { | |
de6f31eb | 599 | return readl(tp->regs + off + GRCMBOX_BASE); |
b5d3772c MC |
600 | } |
601 | ||
602 | static void tg3_write32_mbox_5906(struct tg3 *tp, u32 off, u32 val) | |
603 | { | |
604 | writel(val, tp->regs + off + GRCMBOX_BASE); | |
605 | } | |
606 | ||
c6cdf436 | 607 | #define tw32_mailbox(reg, val) tp->write32_mbox(tp, reg, val) |
09ee929c | 608 | #define tw32_mailbox_f(reg, val) tw32_mailbox_flush(tp, (reg), (val)) |
c6cdf436 MC |
609 | #define tw32_rx_mbox(reg, val) tp->write32_rx_mbox(tp, reg, val) |
610 | #define tw32_tx_mbox(reg, val) tp->write32_tx_mbox(tp, reg, val) | |
611 | #define tr32_mailbox(reg) tp->read32_mbox(tp, reg) | |
20094930 | 612 | |
c6cdf436 MC |
613 | #define tw32(reg, val) tp->write32(tp, reg, val) |
614 | #define tw32_f(reg, val) _tw32_flush(tp, (reg), (val), 0) | |
615 | #define tw32_wait_f(reg, val, us) _tw32_flush(tp, (reg), (val), (us)) | |
616 | #define tr32(reg) tp->read32(tp, reg) | |
1da177e4 LT |
617 | |
618 | static void tg3_write_mem(struct tg3 *tp, u32 off, u32 val) | |
619 | { | |
6892914f MC |
620 | unsigned long flags; |
621 | ||
4153577a | 622 | if (tg3_asic_rev(tp) == ASIC_REV_5906 && |
b5d3772c MC |
623 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) |
624 | return; | |
625 | ||
6892914f | 626 | spin_lock_irqsave(&tp->indirect_lock, flags); |
63c3a66f | 627 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
bbadf503 MC |
628 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
629 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); | |
1da177e4 | 630 | |
bbadf503 MC |
631 | /* Always leave this as zero. */ |
632 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
633 | } else { | |
634 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); | |
635 | tw32_f(TG3PCI_MEM_WIN_DATA, val); | |
28fbef78 | 636 | |
bbadf503 MC |
637 | /* Always leave this as zero. */ |
638 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
639 | } | |
640 | spin_unlock_irqrestore(&tp->indirect_lock, flags); | |
758a6139 DM |
641 | } |
642 | ||
1da177e4 LT |
643 | static void tg3_read_mem(struct tg3 *tp, u32 off, u32 *val) |
644 | { | |
6892914f MC |
645 | unsigned long flags; |
646 | ||
4153577a | 647 | if (tg3_asic_rev(tp) == ASIC_REV_5906 && |
b5d3772c MC |
648 | (off >= NIC_SRAM_STATS_BLK) && (off < NIC_SRAM_TX_BUFFER_DESC)) { |
649 | *val = 0; | |
650 | return; | |
651 | } | |
652 | ||
6892914f | 653 | spin_lock_irqsave(&tp->indirect_lock, flags); |
63c3a66f | 654 | if (tg3_flag(tp, SRAM_USE_CONFIG)) { |
bbadf503 MC |
655 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, off); |
656 | pci_read_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); | |
1da177e4 | 657 | |
bbadf503 MC |
658 | /* Always leave this as zero. */ |
659 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
660 | } else { | |
661 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, off); | |
662 | *val = tr32(TG3PCI_MEM_WIN_DATA); | |
663 | ||
664 | /* Always leave this as zero. */ | |
665 | tw32_f(TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
666 | } | |
6892914f | 667 | spin_unlock_irqrestore(&tp->indirect_lock, flags); |
1da177e4 LT |
668 | } |
669 | ||
0d3031d9 MC |
670 | static void tg3_ape_lock_init(struct tg3 *tp) |
671 | { | |
672 | int i; | |
6f5c8f83 | 673 | u32 regbase, bit; |
f92d9dc1 | 674 | |
4153577a | 675 | if (tg3_asic_rev(tp) == ASIC_REV_5761) |
f92d9dc1 MC |
676 | regbase = TG3_APE_LOCK_GRANT; |
677 | else | |
678 | regbase = TG3_APE_PER_LOCK_GRANT; | |
0d3031d9 MC |
679 | |
680 | /* Make sure the driver hasn't any stale locks. */ | |
78f94dc7 MC |
681 | for (i = TG3_APE_LOCK_PHY0; i <= TG3_APE_LOCK_GPIO; i++) { |
682 | switch (i) { | |
683 | case TG3_APE_LOCK_PHY0: | |
684 | case TG3_APE_LOCK_PHY1: | |
685 | case TG3_APE_LOCK_PHY2: | |
686 | case TG3_APE_LOCK_PHY3: | |
687 | bit = APE_LOCK_GRANT_DRIVER; | |
688 | break; | |
689 | default: | |
690 | if (!tp->pci_fn) | |
691 | bit = APE_LOCK_GRANT_DRIVER; | |
692 | else | |
693 | bit = 1 << tp->pci_fn; | |
694 | } | |
695 | tg3_ape_write32(tp, regbase + 4 * i, bit); | |
6f5c8f83 MC |
696 | } |
697 | ||
0d3031d9 MC |
698 | } |
699 | ||
700 | static int tg3_ape_lock(struct tg3 *tp, int locknum) | |
701 | { | |
702 | int i, off; | |
703 | int ret = 0; | |
6f5c8f83 | 704 | u32 status, req, gnt, bit; |
0d3031d9 | 705 | |
63c3a66f | 706 | if (!tg3_flag(tp, ENABLE_APE)) |
0d3031d9 MC |
707 | return 0; |
708 | ||
709 | switch (locknum) { | |
6f5c8f83 | 710 | case TG3_APE_LOCK_GPIO: |
4153577a | 711 | if (tg3_asic_rev(tp) == ASIC_REV_5761) |
6f5c8f83 | 712 | return 0; |
33f401ae MC |
713 | case TG3_APE_LOCK_GRC: |
714 | case TG3_APE_LOCK_MEM: | |
78f94dc7 MC |
715 | if (!tp->pci_fn) |
716 | bit = APE_LOCK_REQ_DRIVER; | |
717 | else | |
718 | bit = 1 << tp->pci_fn; | |
33f401ae | 719 | break; |
8151ad57 MC |
720 | case TG3_APE_LOCK_PHY0: |
721 | case TG3_APE_LOCK_PHY1: | |
722 | case TG3_APE_LOCK_PHY2: | |
723 | case TG3_APE_LOCK_PHY3: | |
724 | bit = APE_LOCK_REQ_DRIVER; | |
725 | break; | |
33f401ae MC |
726 | default: |
727 | return -EINVAL; | |
0d3031d9 MC |
728 | } |
729 | ||
4153577a | 730 | if (tg3_asic_rev(tp) == ASIC_REV_5761) { |
f92d9dc1 MC |
731 | req = TG3_APE_LOCK_REQ; |
732 | gnt = TG3_APE_LOCK_GRANT; | |
733 | } else { | |
734 | req = TG3_APE_PER_LOCK_REQ; | |
735 | gnt = TG3_APE_PER_LOCK_GRANT; | |
736 | } | |
737 | ||
0d3031d9 MC |
738 | off = 4 * locknum; |
739 | ||
6f5c8f83 | 740 | tg3_ape_write32(tp, req + off, bit); |
0d3031d9 MC |
741 | |
742 | /* Wait for up to 1 millisecond to acquire lock. */ | |
743 | for (i = 0; i < 100; i++) { | |
f92d9dc1 | 744 | status = tg3_ape_read32(tp, gnt + off); |
6f5c8f83 | 745 | if (status == bit) |
0d3031d9 | 746 | break; |
6d446ec3 GS |
747 | if (pci_channel_offline(tp->pdev)) |
748 | break; | |
749 | ||
0d3031d9 MC |
750 | udelay(10); |
751 | } | |
752 | ||
6f5c8f83 | 753 | if (status != bit) { |
0d3031d9 | 754 | /* Revoke the lock request. */ |
6f5c8f83 | 755 | tg3_ape_write32(tp, gnt + off, bit); |
0d3031d9 MC |
756 | ret = -EBUSY; |
757 | } | |
758 | ||
759 | return ret; | |
760 | } | |
761 | ||
762 | static void tg3_ape_unlock(struct tg3 *tp, int locknum) | |
763 | { | |
6f5c8f83 | 764 | u32 gnt, bit; |
0d3031d9 | 765 | |
63c3a66f | 766 | if (!tg3_flag(tp, ENABLE_APE)) |
0d3031d9 MC |
767 | return; |
768 | ||
769 | switch (locknum) { | |
6f5c8f83 | 770 | case TG3_APE_LOCK_GPIO: |
4153577a | 771 | if (tg3_asic_rev(tp) == ASIC_REV_5761) |
6f5c8f83 | 772 | return; |
33f401ae MC |
773 | case TG3_APE_LOCK_GRC: |
774 | case TG3_APE_LOCK_MEM: | |
78f94dc7 MC |
775 | if (!tp->pci_fn) |
776 | bit = APE_LOCK_GRANT_DRIVER; | |
777 | else | |
778 | bit = 1 << tp->pci_fn; | |
33f401ae | 779 | break; |
8151ad57 MC |
780 | case TG3_APE_LOCK_PHY0: |
781 | case TG3_APE_LOCK_PHY1: | |
782 | case TG3_APE_LOCK_PHY2: | |
783 | case TG3_APE_LOCK_PHY3: | |
784 | bit = APE_LOCK_GRANT_DRIVER; | |
785 | break; | |
33f401ae MC |
786 | default: |
787 | return; | |
0d3031d9 MC |
788 | } |
789 | ||
4153577a | 790 | if (tg3_asic_rev(tp) == ASIC_REV_5761) |
f92d9dc1 MC |
791 | gnt = TG3_APE_LOCK_GRANT; |
792 | else | |
793 | gnt = TG3_APE_PER_LOCK_GRANT; | |
794 | ||
6f5c8f83 | 795 | tg3_ape_write32(tp, gnt + 4 * locknum, bit); |
0d3031d9 MC |
796 | } |
797 | ||
b65a372b | 798 | static int tg3_ape_event_lock(struct tg3 *tp, u32 timeout_us) |
fd6d3f0e | 799 | { |
fd6d3f0e MC |
800 | u32 apedata; |
801 | ||
b65a372b MC |
802 | while (timeout_us) { |
803 | if (tg3_ape_lock(tp, TG3_APE_LOCK_MEM)) | |
804 | return -EBUSY; | |
805 | ||
806 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); | |
807 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) | |
808 | break; | |
809 | ||
810 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); | |
811 | ||
812 | udelay(10); | |
813 | timeout_us -= (timeout_us > 10) ? 10 : timeout_us; | |
814 | } | |
815 | ||
816 | return timeout_us ? 0 : -EBUSY; | |
817 | } | |
818 | ||
cf8d55ae MC |
819 | static int tg3_ape_wait_for_event(struct tg3 *tp, u32 timeout_us) |
820 | { | |
821 | u32 i, apedata; | |
822 | ||
823 | for (i = 0; i < timeout_us / 10; i++) { | |
824 | apedata = tg3_ape_read32(tp, TG3_APE_EVENT_STATUS); | |
825 | ||
826 | if (!(apedata & APE_EVENT_STATUS_EVENT_PENDING)) | |
827 | break; | |
828 | ||
829 | udelay(10); | |
830 | } | |
831 | ||
832 | return i == timeout_us / 10; | |
833 | } | |
834 | ||
86449944 MC |
835 | static int tg3_ape_scratchpad_read(struct tg3 *tp, u32 *data, u32 base_off, |
836 | u32 len) | |
cf8d55ae MC |
837 | { |
838 | int err; | |
839 | u32 i, bufoff, msgoff, maxlen, apedata; | |
840 | ||
841 | if (!tg3_flag(tp, APE_HAS_NCSI)) | |
842 | return 0; | |
843 | ||
844 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); | |
845 | if (apedata != APE_SEG_SIG_MAGIC) | |
846 | return -ENODEV; | |
847 | ||
848 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); | |
849 | if (!(apedata & APE_FW_STATUS_READY)) | |
850 | return -EAGAIN; | |
851 | ||
852 | bufoff = tg3_ape_read32(tp, TG3_APE_SEG_MSG_BUF_OFF) + | |
853 | TG3_APE_SHMEM_BASE; | |
854 | msgoff = bufoff + 2 * sizeof(u32); | |
855 | maxlen = tg3_ape_read32(tp, TG3_APE_SEG_MSG_BUF_LEN); | |
856 | ||
857 | while (len) { | |
858 | u32 length; | |
859 | ||
860 | /* Cap xfer sizes to scratchpad limits. */ | |
861 | length = (len > maxlen) ? maxlen : len; | |
862 | len -= length; | |
863 | ||
864 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); | |
865 | if (!(apedata & APE_FW_STATUS_READY)) | |
866 | return -EAGAIN; | |
867 | ||
868 | /* Wait for up to 1 msec for APE to service previous event. */ | |
869 | err = tg3_ape_event_lock(tp, 1000); | |
870 | if (err) | |
871 | return err; | |
872 | ||
873 | apedata = APE_EVENT_STATUS_DRIVER_EVNT | | |
874 | APE_EVENT_STATUS_SCRTCHPD_READ | | |
875 | APE_EVENT_STATUS_EVENT_PENDING; | |
876 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, apedata); | |
877 | ||
878 | tg3_ape_write32(tp, bufoff, base_off); | |
879 | tg3_ape_write32(tp, bufoff + sizeof(u32), length); | |
880 | ||
881 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); | |
882 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); | |
883 | ||
884 | base_off += length; | |
885 | ||
886 | if (tg3_ape_wait_for_event(tp, 30000)) | |
887 | return -EAGAIN; | |
888 | ||
889 | for (i = 0; length; i += 4, length -= 4) { | |
890 | u32 val = tg3_ape_read32(tp, msgoff + i); | |
891 | memcpy(data, &val, sizeof(u32)); | |
892 | data++; | |
893 | } | |
894 | } | |
895 | ||
896 | return 0; | |
897 | } | |
898 | ||
b65a372b MC |
899 | static int tg3_ape_send_event(struct tg3 *tp, u32 event) |
900 | { | |
901 | int err; | |
902 | u32 apedata; | |
fd6d3f0e MC |
903 | |
904 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); | |
905 | if (apedata != APE_SEG_SIG_MAGIC) | |
b65a372b | 906 | return -EAGAIN; |
fd6d3f0e MC |
907 | |
908 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); | |
909 | if (!(apedata & APE_FW_STATUS_READY)) | |
b65a372b | 910 | return -EAGAIN; |
fd6d3f0e MC |
911 | |
912 | /* Wait for up to 1 millisecond for APE to service previous event. */ | |
b65a372b MC |
913 | err = tg3_ape_event_lock(tp, 1000); |
914 | if (err) | |
915 | return err; | |
fd6d3f0e | 916 | |
b65a372b MC |
917 | tg3_ape_write32(tp, TG3_APE_EVENT_STATUS, |
918 | event | APE_EVENT_STATUS_EVENT_PENDING); | |
fd6d3f0e | 919 | |
b65a372b MC |
920 | tg3_ape_unlock(tp, TG3_APE_LOCK_MEM); |
921 | tg3_ape_write32(tp, TG3_APE_EVENT, APE_EVENT_1); | |
fd6d3f0e | 922 | |
b65a372b | 923 | return 0; |
fd6d3f0e MC |
924 | } |
925 | ||
926 | static void tg3_ape_driver_state_change(struct tg3 *tp, int kind) | |
927 | { | |
928 | u32 event; | |
929 | u32 apedata; | |
930 | ||
931 | if (!tg3_flag(tp, ENABLE_APE)) | |
932 | return; | |
933 | ||
934 | switch (kind) { | |
935 | case RESET_KIND_INIT: | |
936 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, | |
937 | APE_HOST_SEG_SIG_MAGIC); | |
938 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_LEN, | |
939 | APE_HOST_SEG_LEN_MAGIC); | |
940 | apedata = tg3_ape_read32(tp, TG3_APE_HOST_INIT_COUNT); | |
941 | tg3_ape_write32(tp, TG3_APE_HOST_INIT_COUNT, ++apedata); | |
942 | tg3_ape_write32(tp, TG3_APE_HOST_DRIVER_ID, | |
943 | APE_HOST_DRIVER_ID_MAGIC(TG3_MAJ_NUM, TG3_MIN_NUM)); | |
944 | tg3_ape_write32(tp, TG3_APE_HOST_BEHAVIOR, | |
945 | APE_HOST_BEHAV_NO_PHYLOCK); | |
946 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, | |
947 | TG3_APE_HOST_DRVR_STATE_START); | |
948 | ||
949 | event = APE_EVENT_STATUS_STATE_START; | |
950 | break; | |
951 | case RESET_KIND_SHUTDOWN: | |
952 | /* With the interface we are currently using, | |
953 | * APE does not track driver state. Wiping | |
954 | * out the HOST SEGMENT SIGNATURE forces | |
955 | * the APE to assume OS absent status. | |
956 | */ | |
957 | tg3_ape_write32(tp, TG3_APE_HOST_SEG_SIG, 0x0); | |
958 | ||
959 | if (device_may_wakeup(&tp->pdev->dev) && | |
960 | tg3_flag(tp, WOL_ENABLE)) { | |
961 | tg3_ape_write32(tp, TG3_APE_HOST_WOL_SPEED, | |
962 | TG3_APE_HOST_WOL_SPEED_AUTO); | |
963 | apedata = TG3_APE_HOST_DRVR_STATE_WOL; | |
964 | } else | |
965 | apedata = TG3_APE_HOST_DRVR_STATE_UNLOAD; | |
966 | ||
967 | tg3_ape_write32(tp, TG3_APE_HOST_DRVR_STATE, apedata); | |
968 | ||
969 | event = APE_EVENT_STATUS_STATE_UNLOAD; | |
970 | break; | |
971 | case RESET_KIND_SUSPEND: | |
972 | event = APE_EVENT_STATUS_STATE_SUSPEND; | |
973 | break; | |
974 | default: | |
975 | return; | |
976 | } | |
977 | ||
978 | event |= APE_EVENT_STATUS_DRIVER_EVNT | APE_EVENT_STATUS_STATE_CHNGE; | |
979 | ||
980 | tg3_ape_send_event(tp, event); | |
981 | } | |
982 | ||
1da177e4 LT |
983 | static void tg3_disable_ints(struct tg3 *tp) |
984 | { | |
89aeb3bc MC |
985 | int i; |
986 | ||
1da177e4 LT |
987 | tw32(TG3PCI_MISC_HOST_CTRL, |
988 | (tp->misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT)); | |
89aeb3bc MC |
989 | for (i = 0; i < tp->irq_max; i++) |
990 | tw32_mailbox_f(tp->napi[i].int_mbox, 0x00000001); | |
1da177e4 LT |
991 | } |
992 | ||
1da177e4 LT |
993 | static void tg3_enable_ints(struct tg3 *tp) |
994 | { | |
89aeb3bc | 995 | int i; |
89aeb3bc | 996 | |
bbe832c0 MC |
997 | tp->irq_sync = 0; |
998 | wmb(); | |
999 | ||
1da177e4 LT |
1000 | tw32(TG3PCI_MISC_HOST_CTRL, |
1001 | (tp->misc_host_ctrl & ~MISC_HOST_CTRL_MASK_PCI_INT)); | |
89aeb3bc | 1002 | |
f89f38b8 | 1003 | tp->coal_now = tp->coalesce_mode | HOSTCC_MODE_ENABLE; |
89aeb3bc MC |
1004 | for (i = 0; i < tp->irq_cnt; i++) { |
1005 | struct tg3_napi *tnapi = &tp->napi[i]; | |
c6cdf436 | 1006 | |
898a56f8 | 1007 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
63c3a66f | 1008 | if (tg3_flag(tp, 1SHOT_MSI)) |
89aeb3bc | 1009 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); |
f19af9c2 | 1010 | |
f89f38b8 | 1011 | tp->coal_now |= tnapi->coal_now; |
89aeb3bc | 1012 | } |
f19af9c2 MC |
1013 | |
1014 | /* Force an initial interrupt */ | |
63c3a66f | 1015 | if (!tg3_flag(tp, TAGGED_STATUS) && |
f19af9c2 MC |
1016 | (tp->napi[0].hw_status->status & SD_STATUS_UPDATED)) |
1017 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); | |
1018 | else | |
f89f38b8 MC |
1019 | tw32(HOSTCC_MODE, tp->coal_now); |
1020 | ||
1021 | tp->coal_now &= ~(tp->napi[0].coal_now | tp->napi[1].coal_now); | |
1da177e4 LT |
1022 | } |
1023 | ||
17375d25 | 1024 | static inline unsigned int tg3_has_work(struct tg3_napi *tnapi) |
04237ddd | 1025 | { |
17375d25 | 1026 | struct tg3 *tp = tnapi->tp; |
898a56f8 | 1027 | struct tg3_hw_status *sblk = tnapi->hw_status; |
04237ddd MC |
1028 | unsigned int work_exists = 0; |
1029 | ||
1030 | /* check for phy events */ | |
63c3a66f | 1031 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
04237ddd MC |
1032 | if (sblk->status & SD_STATUS_LINK_CHG) |
1033 | work_exists = 1; | |
1034 | } | |
f891ea16 MC |
1035 | |
1036 | /* check for TX work to do */ | |
1037 | if (sblk->idx[0].tx_consumer != tnapi->tx_cons) | |
1038 | work_exists = 1; | |
1039 | ||
1040 | /* check for RX work to do */ | |
1041 | if (tnapi->rx_rcb_prod_idx && | |
8d9d7cfc | 1042 | *(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
04237ddd MC |
1043 | work_exists = 1; |
1044 | ||
1045 | return work_exists; | |
1046 | } | |
1047 | ||
17375d25 | 1048 | /* tg3_int_reenable |
04237ddd MC |
1049 | * similar to tg3_enable_ints, but it accurately determines whether there |
1050 | * is new work pending and can return without flushing the PIO write | |
6aa20a22 | 1051 | * which reenables interrupts |
1da177e4 | 1052 | */ |
17375d25 | 1053 | static void tg3_int_reenable(struct tg3_napi *tnapi) |
1da177e4 | 1054 | { |
17375d25 MC |
1055 | struct tg3 *tp = tnapi->tp; |
1056 | ||
898a56f8 | 1057 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); |
1da177e4 LT |
1058 | mmiowb(); |
1059 | ||
fac9b83e DM |
1060 | /* When doing tagged status, this work check is unnecessary. |
1061 | * The last_tag we write above tells the chip which piece of | |
1062 | * work we've completed. | |
1063 | */ | |
63c3a66f | 1064 | if (!tg3_flag(tp, TAGGED_STATUS) && tg3_has_work(tnapi)) |
04237ddd | 1065 | tw32(HOSTCC_MODE, tp->coalesce_mode | |
fd2ce37f | 1066 | HOSTCC_MODE_ENABLE | tnapi->coal_now); |
1da177e4 LT |
1067 | } |
1068 | ||
1da177e4 LT |
1069 | static void tg3_switch_clocks(struct tg3 *tp) |
1070 | { | |
f6eb9b1f | 1071 | u32 clock_ctrl; |
1da177e4 LT |
1072 | u32 orig_clock_ctrl; |
1073 | ||
63c3a66f | 1074 | if (tg3_flag(tp, CPMU_PRESENT) || tg3_flag(tp, 5780_CLASS)) |
4cf78e4f MC |
1075 | return; |
1076 | ||
f6eb9b1f MC |
1077 | clock_ctrl = tr32(TG3PCI_CLOCK_CTRL); |
1078 | ||
1da177e4 LT |
1079 | orig_clock_ctrl = clock_ctrl; |
1080 | clock_ctrl &= (CLOCK_CTRL_FORCE_CLKRUN | | |
1081 | CLOCK_CTRL_CLKRUN_OENABLE | | |
1082 | 0x1f); | |
1083 | tp->pci_clock_ctrl = clock_ctrl; | |
1084 | ||
63c3a66f | 1085 | if (tg3_flag(tp, 5705_PLUS)) { |
1da177e4 | 1086 | if (orig_clock_ctrl & CLOCK_CTRL_625_CORE) { |
b401e9e2 MC |
1087 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
1088 | clock_ctrl | CLOCK_CTRL_625_CORE, 40); | |
1da177e4 LT |
1089 | } |
1090 | } else if ((orig_clock_ctrl & CLOCK_CTRL_44MHZ_CORE) != 0) { | |
b401e9e2 MC |
1091 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
1092 | clock_ctrl | | |
1093 | (CLOCK_CTRL_44MHZ_CORE | CLOCK_CTRL_ALTCLK), | |
1094 | 40); | |
1095 | tw32_wait_f(TG3PCI_CLOCK_CTRL, | |
1096 | clock_ctrl | (CLOCK_CTRL_ALTCLK), | |
1097 | 40); | |
1da177e4 | 1098 | } |
b401e9e2 | 1099 | tw32_wait_f(TG3PCI_CLOCK_CTRL, clock_ctrl, 40); |
1da177e4 LT |
1100 | } |
1101 | ||
1102 | #define PHY_BUSY_LOOPS 5000 | |
1103 | ||
5c358045 HM |
1104 | static int __tg3_readphy(struct tg3 *tp, unsigned int phy_addr, int reg, |
1105 | u32 *val) | |
1da177e4 LT |
1106 | { |
1107 | u32 frame_val; | |
1108 | unsigned int loops; | |
1109 | int ret; | |
1110 | ||
1111 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { | |
1112 | tw32_f(MAC_MI_MODE, | |
1113 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); | |
1114 | udelay(80); | |
1115 | } | |
1116 | ||
8151ad57 MC |
1117 | tg3_ape_lock(tp, tp->phy_ape_lock); |
1118 | ||
1da177e4 LT |
1119 | *val = 0x0; |
1120 | ||
5c358045 | 1121 | frame_val = ((phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
1da177e4 LT |
1122 | MI_COM_PHY_ADDR_MASK); |
1123 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & | |
1124 | MI_COM_REG_ADDR_MASK); | |
1125 | frame_val |= (MI_COM_CMD_READ | MI_COM_START); | |
6aa20a22 | 1126 | |
1da177e4 LT |
1127 | tw32_f(MAC_MI_COM, frame_val); |
1128 | ||
1129 | loops = PHY_BUSY_LOOPS; | |
1130 | while (loops != 0) { | |
1131 | udelay(10); | |
1132 | frame_val = tr32(MAC_MI_COM); | |
1133 | ||
1134 | if ((frame_val & MI_COM_BUSY) == 0) { | |
1135 | udelay(5); | |
1136 | frame_val = tr32(MAC_MI_COM); | |
1137 | break; | |
1138 | } | |
1139 | loops -= 1; | |
1140 | } | |
1141 | ||
1142 | ret = -EBUSY; | |
1143 | if (loops != 0) { | |
1144 | *val = frame_val & MI_COM_DATA_MASK; | |
1145 | ret = 0; | |
1146 | } | |
1147 | ||
1148 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { | |
1149 | tw32_f(MAC_MI_MODE, tp->mi_mode); | |
1150 | udelay(80); | |
1151 | } | |
1152 | ||
8151ad57 MC |
1153 | tg3_ape_unlock(tp, tp->phy_ape_lock); |
1154 | ||
1da177e4 LT |
1155 | return ret; |
1156 | } | |
1157 | ||
5c358045 HM |
1158 | static int tg3_readphy(struct tg3 *tp, int reg, u32 *val) |
1159 | { | |
1160 | return __tg3_readphy(tp, tp->phy_addr, reg, val); | |
1161 | } | |
1162 | ||
1163 | static int __tg3_writephy(struct tg3 *tp, unsigned int phy_addr, int reg, | |
1164 | u32 val) | |
1da177e4 LT |
1165 | { |
1166 | u32 frame_val; | |
1167 | unsigned int loops; | |
1168 | int ret; | |
1169 | ||
f07e9af3 | 1170 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && |
221c5637 | 1171 | (reg == MII_CTRL1000 || reg == MII_TG3_AUX_CTRL)) |
b5d3772c MC |
1172 | return 0; |
1173 | ||
1da177e4 LT |
1174 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
1175 | tw32_f(MAC_MI_MODE, | |
1176 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); | |
1177 | udelay(80); | |
1178 | } | |
1179 | ||
8151ad57 MC |
1180 | tg3_ape_lock(tp, tp->phy_ape_lock); |
1181 | ||
5c358045 | 1182 | frame_val = ((phy_addr << MI_COM_PHY_ADDR_SHIFT) & |
1da177e4 LT |
1183 | MI_COM_PHY_ADDR_MASK); |
1184 | frame_val |= ((reg << MI_COM_REG_ADDR_SHIFT) & | |
1185 | MI_COM_REG_ADDR_MASK); | |
1186 | frame_val |= (val & MI_COM_DATA_MASK); | |
1187 | frame_val |= (MI_COM_CMD_WRITE | MI_COM_START); | |
6aa20a22 | 1188 | |
1da177e4 LT |
1189 | tw32_f(MAC_MI_COM, frame_val); |
1190 | ||
1191 | loops = PHY_BUSY_LOOPS; | |
1192 | while (loops != 0) { | |
1193 | udelay(10); | |
1194 | frame_val = tr32(MAC_MI_COM); | |
1195 | if ((frame_val & MI_COM_BUSY) == 0) { | |
1196 | udelay(5); | |
1197 | frame_val = tr32(MAC_MI_COM); | |
1198 | break; | |
1199 | } | |
1200 | loops -= 1; | |
1201 | } | |
1202 | ||
1203 | ret = -EBUSY; | |
1204 | if (loops != 0) | |
1205 | ret = 0; | |
1206 | ||
1207 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { | |
1208 | tw32_f(MAC_MI_MODE, tp->mi_mode); | |
1209 | udelay(80); | |
1210 | } | |
1211 | ||
8151ad57 MC |
1212 | tg3_ape_unlock(tp, tp->phy_ape_lock); |
1213 | ||
1da177e4 LT |
1214 | return ret; |
1215 | } | |
1216 | ||
5c358045 HM |
1217 | static int tg3_writephy(struct tg3 *tp, int reg, u32 val) |
1218 | { | |
1219 | return __tg3_writephy(tp, tp->phy_addr, reg, val); | |
1220 | } | |
1221 | ||
b0988c15 MC |
1222 | static int tg3_phy_cl45_write(struct tg3 *tp, u32 devad, u32 addr, u32 val) |
1223 | { | |
1224 | int err; | |
1225 | ||
1226 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); | |
1227 | if (err) | |
1228 | goto done; | |
1229 | ||
1230 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); | |
1231 | if (err) | |
1232 | goto done; | |
1233 | ||
1234 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, | |
1235 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); | |
1236 | if (err) | |
1237 | goto done; | |
1238 | ||
1239 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, val); | |
1240 | ||
1241 | done: | |
1242 | return err; | |
1243 | } | |
1244 | ||
1245 | static int tg3_phy_cl45_read(struct tg3 *tp, u32 devad, u32 addr, u32 *val) | |
1246 | { | |
1247 | int err; | |
1248 | ||
1249 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, devad); | |
1250 | if (err) | |
1251 | goto done; | |
1252 | ||
1253 | err = tg3_writephy(tp, MII_TG3_MMD_ADDRESS, addr); | |
1254 | if (err) | |
1255 | goto done; | |
1256 | ||
1257 | err = tg3_writephy(tp, MII_TG3_MMD_CTRL, | |
1258 | MII_TG3_MMD_CTRL_DATA_NOINC | devad); | |
1259 | if (err) | |
1260 | goto done; | |
1261 | ||
1262 | err = tg3_readphy(tp, MII_TG3_MMD_ADDRESS, val); | |
1263 | ||
1264 | done: | |
1265 | return err; | |
1266 | } | |
1267 | ||
1268 | static int tg3_phydsp_read(struct tg3 *tp, u32 reg, u32 *val) | |
1269 | { | |
1270 | int err; | |
1271 | ||
1272 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); | |
1273 | if (!err) | |
1274 | err = tg3_readphy(tp, MII_TG3_DSP_RW_PORT, val); | |
1275 | ||
1276 | return err; | |
1277 | } | |
1278 | ||
1279 | static int tg3_phydsp_write(struct tg3 *tp, u32 reg, u32 val) | |
1280 | { | |
1281 | int err; | |
1282 | ||
1283 | err = tg3_writephy(tp, MII_TG3_DSP_ADDRESS, reg); | |
1284 | if (!err) | |
1285 | err = tg3_writephy(tp, MII_TG3_DSP_RW_PORT, val); | |
1286 | ||
1287 | return err; | |
1288 | } | |
1289 | ||
15ee95c3 MC |
1290 | static int tg3_phy_auxctl_read(struct tg3 *tp, int reg, u32 *val) |
1291 | { | |
1292 | int err; | |
1293 | ||
1294 | err = tg3_writephy(tp, MII_TG3_AUX_CTRL, | |
1295 | (reg << MII_TG3_AUXCTL_MISC_RDSEL_SHIFT) | | |
1296 | MII_TG3_AUXCTL_SHDWSEL_MISC); | |
1297 | if (!err) | |
1298 | err = tg3_readphy(tp, MII_TG3_AUX_CTRL, val); | |
1299 | ||
1300 | return err; | |
1301 | } | |
1302 | ||
b4bd2929 MC |
1303 | static int tg3_phy_auxctl_write(struct tg3 *tp, int reg, u32 set) |
1304 | { | |
1305 | if (reg == MII_TG3_AUXCTL_SHDWSEL_MISC) | |
1306 | set |= MII_TG3_AUXCTL_MISC_WREN; | |
1307 | ||
1308 | return tg3_writephy(tp, MII_TG3_AUX_CTRL, set | reg); | |
1309 | } | |
1310 | ||
daf3ec68 NNS |
1311 | static int tg3_phy_toggle_auxctl_smdsp(struct tg3 *tp, bool enable) |
1312 | { | |
1313 | u32 val; | |
1314 | int err; | |
1d36ba45 | 1315 | |
daf3ec68 | 1316 | err = tg3_phy_auxctl_read(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); |
1d36ba45 | 1317 | |
daf3ec68 NNS |
1318 | if (err) |
1319 | return err; | |
1320 | if (enable) | |
1321 | ||
1322 | val |= MII_TG3_AUXCTL_ACTL_SMDSP_ENA; | |
1323 | else | |
1324 | val &= ~MII_TG3_AUXCTL_ACTL_SMDSP_ENA; | |
1325 | ||
1326 | err = tg3_phy_auxctl_write((tp), MII_TG3_AUXCTL_SHDWSEL_AUXCTL, | |
1327 | val | MII_TG3_AUXCTL_ACTL_TX_6DB); | |
1328 | ||
1329 | return err; | |
1330 | } | |
1d36ba45 | 1331 | |
95e2869a MC |
1332 | static int tg3_bmcr_reset(struct tg3 *tp) |
1333 | { | |
1334 | u32 phy_control; | |
1335 | int limit, err; | |
1336 | ||
1337 | /* OK, reset it, and poll the BMCR_RESET bit until it | |
1338 | * clears or we time out. | |
1339 | */ | |
1340 | phy_control = BMCR_RESET; | |
1341 | err = tg3_writephy(tp, MII_BMCR, phy_control); | |
1342 | if (err != 0) | |
1343 | return -EBUSY; | |
1344 | ||
1345 | limit = 5000; | |
1346 | while (limit--) { | |
1347 | err = tg3_readphy(tp, MII_BMCR, &phy_control); | |
1348 | if (err != 0) | |
1349 | return -EBUSY; | |
1350 | ||
1351 | if ((phy_control & BMCR_RESET) == 0) { | |
1352 | udelay(40); | |
1353 | break; | |
1354 | } | |
1355 | udelay(10); | |
1356 | } | |
d4675b52 | 1357 | if (limit < 0) |
95e2869a MC |
1358 | return -EBUSY; |
1359 | ||
1360 | return 0; | |
1361 | } | |
1362 | ||
158d7abd MC |
1363 | static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg) |
1364 | { | |
3d16543d | 1365 | struct tg3 *tp = bp->priv; |
158d7abd MC |
1366 | u32 val; |
1367 | ||
24bb4fb6 | 1368 | spin_lock_bh(&tp->lock); |
158d7abd MC |
1369 | |
1370 | if (tg3_readphy(tp, reg, &val)) | |
24bb4fb6 MC |
1371 | val = -EIO; |
1372 | ||
1373 | spin_unlock_bh(&tp->lock); | |
158d7abd MC |
1374 | |
1375 | return val; | |
1376 | } | |
1377 | ||
1378 | static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val) | |
1379 | { | |
3d16543d | 1380 | struct tg3 *tp = bp->priv; |
24bb4fb6 | 1381 | u32 ret = 0; |
158d7abd | 1382 | |
24bb4fb6 | 1383 | spin_lock_bh(&tp->lock); |
158d7abd MC |
1384 | |
1385 | if (tg3_writephy(tp, reg, val)) | |
24bb4fb6 | 1386 | ret = -EIO; |
158d7abd | 1387 | |
24bb4fb6 MC |
1388 | spin_unlock_bh(&tp->lock); |
1389 | ||
1390 | return ret; | |
158d7abd MC |
1391 | } |
1392 | ||
1393 | static int tg3_mdio_reset(struct mii_bus *bp) | |
1394 | { | |
1395 | return 0; | |
1396 | } | |
1397 | ||
9c61d6bc | 1398 | static void tg3_mdio_config_5785(struct tg3 *tp) |
a9daf367 MC |
1399 | { |
1400 | u32 val; | |
fcb389df | 1401 | struct phy_device *phydev; |
a9daf367 | 1402 | |
3f0e3ad7 | 1403 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
fcb389df | 1404 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { |
6a443a0f MC |
1405 | case PHY_ID_BCM50610: |
1406 | case PHY_ID_BCM50610M: | |
fcb389df MC |
1407 | val = MAC_PHYCFG2_50610_LED_MODES; |
1408 | break; | |
6a443a0f | 1409 | case PHY_ID_BCMAC131: |
fcb389df MC |
1410 | val = MAC_PHYCFG2_AC131_LED_MODES; |
1411 | break; | |
6a443a0f | 1412 | case PHY_ID_RTL8211C: |
fcb389df MC |
1413 | val = MAC_PHYCFG2_RTL8211C_LED_MODES; |
1414 | break; | |
6a443a0f | 1415 | case PHY_ID_RTL8201E: |
fcb389df MC |
1416 | val = MAC_PHYCFG2_RTL8201E_LED_MODES; |
1417 | break; | |
1418 | default: | |
a9daf367 | 1419 | return; |
fcb389df MC |
1420 | } |
1421 | ||
1422 | if (phydev->interface != PHY_INTERFACE_MODE_RGMII) { | |
1423 | tw32(MAC_PHYCFG2, val); | |
1424 | ||
1425 | val = tr32(MAC_PHYCFG1); | |
bb85fbb6 MC |
1426 | val &= ~(MAC_PHYCFG1_RGMII_INT | |
1427 | MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK); | |
1428 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT; | |
fcb389df MC |
1429 | tw32(MAC_PHYCFG1, val); |
1430 | ||
1431 | return; | |
1432 | } | |
1433 | ||
63c3a66f | 1434 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) |
fcb389df MC |
1435 | val |= MAC_PHYCFG2_EMODE_MASK_MASK | |
1436 | MAC_PHYCFG2_FMODE_MASK_MASK | | |
1437 | MAC_PHYCFG2_GMODE_MASK_MASK | | |
1438 | MAC_PHYCFG2_ACT_MASK_MASK | | |
1439 | MAC_PHYCFG2_QUAL_MASK_MASK | | |
1440 | MAC_PHYCFG2_INBAND_ENABLE; | |
1441 | ||
1442 | tw32(MAC_PHYCFG2, val); | |
a9daf367 | 1443 | |
bb85fbb6 MC |
1444 | val = tr32(MAC_PHYCFG1); |
1445 | val &= ~(MAC_PHYCFG1_RXCLK_TO_MASK | MAC_PHYCFG1_TXCLK_TO_MASK | | |
1446 | MAC_PHYCFG1_RGMII_EXT_RX_DEC | MAC_PHYCFG1_RGMII_SND_STAT_EN); | |
63c3a66f JP |
1447 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
1448 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) | |
a9daf367 | 1449 | val |= MAC_PHYCFG1_RGMII_EXT_RX_DEC; |
63c3a66f | 1450 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
a9daf367 MC |
1451 | val |= MAC_PHYCFG1_RGMII_SND_STAT_EN; |
1452 | } | |
bb85fbb6 MC |
1453 | val |= MAC_PHYCFG1_RXCLK_TIMEOUT | MAC_PHYCFG1_TXCLK_TIMEOUT | |
1454 | MAC_PHYCFG1_RGMII_INT | MAC_PHYCFG1_TXC_DRV; | |
1455 | tw32(MAC_PHYCFG1, val); | |
a9daf367 | 1456 | |
a9daf367 MC |
1457 | val = tr32(MAC_EXT_RGMII_MODE); |
1458 | val &= ~(MAC_RGMII_MODE_RX_INT_B | | |
1459 | MAC_RGMII_MODE_RX_QUALITY | | |
1460 | MAC_RGMII_MODE_RX_ACTIVITY | | |
1461 | MAC_RGMII_MODE_RX_ENG_DET | | |
1462 | MAC_RGMII_MODE_TX_ENABLE | | |
1463 | MAC_RGMII_MODE_TX_LOWPWR | | |
1464 | MAC_RGMII_MODE_TX_RESET); | |
63c3a66f JP |
1465 | if (!tg3_flag(tp, RGMII_INBAND_DISABLE)) { |
1466 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) | |
a9daf367 MC |
1467 | val |= MAC_RGMII_MODE_RX_INT_B | |
1468 | MAC_RGMII_MODE_RX_QUALITY | | |
1469 | MAC_RGMII_MODE_RX_ACTIVITY | | |
1470 | MAC_RGMII_MODE_RX_ENG_DET; | |
63c3a66f | 1471 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
a9daf367 MC |
1472 | val |= MAC_RGMII_MODE_TX_ENABLE | |
1473 | MAC_RGMII_MODE_TX_LOWPWR | | |
1474 | MAC_RGMII_MODE_TX_RESET; | |
1475 | } | |
1476 | tw32(MAC_EXT_RGMII_MODE, val); | |
1477 | } | |
1478 | ||
158d7abd MC |
1479 | static void tg3_mdio_start(struct tg3 *tp) |
1480 | { | |
158d7abd MC |
1481 | tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL; |
1482 | tw32_f(MAC_MI_MODE, tp->mi_mode); | |
1483 | udelay(80); | |
a9daf367 | 1484 | |
63c3a66f | 1485 | if (tg3_flag(tp, MDIOBUS_INITED) && |
4153577a | 1486 | tg3_asic_rev(tp) == ASIC_REV_5785) |
9ea4818d MC |
1487 | tg3_mdio_config_5785(tp); |
1488 | } | |
1489 | ||
1490 | static int tg3_mdio_init(struct tg3 *tp) | |
1491 | { | |
1492 | int i; | |
1493 | u32 reg; | |
1494 | struct phy_device *phydev; | |
1495 | ||
63c3a66f | 1496 | if (tg3_flag(tp, 5717_PLUS)) { |
9c7df915 | 1497 | u32 is_serdes; |
882e9793 | 1498 | |
69f11c99 | 1499 | tp->phy_addr = tp->pci_fn + 1; |
882e9793 | 1500 | |
4153577a | 1501 | if (tg3_chip_rev_id(tp) != CHIPREV_ID_5717_A0) |
d1ec96af MC |
1502 | is_serdes = tr32(SG_DIG_STATUS) & SG_DIG_IS_SERDES; |
1503 | else | |
1504 | is_serdes = tr32(TG3_CPMU_PHY_STRAP) & | |
1505 | TG3_CPMU_PHY_STRAP_IS_SERDES; | |
882e9793 MC |
1506 | if (is_serdes) |
1507 | tp->phy_addr += 7; | |
1508 | } else | |
3f0e3ad7 | 1509 | tp->phy_addr = TG3_PHY_MII_ADDR; |
882e9793 | 1510 | |
158d7abd MC |
1511 | tg3_mdio_start(tp); |
1512 | ||
63c3a66f | 1513 | if (!tg3_flag(tp, USE_PHYLIB) || tg3_flag(tp, MDIOBUS_INITED)) |
158d7abd MC |
1514 | return 0; |
1515 | ||
298cf9be LB |
1516 | tp->mdio_bus = mdiobus_alloc(); |
1517 | if (tp->mdio_bus == NULL) | |
1518 | return -ENOMEM; | |
158d7abd | 1519 | |
298cf9be LB |
1520 | tp->mdio_bus->name = "tg3 mdio bus"; |
1521 | snprintf(tp->mdio_bus->id, MII_BUS_ID_SIZE, "%x", | |
158d7abd | 1522 | (tp->pdev->bus->number << 8) | tp->pdev->devfn); |
298cf9be LB |
1523 | tp->mdio_bus->priv = tp; |
1524 | tp->mdio_bus->parent = &tp->pdev->dev; | |
1525 | tp->mdio_bus->read = &tg3_mdio_read; | |
1526 | tp->mdio_bus->write = &tg3_mdio_write; | |
1527 | tp->mdio_bus->reset = &tg3_mdio_reset; | |
3f0e3ad7 | 1528 | tp->mdio_bus->phy_mask = ~(1 << TG3_PHY_MII_ADDR); |
298cf9be | 1529 | tp->mdio_bus->irq = &tp->mdio_irq[0]; |
158d7abd MC |
1530 | |
1531 | for (i = 0; i < PHY_MAX_ADDR; i++) | |
298cf9be | 1532 | tp->mdio_bus->irq[i] = PHY_POLL; |
158d7abd MC |
1533 | |
1534 | /* The bus registration will look for all the PHYs on the mdio bus. | |
1535 | * Unfortunately, it does not ensure the PHY is powered up before | |
1536 | * accessing the PHY ID registers. A chip reset is the | |
1537 | * quickest way to bring the device back to an operational state.. | |
1538 | */ | |
1539 | if (tg3_readphy(tp, MII_BMCR, ®) || (reg & BMCR_PDOWN)) | |
1540 | tg3_bmcr_reset(tp); | |
1541 | ||
298cf9be | 1542 | i = mdiobus_register(tp->mdio_bus); |
a9daf367 | 1543 | if (i) { |
ab96b241 | 1544 | dev_warn(&tp->pdev->dev, "mdiobus_reg failed (0x%x)\n", i); |
9c61d6bc | 1545 | mdiobus_free(tp->mdio_bus); |
a9daf367 MC |
1546 | return i; |
1547 | } | |
158d7abd | 1548 | |
3f0e3ad7 | 1549 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
a9daf367 | 1550 | |
9c61d6bc | 1551 | if (!phydev || !phydev->drv) { |
ab96b241 | 1552 | dev_warn(&tp->pdev->dev, "No PHY devices\n"); |
9c61d6bc MC |
1553 | mdiobus_unregister(tp->mdio_bus); |
1554 | mdiobus_free(tp->mdio_bus); | |
1555 | return -ENODEV; | |
1556 | } | |
1557 | ||
1558 | switch (phydev->drv->phy_id & phydev->drv->phy_id_mask) { | |
6a443a0f | 1559 | case PHY_ID_BCM57780: |
321d32a0 | 1560 | phydev->interface = PHY_INTERFACE_MODE_GMII; |
c704dc23 | 1561 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
321d32a0 | 1562 | break; |
6a443a0f MC |
1563 | case PHY_ID_BCM50610: |
1564 | case PHY_ID_BCM50610M: | |
32e5a8d6 | 1565 | phydev->dev_flags |= PHY_BRCM_CLEAR_RGMII_MODE | |
c704dc23 | 1566 | PHY_BRCM_RX_REFCLK_UNUSED | |
52fae083 | 1567 | PHY_BRCM_DIS_TXCRXC_NOENRGY | |
c704dc23 | 1568 | PHY_BRCM_AUTO_PWRDWN_ENABLE; |
63c3a66f | 1569 | if (tg3_flag(tp, RGMII_INBAND_DISABLE)) |
a9daf367 | 1570 | phydev->dev_flags |= PHY_BRCM_STD_IBND_DISABLE; |
63c3a66f | 1571 | if (tg3_flag(tp, RGMII_EXT_IBND_RX_EN)) |
a9daf367 | 1572 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_RX_ENABLE; |
63c3a66f | 1573 | if (tg3_flag(tp, RGMII_EXT_IBND_TX_EN)) |
a9daf367 | 1574 | phydev->dev_flags |= PHY_BRCM_EXT_IBND_TX_ENABLE; |
fcb389df | 1575 | /* fallthru */ |
6a443a0f | 1576 | case PHY_ID_RTL8211C: |
fcb389df | 1577 | phydev->interface = PHY_INTERFACE_MODE_RGMII; |
a9daf367 | 1578 | break; |
6a443a0f MC |
1579 | case PHY_ID_RTL8201E: |
1580 | case PHY_ID_BCMAC131: | |
a9daf367 | 1581 | phydev->interface = PHY_INTERFACE_MODE_MII; |
cdd4e09d | 1582 | phydev->dev_flags |= PHY_BRCM_AUTO_PWRDWN_ENABLE; |
f07e9af3 | 1583 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
a9daf367 MC |
1584 | break; |
1585 | } | |
1586 | ||
63c3a66f | 1587 | tg3_flag_set(tp, MDIOBUS_INITED); |
9c61d6bc | 1588 | |
4153577a | 1589 | if (tg3_asic_rev(tp) == ASIC_REV_5785) |
9c61d6bc | 1590 | tg3_mdio_config_5785(tp); |
a9daf367 MC |
1591 | |
1592 | return 0; | |
158d7abd MC |
1593 | } |
1594 | ||
1595 | static void tg3_mdio_fini(struct tg3 *tp) | |
1596 | { | |
63c3a66f JP |
1597 | if (tg3_flag(tp, MDIOBUS_INITED)) { |
1598 | tg3_flag_clear(tp, MDIOBUS_INITED); | |
298cf9be LB |
1599 | mdiobus_unregister(tp->mdio_bus); |
1600 | mdiobus_free(tp->mdio_bus); | |
158d7abd MC |
1601 | } |
1602 | } | |
1603 | ||
4ba526ce MC |
1604 | /* tp->lock is held. */ |
1605 | static inline void tg3_generate_fw_event(struct tg3 *tp) | |
1606 | { | |
1607 | u32 val; | |
1608 | ||
1609 | val = tr32(GRC_RX_CPU_EVENT); | |
1610 | val |= GRC_RX_CPU_DRIVER_EVENT; | |
1611 | tw32_f(GRC_RX_CPU_EVENT, val); | |
1612 | ||
1613 | tp->last_event_jiffies = jiffies; | |
1614 | } | |
1615 | ||
1616 | #define TG3_FW_EVENT_TIMEOUT_USEC 2500 | |
1617 | ||
95e2869a MC |
1618 | /* tp->lock is held. */ |
1619 | static void tg3_wait_for_event_ack(struct tg3 *tp) | |
1620 | { | |
1621 | int i; | |
4ba526ce MC |
1622 | unsigned int delay_cnt; |
1623 | long time_remain; | |
1624 | ||
1625 | /* If enough time has passed, no wait is necessary. */ | |
1626 | time_remain = (long)(tp->last_event_jiffies + 1 + | |
1627 | usecs_to_jiffies(TG3_FW_EVENT_TIMEOUT_USEC)) - | |
1628 | (long)jiffies; | |
1629 | if (time_remain < 0) | |
1630 | return; | |
1631 | ||
1632 | /* Check if we can shorten the wait time. */ | |
1633 | delay_cnt = jiffies_to_usecs(time_remain); | |
1634 | if (delay_cnt > TG3_FW_EVENT_TIMEOUT_USEC) | |
1635 | delay_cnt = TG3_FW_EVENT_TIMEOUT_USEC; | |
1636 | delay_cnt = (delay_cnt >> 3) + 1; | |
95e2869a | 1637 | |
4ba526ce | 1638 | for (i = 0; i < delay_cnt; i++) { |
95e2869a MC |
1639 | if (!(tr32(GRC_RX_CPU_EVENT) & GRC_RX_CPU_DRIVER_EVENT)) |
1640 | break; | |
6d446ec3 GS |
1641 | if (pci_channel_offline(tp->pdev)) |
1642 | break; | |
1643 | ||
4ba526ce | 1644 | udelay(8); |
95e2869a MC |
1645 | } |
1646 | } | |
1647 | ||
1648 | /* tp->lock is held. */ | |
b28f389d | 1649 | static void tg3_phy_gather_ump_data(struct tg3 *tp, u32 *data) |
95e2869a | 1650 | { |
b28f389d | 1651 | u32 reg, val; |
95e2869a MC |
1652 | |
1653 | val = 0; | |
1654 | if (!tg3_readphy(tp, MII_BMCR, ®)) | |
1655 | val = reg << 16; | |
1656 | if (!tg3_readphy(tp, MII_BMSR, ®)) | |
1657 | val |= (reg & 0xffff); | |
b28f389d | 1658 | *data++ = val; |
95e2869a MC |
1659 | |
1660 | val = 0; | |
1661 | if (!tg3_readphy(tp, MII_ADVERTISE, ®)) | |
1662 | val = reg << 16; | |
1663 | if (!tg3_readphy(tp, MII_LPA, ®)) | |
1664 | val |= (reg & 0xffff); | |
b28f389d | 1665 | *data++ = val; |
95e2869a MC |
1666 | |
1667 | val = 0; | |
f07e9af3 | 1668 | if (!(tp->phy_flags & TG3_PHYFLG_MII_SERDES)) { |
95e2869a MC |
1669 | if (!tg3_readphy(tp, MII_CTRL1000, ®)) |
1670 | val = reg << 16; | |
1671 | if (!tg3_readphy(tp, MII_STAT1000, ®)) | |
1672 | val |= (reg & 0xffff); | |
1673 | } | |
b28f389d | 1674 | *data++ = val; |
95e2869a MC |
1675 | |
1676 | if (!tg3_readphy(tp, MII_PHYADDR, ®)) | |
1677 | val = reg << 16; | |
1678 | else | |
1679 | val = 0; | |
b28f389d MC |
1680 | *data++ = val; |
1681 | } | |
1682 | ||
1683 | /* tp->lock is held. */ | |
1684 | static void tg3_ump_link_report(struct tg3 *tp) | |
1685 | { | |
1686 | u32 data[4]; | |
1687 | ||
1688 | if (!tg3_flag(tp, 5780_CLASS) || !tg3_flag(tp, ENABLE_ASF)) | |
1689 | return; | |
1690 | ||
1691 | tg3_phy_gather_ump_data(tp, data); | |
1692 | ||
1693 | tg3_wait_for_event_ack(tp); | |
1694 | ||
1695 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_LINK_UPDATE); | |
1696 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 14); | |
1697 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x0, data[0]); | |
1698 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x4, data[1]); | |
1699 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0x8, data[2]); | |
1700 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX + 0xc, data[3]); | |
95e2869a | 1701 | |
4ba526ce | 1702 | tg3_generate_fw_event(tp); |
95e2869a MC |
1703 | } |
1704 | ||
8d5a89b3 MC |
1705 | /* tp->lock is held. */ |
1706 | static void tg3_stop_fw(struct tg3 *tp) | |
1707 | { | |
1708 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { | |
1709 | /* Wait for RX cpu to ACK the previous event. */ | |
1710 | tg3_wait_for_event_ack(tp); | |
1711 | ||
1712 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, FWCMD_NICDRV_PAUSE_FW); | |
1713 | ||
1714 | tg3_generate_fw_event(tp); | |
1715 | ||
1716 | /* Wait for RX cpu to ACK this event. */ | |
1717 | tg3_wait_for_event_ack(tp); | |
1718 | } | |
1719 | } | |
1720 | ||
fd6d3f0e MC |
1721 | /* tp->lock is held. */ |
1722 | static void tg3_write_sig_pre_reset(struct tg3 *tp, int kind) | |
1723 | { | |
1724 | tg3_write_mem(tp, NIC_SRAM_FIRMWARE_MBOX, | |
1725 | NIC_SRAM_FIRMWARE_MBOX_MAGIC1); | |
1726 | ||
1727 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { | |
1728 | switch (kind) { | |
1729 | case RESET_KIND_INIT: | |
1730 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
1731 | DRV_STATE_START); | |
1732 | break; | |
1733 | ||
1734 | case RESET_KIND_SHUTDOWN: | |
1735 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
1736 | DRV_STATE_UNLOAD); | |
1737 | break; | |
1738 | ||
1739 | case RESET_KIND_SUSPEND: | |
1740 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
1741 | DRV_STATE_SUSPEND); | |
1742 | break; | |
1743 | ||
1744 | default: | |
1745 | break; | |
1746 | } | |
1747 | } | |
1748 | ||
1749 | if (kind == RESET_KIND_INIT || | |
1750 | kind == RESET_KIND_SUSPEND) | |
1751 | tg3_ape_driver_state_change(tp, kind); | |
1752 | } | |
1753 | ||
1754 | /* tp->lock is held. */ | |
1755 | static void tg3_write_sig_post_reset(struct tg3 *tp, int kind) | |
1756 | { | |
1757 | if (tg3_flag(tp, ASF_NEW_HANDSHAKE)) { | |
1758 | switch (kind) { | |
1759 | case RESET_KIND_INIT: | |
1760 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
1761 | DRV_STATE_START_DONE); | |
1762 | break; | |
1763 | ||
1764 | case RESET_KIND_SHUTDOWN: | |
1765 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
1766 | DRV_STATE_UNLOAD_DONE); | |
1767 | break; | |
1768 | ||
1769 | default: | |
1770 | break; | |
1771 | } | |
1772 | } | |
1773 | ||
1774 | if (kind == RESET_KIND_SHUTDOWN) | |
1775 | tg3_ape_driver_state_change(tp, kind); | |
1776 | } | |
1777 | ||
1778 | /* tp->lock is held. */ | |
1779 | static void tg3_write_sig_legacy(struct tg3 *tp, int kind) | |
1780 | { | |
1781 | if (tg3_flag(tp, ENABLE_ASF)) { | |
1782 | switch (kind) { | |
1783 | case RESET_KIND_INIT: | |
1784 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
1785 | DRV_STATE_START); | |
1786 | break; | |
1787 | ||
1788 | case RESET_KIND_SHUTDOWN: | |
1789 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
1790 | DRV_STATE_UNLOAD); | |
1791 | break; | |
1792 | ||
1793 | case RESET_KIND_SUSPEND: | |
1794 | tg3_write_mem(tp, NIC_SRAM_FW_DRV_STATE_MBOX, | |
1795 | DRV_STATE_SUSPEND); | |
1796 | break; | |
1797 | ||
1798 | default: | |
1799 | break; | |
1800 | } | |
1801 | } | |
1802 | } | |
1803 | ||
1804 | static int tg3_poll_fw(struct tg3 *tp) | |
1805 | { | |
1806 | int i; | |
1807 | u32 val; | |
1808 | ||
df465abf NS |
1809 | if (tg3_flag(tp, NO_FWARE_REPORTED)) |
1810 | return 0; | |
1811 | ||
7e6c63f0 HM |
1812 | if (tg3_flag(tp, IS_SSB_CORE)) { |
1813 | /* We don't use firmware. */ | |
1814 | return 0; | |
1815 | } | |
1816 | ||
4153577a | 1817 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
fd6d3f0e MC |
1818 | /* Wait up to 20ms for init done. */ |
1819 | for (i = 0; i < 200; i++) { | |
1820 | if (tr32(VCPU_STATUS) & VCPU_STATUS_INIT_DONE) | |
1821 | return 0; | |
6d446ec3 GS |
1822 | if (pci_channel_offline(tp->pdev)) |
1823 | return -ENODEV; | |
1824 | ||
fd6d3f0e MC |
1825 | udelay(100); |
1826 | } | |
1827 | return -ENODEV; | |
1828 | } | |
1829 | ||
1830 | /* Wait for firmware initialization to complete. */ | |
1831 | for (i = 0; i < 100000; i++) { | |
1832 | tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val); | |
1833 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) | |
1834 | break; | |
6d446ec3 GS |
1835 | if (pci_channel_offline(tp->pdev)) { |
1836 | if (!tg3_flag(tp, NO_FWARE_REPORTED)) { | |
1837 | tg3_flag_set(tp, NO_FWARE_REPORTED); | |
1838 | netdev_info(tp->dev, "No firmware running\n"); | |
1839 | } | |
1840 | ||
1841 | break; | |
1842 | } | |
1843 | ||
fd6d3f0e MC |
1844 | udelay(10); |
1845 | } | |
1846 | ||
1847 | /* Chip might not be fitted with firmware. Some Sun onboard | |
1848 | * parts are configured like that. So don't signal the timeout | |
1849 | * of the above loop as an error, but do report the lack of | |
1850 | * running firmware once. | |
1851 | */ | |
1852 | if (i >= 100000 && !tg3_flag(tp, NO_FWARE_REPORTED)) { | |
1853 | tg3_flag_set(tp, NO_FWARE_REPORTED); | |
1854 | ||
1855 | netdev_info(tp->dev, "No firmware running\n"); | |
1856 | } | |
1857 | ||
4153577a | 1858 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_57765_A0) { |
fd6d3f0e MC |
1859 | /* The 57765 A0 needs a little more |
1860 | * time to do some important work. | |
1861 | */ | |
1862 | mdelay(10); | |
1863 | } | |
1864 | ||
1865 | return 0; | |
1866 | } | |
1867 | ||
95e2869a MC |
1868 | static void tg3_link_report(struct tg3 *tp) |
1869 | { | |
1870 | if (!netif_carrier_ok(tp->dev)) { | |
05dbe005 | 1871 | netif_info(tp, link, tp->dev, "Link is down\n"); |
95e2869a MC |
1872 | tg3_ump_link_report(tp); |
1873 | } else if (netif_msg_link(tp)) { | |
05dbe005 JP |
1874 | netdev_info(tp->dev, "Link is up at %d Mbps, %s duplex\n", |
1875 | (tp->link_config.active_speed == SPEED_1000 ? | |
1876 | 1000 : | |
1877 | (tp->link_config.active_speed == SPEED_100 ? | |
1878 | 100 : 10)), | |
1879 | (tp->link_config.active_duplex == DUPLEX_FULL ? | |
1880 | "full" : "half")); | |
1881 | ||
1882 | netdev_info(tp->dev, "Flow control is %s for TX and %s for RX\n", | |
1883 | (tp->link_config.active_flowctrl & FLOW_CTRL_TX) ? | |
1884 | "on" : "off", | |
1885 | (tp->link_config.active_flowctrl & FLOW_CTRL_RX) ? | |
1886 | "on" : "off"); | |
47007831 MC |
1887 | |
1888 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) | |
1889 | netdev_info(tp->dev, "EEE is %s\n", | |
1890 | tp->setlpicnt ? "enabled" : "disabled"); | |
1891 | ||
95e2869a MC |
1892 | tg3_ump_link_report(tp); |
1893 | } | |
84421b99 NS |
1894 | |
1895 | tp->link_up = netif_carrier_ok(tp->dev); | |
95e2869a MC |
1896 | } |
1897 | ||
fdad8de4 NS |
1898 | static u32 tg3_decode_flowctrl_1000T(u32 adv) |
1899 | { | |
1900 | u32 flowctrl = 0; | |
1901 | ||
1902 | if (adv & ADVERTISE_PAUSE_CAP) { | |
1903 | flowctrl |= FLOW_CTRL_RX; | |
1904 | if (!(adv & ADVERTISE_PAUSE_ASYM)) | |
1905 | flowctrl |= FLOW_CTRL_TX; | |
1906 | } else if (adv & ADVERTISE_PAUSE_ASYM) | |
1907 | flowctrl |= FLOW_CTRL_TX; | |
1908 | ||
1909 | return flowctrl; | |
1910 | } | |
1911 | ||
95e2869a MC |
1912 | static u16 tg3_advert_flowctrl_1000X(u8 flow_ctrl) |
1913 | { | |
1914 | u16 miireg; | |
1915 | ||
e18ce346 | 1916 | if ((flow_ctrl & FLOW_CTRL_TX) && (flow_ctrl & FLOW_CTRL_RX)) |
95e2869a | 1917 | miireg = ADVERTISE_1000XPAUSE; |
e18ce346 | 1918 | else if (flow_ctrl & FLOW_CTRL_TX) |
95e2869a | 1919 | miireg = ADVERTISE_1000XPSE_ASYM; |
e18ce346 | 1920 | else if (flow_ctrl & FLOW_CTRL_RX) |
95e2869a MC |
1921 | miireg = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM; |
1922 | else | |
1923 | miireg = 0; | |
1924 | ||
1925 | return miireg; | |
1926 | } | |
1927 | ||
fdad8de4 NS |
1928 | static u32 tg3_decode_flowctrl_1000X(u32 adv) |
1929 | { | |
1930 | u32 flowctrl = 0; | |
1931 | ||
1932 | if (adv & ADVERTISE_1000XPAUSE) { | |
1933 | flowctrl |= FLOW_CTRL_RX; | |
1934 | if (!(adv & ADVERTISE_1000XPSE_ASYM)) | |
1935 | flowctrl |= FLOW_CTRL_TX; | |
1936 | } else if (adv & ADVERTISE_1000XPSE_ASYM) | |
1937 | flowctrl |= FLOW_CTRL_TX; | |
1938 | ||
1939 | return flowctrl; | |
1940 | } | |
1941 | ||
95e2869a MC |
1942 | static u8 tg3_resolve_flowctrl_1000X(u16 lcladv, u16 rmtadv) |
1943 | { | |
1944 | u8 cap = 0; | |
1945 | ||
f3791cdf MC |
1946 | if (lcladv & rmtadv & ADVERTISE_1000XPAUSE) { |
1947 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; | |
1948 | } else if (lcladv & rmtadv & ADVERTISE_1000XPSE_ASYM) { | |
1949 | if (lcladv & ADVERTISE_1000XPAUSE) | |
1950 | cap = FLOW_CTRL_RX; | |
1951 | if (rmtadv & ADVERTISE_1000XPAUSE) | |
e18ce346 | 1952 | cap = FLOW_CTRL_TX; |
95e2869a MC |
1953 | } |
1954 | ||
1955 | return cap; | |
1956 | } | |
1957 | ||
f51f3562 | 1958 | static void tg3_setup_flow_control(struct tg3 *tp, u32 lcladv, u32 rmtadv) |
95e2869a | 1959 | { |
b02fd9e3 | 1960 | u8 autoneg; |
f51f3562 | 1961 | u8 flowctrl = 0; |
95e2869a MC |
1962 | u32 old_rx_mode = tp->rx_mode; |
1963 | u32 old_tx_mode = tp->tx_mode; | |
1964 | ||
63c3a66f | 1965 | if (tg3_flag(tp, USE_PHYLIB)) |
3f0e3ad7 | 1966 | autoneg = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]->autoneg; |
b02fd9e3 MC |
1967 | else |
1968 | autoneg = tp->link_config.autoneg; | |
1969 | ||
63c3a66f | 1970 | if (autoneg == AUTONEG_ENABLE && tg3_flag(tp, PAUSE_AUTONEG)) { |
f07e9af3 | 1971 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
f51f3562 | 1972 | flowctrl = tg3_resolve_flowctrl_1000X(lcladv, rmtadv); |
95e2869a | 1973 | else |
bc02ff95 | 1974 | flowctrl = mii_resolve_flowctrl_fdx(lcladv, rmtadv); |
f51f3562 MC |
1975 | } else |
1976 | flowctrl = tp->link_config.flowctrl; | |
95e2869a | 1977 | |
f51f3562 | 1978 | tp->link_config.active_flowctrl = flowctrl; |
95e2869a | 1979 | |
e18ce346 | 1980 | if (flowctrl & FLOW_CTRL_RX) |
95e2869a MC |
1981 | tp->rx_mode |= RX_MODE_FLOW_CTRL_ENABLE; |
1982 | else | |
1983 | tp->rx_mode &= ~RX_MODE_FLOW_CTRL_ENABLE; | |
1984 | ||
f51f3562 | 1985 | if (old_rx_mode != tp->rx_mode) |
95e2869a | 1986 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
95e2869a | 1987 | |
e18ce346 | 1988 | if (flowctrl & FLOW_CTRL_TX) |
95e2869a MC |
1989 | tp->tx_mode |= TX_MODE_FLOW_CTRL_ENABLE; |
1990 | else | |
1991 | tp->tx_mode &= ~TX_MODE_FLOW_CTRL_ENABLE; | |
1992 | ||
f51f3562 | 1993 | if (old_tx_mode != tp->tx_mode) |
95e2869a | 1994 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
95e2869a MC |
1995 | } |
1996 | ||
b02fd9e3 MC |
1997 | static void tg3_adjust_link(struct net_device *dev) |
1998 | { | |
1999 | u8 oldflowctrl, linkmesg = 0; | |
2000 | u32 mac_mode, lcl_adv, rmt_adv; | |
2001 | struct tg3 *tp = netdev_priv(dev); | |
3f0e3ad7 | 2002 | struct phy_device *phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
b02fd9e3 | 2003 | |
24bb4fb6 | 2004 | spin_lock_bh(&tp->lock); |
b02fd9e3 MC |
2005 | |
2006 | mac_mode = tp->mac_mode & ~(MAC_MODE_PORT_MODE_MASK | | |
2007 | MAC_MODE_HALF_DUPLEX); | |
2008 | ||
2009 | oldflowctrl = tp->link_config.active_flowctrl; | |
2010 | ||
2011 | if (phydev->link) { | |
2012 | lcl_adv = 0; | |
2013 | rmt_adv = 0; | |
2014 | ||
2015 | if (phydev->speed == SPEED_100 || phydev->speed == SPEED_10) | |
2016 | mac_mode |= MAC_MODE_PORT_MODE_MII; | |
c3df0748 | 2017 | else if (phydev->speed == SPEED_1000 || |
4153577a | 2018 | tg3_asic_rev(tp) != ASIC_REV_5785) |
b02fd9e3 | 2019 | mac_mode |= MAC_MODE_PORT_MODE_GMII; |
c3df0748 MC |
2020 | else |
2021 | mac_mode |= MAC_MODE_PORT_MODE_MII; | |
b02fd9e3 MC |
2022 | |
2023 | if (phydev->duplex == DUPLEX_HALF) | |
2024 | mac_mode |= MAC_MODE_HALF_DUPLEX; | |
2025 | else { | |
f88788f0 | 2026 | lcl_adv = mii_advertise_flowctrl( |
b02fd9e3 MC |
2027 | tp->link_config.flowctrl); |
2028 | ||
2029 | if (phydev->pause) | |
2030 | rmt_adv = LPA_PAUSE_CAP; | |
2031 | if (phydev->asym_pause) | |
2032 | rmt_adv |= LPA_PAUSE_ASYM; | |
2033 | } | |
2034 | ||
2035 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); | |
2036 | } else | |
2037 | mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
2038 | ||
2039 | if (mac_mode != tp->mac_mode) { | |
2040 | tp->mac_mode = mac_mode; | |
2041 | tw32_f(MAC_MODE, tp->mac_mode); | |
2042 | udelay(40); | |
2043 | } | |
2044 | ||
4153577a | 2045 | if (tg3_asic_rev(tp) == ASIC_REV_5785) { |
fcb389df MC |
2046 | if (phydev->speed == SPEED_10) |
2047 | tw32(MAC_MI_STAT, | |
2048 | MAC_MI_STAT_10MBPS_MODE | | |
2049 | MAC_MI_STAT_LNKSTAT_ATTN_ENAB); | |
2050 | else | |
2051 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); | |
2052 | } | |
2053 | ||
b02fd9e3 MC |
2054 | if (phydev->speed == SPEED_1000 && phydev->duplex == DUPLEX_HALF) |
2055 | tw32(MAC_TX_LENGTHS, | |
2056 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | | |
2057 | (6 << TX_LENGTHS_IPG_SHIFT) | | |
2058 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT))); | |
2059 | else | |
2060 | tw32(MAC_TX_LENGTHS, | |
2061 | ((2 << TX_LENGTHS_IPG_CRS_SHIFT) | | |
2062 | (6 << TX_LENGTHS_IPG_SHIFT) | | |
2063 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT))); | |
2064 | ||
34655ad6 | 2065 | if (phydev->link != tp->old_link || |
b02fd9e3 MC |
2066 | phydev->speed != tp->link_config.active_speed || |
2067 | phydev->duplex != tp->link_config.active_duplex || | |
2068 | oldflowctrl != tp->link_config.active_flowctrl) | |
c6cdf436 | 2069 | linkmesg = 1; |
b02fd9e3 | 2070 | |
34655ad6 | 2071 | tp->old_link = phydev->link; |
b02fd9e3 MC |
2072 | tp->link_config.active_speed = phydev->speed; |
2073 | tp->link_config.active_duplex = phydev->duplex; | |
2074 | ||
24bb4fb6 | 2075 | spin_unlock_bh(&tp->lock); |
b02fd9e3 MC |
2076 | |
2077 | if (linkmesg) | |
2078 | tg3_link_report(tp); | |
2079 | } | |
2080 | ||
2081 | static int tg3_phy_init(struct tg3 *tp) | |
2082 | { | |
2083 | struct phy_device *phydev; | |
2084 | ||
f07e9af3 | 2085 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) |
b02fd9e3 MC |
2086 | return 0; |
2087 | ||
2088 | /* Bring the PHY back to a known state. */ | |
2089 | tg3_bmcr_reset(tp); | |
2090 | ||
3f0e3ad7 | 2091 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
b02fd9e3 MC |
2092 | |
2093 | /* Attach the MAC to the PHY. */ | |
f9a8f83b FF |
2094 | phydev = phy_connect(tp->dev, dev_name(&phydev->dev), |
2095 | tg3_adjust_link, phydev->interface); | |
b02fd9e3 | 2096 | if (IS_ERR(phydev)) { |
ab96b241 | 2097 | dev_err(&tp->pdev->dev, "Could not attach to PHY\n"); |
b02fd9e3 MC |
2098 | return PTR_ERR(phydev); |
2099 | } | |
2100 | ||
b02fd9e3 | 2101 | /* Mask with MAC supported features. */ |
9c61d6bc MC |
2102 | switch (phydev->interface) { |
2103 | case PHY_INTERFACE_MODE_GMII: | |
2104 | case PHY_INTERFACE_MODE_RGMII: | |
f07e9af3 | 2105 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
321d32a0 MC |
2106 | phydev->supported &= (PHY_GBIT_FEATURES | |
2107 | SUPPORTED_Pause | | |
2108 | SUPPORTED_Asym_Pause); | |
2109 | break; | |
2110 | } | |
2111 | /* fallthru */ | |
9c61d6bc MC |
2112 | case PHY_INTERFACE_MODE_MII: |
2113 | phydev->supported &= (PHY_BASIC_FEATURES | | |
2114 | SUPPORTED_Pause | | |
2115 | SUPPORTED_Asym_Pause); | |
2116 | break; | |
2117 | default: | |
3f0e3ad7 | 2118 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
9c61d6bc MC |
2119 | return -EINVAL; |
2120 | } | |
2121 | ||
f07e9af3 | 2122 | tp->phy_flags |= TG3_PHYFLG_IS_CONNECTED; |
b02fd9e3 MC |
2123 | |
2124 | phydev->advertising = phydev->supported; | |
2125 | ||
b02fd9e3 MC |
2126 | return 0; |
2127 | } | |
2128 | ||
2129 | static void tg3_phy_start(struct tg3 *tp) | |
2130 | { | |
2131 | struct phy_device *phydev; | |
2132 | ||
f07e9af3 | 2133 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 MC |
2134 | return; |
2135 | ||
3f0e3ad7 | 2136 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
b02fd9e3 | 2137 | |
80096068 MC |
2138 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) { |
2139 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; | |
c6700ce2 MC |
2140 | phydev->speed = tp->link_config.speed; |
2141 | phydev->duplex = tp->link_config.duplex; | |
2142 | phydev->autoneg = tp->link_config.autoneg; | |
2143 | phydev->advertising = tp->link_config.advertising; | |
b02fd9e3 MC |
2144 | } |
2145 | ||
2146 | phy_start(phydev); | |
2147 | ||
2148 | phy_start_aneg(phydev); | |
2149 | } | |
2150 | ||
2151 | static void tg3_phy_stop(struct tg3 *tp) | |
2152 | { | |
f07e9af3 | 2153 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 MC |
2154 | return; |
2155 | ||
3f0e3ad7 | 2156 | phy_stop(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
b02fd9e3 MC |
2157 | } |
2158 | ||
2159 | static void tg3_phy_fini(struct tg3 *tp) | |
2160 | { | |
f07e9af3 | 2161 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
3f0e3ad7 | 2162 | phy_disconnect(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
f07e9af3 | 2163 | tp->phy_flags &= ~TG3_PHYFLG_IS_CONNECTED; |
b02fd9e3 MC |
2164 | } |
2165 | } | |
2166 | ||
941ec90f MC |
2167 | static int tg3_phy_set_extloopbk(struct tg3 *tp) |
2168 | { | |
2169 | int err; | |
2170 | u32 val; | |
2171 | ||
2172 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) | |
2173 | return 0; | |
2174 | ||
2175 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { | |
2176 | /* Cannot do read-modify-write on 5401 */ | |
2177 | err = tg3_phy_auxctl_write(tp, | |
2178 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, | |
2179 | MII_TG3_AUXCTL_ACTL_EXTLOOPBK | | |
2180 | 0x4c20); | |
2181 | goto done; | |
2182 | } | |
2183 | ||
2184 | err = tg3_phy_auxctl_read(tp, | |
2185 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); | |
2186 | if (err) | |
2187 | return err; | |
2188 | ||
2189 | val |= MII_TG3_AUXCTL_ACTL_EXTLOOPBK; | |
2190 | err = tg3_phy_auxctl_write(tp, | |
2191 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, val); | |
2192 | ||
2193 | done: | |
2194 | return err; | |
2195 | } | |
2196 | ||
7f97a4bd MC |
2197 | static void tg3_phy_fet_toggle_apd(struct tg3 *tp, bool enable) |
2198 | { | |
2199 | u32 phytest; | |
2200 | ||
2201 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { | |
2202 | u32 phy; | |
2203 | ||
2204 | tg3_writephy(tp, MII_TG3_FET_TEST, | |
2205 | phytest | MII_TG3_FET_SHADOW_EN); | |
2206 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXSTAT2, &phy)) { | |
2207 | if (enable) | |
2208 | phy |= MII_TG3_FET_SHDW_AUXSTAT2_APD; | |
2209 | else | |
2210 | phy &= ~MII_TG3_FET_SHDW_AUXSTAT2_APD; | |
2211 | tg3_writephy(tp, MII_TG3_FET_SHDW_AUXSTAT2, phy); | |
2212 | } | |
2213 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); | |
2214 | } | |
2215 | } | |
2216 | ||
6833c043 MC |
2217 | static void tg3_phy_toggle_apd(struct tg3 *tp, bool enable) |
2218 | { | |
2219 | u32 reg; | |
2220 | ||
63c3a66f JP |
2221 | if (!tg3_flag(tp, 5705_PLUS) || |
2222 | (tg3_flag(tp, 5717_PLUS) && | |
f07e9af3 | 2223 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES))) |
6833c043 MC |
2224 | return; |
2225 | ||
f07e9af3 | 2226 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
7f97a4bd MC |
2227 | tg3_phy_fet_toggle_apd(tp, enable); |
2228 | return; | |
2229 | } | |
2230 | ||
6833c043 MC |
2231 | reg = MII_TG3_MISC_SHDW_WREN | |
2232 | MII_TG3_MISC_SHDW_SCR5_SEL | | |
2233 | MII_TG3_MISC_SHDW_SCR5_LPED | | |
2234 | MII_TG3_MISC_SHDW_SCR5_DLPTLM | | |
2235 | MII_TG3_MISC_SHDW_SCR5_SDTL | | |
2236 | MII_TG3_MISC_SHDW_SCR5_C125OE; | |
4153577a | 2237 | if (tg3_asic_rev(tp) != ASIC_REV_5784 || !enable) |
6833c043 MC |
2238 | reg |= MII_TG3_MISC_SHDW_SCR5_DLLAPD; |
2239 | ||
2240 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); | |
2241 | ||
2242 | ||
2243 | reg = MII_TG3_MISC_SHDW_WREN | | |
2244 | MII_TG3_MISC_SHDW_APD_SEL | | |
2245 | MII_TG3_MISC_SHDW_APD_WKTM_84MS; | |
2246 | if (enable) | |
2247 | reg |= MII_TG3_MISC_SHDW_APD_ENABLE; | |
2248 | ||
2249 | tg3_writephy(tp, MII_TG3_MISC_SHDW, reg); | |
2250 | } | |
2251 | ||
953c96e0 | 2252 | static void tg3_phy_toggle_automdix(struct tg3 *tp, bool enable) |
9ef8ca99 MC |
2253 | { |
2254 | u32 phy; | |
2255 | ||
63c3a66f | 2256 | if (!tg3_flag(tp, 5705_PLUS) || |
f07e9af3 | 2257 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
9ef8ca99 MC |
2258 | return; |
2259 | ||
f07e9af3 | 2260 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
9ef8ca99 MC |
2261 | u32 ephy; |
2262 | ||
535ef6e1 MC |
2263 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &ephy)) { |
2264 | u32 reg = MII_TG3_FET_SHDW_MISCCTRL; | |
2265 | ||
2266 | tg3_writephy(tp, MII_TG3_FET_TEST, | |
2267 | ephy | MII_TG3_FET_SHADOW_EN); | |
2268 | if (!tg3_readphy(tp, reg, &phy)) { | |
9ef8ca99 | 2269 | if (enable) |
535ef6e1 | 2270 | phy |= MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
9ef8ca99 | 2271 | else |
535ef6e1 MC |
2272 | phy &= ~MII_TG3_FET_SHDW_MISCCTRL_MDIX; |
2273 | tg3_writephy(tp, reg, phy); | |
9ef8ca99 | 2274 | } |
535ef6e1 | 2275 | tg3_writephy(tp, MII_TG3_FET_TEST, ephy); |
9ef8ca99 MC |
2276 | } |
2277 | } else { | |
15ee95c3 MC |
2278 | int ret; |
2279 | ||
2280 | ret = tg3_phy_auxctl_read(tp, | |
2281 | MII_TG3_AUXCTL_SHDWSEL_MISC, &phy); | |
2282 | if (!ret) { | |
9ef8ca99 MC |
2283 | if (enable) |
2284 | phy |= MII_TG3_AUXCTL_MISC_FORCE_AMDIX; | |
2285 | else | |
2286 | phy &= ~MII_TG3_AUXCTL_MISC_FORCE_AMDIX; | |
b4bd2929 MC |
2287 | tg3_phy_auxctl_write(tp, |
2288 | MII_TG3_AUXCTL_SHDWSEL_MISC, phy); | |
9ef8ca99 MC |
2289 | } |
2290 | } | |
2291 | } | |
2292 | ||
1da177e4 LT |
2293 | static void tg3_phy_set_wirespeed(struct tg3 *tp) |
2294 | { | |
15ee95c3 | 2295 | int ret; |
1da177e4 LT |
2296 | u32 val; |
2297 | ||
f07e9af3 | 2298 | if (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) |
1da177e4 LT |
2299 | return; |
2300 | ||
15ee95c3 MC |
2301 | ret = tg3_phy_auxctl_read(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, &val); |
2302 | if (!ret) | |
b4bd2929 MC |
2303 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_MISC, |
2304 | val | MII_TG3_AUXCTL_MISC_WIRESPD_EN); | |
1da177e4 LT |
2305 | } |
2306 | ||
b2a5c19c MC |
2307 | static void tg3_phy_apply_otp(struct tg3 *tp) |
2308 | { | |
2309 | u32 otp, phy; | |
2310 | ||
2311 | if (!tp->phy_otp) | |
2312 | return; | |
2313 | ||
2314 | otp = tp->phy_otp; | |
2315 | ||
daf3ec68 | 2316 | if (tg3_phy_toggle_auxctl_smdsp(tp, true)) |
1d36ba45 | 2317 | return; |
b2a5c19c MC |
2318 | |
2319 | phy = ((otp & TG3_OTP_AGCTGT_MASK) >> TG3_OTP_AGCTGT_SHIFT); | |
2320 | phy |= MII_TG3_DSP_TAP1_AGCTGT_DFLT; | |
2321 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP1, phy); | |
2322 | ||
2323 | phy = ((otp & TG3_OTP_HPFFLTR_MASK) >> TG3_OTP_HPFFLTR_SHIFT) | | |
2324 | ((otp & TG3_OTP_HPFOVER_MASK) >> TG3_OTP_HPFOVER_SHIFT); | |
2325 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH0, phy); | |
2326 | ||
2327 | phy = ((otp & TG3_OTP_LPFDIS_MASK) >> TG3_OTP_LPFDIS_SHIFT); | |
2328 | phy |= MII_TG3_DSP_AADJ1CH3_ADCCKADJ; | |
2329 | tg3_phydsp_write(tp, MII_TG3_DSP_AADJ1CH3, phy); | |
2330 | ||
2331 | phy = ((otp & TG3_OTP_VDAC_MASK) >> TG3_OTP_VDAC_SHIFT); | |
2332 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP75, phy); | |
2333 | ||
2334 | phy = ((otp & TG3_OTP_10BTAMP_MASK) >> TG3_OTP_10BTAMP_SHIFT); | |
2335 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP96, phy); | |
2336 | ||
2337 | phy = ((otp & TG3_OTP_ROFF_MASK) >> TG3_OTP_ROFF_SHIFT) | | |
2338 | ((otp & TG3_OTP_RCOFF_MASK) >> TG3_OTP_RCOFF_SHIFT); | |
2339 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP97, phy); | |
2340 | ||
daf3ec68 | 2341 | tg3_phy_toggle_auxctl_smdsp(tp, false); |
b2a5c19c MC |
2342 | } |
2343 | ||
953c96e0 | 2344 | static void tg3_phy_eee_adjust(struct tg3 *tp, bool current_link_up) |
52b02d04 MC |
2345 | { |
2346 | u32 val; | |
2347 | ||
2348 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) | |
2349 | return; | |
2350 | ||
2351 | tp->setlpicnt = 0; | |
2352 | ||
2353 | if (tp->link_config.autoneg == AUTONEG_ENABLE && | |
953c96e0 | 2354 | current_link_up && |
a6b68dab MC |
2355 | tp->link_config.active_duplex == DUPLEX_FULL && |
2356 | (tp->link_config.active_speed == SPEED_100 || | |
2357 | tp->link_config.active_speed == SPEED_1000)) { | |
52b02d04 MC |
2358 | u32 eeectl; |
2359 | ||
2360 | if (tp->link_config.active_speed == SPEED_1000) | |
2361 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_16_5_US; | |
2362 | else | |
2363 | eeectl = TG3_CPMU_EEE_CTRL_EXIT_36_US; | |
2364 | ||
2365 | tw32(TG3_CPMU_EEE_CTRL, eeectl); | |
2366 | ||
3110f5f5 MC |
2367 | tg3_phy_cl45_read(tp, MDIO_MMD_AN, |
2368 | TG3_CL45_D7_EEERES_STAT, &val); | |
52b02d04 | 2369 | |
b0c5943f MC |
2370 | if (val == TG3_CL45_D7_EEERES_STAT_LP_1000T || |
2371 | val == TG3_CL45_D7_EEERES_STAT_LP_100TX) | |
52b02d04 MC |
2372 | tp->setlpicnt = 2; |
2373 | } | |
2374 | ||
2375 | if (!tp->setlpicnt) { | |
953c96e0 | 2376 | if (current_link_up && |
daf3ec68 | 2377 | !tg3_phy_toggle_auxctl_smdsp(tp, true)) { |
b715ce94 | 2378 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, 0x0000); |
daf3ec68 | 2379 | tg3_phy_toggle_auxctl_smdsp(tp, false); |
b715ce94 MC |
2380 | } |
2381 | ||
52b02d04 MC |
2382 | val = tr32(TG3_CPMU_EEE_MODE); |
2383 | tw32(TG3_CPMU_EEE_MODE, val & ~TG3_CPMU_EEEMD_LPI_ENABLE); | |
2384 | } | |
2385 | } | |
2386 | ||
b0c5943f MC |
2387 | static void tg3_phy_eee_enable(struct tg3 *tp) |
2388 | { | |
2389 | u32 val; | |
2390 | ||
2391 | if (tp->link_config.active_speed == SPEED_1000 && | |
4153577a JP |
2392 | (tg3_asic_rev(tp) == ASIC_REV_5717 || |
2393 | tg3_asic_rev(tp) == ASIC_REV_5719 || | |
55086ad9 | 2394 | tg3_flag(tp, 57765_CLASS)) && |
daf3ec68 | 2395 | !tg3_phy_toggle_auxctl_smdsp(tp, true)) { |
b715ce94 MC |
2396 | val = MII_TG3_DSP_TAP26_ALNOKO | |
2397 | MII_TG3_DSP_TAP26_RMRXSTO; | |
2398 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); | |
daf3ec68 | 2399 | tg3_phy_toggle_auxctl_smdsp(tp, false); |
b0c5943f MC |
2400 | } |
2401 | ||
2402 | val = tr32(TG3_CPMU_EEE_MODE); | |
2403 | tw32(TG3_CPMU_EEE_MODE, val | TG3_CPMU_EEEMD_LPI_ENABLE); | |
2404 | } | |
2405 | ||
1da177e4 LT |
2406 | static int tg3_wait_macro_done(struct tg3 *tp) |
2407 | { | |
2408 | int limit = 100; | |
2409 | ||
2410 | while (limit--) { | |
2411 | u32 tmp32; | |
2412 | ||
f08aa1a8 | 2413 | if (!tg3_readphy(tp, MII_TG3_DSP_CONTROL, &tmp32)) { |
1da177e4 LT |
2414 | if ((tmp32 & 0x1000) == 0) |
2415 | break; | |
2416 | } | |
2417 | } | |
d4675b52 | 2418 | if (limit < 0) |
1da177e4 LT |
2419 | return -EBUSY; |
2420 | ||
2421 | return 0; | |
2422 | } | |
2423 | ||
2424 | static int tg3_phy_write_and_check_testpat(struct tg3 *tp, int *resetp) | |
2425 | { | |
2426 | static const u32 test_pat[4][6] = { | |
2427 | { 0x00005555, 0x00000005, 0x00002aaa, 0x0000000a, 0x00003456, 0x00000003 }, | |
2428 | { 0x00002aaa, 0x0000000a, 0x00003333, 0x00000003, 0x0000789a, 0x00000005 }, | |
2429 | { 0x00005a5a, 0x00000005, 0x00002a6a, 0x0000000a, 0x00001bcd, 0x00000003 }, | |
2430 | { 0x00002a5a, 0x0000000a, 0x000033c3, 0x00000003, 0x00002ef1, 0x00000005 } | |
2431 | }; | |
2432 | int chan; | |
2433 | ||
2434 | for (chan = 0; chan < 4; chan++) { | |
2435 | int i; | |
2436 | ||
2437 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, | |
2438 | (chan * 0x2000) | 0x0200); | |
f08aa1a8 | 2439 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
1da177e4 LT |
2440 | |
2441 | for (i = 0; i < 6; i++) | |
2442 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, | |
2443 | test_pat[chan][i]); | |
2444 | ||
f08aa1a8 | 2445 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
1da177e4 LT |
2446 | if (tg3_wait_macro_done(tp)) { |
2447 | *resetp = 1; | |
2448 | return -EBUSY; | |
2449 | } | |
2450 | ||
2451 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, | |
2452 | (chan * 0x2000) | 0x0200); | |
f08aa1a8 | 2453 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0082); |
1da177e4 LT |
2454 | if (tg3_wait_macro_done(tp)) { |
2455 | *resetp = 1; | |
2456 | return -EBUSY; | |
2457 | } | |
2458 | ||
f08aa1a8 | 2459 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0802); |
1da177e4 LT |
2460 | if (tg3_wait_macro_done(tp)) { |
2461 | *resetp = 1; | |
2462 | return -EBUSY; | |
2463 | } | |
2464 | ||
2465 | for (i = 0; i < 6; i += 2) { | |
2466 | u32 low, high; | |
2467 | ||
2468 | if (tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &low) || | |
2469 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &high) || | |
2470 | tg3_wait_macro_done(tp)) { | |
2471 | *resetp = 1; | |
2472 | return -EBUSY; | |
2473 | } | |
2474 | low &= 0x7fff; | |
2475 | high &= 0x000f; | |
2476 | if (low != test_pat[chan][i] || | |
2477 | high != test_pat[chan][i+1]) { | |
2478 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000b); | |
2479 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4001); | |
2480 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x4005); | |
2481 | ||
2482 | return -EBUSY; | |
2483 | } | |
2484 | } | |
2485 | } | |
2486 | ||
2487 | return 0; | |
2488 | } | |
2489 | ||
2490 | static int tg3_phy_reset_chanpat(struct tg3 *tp) | |
2491 | { | |
2492 | int chan; | |
2493 | ||
2494 | for (chan = 0; chan < 4; chan++) { | |
2495 | int i; | |
2496 | ||
2497 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, | |
2498 | (chan * 0x2000) | 0x0200); | |
f08aa1a8 | 2499 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0002); |
1da177e4 LT |
2500 | for (i = 0; i < 6; i++) |
2501 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x000); | |
f08aa1a8 | 2502 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0202); |
1da177e4 LT |
2503 | if (tg3_wait_macro_done(tp)) |
2504 | return -EBUSY; | |
2505 | } | |
2506 | ||
2507 | return 0; | |
2508 | } | |
2509 | ||
2510 | static int tg3_phy_reset_5703_4_5(struct tg3 *tp) | |
2511 | { | |
2512 | u32 reg32, phy9_orig; | |
2513 | int retries, do_phy_reset, err; | |
2514 | ||
2515 | retries = 10; | |
2516 | do_phy_reset = 1; | |
2517 | do { | |
2518 | if (do_phy_reset) { | |
2519 | err = tg3_bmcr_reset(tp); | |
2520 | if (err) | |
2521 | return err; | |
2522 | do_phy_reset = 0; | |
2523 | } | |
2524 | ||
2525 | /* Disable transmitter and interrupt. */ | |
2526 | if (tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) | |
2527 | continue; | |
2528 | ||
2529 | reg32 |= 0x3000; | |
2530 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); | |
2531 | ||
2532 | /* Set full-duplex, 1000 mbps. */ | |
2533 | tg3_writephy(tp, MII_BMCR, | |
221c5637 | 2534 | BMCR_FULLDPLX | BMCR_SPEED1000); |
1da177e4 LT |
2535 | |
2536 | /* Set to master mode. */ | |
221c5637 | 2537 | if (tg3_readphy(tp, MII_CTRL1000, &phy9_orig)) |
1da177e4 LT |
2538 | continue; |
2539 | ||
221c5637 MC |
2540 | tg3_writephy(tp, MII_CTRL1000, |
2541 | CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER); | |
1da177e4 | 2542 | |
daf3ec68 | 2543 | err = tg3_phy_toggle_auxctl_smdsp(tp, true); |
1d36ba45 MC |
2544 | if (err) |
2545 | return err; | |
1da177e4 LT |
2546 | |
2547 | /* Block the PHY control access. */ | |
6ee7c0a0 | 2548 | tg3_phydsp_write(tp, 0x8005, 0x0800); |
1da177e4 LT |
2549 | |
2550 | err = tg3_phy_write_and_check_testpat(tp, &do_phy_reset); | |
2551 | if (!err) | |
2552 | break; | |
2553 | } while (--retries); | |
2554 | ||
2555 | err = tg3_phy_reset_chanpat(tp); | |
2556 | if (err) | |
2557 | return err; | |
2558 | ||
6ee7c0a0 | 2559 | tg3_phydsp_write(tp, 0x8005, 0x0000); |
1da177e4 LT |
2560 | |
2561 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x8200); | |
f08aa1a8 | 2562 | tg3_writephy(tp, MII_TG3_DSP_CONTROL, 0x0000); |
1da177e4 | 2563 | |
daf3ec68 | 2564 | tg3_phy_toggle_auxctl_smdsp(tp, false); |
1da177e4 | 2565 | |
221c5637 | 2566 | tg3_writephy(tp, MII_CTRL1000, phy9_orig); |
1da177e4 LT |
2567 | |
2568 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, ®32)) { | |
2569 | reg32 &= ~0x3000; | |
2570 | tg3_writephy(tp, MII_TG3_EXT_CTRL, reg32); | |
2571 | } else if (!err) | |
2572 | err = -EBUSY; | |
2573 | ||
2574 | return err; | |
2575 | } | |
2576 | ||
f4a46d1f NNS |
2577 | static void tg3_carrier_off(struct tg3 *tp) |
2578 | { | |
2579 | netif_carrier_off(tp->dev); | |
2580 | tp->link_up = false; | |
2581 | } | |
2582 | ||
ce20f161 NS |
2583 | static void tg3_warn_mgmt_link_flap(struct tg3 *tp) |
2584 | { | |
2585 | if (tg3_flag(tp, ENABLE_ASF)) | |
2586 | netdev_warn(tp->dev, | |
2587 | "Management side-band traffic will be interrupted during phy settings change\n"); | |
2588 | } | |
2589 | ||
1da177e4 LT |
2590 | /* This will reset the tigon3 PHY if there is no valid |
2591 | * link unless the FORCE argument is non-zero. | |
2592 | */ | |
2593 | static int tg3_phy_reset(struct tg3 *tp) | |
2594 | { | |
f833c4c1 | 2595 | u32 val, cpmuctrl; |
1da177e4 LT |
2596 | int err; |
2597 | ||
4153577a | 2598 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
60189ddf MC |
2599 | val = tr32(GRC_MISC_CFG); |
2600 | tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ); | |
2601 | udelay(40); | |
2602 | } | |
f833c4c1 MC |
2603 | err = tg3_readphy(tp, MII_BMSR, &val); |
2604 | err |= tg3_readphy(tp, MII_BMSR, &val); | |
1da177e4 LT |
2605 | if (err != 0) |
2606 | return -EBUSY; | |
2607 | ||
f4a46d1f | 2608 | if (netif_running(tp->dev) && tp->link_up) { |
84421b99 | 2609 | netif_carrier_off(tp->dev); |
c8e1e82b MC |
2610 | tg3_link_report(tp); |
2611 | } | |
2612 | ||
4153577a JP |
2613 | if (tg3_asic_rev(tp) == ASIC_REV_5703 || |
2614 | tg3_asic_rev(tp) == ASIC_REV_5704 || | |
2615 | tg3_asic_rev(tp) == ASIC_REV_5705) { | |
1da177e4 LT |
2616 | err = tg3_phy_reset_5703_4_5(tp); |
2617 | if (err) | |
2618 | return err; | |
2619 | goto out; | |
2620 | } | |
2621 | ||
b2a5c19c | 2622 | cpmuctrl = 0; |
4153577a JP |
2623 | if (tg3_asic_rev(tp) == ASIC_REV_5784 && |
2624 | tg3_chip_rev(tp) != CHIPREV_5784_AX) { | |
b2a5c19c MC |
2625 | cpmuctrl = tr32(TG3_CPMU_CTRL); |
2626 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) | |
2627 | tw32(TG3_CPMU_CTRL, | |
2628 | cpmuctrl & ~CPMU_CTRL_GPHY_10MB_RXONLY); | |
2629 | } | |
2630 | ||
1da177e4 LT |
2631 | err = tg3_bmcr_reset(tp); |
2632 | if (err) | |
2633 | return err; | |
2634 | ||
b2a5c19c | 2635 | if (cpmuctrl & CPMU_CTRL_GPHY_10MB_RXONLY) { |
f833c4c1 MC |
2636 | val = MII_TG3_DSP_EXP8_AEDW | MII_TG3_DSP_EXP8_REJ2MHz; |
2637 | tg3_phydsp_write(tp, MII_TG3_DSP_EXP8, val); | |
b2a5c19c MC |
2638 | |
2639 | tw32(TG3_CPMU_CTRL, cpmuctrl); | |
2640 | } | |
2641 | ||
4153577a JP |
2642 | if (tg3_chip_rev(tp) == CHIPREV_5784_AX || |
2643 | tg3_chip_rev(tp) == CHIPREV_5761_AX) { | |
ce057f01 MC |
2644 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
2645 | if ((val & CPMU_LSPD_1000MB_MACCLK_MASK) == | |
2646 | CPMU_LSPD_1000MB_MACCLK_12_5) { | |
2647 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; | |
2648 | udelay(40); | |
2649 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); | |
2650 | } | |
2651 | } | |
2652 | ||
63c3a66f | 2653 | if (tg3_flag(tp, 5717_PLUS) && |
f07e9af3 | 2654 | (tp->phy_flags & TG3_PHYFLG_MII_SERDES)) |
ecf1410b MC |
2655 | return 0; |
2656 | ||
b2a5c19c MC |
2657 | tg3_phy_apply_otp(tp); |
2658 | ||
f07e9af3 | 2659 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) |
6833c043 MC |
2660 | tg3_phy_toggle_apd(tp, true); |
2661 | else | |
2662 | tg3_phy_toggle_apd(tp, false); | |
2663 | ||
1da177e4 | 2664 | out: |
1d36ba45 | 2665 | if ((tp->phy_flags & TG3_PHYFLG_ADC_BUG) && |
daf3ec68 | 2666 | !tg3_phy_toggle_auxctl_smdsp(tp, true)) { |
6ee7c0a0 MC |
2667 | tg3_phydsp_write(tp, 0x201f, 0x2aaa); |
2668 | tg3_phydsp_write(tp, 0x000a, 0x0323); | |
daf3ec68 | 2669 | tg3_phy_toggle_auxctl_smdsp(tp, false); |
1da177e4 | 2670 | } |
1d36ba45 | 2671 | |
f07e9af3 | 2672 | if (tp->phy_flags & TG3_PHYFLG_5704_A0_BUG) { |
f08aa1a8 MC |
2673 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); |
2674 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); | |
1da177e4 | 2675 | } |
1d36ba45 | 2676 | |
f07e9af3 | 2677 | if (tp->phy_flags & TG3_PHYFLG_BER_BUG) { |
daf3ec68 | 2678 | if (!tg3_phy_toggle_auxctl_smdsp(tp, true)) { |
1d36ba45 MC |
2679 | tg3_phydsp_write(tp, 0x000a, 0x310b); |
2680 | tg3_phydsp_write(tp, 0x201f, 0x9506); | |
2681 | tg3_phydsp_write(tp, 0x401f, 0x14e2); | |
daf3ec68 | 2682 | tg3_phy_toggle_auxctl_smdsp(tp, false); |
1d36ba45 | 2683 | } |
f07e9af3 | 2684 | } else if (tp->phy_flags & TG3_PHYFLG_JITTER_BUG) { |
daf3ec68 | 2685 | if (!tg3_phy_toggle_auxctl_smdsp(tp, true)) { |
1d36ba45 MC |
2686 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, 0x000a); |
2687 | if (tp->phy_flags & TG3_PHYFLG_ADJUST_TRIM) { | |
2688 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x110b); | |
2689 | tg3_writephy(tp, MII_TG3_TEST1, | |
2690 | MII_TG3_TEST1_TRIM_EN | 0x4); | |
2691 | } else | |
2692 | tg3_writephy(tp, MII_TG3_DSP_RW_PORT, 0x010b); | |
2693 | ||
daf3ec68 | 2694 | tg3_phy_toggle_auxctl_smdsp(tp, false); |
1d36ba45 | 2695 | } |
c424cb24 | 2696 | } |
1d36ba45 | 2697 | |
1da177e4 LT |
2698 | /* Set Extended packet length bit (bit 14) on all chips that */ |
2699 | /* support jumbo frames */ | |
79eb6904 | 2700 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
1da177e4 | 2701 | /* Cannot do read-modify-write on 5401 */ |
b4bd2929 | 2702 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
63c3a66f | 2703 | } else if (tg3_flag(tp, JUMBO_CAPABLE)) { |
1da177e4 | 2704 | /* Set bit 14 with read-modify-write to preserve other bits */ |
15ee95c3 MC |
2705 | err = tg3_phy_auxctl_read(tp, |
2706 | MII_TG3_AUXCTL_SHDWSEL_AUXCTL, &val); | |
2707 | if (!err) | |
b4bd2929 MC |
2708 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, |
2709 | val | MII_TG3_AUXCTL_ACTL_EXTPKTLEN); | |
1da177e4 LT |
2710 | } |
2711 | ||
2712 | /* Set phy register 0x10 bit 0 to high fifo elasticity to support | |
2713 | * jumbo frames transmission. | |
2714 | */ | |
63c3a66f | 2715 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
f833c4c1 | 2716 | if (!tg3_readphy(tp, MII_TG3_EXT_CTRL, &val)) |
c6cdf436 | 2717 | tg3_writephy(tp, MII_TG3_EXT_CTRL, |
f833c4c1 | 2718 | val | MII_TG3_EXT_CTRL_FIFO_ELASTIC); |
1da177e4 LT |
2719 | } |
2720 | ||
4153577a | 2721 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
715116a1 | 2722 | /* adjust output voltage */ |
535ef6e1 | 2723 | tg3_writephy(tp, MII_TG3_FET_PTEST, 0x12); |
715116a1 MC |
2724 | } |
2725 | ||
4153577a | 2726 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5762_A0) |
c65a17f4 MC |
2727 | tg3_phydsp_write(tp, 0xffb, 0x4000); |
2728 | ||
953c96e0 | 2729 | tg3_phy_toggle_automdix(tp, true); |
1da177e4 LT |
2730 | tg3_phy_set_wirespeed(tp); |
2731 | return 0; | |
2732 | } | |
2733 | ||
3a1e19d3 MC |
2734 | #define TG3_GPIO_MSG_DRVR_PRES 0x00000001 |
2735 | #define TG3_GPIO_MSG_NEED_VAUX 0x00000002 | |
2736 | #define TG3_GPIO_MSG_MASK (TG3_GPIO_MSG_DRVR_PRES | \ | |
2737 | TG3_GPIO_MSG_NEED_VAUX) | |
2738 | #define TG3_GPIO_MSG_ALL_DRVR_PRES_MASK \ | |
2739 | ((TG3_GPIO_MSG_DRVR_PRES << 0) | \ | |
2740 | (TG3_GPIO_MSG_DRVR_PRES << 4) | \ | |
2741 | (TG3_GPIO_MSG_DRVR_PRES << 8) | \ | |
2742 | (TG3_GPIO_MSG_DRVR_PRES << 12)) | |
2743 | ||
2744 | #define TG3_GPIO_MSG_ALL_NEED_VAUX_MASK \ | |
2745 | ((TG3_GPIO_MSG_NEED_VAUX << 0) | \ | |
2746 | (TG3_GPIO_MSG_NEED_VAUX << 4) | \ | |
2747 | (TG3_GPIO_MSG_NEED_VAUX << 8) | \ | |
2748 | (TG3_GPIO_MSG_NEED_VAUX << 12)) | |
2749 | ||
2750 | static inline u32 tg3_set_function_status(struct tg3 *tp, u32 newstat) | |
2751 | { | |
2752 | u32 status, shift; | |
2753 | ||
4153577a JP |
2754 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
2755 | tg3_asic_rev(tp) == ASIC_REV_5719) | |
3a1e19d3 MC |
2756 | status = tg3_ape_read32(tp, TG3_APE_GPIO_MSG); |
2757 | else | |
2758 | status = tr32(TG3_CPMU_DRV_STATUS); | |
2759 | ||
2760 | shift = TG3_APE_GPIO_MSG_SHIFT + 4 * tp->pci_fn; | |
2761 | status &= ~(TG3_GPIO_MSG_MASK << shift); | |
2762 | status |= (newstat << shift); | |
2763 | ||
4153577a JP |
2764 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
2765 | tg3_asic_rev(tp) == ASIC_REV_5719) | |
3a1e19d3 MC |
2766 | tg3_ape_write32(tp, TG3_APE_GPIO_MSG, status); |
2767 | else | |
2768 | tw32(TG3_CPMU_DRV_STATUS, status); | |
2769 | ||
2770 | return status >> TG3_APE_GPIO_MSG_SHIFT; | |
2771 | } | |
2772 | ||
520b2756 MC |
2773 | static inline int tg3_pwrsrc_switch_to_vmain(struct tg3 *tp) |
2774 | { | |
2775 | if (!tg3_flag(tp, IS_NIC)) | |
2776 | return 0; | |
2777 | ||
4153577a JP |
2778 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
2779 | tg3_asic_rev(tp) == ASIC_REV_5719 || | |
2780 | tg3_asic_rev(tp) == ASIC_REV_5720) { | |
3a1e19d3 MC |
2781 | if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO)) |
2782 | return -EIO; | |
520b2756 | 2783 | |
3a1e19d3 MC |
2784 | tg3_set_function_status(tp, TG3_GPIO_MSG_DRVR_PRES); |
2785 | ||
2786 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, | |
2787 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2788 | ||
2789 | tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO); | |
2790 | } else { | |
2791 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl, | |
2792 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2793 | } | |
6f5c8f83 | 2794 | |
520b2756 MC |
2795 | return 0; |
2796 | } | |
2797 | ||
2798 | static void tg3_pwrsrc_die_with_vmain(struct tg3 *tp) | |
2799 | { | |
2800 | u32 grc_local_ctrl; | |
2801 | ||
2802 | if (!tg3_flag(tp, IS_NIC) || | |
4153577a JP |
2803 | tg3_asic_rev(tp) == ASIC_REV_5700 || |
2804 | tg3_asic_rev(tp) == ASIC_REV_5701) | |
520b2756 MC |
2805 | return; |
2806 | ||
2807 | grc_local_ctrl = tp->grc_local_ctrl | GRC_LCLCTRL_GPIO_OE1; | |
2808 | ||
2809 | tw32_wait_f(GRC_LOCAL_CTRL, | |
2810 | grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1, | |
2811 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2812 | ||
2813 | tw32_wait_f(GRC_LOCAL_CTRL, | |
2814 | grc_local_ctrl, | |
2815 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2816 | ||
2817 | tw32_wait_f(GRC_LOCAL_CTRL, | |
2818 | grc_local_ctrl | GRC_LCLCTRL_GPIO_OUTPUT1, | |
2819 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2820 | } | |
2821 | ||
2822 | static void tg3_pwrsrc_switch_to_vaux(struct tg3 *tp) | |
2823 | { | |
2824 | if (!tg3_flag(tp, IS_NIC)) | |
2825 | return; | |
2826 | ||
4153577a JP |
2827 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
2828 | tg3_asic_rev(tp) == ASIC_REV_5701) { | |
520b2756 MC |
2829 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | |
2830 | (GRC_LCLCTRL_GPIO_OE0 | | |
2831 | GRC_LCLCTRL_GPIO_OE1 | | |
2832 | GRC_LCLCTRL_GPIO_OE2 | | |
2833 | GRC_LCLCTRL_GPIO_OUTPUT0 | | |
2834 | GRC_LCLCTRL_GPIO_OUTPUT1), | |
2835 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2836 | } else if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || | |
2837 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { | |
2838 | /* The 5761 non-e device swaps GPIO 0 and GPIO 2. */ | |
2839 | u32 grc_local_ctrl = GRC_LCLCTRL_GPIO_OE0 | | |
2840 | GRC_LCLCTRL_GPIO_OE1 | | |
2841 | GRC_LCLCTRL_GPIO_OE2 | | |
2842 | GRC_LCLCTRL_GPIO_OUTPUT0 | | |
2843 | GRC_LCLCTRL_GPIO_OUTPUT1 | | |
2844 | tp->grc_local_ctrl; | |
2845 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, | |
2846 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2847 | ||
2848 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT2; | |
2849 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, | |
2850 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2851 | ||
2852 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT0; | |
2853 | tw32_wait_f(GRC_LOCAL_CTRL, grc_local_ctrl, | |
2854 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2855 | } else { | |
2856 | u32 no_gpio2; | |
2857 | u32 grc_local_ctrl = 0; | |
2858 | ||
2859 | /* Workaround to prevent overdrawing Amps. */ | |
4153577a | 2860 | if (tg3_asic_rev(tp) == ASIC_REV_5714) { |
520b2756 MC |
2861 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
2862 | tw32_wait_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl | | |
2863 | grc_local_ctrl, | |
2864 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2865 | } | |
2866 | ||
2867 | /* On 5753 and variants, GPIO2 cannot be used. */ | |
2868 | no_gpio2 = tp->nic_sram_data_cfg & | |
2869 | NIC_SRAM_DATA_CFG_NO_GPIO2; | |
2870 | ||
2871 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | | |
2872 | GRC_LCLCTRL_GPIO_OE1 | | |
2873 | GRC_LCLCTRL_GPIO_OE2 | | |
2874 | GRC_LCLCTRL_GPIO_OUTPUT1 | | |
2875 | GRC_LCLCTRL_GPIO_OUTPUT2; | |
2876 | if (no_gpio2) { | |
2877 | grc_local_ctrl &= ~(GRC_LCLCTRL_GPIO_OE2 | | |
2878 | GRC_LCLCTRL_GPIO_OUTPUT2); | |
2879 | } | |
2880 | tw32_wait_f(GRC_LOCAL_CTRL, | |
2881 | tp->grc_local_ctrl | grc_local_ctrl, | |
2882 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2883 | ||
2884 | grc_local_ctrl |= GRC_LCLCTRL_GPIO_OUTPUT0; | |
2885 | ||
2886 | tw32_wait_f(GRC_LOCAL_CTRL, | |
2887 | tp->grc_local_ctrl | grc_local_ctrl, | |
2888 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2889 | ||
2890 | if (!no_gpio2) { | |
2891 | grc_local_ctrl &= ~GRC_LCLCTRL_GPIO_OUTPUT2; | |
2892 | tw32_wait_f(GRC_LOCAL_CTRL, | |
2893 | tp->grc_local_ctrl | grc_local_ctrl, | |
2894 | TG3_GRC_LCLCTL_PWRSW_DELAY); | |
2895 | } | |
2896 | } | |
3a1e19d3 MC |
2897 | } |
2898 | ||
cd0d7228 | 2899 | static void tg3_frob_aux_power_5717(struct tg3 *tp, bool wol_enable) |
3a1e19d3 MC |
2900 | { |
2901 | u32 msg = 0; | |
2902 | ||
2903 | /* Serialize power state transitions */ | |
2904 | if (tg3_ape_lock(tp, TG3_APE_LOCK_GPIO)) | |
2905 | return; | |
2906 | ||
cd0d7228 | 2907 | if (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE) || wol_enable) |
3a1e19d3 MC |
2908 | msg = TG3_GPIO_MSG_NEED_VAUX; |
2909 | ||
2910 | msg = tg3_set_function_status(tp, msg); | |
2911 | ||
2912 | if (msg & TG3_GPIO_MSG_ALL_DRVR_PRES_MASK) | |
2913 | goto done; | |
6f5c8f83 | 2914 | |
3a1e19d3 MC |
2915 | if (msg & TG3_GPIO_MSG_ALL_NEED_VAUX_MASK) |
2916 | tg3_pwrsrc_switch_to_vaux(tp); | |
2917 | else | |
2918 | tg3_pwrsrc_die_with_vmain(tp); | |
2919 | ||
2920 | done: | |
6f5c8f83 | 2921 | tg3_ape_unlock(tp, TG3_APE_LOCK_GPIO); |
520b2756 MC |
2922 | } |
2923 | ||
cd0d7228 | 2924 | static void tg3_frob_aux_power(struct tg3 *tp, bool include_wol) |
1da177e4 | 2925 | { |
683644b7 | 2926 | bool need_vaux = false; |
1da177e4 | 2927 | |
334355aa | 2928 | /* The GPIOs do something completely different on 57765. */ |
55086ad9 | 2929 | if (!tg3_flag(tp, IS_NIC) || tg3_flag(tp, 57765_CLASS)) |
1da177e4 LT |
2930 | return; |
2931 | ||
4153577a JP |
2932 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
2933 | tg3_asic_rev(tp) == ASIC_REV_5719 || | |
2934 | tg3_asic_rev(tp) == ASIC_REV_5720) { | |
cd0d7228 MC |
2935 | tg3_frob_aux_power_5717(tp, include_wol ? |
2936 | tg3_flag(tp, WOL_ENABLE) != 0 : 0); | |
3a1e19d3 MC |
2937 | return; |
2938 | } | |
2939 | ||
2940 | if (tp->pdev_peer && tp->pdev_peer != tp->pdev) { | |
8c2dc7e1 MC |
2941 | struct net_device *dev_peer; |
2942 | ||
2943 | dev_peer = pci_get_drvdata(tp->pdev_peer); | |
683644b7 | 2944 | |
bc1c7567 | 2945 | /* remove_one() may have been run on the peer. */ |
683644b7 MC |
2946 | if (dev_peer) { |
2947 | struct tg3 *tp_peer = netdev_priv(dev_peer); | |
2948 | ||
63c3a66f | 2949 | if (tg3_flag(tp_peer, INIT_COMPLETE)) |
683644b7 MC |
2950 | return; |
2951 | ||
cd0d7228 | 2952 | if ((include_wol && tg3_flag(tp_peer, WOL_ENABLE)) || |
63c3a66f | 2953 | tg3_flag(tp_peer, ENABLE_ASF)) |
683644b7 MC |
2954 | need_vaux = true; |
2955 | } | |
1da177e4 LT |
2956 | } |
2957 | ||
cd0d7228 MC |
2958 | if ((include_wol && tg3_flag(tp, WOL_ENABLE)) || |
2959 | tg3_flag(tp, ENABLE_ASF)) | |
683644b7 MC |
2960 | need_vaux = true; |
2961 | ||
520b2756 MC |
2962 | if (need_vaux) |
2963 | tg3_pwrsrc_switch_to_vaux(tp); | |
2964 | else | |
2965 | tg3_pwrsrc_die_with_vmain(tp); | |
1da177e4 LT |
2966 | } |
2967 | ||
e8f3f6ca MC |
2968 | static int tg3_5700_link_polarity(struct tg3 *tp, u32 speed) |
2969 | { | |
2970 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_2) | |
2971 | return 1; | |
79eb6904 | 2972 | else if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411) { |
e8f3f6ca MC |
2973 | if (speed != SPEED_10) |
2974 | return 1; | |
2975 | } else if (speed == SPEED_10) | |
2976 | return 1; | |
2977 | ||
2978 | return 0; | |
2979 | } | |
2980 | ||
44f3b503 NS |
2981 | static bool tg3_phy_power_bug(struct tg3 *tp) |
2982 | { | |
2983 | switch (tg3_asic_rev(tp)) { | |
2984 | case ASIC_REV_5700: | |
2985 | case ASIC_REV_5704: | |
2986 | return true; | |
2987 | case ASIC_REV_5780: | |
2988 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) | |
2989 | return true; | |
2990 | return false; | |
2991 | case ASIC_REV_5717: | |
2992 | if (!tp->pci_fn) | |
2993 | return true; | |
2994 | return false; | |
2995 | case ASIC_REV_5719: | |
2996 | case ASIC_REV_5720: | |
2997 | if ((tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && | |
2998 | !tp->pci_fn) | |
2999 | return true; | |
3000 | return false; | |
3001 | } | |
3002 | ||
3003 | return false; | |
3004 | } | |
3005 | ||
84a38c47 NS |
3006 | static bool tg3_phy_led_bug(struct tg3 *tp) |
3007 | { | |
3008 | switch (tg3_asic_rev(tp)) { | |
3009 | case ASIC_REV_5719: | |
3010 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && | |
3011 | !tp->pci_fn) | |
3012 | return true; | |
3013 | return false; | |
3014 | } | |
3015 | ||
3016 | return false; | |
3017 | } | |
3018 | ||
0a459aac | 3019 | static void tg3_power_down_phy(struct tg3 *tp, bool do_low_power) |
15c3b696 | 3020 | { |
ce057f01 MC |
3021 | u32 val; |
3022 | ||
942d1af0 NS |
3023 | if (tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN) |
3024 | return; | |
3025 | ||
f07e9af3 | 3026 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
4153577a | 3027 | if (tg3_asic_rev(tp) == ASIC_REV_5704) { |
5129724a MC |
3028 | u32 sg_dig_ctrl = tr32(SG_DIG_CTRL); |
3029 | u32 serdes_cfg = tr32(MAC_SERDES_CFG); | |
3030 | ||
3031 | sg_dig_ctrl |= | |
3032 | SG_DIG_USING_HW_AUTONEG | SG_DIG_SOFT_RESET; | |
3033 | tw32(SG_DIG_CTRL, sg_dig_ctrl); | |
3034 | tw32(MAC_SERDES_CFG, serdes_cfg | (1 << 15)); | |
3035 | } | |
3f7045c1 | 3036 | return; |
5129724a | 3037 | } |
3f7045c1 | 3038 | |
4153577a | 3039 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
60189ddf MC |
3040 | tg3_bmcr_reset(tp); |
3041 | val = tr32(GRC_MISC_CFG); | |
3042 | tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ); | |
3043 | udelay(40); | |
3044 | return; | |
f07e9af3 | 3045 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
0e5f784c MC |
3046 | u32 phytest; |
3047 | if (!tg3_readphy(tp, MII_TG3_FET_TEST, &phytest)) { | |
3048 | u32 phy; | |
3049 | ||
3050 | tg3_writephy(tp, MII_ADVERTISE, 0); | |
3051 | tg3_writephy(tp, MII_BMCR, | |
3052 | BMCR_ANENABLE | BMCR_ANRESTART); | |
3053 | ||
3054 | tg3_writephy(tp, MII_TG3_FET_TEST, | |
3055 | phytest | MII_TG3_FET_SHADOW_EN); | |
3056 | if (!tg3_readphy(tp, MII_TG3_FET_SHDW_AUXMODE4, &phy)) { | |
3057 | phy |= MII_TG3_FET_SHDW_AUXMODE4_SBPD; | |
3058 | tg3_writephy(tp, | |
3059 | MII_TG3_FET_SHDW_AUXMODE4, | |
3060 | phy); | |
3061 | } | |
3062 | tg3_writephy(tp, MII_TG3_FET_TEST, phytest); | |
3063 | } | |
3064 | return; | |
0a459aac | 3065 | } else if (do_low_power) { |
84a38c47 NS |
3066 | if (!tg3_phy_led_bug(tp)) |
3067 | tg3_writephy(tp, MII_TG3_EXT_CTRL, | |
3068 | MII_TG3_EXT_CTRL_FORCE_LED_OFF); | |
0a459aac | 3069 | |
b4bd2929 MC |
3070 | val = MII_TG3_AUXCTL_PCTL_100TX_LPWR | |
3071 | MII_TG3_AUXCTL_PCTL_SPR_ISOLATE | | |
3072 | MII_TG3_AUXCTL_PCTL_VREG_11V; | |
3073 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, val); | |
715116a1 | 3074 | } |
3f7045c1 | 3075 | |
15c3b696 MC |
3076 | /* The PHY should not be powered down on some chips because |
3077 | * of bugs. | |
3078 | */ | |
44f3b503 | 3079 | if (tg3_phy_power_bug(tp)) |
15c3b696 | 3080 | return; |
ce057f01 | 3081 | |
4153577a JP |
3082 | if (tg3_chip_rev(tp) == CHIPREV_5784_AX || |
3083 | tg3_chip_rev(tp) == CHIPREV_5761_AX) { | |
ce057f01 MC |
3084 | val = tr32(TG3_CPMU_LSPD_1000MB_CLK); |
3085 | val &= ~CPMU_LSPD_1000MB_MACCLK_MASK; | |
3086 | val |= CPMU_LSPD_1000MB_MACCLK_12_5; | |
3087 | tw32_f(TG3_CPMU_LSPD_1000MB_CLK, val); | |
3088 | } | |
3089 | ||
15c3b696 MC |
3090 | tg3_writephy(tp, MII_BMCR, BMCR_PDOWN); |
3091 | } | |
3092 | ||
ffbcfed4 MC |
3093 | /* tp->lock is held. */ |
3094 | static int tg3_nvram_lock(struct tg3 *tp) | |
3095 | { | |
63c3a66f | 3096 | if (tg3_flag(tp, NVRAM)) { |
ffbcfed4 MC |
3097 | int i; |
3098 | ||
3099 | if (tp->nvram_lock_cnt == 0) { | |
3100 | tw32(NVRAM_SWARB, SWARB_REQ_SET1); | |
3101 | for (i = 0; i < 8000; i++) { | |
3102 | if (tr32(NVRAM_SWARB) & SWARB_GNT1) | |
3103 | break; | |
3104 | udelay(20); | |
3105 | } | |
3106 | if (i == 8000) { | |
3107 | tw32(NVRAM_SWARB, SWARB_REQ_CLR1); | |
3108 | return -ENODEV; | |
3109 | } | |
3110 | } | |
3111 | tp->nvram_lock_cnt++; | |
3112 | } | |
3113 | return 0; | |
3114 | } | |
3115 | ||
3116 | /* tp->lock is held. */ | |
3117 | static void tg3_nvram_unlock(struct tg3 *tp) | |
3118 | { | |
63c3a66f | 3119 | if (tg3_flag(tp, NVRAM)) { |
ffbcfed4 MC |
3120 | if (tp->nvram_lock_cnt > 0) |
3121 | tp->nvram_lock_cnt--; | |
3122 | if (tp->nvram_lock_cnt == 0) | |
3123 | tw32_f(NVRAM_SWARB, SWARB_REQ_CLR1); | |
3124 | } | |
3125 | } | |
3126 | ||
3127 | /* tp->lock is held. */ | |
3128 | static void tg3_enable_nvram_access(struct tg3 *tp) | |
3129 | { | |
63c3a66f | 3130 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
ffbcfed4 MC |
3131 | u32 nvaccess = tr32(NVRAM_ACCESS); |
3132 | ||
3133 | tw32(NVRAM_ACCESS, nvaccess | ACCESS_ENABLE); | |
3134 | } | |
3135 | } | |
3136 | ||
3137 | /* tp->lock is held. */ | |
3138 | static void tg3_disable_nvram_access(struct tg3 *tp) | |
3139 | { | |
63c3a66f | 3140 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) { |
ffbcfed4 MC |
3141 | u32 nvaccess = tr32(NVRAM_ACCESS); |
3142 | ||
3143 | tw32(NVRAM_ACCESS, nvaccess & ~ACCESS_ENABLE); | |
3144 | } | |
3145 | } | |
3146 | ||
3147 | static int tg3_nvram_read_using_eeprom(struct tg3 *tp, | |
3148 | u32 offset, u32 *val) | |
3149 | { | |
3150 | u32 tmp; | |
3151 | int i; | |
3152 | ||
3153 | if (offset > EEPROM_ADDR_ADDR_MASK || (offset % 4) != 0) | |
3154 | return -EINVAL; | |
3155 | ||
3156 | tmp = tr32(GRC_EEPROM_ADDR) & ~(EEPROM_ADDR_ADDR_MASK | | |
3157 | EEPROM_ADDR_DEVID_MASK | | |
3158 | EEPROM_ADDR_READ); | |
3159 | tw32(GRC_EEPROM_ADDR, | |
3160 | tmp | | |
3161 | (0 << EEPROM_ADDR_DEVID_SHIFT) | | |
3162 | ((offset << EEPROM_ADDR_ADDR_SHIFT) & | |
3163 | EEPROM_ADDR_ADDR_MASK) | | |
3164 | EEPROM_ADDR_READ | EEPROM_ADDR_START); | |
3165 | ||
3166 | for (i = 0; i < 1000; i++) { | |
3167 | tmp = tr32(GRC_EEPROM_ADDR); | |
3168 | ||
3169 | if (tmp & EEPROM_ADDR_COMPLETE) | |
3170 | break; | |
3171 | msleep(1); | |
3172 | } | |
3173 | if (!(tmp & EEPROM_ADDR_COMPLETE)) | |
3174 | return -EBUSY; | |
3175 | ||
62cedd11 MC |
3176 | tmp = tr32(GRC_EEPROM_DATA); |
3177 | ||
3178 | /* | |
3179 | * The data will always be opposite the native endian | |
3180 | * format. Perform a blind byteswap to compensate. | |
3181 | */ | |
3182 | *val = swab32(tmp); | |
3183 | ||
ffbcfed4 MC |
3184 | return 0; |
3185 | } | |
3186 | ||
3187 | #define NVRAM_CMD_TIMEOUT 10000 | |
3188 | ||
3189 | static int tg3_nvram_exec_cmd(struct tg3 *tp, u32 nvram_cmd) | |
3190 | { | |
3191 | int i; | |
3192 | ||
3193 | tw32(NVRAM_CMD, nvram_cmd); | |
3194 | for (i = 0; i < NVRAM_CMD_TIMEOUT; i++) { | |
3195 | udelay(10); | |
3196 | if (tr32(NVRAM_CMD) & NVRAM_CMD_DONE) { | |
3197 | udelay(10); | |
3198 | break; | |
3199 | } | |
3200 | } | |
3201 | ||
3202 | if (i == NVRAM_CMD_TIMEOUT) | |
3203 | return -EBUSY; | |
3204 | ||
3205 | return 0; | |
3206 | } | |
3207 | ||
3208 | static u32 tg3_nvram_phys_addr(struct tg3 *tp, u32 addr) | |
3209 | { | |
63c3a66f JP |
3210 | if (tg3_flag(tp, NVRAM) && |
3211 | tg3_flag(tp, NVRAM_BUFFERED) && | |
3212 | tg3_flag(tp, FLASH) && | |
3213 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && | |
ffbcfed4 MC |
3214 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
3215 | ||
3216 | addr = ((addr / tp->nvram_pagesize) << | |
3217 | ATMEL_AT45DB0X1B_PAGE_POS) + | |
3218 | (addr % tp->nvram_pagesize); | |
3219 | ||
3220 | return addr; | |
3221 | } | |
3222 | ||
3223 | static u32 tg3_nvram_logical_addr(struct tg3 *tp, u32 addr) | |
3224 | { | |
63c3a66f JP |
3225 | if (tg3_flag(tp, NVRAM) && |
3226 | tg3_flag(tp, NVRAM_BUFFERED) && | |
3227 | tg3_flag(tp, FLASH) && | |
3228 | !tg3_flag(tp, NO_NVRAM_ADDR_TRANS) && | |
ffbcfed4 MC |
3229 | (tp->nvram_jedecnum == JEDEC_ATMEL)) |
3230 | ||
3231 | addr = ((addr >> ATMEL_AT45DB0X1B_PAGE_POS) * | |
3232 | tp->nvram_pagesize) + | |
3233 | (addr & ((1 << ATMEL_AT45DB0X1B_PAGE_POS) - 1)); | |
3234 | ||
3235 | return addr; | |
3236 | } | |
3237 | ||
e4f34110 MC |
3238 | /* NOTE: Data read in from NVRAM is byteswapped according to |
3239 | * the byteswapping settings for all other register accesses. | |
3240 | * tg3 devices are BE devices, so on a BE machine, the data | |
3241 | * returned will be exactly as it is seen in NVRAM. On a LE | |
3242 | * machine, the 32-bit value will be byteswapped. | |
3243 | */ | |
ffbcfed4 MC |
3244 | static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val) |
3245 | { | |
3246 | int ret; | |
3247 | ||
63c3a66f | 3248 | if (!tg3_flag(tp, NVRAM)) |
ffbcfed4 MC |
3249 | return tg3_nvram_read_using_eeprom(tp, offset, val); |
3250 | ||
3251 | offset = tg3_nvram_phys_addr(tp, offset); | |
3252 | ||
3253 | if (offset > NVRAM_ADDR_MSK) | |
3254 | return -EINVAL; | |
3255 | ||
3256 | ret = tg3_nvram_lock(tp); | |
3257 | if (ret) | |
3258 | return ret; | |
3259 | ||
3260 | tg3_enable_nvram_access(tp); | |
3261 | ||
3262 | tw32(NVRAM_ADDR, offset); | |
3263 | ret = tg3_nvram_exec_cmd(tp, NVRAM_CMD_RD | NVRAM_CMD_GO | | |
3264 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE); | |
3265 | ||
3266 | if (ret == 0) | |
e4f34110 | 3267 | *val = tr32(NVRAM_RDDATA); |
ffbcfed4 MC |
3268 | |
3269 | tg3_disable_nvram_access(tp); | |
3270 | ||
3271 | tg3_nvram_unlock(tp); | |
3272 | ||
3273 | return ret; | |
3274 | } | |
3275 | ||
a9dc529d MC |
3276 | /* Ensures NVRAM data is in bytestream format. */ |
3277 | static int tg3_nvram_read_be32(struct tg3 *tp, u32 offset, __be32 *val) | |
ffbcfed4 MC |
3278 | { |
3279 | u32 v; | |
a9dc529d | 3280 | int res = tg3_nvram_read(tp, offset, &v); |
ffbcfed4 | 3281 | if (!res) |
a9dc529d | 3282 | *val = cpu_to_be32(v); |
ffbcfed4 MC |
3283 | return res; |
3284 | } | |
3285 | ||
dbe9b92a MC |
3286 | static int tg3_nvram_write_block_using_eeprom(struct tg3 *tp, |
3287 | u32 offset, u32 len, u8 *buf) | |
3288 | { | |
3289 | int i, j, rc = 0; | |
3290 | u32 val; | |
3291 | ||
3292 | for (i = 0; i < len; i += 4) { | |
3293 | u32 addr; | |
3294 | __be32 data; | |
3295 | ||
3296 | addr = offset + i; | |
3297 | ||
3298 | memcpy(&data, buf + i, 4); | |
3299 | ||
3300 | /* | |
3301 | * The SEEPROM interface expects the data to always be opposite | |
3302 | * the native endian format. We accomplish this by reversing | |
3303 | * all the operations that would have been performed on the | |
3304 | * data from a call to tg3_nvram_read_be32(). | |
3305 | */ | |
3306 | tw32(GRC_EEPROM_DATA, swab32(be32_to_cpu(data))); | |
3307 | ||
3308 | val = tr32(GRC_EEPROM_ADDR); | |
3309 | tw32(GRC_EEPROM_ADDR, val | EEPROM_ADDR_COMPLETE); | |
3310 | ||
3311 | val &= ~(EEPROM_ADDR_ADDR_MASK | EEPROM_ADDR_DEVID_MASK | | |
3312 | EEPROM_ADDR_READ); | |
3313 | tw32(GRC_EEPROM_ADDR, val | | |
3314 | (0 << EEPROM_ADDR_DEVID_SHIFT) | | |
3315 | (addr & EEPROM_ADDR_ADDR_MASK) | | |
3316 | EEPROM_ADDR_START | | |
3317 | EEPROM_ADDR_WRITE); | |
3318 | ||
3319 | for (j = 0; j < 1000; j++) { | |
3320 | val = tr32(GRC_EEPROM_ADDR); | |
3321 | ||
3322 | if (val & EEPROM_ADDR_COMPLETE) | |
3323 | break; | |
3324 | msleep(1); | |
3325 | } | |
3326 | if (!(val & EEPROM_ADDR_COMPLETE)) { | |
3327 | rc = -EBUSY; | |
3328 | break; | |
3329 | } | |
3330 | } | |
3331 | ||
3332 | return rc; | |
3333 | } | |
3334 | ||
3335 | /* offset and length are dword aligned */ | |
3336 | static int tg3_nvram_write_block_unbuffered(struct tg3 *tp, u32 offset, u32 len, | |
3337 | u8 *buf) | |
3338 | { | |
3339 | int ret = 0; | |
3340 | u32 pagesize = tp->nvram_pagesize; | |
3341 | u32 pagemask = pagesize - 1; | |
3342 | u32 nvram_cmd; | |
3343 | u8 *tmp; | |
3344 | ||
3345 | tmp = kmalloc(pagesize, GFP_KERNEL); | |
3346 | if (tmp == NULL) | |
3347 | return -ENOMEM; | |
3348 | ||
3349 | while (len) { | |
3350 | int j; | |
3351 | u32 phy_addr, page_off, size; | |
3352 | ||
3353 | phy_addr = offset & ~pagemask; | |
3354 | ||
3355 | for (j = 0; j < pagesize; j += 4) { | |
3356 | ret = tg3_nvram_read_be32(tp, phy_addr + j, | |
3357 | (__be32 *) (tmp + j)); | |
3358 | if (ret) | |
3359 | break; | |
3360 | } | |
3361 | if (ret) | |
3362 | break; | |
3363 | ||
3364 | page_off = offset & pagemask; | |
3365 | size = pagesize; | |
3366 | if (len < size) | |
3367 | size = len; | |
3368 | ||
3369 | len -= size; | |
3370 | ||
3371 | memcpy(tmp + page_off, buf, size); | |
3372 | ||
3373 | offset = offset + (pagesize - page_off); | |
3374 | ||
3375 | tg3_enable_nvram_access(tp); | |
3376 | ||
3377 | /* | |
3378 | * Before we can erase the flash page, we need | |
3379 | * to issue a special "write enable" command. | |
3380 | */ | |
3381 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; | |
3382 | ||
3383 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) | |
3384 | break; | |
3385 | ||
3386 | /* Erase the target page */ | |
3387 | tw32(NVRAM_ADDR, phy_addr); | |
3388 | ||
3389 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR | | |
3390 | NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_ERASE; | |
3391 | ||
3392 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) | |
3393 | break; | |
3394 | ||
3395 | /* Issue another write enable to start the write. */ | |
3396 | nvram_cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; | |
3397 | ||
3398 | if (tg3_nvram_exec_cmd(tp, nvram_cmd)) | |
3399 | break; | |
3400 | ||
3401 | for (j = 0; j < pagesize; j += 4) { | |
3402 | __be32 data; | |
3403 | ||
3404 | data = *((__be32 *) (tmp + j)); | |
3405 | ||
3406 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); | |
3407 | ||
3408 | tw32(NVRAM_ADDR, phy_addr + j); | |
3409 | ||
3410 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | | |
3411 | NVRAM_CMD_WR; | |
3412 | ||
3413 | if (j == 0) | |
3414 | nvram_cmd |= NVRAM_CMD_FIRST; | |
3415 | else if (j == (pagesize - 4)) | |
3416 | nvram_cmd |= NVRAM_CMD_LAST; | |
3417 | ||
3418 | ret = tg3_nvram_exec_cmd(tp, nvram_cmd); | |
3419 | if (ret) | |
3420 | break; | |
3421 | } | |
3422 | if (ret) | |
3423 | break; | |
3424 | } | |
3425 | ||
3426 | nvram_cmd = NVRAM_CMD_WRDI | NVRAM_CMD_GO | NVRAM_CMD_DONE; | |
3427 | tg3_nvram_exec_cmd(tp, nvram_cmd); | |
3428 | ||
3429 | kfree(tmp); | |
3430 | ||
3431 | return ret; | |
3432 | } | |
3433 | ||
3434 | /* offset and length are dword aligned */ | |
3435 | static int tg3_nvram_write_block_buffered(struct tg3 *tp, u32 offset, u32 len, | |
3436 | u8 *buf) | |
3437 | { | |
3438 | int i, ret = 0; | |
3439 | ||
3440 | for (i = 0; i < len; i += 4, offset += 4) { | |
3441 | u32 page_off, phy_addr, nvram_cmd; | |
3442 | __be32 data; | |
3443 | ||
3444 | memcpy(&data, buf + i, 4); | |
3445 | tw32(NVRAM_WRDATA, be32_to_cpu(data)); | |
3446 | ||
3447 | page_off = offset % tp->nvram_pagesize; | |
3448 | ||
3449 | phy_addr = tg3_nvram_phys_addr(tp, offset); | |
3450 | ||
dbe9b92a MC |
3451 | nvram_cmd = NVRAM_CMD_GO | NVRAM_CMD_DONE | NVRAM_CMD_WR; |
3452 | ||
3453 | if (page_off == 0 || i == 0) | |
3454 | nvram_cmd |= NVRAM_CMD_FIRST; | |
3455 | if (page_off == (tp->nvram_pagesize - 4)) | |
3456 | nvram_cmd |= NVRAM_CMD_LAST; | |
3457 | ||
3458 | if (i == (len - 4)) | |
3459 | nvram_cmd |= NVRAM_CMD_LAST; | |
3460 | ||
42278224 MC |
3461 | if ((nvram_cmd & NVRAM_CMD_FIRST) || |
3462 | !tg3_flag(tp, FLASH) || | |
3463 | !tg3_flag(tp, 57765_PLUS)) | |
3464 | tw32(NVRAM_ADDR, phy_addr); | |
3465 | ||
4153577a | 3466 | if (tg3_asic_rev(tp) != ASIC_REV_5752 && |
dbe9b92a MC |
3467 | !tg3_flag(tp, 5755_PLUS) && |
3468 | (tp->nvram_jedecnum == JEDEC_ST) && | |
3469 | (nvram_cmd & NVRAM_CMD_FIRST)) { | |
3470 | u32 cmd; | |
3471 | ||
3472 | cmd = NVRAM_CMD_WREN | NVRAM_CMD_GO | NVRAM_CMD_DONE; | |
3473 | ret = tg3_nvram_exec_cmd(tp, cmd); | |
3474 | if (ret) | |
3475 | break; | |
3476 | } | |
3477 | if (!tg3_flag(tp, FLASH)) { | |
3478 | /* We always do complete word writes to eeprom. */ | |
3479 | nvram_cmd |= (NVRAM_CMD_FIRST | NVRAM_CMD_LAST); | |
3480 | } | |
3481 | ||
3482 | ret = tg3_nvram_exec_cmd(tp, nvram_cmd); | |
3483 | if (ret) | |
3484 | break; | |
3485 | } | |
3486 | return ret; | |
3487 | } | |
3488 | ||
3489 | /* offset and length are dword aligned */ | |
3490 | static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf) | |
3491 | { | |
3492 | int ret; | |
3493 | ||
3494 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { | |
3495 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl & | |
3496 | ~GRC_LCLCTRL_GPIO_OUTPUT1); | |
3497 | udelay(40); | |
3498 | } | |
3499 | ||
3500 | if (!tg3_flag(tp, NVRAM)) { | |
3501 | ret = tg3_nvram_write_block_using_eeprom(tp, offset, len, buf); | |
3502 | } else { | |
3503 | u32 grc_mode; | |
3504 | ||
3505 | ret = tg3_nvram_lock(tp); | |
3506 | if (ret) | |
3507 | return ret; | |
3508 | ||
3509 | tg3_enable_nvram_access(tp); | |
3510 | if (tg3_flag(tp, 5750_PLUS) && !tg3_flag(tp, PROTECTED_NVRAM)) | |
3511 | tw32(NVRAM_WRITE1, 0x406); | |
3512 | ||
3513 | grc_mode = tr32(GRC_MODE); | |
3514 | tw32(GRC_MODE, grc_mode | GRC_MODE_NVRAM_WR_ENABLE); | |
3515 | ||
3516 | if (tg3_flag(tp, NVRAM_BUFFERED) || !tg3_flag(tp, FLASH)) { | |
3517 | ret = tg3_nvram_write_block_buffered(tp, offset, len, | |
3518 | buf); | |
3519 | } else { | |
3520 | ret = tg3_nvram_write_block_unbuffered(tp, offset, len, | |
3521 | buf); | |
3522 | } | |
3523 | ||
3524 | grc_mode = tr32(GRC_MODE); | |
3525 | tw32(GRC_MODE, grc_mode & ~GRC_MODE_NVRAM_WR_ENABLE); | |
3526 | ||
3527 | tg3_disable_nvram_access(tp); | |
3528 | tg3_nvram_unlock(tp); | |
3529 | } | |
3530 | ||
3531 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) { | |
3532 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); | |
3533 | udelay(40); | |
3534 | } | |
3535 | ||
3536 | return ret; | |
3537 | } | |
3538 | ||
997b4f13 MC |
3539 | #define RX_CPU_SCRATCH_BASE 0x30000 |
3540 | #define RX_CPU_SCRATCH_SIZE 0x04000 | |
3541 | #define TX_CPU_SCRATCH_BASE 0x34000 | |
3542 | #define TX_CPU_SCRATCH_SIZE 0x04000 | |
3543 | ||
3544 | /* tp->lock is held. */ | |
837c45bb | 3545 | static int tg3_pause_cpu(struct tg3 *tp, u32 cpu_base) |
997b4f13 MC |
3546 | { |
3547 | int i; | |
837c45bb | 3548 | const int iters = 10000; |
997b4f13 | 3549 | |
837c45bb NS |
3550 | for (i = 0; i < iters; i++) { |
3551 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
3552 | tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); | |
3553 | if (tr32(cpu_base + CPU_MODE) & CPU_MODE_HALT) | |
3554 | break; | |
6d446ec3 GS |
3555 | if (pci_channel_offline(tp->pdev)) |
3556 | return -EBUSY; | |
837c45bb NS |
3557 | } |
3558 | ||
3559 | return (i == iters) ? -EBUSY : 0; | |
3560 | } | |
3561 | ||
3562 | /* tp->lock is held. */ | |
3563 | static int tg3_rxcpu_pause(struct tg3 *tp) | |
3564 | { | |
3565 | int rc = tg3_pause_cpu(tp, RX_CPU_BASE); | |
3566 | ||
3567 | tw32(RX_CPU_BASE + CPU_STATE, 0xffffffff); | |
3568 | tw32_f(RX_CPU_BASE + CPU_MODE, CPU_MODE_HALT); | |
3569 | udelay(10); | |
3570 | ||
3571 | return rc; | |
3572 | } | |
3573 | ||
3574 | /* tp->lock is held. */ | |
3575 | static int tg3_txcpu_pause(struct tg3 *tp) | |
3576 | { | |
3577 | return tg3_pause_cpu(tp, TX_CPU_BASE); | |
3578 | } | |
3579 | ||
3580 | /* tp->lock is held. */ | |
3581 | static void tg3_resume_cpu(struct tg3 *tp, u32 cpu_base) | |
3582 | { | |
3583 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
3584 | tw32_f(cpu_base + CPU_MODE, 0x00000000); | |
3585 | } | |
3586 | ||
3587 | /* tp->lock is held. */ | |
3588 | static void tg3_rxcpu_resume(struct tg3 *tp) | |
3589 | { | |
3590 | tg3_resume_cpu(tp, RX_CPU_BASE); | |
3591 | } | |
3592 | ||
3593 | /* tp->lock is held. */ | |
3594 | static int tg3_halt_cpu(struct tg3 *tp, u32 cpu_base) | |
3595 | { | |
3596 | int rc; | |
3597 | ||
3598 | BUG_ON(cpu_base == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)); | |
997b4f13 | 3599 | |
4153577a | 3600 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
997b4f13 MC |
3601 | u32 val = tr32(GRC_VCPU_EXT_CTRL); |
3602 | ||
3603 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_HALT_CPU); | |
3604 | return 0; | |
3605 | } | |
837c45bb NS |
3606 | if (cpu_base == RX_CPU_BASE) { |
3607 | rc = tg3_rxcpu_pause(tp); | |
997b4f13 | 3608 | } else { |
7e6c63f0 HM |
3609 | /* |
3610 | * There is only an Rx CPU for the 5750 derivative in the | |
3611 | * BCM4785. | |
3612 | */ | |
3613 | if (tg3_flag(tp, IS_SSB_CORE)) | |
3614 | return 0; | |
3615 | ||
837c45bb | 3616 | rc = tg3_txcpu_pause(tp); |
997b4f13 MC |
3617 | } |
3618 | ||
837c45bb | 3619 | if (rc) { |
997b4f13 | 3620 | netdev_err(tp->dev, "%s timed out, %s CPU\n", |
837c45bb | 3621 | __func__, cpu_base == RX_CPU_BASE ? "RX" : "TX"); |
997b4f13 MC |
3622 | return -ENODEV; |
3623 | } | |
3624 | ||
3625 | /* Clear firmware's nvram arbitration. */ | |
3626 | if (tg3_flag(tp, NVRAM)) | |
3627 | tw32(NVRAM_SWARB, SWARB_REQ_CLR0); | |
3628 | return 0; | |
3629 | } | |
3630 | ||
31f11a95 NS |
3631 | static int tg3_fw_data_len(struct tg3 *tp, |
3632 | const struct tg3_firmware_hdr *fw_hdr) | |
3633 | { | |
3634 | int fw_len; | |
3635 | ||
3636 | /* Non fragmented firmware have one firmware header followed by a | |
3637 | * contiguous chunk of data to be written. The length field in that | |
3638 | * header is not the length of data to be written but the complete | |
3639 | * length of the bss. The data length is determined based on | |
3640 | * tp->fw->size minus headers. | |
3641 | * | |
3642 | * Fragmented firmware have a main header followed by multiple | |
3643 | * fragments. Each fragment is identical to non fragmented firmware | |
3644 | * with a firmware header followed by a contiguous chunk of data. In | |
3645 | * the main header, the length field is unused and set to 0xffffffff. | |
3646 | * In each fragment header the length is the entire size of that | |
3647 | * fragment i.e. fragment data + header length. Data length is | |
3648 | * therefore length field in the header minus TG3_FW_HDR_LEN. | |
3649 | */ | |
3650 | if (tp->fw_len == 0xffffffff) | |
3651 | fw_len = be32_to_cpu(fw_hdr->len); | |
3652 | else | |
3653 | fw_len = tp->fw->size; | |
3654 | ||
3655 | return (fw_len - TG3_FW_HDR_LEN) / sizeof(u32); | |
3656 | } | |
3657 | ||
997b4f13 MC |
3658 | /* tp->lock is held. */ |
3659 | static int tg3_load_firmware_cpu(struct tg3 *tp, u32 cpu_base, | |
3660 | u32 cpu_scratch_base, int cpu_scratch_size, | |
77997ea3 | 3661 | const struct tg3_firmware_hdr *fw_hdr) |
997b4f13 | 3662 | { |
c4dab506 | 3663 | int err, i; |
997b4f13 | 3664 | void (*write_op)(struct tg3 *, u32, u32); |
31f11a95 | 3665 | int total_len = tp->fw->size; |
997b4f13 MC |
3666 | |
3667 | if (cpu_base == TX_CPU_BASE && tg3_flag(tp, 5705_PLUS)) { | |
3668 | netdev_err(tp->dev, | |
3669 | "%s: Trying to load TX cpu firmware which is 5705\n", | |
3670 | __func__); | |
3671 | return -EINVAL; | |
3672 | } | |
3673 | ||
c4dab506 | 3674 | if (tg3_flag(tp, 5705_PLUS) && tg3_asic_rev(tp) != ASIC_REV_57766) |
997b4f13 MC |
3675 | write_op = tg3_write_mem; |
3676 | else | |
3677 | write_op = tg3_write_indirect_reg32; | |
3678 | ||
c4dab506 NS |
3679 | if (tg3_asic_rev(tp) != ASIC_REV_57766) { |
3680 | /* It is possible that bootcode is still loading at this point. | |
3681 | * Get the nvram lock first before halting the cpu. | |
3682 | */ | |
3683 | int lock_err = tg3_nvram_lock(tp); | |
3684 | err = tg3_halt_cpu(tp, cpu_base); | |
3685 | if (!lock_err) | |
3686 | tg3_nvram_unlock(tp); | |
3687 | if (err) | |
3688 | goto out; | |
997b4f13 | 3689 | |
c4dab506 NS |
3690 | for (i = 0; i < cpu_scratch_size; i += sizeof(u32)) |
3691 | write_op(tp, cpu_scratch_base + i, 0); | |
3692 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
3693 | tw32(cpu_base + CPU_MODE, | |
3694 | tr32(cpu_base + CPU_MODE) | CPU_MODE_HALT); | |
3695 | } else { | |
3696 | /* Subtract additional main header for fragmented firmware and | |
3697 | * advance to the first fragment | |
3698 | */ | |
3699 | total_len -= TG3_FW_HDR_LEN; | |
3700 | fw_hdr++; | |
3701 | } | |
77997ea3 | 3702 | |
31f11a95 NS |
3703 | do { |
3704 | u32 *fw_data = (u32 *)(fw_hdr + 1); | |
3705 | for (i = 0; i < tg3_fw_data_len(tp, fw_hdr); i++) | |
3706 | write_op(tp, cpu_scratch_base + | |
3707 | (be32_to_cpu(fw_hdr->base_addr) & 0xffff) + | |
3708 | (i * sizeof(u32)), | |
3709 | be32_to_cpu(fw_data[i])); | |
3710 | ||
3711 | total_len -= be32_to_cpu(fw_hdr->len); | |
3712 | ||
3713 | /* Advance to next fragment */ | |
3714 | fw_hdr = (struct tg3_firmware_hdr *) | |
3715 | ((void *)fw_hdr + be32_to_cpu(fw_hdr->len)); | |
3716 | } while (total_len > 0); | |
997b4f13 MC |
3717 | |
3718 | err = 0; | |
3719 | ||
3720 | out: | |
3721 | return err; | |
3722 | } | |
3723 | ||
f4bffb28 NS |
3724 | /* tp->lock is held. */ |
3725 | static int tg3_pause_cpu_and_set_pc(struct tg3 *tp, u32 cpu_base, u32 pc) | |
3726 | { | |
3727 | int i; | |
3728 | const int iters = 5; | |
3729 | ||
3730 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
3731 | tw32_f(cpu_base + CPU_PC, pc); | |
3732 | ||
3733 | for (i = 0; i < iters; i++) { | |
3734 | if (tr32(cpu_base + CPU_PC) == pc) | |
3735 | break; | |
3736 | tw32(cpu_base + CPU_STATE, 0xffffffff); | |
3737 | tw32(cpu_base + CPU_MODE, CPU_MODE_HALT); | |
3738 | tw32_f(cpu_base + CPU_PC, pc); | |
3739 | udelay(1000); | |
3740 | } | |
3741 | ||
3742 | return (i == iters) ? -EBUSY : 0; | |
3743 | } | |
3744 | ||
997b4f13 MC |
3745 | /* tp->lock is held. */ |
3746 | static int tg3_load_5701_a0_firmware_fix(struct tg3 *tp) | |
3747 | { | |
77997ea3 | 3748 | const struct tg3_firmware_hdr *fw_hdr; |
f4bffb28 | 3749 | int err; |
997b4f13 | 3750 | |
77997ea3 | 3751 | fw_hdr = (struct tg3_firmware_hdr *)tp->fw->data; |
997b4f13 MC |
3752 | |
3753 | /* Firmware blob starts with version numbers, followed by | |
3754 | start address and length. We are setting complete length. | |
3755 | length = end_address_of_bss - start_address_of_text. | |
3756 | Remainder is the blob to be loaded contiguously | |
3757 | from start address. */ | |
3758 | ||
997b4f13 MC |
3759 | err = tg3_load_firmware_cpu(tp, RX_CPU_BASE, |
3760 | RX_CPU_SCRATCH_BASE, RX_CPU_SCRATCH_SIZE, | |
77997ea3 | 3761 | fw_hdr); |
997b4f13 MC |
3762 | if (err) |
3763 | return err; | |
3764 | ||
3765 | err = tg3_load_firmware_cpu(tp, TX_CPU_BASE, | |
3766 | TX_CPU_SCRATCH_BASE, TX_CPU_SCRATCH_SIZE, | |
77997ea3 | 3767 | fw_hdr); |
997b4f13 MC |
3768 | if (err) |
3769 | return err; | |
3770 | ||
3771 | /* Now startup only the RX cpu. */ | |
77997ea3 NS |
3772 | err = tg3_pause_cpu_and_set_pc(tp, RX_CPU_BASE, |
3773 | be32_to_cpu(fw_hdr->base_addr)); | |
f4bffb28 | 3774 | if (err) { |
997b4f13 MC |
3775 | netdev_err(tp->dev, "%s fails to set RX CPU PC, is %08x " |
3776 | "should be %08x\n", __func__, | |
77997ea3 NS |
3777 | tr32(RX_CPU_BASE + CPU_PC), |
3778 | be32_to_cpu(fw_hdr->base_addr)); | |
997b4f13 MC |
3779 | return -ENODEV; |
3780 | } | |
837c45bb NS |
3781 | |
3782 | tg3_rxcpu_resume(tp); | |
997b4f13 MC |
3783 | |
3784 | return 0; | |
3785 | } | |
3786 | ||
c4dab506 NS |
3787 | static int tg3_validate_rxcpu_state(struct tg3 *tp) |
3788 | { | |
3789 | const int iters = 1000; | |
3790 | int i; | |
3791 | u32 val; | |
3792 | ||
3793 | /* Wait for boot code to complete initialization and enter service | |
3794 | * loop. It is then safe to download service patches | |
3795 | */ | |
3796 | for (i = 0; i < iters; i++) { | |
3797 | if (tr32(RX_CPU_HWBKPT) == TG3_SBROM_IN_SERVICE_LOOP) | |
3798 | break; | |
3799 | ||
3800 | udelay(10); | |
3801 | } | |
3802 | ||
3803 | if (i == iters) { | |
3804 | netdev_err(tp->dev, "Boot code not ready for service patches\n"); | |
3805 | return -EBUSY; | |
3806 | } | |
3807 | ||
3808 | val = tg3_read_indirect_reg32(tp, TG3_57766_FW_HANDSHAKE); | |
3809 | if (val & 0xff) { | |
3810 | netdev_warn(tp->dev, | |
3811 | "Other patches exist. Not downloading EEE patch\n"); | |
3812 | return -EEXIST; | |
3813 | } | |
3814 | ||
3815 | return 0; | |
3816 | } | |
3817 | ||
3818 | /* tp->lock is held. */ | |
3819 | static void tg3_load_57766_firmware(struct tg3 *tp) | |
3820 | { | |
3821 | struct tg3_firmware_hdr *fw_hdr; | |
3822 | ||
3823 | if (!tg3_flag(tp, NO_NVRAM)) | |
3824 | return; | |
3825 | ||
3826 | if (tg3_validate_rxcpu_state(tp)) | |
3827 | return; | |
3828 | ||
3829 | if (!tp->fw) | |
3830 | return; | |
3831 | ||
3832 | /* This firmware blob has a different format than older firmware | |
3833 | * releases as given below. The main difference is we have fragmented | |
3834 | * data to be written to non-contiguous locations. | |
3835 | * | |
3836 | * In the beginning we have a firmware header identical to other | |
3837 | * firmware which consists of version, base addr and length. The length | |
3838 | * here is unused and set to 0xffffffff. | |
3839 | * | |
3840 | * This is followed by a series of firmware fragments which are | |
3841 | * individually identical to previous firmware. i.e. they have the | |
3842 | * firmware header and followed by data for that fragment. The version | |
3843 | * field of the individual fragment header is unused. | |
3844 | */ | |
3845 | ||
3846 | fw_hdr = (struct tg3_firmware_hdr *)tp->fw->data; | |
3847 | if (be32_to_cpu(fw_hdr->base_addr) != TG3_57766_FW_BASE_ADDR) | |
3848 | return; | |
3849 | ||
3850 | if (tg3_rxcpu_pause(tp)) | |
3851 | return; | |
3852 | ||
3853 | /* tg3_load_firmware_cpu() will always succeed for the 57766 */ | |
3854 | tg3_load_firmware_cpu(tp, 0, TG3_57766_FW_BASE_ADDR, 0, fw_hdr); | |
3855 | ||
3856 | tg3_rxcpu_resume(tp); | |
3857 | } | |
3858 | ||
997b4f13 MC |
3859 | /* tp->lock is held. */ |
3860 | static int tg3_load_tso_firmware(struct tg3 *tp) | |
3861 | { | |
77997ea3 | 3862 | const struct tg3_firmware_hdr *fw_hdr; |
997b4f13 | 3863 | unsigned long cpu_base, cpu_scratch_base, cpu_scratch_size; |
f4bffb28 | 3864 | int err; |
997b4f13 | 3865 | |
1caf13eb | 3866 | if (!tg3_flag(tp, FW_TSO)) |
997b4f13 MC |
3867 | return 0; |
3868 | ||
77997ea3 | 3869 | fw_hdr = (struct tg3_firmware_hdr *)tp->fw->data; |
997b4f13 MC |
3870 | |
3871 | /* Firmware blob starts with version numbers, followed by | |
3872 | start address and length. We are setting complete length. | |
3873 | length = end_address_of_bss - start_address_of_text. | |
3874 | Remainder is the blob to be loaded contiguously | |
3875 | from start address. */ | |
3876 | ||
997b4f13 | 3877 | cpu_scratch_size = tp->fw_len; |
997b4f13 | 3878 | |
4153577a | 3879 | if (tg3_asic_rev(tp) == ASIC_REV_5705) { |
997b4f13 MC |
3880 | cpu_base = RX_CPU_BASE; |
3881 | cpu_scratch_base = NIC_SRAM_MBUF_POOL_BASE5705; | |
3882 | } else { | |
3883 | cpu_base = TX_CPU_BASE; | |
3884 | cpu_scratch_base = TX_CPU_SCRATCH_BASE; | |
3885 | cpu_scratch_size = TX_CPU_SCRATCH_SIZE; | |
3886 | } | |
3887 | ||
3888 | err = tg3_load_firmware_cpu(tp, cpu_base, | |
3889 | cpu_scratch_base, cpu_scratch_size, | |
77997ea3 | 3890 | fw_hdr); |
997b4f13 MC |
3891 | if (err) |
3892 | return err; | |
3893 | ||
3894 | /* Now startup the cpu. */ | |
77997ea3 NS |
3895 | err = tg3_pause_cpu_and_set_pc(tp, cpu_base, |
3896 | be32_to_cpu(fw_hdr->base_addr)); | |
f4bffb28 | 3897 | if (err) { |
997b4f13 MC |
3898 | netdev_err(tp->dev, |
3899 | "%s fails to set CPU PC, is %08x should be %08x\n", | |
77997ea3 NS |
3900 | __func__, tr32(cpu_base + CPU_PC), |
3901 | be32_to_cpu(fw_hdr->base_addr)); | |
997b4f13 MC |
3902 | return -ENODEV; |
3903 | } | |
837c45bb NS |
3904 | |
3905 | tg3_resume_cpu(tp, cpu_base); | |
997b4f13 MC |
3906 | return 0; |
3907 | } | |
3908 | ||
3909 | ||
3f007891 | 3910 | /* tp->lock is held. */ |
953c96e0 | 3911 | static void __tg3_set_mac_addr(struct tg3 *tp, bool skip_mac_1) |
3f007891 MC |
3912 | { |
3913 | u32 addr_high, addr_low; | |
3914 | int i; | |
3915 | ||
3916 | addr_high = ((tp->dev->dev_addr[0] << 8) | | |
3917 | tp->dev->dev_addr[1]); | |
3918 | addr_low = ((tp->dev->dev_addr[2] << 24) | | |
3919 | (tp->dev->dev_addr[3] << 16) | | |
3920 | (tp->dev->dev_addr[4] << 8) | | |
3921 | (tp->dev->dev_addr[5] << 0)); | |
3922 | for (i = 0; i < 4; i++) { | |
3923 | if (i == 1 && skip_mac_1) | |
3924 | continue; | |
3925 | tw32(MAC_ADDR_0_HIGH + (i * 8), addr_high); | |
3926 | tw32(MAC_ADDR_0_LOW + (i * 8), addr_low); | |
3927 | } | |
3928 | ||
4153577a JP |
3929 | if (tg3_asic_rev(tp) == ASIC_REV_5703 || |
3930 | tg3_asic_rev(tp) == ASIC_REV_5704) { | |
3f007891 MC |
3931 | for (i = 0; i < 12; i++) { |
3932 | tw32(MAC_EXTADDR_0_HIGH + (i * 8), addr_high); | |
3933 | tw32(MAC_EXTADDR_0_LOW + (i * 8), addr_low); | |
3934 | } | |
3935 | } | |
3936 | ||
3937 | addr_high = (tp->dev->dev_addr[0] + | |
3938 | tp->dev->dev_addr[1] + | |
3939 | tp->dev->dev_addr[2] + | |
3940 | tp->dev->dev_addr[3] + | |
3941 | tp->dev->dev_addr[4] + | |
3942 | tp->dev->dev_addr[5]) & | |
3943 | TX_BACKOFF_SEED_MASK; | |
3944 | tw32(MAC_TX_BACKOFF_SEED, addr_high); | |
3945 | } | |
3946 | ||
c866b7ea | 3947 | static void tg3_enable_register_access(struct tg3 *tp) |
1da177e4 | 3948 | { |
c866b7ea RW |
3949 | /* |
3950 | * Make sure register accesses (indirect or otherwise) will function | |
3951 | * correctly. | |
1da177e4 LT |
3952 | */ |
3953 | pci_write_config_dword(tp->pdev, | |
c866b7ea RW |
3954 | TG3PCI_MISC_HOST_CTRL, tp->misc_host_ctrl); |
3955 | } | |
1da177e4 | 3956 | |
c866b7ea RW |
3957 | static int tg3_power_up(struct tg3 *tp) |
3958 | { | |
bed9829f | 3959 | int err; |
8c6bda1a | 3960 | |
bed9829f | 3961 | tg3_enable_register_access(tp); |
1da177e4 | 3962 | |
bed9829f MC |
3963 | err = pci_set_power_state(tp->pdev, PCI_D0); |
3964 | if (!err) { | |
3965 | /* Switch out of Vaux if it is a NIC */ | |
3966 | tg3_pwrsrc_switch_to_vmain(tp); | |
3967 | } else { | |
3968 | netdev_err(tp->dev, "Transition to D0 failed\n"); | |
3969 | } | |
1da177e4 | 3970 | |
bed9829f | 3971 | return err; |
c866b7ea | 3972 | } |
1da177e4 | 3973 | |
953c96e0 | 3974 | static int tg3_setup_phy(struct tg3 *, bool); |
4b409522 | 3975 | |
c866b7ea RW |
3976 | static int tg3_power_down_prepare(struct tg3 *tp) |
3977 | { | |
3978 | u32 misc_host_ctrl; | |
3979 | bool device_should_wake, do_low_power; | |
3980 | ||
3981 | tg3_enable_register_access(tp); | |
5e7dfd0f MC |
3982 | |
3983 | /* Restore the CLKREQ setting. */ | |
0f49bfbd JL |
3984 | if (tg3_flag(tp, CLKREQ_BUG)) |
3985 | pcie_capability_set_word(tp->pdev, PCI_EXP_LNKCTL, | |
3986 | PCI_EXP_LNKCTL_CLKREQ_EN); | |
5e7dfd0f | 3987 | |
1da177e4 LT |
3988 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
3989 | tw32(TG3PCI_MISC_HOST_CTRL, | |
3990 | misc_host_ctrl | MISC_HOST_CTRL_MASK_PCI_INT); | |
3991 | ||
c866b7ea | 3992 | device_should_wake = device_may_wakeup(&tp->pdev->dev) && |
63c3a66f | 3993 | tg3_flag(tp, WOL_ENABLE); |
05ac4cb7 | 3994 | |
63c3a66f | 3995 | if (tg3_flag(tp, USE_PHYLIB)) { |
0a459aac | 3996 | do_low_power = false; |
f07e9af3 | 3997 | if ((tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) && |
80096068 | 3998 | !(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
b02fd9e3 | 3999 | struct phy_device *phydev; |
0a459aac | 4000 | u32 phyid, advertising; |
b02fd9e3 | 4001 | |
3f0e3ad7 | 4002 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
b02fd9e3 | 4003 | |
80096068 | 4004 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
b02fd9e3 | 4005 | |
c6700ce2 MC |
4006 | tp->link_config.speed = phydev->speed; |
4007 | tp->link_config.duplex = phydev->duplex; | |
4008 | tp->link_config.autoneg = phydev->autoneg; | |
4009 | tp->link_config.advertising = phydev->advertising; | |
b02fd9e3 MC |
4010 | |
4011 | advertising = ADVERTISED_TP | | |
4012 | ADVERTISED_Pause | | |
4013 | ADVERTISED_Autoneg | | |
4014 | ADVERTISED_10baseT_Half; | |
4015 | ||
63c3a66f JP |
4016 | if (tg3_flag(tp, ENABLE_ASF) || device_should_wake) { |
4017 | if (tg3_flag(tp, WOL_SPEED_100MB)) | |
b02fd9e3 MC |
4018 | advertising |= |
4019 | ADVERTISED_100baseT_Half | | |
4020 | ADVERTISED_100baseT_Full | | |
4021 | ADVERTISED_10baseT_Full; | |
4022 | else | |
4023 | advertising |= ADVERTISED_10baseT_Full; | |
4024 | } | |
4025 | ||
4026 | phydev->advertising = advertising; | |
4027 | ||
4028 | phy_start_aneg(phydev); | |
0a459aac MC |
4029 | |
4030 | phyid = phydev->drv->phy_id & phydev->drv->phy_id_mask; | |
6a443a0f MC |
4031 | if (phyid != PHY_ID_BCMAC131) { |
4032 | phyid &= PHY_BCM_OUI_MASK; | |
4033 | if (phyid == PHY_BCM_OUI_1 || | |
4034 | phyid == PHY_BCM_OUI_2 || | |
4035 | phyid == PHY_BCM_OUI_3) | |
0a459aac MC |
4036 | do_low_power = true; |
4037 | } | |
b02fd9e3 | 4038 | } |
dd477003 | 4039 | } else { |
2023276e | 4040 | do_low_power = true; |
0a459aac | 4041 | |
c6700ce2 | 4042 | if (!(tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) |
80096068 | 4043 | tp->phy_flags |= TG3_PHYFLG_IS_LOW_POWER; |
1da177e4 | 4044 | |
2855b9fe | 4045 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
953c96e0 | 4046 | tg3_setup_phy(tp, false); |
1da177e4 LT |
4047 | } |
4048 | ||
4153577a | 4049 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
b5d3772c MC |
4050 | u32 val; |
4051 | ||
4052 | val = tr32(GRC_VCPU_EXT_CTRL); | |
4053 | tw32(GRC_VCPU_EXT_CTRL, val | GRC_VCPU_EXT_CTRL_DISABLE_WOL); | |
63c3a66f | 4054 | } else if (!tg3_flag(tp, ENABLE_ASF)) { |
6921d201 MC |
4055 | int i; |
4056 | u32 val; | |
4057 | ||
4058 | for (i = 0; i < 200; i++) { | |
4059 | tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val); | |
4060 | if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1) | |
4061 | break; | |
4062 | msleep(1); | |
4063 | } | |
4064 | } | |
63c3a66f | 4065 | if (tg3_flag(tp, WOL_CAP)) |
a85feb8c GZ |
4066 | tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE | |
4067 | WOL_DRV_STATE_SHUTDOWN | | |
4068 | WOL_DRV_WOL | | |
4069 | WOL_SET_MAGIC_PKT); | |
6921d201 | 4070 | |
05ac4cb7 | 4071 | if (device_should_wake) { |
1da177e4 LT |
4072 | u32 mac_mode; |
4073 | ||
f07e9af3 | 4074 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
b4bd2929 MC |
4075 | if (do_low_power && |
4076 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { | |
4077 | tg3_phy_auxctl_write(tp, | |
4078 | MII_TG3_AUXCTL_SHDWSEL_PWRCTL, | |
4079 | MII_TG3_AUXCTL_PCTL_WOL_EN | | |
4080 | MII_TG3_AUXCTL_PCTL_100TX_LPWR | | |
4081 | MII_TG3_AUXCTL_PCTL_CL_AB_TXDAC); | |
dd477003 MC |
4082 | udelay(40); |
4083 | } | |
1da177e4 | 4084 | |
f07e9af3 | 4085 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
3f7045c1 | 4086 | mac_mode = MAC_MODE_PORT_MODE_GMII; |
942d1af0 NS |
4087 | else if (tp->phy_flags & |
4088 | TG3_PHYFLG_KEEP_LINK_ON_PWRDN) { | |
4089 | if (tp->link_config.active_speed == SPEED_1000) | |
4090 | mac_mode = MAC_MODE_PORT_MODE_GMII; | |
4091 | else | |
4092 | mac_mode = MAC_MODE_PORT_MODE_MII; | |
4093 | } else | |
3f7045c1 | 4094 | mac_mode = MAC_MODE_PORT_MODE_MII; |
1da177e4 | 4095 | |
e8f3f6ca | 4096 | mac_mode |= tp->mac_mode & MAC_MODE_LINK_POLARITY; |
4153577a | 4097 | if (tg3_asic_rev(tp) == ASIC_REV_5700) { |
63c3a66f | 4098 | u32 speed = tg3_flag(tp, WOL_SPEED_100MB) ? |
e8f3f6ca MC |
4099 | SPEED_100 : SPEED_10; |
4100 | if (tg3_5700_link_polarity(tp, speed)) | |
4101 | mac_mode |= MAC_MODE_LINK_POLARITY; | |
4102 | else | |
4103 | mac_mode &= ~MAC_MODE_LINK_POLARITY; | |
4104 | } | |
1da177e4 LT |
4105 | } else { |
4106 | mac_mode = MAC_MODE_PORT_MODE_TBI; | |
4107 | } | |
4108 | ||
63c3a66f | 4109 | if (!tg3_flag(tp, 5750_PLUS)) |
1da177e4 LT |
4110 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
4111 | ||
05ac4cb7 | 4112 | mac_mode |= MAC_MODE_MAGIC_PKT_ENABLE; |
63c3a66f JP |
4113 | if ((tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) && |
4114 | (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE))) | |
05ac4cb7 | 4115 | mac_mode |= MAC_MODE_KEEP_FRAME_IN_WOL; |
1da177e4 | 4116 | |
63c3a66f | 4117 | if (tg3_flag(tp, ENABLE_APE)) |
d2394e6b MC |
4118 | mac_mode |= MAC_MODE_APE_TX_EN | |
4119 | MAC_MODE_APE_RX_EN | | |
4120 | MAC_MODE_TDE_ENABLE; | |
3bda1258 | 4121 | |
1da177e4 LT |
4122 | tw32_f(MAC_MODE, mac_mode); |
4123 | udelay(100); | |
4124 | ||
4125 | tw32_f(MAC_RX_MODE, RX_MODE_ENABLE); | |
4126 | udelay(10); | |
4127 | } | |
4128 | ||
63c3a66f | 4129 | if (!tg3_flag(tp, WOL_SPEED_100MB) && |
4153577a JP |
4130 | (tg3_asic_rev(tp) == ASIC_REV_5700 || |
4131 | tg3_asic_rev(tp) == ASIC_REV_5701)) { | |
1da177e4 LT |
4132 | u32 base_val; |
4133 | ||
4134 | base_val = tp->pci_clock_ctrl; | |
4135 | base_val |= (CLOCK_CTRL_RXCLK_DISABLE | | |
4136 | CLOCK_CTRL_TXCLK_DISABLE); | |
4137 | ||
b401e9e2 MC |
4138 | tw32_wait_f(TG3PCI_CLOCK_CTRL, base_val | CLOCK_CTRL_ALTCLK | |
4139 | CLOCK_CTRL_PWRDOWN_PLL133, 40); | |
63c3a66f JP |
4140 | } else if (tg3_flag(tp, 5780_CLASS) || |
4141 | tg3_flag(tp, CPMU_PRESENT) || | |
4153577a | 4142 | tg3_asic_rev(tp) == ASIC_REV_5906) { |
4cf78e4f | 4143 | /* do nothing */ |
63c3a66f | 4144 | } else if (!(tg3_flag(tp, 5750_PLUS) && tg3_flag(tp, ENABLE_ASF))) { |
1da177e4 LT |
4145 | u32 newbits1, newbits2; |
4146 | ||
4153577a JP |
4147 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
4148 | tg3_asic_rev(tp) == ASIC_REV_5701) { | |
1da177e4 LT |
4149 | newbits1 = (CLOCK_CTRL_RXCLK_DISABLE | |
4150 | CLOCK_CTRL_TXCLK_DISABLE | | |
4151 | CLOCK_CTRL_ALTCLK); | |
4152 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; | |
63c3a66f | 4153 | } else if (tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
4154 | newbits1 = CLOCK_CTRL_625_CORE; |
4155 | newbits2 = newbits1 | CLOCK_CTRL_ALTCLK; | |
4156 | } else { | |
4157 | newbits1 = CLOCK_CTRL_ALTCLK; | |
4158 | newbits2 = newbits1 | CLOCK_CTRL_44MHZ_CORE; | |
4159 | } | |
4160 | ||
b401e9e2 MC |
4161 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits1, |
4162 | 40); | |
1da177e4 | 4163 | |
b401e9e2 MC |
4164 | tw32_wait_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl | newbits2, |
4165 | 40); | |
1da177e4 | 4166 | |
63c3a66f | 4167 | if (!tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
4168 | u32 newbits3; |
4169 | ||
4153577a JP |
4170 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
4171 | tg3_asic_rev(tp) == ASIC_REV_5701) { | |
1da177e4 LT |
4172 | newbits3 = (CLOCK_CTRL_RXCLK_DISABLE | |
4173 | CLOCK_CTRL_TXCLK_DISABLE | | |
4174 | CLOCK_CTRL_44MHZ_CORE); | |
4175 | } else { | |
4176 | newbits3 = CLOCK_CTRL_44MHZ_CORE; | |
4177 | } | |
4178 | ||
b401e9e2 MC |
4179 | tw32_wait_f(TG3PCI_CLOCK_CTRL, |
4180 | tp->pci_clock_ctrl | newbits3, 40); | |
1da177e4 LT |
4181 | } |
4182 | } | |
4183 | ||
63c3a66f | 4184 | if (!(device_should_wake) && !tg3_flag(tp, ENABLE_ASF)) |
0a459aac | 4185 | tg3_power_down_phy(tp, do_low_power); |
6921d201 | 4186 | |
cd0d7228 | 4187 | tg3_frob_aux_power(tp, true); |
1da177e4 LT |
4188 | |
4189 | /* Workaround for unstable PLL clock */ | |
7e6c63f0 | 4190 | if ((!tg3_flag(tp, IS_SSB_CORE)) && |
4153577a JP |
4191 | ((tg3_chip_rev(tp) == CHIPREV_5750_AX) || |
4192 | (tg3_chip_rev(tp) == CHIPREV_5750_BX))) { | |
1da177e4 LT |
4193 | u32 val = tr32(0x7d00); |
4194 | ||
4195 | val &= ~((1 << 16) | (1 << 4) | (1 << 2) | (1 << 1) | 1); | |
4196 | tw32(0x7d00, val); | |
63c3a66f | 4197 | if (!tg3_flag(tp, ENABLE_ASF)) { |
ec41c7df MC |
4198 | int err; |
4199 | ||
4200 | err = tg3_nvram_lock(tp); | |
1da177e4 | 4201 | tg3_halt_cpu(tp, RX_CPU_BASE); |
ec41c7df MC |
4202 | if (!err) |
4203 | tg3_nvram_unlock(tp); | |
6921d201 | 4204 | } |
1da177e4 LT |
4205 | } |
4206 | ||
bbadf503 MC |
4207 | tg3_write_sig_post_reset(tp, RESET_KIND_SHUTDOWN); |
4208 | ||
c866b7ea RW |
4209 | return 0; |
4210 | } | |
12dac075 | 4211 | |
c866b7ea RW |
4212 | static void tg3_power_down(struct tg3 *tp) |
4213 | { | |
4214 | tg3_power_down_prepare(tp); | |
1da177e4 | 4215 | |
63c3a66f | 4216 | pci_wake_from_d3(tp->pdev, tg3_flag(tp, WOL_ENABLE)); |
c866b7ea | 4217 | pci_set_power_state(tp->pdev, PCI_D3hot); |
1da177e4 LT |
4218 | } |
4219 | ||
1da177e4 LT |
4220 | static void tg3_aux_stat_to_speed_duplex(struct tg3 *tp, u32 val, u16 *speed, u8 *duplex) |
4221 | { | |
4222 | switch (val & MII_TG3_AUX_STAT_SPDMASK) { | |
4223 | case MII_TG3_AUX_STAT_10HALF: | |
4224 | *speed = SPEED_10; | |
4225 | *duplex = DUPLEX_HALF; | |
4226 | break; | |
4227 | ||
4228 | case MII_TG3_AUX_STAT_10FULL: | |
4229 | *speed = SPEED_10; | |
4230 | *duplex = DUPLEX_FULL; | |
4231 | break; | |
4232 | ||
4233 | case MII_TG3_AUX_STAT_100HALF: | |
4234 | *speed = SPEED_100; | |
4235 | *duplex = DUPLEX_HALF; | |
4236 | break; | |
4237 | ||
4238 | case MII_TG3_AUX_STAT_100FULL: | |
4239 | *speed = SPEED_100; | |
4240 | *duplex = DUPLEX_FULL; | |
4241 | break; | |
4242 | ||
4243 | case MII_TG3_AUX_STAT_1000HALF: | |
4244 | *speed = SPEED_1000; | |
4245 | *duplex = DUPLEX_HALF; | |
4246 | break; | |
4247 | ||
4248 | case MII_TG3_AUX_STAT_1000FULL: | |
4249 | *speed = SPEED_1000; | |
4250 | *duplex = DUPLEX_FULL; | |
4251 | break; | |
4252 | ||
4253 | default: | |
f07e9af3 | 4254 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { |
715116a1 MC |
4255 | *speed = (val & MII_TG3_AUX_STAT_100) ? SPEED_100 : |
4256 | SPEED_10; | |
4257 | *duplex = (val & MII_TG3_AUX_STAT_FULL) ? DUPLEX_FULL : | |
4258 | DUPLEX_HALF; | |
4259 | break; | |
4260 | } | |
e740522e MC |
4261 | *speed = SPEED_UNKNOWN; |
4262 | *duplex = DUPLEX_UNKNOWN; | |
1da177e4 | 4263 | break; |
855e1111 | 4264 | } |
1da177e4 LT |
4265 | } |
4266 | ||
42b64a45 | 4267 | static int tg3_phy_autoneg_cfg(struct tg3 *tp, u32 advertise, u32 flowctrl) |
1da177e4 | 4268 | { |
42b64a45 MC |
4269 | int err = 0; |
4270 | u32 val, new_adv; | |
1da177e4 | 4271 | |
42b64a45 | 4272 | new_adv = ADVERTISE_CSMA; |
202ff1c2 | 4273 | new_adv |= ethtool_adv_to_mii_adv_t(advertise) & ADVERTISE_ALL; |
f88788f0 | 4274 | new_adv |= mii_advertise_flowctrl(flowctrl); |
1da177e4 | 4275 | |
42b64a45 MC |
4276 | err = tg3_writephy(tp, MII_ADVERTISE, new_adv); |
4277 | if (err) | |
4278 | goto done; | |
ba4d07a8 | 4279 | |
4f272096 MC |
4280 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
4281 | new_adv = ethtool_adv_to_mii_ctrl1000_t(advertise); | |
ba4d07a8 | 4282 | |
4153577a JP |
4283 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0 || |
4284 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B0) | |
4f272096 | 4285 | new_adv |= CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER; |
ba4d07a8 | 4286 | |
4f272096 MC |
4287 | err = tg3_writephy(tp, MII_CTRL1000, new_adv); |
4288 | if (err) | |
4289 | goto done; | |
4290 | } | |
1da177e4 | 4291 | |
42b64a45 MC |
4292 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) |
4293 | goto done; | |
52b02d04 | 4294 | |
42b64a45 MC |
4295 | tw32(TG3_CPMU_EEE_MODE, |
4296 | tr32(TG3_CPMU_EEE_MODE) & ~TG3_CPMU_EEEMD_LPI_ENABLE); | |
52b02d04 | 4297 | |
daf3ec68 | 4298 | err = tg3_phy_toggle_auxctl_smdsp(tp, true); |
42b64a45 MC |
4299 | if (!err) { |
4300 | u32 err2; | |
52b02d04 | 4301 | |
b715ce94 MC |
4302 | val = 0; |
4303 | /* Advertise 100-BaseTX EEE ability */ | |
4304 | if (advertise & ADVERTISED_100baseT_Full) | |
4305 | val |= MDIO_AN_EEE_ADV_100TX; | |
4306 | /* Advertise 1000-BaseT EEE ability */ | |
4307 | if (advertise & ADVERTISED_1000baseT_Full) | |
4308 | val |= MDIO_AN_EEE_ADV_1000T; | |
4309 | err = tg3_phy_cl45_write(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV, val); | |
4310 | if (err) | |
4311 | val = 0; | |
4312 | ||
4153577a | 4313 | switch (tg3_asic_rev(tp)) { |
21a00ab2 MC |
4314 | case ASIC_REV_5717: |
4315 | case ASIC_REV_57765: | |
55086ad9 | 4316 | case ASIC_REV_57766: |
21a00ab2 | 4317 | case ASIC_REV_5719: |
b715ce94 MC |
4318 | /* If we advertised any eee advertisements above... */ |
4319 | if (val) | |
4320 | val = MII_TG3_DSP_TAP26_ALNOKO | | |
4321 | MII_TG3_DSP_TAP26_RMRXSTO | | |
4322 | MII_TG3_DSP_TAP26_OPCSINPT; | |
21a00ab2 | 4323 | tg3_phydsp_write(tp, MII_TG3_DSP_TAP26, val); |
be671947 MC |
4324 | /* Fall through */ |
4325 | case ASIC_REV_5720: | |
c65a17f4 | 4326 | case ASIC_REV_5762: |
be671947 MC |
4327 | if (!tg3_phydsp_read(tp, MII_TG3_DSP_CH34TP2, &val)) |
4328 | tg3_phydsp_write(tp, MII_TG3_DSP_CH34TP2, val | | |
4329 | MII_TG3_DSP_CH34TP2_HIBW01); | |
21a00ab2 | 4330 | } |
52b02d04 | 4331 | |
daf3ec68 | 4332 | err2 = tg3_phy_toggle_auxctl_smdsp(tp, false); |
42b64a45 MC |
4333 | if (!err) |
4334 | err = err2; | |
4335 | } | |
4336 | ||
4337 | done: | |
4338 | return err; | |
4339 | } | |
4340 | ||
4341 | static void tg3_phy_copper_begin(struct tg3 *tp) | |
4342 | { | |
d13ba512 MC |
4343 | if (tp->link_config.autoneg == AUTONEG_ENABLE || |
4344 | (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { | |
4345 | u32 adv, fc; | |
4346 | ||
942d1af0 NS |
4347 | if ((tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) && |
4348 | !(tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN)) { | |
d13ba512 MC |
4349 | adv = ADVERTISED_10baseT_Half | |
4350 | ADVERTISED_10baseT_Full; | |
4351 | if (tg3_flag(tp, WOL_SPEED_100MB)) | |
4352 | adv |= ADVERTISED_100baseT_Half | | |
4353 | ADVERTISED_100baseT_Full; | |
942d1af0 NS |
4354 | if (tp->phy_flags & TG3_PHYFLG_1G_ON_VAUX_OK) |
4355 | adv |= ADVERTISED_1000baseT_Half | | |
4356 | ADVERTISED_1000baseT_Full; | |
d13ba512 MC |
4357 | |
4358 | fc = FLOW_CTRL_TX | FLOW_CTRL_RX; | |
42b64a45 | 4359 | } else { |
d13ba512 MC |
4360 | adv = tp->link_config.advertising; |
4361 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) | |
4362 | adv &= ~(ADVERTISED_1000baseT_Half | | |
4363 | ADVERTISED_1000baseT_Full); | |
4364 | ||
4365 | fc = tp->link_config.flowctrl; | |
52b02d04 | 4366 | } |
52b02d04 | 4367 | |
d13ba512 | 4368 | tg3_phy_autoneg_cfg(tp, adv, fc); |
52b02d04 | 4369 | |
942d1af0 NS |
4370 | if ((tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) && |
4371 | (tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN)) { | |
4372 | /* Normally during power down we want to autonegotiate | |
4373 | * the lowest possible speed for WOL. However, to avoid | |
4374 | * link flap, we leave it untouched. | |
4375 | */ | |
4376 | return; | |
4377 | } | |
4378 | ||
d13ba512 MC |
4379 | tg3_writephy(tp, MII_BMCR, |
4380 | BMCR_ANENABLE | BMCR_ANRESTART); | |
4381 | } else { | |
4382 | int i; | |
1da177e4 LT |
4383 | u32 bmcr, orig_bmcr; |
4384 | ||
4385 | tp->link_config.active_speed = tp->link_config.speed; | |
4386 | tp->link_config.active_duplex = tp->link_config.duplex; | |
4387 | ||
7c6cdead NS |
4388 | if (tg3_asic_rev(tp) == ASIC_REV_5714) { |
4389 | /* With autoneg disabled, 5715 only links up when the | |
4390 | * advertisement register has the configured speed | |
4391 | * enabled. | |
4392 | */ | |
4393 | tg3_writephy(tp, MII_ADVERTISE, ADVERTISE_ALL); | |
4394 | } | |
4395 | ||
1da177e4 LT |
4396 | bmcr = 0; |
4397 | switch (tp->link_config.speed) { | |
4398 | default: | |
4399 | case SPEED_10: | |
4400 | break; | |
4401 | ||
4402 | case SPEED_100: | |
4403 | bmcr |= BMCR_SPEED100; | |
4404 | break; | |
4405 | ||
4406 | case SPEED_1000: | |
221c5637 | 4407 | bmcr |= BMCR_SPEED1000; |
1da177e4 | 4408 | break; |
855e1111 | 4409 | } |
1da177e4 LT |
4410 | |
4411 | if (tp->link_config.duplex == DUPLEX_FULL) | |
4412 | bmcr |= BMCR_FULLDPLX; | |
4413 | ||
4414 | if (!tg3_readphy(tp, MII_BMCR, &orig_bmcr) && | |
4415 | (bmcr != orig_bmcr)) { | |
4416 | tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK); | |
4417 | for (i = 0; i < 1500; i++) { | |
4418 | u32 tmp; | |
4419 | ||
4420 | udelay(10); | |
4421 | if (tg3_readphy(tp, MII_BMSR, &tmp) || | |
4422 | tg3_readphy(tp, MII_BMSR, &tmp)) | |
4423 | continue; | |
4424 | if (!(tmp & BMSR_LSTATUS)) { | |
4425 | udelay(40); | |
4426 | break; | |
4427 | } | |
4428 | } | |
4429 | tg3_writephy(tp, MII_BMCR, bmcr); | |
4430 | udelay(40); | |
4431 | } | |
1da177e4 LT |
4432 | } |
4433 | } | |
4434 | ||
fdad8de4 NS |
4435 | static int tg3_phy_pull_config(struct tg3 *tp) |
4436 | { | |
4437 | int err; | |
4438 | u32 val; | |
4439 | ||
4440 | err = tg3_readphy(tp, MII_BMCR, &val); | |
4441 | if (err) | |
4442 | goto done; | |
4443 | ||
4444 | if (!(val & BMCR_ANENABLE)) { | |
4445 | tp->link_config.autoneg = AUTONEG_DISABLE; | |
4446 | tp->link_config.advertising = 0; | |
4447 | tg3_flag_clear(tp, PAUSE_AUTONEG); | |
4448 | ||
4449 | err = -EIO; | |
4450 | ||
4451 | switch (val & (BMCR_SPEED1000 | BMCR_SPEED100)) { | |
4452 | case 0: | |
4453 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) | |
4454 | goto done; | |
4455 | ||
4456 | tp->link_config.speed = SPEED_10; | |
4457 | break; | |
4458 | case BMCR_SPEED100: | |
4459 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) | |
4460 | goto done; | |
4461 | ||
4462 | tp->link_config.speed = SPEED_100; | |
4463 | break; | |
4464 | case BMCR_SPEED1000: | |
4465 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { | |
4466 | tp->link_config.speed = SPEED_1000; | |
4467 | break; | |
4468 | } | |
4469 | /* Fall through */ | |
4470 | default: | |
4471 | goto done; | |
4472 | } | |
4473 | ||
4474 | if (val & BMCR_FULLDPLX) | |
4475 | tp->link_config.duplex = DUPLEX_FULL; | |
4476 | else | |
4477 | tp->link_config.duplex = DUPLEX_HALF; | |
4478 | ||
4479 | tp->link_config.flowctrl = FLOW_CTRL_RX | FLOW_CTRL_TX; | |
4480 | ||
4481 | err = 0; | |
4482 | goto done; | |
4483 | } | |
4484 | ||
4485 | tp->link_config.autoneg = AUTONEG_ENABLE; | |
4486 | tp->link_config.advertising = ADVERTISED_Autoneg; | |
4487 | tg3_flag_set(tp, PAUSE_AUTONEG); | |
4488 | ||
4489 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { | |
4490 | u32 adv; | |
4491 | ||
4492 | err = tg3_readphy(tp, MII_ADVERTISE, &val); | |
4493 | if (err) | |
4494 | goto done; | |
4495 | ||
4496 | adv = mii_adv_to_ethtool_adv_t(val & ADVERTISE_ALL); | |
4497 | tp->link_config.advertising |= adv | ADVERTISED_TP; | |
4498 | ||
4499 | tp->link_config.flowctrl = tg3_decode_flowctrl_1000T(val); | |
4500 | } else { | |
4501 | tp->link_config.advertising |= ADVERTISED_FIBRE; | |
4502 | } | |
4503 | ||
4504 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { | |
4505 | u32 adv; | |
4506 | ||
4507 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { | |
4508 | err = tg3_readphy(tp, MII_CTRL1000, &val); | |
4509 | if (err) | |
4510 | goto done; | |
4511 | ||
4512 | adv = mii_ctrl1000_to_ethtool_adv_t(val); | |
4513 | } else { | |
4514 | err = tg3_readphy(tp, MII_ADVERTISE, &val); | |
4515 | if (err) | |
4516 | goto done; | |
4517 | ||
4518 | adv = tg3_decode_flowctrl_1000X(val); | |
4519 | tp->link_config.flowctrl = adv; | |
4520 | ||
4521 | val &= (ADVERTISE_1000XHALF | ADVERTISE_1000XFULL); | |
4522 | adv = mii_adv_to_ethtool_adv_x(val); | |
4523 | } | |
4524 | ||
4525 | tp->link_config.advertising |= adv; | |
4526 | } | |
4527 | ||
4528 | done: | |
4529 | return err; | |
4530 | } | |
4531 | ||
1da177e4 LT |
4532 | static int tg3_init_5401phy_dsp(struct tg3 *tp) |
4533 | { | |
4534 | int err; | |
4535 | ||
4536 | /* Turn off tap power management. */ | |
4537 | /* Set Extended packet length bit */ | |
b4bd2929 | 4538 | err = tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_AUXCTL, 0x4c20); |
1da177e4 | 4539 | |
6ee7c0a0 MC |
4540 | err |= tg3_phydsp_write(tp, 0x0012, 0x1804); |
4541 | err |= tg3_phydsp_write(tp, 0x0013, 0x1204); | |
4542 | err |= tg3_phydsp_write(tp, 0x8006, 0x0132); | |
4543 | err |= tg3_phydsp_write(tp, 0x8006, 0x0232); | |
4544 | err |= tg3_phydsp_write(tp, 0x201f, 0x0a20); | |
1da177e4 LT |
4545 | |
4546 | udelay(40); | |
4547 | ||
4548 | return err; | |
4549 | } | |
4550 | ||
ed1ff5c3 NS |
4551 | static bool tg3_phy_eee_config_ok(struct tg3 *tp) |
4552 | { | |
4553 | u32 val; | |
4554 | u32 tgtadv = 0; | |
4555 | u32 advertising = tp->link_config.advertising; | |
4556 | ||
4557 | if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) | |
4558 | return true; | |
4559 | ||
4560 | if (tg3_phy_cl45_read(tp, MDIO_MMD_AN, MDIO_AN_EEE_ADV, &val)) | |
4561 | return false; | |
4562 | ||
4563 | val &= (MDIO_AN_EEE_ADV_100TX | MDIO_AN_EEE_ADV_1000T); | |
4564 | ||
4565 | ||
4566 | if (advertising & ADVERTISED_100baseT_Full) | |
4567 | tgtadv |= MDIO_AN_EEE_ADV_100TX; | |
4568 | if (advertising & ADVERTISED_1000baseT_Full) | |
4569 | tgtadv |= MDIO_AN_EEE_ADV_1000T; | |
4570 | ||
4571 | if (val != tgtadv) | |
4572 | return false; | |
4573 | ||
4574 | return true; | |
4575 | } | |
4576 | ||
e2bf73e7 | 4577 | static bool tg3_phy_copper_an_config_ok(struct tg3 *tp, u32 *lcladv) |
1da177e4 | 4578 | { |
e2bf73e7 | 4579 | u32 advmsk, tgtadv, advertising; |
3600d918 | 4580 | |
e2bf73e7 MC |
4581 | advertising = tp->link_config.advertising; |
4582 | tgtadv = ethtool_adv_to_mii_adv_t(advertising) & ADVERTISE_ALL; | |
1da177e4 | 4583 | |
e2bf73e7 MC |
4584 | advmsk = ADVERTISE_ALL; |
4585 | if (tp->link_config.active_duplex == DUPLEX_FULL) { | |
f88788f0 | 4586 | tgtadv |= mii_advertise_flowctrl(tp->link_config.flowctrl); |
e2bf73e7 MC |
4587 | advmsk |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
4588 | } | |
1da177e4 | 4589 | |
e2bf73e7 MC |
4590 | if (tg3_readphy(tp, MII_ADVERTISE, lcladv)) |
4591 | return false; | |
4592 | ||
4593 | if ((*lcladv & advmsk) != tgtadv) | |
4594 | return false; | |
b99d2a57 | 4595 | |
f07e9af3 | 4596 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { |
1da177e4 LT |
4597 | u32 tg3_ctrl; |
4598 | ||
e2bf73e7 | 4599 | tgtadv = ethtool_adv_to_mii_ctrl1000_t(advertising); |
3600d918 | 4600 | |
221c5637 | 4601 | if (tg3_readphy(tp, MII_CTRL1000, &tg3_ctrl)) |
e2bf73e7 | 4602 | return false; |
1da177e4 | 4603 | |
3198e07f | 4604 | if (tgtadv && |
4153577a JP |
4605 | (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0 || |
4606 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B0)) { | |
3198e07f MC |
4607 | tgtadv |= CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER; |
4608 | tg3_ctrl &= (ADVERTISE_1000HALF | ADVERTISE_1000FULL | | |
4609 | CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER); | |
4610 | } else { | |
4611 | tg3_ctrl &= (ADVERTISE_1000HALF | ADVERTISE_1000FULL); | |
4612 | } | |
4613 | ||
e2bf73e7 MC |
4614 | if (tg3_ctrl != tgtadv) |
4615 | return false; | |
ef167e27 MC |
4616 | } |
4617 | ||
e2bf73e7 | 4618 | return true; |
ef167e27 MC |
4619 | } |
4620 | ||
859edb26 MC |
4621 | static bool tg3_phy_copper_fetch_rmtadv(struct tg3 *tp, u32 *rmtadv) |
4622 | { | |
4623 | u32 lpeth = 0; | |
4624 | ||
4625 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) { | |
4626 | u32 val; | |
4627 | ||
4628 | if (tg3_readphy(tp, MII_STAT1000, &val)) | |
4629 | return false; | |
4630 | ||
4631 | lpeth = mii_stat1000_to_ethtool_lpa_t(val); | |
4632 | } | |
4633 | ||
4634 | if (tg3_readphy(tp, MII_LPA, rmtadv)) | |
4635 | return false; | |
4636 | ||
4637 | lpeth |= mii_lpa_to_ethtool_lpa_t(*rmtadv); | |
4638 | tp->link_config.rmt_adv = lpeth; | |
4639 | ||
4640 | return true; | |
4641 | } | |
4642 | ||
953c96e0 | 4643 | static bool tg3_test_and_report_link_chg(struct tg3 *tp, bool curr_link_up) |
f4a46d1f NNS |
4644 | { |
4645 | if (curr_link_up != tp->link_up) { | |
4646 | if (curr_link_up) { | |
84421b99 | 4647 | netif_carrier_on(tp->dev); |
f4a46d1f | 4648 | } else { |
84421b99 | 4649 | netif_carrier_off(tp->dev); |
f4a46d1f NNS |
4650 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
4651 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; | |
4652 | } | |
4653 | ||
4654 | tg3_link_report(tp); | |
4655 | return true; | |
4656 | } | |
4657 | ||
4658 | return false; | |
4659 | } | |
4660 | ||
3310e248 MC |
4661 | static void tg3_clear_mac_status(struct tg3 *tp) |
4662 | { | |
4663 | tw32(MAC_EVENT, 0); | |
4664 | ||
4665 | tw32_f(MAC_STATUS, | |
4666 | MAC_STATUS_SYNC_CHANGED | | |
4667 | MAC_STATUS_CFG_CHANGED | | |
4668 | MAC_STATUS_MI_COMPLETION | | |
4669 | MAC_STATUS_LNKSTATE_CHANGED); | |
4670 | udelay(40); | |
4671 | } | |
4672 | ||
953c96e0 | 4673 | static int tg3_setup_copper_phy(struct tg3 *tp, bool force_reset) |
1da177e4 | 4674 | { |
953c96e0 | 4675 | bool current_link_up; |
f833c4c1 | 4676 | u32 bmsr, val; |
ef167e27 | 4677 | u32 lcl_adv, rmt_adv; |
1da177e4 LT |
4678 | u16 current_speed; |
4679 | u8 current_duplex; | |
4680 | int i, err; | |
4681 | ||
3310e248 | 4682 | tg3_clear_mac_status(tp); |
1da177e4 | 4683 | |
8ef21428 MC |
4684 | if ((tp->mi_mode & MAC_MI_MODE_AUTO_POLL) != 0) { |
4685 | tw32_f(MAC_MI_MODE, | |
4686 | (tp->mi_mode & ~MAC_MI_MODE_AUTO_POLL)); | |
4687 | udelay(80); | |
4688 | } | |
1da177e4 | 4689 | |
b4bd2929 | 4690 | tg3_phy_auxctl_write(tp, MII_TG3_AUXCTL_SHDWSEL_PWRCTL, 0); |
1da177e4 LT |
4691 | |
4692 | /* Some third-party PHYs need to be reset on link going | |
4693 | * down. | |
4694 | */ | |
4153577a JP |
4695 | if ((tg3_asic_rev(tp) == ASIC_REV_5703 || |
4696 | tg3_asic_rev(tp) == ASIC_REV_5704 || | |
4697 | tg3_asic_rev(tp) == ASIC_REV_5705) && | |
f4a46d1f | 4698 | tp->link_up) { |
1da177e4 LT |
4699 | tg3_readphy(tp, MII_BMSR, &bmsr); |
4700 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && | |
4701 | !(bmsr & BMSR_LSTATUS)) | |
953c96e0 | 4702 | force_reset = true; |
1da177e4 LT |
4703 | } |
4704 | if (force_reset) | |
4705 | tg3_phy_reset(tp); | |
4706 | ||
79eb6904 | 4707 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
1da177e4 LT |
4708 | tg3_readphy(tp, MII_BMSR, &bmsr); |
4709 | if (tg3_readphy(tp, MII_BMSR, &bmsr) || | |
63c3a66f | 4710 | !tg3_flag(tp, INIT_COMPLETE)) |
1da177e4 LT |
4711 | bmsr = 0; |
4712 | ||
4713 | if (!(bmsr & BMSR_LSTATUS)) { | |
4714 | err = tg3_init_5401phy_dsp(tp); | |
4715 | if (err) | |
4716 | return err; | |
4717 | ||
4718 | tg3_readphy(tp, MII_BMSR, &bmsr); | |
4719 | for (i = 0; i < 1000; i++) { | |
4720 | udelay(10); | |
4721 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && | |
4722 | (bmsr & BMSR_LSTATUS)) { | |
4723 | udelay(40); | |
4724 | break; | |
4725 | } | |
4726 | } | |
4727 | ||
79eb6904 MC |
4728 | if ((tp->phy_id & TG3_PHY_ID_REV_MASK) == |
4729 | TG3_PHY_REV_BCM5401_B0 && | |
1da177e4 LT |
4730 | !(bmsr & BMSR_LSTATUS) && |
4731 | tp->link_config.active_speed == SPEED_1000) { | |
4732 | err = tg3_phy_reset(tp); | |
4733 | if (!err) | |
4734 | err = tg3_init_5401phy_dsp(tp); | |
4735 | if (err) | |
4736 | return err; | |
4737 | } | |
4738 | } | |
4153577a JP |
4739 | } else if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0 || |
4740 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B0) { | |
1da177e4 LT |
4741 | /* 5701 {A0,B0} CRC bug workaround */ |
4742 | tg3_writephy(tp, 0x15, 0x0a75); | |
f08aa1a8 MC |
4743 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); |
4744 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8d68); | |
4745 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x8c68); | |
1da177e4 LT |
4746 | } |
4747 | ||
4748 | /* Clear pending interrupts... */ | |
f833c4c1 MC |
4749 | tg3_readphy(tp, MII_TG3_ISTAT, &val); |
4750 | tg3_readphy(tp, MII_TG3_ISTAT, &val); | |
1da177e4 | 4751 | |
f07e9af3 | 4752 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) |
1da177e4 | 4753 | tg3_writephy(tp, MII_TG3_IMASK, ~MII_TG3_INT_LINKCHG); |
f07e9af3 | 4754 | else if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) |
1da177e4 LT |
4755 | tg3_writephy(tp, MII_TG3_IMASK, ~0); |
4756 | ||
4153577a JP |
4757 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
4758 | tg3_asic_rev(tp) == ASIC_REV_5701) { | |
1da177e4 LT |
4759 | if (tp->led_ctrl == LED_CTRL_MODE_PHY_1) |
4760 | tg3_writephy(tp, MII_TG3_EXT_CTRL, | |
4761 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); | |
4762 | else | |
4763 | tg3_writephy(tp, MII_TG3_EXT_CTRL, 0); | |
4764 | } | |
4765 | ||
953c96e0 | 4766 | current_link_up = false; |
e740522e MC |
4767 | current_speed = SPEED_UNKNOWN; |
4768 | current_duplex = DUPLEX_UNKNOWN; | |
e348c5e7 | 4769 | tp->phy_flags &= ~TG3_PHYFLG_MDIX_STATE; |
859edb26 | 4770 | tp->link_config.rmt_adv = 0; |
1da177e4 | 4771 | |
f07e9af3 | 4772 | if (tp->phy_flags & TG3_PHYFLG_CAPACITIVE_COUPLING) { |
15ee95c3 MC |
4773 | err = tg3_phy_auxctl_read(tp, |
4774 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, | |
4775 | &val); | |
4776 | if (!err && !(val & (1 << 10))) { | |
b4bd2929 MC |
4777 | tg3_phy_auxctl_write(tp, |
4778 | MII_TG3_AUXCTL_SHDWSEL_MISCTEST, | |
4779 | val | (1 << 10)); | |
1da177e4 LT |
4780 | goto relink; |
4781 | } | |
4782 | } | |
4783 | ||
4784 | bmsr = 0; | |
4785 | for (i = 0; i < 100; i++) { | |
4786 | tg3_readphy(tp, MII_BMSR, &bmsr); | |
4787 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && | |
4788 | (bmsr & BMSR_LSTATUS)) | |
4789 | break; | |
4790 | udelay(40); | |
4791 | } | |
4792 | ||
4793 | if (bmsr & BMSR_LSTATUS) { | |
4794 | u32 aux_stat, bmcr; | |
4795 | ||
4796 | tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat); | |
4797 | for (i = 0; i < 2000; i++) { | |
4798 | udelay(10); | |
4799 | if (!tg3_readphy(tp, MII_TG3_AUX_STAT, &aux_stat) && | |
4800 | aux_stat) | |
4801 | break; | |
4802 | } | |
4803 | ||
4804 | tg3_aux_stat_to_speed_duplex(tp, aux_stat, | |
4805 | ¤t_speed, | |
4806 | ¤t_duplex); | |
4807 | ||
4808 | bmcr = 0; | |
4809 | for (i = 0; i < 200; i++) { | |
4810 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
4811 | if (tg3_readphy(tp, MII_BMCR, &bmcr)) | |
4812 | continue; | |
4813 | if (bmcr && bmcr != 0x7fff) | |
4814 | break; | |
4815 | udelay(10); | |
4816 | } | |
4817 | ||
ef167e27 MC |
4818 | lcl_adv = 0; |
4819 | rmt_adv = 0; | |
1da177e4 | 4820 | |
ef167e27 MC |
4821 | tp->link_config.active_speed = current_speed; |
4822 | tp->link_config.active_duplex = current_duplex; | |
4823 | ||
4824 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { | |
ed1ff5c3 NS |
4825 | bool eee_config_ok = tg3_phy_eee_config_ok(tp); |
4826 | ||
ef167e27 | 4827 | if ((bmcr & BMCR_ANENABLE) && |
ed1ff5c3 | 4828 | eee_config_ok && |
e2bf73e7 | 4829 | tg3_phy_copper_an_config_ok(tp, &lcl_adv) && |
859edb26 | 4830 | tg3_phy_copper_fetch_rmtadv(tp, &rmt_adv)) |
953c96e0 | 4831 | current_link_up = true; |
ed1ff5c3 NS |
4832 | |
4833 | /* EEE settings changes take effect only after a phy | |
4834 | * reset. If we have skipped a reset due to Link Flap | |
4835 | * Avoidance being enabled, do it now. | |
4836 | */ | |
4837 | if (!eee_config_ok && | |
4838 | (tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN) && | |
4839 | !force_reset) | |
4840 | tg3_phy_reset(tp); | |
1da177e4 LT |
4841 | } else { |
4842 | if (!(bmcr & BMCR_ANENABLE) && | |
4843 | tp->link_config.speed == current_speed && | |
f0fcd7a9 | 4844 | tp->link_config.duplex == current_duplex) { |
953c96e0 | 4845 | current_link_up = true; |
1da177e4 LT |
4846 | } |
4847 | } | |
4848 | ||
953c96e0 | 4849 | if (current_link_up && |
e348c5e7 MC |
4850 | tp->link_config.active_duplex == DUPLEX_FULL) { |
4851 | u32 reg, bit; | |
4852 | ||
4853 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { | |
4854 | reg = MII_TG3_FET_GEN_STAT; | |
4855 | bit = MII_TG3_FET_GEN_STAT_MDIXSTAT; | |
4856 | } else { | |
4857 | reg = MII_TG3_EXT_STAT; | |
4858 | bit = MII_TG3_EXT_STAT_MDIX; | |
4859 | } | |
4860 | ||
4861 | if (!tg3_readphy(tp, reg, &val) && (val & bit)) | |
4862 | tp->phy_flags |= TG3_PHYFLG_MDIX_STATE; | |
4863 | ||
ef167e27 | 4864 | tg3_setup_flow_control(tp, lcl_adv, rmt_adv); |
e348c5e7 | 4865 | } |
1da177e4 LT |
4866 | } |
4867 | ||
1da177e4 | 4868 | relink: |
953c96e0 | 4869 | if (!current_link_up || (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER)) { |
1da177e4 LT |
4870 | tg3_phy_copper_begin(tp); |
4871 | ||
7e6c63f0 | 4872 | if (tg3_flag(tp, ROBOSWITCH)) { |
953c96e0 | 4873 | current_link_up = true; |
7e6c63f0 HM |
4874 | /* FIXME: when BCM5325 switch is used use 100 MBit/s */ |
4875 | current_speed = SPEED_1000; | |
4876 | current_duplex = DUPLEX_FULL; | |
4877 | tp->link_config.active_speed = current_speed; | |
4878 | tp->link_config.active_duplex = current_duplex; | |
4879 | } | |
4880 | ||
f833c4c1 | 4881 | tg3_readphy(tp, MII_BMSR, &bmsr); |
06c03c02 MB |
4882 | if ((!tg3_readphy(tp, MII_BMSR, &bmsr) && (bmsr & BMSR_LSTATUS)) || |
4883 | (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) | |
953c96e0 | 4884 | current_link_up = true; |
1da177e4 LT |
4885 | } |
4886 | ||
4887 | tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; | |
953c96e0 | 4888 | if (current_link_up) { |
1da177e4 LT |
4889 | if (tp->link_config.active_speed == SPEED_100 || |
4890 | tp->link_config.active_speed == SPEED_10) | |
4891 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; | |
4892 | else | |
4893 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
f07e9af3 | 4894 | } else if (tp->phy_flags & TG3_PHYFLG_IS_FET) |
7f97a4bd MC |
4895 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; |
4896 | else | |
1da177e4 LT |
4897 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; |
4898 | ||
7e6c63f0 HM |
4899 | /* In order for the 5750 core in BCM4785 chip to work properly |
4900 | * in RGMII mode, the Led Control Register must be set up. | |
4901 | */ | |
4902 | if (tg3_flag(tp, RGMII_MODE)) { | |
4903 | u32 led_ctrl = tr32(MAC_LED_CTRL); | |
4904 | led_ctrl &= ~(LED_CTRL_1000MBPS_ON | LED_CTRL_100MBPS_ON); | |
4905 | ||
4906 | if (tp->link_config.active_speed == SPEED_10) | |
4907 | led_ctrl |= LED_CTRL_LNKLED_OVERRIDE; | |
4908 | else if (tp->link_config.active_speed == SPEED_100) | |
4909 | led_ctrl |= (LED_CTRL_LNKLED_OVERRIDE | | |
4910 | LED_CTRL_100MBPS_ON); | |
4911 | else if (tp->link_config.active_speed == SPEED_1000) | |
4912 | led_ctrl |= (LED_CTRL_LNKLED_OVERRIDE | | |
4913 | LED_CTRL_1000MBPS_ON); | |
4914 | ||
4915 | tw32(MAC_LED_CTRL, led_ctrl); | |
4916 | udelay(40); | |
4917 | } | |
4918 | ||
1da177e4 LT |
4919 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
4920 | if (tp->link_config.active_duplex == DUPLEX_HALF) | |
4921 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; | |
4922 | ||
4153577a | 4923 | if (tg3_asic_rev(tp) == ASIC_REV_5700) { |
953c96e0 | 4924 | if (current_link_up && |
e8f3f6ca | 4925 | tg3_5700_link_polarity(tp, tp->link_config.active_speed)) |
1da177e4 | 4926 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
e8f3f6ca MC |
4927 | else |
4928 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; | |
1da177e4 LT |
4929 | } |
4930 | ||
4931 | /* ??? Without this setting Netgear GA302T PHY does not | |
4932 | * ??? send/receive packets... | |
4933 | */ | |
79eb6904 | 4934 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5411 && |
4153577a | 4935 | tg3_chip_rev_id(tp) == CHIPREV_ID_5700_ALTIMA) { |
1da177e4 LT |
4936 | tp->mi_mode |= MAC_MI_MODE_AUTO_POLL; |
4937 | tw32_f(MAC_MI_MODE, tp->mi_mode); | |
4938 | udelay(80); | |
4939 | } | |
4940 | ||
4941 | tw32_f(MAC_MODE, tp->mac_mode); | |
4942 | udelay(40); | |
4943 | ||
52b02d04 MC |
4944 | tg3_phy_eee_adjust(tp, current_link_up); |
4945 | ||
63c3a66f | 4946 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
1da177e4 LT |
4947 | /* Polled via timer. */ |
4948 | tw32_f(MAC_EVENT, 0); | |
4949 | } else { | |
4950 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); | |
4951 | } | |
4952 | udelay(40); | |
4953 | ||
4153577a | 4954 | if (tg3_asic_rev(tp) == ASIC_REV_5700 && |
953c96e0 | 4955 | current_link_up && |
1da177e4 | 4956 | tp->link_config.active_speed == SPEED_1000 && |
63c3a66f | 4957 | (tg3_flag(tp, PCIX_MODE) || tg3_flag(tp, PCI_HIGH_SPEED))) { |
1da177e4 LT |
4958 | udelay(120); |
4959 | tw32_f(MAC_STATUS, | |
4960 | (MAC_STATUS_SYNC_CHANGED | | |
4961 | MAC_STATUS_CFG_CHANGED)); | |
4962 | udelay(40); | |
4963 | tg3_write_mem(tp, | |
4964 | NIC_SRAM_FIRMWARE_MBOX, | |
4965 | NIC_SRAM_FIRMWARE_MBOX_MAGIC2); | |
4966 | } | |
4967 | ||
5e7dfd0f | 4968 | /* Prevent send BD corruption. */ |
63c3a66f | 4969 | if (tg3_flag(tp, CLKREQ_BUG)) { |
5e7dfd0f MC |
4970 | if (tp->link_config.active_speed == SPEED_100 || |
4971 | tp->link_config.active_speed == SPEED_10) | |
0f49bfbd JL |
4972 | pcie_capability_clear_word(tp->pdev, PCI_EXP_LNKCTL, |
4973 | PCI_EXP_LNKCTL_CLKREQ_EN); | |
5e7dfd0f | 4974 | else |
0f49bfbd JL |
4975 | pcie_capability_set_word(tp->pdev, PCI_EXP_LNKCTL, |
4976 | PCI_EXP_LNKCTL_CLKREQ_EN); | |
5e7dfd0f MC |
4977 | } |
4978 | ||
f4a46d1f | 4979 | tg3_test_and_report_link_chg(tp, current_link_up); |
1da177e4 LT |
4980 | |
4981 | return 0; | |
4982 | } | |
4983 | ||
4984 | struct tg3_fiber_aneginfo { | |
4985 | int state; | |
4986 | #define ANEG_STATE_UNKNOWN 0 | |
4987 | #define ANEG_STATE_AN_ENABLE 1 | |
4988 | #define ANEG_STATE_RESTART_INIT 2 | |
4989 | #define ANEG_STATE_RESTART 3 | |
4990 | #define ANEG_STATE_DISABLE_LINK_OK 4 | |
4991 | #define ANEG_STATE_ABILITY_DETECT_INIT 5 | |
4992 | #define ANEG_STATE_ABILITY_DETECT 6 | |
4993 | #define ANEG_STATE_ACK_DETECT_INIT 7 | |
4994 | #define ANEG_STATE_ACK_DETECT 8 | |
4995 | #define ANEG_STATE_COMPLETE_ACK_INIT 9 | |
4996 | #define ANEG_STATE_COMPLETE_ACK 10 | |
4997 | #define ANEG_STATE_IDLE_DETECT_INIT 11 | |
4998 | #define ANEG_STATE_IDLE_DETECT 12 | |
4999 | #define ANEG_STATE_LINK_OK 13 | |
5000 | #define ANEG_STATE_NEXT_PAGE_WAIT_INIT 14 | |
5001 | #define ANEG_STATE_NEXT_PAGE_WAIT 15 | |
5002 | ||
5003 | u32 flags; | |
5004 | #define MR_AN_ENABLE 0x00000001 | |
5005 | #define MR_RESTART_AN 0x00000002 | |
5006 | #define MR_AN_COMPLETE 0x00000004 | |
5007 | #define MR_PAGE_RX 0x00000008 | |
5008 | #define MR_NP_LOADED 0x00000010 | |
5009 | #define MR_TOGGLE_TX 0x00000020 | |
5010 | #define MR_LP_ADV_FULL_DUPLEX 0x00000040 | |
5011 | #define MR_LP_ADV_HALF_DUPLEX 0x00000080 | |
5012 | #define MR_LP_ADV_SYM_PAUSE 0x00000100 | |
5013 | #define MR_LP_ADV_ASYM_PAUSE 0x00000200 | |
5014 | #define MR_LP_ADV_REMOTE_FAULT1 0x00000400 | |
5015 | #define MR_LP_ADV_REMOTE_FAULT2 0x00000800 | |
5016 | #define MR_LP_ADV_NEXT_PAGE 0x00001000 | |
5017 | #define MR_TOGGLE_RX 0x00002000 | |
5018 | #define MR_NP_RX 0x00004000 | |
5019 | ||
5020 | #define MR_LINK_OK 0x80000000 | |
5021 | ||
5022 | unsigned long link_time, cur_time; | |
5023 | ||
5024 | u32 ability_match_cfg; | |
5025 | int ability_match_count; | |
5026 | ||
5027 | char ability_match, idle_match, ack_match; | |
5028 | ||
5029 | u32 txconfig, rxconfig; | |
5030 | #define ANEG_CFG_NP 0x00000080 | |
5031 | #define ANEG_CFG_ACK 0x00000040 | |
5032 | #define ANEG_CFG_RF2 0x00000020 | |
5033 | #define ANEG_CFG_RF1 0x00000010 | |
5034 | #define ANEG_CFG_PS2 0x00000001 | |
5035 | #define ANEG_CFG_PS1 0x00008000 | |
5036 | #define ANEG_CFG_HD 0x00004000 | |
5037 | #define ANEG_CFG_FD 0x00002000 | |
5038 | #define ANEG_CFG_INVAL 0x00001f06 | |
5039 | ||
5040 | }; | |
5041 | #define ANEG_OK 0 | |
5042 | #define ANEG_DONE 1 | |
5043 | #define ANEG_TIMER_ENAB 2 | |
5044 | #define ANEG_FAILED -1 | |
5045 | ||
5046 | #define ANEG_STATE_SETTLE_TIME 10000 | |
5047 | ||
5048 | static int tg3_fiber_aneg_smachine(struct tg3 *tp, | |
5049 | struct tg3_fiber_aneginfo *ap) | |
5050 | { | |
5be73b47 | 5051 | u16 flowctrl; |
1da177e4 LT |
5052 | unsigned long delta; |
5053 | u32 rx_cfg_reg; | |
5054 | int ret; | |
5055 | ||
5056 | if (ap->state == ANEG_STATE_UNKNOWN) { | |
5057 | ap->rxconfig = 0; | |
5058 | ap->link_time = 0; | |
5059 | ap->cur_time = 0; | |
5060 | ap->ability_match_cfg = 0; | |
5061 | ap->ability_match_count = 0; | |
5062 | ap->ability_match = 0; | |
5063 | ap->idle_match = 0; | |
5064 | ap->ack_match = 0; | |
5065 | } | |
5066 | ap->cur_time++; | |
5067 | ||
5068 | if (tr32(MAC_STATUS) & MAC_STATUS_RCVD_CFG) { | |
5069 | rx_cfg_reg = tr32(MAC_RX_AUTO_NEG); | |
5070 | ||
5071 | if (rx_cfg_reg != ap->ability_match_cfg) { | |
5072 | ap->ability_match_cfg = rx_cfg_reg; | |
5073 | ap->ability_match = 0; | |
5074 | ap->ability_match_count = 0; | |
5075 | } else { | |
5076 | if (++ap->ability_match_count > 1) { | |
5077 | ap->ability_match = 1; | |
5078 | ap->ability_match_cfg = rx_cfg_reg; | |
5079 | } | |
5080 | } | |
5081 | if (rx_cfg_reg & ANEG_CFG_ACK) | |
5082 | ap->ack_match = 1; | |
5083 | else | |
5084 | ap->ack_match = 0; | |
5085 | ||
5086 | ap->idle_match = 0; | |
5087 | } else { | |
5088 | ap->idle_match = 1; | |
5089 | ap->ability_match_cfg = 0; | |
5090 | ap->ability_match_count = 0; | |
5091 | ap->ability_match = 0; | |
5092 | ap->ack_match = 0; | |
5093 | ||
5094 | rx_cfg_reg = 0; | |
5095 | } | |
5096 | ||
5097 | ap->rxconfig = rx_cfg_reg; | |
5098 | ret = ANEG_OK; | |
5099 | ||
33f401ae | 5100 | switch (ap->state) { |
1da177e4 LT |
5101 | case ANEG_STATE_UNKNOWN: |
5102 | if (ap->flags & (MR_AN_ENABLE | MR_RESTART_AN)) | |
5103 | ap->state = ANEG_STATE_AN_ENABLE; | |
5104 | ||
5105 | /* fallthru */ | |
5106 | case ANEG_STATE_AN_ENABLE: | |
5107 | ap->flags &= ~(MR_AN_COMPLETE | MR_PAGE_RX); | |
5108 | if (ap->flags & MR_AN_ENABLE) { | |
5109 | ap->link_time = 0; | |
5110 | ap->cur_time = 0; | |
5111 | ap->ability_match_cfg = 0; | |
5112 | ap->ability_match_count = 0; | |
5113 | ap->ability_match = 0; | |
5114 | ap->idle_match = 0; | |
5115 | ap->ack_match = 0; | |
5116 | ||
5117 | ap->state = ANEG_STATE_RESTART_INIT; | |
5118 | } else { | |
5119 | ap->state = ANEG_STATE_DISABLE_LINK_OK; | |
5120 | } | |
5121 | break; | |
5122 | ||
5123 | case ANEG_STATE_RESTART_INIT: | |
5124 | ap->link_time = ap->cur_time; | |
5125 | ap->flags &= ~(MR_NP_LOADED); | |
5126 | ap->txconfig = 0; | |
5127 | tw32(MAC_TX_AUTO_NEG, 0); | |
5128 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; | |
5129 | tw32_f(MAC_MODE, tp->mac_mode); | |
5130 | udelay(40); | |
5131 | ||
5132 | ret = ANEG_TIMER_ENAB; | |
5133 | ap->state = ANEG_STATE_RESTART; | |
5134 | ||
5135 | /* fallthru */ | |
5136 | case ANEG_STATE_RESTART: | |
5137 | delta = ap->cur_time - ap->link_time; | |
859a5887 | 5138 | if (delta > ANEG_STATE_SETTLE_TIME) |
1da177e4 | 5139 | ap->state = ANEG_STATE_ABILITY_DETECT_INIT; |
859a5887 | 5140 | else |
1da177e4 | 5141 | ret = ANEG_TIMER_ENAB; |
1da177e4 LT |
5142 | break; |
5143 | ||
5144 | case ANEG_STATE_DISABLE_LINK_OK: | |
5145 | ret = ANEG_DONE; | |
5146 | break; | |
5147 | ||
5148 | case ANEG_STATE_ABILITY_DETECT_INIT: | |
5149 | ap->flags &= ~(MR_TOGGLE_TX); | |
5be73b47 MC |
5150 | ap->txconfig = ANEG_CFG_FD; |
5151 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); | |
5152 | if (flowctrl & ADVERTISE_1000XPAUSE) | |
5153 | ap->txconfig |= ANEG_CFG_PS1; | |
5154 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) | |
5155 | ap->txconfig |= ANEG_CFG_PS2; | |
1da177e4 LT |
5156 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); |
5157 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; | |
5158 | tw32_f(MAC_MODE, tp->mac_mode); | |
5159 | udelay(40); | |
5160 | ||
5161 | ap->state = ANEG_STATE_ABILITY_DETECT; | |
5162 | break; | |
5163 | ||
5164 | case ANEG_STATE_ABILITY_DETECT: | |
859a5887 | 5165 | if (ap->ability_match != 0 && ap->rxconfig != 0) |
1da177e4 | 5166 | ap->state = ANEG_STATE_ACK_DETECT_INIT; |
1da177e4 LT |
5167 | break; |
5168 | ||
5169 | case ANEG_STATE_ACK_DETECT_INIT: | |
5170 | ap->txconfig |= ANEG_CFG_ACK; | |
5171 | tw32(MAC_TX_AUTO_NEG, ap->txconfig); | |
5172 | tp->mac_mode |= MAC_MODE_SEND_CONFIGS; | |
5173 | tw32_f(MAC_MODE, tp->mac_mode); | |
5174 | udelay(40); | |
5175 | ||
5176 | ap->state = ANEG_STATE_ACK_DETECT; | |
5177 | ||
5178 | /* fallthru */ | |
5179 | case ANEG_STATE_ACK_DETECT: | |
5180 | if (ap->ack_match != 0) { | |
5181 | if ((ap->rxconfig & ~ANEG_CFG_ACK) == | |
5182 | (ap->ability_match_cfg & ~ANEG_CFG_ACK)) { | |
5183 | ap->state = ANEG_STATE_COMPLETE_ACK_INIT; | |
5184 | } else { | |
5185 | ap->state = ANEG_STATE_AN_ENABLE; | |
5186 | } | |
5187 | } else if (ap->ability_match != 0 && | |
5188 | ap->rxconfig == 0) { | |
5189 | ap->state = ANEG_STATE_AN_ENABLE; | |
5190 | } | |
5191 | break; | |
5192 | ||
5193 | case ANEG_STATE_COMPLETE_ACK_INIT: | |
5194 | if (ap->rxconfig & ANEG_CFG_INVAL) { | |
5195 | ret = ANEG_FAILED; | |
5196 | break; | |
5197 | } | |
5198 | ap->flags &= ~(MR_LP_ADV_FULL_DUPLEX | | |
5199 | MR_LP_ADV_HALF_DUPLEX | | |
5200 | MR_LP_ADV_SYM_PAUSE | | |
5201 | MR_LP_ADV_ASYM_PAUSE | | |
5202 | MR_LP_ADV_REMOTE_FAULT1 | | |
5203 | MR_LP_ADV_REMOTE_FAULT2 | | |
5204 | MR_LP_ADV_NEXT_PAGE | | |
5205 | MR_TOGGLE_RX | | |
5206 | MR_NP_RX); | |
5207 | if (ap->rxconfig & ANEG_CFG_FD) | |
5208 | ap->flags |= MR_LP_ADV_FULL_DUPLEX; | |
5209 | if (ap->rxconfig & ANEG_CFG_HD) | |
5210 | ap->flags |= MR_LP_ADV_HALF_DUPLEX; | |
5211 | if (ap->rxconfig & ANEG_CFG_PS1) | |
5212 | ap->flags |= MR_LP_ADV_SYM_PAUSE; | |
5213 | if (ap->rxconfig & ANEG_CFG_PS2) | |
5214 | ap->flags |= MR_LP_ADV_ASYM_PAUSE; | |
5215 | if (ap->rxconfig & ANEG_CFG_RF1) | |
5216 | ap->flags |= MR_LP_ADV_REMOTE_FAULT1; | |
5217 | if (ap->rxconfig & ANEG_CFG_RF2) | |
5218 | ap->flags |= MR_LP_ADV_REMOTE_FAULT2; | |
5219 | if (ap->rxconfig & ANEG_CFG_NP) | |
5220 | ap->flags |= MR_LP_ADV_NEXT_PAGE; | |
5221 | ||
5222 | ap->link_time = ap->cur_time; | |
5223 | ||
5224 | ap->flags ^= (MR_TOGGLE_TX); | |
5225 | if (ap->rxconfig & 0x0008) | |
5226 | ap->flags |= MR_TOGGLE_RX; | |
5227 | if (ap->rxconfig & ANEG_CFG_NP) | |
5228 | ap->flags |= MR_NP_RX; | |
5229 | ap->flags |= MR_PAGE_RX; | |
5230 | ||
5231 | ap->state = ANEG_STATE_COMPLETE_ACK; | |
5232 | ret = ANEG_TIMER_ENAB; | |
5233 | break; | |
5234 | ||
5235 | case ANEG_STATE_COMPLETE_ACK: | |
5236 | if (ap->ability_match != 0 && | |
5237 | ap->rxconfig == 0) { | |
5238 | ap->state = ANEG_STATE_AN_ENABLE; | |
5239 | break; | |
5240 | } | |
5241 | delta = ap->cur_time - ap->link_time; | |
5242 | if (delta > ANEG_STATE_SETTLE_TIME) { | |
5243 | if (!(ap->flags & (MR_LP_ADV_NEXT_PAGE))) { | |
5244 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; | |
5245 | } else { | |
5246 | if ((ap->txconfig & ANEG_CFG_NP) == 0 && | |
5247 | !(ap->flags & MR_NP_RX)) { | |
5248 | ap->state = ANEG_STATE_IDLE_DETECT_INIT; | |
5249 | } else { | |
5250 | ret = ANEG_FAILED; | |
5251 | } | |
5252 | } | |
5253 | } | |
5254 | break; | |
5255 | ||
5256 | case ANEG_STATE_IDLE_DETECT_INIT: | |
5257 | ap->link_time = ap->cur_time; | |
5258 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; | |
5259 | tw32_f(MAC_MODE, tp->mac_mode); | |
5260 | udelay(40); | |
5261 | ||
5262 | ap->state = ANEG_STATE_IDLE_DETECT; | |
5263 | ret = ANEG_TIMER_ENAB; | |
5264 | break; | |
5265 | ||
5266 | case ANEG_STATE_IDLE_DETECT: | |
5267 | if (ap->ability_match != 0 && | |
5268 | ap->rxconfig == 0) { | |
5269 | ap->state = ANEG_STATE_AN_ENABLE; | |
5270 | break; | |
5271 | } | |
5272 | delta = ap->cur_time - ap->link_time; | |
5273 | if (delta > ANEG_STATE_SETTLE_TIME) { | |
5274 | /* XXX another gem from the Broadcom driver :( */ | |
5275 | ap->state = ANEG_STATE_LINK_OK; | |
5276 | } | |
5277 | break; | |
5278 | ||
5279 | case ANEG_STATE_LINK_OK: | |
5280 | ap->flags |= (MR_AN_COMPLETE | MR_LINK_OK); | |
5281 | ret = ANEG_DONE; | |
5282 | break; | |
5283 | ||
5284 | case ANEG_STATE_NEXT_PAGE_WAIT_INIT: | |
5285 | /* ??? unimplemented */ | |
5286 | break; | |
5287 | ||
5288 | case ANEG_STATE_NEXT_PAGE_WAIT: | |
5289 | /* ??? unimplemented */ | |
5290 | break; | |
5291 | ||
5292 | default: | |
5293 | ret = ANEG_FAILED; | |
5294 | break; | |
855e1111 | 5295 | } |
1da177e4 LT |
5296 | |
5297 | return ret; | |
5298 | } | |
5299 | ||
5be73b47 | 5300 | static int fiber_autoneg(struct tg3 *tp, u32 *txflags, u32 *rxflags) |
1da177e4 LT |
5301 | { |
5302 | int res = 0; | |
5303 | struct tg3_fiber_aneginfo aninfo; | |
5304 | int status = ANEG_FAILED; | |
5305 | unsigned int tick; | |
5306 | u32 tmp; | |
5307 | ||
5308 | tw32_f(MAC_TX_AUTO_NEG, 0); | |
5309 | ||
5310 | tmp = tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK; | |
5311 | tw32_f(MAC_MODE, tmp | MAC_MODE_PORT_MODE_GMII); | |
5312 | udelay(40); | |
5313 | ||
5314 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_SEND_CONFIGS); | |
5315 | udelay(40); | |
5316 | ||
5317 | memset(&aninfo, 0, sizeof(aninfo)); | |
5318 | aninfo.flags |= MR_AN_ENABLE; | |
5319 | aninfo.state = ANEG_STATE_UNKNOWN; | |
5320 | aninfo.cur_time = 0; | |
5321 | tick = 0; | |
5322 | while (++tick < 195000) { | |
5323 | status = tg3_fiber_aneg_smachine(tp, &aninfo); | |
5324 | if (status == ANEG_DONE || status == ANEG_FAILED) | |
5325 | break; | |
5326 | ||
5327 | udelay(1); | |
5328 | } | |
5329 | ||
5330 | tp->mac_mode &= ~MAC_MODE_SEND_CONFIGS; | |
5331 | tw32_f(MAC_MODE, tp->mac_mode); | |
5332 | udelay(40); | |
5333 | ||
5be73b47 MC |
5334 | *txflags = aninfo.txconfig; |
5335 | *rxflags = aninfo.flags; | |
1da177e4 LT |
5336 | |
5337 | if (status == ANEG_DONE && | |
5338 | (aninfo.flags & (MR_AN_COMPLETE | MR_LINK_OK | | |
5339 | MR_LP_ADV_FULL_DUPLEX))) | |
5340 | res = 1; | |
5341 | ||
5342 | return res; | |
5343 | } | |
5344 | ||
5345 | static void tg3_init_bcm8002(struct tg3 *tp) | |
5346 | { | |
5347 | u32 mac_status = tr32(MAC_STATUS); | |
5348 | int i; | |
5349 | ||
5350 | /* Reset when initting first time or we have a link. */ | |
63c3a66f | 5351 | if (tg3_flag(tp, INIT_COMPLETE) && |
1da177e4 LT |
5352 | !(mac_status & MAC_STATUS_PCS_SYNCED)) |
5353 | return; | |
5354 | ||
5355 | /* Set PLL lock range. */ | |
5356 | tg3_writephy(tp, 0x16, 0x8007); | |
5357 | ||
5358 | /* SW reset */ | |
5359 | tg3_writephy(tp, MII_BMCR, BMCR_RESET); | |
5360 | ||
5361 | /* Wait for reset to complete. */ | |
5362 | /* XXX schedule_timeout() ... */ | |
5363 | for (i = 0; i < 500; i++) | |
5364 | udelay(10); | |
5365 | ||
5366 | /* Config mode; select PMA/Ch 1 regs. */ | |
5367 | tg3_writephy(tp, 0x10, 0x8411); | |
5368 | ||
5369 | /* Enable auto-lock and comdet, select txclk for tx. */ | |
5370 | tg3_writephy(tp, 0x11, 0x0a10); | |
5371 | ||
5372 | tg3_writephy(tp, 0x18, 0x00a0); | |
5373 | tg3_writephy(tp, 0x16, 0x41ff); | |
5374 | ||
5375 | /* Assert and deassert POR. */ | |
5376 | tg3_writephy(tp, 0x13, 0x0400); | |
5377 | udelay(40); | |
5378 | tg3_writephy(tp, 0x13, 0x0000); | |
5379 | ||
5380 | tg3_writephy(tp, 0x11, 0x0a50); | |
5381 | udelay(40); | |
5382 | tg3_writephy(tp, 0x11, 0x0a10); | |
5383 | ||
5384 | /* Wait for signal to stabilize */ | |
5385 | /* XXX schedule_timeout() ... */ | |
5386 | for (i = 0; i < 15000; i++) | |
5387 | udelay(10); | |
5388 | ||
5389 | /* Deselect the channel register so we can read the PHYID | |
5390 | * later. | |
5391 | */ | |
5392 | tg3_writephy(tp, 0x10, 0x8011); | |
5393 | } | |
5394 | ||
953c96e0 | 5395 | static bool tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status) |
1da177e4 | 5396 | { |
82cd3d11 | 5397 | u16 flowctrl; |
953c96e0 | 5398 | bool current_link_up; |
1da177e4 LT |
5399 | u32 sg_dig_ctrl, sg_dig_status; |
5400 | u32 serdes_cfg, expected_sg_dig_ctrl; | |
5401 | int workaround, port_a; | |
1da177e4 LT |
5402 | |
5403 | serdes_cfg = 0; | |
5404 | expected_sg_dig_ctrl = 0; | |
5405 | workaround = 0; | |
5406 | port_a = 1; | |
953c96e0 | 5407 | current_link_up = false; |
1da177e4 | 5408 | |
4153577a JP |
5409 | if (tg3_chip_rev_id(tp) != CHIPREV_ID_5704_A0 && |
5410 | tg3_chip_rev_id(tp) != CHIPREV_ID_5704_A1) { | |
1da177e4 LT |
5411 | workaround = 1; |
5412 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) | |
5413 | port_a = 0; | |
5414 | ||
5415 | /* preserve bits 0-11,13,14 for signal pre-emphasis */ | |
5416 | /* preserve bits 20-23 for voltage regulator */ | |
5417 | serdes_cfg = tr32(MAC_SERDES_CFG) & 0x00f06fff; | |
5418 | } | |
5419 | ||
5420 | sg_dig_ctrl = tr32(SG_DIG_CTRL); | |
5421 | ||
5422 | if (tp->link_config.autoneg != AUTONEG_ENABLE) { | |
c98f6e3b | 5423 | if (sg_dig_ctrl & SG_DIG_USING_HW_AUTONEG) { |
1da177e4 LT |
5424 | if (workaround) { |
5425 | u32 val = serdes_cfg; | |
5426 | ||
5427 | if (port_a) | |
5428 | val |= 0xc010000; | |
5429 | else | |
5430 | val |= 0x4010000; | |
5431 | tw32_f(MAC_SERDES_CFG, val); | |
5432 | } | |
c98f6e3b MC |
5433 | |
5434 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); | |
1da177e4 LT |
5435 | } |
5436 | if (mac_status & MAC_STATUS_PCS_SYNCED) { | |
5437 | tg3_setup_flow_control(tp, 0, 0); | |
953c96e0 | 5438 | current_link_up = true; |
1da177e4 LT |
5439 | } |
5440 | goto out; | |
5441 | } | |
5442 | ||
5443 | /* Want auto-negotiation. */ | |
c98f6e3b | 5444 | expected_sg_dig_ctrl = SG_DIG_USING_HW_AUTONEG | SG_DIG_COMMON_SETUP; |
1da177e4 | 5445 | |
82cd3d11 MC |
5446 | flowctrl = tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
5447 | if (flowctrl & ADVERTISE_1000XPAUSE) | |
5448 | expected_sg_dig_ctrl |= SG_DIG_PAUSE_CAP; | |
5449 | if (flowctrl & ADVERTISE_1000XPSE_ASYM) | |
5450 | expected_sg_dig_ctrl |= SG_DIG_ASYM_PAUSE; | |
1da177e4 LT |
5451 | |
5452 | if (sg_dig_ctrl != expected_sg_dig_ctrl) { | |
f07e9af3 | 5453 | if ((tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT) && |
3d3ebe74 MC |
5454 | tp->serdes_counter && |
5455 | ((mac_status & (MAC_STATUS_PCS_SYNCED | | |
5456 | MAC_STATUS_RCVD_CFG)) == | |
5457 | MAC_STATUS_PCS_SYNCED)) { | |
5458 | tp->serdes_counter--; | |
953c96e0 | 5459 | current_link_up = true; |
3d3ebe74 MC |
5460 | goto out; |
5461 | } | |
5462 | restart_autoneg: | |
1da177e4 LT |
5463 | if (workaround) |
5464 | tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000); | |
c98f6e3b | 5465 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | SG_DIG_SOFT_RESET); |
1da177e4 LT |
5466 | udelay(5); |
5467 | tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl); | |
5468 | ||
3d3ebe74 | 5469 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; |
f07e9af3 | 5470 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
1da177e4 LT |
5471 | } else if (mac_status & (MAC_STATUS_PCS_SYNCED | |
5472 | MAC_STATUS_SIGNAL_DET)) { | |
3d3ebe74 | 5473 | sg_dig_status = tr32(SG_DIG_STATUS); |
1da177e4 LT |
5474 | mac_status = tr32(MAC_STATUS); |
5475 | ||
c98f6e3b | 5476 | if ((sg_dig_status & SG_DIG_AUTONEG_COMPLETE) && |
1da177e4 | 5477 | (mac_status & MAC_STATUS_PCS_SYNCED)) { |
82cd3d11 MC |
5478 | u32 local_adv = 0, remote_adv = 0; |
5479 | ||
5480 | if (sg_dig_ctrl & SG_DIG_PAUSE_CAP) | |
5481 | local_adv |= ADVERTISE_1000XPAUSE; | |
5482 | if (sg_dig_ctrl & SG_DIG_ASYM_PAUSE) | |
5483 | local_adv |= ADVERTISE_1000XPSE_ASYM; | |
1da177e4 | 5484 | |
c98f6e3b | 5485 | if (sg_dig_status & SG_DIG_PARTNER_PAUSE_CAPABLE) |
82cd3d11 | 5486 | remote_adv |= LPA_1000XPAUSE; |
c98f6e3b | 5487 | if (sg_dig_status & SG_DIG_PARTNER_ASYM_PAUSE) |
82cd3d11 | 5488 | remote_adv |= LPA_1000XPAUSE_ASYM; |
1da177e4 | 5489 | |
859edb26 MC |
5490 | tp->link_config.rmt_adv = |
5491 | mii_adv_to_ethtool_adv_x(remote_adv); | |
5492 | ||
1da177e4 | 5493 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
953c96e0 | 5494 | current_link_up = true; |
3d3ebe74 | 5495 | tp->serdes_counter = 0; |
f07e9af3 | 5496 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
c98f6e3b | 5497 | } else if (!(sg_dig_status & SG_DIG_AUTONEG_COMPLETE)) { |
3d3ebe74 MC |
5498 | if (tp->serdes_counter) |
5499 | tp->serdes_counter--; | |
1da177e4 LT |
5500 | else { |
5501 | if (workaround) { | |
5502 | u32 val = serdes_cfg; | |
5503 | ||
5504 | if (port_a) | |
5505 | val |= 0xc010000; | |
5506 | else | |
5507 | val |= 0x4010000; | |
5508 | ||
5509 | tw32_f(MAC_SERDES_CFG, val); | |
5510 | } | |
5511 | ||
c98f6e3b | 5512 | tw32_f(SG_DIG_CTRL, SG_DIG_COMMON_SETUP); |
1da177e4 LT |
5513 | udelay(40); |
5514 | ||
5515 | /* Link parallel detection - link is up */ | |
5516 | /* only if we have PCS_SYNC and not */ | |
5517 | /* receiving config code words */ | |
5518 | mac_status = tr32(MAC_STATUS); | |
5519 | if ((mac_status & MAC_STATUS_PCS_SYNCED) && | |
5520 | !(mac_status & MAC_STATUS_RCVD_CFG)) { | |
5521 | tg3_setup_flow_control(tp, 0, 0); | |
953c96e0 | 5522 | current_link_up = true; |
f07e9af3 MC |
5523 | tp->phy_flags |= |
5524 | TG3_PHYFLG_PARALLEL_DETECT; | |
3d3ebe74 MC |
5525 | tp->serdes_counter = |
5526 | SERDES_PARALLEL_DET_TIMEOUT; | |
5527 | } else | |
5528 | goto restart_autoneg; | |
1da177e4 LT |
5529 | } |
5530 | } | |
3d3ebe74 MC |
5531 | } else { |
5532 | tp->serdes_counter = SERDES_AN_TIMEOUT_5704S; | |
f07e9af3 | 5533 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
1da177e4 LT |
5534 | } |
5535 | ||
5536 | out: | |
5537 | return current_link_up; | |
5538 | } | |
5539 | ||
953c96e0 | 5540 | static bool tg3_setup_fiber_by_hand(struct tg3 *tp, u32 mac_status) |
1da177e4 | 5541 | { |
953c96e0 | 5542 | bool current_link_up = false; |
1da177e4 | 5543 | |
5cf64b8a | 5544 | if (!(mac_status & MAC_STATUS_PCS_SYNCED)) |
1da177e4 | 5545 | goto out; |
1da177e4 LT |
5546 | |
5547 | if (tp->link_config.autoneg == AUTONEG_ENABLE) { | |
5be73b47 | 5548 | u32 txflags, rxflags; |
1da177e4 | 5549 | int i; |
6aa20a22 | 5550 | |
5be73b47 MC |
5551 | if (fiber_autoneg(tp, &txflags, &rxflags)) { |
5552 | u32 local_adv = 0, remote_adv = 0; | |
1da177e4 | 5553 | |
5be73b47 MC |
5554 | if (txflags & ANEG_CFG_PS1) |
5555 | local_adv |= ADVERTISE_1000XPAUSE; | |
5556 | if (txflags & ANEG_CFG_PS2) | |
5557 | local_adv |= ADVERTISE_1000XPSE_ASYM; | |
5558 | ||
5559 | if (rxflags & MR_LP_ADV_SYM_PAUSE) | |
5560 | remote_adv |= LPA_1000XPAUSE; | |
5561 | if (rxflags & MR_LP_ADV_ASYM_PAUSE) | |
5562 | remote_adv |= LPA_1000XPAUSE_ASYM; | |
1da177e4 | 5563 | |
859edb26 MC |
5564 | tp->link_config.rmt_adv = |
5565 | mii_adv_to_ethtool_adv_x(remote_adv); | |
5566 | ||
1da177e4 LT |
5567 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
5568 | ||
953c96e0 | 5569 | current_link_up = true; |
1da177e4 LT |
5570 | } |
5571 | for (i = 0; i < 30; i++) { | |
5572 | udelay(20); | |
5573 | tw32_f(MAC_STATUS, | |
5574 | (MAC_STATUS_SYNC_CHANGED | | |
5575 | MAC_STATUS_CFG_CHANGED)); | |
5576 | udelay(40); | |
5577 | if ((tr32(MAC_STATUS) & | |
5578 | (MAC_STATUS_SYNC_CHANGED | | |
5579 | MAC_STATUS_CFG_CHANGED)) == 0) | |
5580 | break; | |
5581 | } | |
5582 | ||
5583 | mac_status = tr32(MAC_STATUS); | |
953c96e0 | 5584 | if (!current_link_up && |
1da177e4 LT |
5585 | (mac_status & MAC_STATUS_PCS_SYNCED) && |
5586 | !(mac_status & MAC_STATUS_RCVD_CFG)) | |
953c96e0 | 5587 | current_link_up = true; |
1da177e4 | 5588 | } else { |
5be73b47 MC |
5589 | tg3_setup_flow_control(tp, 0, 0); |
5590 | ||
1da177e4 | 5591 | /* Forcing 1000FD link up. */ |
953c96e0 | 5592 | current_link_up = true; |
1da177e4 LT |
5593 | |
5594 | tw32_f(MAC_MODE, (tp->mac_mode | MAC_MODE_SEND_CONFIGS)); | |
5595 | udelay(40); | |
e8f3f6ca MC |
5596 | |
5597 | tw32_f(MAC_MODE, tp->mac_mode); | |
5598 | udelay(40); | |
1da177e4 LT |
5599 | } |
5600 | ||
5601 | out: | |
5602 | return current_link_up; | |
5603 | } | |
5604 | ||
953c96e0 | 5605 | static int tg3_setup_fiber_phy(struct tg3 *tp, bool force_reset) |
1da177e4 LT |
5606 | { |
5607 | u32 orig_pause_cfg; | |
5608 | u16 orig_active_speed; | |
5609 | u8 orig_active_duplex; | |
5610 | u32 mac_status; | |
953c96e0 | 5611 | bool current_link_up; |
1da177e4 LT |
5612 | int i; |
5613 | ||
8d018621 | 5614 | orig_pause_cfg = tp->link_config.active_flowctrl; |
1da177e4 LT |
5615 | orig_active_speed = tp->link_config.active_speed; |
5616 | orig_active_duplex = tp->link_config.active_duplex; | |
5617 | ||
63c3a66f | 5618 | if (!tg3_flag(tp, HW_AUTONEG) && |
f4a46d1f | 5619 | tp->link_up && |
63c3a66f | 5620 | tg3_flag(tp, INIT_COMPLETE)) { |
1da177e4 LT |
5621 | mac_status = tr32(MAC_STATUS); |
5622 | mac_status &= (MAC_STATUS_PCS_SYNCED | | |
5623 | MAC_STATUS_SIGNAL_DET | | |
5624 | MAC_STATUS_CFG_CHANGED | | |
5625 | MAC_STATUS_RCVD_CFG); | |
5626 | if (mac_status == (MAC_STATUS_PCS_SYNCED | | |
5627 | MAC_STATUS_SIGNAL_DET)) { | |
5628 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | | |
5629 | MAC_STATUS_CFG_CHANGED)); | |
5630 | return 0; | |
5631 | } | |
5632 | } | |
5633 | ||
5634 | tw32_f(MAC_TX_AUTO_NEG, 0); | |
5635 | ||
5636 | tp->mac_mode &= ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); | |
5637 | tp->mac_mode |= MAC_MODE_PORT_MODE_TBI; | |
5638 | tw32_f(MAC_MODE, tp->mac_mode); | |
5639 | udelay(40); | |
5640 | ||
79eb6904 | 5641 | if (tp->phy_id == TG3_PHY_ID_BCM8002) |
1da177e4 LT |
5642 | tg3_init_bcm8002(tp); |
5643 | ||
5644 | /* Enable link change event even when serdes polling. */ | |
5645 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); | |
5646 | udelay(40); | |
5647 | ||
953c96e0 | 5648 | current_link_up = false; |
859edb26 | 5649 | tp->link_config.rmt_adv = 0; |
1da177e4 LT |
5650 | mac_status = tr32(MAC_STATUS); |
5651 | ||
63c3a66f | 5652 | if (tg3_flag(tp, HW_AUTONEG)) |
1da177e4 LT |
5653 | current_link_up = tg3_setup_fiber_hw_autoneg(tp, mac_status); |
5654 | else | |
5655 | current_link_up = tg3_setup_fiber_by_hand(tp, mac_status); | |
5656 | ||
898a56f8 | 5657 | tp->napi[0].hw_status->status = |
1da177e4 | 5658 | (SD_STATUS_UPDATED | |
898a56f8 | 5659 | (tp->napi[0].hw_status->status & ~SD_STATUS_LINK_CHG)); |
1da177e4 LT |
5660 | |
5661 | for (i = 0; i < 100; i++) { | |
5662 | tw32_f(MAC_STATUS, (MAC_STATUS_SYNC_CHANGED | | |
5663 | MAC_STATUS_CFG_CHANGED)); | |
5664 | udelay(5); | |
5665 | if ((tr32(MAC_STATUS) & (MAC_STATUS_SYNC_CHANGED | | |
3d3ebe74 MC |
5666 | MAC_STATUS_CFG_CHANGED | |
5667 | MAC_STATUS_LNKSTATE_CHANGED)) == 0) | |
1da177e4 LT |
5668 | break; |
5669 | } | |
5670 | ||
5671 | mac_status = tr32(MAC_STATUS); | |
5672 | if ((mac_status & MAC_STATUS_PCS_SYNCED) == 0) { | |
953c96e0 | 5673 | current_link_up = false; |
3d3ebe74 MC |
5674 | if (tp->link_config.autoneg == AUTONEG_ENABLE && |
5675 | tp->serdes_counter == 0) { | |
1da177e4 LT |
5676 | tw32_f(MAC_MODE, (tp->mac_mode | |
5677 | MAC_MODE_SEND_CONFIGS)); | |
5678 | udelay(1); | |
5679 | tw32_f(MAC_MODE, tp->mac_mode); | |
5680 | } | |
5681 | } | |
5682 | ||
953c96e0 | 5683 | if (current_link_up) { |
1da177e4 LT |
5684 | tp->link_config.active_speed = SPEED_1000; |
5685 | tp->link_config.active_duplex = DUPLEX_FULL; | |
5686 | tw32(MAC_LED_CTRL, (tp->led_ctrl | | |
5687 | LED_CTRL_LNKLED_OVERRIDE | | |
5688 | LED_CTRL_1000MBPS_ON)); | |
5689 | } else { | |
e740522e MC |
5690 | tp->link_config.active_speed = SPEED_UNKNOWN; |
5691 | tp->link_config.active_duplex = DUPLEX_UNKNOWN; | |
1da177e4 LT |
5692 | tw32(MAC_LED_CTRL, (tp->led_ctrl | |
5693 | LED_CTRL_LNKLED_OVERRIDE | | |
5694 | LED_CTRL_TRAFFIC_OVERRIDE)); | |
5695 | } | |
5696 | ||
f4a46d1f | 5697 | if (!tg3_test_and_report_link_chg(tp, current_link_up)) { |
8d018621 | 5698 | u32 now_pause_cfg = tp->link_config.active_flowctrl; |
1da177e4 LT |
5699 | if (orig_pause_cfg != now_pause_cfg || |
5700 | orig_active_speed != tp->link_config.active_speed || | |
5701 | orig_active_duplex != tp->link_config.active_duplex) | |
5702 | tg3_link_report(tp); | |
5703 | } | |
5704 | ||
5705 | return 0; | |
5706 | } | |
5707 | ||
953c96e0 | 5708 | static int tg3_setup_fiber_mii_phy(struct tg3 *tp, bool force_reset) |
747e8f8b | 5709 | { |
953c96e0 | 5710 | int err = 0; |
747e8f8b | 5711 | u32 bmsr, bmcr; |
85730a63 MC |
5712 | u16 current_speed = SPEED_UNKNOWN; |
5713 | u8 current_duplex = DUPLEX_UNKNOWN; | |
953c96e0 | 5714 | bool current_link_up = false; |
85730a63 MC |
5715 | u32 local_adv, remote_adv, sgsr; |
5716 | ||
5717 | if ((tg3_asic_rev(tp) == ASIC_REV_5719 || | |
5718 | tg3_asic_rev(tp) == ASIC_REV_5720) && | |
5719 | !tg3_readphy(tp, SERDES_TG3_1000X_STATUS, &sgsr) && | |
5720 | (sgsr & SERDES_TG3_SGMII_MODE)) { | |
5721 | ||
5722 | if (force_reset) | |
5723 | tg3_phy_reset(tp); | |
5724 | ||
5725 | tp->mac_mode &= ~MAC_MODE_PORT_MODE_MASK; | |
5726 | ||
5727 | if (!(sgsr & SERDES_TG3_LINK_UP)) { | |
5728 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
5729 | } else { | |
953c96e0 | 5730 | current_link_up = true; |
85730a63 MC |
5731 | if (sgsr & SERDES_TG3_SPEED_1000) { |
5732 | current_speed = SPEED_1000; | |
5733 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
5734 | } else if (sgsr & SERDES_TG3_SPEED_100) { | |
5735 | current_speed = SPEED_100; | |
5736 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; | |
5737 | } else { | |
5738 | current_speed = SPEED_10; | |
5739 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; | |
5740 | } | |
5741 | ||
5742 | if (sgsr & SERDES_TG3_FULL_DUPLEX) | |
5743 | current_duplex = DUPLEX_FULL; | |
5744 | else | |
5745 | current_duplex = DUPLEX_HALF; | |
5746 | } | |
5747 | ||
5748 | tw32_f(MAC_MODE, tp->mac_mode); | |
5749 | udelay(40); | |
5750 | ||
5751 | tg3_clear_mac_status(tp); | |
5752 | ||
5753 | goto fiber_setup_done; | |
5754 | } | |
747e8f8b MC |
5755 | |
5756 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
5757 | tw32_f(MAC_MODE, tp->mac_mode); | |
5758 | udelay(40); | |
5759 | ||
3310e248 | 5760 | tg3_clear_mac_status(tp); |
747e8f8b MC |
5761 | |
5762 | if (force_reset) | |
5763 | tg3_phy_reset(tp); | |
5764 | ||
859edb26 | 5765 | tp->link_config.rmt_adv = 0; |
747e8f8b MC |
5766 | |
5767 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); | |
5768 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); | |
4153577a | 5769 | if (tg3_asic_rev(tp) == ASIC_REV_5714) { |
d4d2c558 MC |
5770 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
5771 | bmsr |= BMSR_LSTATUS; | |
5772 | else | |
5773 | bmsr &= ~BMSR_LSTATUS; | |
5774 | } | |
747e8f8b MC |
5775 | |
5776 | err |= tg3_readphy(tp, MII_BMCR, &bmcr); | |
5777 | ||
5778 | if ((tp->link_config.autoneg == AUTONEG_ENABLE) && !force_reset && | |
f07e9af3 | 5779 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
747e8f8b MC |
5780 | /* do nothing, just check for link up at the end */ |
5781 | } else if (tp->link_config.autoneg == AUTONEG_ENABLE) { | |
28011cf1 | 5782 | u32 adv, newadv; |
747e8f8b MC |
5783 | |
5784 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); | |
28011cf1 MC |
5785 | newadv = adv & ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF | |
5786 | ADVERTISE_1000XPAUSE | | |
5787 | ADVERTISE_1000XPSE_ASYM | | |
5788 | ADVERTISE_SLCT); | |
747e8f8b | 5789 | |
28011cf1 | 5790 | newadv |= tg3_advert_flowctrl_1000X(tp->link_config.flowctrl); |
37f07023 | 5791 | newadv |= ethtool_adv_to_mii_adv_x(tp->link_config.advertising); |
747e8f8b | 5792 | |
28011cf1 MC |
5793 | if ((newadv != adv) || !(bmcr & BMCR_ANENABLE)) { |
5794 | tg3_writephy(tp, MII_ADVERTISE, newadv); | |
747e8f8b MC |
5795 | bmcr |= BMCR_ANENABLE | BMCR_ANRESTART; |
5796 | tg3_writephy(tp, MII_BMCR, bmcr); | |
5797 | ||
5798 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); | |
3d3ebe74 | 5799 | tp->serdes_counter = SERDES_AN_TIMEOUT_5714S; |
f07e9af3 | 5800 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
5801 | |
5802 | return err; | |
5803 | } | |
5804 | } else { | |
5805 | u32 new_bmcr; | |
5806 | ||
5807 | bmcr &= ~BMCR_SPEED1000; | |
5808 | new_bmcr = bmcr & ~(BMCR_ANENABLE | BMCR_FULLDPLX); | |
5809 | ||
5810 | if (tp->link_config.duplex == DUPLEX_FULL) | |
5811 | new_bmcr |= BMCR_FULLDPLX; | |
5812 | ||
5813 | if (new_bmcr != bmcr) { | |
5814 | /* BMCR_SPEED1000 is a reserved bit that needs | |
5815 | * to be set on write. | |
5816 | */ | |
5817 | new_bmcr |= BMCR_SPEED1000; | |
5818 | ||
5819 | /* Force a linkdown */ | |
f4a46d1f | 5820 | if (tp->link_up) { |
747e8f8b MC |
5821 | u32 adv; |
5822 | ||
5823 | err |= tg3_readphy(tp, MII_ADVERTISE, &adv); | |
5824 | adv &= ~(ADVERTISE_1000XFULL | | |
5825 | ADVERTISE_1000XHALF | | |
5826 | ADVERTISE_SLCT); | |
5827 | tg3_writephy(tp, MII_ADVERTISE, adv); | |
5828 | tg3_writephy(tp, MII_BMCR, bmcr | | |
5829 | BMCR_ANRESTART | | |
5830 | BMCR_ANENABLE); | |
5831 | udelay(10); | |
f4a46d1f | 5832 | tg3_carrier_off(tp); |
747e8f8b MC |
5833 | } |
5834 | tg3_writephy(tp, MII_BMCR, new_bmcr); | |
5835 | bmcr = new_bmcr; | |
5836 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); | |
5837 | err |= tg3_readphy(tp, MII_BMSR, &bmsr); | |
4153577a | 5838 | if (tg3_asic_rev(tp) == ASIC_REV_5714) { |
d4d2c558 MC |
5839 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) |
5840 | bmsr |= BMSR_LSTATUS; | |
5841 | else | |
5842 | bmsr &= ~BMSR_LSTATUS; | |
5843 | } | |
f07e9af3 | 5844 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
5845 | } |
5846 | } | |
5847 | ||
5848 | if (bmsr & BMSR_LSTATUS) { | |
5849 | current_speed = SPEED_1000; | |
953c96e0 | 5850 | current_link_up = true; |
747e8f8b MC |
5851 | if (bmcr & BMCR_FULLDPLX) |
5852 | current_duplex = DUPLEX_FULL; | |
5853 | else | |
5854 | current_duplex = DUPLEX_HALF; | |
5855 | ||
ef167e27 MC |
5856 | local_adv = 0; |
5857 | remote_adv = 0; | |
5858 | ||
747e8f8b | 5859 | if (bmcr & BMCR_ANENABLE) { |
ef167e27 | 5860 | u32 common; |
747e8f8b MC |
5861 | |
5862 | err |= tg3_readphy(tp, MII_ADVERTISE, &local_adv); | |
5863 | err |= tg3_readphy(tp, MII_LPA, &remote_adv); | |
5864 | common = local_adv & remote_adv; | |
5865 | if (common & (ADVERTISE_1000XHALF | | |
5866 | ADVERTISE_1000XFULL)) { | |
5867 | if (common & ADVERTISE_1000XFULL) | |
5868 | current_duplex = DUPLEX_FULL; | |
5869 | else | |
5870 | current_duplex = DUPLEX_HALF; | |
859edb26 MC |
5871 | |
5872 | tp->link_config.rmt_adv = | |
5873 | mii_adv_to_ethtool_adv_x(remote_adv); | |
63c3a66f | 5874 | } else if (!tg3_flag(tp, 5780_CLASS)) { |
57d8b880 | 5875 | /* Link is up via parallel detect */ |
859a5887 | 5876 | } else { |
953c96e0 | 5877 | current_link_up = false; |
859a5887 | 5878 | } |
747e8f8b MC |
5879 | } |
5880 | } | |
5881 | ||
85730a63 | 5882 | fiber_setup_done: |
953c96e0 | 5883 | if (current_link_up && current_duplex == DUPLEX_FULL) |
ef167e27 MC |
5884 | tg3_setup_flow_control(tp, local_adv, remote_adv); |
5885 | ||
747e8f8b MC |
5886 | tp->mac_mode &= ~MAC_MODE_HALF_DUPLEX; |
5887 | if (tp->link_config.active_duplex == DUPLEX_HALF) | |
5888 | tp->mac_mode |= MAC_MODE_HALF_DUPLEX; | |
5889 | ||
5890 | tw32_f(MAC_MODE, tp->mac_mode); | |
5891 | udelay(40); | |
5892 | ||
5893 | tw32_f(MAC_EVENT, MAC_EVENT_LNKSTATE_CHANGED); | |
5894 | ||
5895 | tp->link_config.active_speed = current_speed; | |
5896 | tp->link_config.active_duplex = current_duplex; | |
5897 | ||
f4a46d1f | 5898 | tg3_test_and_report_link_chg(tp, current_link_up); |
747e8f8b MC |
5899 | return err; |
5900 | } | |
5901 | ||
5902 | static void tg3_serdes_parallel_detect(struct tg3 *tp) | |
5903 | { | |
3d3ebe74 | 5904 | if (tp->serdes_counter) { |
747e8f8b | 5905 | /* Give autoneg time to complete. */ |
3d3ebe74 | 5906 | tp->serdes_counter--; |
747e8f8b MC |
5907 | return; |
5908 | } | |
c6cdf436 | 5909 | |
f4a46d1f | 5910 | if (!tp->link_up && |
747e8f8b MC |
5911 | (tp->link_config.autoneg == AUTONEG_ENABLE)) { |
5912 | u32 bmcr; | |
5913 | ||
5914 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
5915 | if (bmcr & BMCR_ANENABLE) { | |
5916 | u32 phy1, phy2; | |
5917 | ||
5918 | /* Select shadow register 0x1f */ | |
f08aa1a8 MC |
5919 | tg3_writephy(tp, MII_TG3_MISC_SHDW, 0x7c00); |
5920 | tg3_readphy(tp, MII_TG3_MISC_SHDW, &phy1); | |
747e8f8b MC |
5921 | |
5922 | /* Select expansion interrupt status register */ | |
f08aa1a8 MC |
5923 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
5924 | MII_TG3_DSP_EXP1_INT_STAT); | |
5925 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); | |
5926 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); | |
747e8f8b MC |
5927 | |
5928 | if ((phy1 & 0x10) && !(phy2 & 0x20)) { | |
5929 | /* We have signal detect and not receiving | |
5930 | * config code words, link is up by parallel | |
5931 | * detection. | |
5932 | */ | |
5933 | ||
5934 | bmcr &= ~BMCR_ANENABLE; | |
5935 | bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX; | |
5936 | tg3_writephy(tp, MII_BMCR, bmcr); | |
f07e9af3 | 5937 | tp->phy_flags |= TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
5938 | } |
5939 | } | |
f4a46d1f | 5940 | } else if (tp->link_up && |
859a5887 | 5941 | (tp->link_config.autoneg == AUTONEG_ENABLE) && |
f07e9af3 | 5942 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT)) { |
747e8f8b MC |
5943 | u32 phy2; |
5944 | ||
5945 | /* Select expansion interrupt status register */ | |
f08aa1a8 MC |
5946 | tg3_writephy(tp, MII_TG3_DSP_ADDRESS, |
5947 | MII_TG3_DSP_EXP1_INT_STAT); | |
5948 | tg3_readphy(tp, MII_TG3_DSP_RW_PORT, &phy2); | |
747e8f8b MC |
5949 | if (phy2 & 0x20) { |
5950 | u32 bmcr; | |
5951 | ||
5952 | /* Config code words received, turn on autoneg. */ | |
5953 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
5954 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANENABLE); | |
5955 | ||
f07e9af3 | 5956 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; |
747e8f8b MC |
5957 | |
5958 | } | |
5959 | } | |
5960 | } | |
5961 | ||
953c96e0 | 5962 | static int tg3_setup_phy(struct tg3 *tp, bool force_reset) |
1da177e4 | 5963 | { |
f2096f94 | 5964 | u32 val; |
1da177e4 LT |
5965 | int err; |
5966 | ||
f07e9af3 | 5967 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
1da177e4 | 5968 | err = tg3_setup_fiber_phy(tp, force_reset); |
f07e9af3 | 5969 | else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
747e8f8b | 5970 | err = tg3_setup_fiber_mii_phy(tp, force_reset); |
859a5887 | 5971 | else |
1da177e4 | 5972 | err = tg3_setup_copper_phy(tp, force_reset); |
1da177e4 | 5973 | |
4153577a | 5974 | if (tg3_chip_rev(tp) == CHIPREV_5784_AX) { |
f2096f94 | 5975 | u32 scale; |
aa6c91fe MC |
5976 | |
5977 | val = tr32(TG3_CPMU_CLCK_STAT) & CPMU_CLCK_STAT_MAC_CLCK_MASK; | |
5978 | if (val == CPMU_CLCK_STAT_MAC_CLCK_62_5) | |
5979 | scale = 65; | |
5980 | else if (val == CPMU_CLCK_STAT_MAC_CLCK_6_25) | |
5981 | scale = 6; | |
5982 | else | |
5983 | scale = 12; | |
5984 | ||
5985 | val = tr32(GRC_MISC_CFG) & ~GRC_MISC_CFG_PRESCALAR_MASK; | |
5986 | val |= (scale << GRC_MISC_CFG_PRESCALAR_SHIFT); | |
5987 | tw32(GRC_MISC_CFG, val); | |
5988 | } | |
5989 | ||
f2096f94 MC |
5990 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
5991 | (6 << TX_LENGTHS_IPG_SHIFT); | |
4153577a JP |
5992 | if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
5993 | tg3_asic_rev(tp) == ASIC_REV_5762) | |
f2096f94 MC |
5994 | val |= tr32(MAC_TX_LENGTHS) & |
5995 | (TX_LENGTHS_JMB_FRM_LEN_MSK | | |
5996 | TX_LENGTHS_CNT_DWN_VAL_MSK); | |
5997 | ||
1da177e4 LT |
5998 | if (tp->link_config.active_speed == SPEED_1000 && |
5999 | tp->link_config.active_duplex == DUPLEX_HALF) | |
f2096f94 MC |
6000 | tw32(MAC_TX_LENGTHS, val | |
6001 | (0xff << TX_LENGTHS_SLOT_TIME_SHIFT)); | |
1da177e4 | 6002 | else |
f2096f94 MC |
6003 | tw32(MAC_TX_LENGTHS, val | |
6004 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT)); | |
1da177e4 | 6005 | |
63c3a66f | 6006 | if (!tg3_flag(tp, 5705_PLUS)) { |
f4a46d1f | 6007 | if (tp->link_up) { |
1da177e4 | 6008 | tw32(HOSTCC_STAT_COAL_TICKS, |
15f9850d | 6009 | tp->coal.stats_block_coalesce_usecs); |
1da177e4 LT |
6010 | } else { |
6011 | tw32(HOSTCC_STAT_COAL_TICKS, 0); | |
6012 | } | |
6013 | } | |
6014 | ||
63c3a66f | 6015 | if (tg3_flag(tp, ASPM_WORKAROUND)) { |
f2096f94 | 6016 | val = tr32(PCIE_PWR_MGMT_THRESH); |
f4a46d1f | 6017 | if (!tp->link_up) |
8ed5d97e MC |
6018 | val = (val & ~PCIE_PWR_MGMT_L1_THRESH_MSK) | |
6019 | tp->pwrmgmt_thresh; | |
6020 | else | |
6021 | val |= PCIE_PWR_MGMT_L1_THRESH_MSK; | |
6022 | tw32(PCIE_PWR_MGMT_THRESH, val); | |
6023 | } | |
6024 | ||
1da177e4 LT |
6025 | return err; |
6026 | } | |
6027 | ||
7d41e49a MC |
6028 | /* tp->lock must be held */ |
6029 | static u64 tg3_refclk_read(struct tg3 *tp) | |
6030 | { | |
6031 | u64 stamp = tr32(TG3_EAV_REF_CLCK_LSB); | |
6032 | return stamp | (u64)tr32(TG3_EAV_REF_CLCK_MSB) << 32; | |
6033 | } | |
6034 | ||
be947307 MC |
6035 | /* tp->lock must be held */ |
6036 | static void tg3_refclk_write(struct tg3 *tp, u64 newval) | |
6037 | { | |
6038 | tw32(TG3_EAV_REF_CLCK_CTL, TG3_EAV_REF_CLCK_CTL_STOP); | |
6039 | tw32(TG3_EAV_REF_CLCK_LSB, newval & 0xffffffff); | |
6040 | tw32(TG3_EAV_REF_CLCK_MSB, newval >> 32); | |
6041 | tw32_f(TG3_EAV_REF_CLCK_CTL, TG3_EAV_REF_CLCK_CTL_RESUME); | |
6042 | } | |
6043 | ||
7d41e49a MC |
6044 | static inline void tg3_full_lock(struct tg3 *tp, int irq_sync); |
6045 | static inline void tg3_full_unlock(struct tg3 *tp); | |
6046 | static int tg3_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info) | |
6047 | { | |
6048 | struct tg3 *tp = netdev_priv(dev); | |
6049 | ||
6050 | info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | | |
6051 | SOF_TIMESTAMPING_RX_SOFTWARE | | |
f233a976 FL |
6052 | SOF_TIMESTAMPING_SOFTWARE; |
6053 | ||
6054 | if (tg3_flag(tp, PTP_CAPABLE)) { | |
32e19272 | 6055 | info->so_timestamping |= SOF_TIMESTAMPING_TX_HARDWARE | |
f233a976 FL |
6056 | SOF_TIMESTAMPING_RX_HARDWARE | |
6057 | SOF_TIMESTAMPING_RAW_HARDWARE; | |
6058 | } | |
7d41e49a MC |
6059 | |
6060 | if (tp->ptp_clock) | |
6061 | info->phc_index = ptp_clock_index(tp->ptp_clock); | |
6062 | else | |
6063 | info->phc_index = -1; | |
6064 | ||
6065 | info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON); | |
6066 | ||
6067 | info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | | |
6068 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) | | |
6069 | (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) | | |
6070 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT); | |
6071 | return 0; | |
6072 | } | |
6073 | ||
6074 | static int tg3_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) | |
6075 | { | |
6076 | struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); | |
6077 | bool neg_adj = false; | |
6078 | u32 correction = 0; | |
6079 | ||
6080 | if (ppb < 0) { | |
6081 | neg_adj = true; | |
6082 | ppb = -ppb; | |
6083 | } | |
6084 | ||
6085 | /* Frequency adjustment is performed using hardware with a 24 bit | |
6086 | * accumulator and a programmable correction value. On each clk, the | |
6087 | * correction value gets added to the accumulator and when it | |
6088 | * overflows, the time counter is incremented/decremented. | |
6089 | * | |
6090 | * So conversion from ppb to correction value is | |
6091 | * ppb * (1 << 24) / 1000000000 | |
6092 | */ | |
6093 | correction = div_u64((u64)ppb * (1 << 24), 1000000000ULL) & | |
6094 | TG3_EAV_REF_CLK_CORRECT_MASK; | |
6095 | ||
6096 | tg3_full_lock(tp, 0); | |
6097 | ||
6098 | if (correction) | |
6099 | tw32(TG3_EAV_REF_CLK_CORRECT_CTL, | |
6100 | TG3_EAV_REF_CLK_CORRECT_EN | | |
6101 | (neg_adj ? TG3_EAV_REF_CLK_CORRECT_NEG : 0) | correction); | |
6102 | else | |
6103 | tw32(TG3_EAV_REF_CLK_CORRECT_CTL, 0); | |
6104 | ||
6105 | tg3_full_unlock(tp); | |
6106 | ||
6107 | return 0; | |
6108 | } | |
6109 | ||
6110 | static int tg3_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) | |
6111 | { | |
6112 | struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); | |
6113 | ||
6114 | tg3_full_lock(tp, 0); | |
6115 | tp->ptp_adjust += delta; | |
6116 | tg3_full_unlock(tp); | |
6117 | ||
6118 | return 0; | |
6119 | } | |
6120 | ||
6121 | static int tg3_ptp_gettime(struct ptp_clock_info *ptp, struct timespec *ts) | |
6122 | { | |
6123 | u64 ns; | |
6124 | u32 remainder; | |
6125 | struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); | |
6126 | ||
6127 | tg3_full_lock(tp, 0); | |
6128 | ns = tg3_refclk_read(tp); | |
6129 | ns += tp->ptp_adjust; | |
6130 | tg3_full_unlock(tp); | |
6131 | ||
6132 | ts->tv_sec = div_u64_rem(ns, 1000000000, &remainder); | |
6133 | ts->tv_nsec = remainder; | |
6134 | ||
6135 | return 0; | |
6136 | } | |
6137 | ||
6138 | static int tg3_ptp_settime(struct ptp_clock_info *ptp, | |
6139 | const struct timespec *ts) | |
6140 | { | |
6141 | u64 ns; | |
6142 | struct tg3 *tp = container_of(ptp, struct tg3, ptp_info); | |
6143 | ||
6144 | ns = timespec_to_ns(ts); | |
6145 | ||
6146 | tg3_full_lock(tp, 0); | |
6147 | tg3_refclk_write(tp, ns); | |
6148 | tp->ptp_adjust = 0; | |
6149 | tg3_full_unlock(tp); | |
6150 | ||
6151 | return 0; | |
6152 | } | |
6153 | ||
6154 | static int tg3_ptp_enable(struct ptp_clock_info *ptp, | |
6155 | struct ptp_clock_request *rq, int on) | |
6156 | { | |
6157 | return -EOPNOTSUPP; | |
6158 | } | |
6159 | ||
6160 | static const struct ptp_clock_info tg3_ptp_caps = { | |
6161 | .owner = THIS_MODULE, | |
6162 | .name = "tg3 clock", | |
6163 | .max_adj = 250000000, | |
6164 | .n_alarm = 0, | |
6165 | .n_ext_ts = 0, | |
6166 | .n_per_out = 0, | |
6167 | .pps = 0, | |
6168 | .adjfreq = tg3_ptp_adjfreq, | |
6169 | .adjtime = tg3_ptp_adjtime, | |
6170 | .gettime = tg3_ptp_gettime, | |
6171 | .settime = tg3_ptp_settime, | |
6172 | .enable = tg3_ptp_enable, | |
6173 | }; | |
6174 | ||
fb4ce8ad MC |
6175 | static void tg3_hwclock_to_timestamp(struct tg3 *tp, u64 hwclock, |
6176 | struct skb_shared_hwtstamps *timestamp) | |
6177 | { | |
6178 | memset(timestamp, 0, sizeof(struct skb_shared_hwtstamps)); | |
6179 | timestamp->hwtstamp = ns_to_ktime((hwclock & TG3_TSTAMP_MASK) + | |
6180 | tp->ptp_adjust); | |
6181 | } | |
6182 | ||
be947307 MC |
6183 | /* tp->lock must be held */ |
6184 | static void tg3_ptp_init(struct tg3 *tp) | |
6185 | { | |
6186 | if (!tg3_flag(tp, PTP_CAPABLE)) | |
6187 | return; | |
6188 | ||
6189 | /* Initialize the hardware clock to the system time. */ | |
6190 | tg3_refclk_write(tp, ktime_to_ns(ktime_get_real())); | |
6191 | tp->ptp_adjust = 0; | |
7d41e49a | 6192 | tp->ptp_info = tg3_ptp_caps; |
be947307 MC |
6193 | } |
6194 | ||
6195 | /* tp->lock must be held */ | |
6196 | static void tg3_ptp_resume(struct tg3 *tp) | |
6197 | { | |
6198 | if (!tg3_flag(tp, PTP_CAPABLE)) | |
6199 | return; | |
6200 | ||
6201 | tg3_refclk_write(tp, ktime_to_ns(ktime_get_real()) + tp->ptp_adjust); | |
6202 | tp->ptp_adjust = 0; | |
6203 | } | |
6204 | ||
6205 | static void tg3_ptp_fini(struct tg3 *tp) | |
6206 | { | |
6207 | if (!tg3_flag(tp, PTP_CAPABLE) || !tp->ptp_clock) | |
6208 | return; | |
6209 | ||
7d41e49a | 6210 | ptp_clock_unregister(tp->ptp_clock); |
be947307 MC |
6211 | tp->ptp_clock = NULL; |
6212 | tp->ptp_adjust = 0; | |
6213 | } | |
6214 | ||
66cfd1bd MC |
6215 | static inline int tg3_irq_sync(struct tg3 *tp) |
6216 | { | |
6217 | return tp->irq_sync; | |
6218 | } | |
6219 | ||
97bd8e49 MC |
6220 | static inline void tg3_rd32_loop(struct tg3 *tp, u32 *dst, u32 off, u32 len) |
6221 | { | |
6222 | int i; | |
6223 | ||
6224 | dst = (u32 *)((u8 *)dst + off); | |
6225 | for (i = 0; i < len; i += sizeof(u32)) | |
6226 | *dst++ = tr32(off + i); | |
6227 | } | |
6228 | ||
6229 | static void tg3_dump_legacy_regs(struct tg3 *tp, u32 *regs) | |
6230 | { | |
6231 | tg3_rd32_loop(tp, regs, TG3PCI_VENDOR, 0xb0); | |
6232 | tg3_rd32_loop(tp, regs, MAILBOX_INTERRUPT_0, 0x200); | |
6233 | tg3_rd32_loop(tp, regs, MAC_MODE, 0x4f0); | |
6234 | tg3_rd32_loop(tp, regs, SNDDATAI_MODE, 0xe0); | |
6235 | tg3_rd32_loop(tp, regs, SNDDATAC_MODE, 0x04); | |
6236 | tg3_rd32_loop(tp, regs, SNDBDS_MODE, 0x80); | |
6237 | tg3_rd32_loop(tp, regs, SNDBDI_MODE, 0x48); | |
6238 | tg3_rd32_loop(tp, regs, SNDBDC_MODE, 0x04); | |
6239 | tg3_rd32_loop(tp, regs, RCVLPC_MODE, 0x20); | |
6240 | tg3_rd32_loop(tp, regs, RCVLPC_SELLST_BASE, 0x15c); | |
6241 | tg3_rd32_loop(tp, regs, RCVDBDI_MODE, 0x0c); | |
6242 | tg3_rd32_loop(tp, regs, RCVDBDI_JUMBO_BD, 0x3c); | |
6243 | tg3_rd32_loop(tp, regs, RCVDBDI_BD_PROD_IDX_0, 0x44); | |
6244 | tg3_rd32_loop(tp, regs, RCVDCC_MODE, 0x04); | |
6245 | tg3_rd32_loop(tp, regs, RCVBDI_MODE, 0x20); | |
6246 | tg3_rd32_loop(tp, regs, RCVCC_MODE, 0x14); | |
6247 | tg3_rd32_loop(tp, regs, RCVLSC_MODE, 0x08); | |
6248 | tg3_rd32_loop(tp, regs, MBFREE_MODE, 0x08); | |
6249 | tg3_rd32_loop(tp, regs, HOSTCC_MODE, 0x100); | |
6250 | ||
63c3a66f | 6251 | if (tg3_flag(tp, SUPPORT_MSIX)) |
97bd8e49 MC |
6252 | tg3_rd32_loop(tp, regs, HOSTCC_RXCOL_TICKS_VEC1, 0x180); |
6253 | ||
6254 | tg3_rd32_loop(tp, regs, MEMARB_MODE, 0x10); | |
6255 | tg3_rd32_loop(tp, regs, BUFMGR_MODE, 0x58); | |
6256 | tg3_rd32_loop(tp, regs, RDMAC_MODE, 0x08); | |
6257 | tg3_rd32_loop(tp, regs, WDMAC_MODE, 0x08); | |
6258 | tg3_rd32_loop(tp, regs, RX_CPU_MODE, 0x04); | |
6259 | tg3_rd32_loop(tp, regs, RX_CPU_STATE, 0x04); | |
6260 | tg3_rd32_loop(tp, regs, RX_CPU_PGMCTR, 0x04); | |
6261 | tg3_rd32_loop(tp, regs, RX_CPU_HWBKPT, 0x04); | |
6262 | ||
63c3a66f | 6263 | if (!tg3_flag(tp, 5705_PLUS)) { |
97bd8e49 MC |
6264 | tg3_rd32_loop(tp, regs, TX_CPU_MODE, 0x04); |
6265 | tg3_rd32_loop(tp, regs, TX_CPU_STATE, 0x04); | |
6266 | tg3_rd32_loop(tp, regs, TX_CPU_PGMCTR, 0x04); | |
6267 | } | |
6268 | ||
6269 | tg3_rd32_loop(tp, regs, GRCMBOX_INTERRUPT_0, 0x110); | |
6270 | tg3_rd32_loop(tp, regs, FTQ_RESET, 0x120); | |
6271 | tg3_rd32_loop(tp, regs, MSGINT_MODE, 0x0c); | |
6272 | tg3_rd32_loop(tp, regs, DMAC_MODE, 0x04); | |
6273 | tg3_rd32_loop(tp, regs, GRC_MODE, 0x4c); | |
6274 | ||
63c3a66f | 6275 | if (tg3_flag(tp, NVRAM)) |
97bd8e49 MC |
6276 | tg3_rd32_loop(tp, regs, NVRAM_CMD, 0x24); |
6277 | } | |
6278 | ||
6279 | static void tg3_dump_state(struct tg3 *tp) | |
6280 | { | |
6281 | int i; | |
6282 | u32 *regs; | |
6283 | ||
6284 | regs = kzalloc(TG3_REG_BLK_SIZE, GFP_ATOMIC); | |
b2adaca9 | 6285 | if (!regs) |
97bd8e49 | 6286 | return; |
97bd8e49 | 6287 | |
63c3a66f | 6288 | if (tg3_flag(tp, PCI_EXPRESS)) { |
97bd8e49 MC |
6289 | /* Read up to but not including private PCI registers */ |
6290 | for (i = 0; i < TG3_PCIE_TLDLPL_PORT; i += sizeof(u32)) | |
6291 | regs[i / sizeof(u32)] = tr32(i); | |
6292 | } else | |
6293 | tg3_dump_legacy_regs(tp, regs); | |
6294 | ||
6295 | for (i = 0; i < TG3_REG_BLK_SIZE / sizeof(u32); i += 4) { | |
6296 | if (!regs[i + 0] && !regs[i + 1] && | |
6297 | !regs[i + 2] && !regs[i + 3]) | |
6298 | continue; | |
6299 | ||
6300 | netdev_err(tp->dev, "0x%08x: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n", | |
6301 | i * 4, | |
6302 | regs[i + 0], regs[i + 1], regs[i + 2], regs[i + 3]); | |
6303 | } | |
6304 | ||
6305 | kfree(regs); | |
6306 | ||
6307 | for (i = 0; i < tp->irq_cnt; i++) { | |
6308 | struct tg3_napi *tnapi = &tp->napi[i]; | |
6309 | ||
6310 | /* SW status block */ | |
6311 | netdev_err(tp->dev, | |
6312 | "%d: Host status block [%08x:%08x:(%04x:%04x:%04x):(%04x:%04x)]\n", | |
6313 | i, | |
6314 | tnapi->hw_status->status, | |
6315 | tnapi->hw_status->status_tag, | |
6316 | tnapi->hw_status->rx_jumbo_consumer, | |
6317 | tnapi->hw_status->rx_consumer, | |
6318 | tnapi->hw_status->rx_mini_consumer, | |
6319 | tnapi->hw_status->idx[0].rx_producer, | |
6320 | tnapi->hw_status->idx[0].tx_consumer); | |
6321 | ||
6322 | netdev_err(tp->dev, | |
6323 | "%d: NAPI info [%08x:%08x:(%04x:%04x:%04x):%04x:(%04x:%04x:%04x:%04x)]\n", | |
6324 | i, | |
6325 | tnapi->last_tag, tnapi->last_irq_tag, | |
6326 | tnapi->tx_prod, tnapi->tx_cons, tnapi->tx_pending, | |
6327 | tnapi->rx_rcb_ptr, | |
6328 | tnapi->prodring.rx_std_prod_idx, | |
6329 | tnapi->prodring.rx_std_cons_idx, | |
6330 | tnapi->prodring.rx_jmb_prod_idx, | |
6331 | tnapi->prodring.rx_jmb_cons_idx); | |
6332 | } | |
6333 | } | |
6334 | ||
df3e6548 MC |
6335 | /* This is called whenever we suspect that the system chipset is re- |
6336 | * ordering the sequence of MMIO to the tx send mailbox. The symptom | |
6337 | * is bogus tx completions. We try to recover by setting the | |
6338 | * TG3_FLAG_MBOX_WRITE_REORDER flag and resetting the chip later | |
6339 | * in the workqueue. | |
6340 | */ | |
6341 | static void tg3_tx_recover(struct tg3 *tp) | |
6342 | { | |
63c3a66f | 6343 | BUG_ON(tg3_flag(tp, MBOX_WRITE_REORDER) || |
df3e6548 MC |
6344 | tp->write32_tx_mbox == tg3_write_indirect_mbox); |
6345 | ||
5129c3a3 MC |
6346 | netdev_warn(tp->dev, |
6347 | "The system may be re-ordering memory-mapped I/O " | |
6348 | "cycles to the network device, attempting to recover. " | |
6349 | "Please report the problem to the driver maintainer " | |
6350 | "and include system chipset information.\n"); | |
df3e6548 MC |
6351 | |
6352 | spin_lock(&tp->lock); | |
63c3a66f | 6353 | tg3_flag_set(tp, TX_RECOVERY_PENDING); |
df3e6548 MC |
6354 | spin_unlock(&tp->lock); |
6355 | } | |
6356 | ||
f3f3f27e | 6357 | static inline u32 tg3_tx_avail(struct tg3_napi *tnapi) |
1b2a7205 | 6358 | { |
f65aac16 MC |
6359 | /* Tell compiler to fetch tx indices from memory. */ |
6360 | barrier(); | |
f3f3f27e MC |
6361 | return tnapi->tx_pending - |
6362 | ((tnapi->tx_prod - tnapi->tx_cons) & (TG3_TX_RING_SIZE - 1)); | |
1b2a7205 MC |
6363 | } |
6364 | ||
1da177e4 LT |
6365 | /* Tigon3 never reports partial packet sends. So we do not |
6366 | * need special logic to handle SKBs that have not had all | |
6367 | * of their frags sent yet, like SunGEM does. | |
6368 | */ | |
17375d25 | 6369 | static void tg3_tx(struct tg3_napi *tnapi) |
1da177e4 | 6370 | { |
17375d25 | 6371 | struct tg3 *tp = tnapi->tp; |
898a56f8 | 6372 | u32 hw_idx = tnapi->hw_status->idx[0].tx_consumer; |
f3f3f27e | 6373 | u32 sw_idx = tnapi->tx_cons; |
fe5f5787 MC |
6374 | struct netdev_queue *txq; |
6375 | int index = tnapi - tp->napi; | |
298376d3 | 6376 | unsigned int pkts_compl = 0, bytes_compl = 0; |
fe5f5787 | 6377 | |
63c3a66f | 6378 | if (tg3_flag(tp, ENABLE_TSS)) |
fe5f5787 MC |
6379 | index--; |
6380 | ||
6381 | txq = netdev_get_tx_queue(tp->dev, index); | |
1da177e4 LT |
6382 | |
6383 | while (sw_idx != hw_idx) { | |
df8944cf | 6384 | struct tg3_tx_ring_info *ri = &tnapi->tx_buffers[sw_idx]; |
1da177e4 | 6385 | struct sk_buff *skb = ri->skb; |
df3e6548 MC |
6386 | int i, tx_bug = 0; |
6387 | ||
6388 | if (unlikely(skb == NULL)) { | |
6389 | tg3_tx_recover(tp); | |
6390 | return; | |
6391 | } | |
1da177e4 | 6392 | |
fb4ce8ad MC |
6393 | if (tnapi->tx_ring[sw_idx].len_flags & TXD_FLAG_HWTSTAMP) { |
6394 | struct skb_shared_hwtstamps timestamp; | |
6395 | u64 hwclock = tr32(TG3_TX_TSTAMP_LSB); | |
6396 | hwclock |= (u64)tr32(TG3_TX_TSTAMP_MSB) << 32; | |
6397 | ||
6398 | tg3_hwclock_to_timestamp(tp, hwclock, ×tamp); | |
6399 | ||
6400 | skb_tstamp_tx(skb, ×tamp); | |
6401 | } | |
6402 | ||
f4188d8a | 6403 | pci_unmap_single(tp->pdev, |
4e5e4f0d | 6404 | dma_unmap_addr(ri, mapping), |
f4188d8a AD |
6405 | skb_headlen(skb), |
6406 | PCI_DMA_TODEVICE); | |
1da177e4 LT |
6407 | |
6408 | ri->skb = NULL; | |
6409 | ||
e01ee14d MC |
6410 | while (ri->fragmented) { |
6411 | ri->fragmented = false; | |
6412 | sw_idx = NEXT_TX(sw_idx); | |
6413 | ri = &tnapi->tx_buffers[sw_idx]; | |
6414 | } | |
6415 | ||
1da177e4 LT |
6416 | sw_idx = NEXT_TX(sw_idx); |
6417 | ||
6418 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { | |
f3f3f27e | 6419 | ri = &tnapi->tx_buffers[sw_idx]; |
df3e6548 MC |
6420 | if (unlikely(ri->skb != NULL || sw_idx == hw_idx)) |
6421 | tx_bug = 1; | |
f4188d8a AD |
6422 | |
6423 | pci_unmap_page(tp->pdev, | |
4e5e4f0d | 6424 | dma_unmap_addr(ri, mapping), |
9e903e08 | 6425 | skb_frag_size(&skb_shinfo(skb)->frags[i]), |
f4188d8a | 6426 | PCI_DMA_TODEVICE); |
e01ee14d MC |
6427 | |
6428 | while (ri->fragmented) { | |
6429 | ri->fragmented = false; | |
6430 | sw_idx = NEXT_TX(sw_idx); | |
6431 | ri = &tnapi->tx_buffers[sw_idx]; | |
6432 | } | |
6433 | ||
1da177e4 LT |
6434 | sw_idx = NEXT_TX(sw_idx); |
6435 | } | |
6436 | ||
298376d3 TH |
6437 | pkts_compl++; |
6438 | bytes_compl += skb->len; | |
6439 | ||
f47c11ee | 6440 | dev_kfree_skb(skb); |
df3e6548 MC |
6441 | |
6442 | if (unlikely(tx_bug)) { | |
6443 | tg3_tx_recover(tp); | |
6444 | return; | |
6445 | } | |
1da177e4 LT |
6446 | } |
6447 | ||
5cb917bc | 6448 | netdev_tx_completed_queue(txq, pkts_compl, bytes_compl); |
298376d3 | 6449 | |
f3f3f27e | 6450 | tnapi->tx_cons = sw_idx; |
1da177e4 | 6451 | |
1b2a7205 MC |
6452 | /* Need to make the tx_cons update visible to tg3_start_xmit() |
6453 | * before checking for netif_queue_stopped(). Without the | |
6454 | * memory barrier, there is a small possibility that tg3_start_xmit() | |
6455 | * will miss it and cause the queue to be stopped forever. | |
6456 | */ | |
6457 | smp_mb(); | |
6458 | ||
fe5f5787 | 6459 | if (unlikely(netif_tx_queue_stopped(txq) && |
f3f3f27e | 6460 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)))) { |
fe5f5787 MC |
6461 | __netif_tx_lock(txq, smp_processor_id()); |
6462 | if (netif_tx_queue_stopped(txq) && | |
f3f3f27e | 6463 | (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi))) |
fe5f5787 MC |
6464 | netif_tx_wake_queue(txq); |
6465 | __netif_tx_unlock(txq); | |
51b91468 | 6466 | } |
1da177e4 LT |
6467 | } |
6468 | ||
8d4057a9 ED |
6469 | static void tg3_frag_free(bool is_frag, void *data) |
6470 | { | |
6471 | if (is_frag) | |
6472 | put_page(virt_to_head_page(data)); | |
6473 | else | |
6474 | kfree(data); | |
6475 | } | |
6476 | ||
9205fd9c | 6477 | static void tg3_rx_data_free(struct tg3 *tp, struct ring_info *ri, u32 map_sz) |
2b2cdb65 | 6478 | { |
8d4057a9 ED |
6479 | unsigned int skb_size = SKB_DATA_ALIGN(map_sz + TG3_RX_OFFSET(tp)) + |
6480 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); | |
6481 | ||
9205fd9c | 6482 | if (!ri->data) |
2b2cdb65 MC |
6483 | return; |
6484 | ||
4e5e4f0d | 6485 | pci_unmap_single(tp->pdev, dma_unmap_addr(ri, mapping), |
2b2cdb65 | 6486 | map_sz, PCI_DMA_FROMDEVICE); |
a1e8b307 | 6487 | tg3_frag_free(skb_size <= PAGE_SIZE, ri->data); |
9205fd9c | 6488 | ri->data = NULL; |
2b2cdb65 MC |
6489 | } |
6490 | ||
8d4057a9 | 6491 | |
1da177e4 LT |
6492 | /* Returns size of skb allocated or < 0 on error. |
6493 | * | |
6494 | * We only need to fill in the address because the other members | |
6495 | * of the RX descriptor are invariant, see tg3_init_rings. | |
6496 | * | |
6497 | * Note the purposeful assymetry of cpu vs. chip accesses. For | |
6498 | * posting buffers we only dirty the first cache line of the RX | |
6499 | * descriptor (containing the address). Whereas for the RX status | |
6500 | * buffers the cpu only reads the last cacheline of the RX descriptor | |
6501 | * (to fetch the error flags, vlan tag, checksum, and opaque cookie). | |
6502 | */ | |
9205fd9c | 6503 | static int tg3_alloc_rx_data(struct tg3 *tp, struct tg3_rx_prodring_set *tpr, |
8d4057a9 ED |
6504 | u32 opaque_key, u32 dest_idx_unmasked, |
6505 | unsigned int *frag_size) | |
1da177e4 LT |
6506 | { |
6507 | struct tg3_rx_buffer_desc *desc; | |
f94e290e | 6508 | struct ring_info *map; |
9205fd9c | 6509 | u8 *data; |
1da177e4 | 6510 | dma_addr_t mapping; |
9205fd9c | 6511 | int skb_size, data_size, dest_idx; |
1da177e4 | 6512 | |
1da177e4 LT |
6513 | switch (opaque_key) { |
6514 | case RXD_OPAQUE_RING_STD: | |
2c49a44d | 6515 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
21f581a5 MC |
6516 | desc = &tpr->rx_std[dest_idx]; |
6517 | map = &tpr->rx_std_buffers[dest_idx]; | |
9205fd9c | 6518 | data_size = tp->rx_pkt_map_sz; |
1da177e4 LT |
6519 | break; |
6520 | ||
6521 | case RXD_OPAQUE_RING_JUMBO: | |
2c49a44d | 6522 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
79ed5ac7 | 6523 | desc = &tpr->rx_jmb[dest_idx].std; |
21f581a5 | 6524 | map = &tpr->rx_jmb_buffers[dest_idx]; |
9205fd9c | 6525 | data_size = TG3_RX_JMB_MAP_SZ; |
1da177e4 LT |
6526 | break; |
6527 | ||
6528 | default: | |
6529 | return -EINVAL; | |
855e1111 | 6530 | } |
1da177e4 LT |
6531 | |
6532 | /* Do not overwrite any of the map or rp information | |
6533 | * until we are sure we can commit to a new buffer. | |
6534 | * | |
6535 | * Callers depend upon this behavior and assume that | |
6536 | * we leave everything unchanged if we fail. | |
6537 | */ | |
9205fd9c ED |
6538 | skb_size = SKB_DATA_ALIGN(data_size + TG3_RX_OFFSET(tp)) + |
6539 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); | |
a1e8b307 ED |
6540 | if (skb_size <= PAGE_SIZE) { |
6541 | data = netdev_alloc_frag(skb_size); | |
6542 | *frag_size = skb_size; | |
8d4057a9 ED |
6543 | } else { |
6544 | data = kmalloc(skb_size, GFP_ATOMIC); | |
6545 | *frag_size = 0; | |
6546 | } | |
9205fd9c | 6547 | if (!data) |
1da177e4 LT |
6548 | return -ENOMEM; |
6549 | ||
9205fd9c ED |
6550 | mapping = pci_map_single(tp->pdev, |
6551 | data + TG3_RX_OFFSET(tp), | |
6552 | data_size, | |
1da177e4 | 6553 | PCI_DMA_FROMDEVICE); |
8d4057a9 | 6554 | if (unlikely(pci_dma_mapping_error(tp->pdev, mapping))) { |
a1e8b307 | 6555 | tg3_frag_free(skb_size <= PAGE_SIZE, data); |
a21771dd MC |
6556 | return -EIO; |
6557 | } | |
1da177e4 | 6558 | |
9205fd9c | 6559 | map->data = data; |
4e5e4f0d | 6560 | dma_unmap_addr_set(map, mapping, mapping); |
1da177e4 | 6561 | |
1da177e4 LT |
6562 | desc->addr_hi = ((u64)mapping >> 32); |
6563 | desc->addr_lo = ((u64)mapping & 0xffffffff); | |
6564 | ||
9205fd9c | 6565 | return data_size; |
1da177e4 LT |
6566 | } |
6567 | ||
6568 | /* We only need to move over in the address because the other | |
6569 | * members of the RX descriptor are invariant. See notes above | |
9205fd9c | 6570 | * tg3_alloc_rx_data for full details. |
1da177e4 | 6571 | */ |
a3896167 MC |
6572 | static void tg3_recycle_rx(struct tg3_napi *tnapi, |
6573 | struct tg3_rx_prodring_set *dpr, | |
6574 | u32 opaque_key, int src_idx, | |
6575 | u32 dest_idx_unmasked) | |
1da177e4 | 6576 | { |
17375d25 | 6577 | struct tg3 *tp = tnapi->tp; |
1da177e4 LT |
6578 | struct tg3_rx_buffer_desc *src_desc, *dest_desc; |
6579 | struct ring_info *src_map, *dest_map; | |
8fea32b9 | 6580 | struct tg3_rx_prodring_set *spr = &tp->napi[0].prodring; |
c6cdf436 | 6581 | int dest_idx; |
1da177e4 LT |
6582 | |
6583 | switch (opaque_key) { | |
6584 | case RXD_OPAQUE_RING_STD: | |
2c49a44d | 6585 | dest_idx = dest_idx_unmasked & tp->rx_std_ring_mask; |
a3896167 MC |
6586 | dest_desc = &dpr->rx_std[dest_idx]; |
6587 | dest_map = &dpr->rx_std_buffers[dest_idx]; | |
6588 | src_desc = &spr->rx_std[src_idx]; | |
6589 | src_map = &spr->rx_std_buffers[src_idx]; | |
1da177e4 LT |
6590 | break; |
6591 | ||
6592 | case RXD_OPAQUE_RING_JUMBO: | |
2c49a44d | 6593 | dest_idx = dest_idx_unmasked & tp->rx_jmb_ring_mask; |
a3896167 MC |
6594 | dest_desc = &dpr->rx_jmb[dest_idx].std; |
6595 | dest_map = &dpr->rx_jmb_buffers[dest_idx]; | |
6596 | src_desc = &spr->rx_jmb[src_idx].std; | |
6597 | src_map = &spr->rx_jmb_buffers[src_idx]; | |
1da177e4 LT |
6598 | break; |
6599 | ||
6600 | default: | |
6601 | return; | |
855e1111 | 6602 | } |
1da177e4 | 6603 | |
9205fd9c | 6604 | dest_map->data = src_map->data; |
4e5e4f0d FT |
6605 | dma_unmap_addr_set(dest_map, mapping, |
6606 | dma_unmap_addr(src_map, mapping)); | |
1da177e4 LT |
6607 | dest_desc->addr_hi = src_desc->addr_hi; |
6608 | dest_desc->addr_lo = src_desc->addr_lo; | |
e92967bf MC |
6609 | |
6610 | /* Ensure that the update to the skb happens after the physical | |
6611 | * addresses have been transferred to the new BD location. | |
6612 | */ | |
6613 | smp_wmb(); | |
6614 | ||
9205fd9c | 6615 | src_map->data = NULL; |
1da177e4 LT |
6616 | } |
6617 | ||
1da177e4 LT |
6618 | /* The RX ring scheme is composed of multiple rings which post fresh |
6619 | * buffers to the chip, and one special ring the chip uses to report | |
6620 | * status back to the host. | |
6621 | * | |
6622 | * The special ring reports the status of received packets to the | |
6623 | * host. The chip does not write into the original descriptor the | |
6624 | * RX buffer was obtained from. The chip simply takes the original | |
6625 | * descriptor as provided by the host, updates the status and length | |
6626 | * field, then writes this into the next status ring entry. | |
6627 | * | |
6628 | * Each ring the host uses to post buffers to the chip is described | |
6629 | * by a TG3_BDINFO entry in the chips SRAM area. When a packet arrives, | |
6630 | * it is first placed into the on-chip ram. When the packet's length | |
6631 | * is known, it walks down the TG3_BDINFO entries to select the ring. | |
6632 | * Each TG3_BDINFO specifies a MAXLEN field and the first TG3_BDINFO | |
6633 | * which is within the range of the new packet's length is chosen. | |
6634 | * | |
6635 | * The "separate ring for rx status" scheme may sound queer, but it makes | |
6636 | * sense from a cache coherency perspective. If only the host writes | |
6637 | * to the buffer post rings, and only the chip writes to the rx status | |
6638 | * rings, then cache lines never move beyond shared-modified state. | |
6639 | * If both the host and chip were to write into the same ring, cache line | |
6640 | * eviction could occur since both entities want it in an exclusive state. | |
6641 | */ | |
17375d25 | 6642 | static int tg3_rx(struct tg3_napi *tnapi, int budget) |
1da177e4 | 6643 | { |
17375d25 | 6644 | struct tg3 *tp = tnapi->tp; |
f92905de | 6645 | u32 work_mask, rx_std_posted = 0; |
4361935a | 6646 | u32 std_prod_idx, jmb_prod_idx; |
72334482 | 6647 | u32 sw_idx = tnapi->rx_rcb_ptr; |
483ba50b | 6648 | u16 hw_idx; |
1da177e4 | 6649 | int received; |
8fea32b9 | 6650 | struct tg3_rx_prodring_set *tpr = &tnapi->prodring; |
1da177e4 | 6651 | |
8d9d7cfc | 6652 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
1da177e4 LT |
6653 | /* |
6654 | * We need to order the read of hw_idx and the read of | |
6655 | * the opaque cookie. | |
6656 | */ | |
6657 | rmb(); | |
1da177e4 LT |
6658 | work_mask = 0; |
6659 | received = 0; | |
4361935a MC |
6660 | std_prod_idx = tpr->rx_std_prod_idx; |
6661 | jmb_prod_idx = tpr->rx_jmb_prod_idx; | |
1da177e4 | 6662 | while (sw_idx != hw_idx && budget > 0) { |
afc081f8 | 6663 | struct ring_info *ri; |
72334482 | 6664 | struct tg3_rx_buffer_desc *desc = &tnapi->rx_rcb[sw_idx]; |
1da177e4 LT |
6665 | unsigned int len; |
6666 | struct sk_buff *skb; | |
6667 | dma_addr_t dma_addr; | |
6668 | u32 opaque_key, desc_idx, *post_ptr; | |
9205fd9c | 6669 | u8 *data; |
fb4ce8ad | 6670 | u64 tstamp = 0; |
1da177e4 LT |
6671 | |
6672 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; | |
6673 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; | |
6674 | if (opaque_key == RXD_OPAQUE_RING_STD) { | |
8fea32b9 | 6675 | ri = &tp->napi[0].prodring.rx_std_buffers[desc_idx]; |
4e5e4f0d | 6676 | dma_addr = dma_unmap_addr(ri, mapping); |
9205fd9c | 6677 | data = ri->data; |
4361935a | 6678 | post_ptr = &std_prod_idx; |
f92905de | 6679 | rx_std_posted++; |
1da177e4 | 6680 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { |
8fea32b9 | 6681 | ri = &tp->napi[0].prodring.rx_jmb_buffers[desc_idx]; |
4e5e4f0d | 6682 | dma_addr = dma_unmap_addr(ri, mapping); |
9205fd9c | 6683 | data = ri->data; |
4361935a | 6684 | post_ptr = &jmb_prod_idx; |
21f581a5 | 6685 | } else |
1da177e4 | 6686 | goto next_pkt_nopost; |
1da177e4 LT |
6687 | |
6688 | work_mask |= opaque_key; | |
6689 | ||
e16d4982 | 6690 | if (desc->err_vlan & RXD_ERR_MASK) { |
1da177e4 | 6691 | drop_it: |
a3896167 | 6692 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
1da177e4 LT |
6693 | desc_idx, *post_ptr); |
6694 | drop_it_no_recycle: | |
6695 | /* Other statistics kept track of by card. */ | |
b0057c51 | 6696 | tp->rx_dropped++; |
1da177e4 LT |
6697 | goto next_pkt; |
6698 | } | |
6699 | ||
9205fd9c | 6700 | prefetch(data + TG3_RX_OFFSET(tp)); |
ad829268 MC |
6701 | len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) - |
6702 | ETH_FCS_LEN; | |
1da177e4 | 6703 | |
fb4ce8ad MC |
6704 | if ((desc->type_flags & RXD_FLAG_PTPSTAT_MASK) == |
6705 | RXD_FLAG_PTPSTAT_PTPV1 || | |
6706 | (desc->type_flags & RXD_FLAG_PTPSTAT_MASK) == | |
6707 | RXD_FLAG_PTPSTAT_PTPV2) { | |
6708 | tstamp = tr32(TG3_RX_TSTAMP_LSB); | |
6709 | tstamp |= (u64)tr32(TG3_RX_TSTAMP_MSB) << 32; | |
6710 | } | |
6711 | ||
d2757fc4 | 6712 | if (len > TG3_RX_COPY_THRESH(tp)) { |
1da177e4 | 6713 | int skb_size; |
8d4057a9 | 6714 | unsigned int frag_size; |
1da177e4 | 6715 | |
9205fd9c | 6716 | skb_size = tg3_alloc_rx_data(tp, tpr, opaque_key, |
8d4057a9 | 6717 | *post_ptr, &frag_size); |
1da177e4 LT |
6718 | if (skb_size < 0) |
6719 | goto drop_it; | |
6720 | ||
287be12e | 6721 | pci_unmap_single(tp->pdev, dma_addr, skb_size, |
1da177e4 LT |
6722 | PCI_DMA_FROMDEVICE); |
6723 | ||
9205fd9c | 6724 | /* Ensure that the update to the data happens |
61e800cf MC |
6725 | * after the usage of the old DMA mapping. |
6726 | */ | |
6727 | smp_wmb(); | |
6728 | ||
9205fd9c | 6729 | ri->data = NULL; |
61e800cf | 6730 | |
6c02a5a2 IV |
6731 | skb = build_skb(data, frag_size); |
6732 | if (!skb) { | |
6733 | tg3_frag_free(frag_size != 0, data); | |
6734 | goto drop_it_no_recycle; | |
6735 | } | |
6736 | skb_reserve(skb, TG3_RX_OFFSET(tp)); | |
1da177e4 | 6737 | } else { |
a3896167 | 6738 | tg3_recycle_rx(tnapi, tpr, opaque_key, |
1da177e4 LT |
6739 | desc_idx, *post_ptr); |
6740 | ||
9205fd9c ED |
6741 | skb = netdev_alloc_skb(tp->dev, |
6742 | len + TG3_RAW_IP_ALIGN); | |
6743 | if (skb == NULL) | |
1da177e4 LT |
6744 | goto drop_it_no_recycle; |
6745 | ||
9205fd9c | 6746 | skb_reserve(skb, TG3_RAW_IP_ALIGN); |
1da177e4 | 6747 | pci_dma_sync_single_for_cpu(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); |
9205fd9c ED |
6748 | memcpy(skb->data, |
6749 | data + TG3_RX_OFFSET(tp), | |
6750 | len); | |
1da177e4 | 6751 | pci_dma_sync_single_for_device(tp->pdev, dma_addr, len, PCI_DMA_FROMDEVICE); |
1da177e4 LT |
6752 | } |
6753 | ||
9205fd9c | 6754 | skb_put(skb, len); |
fb4ce8ad MC |
6755 | if (tstamp) |
6756 | tg3_hwclock_to_timestamp(tp, tstamp, | |
6757 | skb_hwtstamps(skb)); | |
6758 | ||
dc668910 | 6759 | if ((tp->dev->features & NETIF_F_RXCSUM) && |
1da177e4 LT |
6760 | (desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && |
6761 | (((desc->ip_tcp_csum & RXD_TCPCSUM_MASK) | |
6762 | >> RXD_TCPCSUM_SHIFT) == 0xffff)) | |
6763 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
6764 | else | |
bc8acf2c | 6765 | skb_checksum_none_assert(skb); |
1da177e4 LT |
6766 | |
6767 | skb->protocol = eth_type_trans(skb, tp->dev); | |
f7b493e0 MC |
6768 | |
6769 | if (len > (tp->dev->mtu + ETH_HLEN) && | |
6770 | skb->protocol != htons(ETH_P_8021Q)) { | |
6771 | dev_kfree_skb(skb); | |
b0057c51 | 6772 | goto drop_it_no_recycle; |
f7b493e0 MC |
6773 | } |
6774 | ||
9dc7a113 | 6775 | if (desc->type_flags & RXD_FLAG_VLAN && |
bf933c80 | 6776 | !(tp->rx_mode & RX_MODE_KEEP_VLAN_TAG)) |
86a9bad3 | 6777 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), |
bf933c80 | 6778 | desc->err_vlan & RXD_VLAN_MASK); |
9dc7a113 | 6779 | |
bf933c80 | 6780 | napi_gro_receive(&tnapi->napi, skb); |
1da177e4 | 6781 | |
1da177e4 LT |
6782 | received++; |
6783 | budget--; | |
6784 | ||
6785 | next_pkt: | |
6786 | (*post_ptr)++; | |
f92905de MC |
6787 | |
6788 | if (unlikely(rx_std_posted >= tp->rx_std_max_post)) { | |
2c49a44d MC |
6789 | tpr->rx_std_prod_idx = std_prod_idx & |
6790 | tp->rx_std_ring_mask; | |
86cfe4ff MC |
6791 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
6792 | tpr->rx_std_prod_idx); | |
f92905de MC |
6793 | work_mask &= ~RXD_OPAQUE_RING_STD; |
6794 | rx_std_posted = 0; | |
6795 | } | |
1da177e4 | 6796 | next_pkt_nopost: |
483ba50b | 6797 | sw_idx++; |
7cb32cf2 | 6798 | sw_idx &= tp->rx_ret_ring_mask; |
52f6d697 MC |
6799 | |
6800 | /* Refresh hw_idx to see if there is new work */ | |
6801 | if (sw_idx == hw_idx) { | |
8d9d7cfc | 6802 | hw_idx = *(tnapi->rx_rcb_prod_idx); |
52f6d697 MC |
6803 | rmb(); |
6804 | } | |
1da177e4 LT |
6805 | } |
6806 | ||
6807 | /* ACK the status ring. */ | |
72334482 MC |
6808 | tnapi->rx_rcb_ptr = sw_idx; |
6809 | tw32_rx_mbox(tnapi->consmbox, sw_idx); | |
1da177e4 LT |
6810 | |
6811 | /* Refill RX ring(s). */ | |
63c3a66f | 6812 | if (!tg3_flag(tp, ENABLE_RSS)) { |
6541b806 MC |
6813 | /* Sync BD data before updating mailbox */ |
6814 | wmb(); | |
6815 | ||
b196c7e4 | 6816 | if (work_mask & RXD_OPAQUE_RING_STD) { |
2c49a44d MC |
6817 | tpr->rx_std_prod_idx = std_prod_idx & |
6818 | tp->rx_std_ring_mask; | |
b196c7e4 MC |
6819 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, |
6820 | tpr->rx_std_prod_idx); | |
6821 | } | |
6822 | if (work_mask & RXD_OPAQUE_RING_JUMBO) { | |
2c49a44d MC |
6823 | tpr->rx_jmb_prod_idx = jmb_prod_idx & |
6824 | tp->rx_jmb_ring_mask; | |
b196c7e4 MC |
6825 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, |
6826 | tpr->rx_jmb_prod_idx); | |
6827 | } | |
6828 | mmiowb(); | |
6829 | } else if (work_mask) { | |
6830 | /* rx_std_buffers[] and rx_jmb_buffers[] entries must be | |
6831 | * updated before the producer indices can be updated. | |
6832 | */ | |
6833 | smp_wmb(); | |
6834 | ||
2c49a44d MC |
6835 | tpr->rx_std_prod_idx = std_prod_idx & tp->rx_std_ring_mask; |
6836 | tpr->rx_jmb_prod_idx = jmb_prod_idx & tp->rx_jmb_ring_mask; | |
b196c7e4 | 6837 | |
7ae52890 MC |
6838 | if (tnapi != &tp->napi[1]) { |
6839 | tp->rx_refill = true; | |
e4af1af9 | 6840 | napi_schedule(&tp->napi[1].napi); |
7ae52890 | 6841 | } |
1da177e4 | 6842 | } |
1da177e4 LT |
6843 | |
6844 | return received; | |
6845 | } | |
6846 | ||
35f2d7d0 | 6847 | static void tg3_poll_link(struct tg3 *tp) |
1da177e4 | 6848 | { |
1da177e4 | 6849 | /* handle link change and other phy events */ |
63c3a66f | 6850 | if (!(tg3_flag(tp, USE_LINKCHG_REG) || tg3_flag(tp, POLL_SERDES))) { |
35f2d7d0 MC |
6851 | struct tg3_hw_status *sblk = tp->napi[0].hw_status; |
6852 | ||
1da177e4 LT |
6853 | if (sblk->status & SD_STATUS_LINK_CHG) { |
6854 | sblk->status = SD_STATUS_UPDATED | | |
35f2d7d0 | 6855 | (sblk->status & ~SD_STATUS_LINK_CHG); |
f47c11ee | 6856 | spin_lock(&tp->lock); |
63c3a66f | 6857 | if (tg3_flag(tp, USE_PHYLIB)) { |
dd477003 MC |
6858 | tw32_f(MAC_STATUS, |
6859 | (MAC_STATUS_SYNC_CHANGED | | |
6860 | MAC_STATUS_CFG_CHANGED | | |
6861 | MAC_STATUS_MI_COMPLETION | | |
6862 | MAC_STATUS_LNKSTATE_CHANGED)); | |
6863 | udelay(40); | |
6864 | } else | |
953c96e0 | 6865 | tg3_setup_phy(tp, false); |
f47c11ee | 6866 | spin_unlock(&tp->lock); |
1da177e4 LT |
6867 | } |
6868 | } | |
35f2d7d0 MC |
6869 | } |
6870 | ||
f89f38b8 MC |
6871 | static int tg3_rx_prodring_xfer(struct tg3 *tp, |
6872 | struct tg3_rx_prodring_set *dpr, | |
6873 | struct tg3_rx_prodring_set *spr) | |
b196c7e4 MC |
6874 | { |
6875 | u32 si, di, cpycnt, src_prod_idx; | |
f89f38b8 | 6876 | int i, err = 0; |
b196c7e4 MC |
6877 | |
6878 | while (1) { | |
6879 | src_prod_idx = spr->rx_std_prod_idx; | |
6880 | ||
6881 | /* Make sure updates to the rx_std_buffers[] entries and the | |
6882 | * standard producer index are seen in the correct order. | |
6883 | */ | |
6884 | smp_rmb(); | |
6885 | ||
6886 | if (spr->rx_std_cons_idx == src_prod_idx) | |
6887 | break; | |
6888 | ||
6889 | if (spr->rx_std_cons_idx < src_prod_idx) | |
6890 | cpycnt = src_prod_idx - spr->rx_std_cons_idx; | |
6891 | else | |
2c49a44d MC |
6892 | cpycnt = tp->rx_std_ring_mask + 1 - |
6893 | spr->rx_std_cons_idx; | |
b196c7e4 | 6894 | |
2c49a44d MC |
6895 | cpycnt = min(cpycnt, |
6896 | tp->rx_std_ring_mask + 1 - dpr->rx_std_prod_idx); | |
b196c7e4 MC |
6897 | |
6898 | si = spr->rx_std_cons_idx; | |
6899 | di = dpr->rx_std_prod_idx; | |
6900 | ||
e92967bf | 6901 | for (i = di; i < di + cpycnt; i++) { |
9205fd9c | 6902 | if (dpr->rx_std_buffers[i].data) { |
e92967bf | 6903 | cpycnt = i - di; |
f89f38b8 | 6904 | err = -ENOSPC; |
e92967bf MC |
6905 | break; |
6906 | } | |
6907 | } | |
6908 | ||
6909 | if (!cpycnt) | |
6910 | break; | |
6911 | ||
6912 | /* Ensure that updates to the rx_std_buffers ring and the | |
6913 | * shadowed hardware producer ring from tg3_recycle_skb() are | |
6914 | * ordered correctly WRT the skb check above. | |
6915 | */ | |
6916 | smp_rmb(); | |
6917 | ||
b196c7e4 MC |
6918 | memcpy(&dpr->rx_std_buffers[di], |
6919 | &spr->rx_std_buffers[si], | |
6920 | cpycnt * sizeof(struct ring_info)); | |
6921 | ||
6922 | for (i = 0; i < cpycnt; i++, di++, si++) { | |
6923 | struct tg3_rx_buffer_desc *sbd, *dbd; | |
6924 | sbd = &spr->rx_std[si]; | |
6925 | dbd = &dpr->rx_std[di]; | |
6926 | dbd->addr_hi = sbd->addr_hi; | |
6927 | dbd->addr_lo = sbd->addr_lo; | |
6928 | } | |
6929 | ||
2c49a44d MC |
6930 | spr->rx_std_cons_idx = (spr->rx_std_cons_idx + cpycnt) & |
6931 | tp->rx_std_ring_mask; | |
6932 | dpr->rx_std_prod_idx = (dpr->rx_std_prod_idx + cpycnt) & | |
6933 | tp->rx_std_ring_mask; | |
b196c7e4 MC |
6934 | } |
6935 | ||
6936 | while (1) { | |
6937 | src_prod_idx = spr->rx_jmb_prod_idx; | |
6938 | ||
6939 | /* Make sure updates to the rx_jmb_buffers[] entries and | |
6940 | * the jumbo producer index are seen in the correct order. | |
6941 | */ | |
6942 | smp_rmb(); | |
6943 | ||
6944 | if (spr->rx_jmb_cons_idx == src_prod_idx) | |
6945 | break; | |
6946 | ||
6947 | if (spr->rx_jmb_cons_idx < src_prod_idx) | |
6948 | cpycnt = src_prod_idx - spr->rx_jmb_cons_idx; | |
6949 | else | |
2c49a44d MC |
6950 | cpycnt = tp->rx_jmb_ring_mask + 1 - |
6951 | spr->rx_jmb_cons_idx; | |
b196c7e4 MC |
6952 | |
6953 | cpycnt = min(cpycnt, | |
2c49a44d | 6954 | tp->rx_jmb_ring_mask + 1 - dpr->rx_jmb_prod_idx); |
b196c7e4 MC |
6955 | |
6956 | si = spr->rx_jmb_cons_idx; | |
6957 | di = dpr->rx_jmb_prod_idx; | |
6958 | ||
e92967bf | 6959 | for (i = di; i < di + cpycnt; i++) { |
9205fd9c | 6960 | if (dpr->rx_jmb_buffers[i].data) { |
e92967bf | 6961 | cpycnt = i - di; |
f89f38b8 | 6962 | err = -ENOSPC; |
e92967bf MC |
6963 | break; |
6964 | } | |
6965 | } | |
6966 | ||
6967 | if (!cpycnt) | |
6968 | break; | |
6969 | ||
6970 | /* Ensure that updates to the rx_jmb_buffers ring and the | |
6971 | * shadowed hardware producer ring from tg3_recycle_skb() are | |
6972 | * ordered correctly WRT the skb check above. | |
6973 | */ | |
6974 | smp_rmb(); | |
6975 | ||
b196c7e4 MC |
6976 | memcpy(&dpr->rx_jmb_buffers[di], |
6977 | &spr->rx_jmb_buffers[si], | |
6978 | cpycnt * sizeof(struct ring_info)); | |
6979 | ||
6980 | for (i = 0; i < cpycnt; i++, di++, si++) { | |
6981 | struct tg3_rx_buffer_desc *sbd, *dbd; | |
6982 | sbd = &spr->rx_jmb[si].std; | |
6983 | dbd = &dpr->rx_jmb[di].std; | |
6984 | dbd->addr_hi = sbd->addr_hi; | |
6985 | dbd->addr_lo = sbd->addr_lo; | |
6986 | } | |
6987 | ||
2c49a44d MC |
6988 | spr->rx_jmb_cons_idx = (spr->rx_jmb_cons_idx + cpycnt) & |
6989 | tp->rx_jmb_ring_mask; | |
6990 | dpr->rx_jmb_prod_idx = (dpr->rx_jmb_prod_idx + cpycnt) & | |
6991 | tp->rx_jmb_ring_mask; | |
b196c7e4 | 6992 | } |
f89f38b8 MC |
6993 | |
6994 | return err; | |
b196c7e4 MC |
6995 | } |
6996 | ||
35f2d7d0 MC |
6997 | static int tg3_poll_work(struct tg3_napi *tnapi, int work_done, int budget) |
6998 | { | |
6999 | struct tg3 *tp = tnapi->tp; | |
1da177e4 LT |
7000 | |
7001 | /* run TX completion thread */ | |
f3f3f27e | 7002 | if (tnapi->hw_status->idx[0].tx_consumer != tnapi->tx_cons) { |
17375d25 | 7003 | tg3_tx(tnapi); |
63c3a66f | 7004 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
4fd7ab59 | 7005 | return work_done; |
1da177e4 LT |
7006 | } |
7007 | ||
f891ea16 MC |
7008 | if (!tnapi->rx_rcb_prod_idx) |
7009 | return work_done; | |
7010 | ||
1da177e4 LT |
7011 | /* run RX thread, within the bounds set by NAPI. |
7012 | * All RX "locking" is done by ensuring outside | |
bea3348e | 7013 | * code synchronizes with tg3->napi.poll() |
1da177e4 | 7014 | */ |
8d9d7cfc | 7015 | if (*(tnapi->rx_rcb_prod_idx) != tnapi->rx_rcb_ptr) |
17375d25 | 7016 | work_done += tg3_rx(tnapi, budget - work_done); |
1da177e4 | 7017 | |
63c3a66f | 7018 | if (tg3_flag(tp, ENABLE_RSS) && tnapi == &tp->napi[1]) { |
8fea32b9 | 7019 | struct tg3_rx_prodring_set *dpr = &tp->napi[0].prodring; |
f89f38b8 | 7020 | int i, err = 0; |
e4af1af9 MC |
7021 | u32 std_prod_idx = dpr->rx_std_prod_idx; |
7022 | u32 jmb_prod_idx = dpr->rx_jmb_prod_idx; | |
b196c7e4 | 7023 | |
7ae52890 | 7024 | tp->rx_refill = false; |
9102426a | 7025 | for (i = 1; i <= tp->rxq_cnt; i++) |
f89f38b8 | 7026 | err |= tg3_rx_prodring_xfer(tp, dpr, |
8fea32b9 | 7027 | &tp->napi[i].prodring); |
b196c7e4 MC |
7028 | |
7029 | wmb(); | |
7030 | ||
e4af1af9 MC |
7031 | if (std_prod_idx != dpr->rx_std_prod_idx) |
7032 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, | |
7033 | dpr->rx_std_prod_idx); | |
b196c7e4 | 7034 | |
e4af1af9 MC |
7035 | if (jmb_prod_idx != dpr->rx_jmb_prod_idx) |
7036 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, | |
7037 | dpr->rx_jmb_prod_idx); | |
b196c7e4 MC |
7038 | |
7039 | mmiowb(); | |
f89f38b8 MC |
7040 | |
7041 | if (err) | |
7042 | tw32_f(HOSTCC_MODE, tp->coal_now); | |
b196c7e4 MC |
7043 | } |
7044 | ||
6f535763 DM |
7045 | return work_done; |
7046 | } | |
7047 | ||
db219973 MC |
7048 | static inline void tg3_reset_task_schedule(struct tg3 *tp) |
7049 | { | |
7050 | if (!test_and_set_bit(TG3_FLAG_RESET_TASK_PENDING, tp->tg3_flags)) | |
7051 | schedule_work(&tp->reset_task); | |
7052 | } | |
7053 | ||
7054 | static inline void tg3_reset_task_cancel(struct tg3 *tp) | |
7055 | { | |
7056 | cancel_work_sync(&tp->reset_task); | |
7057 | tg3_flag_clear(tp, RESET_TASK_PENDING); | |
c7101359 | 7058 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); |
db219973 MC |
7059 | } |
7060 | ||
35f2d7d0 MC |
7061 | static int tg3_poll_msix(struct napi_struct *napi, int budget) |
7062 | { | |
7063 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); | |
7064 | struct tg3 *tp = tnapi->tp; | |
7065 | int work_done = 0; | |
7066 | struct tg3_hw_status *sblk = tnapi->hw_status; | |
7067 | ||
7068 | while (1) { | |
7069 | work_done = tg3_poll_work(tnapi, work_done, budget); | |
7070 | ||
63c3a66f | 7071 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
35f2d7d0 MC |
7072 | goto tx_recovery; |
7073 | ||
7074 | if (unlikely(work_done >= budget)) | |
7075 | break; | |
7076 | ||
c6cdf436 | 7077 | /* tp->last_tag is used in tg3_int_reenable() below |
35f2d7d0 MC |
7078 | * to tell the hw how much work has been processed, |
7079 | * so we must read it before checking for more work. | |
7080 | */ | |
7081 | tnapi->last_tag = sblk->status_tag; | |
7082 | tnapi->last_irq_tag = tnapi->last_tag; | |
7083 | rmb(); | |
7084 | ||
7085 | /* check for RX/TX work to do */ | |
6d40db7b MC |
7086 | if (likely(sblk->idx[0].tx_consumer == tnapi->tx_cons && |
7087 | *(tnapi->rx_rcb_prod_idx) == tnapi->rx_rcb_ptr)) { | |
7ae52890 MC |
7088 | |
7089 | /* This test here is not race free, but will reduce | |
7090 | * the number of interrupts by looping again. | |
7091 | */ | |
7092 | if (tnapi == &tp->napi[1] && tp->rx_refill) | |
7093 | continue; | |
7094 | ||
35f2d7d0 MC |
7095 | napi_complete(napi); |
7096 | /* Reenable interrupts. */ | |
7097 | tw32_mailbox(tnapi->int_mbox, tnapi->last_tag << 24); | |
7ae52890 MC |
7098 | |
7099 | /* This test here is synchronized by napi_schedule() | |
7100 | * and napi_complete() to close the race condition. | |
7101 | */ | |
7102 | if (unlikely(tnapi == &tp->napi[1] && tp->rx_refill)) { | |
7103 | tw32(HOSTCC_MODE, tp->coalesce_mode | | |
7104 | HOSTCC_MODE_ENABLE | | |
7105 | tnapi->coal_now); | |
7106 | } | |
35f2d7d0 MC |
7107 | mmiowb(); |
7108 | break; | |
7109 | } | |
7110 | } | |
7111 | ||
7112 | return work_done; | |
7113 | ||
7114 | tx_recovery: | |
7115 | /* work_done is guaranteed to be less than budget. */ | |
7116 | napi_complete(napi); | |
db219973 | 7117 | tg3_reset_task_schedule(tp); |
35f2d7d0 MC |
7118 | return work_done; |
7119 | } | |
7120 | ||
e64de4e6 MC |
7121 | static void tg3_process_error(struct tg3 *tp) |
7122 | { | |
7123 | u32 val; | |
7124 | bool real_error = false; | |
7125 | ||
63c3a66f | 7126 | if (tg3_flag(tp, ERROR_PROCESSED)) |
e64de4e6 MC |
7127 | return; |
7128 | ||
7129 | /* Check Flow Attention register */ | |
7130 | val = tr32(HOSTCC_FLOW_ATTN); | |
7131 | if (val & ~HOSTCC_FLOW_ATTN_MBUF_LWM) { | |
7132 | netdev_err(tp->dev, "FLOW Attention error. Resetting chip.\n"); | |
7133 | real_error = true; | |
7134 | } | |
7135 | ||
7136 | if (tr32(MSGINT_STATUS) & ~MSGINT_STATUS_MSI_REQ) { | |
7137 | netdev_err(tp->dev, "MSI Status error. Resetting chip.\n"); | |
7138 | real_error = true; | |
7139 | } | |
7140 | ||
7141 | if (tr32(RDMAC_STATUS) || tr32(WDMAC_STATUS)) { | |
7142 | netdev_err(tp->dev, "DMA Status error. Resetting chip.\n"); | |
7143 | real_error = true; | |
7144 | } | |
7145 | ||
7146 | if (!real_error) | |
7147 | return; | |
7148 | ||
7149 | tg3_dump_state(tp); | |
7150 | ||
63c3a66f | 7151 | tg3_flag_set(tp, ERROR_PROCESSED); |
db219973 | 7152 | tg3_reset_task_schedule(tp); |
e64de4e6 MC |
7153 | } |
7154 | ||
6f535763 DM |
7155 | static int tg3_poll(struct napi_struct *napi, int budget) |
7156 | { | |
8ef0442f MC |
7157 | struct tg3_napi *tnapi = container_of(napi, struct tg3_napi, napi); |
7158 | struct tg3 *tp = tnapi->tp; | |
6f535763 | 7159 | int work_done = 0; |
898a56f8 | 7160 | struct tg3_hw_status *sblk = tnapi->hw_status; |
6f535763 DM |
7161 | |
7162 | while (1) { | |
e64de4e6 MC |
7163 | if (sblk->status & SD_STATUS_ERROR) |
7164 | tg3_process_error(tp); | |
7165 | ||
35f2d7d0 MC |
7166 | tg3_poll_link(tp); |
7167 | ||
17375d25 | 7168 | work_done = tg3_poll_work(tnapi, work_done, budget); |
6f535763 | 7169 | |
63c3a66f | 7170 | if (unlikely(tg3_flag(tp, TX_RECOVERY_PENDING))) |
6f535763 DM |
7171 | goto tx_recovery; |
7172 | ||
7173 | if (unlikely(work_done >= budget)) | |
7174 | break; | |
7175 | ||
63c3a66f | 7176 | if (tg3_flag(tp, TAGGED_STATUS)) { |
17375d25 | 7177 | /* tp->last_tag is used in tg3_int_reenable() below |
4fd7ab59 MC |
7178 | * to tell the hw how much work has been processed, |
7179 | * so we must read it before checking for more work. | |
7180 | */ | |
898a56f8 MC |
7181 | tnapi->last_tag = sblk->status_tag; |
7182 | tnapi->last_irq_tag = tnapi->last_tag; | |
4fd7ab59 MC |
7183 | rmb(); |
7184 | } else | |
7185 | sblk->status &= ~SD_STATUS_UPDATED; | |
6f535763 | 7186 | |
17375d25 | 7187 | if (likely(!tg3_has_work(tnapi))) { |
288379f0 | 7188 | napi_complete(napi); |
17375d25 | 7189 | tg3_int_reenable(tnapi); |
6f535763 DM |
7190 | break; |
7191 | } | |
1da177e4 LT |
7192 | } |
7193 | ||
bea3348e | 7194 | return work_done; |
6f535763 DM |
7195 | |
7196 | tx_recovery: | |
4fd7ab59 | 7197 | /* work_done is guaranteed to be less than budget. */ |
288379f0 | 7198 | napi_complete(napi); |
db219973 | 7199 | tg3_reset_task_schedule(tp); |
4fd7ab59 | 7200 | return work_done; |
1da177e4 LT |
7201 | } |
7202 | ||
66cfd1bd MC |
7203 | static void tg3_napi_disable(struct tg3 *tp) |
7204 | { | |
7205 | int i; | |
7206 | ||
7207 | for (i = tp->irq_cnt - 1; i >= 0; i--) | |
7208 | napi_disable(&tp->napi[i].napi); | |
7209 | } | |
7210 | ||
7211 | static void tg3_napi_enable(struct tg3 *tp) | |
7212 | { | |
7213 | int i; | |
7214 | ||
7215 | for (i = 0; i < tp->irq_cnt; i++) | |
7216 | napi_enable(&tp->napi[i].napi); | |
7217 | } | |
7218 | ||
7219 | static void tg3_napi_init(struct tg3 *tp) | |
7220 | { | |
7221 | int i; | |
7222 | ||
7223 | netif_napi_add(tp->dev, &tp->napi[0].napi, tg3_poll, 64); | |
7224 | for (i = 1; i < tp->irq_cnt; i++) | |
7225 | netif_napi_add(tp->dev, &tp->napi[i].napi, tg3_poll_msix, 64); | |
7226 | } | |
7227 | ||
7228 | static void tg3_napi_fini(struct tg3 *tp) | |
7229 | { | |
7230 | int i; | |
7231 | ||
7232 | for (i = 0; i < tp->irq_cnt; i++) | |
7233 | netif_napi_del(&tp->napi[i].napi); | |
7234 | } | |
7235 | ||
7236 | static inline void tg3_netif_stop(struct tg3 *tp) | |
7237 | { | |
7238 | tp->dev->trans_start = jiffies; /* prevent tx timeout */ | |
7239 | tg3_napi_disable(tp); | |
f4a46d1f | 7240 | netif_carrier_off(tp->dev); |
66cfd1bd MC |
7241 | netif_tx_disable(tp->dev); |
7242 | } | |
7243 | ||
35763066 | 7244 | /* tp->lock must be held */ |
66cfd1bd MC |
7245 | static inline void tg3_netif_start(struct tg3 *tp) |
7246 | { | |
be947307 MC |
7247 | tg3_ptp_resume(tp); |
7248 | ||
66cfd1bd MC |
7249 | /* NOTE: unconditional netif_tx_wake_all_queues is only |
7250 | * appropriate so long as all callers are assured to | |
7251 | * have free tx slots (such as after tg3_init_hw) | |
7252 | */ | |
7253 | netif_tx_wake_all_queues(tp->dev); | |
7254 | ||
f4a46d1f NNS |
7255 | if (tp->link_up) |
7256 | netif_carrier_on(tp->dev); | |
7257 | ||
66cfd1bd MC |
7258 | tg3_napi_enable(tp); |
7259 | tp->napi[0].hw_status->status |= SD_STATUS_UPDATED; | |
7260 | tg3_enable_ints(tp); | |
7261 | } | |
7262 | ||
f47c11ee DM |
7263 | static void tg3_irq_quiesce(struct tg3 *tp) |
7264 | { | |
4f125f42 MC |
7265 | int i; |
7266 | ||
f47c11ee DM |
7267 | BUG_ON(tp->irq_sync); |
7268 | ||
7269 | tp->irq_sync = 1; | |
7270 | smp_mb(); | |
7271 | ||
4f125f42 MC |
7272 | for (i = 0; i < tp->irq_cnt; i++) |
7273 | synchronize_irq(tp->napi[i].irq_vec); | |
f47c11ee DM |
7274 | } |
7275 | ||
f47c11ee DM |
7276 | /* Fully shutdown all tg3 driver activity elsewhere in the system. |
7277 | * If irq_sync is non-zero, then the IRQ handler must be synchronized | |
7278 | * with as well. Most of the time, this is not necessary except when | |
7279 | * shutting down the device. | |
7280 | */ | |
7281 | static inline void tg3_full_lock(struct tg3 *tp, int irq_sync) | |
7282 | { | |
46966545 | 7283 | spin_lock_bh(&tp->lock); |
f47c11ee DM |
7284 | if (irq_sync) |
7285 | tg3_irq_quiesce(tp); | |
f47c11ee DM |
7286 | } |
7287 | ||
7288 | static inline void tg3_full_unlock(struct tg3 *tp) | |
7289 | { | |
f47c11ee DM |
7290 | spin_unlock_bh(&tp->lock); |
7291 | } | |
7292 | ||
fcfa0a32 MC |
7293 | /* One-shot MSI handler - Chip automatically disables interrupt |
7294 | * after sending MSI so driver doesn't have to do it. | |
7295 | */ | |
7d12e780 | 7296 | static irqreturn_t tg3_msi_1shot(int irq, void *dev_id) |
fcfa0a32 | 7297 | { |
09943a18 MC |
7298 | struct tg3_napi *tnapi = dev_id; |
7299 | struct tg3 *tp = tnapi->tp; | |
fcfa0a32 | 7300 | |
898a56f8 | 7301 | prefetch(tnapi->hw_status); |
0c1d0e2b MC |
7302 | if (tnapi->rx_rcb) |
7303 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); | |
fcfa0a32 MC |
7304 | |
7305 | if (likely(!tg3_irq_sync(tp))) | |
09943a18 | 7306 | napi_schedule(&tnapi->napi); |
fcfa0a32 MC |
7307 | |
7308 | return IRQ_HANDLED; | |
7309 | } | |
7310 | ||
88b06bc2 MC |
7311 | /* MSI ISR - No need to check for interrupt sharing and no need to |
7312 | * flush status block and interrupt mailbox. PCI ordering rules | |
7313 | * guarantee that MSI will arrive after the status block. | |
7314 | */ | |
7d12e780 | 7315 | static irqreturn_t tg3_msi(int irq, void *dev_id) |
88b06bc2 | 7316 | { |
09943a18 MC |
7317 | struct tg3_napi *tnapi = dev_id; |
7318 | struct tg3 *tp = tnapi->tp; | |
88b06bc2 | 7319 | |
898a56f8 | 7320 | prefetch(tnapi->hw_status); |
0c1d0e2b MC |
7321 | if (tnapi->rx_rcb) |
7322 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); | |
88b06bc2 | 7323 | /* |
fac9b83e | 7324 | * Writing any value to intr-mbox-0 clears PCI INTA# and |
88b06bc2 | 7325 | * chip-internal interrupt pending events. |
fac9b83e | 7326 | * Writing non-zero to intr-mbox-0 additional tells the |
88b06bc2 MC |
7327 | * NIC to stop sending us irqs, engaging "in-intr-handler" |
7328 | * event coalescing. | |
7329 | */ | |
5b39de91 | 7330 | tw32_mailbox(tnapi->int_mbox, 0x00000001); |
61487480 | 7331 | if (likely(!tg3_irq_sync(tp))) |
09943a18 | 7332 | napi_schedule(&tnapi->napi); |
61487480 | 7333 | |
88b06bc2 MC |
7334 | return IRQ_RETVAL(1); |
7335 | } | |
7336 | ||
7d12e780 | 7337 | static irqreturn_t tg3_interrupt(int irq, void *dev_id) |
1da177e4 | 7338 | { |
09943a18 MC |
7339 | struct tg3_napi *tnapi = dev_id; |
7340 | struct tg3 *tp = tnapi->tp; | |
898a56f8 | 7341 | struct tg3_hw_status *sblk = tnapi->hw_status; |
1da177e4 LT |
7342 | unsigned int handled = 1; |
7343 | ||
1da177e4 LT |
7344 | /* In INTx mode, it is possible for the interrupt to arrive at |
7345 | * the CPU before the status block posted prior to the interrupt. | |
7346 | * Reading the PCI State register will confirm whether the | |
7347 | * interrupt is ours and will flush the status block. | |
7348 | */ | |
d18edcb2 | 7349 | if (unlikely(!(sblk->status & SD_STATUS_UPDATED))) { |
63c3a66f | 7350 | if (tg3_flag(tp, CHIP_RESETTING) || |
d18edcb2 MC |
7351 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
7352 | handled = 0; | |
f47c11ee | 7353 | goto out; |
fac9b83e | 7354 | } |
d18edcb2 MC |
7355 | } |
7356 | ||
7357 | /* | |
7358 | * Writing any value to intr-mbox-0 clears PCI INTA# and | |
7359 | * chip-internal interrupt pending events. | |
7360 | * Writing non-zero to intr-mbox-0 additional tells the | |
7361 | * NIC to stop sending us irqs, engaging "in-intr-handler" | |
7362 | * event coalescing. | |
c04cb347 MC |
7363 | * |
7364 | * Flush the mailbox to de-assert the IRQ immediately to prevent | |
7365 | * spurious interrupts. The flush impacts performance but | |
7366 | * excessive spurious interrupts can be worse in some cases. | |
d18edcb2 | 7367 | */ |
c04cb347 | 7368 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
d18edcb2 MC |
7369 | if (tg3_irq_sync(tp)) |
7370 | goto out; | |
7371 | sblk->status &= ~SD_STATUS_UPDATED; | |
17375d25 | 7372 | if (likely(tg3_has_work(tnapi))) { |
72334482 | 7373 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
09943a18 | 7374 | napi_schedule(&tnapi->napi); |
d18edcb2 MC |
7375 | } else { |
7376 | /* No work, shared interrupt perhaps? re-enable | |
7377 | * interrupts, and flush that PCI write | |
7378 | */ | |
7379 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, | |
7380 | 0x00000000); | |
fac9b83e | 7381 | } |
f47c11ee | 7382 | out: |
fac9b83e DM |
7383 | return IRQ_RETVAL(handled); |
7384 | } | |
7385 | ||
7d12e780 | 7386 | static irqreturn_t tg3_interrupt_tagged(int irq, void *dev_id) |
fac9b83e | 7387 | { |
09943a18 MC |
7388 | struct tg3_napi *tnapi = dev_id; |
7389 | struct tg3 *tp = tnapi->tp; | |
898a56f8 | 7390 | struct tg3_hw_status *sblk = tnapi->hw_status; |
fac9b83e DM |
7391 | unsigned int handled = 1; |
7392 | ||
fac9b83e DM |
7393 | /* In INTx mode, it is possible for the interrupt to arrive at |
7394 | * the CPU before the status block posted prior to the interrupt. | |
7395 | * Reading the PCI State register will confirm whether the | |
7396 | * interrupt is ours and will flush the status block. | |
7397 | */ | |
898a56f8 | 7398 | if (unlikely(sblk->status_tag == tnapi->last_irq_tag)) { |
63c3a66f | 7399 | if (tg3_flag(tp, CHIP_RESETTING) || |
d18edcb2 MC |
7400 | (tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { |
7401 | handled = 0; | |
f47c11ee | 7402 | goto out; |
1da177e4 | 7403 | } |
d18edcb2 MC |
7404 | } |
7405 | ||
7406 | /* | |
7407 | * writing any value to intr-mbox-0 clears PCI INTA# and | |
7408 | * chip-internal interrupt pending events. | |
7409 | * writing non-zero to intr-mbox-0 additional tells the | |
7410 | * NIC to stop sending us irqs, engaging "in-intr-handler" | |
7411 | * event coalescing. | |
c04cb347 MC |
7412 | * |
7413 | * Flush the mailbox to de-assert the IRQ immediately to prevent | |
7414 | * spurious interrupts. The flush impacts performance but | |
7415 | * excessive spurious interrupts can be worse in some cases. | |
d18edcb2 | 7416 | */ |
c04cb347 | 7417 | tw32_mailbox_f(MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW, 0x00000001); |
624f8e50 MC |
7418 | |
7419 | /* | |
7420 | * In a shared interrupt configuration, sometimes other devices' | |
7421 | * interrupts will scream. We record the current status tag here | |
7422 | * so that the above check can report that the screaming interrupts | |
7423 | * are unhandled. Eventually they will be silenced. | |
7424 | */ | |
898a56f8 | 7425 | tnapi->last_irq_tag = sblk->status_tag; |
624f8e50 | 7426 | |
d18edcb2 MC |
7427 | if (tg3_irq_sync(tp)) |
7428 | goto out; | |
624f8e50 | 7429 | |
72334482 | 7430 | prefetch(&tnapi->rx_rcb[tnapi->rx_rcb_ptr]); |
624f8e50 | 7431 | |
09943a18 | 7432 | napi_schedule(&tnapi->napi); |
624f8e50 | 7433 | |
f47c11ee | 7434 | out: |
1da177e4 LT |
7435 | return IRQ_RETVAL(handled); |
7436 | } | |
7437 | ||
7938109f | 7438 | /* ISR for interrupt test */ |
7d12e780 | 7439 | static irqreturn_t tg3_test_isr(int irq, void *dev_id) |
7938109f | 7440 | { |
09943a18 MC |
7441 | struct tg3_napi *tnapi = dev_id; |
7442 | struct tg3 *tp = tnapi->tp; | |
898a56f8 | 7443 | struct tg3_hw_status *sblk = tnapi->hw_status; |
7938109f | 7444 | |
f9804ddb MC |
7445 | if ((sblk->status & SD_STATUS_UPDATED) || |
7446 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_INT_NOT_ACTIVE)) { | |
b16250e3 | 7447 | tg3_disable_ints(tp); |
7938109f MC |
7448 | return IRQ_RETVAL(1); |
7449 | } | |
7450 | return IRQ_RETVAL(0); | |
7451 | } | |
7452 | ||
1da177e4 LT |
7453 | #ifdef CONFIG_NET_POLL_CONTROLLER |
7454 | static void tg3_poll_controller(struct net_device *dev) | |
7455 | { | |
4f125f42 | 7456 | int i; |
88b06bc2 MC |
7457 | struct tg3 *tp = netdev_priv(dev); |
7458 | ||
9c13cb8b NNS |
7459 | if (tg3_irq_sync(tp)) |
7460 | return; | |
7461 | ||
4f125f42 | 7462 | for (i = 0; i < tp->irq_cnt; i++) |
fe234f0e | 7463 | tg3_interrupt(tp->napi[i].irq_vec, &tp->napi[i]); |
1da177e4 LT |
7464 | } |
7465 | #endif | |
7466 | ||
1da177e4 LT |
7467 | static void tg3_tx_timeout(struct net_device *dev) |
7468 | { | |
7469 | struct tg3 *tp = netdev_priv(dev); | |
7470 | ||
b0408751 | 7471 | if (netif_msg_tx_err(tp)) { |
05dbe005 | 7472 | netdev_err(dev, "transmit timed out, resetting\n"); |
97bd8e49 | 7473 | tg3_dump_state(tp); |
b0408751 | 7474 | } |
1da177e4 | 7475 | |
db219973 | 7476 | tg3_reset_task_schedule(tp); |
1da177e4 LT |
7477 | } |
7478 | ||
c58ec932 MC |
7479 | /* Test for DMA buffers crossing any 4GB boundaries: 4G, 8G, etc */ |
7480 | static inline int tg3_4g_overflow_test(dma_addr_t mapping, int len) | |
7481 | { | |
7482 | u32 base = (u32) mapping & 0xffffffff; | |
7483 | ||
a3c448cd | 7484 | return base + len + 8 < base; |
c58ec932 MC |
7485 | } |
7486 | ||
0f0d1510 MC |
7487 | /* Test for TSO DMA buffers that cross into regions which are within MSS bytes |
7488 | * of any 4GB boundaries: 4G, 8G, etc | |
7489 | */ | |
7490 | static inline int tg3_4g_tso_overflow_test(struct tg3 *tp, dma_addr_t mapping, | |
7491 | u32 len, u32 mss) | |
7492 | { | |
7493 | if (tg3_asic_rev(tp) == ASIC_REV_5762 && mss) { | |
7494 | u32 base = (u32) mapping & 0xffffffff; | |
7495 | ||
7496 | return ((base + len + (mss & 0x3fff)) < base); | |
7497 | } | |
7498 | return 0; | |
7499 | } | |
7500 | ||
72f2afb8 MC |
7501 | /* Test for DMA addresses > 40-bit */ |
7502 | static inline int tg3_40bit_overflow_test(struct tg3 *tp, dma_addr_t mapping, | |
7503 | int len) | |
7504 | { | |
7505 | #if defined(CONFIG_HIGHMEM) && (BITS_PER_LONG == 64) | |
63c3a66f | 7506 | if (tg3_flag(tp, 40BIT_DMA_BUG)) |
807540ba | 7507 | return ((u64) mapping + len) > DMA_BIT_MASK(40); |
72f2afb8 MC |
7508 | return 0; |
7509 | #else | |
7510 | return 0; | |
7511 | #endif | |
7512 | } | |
7513 | ||
d1a3b737 | 7514 | static inline void tg3_tx_set_bd(struct tg3_tx_buffer_desc *txbd, |
92cd3a17 MC |
7515 | dma_addr_t mapping, u32 len, u32 flags, |
7516 | u32 mss, u32 vlan) | |
2ffcc981 | 7517 | { |
92cd3a17 MC |
7518 | txbd->addr_hi = ((u64) mapping >> 32); |
7519 | txbd->addr_lo = ((u64) mapping & 0xffffffff); | |
7520 | txbd->len_flags = (len << TXD_LEN_SHIFT) | (flags & 0x0000ffff); | |
7521 | txbd->vlan_tag = (mss << TXD_MSS_SHIFT) | (vlan << TXD_VLAN_TAG_SHIFT); | |
2ffcc981 | 7522 | } |
1da177e4 | 7523 | |
84b67b27 | 7524 | static bool tg3_tx_frag_set(struct tg3_napi *tnapi, u32 *entry, u32 *budget, |
d1a3b737 MC |
7525 | dma_addr_t map, u32 len, u32 flags, |
7526 | u32 mss, u32 vlan) | |
7527 | { | |
7528 | struct tg3 *tp = tnapi->tp; | |
7529 | bool hwbug = false; | |
7530 | ||
7531 | if (tg3_flag(tp, SHORT_DMA_BUG) && len <= 8) | |
3db1cd5c | 7532 | hwbug = true; |
d1a3b737 MC |
7533 | |
7534 | if (tg3_4g_overflow_test(map, len)) | |
3db1cd5c | 7535 | hwbug = true; |
d1a3b737 | 7536 | |
0f0d1510 MC |
7537 | if (tg3_4g_tso_overflow_test(tp, map, len, mss)) |
7538 | hwbug = true; | |
7539 | ||
d1a3b737 | 7540 | if (tg3_40bit_overflow_test(tp, map, len)) |
3db1cd5c | 7541 | hwbug = true; |
d1a3b737 | 7542 | |
a4cb428d | 7543 | if (tp->dma_limit) { |
b9e45482 | 7544 | u32 prvidx = *entry; |
e31aa987 | 7545 | u32 tmp_flag = flags & ~TXD_FLAG_END; |
a4cb428d MC |
7546 | while (len > tp->dma_limit && *budget) { |
7547 | u32 frag_len = tp->dma_limit; | |
7548 | len -= tp->dma_limit; | |
e31aa987 | 7549 | |
b9e45482 MC |
7550 | /* Avoid the 8byte DMA problem */ |
7551 | if (len <= 8) { | |
a4cb428d MC |
7552 | len += tp->dma_limit / 2; |
7553 | frag_len = tp->dma_limit / 2; | |
e31aa987 MC |
7554 | } |
7555 | ||
b9e45482 MC |
7556 | tnapi->tx_buffers[*entry].fragmented = true; |
7557 | ||
7558 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, | |
7559 | frag_len, tmp_flag, mss, vlan); | |
7560 | *budget -= 1; | |
7561 | prvidx = *entry; | |
7562 | *entry = NEXT_TX(*entry); | |
7563 | ||
e31aa987 MC |
7564 | map += frag_len; |
7565 | } | |
7566 | ||
7567 | if (len) { | |
7568 | if (*budget) { | |
7569 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, | |
7570 | len, flags, mss, vlan); | |
b9e45482 | 7571 | *budget -= 1; |
e31aa987 MC |
7572 | *entry = NEXT_TX(*entry); |
7573 | } else { | |
3db1cd5c | 7574 | hwbug = true; |
b9e45482 | 7575 | tnapi->tx_buffers[prvidx].fragmented = false; |
e31aa987 MC |
7576 | } |
7577 | } | |
7578 | } else { | |
84b67b27 MC |
7579 | tg3_tx_set_bd(&tnapi->tx_ring[*entry], map, |
7580 | len, flags, mss, vlan); | |
e31aa987 MC |
7581 | *entry = NEXT_TX(*entry); |
7582 | } | |
d1a3b737 MC |
7583 | |
7584 | return hwbug; | |
7585 | } | |
7586 | ||
0d681b27 | 7587 | static void tg3_tx_skb_unmap(struct tg3_napi *tnapi, u32 entry, int last) |
432aa7ed MC |
7588 | { |
7589 | int i; | |
0d681b27 | 7590 | struct sk_buff *skb; |
df8944cf | 7591 | struct tg3_tx_ring_info *txb = &tnapi->tx_buffers[entry]; |
432aa7ed | 7592 | |
0d681b27 MC |
7593 | skb = txb->skb; |
7594 | txb->skb = NULL; | |
7595 | ||
432aa7ed MC |
7596 | pci_unmap_single(tnapi->tp->pdev, |
7597 | dma_unmap_addr(txb, mapping), | |
7598 | skb_headlen(skb), | |
7599 | PCI_DMA_TODEVICE); | |
e01ee14d MC |
7600 | |
7601 | while (txb->fragmented) { | |
7602 | txb->fragmented = false; | |
7603 | entry = NEXT_TX(entry); | |
7604 | txb = &tnapi->tx_buffers[entry]; | |
7605 | } | |
7606 | ||
ba1142e4 | 7607 | for (i = 0; i <= last; i++) { |
9e903e08 | 7608 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
432aa7ed MC |
7609 | |
7610 | entry = NEXT_TX(entry); | |
7611 | txb = &tnapi->tx_buffers[entry]; | |
7612 | ||
7613 | pci_unmap_page(tnapi->tp->pdev, | |
7614 | dma_unmap_addr(txb, mapping), | |
9e903e08 | 7615 | skb_frag_size(frag), PCI_DMA_TODEVICE); |
e01ee14d MC |
7616 | |
7617 | while (txb->fragmented) { | |
7618 | txb->fragmented = false; | |
7619 | entry = NEXT_TX(entry); | |
7620 | txb = &tnapi->tx_buffers[entry]; | |
7621 | } | |
432aa7ed MC |
7622 | } |
7623 | } | |
7624 | ||
72f2afb8 | 7625 | /* Workaround 4GB and 40-bit hardware DMA bugs. */ |
24f4efd4 | 7626 | static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi, |
f7ff1987 | 7627 | struct sk_buff **pskb, |
84b67b27 | 7628 | u32 *entry, u32 *budget, |
92cd3a17 | 7629 | u32 base_flags, u32 mss, u32 vlan) |
1da177e4 | 7630 | { |
24f4efd4 | 7631 | struct tg3 *tp = tnapi->tp; |
f7ff1987 | 7632 | struct sk_buff *new_skb, *skb = *pskb; |
c58ec932 | 7633 | dma_addr_t new_addr = 0; |
432aa7ed | 7634 | int ret = 0; |
1da177e4 | 7635 | |
4153577a | 7636 | if (tg3_asic_rev(tp) != ASIC_REV_5701) |
41588ba1 MC |
7637 | new_skb = skb_copy(skb, GFP_ATOMIC); |
7638 | else { | |
7639 | int more_headroom = 4 - ((unsigned long)skb->data & 3); | |
7640 | ||
7641 | new_skb = skb_copy_expand(skb, | |
7642 | skb_headroom(skb) + more_headroom, | |
7643 | skb_tailroom(skb), GFP_ATOMIC); | |
7644 | } | |
7645 | ||
1da177e4 | 7646 | if (!new_skb) { |
c58ec932 MC |
7647 | ret = -1; |
7648 | } else { | |
7649 | /* New SKB is guaranteed to be linear. */ | |
f4188d8a AD |
7650 | new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len, |
7651 | PCI_DMA_TODEVICE); | |
7652 | /* Make sure the mapping succeeded */ | |
7653 | if (pci_dma_mapping_error(tp->pdev, new_addr)) { | |
f4188d8a | 7654 | dev_kfree_skb(new_skb); |
c58ec932 | 7655 | ret = -1; |
c58ec932 | 7656 | } else { |
b9e45482 MC |
7657 | u32 save_entry = *entry; |
7658 | ||
92cd3a17 MC |
7659 | base_flags |= TXD_FLAG_END; |
7660 | ||
84b67b27 MC |
7661 | tnapi->tx_buffers[*entry].skb = new_skb; |
7662 | dma_unmap_addr_set(&tnapi->tx_buffers[*entry], | |
432aa7ed MC |
7663 | mapping, new_addr); |
7664 | ||
84b67b27 | 7665 | if (tg3_tx_frag_set(tnapi, entry, budget, new_addr, |
d1a3b737 MC |
7666 | new_skb->len, base_flags, |
7667 | mss, vlan)) { | |
ba1142e4 | 7668 | tg3_tx_skb_unmap(tnapi, save_entry, -1); |
d1a3b737 MC |
7669 | dev_kfree_skb(new_skb); |
7670 | ret = -1; | |
7671 | } | |
f4188d8a | 7672 | } |
1da177e4 LT |
7673 | } |
7674 | ||
7675 | dev_kfree_skb(skb); | |
f7ff1987 | 7676 | *pskb = new_skb; |
c58ec932 | 7677 | return ret; |
1da177e4 LT |
7678 | } |
7679 | ||
2ffcc981 | 7680 | static netdev_tx_t tg3_start_xmit(struct sk_buff *, struct net_device *); |
52c0fd83 MC |
7681 | |
7682 | /* Use GSO to workaround a rare TSO bug that may be triggered when the | |
7683 | * TSO header is greater than 80 bytes. | |
7684 | */ | |
7685 | static int tg3_tso_bug(struct tg3 *tp, struct sk_buff *skb) | |
7686 | { | |
7687 | struct sk_buff *segs, *nskb; | |
f3f3f27e | 7688 | u32 frag_cnt_est = skb_shinfo(skb)->gso_segs * 3; |
52c0fd83 MC |
7689 | |
7690 | /* Estimate the number of fragments in the worst case */ | |
f3f3f27e | 7691 | if (unlikely(tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est)) { |
52c0fd83 | 7692 | netif_stop_queue(tp->dev); |
f65aac16 MC |
7693 | |
7694 | /* netif_tx_stop_queue() must be done before checking | |
7695 | * checking tx index in tg3_tx_avail() below, because in | |
7696 | * tg3_tx(), we update tx index before checking for | |
7697 | * netif_tx_queue_stopped(). | |
7698 | */ | |
7699 | smp_mb(); | |
f3f3f27e | 7700 | if (tg3_tx_avail(&tp->napi[0]) <= frag_cnt_est) |
7f62ad5d MC |
7701 | return NETDEV_TX_BUSY; |
7702 | ||
7703 | netif_wake_queue(tp->dev); | |
52c0fd83 MC |
7704 | } |
7705 | ||
7706 | segs = skb_gso_segment(skb, tp->dev->features & ~NETIF_F_TSO); | |
801678c5 | 7707 | if (IS_ERR(segs)) |
52c0fd83 MC |
7708 | goto tg3_tso_bug_end; |
7709 | ||
7710 | do { | |
7711 | nskb = segs; | |
7712 | segs = segs->next; | |
7713 | nskb->next = NULL; | |
2ffcc981 | 7714 | tg3_start_xmit(nskb, tp->dev); |
52c0fd83 MC |
7715 | } while (segs); |
7716 | ||
7717 | tg3_tso_bug_end: | |
7718 | dev_kfree_skb(skb); | |
7719 | ||
7720 | return NETDEV_TX_OK; | |
7721 | } | |
52c0fd83 | 7722 | |
5a6f3074 | 7723 | /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and |
63c3a66f | 7724 | * support TG3_FLAG_HW_TSO_1 or firmware TSO only. |
5a6f3074 | 7725 | */ |
2ffcc981 | 7726 | static netdev_tx_t tg3_start_xmit(struct sk_buff *skb, struct net_device *dev) |
1da177e4 LT |
7727 | { |
7728 | struct tg3 *tp = netdev_priv(dev); | |
92cd3a17 | 7729 | u32 len, entry, base_flags, mss, vlan = 0; |
84b67b27 | 7730 | u32 budget; |
432aa7ed | 7731 | int i = -1, would_hit_hwbug; |
90079ce8 | 7732 | dma_addr_t mapping; |
24f4efd4 MC |
7733 | struct tg3_napi *tnapi; |
7734 | struct netdev_queue *txq; | |
432aa7ed | 7735 | unsigned int last; |
f4188d8a | 7736 | |
24f4efd4 MC |
7737 | txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb)); |
7738 | tnapi = &tp->napi[skb_get_queue_mapping(skb)]; | |
63c3a66f | 7739 | if (tg3_flag(tp, ENABLE_TSS)) |
24f4efd4 | 7740 | tnapi++; |
1da177e4 | 7741 | |
84b67b27 MC |
7742 | budget = tg3_tx_avail(tnapi); |
7743 | ||
00b70504 | 7744 | /* We are running in BH disabled context with netif_tx_lock |
bea3348e | 7745 | * and TX reclaim runs via tp->napi.poll inside of a software |
f47c11ee DM |
7746 | * interrupt. Furthermore, IRQ processing runs lockless so we have |
7747 | * no IRQ context deadlocks to worry about either. Rejoice! | |
1da177e4 | 7748 | */ |
84b67b27 | 7749 | if (unlikely(budget <= (skb_shinfo(skb)->nr_frags + 1))) { |
24f4efd4 MC |
7750 | if (!netif_tx_queue_stopped(txq)) { |
7751 | netif_tx_stop_queue(txq); | |
1f064a87 SH |
7752 | |
7753 | /* This is a hard error, log it. */ | |
5129c3a3 MC |
7754 | netdev_err(dev, |
7755 | "BUG! Tx Ring full when queue awake!\n"); | |
1f064a87 | 7756 | } |
1da177e4 LT |
7757 | return NETDEV_TX_BUSY; |
7758 | } | |
7759 | ||
f3f3f27e | 7760 | entry = tnapi->tx_prod; |
1da177e4 | 7761 | base_flags = 0; |
24f4efd4 | 7762 | |
be98da6a MC |
7763 | mss = skb_shinfo(skb)->gso_size; |
7764 | if (mss) { | |
eddc9ec5 | 7765 | struct iphdr *iph; |
34195c3d | 7766 | u32 tcp_opt_len, hdr_len; |
1da177e4 LT |
7767 | |
7768 | if (skb_header_cloned(skb) && | |
48855432 ED |
7769 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) |
7770 | goto drop; | |
1da177e4 | 7771 | |
34195c3d | 7772 | iph = ip_hdr(skb); |
ab6a5bb6 | 7773 | tcp_opt_len = tcp_optlen(skb); |
1da177e4 | 7774 | |
a5a11955 | 7775 | hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb) - ETH_HLEN; |
34195c3d | 7776 | |
654850db VY |
7777 | /* HW/FW can not correctly segment packets that have been |
7778 | * vlan encapsulated. | |
7779 | */ | |
7780 | if (skb->protocol == htons(ETH_P_8021Q) || | |
7781 | skb->protocol == htons(ETH_P_8021AD)) | |
7782 | return tg3_tso_bug(tp, skb); | |
7783 | ||
a5a11955 | 7784 | if (!skb_is_gso_v6(skb)) { |
34195c3d MC |
7785 | iph->check = 0; |
7786 | iph->tot_len = htons(mss + hdr_len); | |
7787 | } | |
7788 | ||
52c0fd83 | 7789 | if (unlikely((ETH_HLEN + hdr_len) > 80) && |
63c3a66f | 7790 | tg3_flag(tp, TSO_BUG)) |
de6f31eb | 7791 | return tg3_tso_bug(tp, skb); |
52c0fd83 | 7792 | |
1da177e4 LT |
7793 | base_flags |= (TXD_FLAG_CPU_PRE_DMA | |
7794 | TXD_FLAG_CPU_POST_DMA); | |
7795 | ||
63c3a66f JP |
7796 | if (tg3_flag(tp, HW_TSO_1) || |
7797 | tg3_flag(tp, HW_TSO_2) || | |
7798 | tg3_flag(tp, HW_TSO_3)) { | |
aa8223c7 | 7799 | tcp_hdr(skb)->check = 0; |
1da177e4 | 7800 | base_flags &= ~TXD_FLAG_TCPUDP_CSUM; |
aa8223c7 ACM |
7801 | } else |
7802 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, | |
7803 | iph->daddr, 0, | |
7804 | IPPROTO_TCP, | |
7805 | 0); | |
1da177e4 | 7806 | |
63c3a66f | 7807 | if (tg3_flag(tp, HW_TSO_3)) { |
615774fe MC |
7808 | mss |= (hdr_len & 0xc) << 12; |
7809 | if (hdr_len & 0x10) | |
7810 | base_flags |= 0x00000010; | |
7811 | base_flags |= (hdr_len & 0x3e0) << 5; | |
63c3a66f | 7812 | } else if (tg3_flag(tp, HW_TSO_2)) |
92c6b8d1 | 7813 | mss |= hdr_len << 9; |
63c3a66f | 7814 | else if (tg3_flag(tp, HW_TSO_1) || |
4153577a | 7815 | tg3_asic_rev(tp) == ASIC_REV_5705) { |
eddc9ec5 | 7816 | if (tcp_opt_len || iph->ihl > 5) { |
1da177e4 LT |
7817 | int tsflags; |
7818 | ||
eddc9ec5 | 7819 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
1da177e4 LT |
7820 | mss |= (tsflags << 11); |
7821 | } | |
7822 | } else { | |
eddc9ec5 | 7823 | if (tcp_opt_len || iph->ihl > 5) { |
1da177e4 LT |
7824 | int tsflags; |
7825 | ||
eddc9ec5 | 7826 | tsflags = (iph->ihl - 5) + (tcp_opt_len >> 2); |
1da177e4 LT |
7827 | base_flags |= tsflags << 12; |
7828 | } | |
7829 | } | |
654850db VY |
7830 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
7831 | /* HW/FW can not correctly checksum packets that have been | |
7832 | * vlan encapsulated. | |
7833 | */ | |
7834 | if (skb->protocol == htons(ETH_P_8021Q) || | |
7835 | skb->protocol == htons(ETH_P_8021AD)) { | |
7836 | if (skb_checksum_help(skb)) | |
7837 | goto drop; | |
7838 | } else { | |
7839 | base_flags |= TXD_FLAG_TCPUDP_CSUM; | |
7840 | } | |
1da177e4 | 7841 | } |
bf933c80 | 7842 | |
93a700a9 MC |
7843 | if (tg3_flag(tp, USE_JUMBO_BDFLAG) && |
7844 | !mss && skb->len > VLAN_ETH_FRAME_LEN) | |
7845 | base_flags |= TXD_FLAG_JMB_PKT; | |
7846 | ||
92cd3a17 MC |
7847 | if (vlan_tx_tag_present(skb)) { |
7848 | base_flags |= TXD_FLAG_VLAN; | |
7849 | vlan = vlan_tx_tag_get(skb); | |
7850 | } | |
1da177e4 | 7851 | |
fb4ce8ad MC |
7852 | if ((unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) && |
7853 | tg3_flag(tp, TX_TSTAMP_EN)) { | |
7854 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; | |
7855 | base_flags |= TXD_FLAG_HWTSTAMP; | |
7856 | } | |
7857 | ||
f4188d8a AD |
7858 | len = skb_headlen(skb); |
7859 | ||
7860 | mapping = pci_map_single(tp->pdev, skb->data, len, PCI_DMA_TODEVICE); | |
48855432 ED |
7861 | if (pci_dma_mapping_error(tp->pdev, mapping)) |
7862 | goto drop; | |
7863 | ||
90079ce8 | 7864 | |
f3f3f27e | 7865 | tnapi->tx_buffers[entry].skb = skb; |
4e5e4f0d | 7866 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, mapping); |
1da177e4 LT |
7867 | |
7868 | would_hit_hwbug = 0; | |
7869 | ||
63c3a66f | 7870 | if (tg3_flag(tp, 5701_DMA_BUG)) |
c58ec932 | 7871 | would_hit_hwbug = 1; |
1da177e4 | 7872 | |
84b67b27 | 7873 | if (tg3_tx_frag_set(tnapi, &entry, &budget, mapping, len, base_flags | |
d1a3b737 | 7874 | ((skb_shinfo(skb)->nr_frags == 0) ? TXD_FLAG_END : 0), |
ba1142e4 | 7875 | mss, vlan)) { |
d1a3b737 | 7876 | would_hit_hwbug = 1; |
ba1142e4 | 7877 | } else if (skb_shinfo(skb)->nr_frags > 0) { |
92cd3a17 MC |
7878 | u32 tmp_mss = mss; |
7879 | ||
7880 | if (!tg3_flag(tp, HW_TSO_1) && | |
7881 | !tg3_flag(tp, HW_TSO_2) && | |
7882 | !tg3_flag(tp, HW_TSO_3)) | |
7883 | tmp_mss = 0; | |
7884 | ||
c5665a53 MC |
7885 | /* Now loop through additional data |
7886 | * fragments, and queue them. | |
7887 | */ | |
1da177e4 LT |
7888 | last = skb_shinfo(skb)->nr_frags - 1; |
7889 | for (i = 0; i <= last; i++) { | |
7890 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | |
7891 | ||
9e903e08 | 7892 | len = skb_frag_size(frag); |
dc234d0b | 7893 | mapping = skb_frag_dma_map(&tp->pdev->dev, frag, 0, |
5d6bcdfe | 7894 | len, DMA_TO_DEVICE); |
1da177e4 | 7895 | |
f3f3f27e | 7896 | tnapi->tx_buffers[entry].skb = NULL; |
4e5e4f0d | 7897 | dma_unmap_addr_set(&tnapi->tx_buffers[entry], mapping, |
f4188d8a | 7898 | mapping); |
5d6bcdfe | 7899 | if (dma_mapping_error(&tp->pdev->dev, mapping)) |
f4188d8a | 7900 | goto dma_error; |
1da177e4 | 7901 | |
b9e45482 MC |
7902 | if (!budget || |
7903 | tg3_tx_frag_set(tnapi, &entry, &budget, mapping, | |
84b67b27 MC |
7904 | len, base_flags | |
7905 | ((i == last) ? TXD_FLAG_END : 0), | |
b9e45482 | 7906 | tmp_mss, vlan)) { |
72f2afb8 | 7907 | would_hit_hwbug = 1; |
b9e45482 MC |
7908 | break; |
7909 | } | |
1da177e4 LT |
7910 | } |
7911 | } | |
7912 | ||
7913 | if (would_hit_hwbug) { | |
0d681b27 | 7914 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, i); |
1da177e4 LT |
7915 | |
7916 | /* If the workaround fails due to memory/mapping | |
7917 | * failure, silently drop this packet. | |
7918 | */ | |
84b67b27 MC |
7919 | entry = tnapi->tx_prod; |
7920 | budget = tg3_tx_avail(tnapi); | |
f7ff1987 | 7921 | if (tigon3_dma_hwbug_workaround(tnapi, &skb, &entry, &budget, |
84b67b27 | 7922 | base_flags, mss, vlan)) |
48855432 | 7923 | goto drop_nofree; |
1da177e4 LT |
7924 | } |
7925 | ||
d515b450 | 7926 | skb_tx_timestamp(skb); |
5cb917bc | 7927 | netdev_tx_sent_queue(txq, skb->len); |
d515b450 | 7928 | |
6541b806 MC |
7929 | /* Sync BD data before updating mailbox */ |
7930 | wmb(); | |
7931 | ||
1da177e4 | 7932 | /* Packets are ready, update Tx producer idx local and on card. */ |
24f4efd4 | 7933 | tw32_tx_mbox(tnapi->prodmbox, entry); |
1da177e4 | 7934 | |
f3f3f27e MC |
7935 | tnapi->tx_prod = entry; |
7936 | if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) { | |
24f4efd4 | 7937 | netif_tx_stop_queue(txq); |
f65aac16 MC |
7938 | |
7939 | /* netif_tx_stop_queue() must be done before checking | |
7940 | * checking tx index in tg3_tx_avail() below, because in | |
7941 | * tg3_tx(), we update tx index before checking for | |
7942 | * netif_tx_queue_stopped(). | |
7943 | */ | |
7944 | smp_mb(); | |
f3f3f27e | 7945 | if (tg3_tx_avail(tnapi) > TG3_TX_WAKEUP_THRESH(tnapi)) |
24f4efd4 | 7946 | netif_tx_wake_queue(txq); |
51b91468 | 7947 | } |
1da177e4 | 7948 | |
cdd0db05 | 7949 | mmiowb(); |
1da177e4 | 7950 | return NETDEV_TX_OK; |
f4188d8a AD |
7951 | |
7952 | dma_error: | |
ba1142e4 | 7953 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod, --i); |
432aa7ed | 7954 | tnapi->tx_buffers[tnapi->tx_prod].skb = NULL; |
48855432 ED |
7955 | drop: |
7956 | dev_kfree_skb(skb); | |
7957 | drop_nofree: | |
7958 | tp->tx_dropped++; | |
f4188d8a | 7959 | return NETDEV_TX_OK; |
1da177e4 LT |
7960 | } |
7961 | ||
6e01b20b MC |
7962 | static void tg3_mac_loopback(struct tg3 *tp, bool enable) |
7963 | { | |
7964 | if (enable) { | |
7965 | tp->mac_mode &= ~(MAC_MODE_HALF_DUPLEX | | |
7966 | MAC_MODE_PORT_MODE_MASK); | |
7967 | ||
7968 | tp->mac_mode |= MAC_MODE_PORT_INT_LPBACK; | |
7969 | ||
7970 | if (!tg3_flag(tp, 5705_PLUS)) | |
7971 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; | |
7972 | ||
7973 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) | |
7974 | tp->mac_mode |= MAC_MODE_PORT_MODE_MII; | |
7975 | else | |
7976 | tp->mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
7977 | } else { | |
7978 | tp->mac_mode &= ~MAC_MODE_PORT_INT_LPBACK; | |
7979 | ||
7980 | if (tg3_flag(tp, 5705_PLUS) || | |
7981 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) || | |
4153577a | 7982 | tg3_asic_rev(tp) == ASIC_REV_5700) |
6e01b20b MC |
7983 | tp->mac_mode &= ~MAC_MODE_LINK_POLARITY; |
7984 | } | |
7985 | ||
7986 | tw32(MAC_MODE, tp->mac_mode); | |
7987 | udelay(40); | |
7988 | } | |
7989 | ||
941ec90f | 7990 | static int tg3_phy_lpbk_set(struct tg3 *tp, u32 speed, bool extlpbk) |
5e5a7f37 | 7991 | { |
941ec90f | 7992 | u32 val, bmcr, mac_mode, ptest = 0; |
5e5a7f37 MC |
7993 | |
7994 | tg3_phy_toggle_apd(tp, false); | |
953c96e0 | 7995 | tg3_phy_toggle_automdix(tp, false); |
5e5a7f37 | 7996 | |
941ec90f MC |
7997 | if (extlpbk && tg3_phy_set_extloopbk(tp)) |
7998 | return -EIO; | |
7999 | ||
8000 | bmcr = BMCR_FULLDPLX; | |
5e5a7f37 MC |
8001 | switch (speed) { |
8002 | case SPEED_10: | |
8003 | break; | |
8004 | case SPEED_100: | |
8005 | bmcr |= BMCR_SPEED100; | |
8006 | break; | |
8007 | case SPEED_1000: | |
8008 | default: | |
8009 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) { | |
8010 | speed = SPEED_100; | |
8011 | bmcr |= BMCR_SPEED100; | |
8012 | } else { | |
8013 | speed = SPEED_1000; | |
8014 | bmcr |= BMCR_SPEED1000; | |
8015 | } | |
8016 | } | |
8017 | ||
941ec90f MC |
8018 | if (extlpbk) { |
8019 | if (!(tp->phy_flags & TG3_PHYFLG_IS_FET)) { | |
8020 | tg3_readphy(tp, MII_CTRL1000, &val); | |
8021 | val |= CTL1000_AS_MASTER | | |
8022 | CTL1000_ENABLE_MASTER; | |
8023 | tg3_writephy(tp, MII_CTRL1000, val); | |
8024 | } else { | |
8025 | ptest = MII_TG3_FET_PTEST_TRIM_SEL | | |
8026 | MII_TG3_FET_PTEST_TRIM_2; | |
8027 | tg3_writephy(tp, MII_TG3_FET_PTEST, ptest); | |
8028 | } | |
8029 | } else | |
8030 | bmcr |= BMCR_LOOPBACK; | |
8031 | ||
5e5a7f37 MC |
8032 | tg3_writephy(tp, MII_BMCR, bmcr); |
8033 | ||
8034 | /* The write needs to be flushed for the FETs */ | |
8035 | if (tp->phy_flags & TG3_PHYFLG_IS_FET) | |
8036 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
8037 | ||
8038 | udelay(40); | |
8039 | ||
8040 | if ((tp->phy_flags & TG3_PHYFLG_IS_FET) && | |
4153577a | 8041 | tg3_asic_rev(tp) == ASIC_REV_5785) { |
941ec90f | 8042 | tg3_writephy(tp, MII_TG3_FET_PTEST, ptest | |
5e5a7f37 MC |
8043 | MII_TG3_FET_PTEST_FRC_TX_LINK | |
8044 | MII_TG3_FET_PTEST_FRC_TX_LOCK); | |
8045 | ||
8046 | /* The write needs to be flushed for the AC131 */ | |
8047 | tg3_readphy(tp, MII_TG3_FET_PTEST, &val); | |
8048 | } | |
8049 | ||
8050 | /* Reset to prevent losing 1st rx packet intermittently */ | |
8051 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && | |
8052 | tg3_flag(tp, 5780_CLASS)) { | |
8053 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); | |
8054 | udelay(10); | |
8055 | tw32_f(MAC_RX_MODE, tp->rx_mode); | |
8056 | } | |
8057 | ||
8058 | mac_mode = tp->mac_mode & | |
8059 | ~(MAC_MODE_PORT_MODE_MASK | MAC_MODE_HALF_DUPLEX); | |
8060 | if (speed == SPEED_1000) | |
8061 | mac_mode |= MAC_MODE_PORT_MODE_GMII; | |
8062 | else | |
8063 | mac_mode |= MAC_MODE_PORT_MODE_MII; | |
8064 | ||
4153577a | 8065 | if (tg3_asic_rev(tp) == ASIC_REV_5700) { |
5e5a7f37 MC |
8066 | u32 masked_phy_id = tp->phy_id & TG3_PHY_ID_MASK; |
8067 | ||
8068 | if (masked_phy_id == TG3_PHY_ID_BCM5401) | |
8069 | mac_mode &= ~MAC_MODE_LINK_POLARITY; | |
8070 | else if (masked_phy_id == TG3_PHY_ID_BCM5411) | |
8071 | mac_mode |= MAC_MODE_LINK_POLARITY; | |
8072 | ||
8073 | tg3_writephy(tp, MII_TG3_EXT_CTRL, | |
8074 | MII_TG3_EXT_CTRL_LNK3_LED_MODE); | |
8075 | } | |
8076 | ||
8077 | tw32(MAC_MODE, mac_mode); | |
8078 | udelay(40); | |
941ec90f MC |
8079 | |
8080 | return 0; | |
5e5a7f37 MC |
8081 | } |
8082 | ||
c8f44aff | 8083 | static void tg3_set_loopback(struct net_device *dev, netdev_features_t features) |
06c03c02 MB |
8084 | { |
8085 | struct tg3 *tp = netdev_priv(dev); | |
8086 | ||
8087 | if (features & NETIF_F_LOOPBACK) { | |
8088 | if (tp->mac_mode & MAC_MODE_PORT_INT_LPBACK) | |
8089 | return; | |
8090 | ||
06c03c02 | 8091 | spin_lock_bh(&tp->lock); |
6e01b20b | 8092 | tg3_mac_loopback(tp, true); |
06c03c02 MB |
8093 | netif_carrier_on(tp->dev); |
8094 | spin_unlock_bh(&tp->lock); | |
8095 | netdev_info(dev, "Internal MAC loopback mode enabled.\n"); | |
8096 | } else { | |
8097 | if (!(tp->mac_mode & MAC_MODE_PORT_INT_LPBACK)) | |
8098 | return; | |
8099 | ||
06c03c02 | 8100 | spin_lock_bh(&tp->lock); |
6e01b20b | 8101 | tg3_mac_loopback(tp, false); |
06c03c02 | 8102 | /* Force link status check */ |
953c96e0 | 8103 | tg3_setup_phy(tp, true); |
06c03c02 MB |
8104 | spin_unlock_bh(&tp->lock); |
8105 | netdev_info(dev, "Internal MAC loopback mode disabled.\n"); | |
8106 | } | |
8107 | } | |
8108 | ||
c8f44aff MM |
8109 | static netdev_features_t tg3_fix_features(struct net_device *dev, |
8110 | netdev_features_t features) | |
dc668910 MM |
8111 | { |
8112 | struct tg3 *tp = netdev_priv(dev); | |
8113 | ||
63c3a66f | 8114 | if (dev->mtu > ETH_DATA_LEN && tg3_flag(tp, 5780_CLASS)) |
dc668910 MM |
8115 | features &= ~NETIF_F_ALL_TSO; |
8116 | ||
8117 | return features; | |
8118 | } | |
8119 | ||
c8f44aff | 8120 | static int tg3_set_features(struct net_device *dev, netdev_features_t features) |
06c03c02 | 8121 | { |
c8f44aff | 8122 | netdev_features_t changed = dev->features ^ features; |
06c03c02 MB |
8123 | |
8124 | if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) | |
8125 | tg3_set_loopback(dev, features); | |
8126 | ||
8127 | return 0; | |
8128 | } | |
8129 | ||
21f581a5 MC |
8130 | static void tg3_rx_prodring_free(struct tg3 *tp, |
8131 | struct tg3_rx_prodring_set *tpr) | |
1da177e4 | 8132 | { |
1da177e4 LT |
8133 | int i; |
8134 | ||
8fea32b9 | 8135 | if (tpr != &tp->napi[0].prodring) { |
b196c7e4 | 8136 | for (i = tpr->rx_std_cons_idx; i != tpr->rx_std_prod_idx; |
2c49a44d | 8137 | i = (i + 1) & tp->rx_std_ring_mask) |
9205fd9c | 8138 | tg3_rx_data_free(tp, &tpr->rx_std_buffers[i], |
b196c7e4 MC |
8139 | tp->rx_pkt_map_sz); |
8140 | ||
63c3a66f | 8141 | if (tg3_flag(tp, JUMBO_CAPABLE)) { |
b196c7e4 MC |
8142 | for (i = tpr->rx_jmb_cons_idx; |
8143 | i != tpr->rx_jmb_prod_idx; | |
2c49a44d | 8144 | i = (i + 1) & tp->rx_jmb_ring_mask) { |
9205fd9c | 8145 | tg3_rx_data_free(tp, &tpr->rx_jmb_buffers[i], |
b196c7e4 MC |
8146 | TG3_RX_JMB_MAP_SZ); |
8147 | } | |
8148 | } | |
8149 | ||
2b2cdb65 | 8150 | return; |
b196c7e4 | 8151 | } |
1da177e4 | 8152 | |
2c49a44d | 8153 | for (i = 0; i <= tp->rx_std_ring_mask; i++) |
9205fd9c | 8154 | tg3_rx_data_free(tp, &tpr->rx_std_buffers[i], |
2b2cdb65 | 8155 | tp->rx_pkt_map_sz); |
1da177e4 | 8156 | |
63c3a66f | 8157 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
2c49a44d | 8158 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) |
9205fd9c | 8159 | tg3_rx_data_free(tp, &tpr->rx_jmb_buffers[i], |
2b2cdb65 | 8160 | TG3_RX_JMB_MAP_SZ); |
1da177e4 LT |
8161 | } |
8162 | } | |
8163 | ||
c6cdf436 | 8164 | /* Initialize rx rings for packet processing. |
1da177e4 LT |
8165 | * |
8166 | * The chip has been shut down and the driver detached from | |
8167 | * the networking, so no interrupts or new tx packets will | |
8168 | * end up in the driver. tp->{tx,}lock are held and thus | |
8169 | * we may not sleep. | |
8170 | */ | |
21f581a5 MC |
8171 | static int tg3_rx_prodring_alloc(struct tg3 *tp, |
8172 | struct tg3_rx_prodring_set *tpr) | |
1da177e4 | 8173 | { |
287be12e | 8174 | u32 i, rx_pkt_dma_sz; |
1da177e4 | 8175 | |
b196c7e4 MC |
8176 | tpr->rx_std_cons_idx = 0; |
8177 | tpr->rx_std_prod_idx = 0; | |
8178 | tpr->rx_jmb_cons_idx = 0; | |
8179 | tpr->rx_jmb_prod_idx = 0; | |
8180 | ||
8fea32b9 | 8181 | if (tpr != &tp->napi[0].prodring) { |
2c49a44d MC |
8182 | memset(&tpr->rx_std_buffers[0], 0, |
8183 | TG3_RX_STD_BUFF_RING_SIZE(tp)); | |
48035728 | 8184 | if (tpr->rx_jmb_buffers) |
2b2cdb65 | 8185 | memset(&tpr->rx_jmb_buffers[0], 0, |
2c49a44d | 8186 | TG3_RX_JMB_BUFF_RING_SIZE(tp)); |
2b2cdb65 MC |
8187 | goto done; |
8188 | } | |
8189 | ||
1da177e4 | 8190 | /* Zero out all descriptors. */ |
2c49a44d | 8191 | memset(tpr->rx_std, 0, TG3_RX_STD_RING_BYTES(tp)); |
1da177e4 | 8192 | |
287be12e | 8193 | rx_pkt_dma_sz = TG3_RX_STD_DMA_SZ; |
63c3a66f | 8194 | if (tg3_flag(tp, 5780_CLASS) && |
287be12e MC |
8195 | tp->dev->mtu > ETH_DATA_LEN) |
8196 | rx_pkt_dma_sz = TG3_RX_JMB_DMA_SZ; | |
8197 | tp->rx_pkt_map_sz = TG3_RX_DMA_TO_MAP_SZ(rx_pkt_dma_sz); | |
7e72aad4 | 8198 | |
1da177e4 LT |
8199 | /* Initialize invariants of the rings, we only set this |
8200 | * stuff once. This works because the card does not | |
8201 | * write into the rx buffer posting rings. | |
8202 | */ | |
2c49a44d | 8203 | for (i = 0; i <= tp->rx_std_ring_mask; i++) { |
1da177e4 LT |
8204 | struct tg3_rx_buffer_desc *rxd; |
8205 | ||
21f581a5 | 8206 | rxd = &tpr->rx_std[i]; |
287be12e | 8207 | rxd->idx_len = rx_pkt_dma_sz << RXD_LEN_SHIFT; |
1da177e4 LT |
8208 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT); |
8209 | rxd->opaque = (RXD_OPAQUE_RING_STD | | |
8210 | (i << RXD_OPAQUE_INDEX_SHIFT)); | |
8211 | } | |
8212 | ||
1da177e4 LT |
8213 | /* Now allocate fresh SKBs for each rx ring. */ |
8214 | for (i = 0; i < tp->rx_pending; i++) { | |
8d4057a9 ED |
8215 | unsigned int frag_size; |
8216 | ||
8217 | if (tg3_alloc_rx_data(tp, tpr, RXD_OPAQUE_RING_STD, i, | |
8218 | &frag_size) < 0) { | |
5129c3a3 MC |
8219 | netdev_warn(tp->dev, |
8220 | "Using a smaller RX standard ring. Only " | |
8221 | "%d out of %d buffers were allocated " | |
8222 | "successfully\n", i, tp->rx_pending); | |
32d8c572 | 8223 | if (i == 0) |
cf7a7298 | 8224 | goto initfail; |
32d8c572 | 8225 | tp->rx_pending = i; |
1da177e4 | 8226 | break; |
32d8c572 | 8227 | } |
1da177e4 LT |
8228 | } |
8229 | ||
63c3a66f | 8230 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
cf7a7298 MC |
8231 | goto done; |
8232 | ||
2c49a44d | 8233 | memset(tpr->rx_jmb, 0, TG3_RX_JMB_RING_BYTES(tp)); |
cf7a7298 | 8234 | |
63c3a66f | 8235 | if (!tg3_flag(tp, JUMBO_RING_ENABLE)) |
0d86df80 | 8236 | goto done; |
cf7a7298 | 8237 | |
2c49a44d | 8238 | for (i = 0; i <= tp->rx_jmb_ring_mask; i++) { |
0d86df80 MC |
8239 | struct tg3_rx_buffer_desc *rxd; |
8240 | ||
8241 | rxd = &tpr->rx_jmb[i].std; | |
8242 | rxd->idx_len = TG3_RX_JMB_DMA_SZ << RXD_LEN_SHIFT; | |
8243 | rxd->type_flags = (RXD_FLAG_END << RXD_FLAGS_SHIFT) | | |
8244 | RXD_FLAG_JUMBO; | |
8245 | rxd->opaque = (RXD_OPAQUE_RING_JUMBO | | |
8246 | (i << RXD_OPAQUE_INDEX_SHIFT)); | |
8247 | } | |
8248 | ||
8249 | for (i = 0; i < tp->rx_jumbo_pending; i++) { | |
8d4057a9 ED |
8250 | unsigned int frag_size; |
8251 | ||
8252 | if (tg3_alloc_rx_data(tp, tpr, RXD_OPAQUE_RING_JUMBO, i, | |
8253 | &frag_size) < 0) { | |
5129c3a3 MC |
8254 | netdev_warn(tp->dev, |
8255 | "Using a smaller RX jumbo ring. Only %d " | |
8256 | "out of %d buffers were allocated " | |
8257 | "successfully\n", i, tp->rx_jumbo_pending); | |
0d86df80 MC |
8258 | if (i == 0) |
8259 | goto initfail; | |
8260 | tp->rx_jumbo_pending = i; | |
8261 | break; | |
1da177e4 LT |
8262 | } |
8263 | } | |
cf7a7298 MC |
8264 | |
8265 | done: | |
32d8c572 | 8266 | return 0; |
cf7a7298 MC |
8267 | |
8268 | initfail: | |
21f581a5 | 8269 | tg3_rx_prodring_free(tp, tpr); |
cf7a7298 | 8270 | return -ENOMEM; |
1da177e4 LT |
8271 | } |
8272 | ||
21f581a5 MC |
8273 | static void tg3_rx_prodring_fini(struct tg3 *tp, |
8274 | struct tg3_rx_prodring_set *tpr) | |
1da177e4 | 8275 | { |
21f581a5 MC |
8276 | kfree(tpr->rx_std_buffers); |
8277 | tpr->rx_std_buffers = NULL; | |
8278 | kfree(tpr->rx_jmb_buffers); | |
8279 | tpr->rx_jmb_buffers = NULL; | |
8280 | if (tpr->rx_std) { | |
4bae65c8 MC |
8281 | dma_free_coherent(&tp->pdev->dev, TG3_RX_STD_RING_BYTES(tp), |
8282 | tpr->rx_std, tpr->rx_std_mapping); | |
21f581a5 | 8283 | tpr->rx_std = NULL; |
1da177e4 | 8284 | } |
21f581a5 | 8285 | if (tpr->rx_jmb) { |
4bae65c8 MC |
8286 | dma_free_coherent(&tp->pdev->dev, TG3_RX_JMB_RING_BYTES(tp), |
8287 | tpr->rx_jmb, tpr->rx_jmb_mapping); | |
21f581a5 | 8288 | tpr->rx_jmb = NULL; |
1da177e4 | 8289 | } |
cf7a7298 MC |
8290 | } |
8291 | ||
21f581a5 MC |
8292 | static int tg3_rx_prodring_init(struct tg3 *tp, |
8293 | struct tg3_rx_prodring_set *tpr) | |
cf7a7298 | 8294 | { |
2c49a44d MC |
8295 | tpr->rx_std_buffers = kzalloc(TG3_RX_STD_BUFF_RING_SIZE(tp), |
8296 | GFP_KERNEL); | |
21f581a5 | 8297 | if (!tpr->rx_std_buffers) |
cf7a7298 MC |
8298 | return -ENOMEM; |
8299 | ||
4bae65c8 MC |
8300 | tpr->rx_std = dma_alloc_coherent(&tp->pdev->dev, |
8301 | TG3_RX_STD_RING_BYTES(tp), | |
8302 | &tpr->rx_std_mapping, | |
8303 | GFP_KERNEL); | |
21f581a5 | 8304 | if (!tpr->rx_std) |
cf7a7298 MC |
8305 | goto err_out; |
8306 | ||
63c3a66f | 8307 | if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) { |
2c49a44d | 8308 | tpr->rx_jmb_buffers = kzalloc(TG3_RX_JMB_BUFF_RING_SIZE(tp), |
21f581a5 MC |
8309 | GFP_KERNEL); |
8310 | if (!tpr->rx_jmb_buffers) | |
cf7a7298 MC |
8311 | goto err_out; |
8312 | ||
4bae65c8 MC |
8313 | tpr->rx_jmb = dma_alloc_coherent(&tp->pdev->dev, |
8314 | TG3_RX_JMB_RING_BYTES(tp), | |
8315 | &tpr->rx_jmb_mapping, | |
8316 | GFP_KERNEL); | |
21f581a5 | 8317 | if (!tpr->rx_jmb) |
cf7a7298 MC |
8318 | goto err_out; |
8319 | } | |
8320 | ||
8321 | return 0; | |
8322 | ||
8323 | err_out: | |
21f581a5 | 8324 | tg3_rx_prodring_fini(tp, tpr); |
cf7a7298 MC |
8325 | return -ENOMEM; |
8326 | } | |
8327 | ||
8328 | /* Free up pending packets in all rx/tx rings. | |
8329 | * | |
8330 | * The chip has been shut down and the driver detached from | |
8331 | * the networking, so no interrupts or new tx packets will | |
8332 | * end up in the driver. tp->{tx,}lock is not held and we are not | |
8333 | * in an interrupt context and thus may sleep. | |
8334 | */ | |
8335 | static void tg3_free_rings(struct tg3 *tp) | |
8336 | { | |
f77a6a8e | 8337 | int i, j; |
cf7a7298 | 8338 | |
f77a6a8e MC |
8339 | for (j = 0; j < tp->irq_cnt; j++) { |
8340 | struct tg3_napi *tnapi = &tp->napi[j]; | |
cf7a7298 | 8341 | |
8fea32b9 | 8342 | tg3_rx_prodring_free(tp, &tnapi->prodring); |
b28f6428 | 8343 | |
0c1d0e2b MC |
8344 | if (!tnapi->tx_buffers) |
8345 | continue; | |
8346 | ||
0d681b27 MC |
8347 | for (i = 0; i < TG3_TX_RING_SIZE; i++) { |
8348 | struct sk_buff *skb = tnapi->tx_buffers[i].skb; | |
cf7a7298 | 8349 | |
0d681b27 | 8350 | if (!skb) |
f77a6a8e | 8351 | continue; |
cf7a7298 | 8352 | |
ba1142e4 MC |
8353 | tg3_tx_skb_unmap(tnapi, i, |
8354 | skb_shinfo(skb)->nr_frags - 1); | |
f77a6a8e MC |
8355 | |
8356 | dev_kfree_skb_any(skb); | |
8357 | } | |
5cb917bc | 8358 | netdev_tx_reset_queue(netdev_get_tx_queue(tp->dev, j)); |
2b2cdb65 | 8359 | } |
cf7a7298 MC |
8360 | } |
8361 | ||
8362 | /* Initialize tx/rx rings for packet processing. | |
8363 | * | |
8364 | * The chip has been shut down and the driver detached from | |
8365 | * the networking, so no interrupts or new tx packets will | |
8366 | * end up in the driver. tp->{tx,}lock are held and thus | |
8367 | * we may not sleep. | |
8368 | */ | |
8369 | static int tg3_init_rings(struct tg3 *tp) | |
8370 | { | |
f77a6a8e | 8371 | int i; |
72334482 | 8372 | |
cf7a7298 MC |
8373 | /* Free up all the SKBs. */ |
8374 | tg3_free_rings(tp); | |
8375 | ||
f77a6a8e MC |
8376 | for (i = 0; i < tp->irq_cnt; i++) { |
8377 | struct tg3_napi *tnapi = &tp->napi[i]; | |
8378 | ||
8379 | tnapi->last_tag = 0; | |
8380 | tnapi->last_irq_tag = 0; | |
8381 | tnapi->hw_status->status = 0; | |
8382 | tnapi->hw_status->status_tag = 0; | |
8383 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); | |
cf7a7298 | 8384 | |
f77a6a8e MC |
8385 | tnapi->tx_prod = 0; |
8386 | tnapi->tx_cons = 0; | |
0c1d0e2b MC |
8387 | if (tnapi->tx_ring) |
8388 | memset(tnapi->tx_ring, 0, TG3_TX_RING_BYTES); | |
f77a6a8e MC |
8389 | |
8390 | tnapi->rx_rcb_ptr = 0; | |
0c1d0e2b MC |
8391 | if (tnapi->rx_rcb) |
8392 | memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); | |
2b2cdb65 | 8393 | |
8fea32b9 | 8394 | if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) { |
e4af1af9 | 8395 | tg3_free_rings(tp); |
2b2cdb65 | 8396 | return -ENOMEM; |
e4af1af9 | 8397 | } |
f77a6a8e | 8398 | } |
72334482 | 8399 | |
2b2cdb65 | 8400 | return 0; |
cf7a7298 MC |
8401 | } |
8402 | ||
49a359e3 | 8403 | static void tg3_mem_tx_release(struct tg3 *tp) |
cf7a7298 | 8404 | { |
f77a6a8e | 8405 | int i; |
898a56f8 | 8406 | |
49a359e3 | 8407 | for (i = 0; i < tp->irq_max; i++) { |
f77a6a8e MC |
8408 | struct tg3_napi *tnapi = &tp->napi[i]; |
8409 | ||
8410 | if (tnapi->tx_ring) { | |
4bae65c8 | 8411 | dma_free_coherent(&tp->pdev->dev, TG3_TX_RING_BYTES, |
f77a6a8e MC |
8412 | tnapi->tx_ring, tnapi->tx_desc_mapping); |
8413 | tnapi->tx_ring = NULL; | |
8414 | } | |
8415 | ||
8416 | kfree(tnapi->tx_buffers); | |
8417 | tnapi->tx_buffers = NULL; | |
49a359e3 MC |
8418 | } |
8419 | } | |
f77a6a8e | 8420 | |
49a359e3 MC |
8421 | static int tg3_mem_tx_acquire(struct tg3 *tp) |
8422 | { | |
8423 | int i; | |
8424 | struct tg3_napi *tnapi = &tp->napi[0]; | |
8425 | ||
8426 | /* If multivector TSS is enabled, vector 0 does not handle | |
8427 | * tx interrupts. Don't allocate any resources for it. | |
8428 | */ | |
8429 | if (tg3_flag(tp, ENABLE_TSS)) | |
8430 | tnapi++; | |
8431 | ||
8432 | for (i = 0; i < tp->txq_cnt; i++, tnapi++) { | |
8433 | tnapi->tx_buffers = kzalloc(sizeof(struct tg3_tx_ring_info) * | |
8434 | TG3_TX_RING_SIZE, GFP_KERNEL); | |
8435 | if (!tnapi->tx_buffers) | |
8436 | goto err_out; | |
8437 | ||
8438 | tnapi->tx_ring = dma_alloc_coherent(&tp->pdev->dev, | |
8439 | TG3_TX_RING_BYTES, | |
8440 | &tnapi->tx_desc_mapping, | |
8441 | GFP_KERNEL); | |
8442 | if (!tnapi->tx_ring) | |
8443 | goto err_out; | |
8444 | } | |
8445 | ||
8446 | return 0; | |
8447 | ||
8448 | err_out: | |
8449 | tg3_mem_tx_release(tp); | |
8450 | return -ENOMEM; | |
8451 | } | |
8452 | ||
8453 | static void tg3_mem_rx_release(struct tg3 *tp) | |
8454 | { | |
8455 | int i; | |
8456 | ||
8457 | for (i = 0; i < tp->irq_max; i++) { | |
8458 | struct tg3_napi *tnapi = &tp->napi[i]; | |
f77a6a8e | 8459 | |
8fea32b9 MC |
8460 | tg3_rx_prodring_fini(tp, &tnapi->prodring); |
8461 | ||
49a359e3 MC |
8462 | if (!tnapi->rx_rcb) |
8463 | continue; | |
8464 | ||
8465 | dma_free_coherent(&tp->pdev->dev, | |
8466 | TG3_RX_RCB_RING_BYTES(tp), | |
8467 | tnapi->rx_rcb, | |
8468 | tnapi->rx_rcb_mapping); | |
8469 | tnapi->rx_rcb = NULL; | |
8470 | } | |
8471 | } | |
8472 | ||
8473 | static int tg3_mem_rx_acquire(struct tg3 *tp) | |
8474 | { | |
8475 | unsigned int i, limit; | |
8476 | ||
8477 | limit = tp->rxq_cnt; | |
8478 | ||
8479 | /* If RSS is enabled, we need a (dummy) producer ring | |
8480 | * set on vector zero. This is the true hw prodring. | |
8481 | */ | |
8482 | if (tg3_flag(tp, ENABLE_RSS)) | |
8483 | limit++; | |
8484 | ||
8485 | for (i = 0; i < limit; i++) { | |
8486 | struct tg3_napi *tnapi = &tp->napi[i]; | |
8487 | ||
8488 | if (tg3_rx_prodring_init(tp, &tnapi->prodring)) | |
8489 | goto err_out; | |
8490 | ||
8491 | /* If multivector RSS is enabled, vector 0 | |
8492 | * does not handle rx or tx interrupts. | |
8493 | * Don't allocate any resources for it. | |
8494 | */ | |
8495 | if (!i && tg3_flag(tp, ENABLE_RSS)) | |
8496 | continue; | |
8497 | ||
8498 | tnapi->rx_rcb = dma_alloc_coherent(&tp->pdev->dev, | |
8499 | TG3_RX_RCB_RING_BYTES(tp), | |
8500 | &tnapi->rx_rcb_mapping, | |
1f9061d2 | 8501 | GFP_KERNEL | __GFP_ZERO); |
49a359e3 MC |
8502 | if (!tnapi->rx_rcb) |
8503 | goto err_out; | |
49a359e3 MC |
8504 | } |
8505 | ||
8506 | return 0; | |
8507 | ||
8508 | err_out: | |
8509 | tg3_mem_rx_release(tp); | |
8510 | return -ENOMEM; | |
8511 | } | |
8512 | ||
8513 | /* | |
8514 | * Must not be invoked with interrupt sources disabled and | |
8515 | * the hardware shutdown down. | |
8516 | */ | |
8517 | static void tg3_free_consistent(struct tg3 *tp) | |
8518 | { | |
8519 | int i; | |
8520 | ||
8521 | for (i = 0; i < tp->irq_cnt; i++) { | |
8522 | struct tg3_napi *tnapi = &tp->napi[i]; | |
8523 | ||
f77a6a8e | 8524 | if (tnapi->hw_status) { |
4bae65c8 MC |
8525 | dma_free_coherent(&tp->pdev->dev, TG3_HW_STATUS_SIZE, |
8526 | tnapi->hw_status, | |
8527 | tnapi->status_mapping); | |
f77a6a8e MC |
8528 | tnapi->hw_status = NULL; |
8529 | } | |
1da177e4 | 8530 | } |
f77a6a8e | 8531 | |
49a359e3 MC |
8532 | tg3_mem_rx_release(tp); |
8533 | tg3_mem_tx_release(tp); | |
8534 | ||
1da177e4 | 8535 | if (tp->hw_stats) { |
4bae65c8 MC |
8536 | dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats), |
8537 | tp->hw_stats, tp->stats_mapping); | |
1da177e4 LT |
8538 | tp->hw_stats = NULL; |
8539 | } | |
8540 | } | |
8541 | ||
8542 | /* | |
8543 | * Must not be invoked with interrupt sources disabled and | |
8544 | * the hardware shutdown down. Can sleep. | |
8545 | */ | |
8546 | static int tg3_alloc_consistent(struct tg3 *tp) | |
8547 | { | |
f77a6a8e | 8548 | int i; |
898a56f8 | 8549 | |
4bae65c8 MC |
8550 | tp->hw_stats = dma_alloc_coherent(&tp->pdev->dev, |
8551 | sizeof(struct tg3_hw_stats), | |
8552 | &tp->stats_mapping, | |
1f9061d2 | 8553 | GFP_KERNEL | __GFP_ZERO); |
f77a6a8e | 8554 | if (!tp->hw_stats) |
1da177e4 LT |
8555 | goto err_out; |
8556 | ||
f77a6a8e MC |
8557 | for (i = 0; i < tp->irq_cnt; i++) { |
8558 | struct tg3_napi *tnapi = &tp->napi[i]; | |
8d9d7cfc | 8559 | struct tg3_hw_status *sblk; |
1da177e4 | 8560 | |
4bae65c8 MC |
8561 | tnapi->hw_status = dma_alloc_coherent(&tp->pdev->dev, |
8562 | TG3_HW_STATUS_SIZE, | |
8563 | &tnapi->status_mapping, | |
1f9061d2 | 8564 | GFP_KERNEL | __GFP_ZERO); |
f77a6a8e MC |
8565 | if (!tnapi->hw_status) |
8566 | goto err_out; | |
898a56f8 | 8567 | |
8d9d7cfc MC |
8568 | sblk = tnapi->hw_status; |
8569 | ||
49a359e3 | 8570 | if (tg3_flag(tp, ENABLE_RSS)) { |
86449944 | 8571 | u16 *prodptr = NULL; |
8fea32b9 | 8572 | |
49a359e3 MC |
8573 | /* |
8574 | * When RSS is enabled, the status block format changes | |
8575 | * slightly. The "rx_jumbo_consumer", "reserved", | |
8576 | * and "rx_mini_consumer" members get mapped to the | |
8577 | * other three rx return ring producer indexes. | |
8578 | */ | |
8579 | switch (i) { | |
8580 | case 1: | |
8581 | prodptr = &sblk->idx[0].rx_producer; | |
8582 | break; | |
8583 | case 2: | |
8584 | prodptr = &sblk->rx_jumbo_consumer; | |
8585 | break; | |
8586 | case 3: | |
8587 | prodptr = &sblk->reserved; | |
8588 | break; | |
8589 | case 4: | |
8590 | prodptr = &sblk->rx_mini_consumer; | |
f891ea16 MC |
8591 | break; |
8592 | } | |
49a359e3 MC |
8593 | tnapi->rx_rcb_prod_idx = prodptr; |
8594 | } else { | |
8d9d7cfc | 8595 | tnapi->rx_rcb_prod_idx = &sblk->idx[0].rx_producer; |
8d9d7cfc | 8596 | } |
f77a6a8e | 8597 | } |
1da177e4 | 8598 | |
49a359e3 MC |
8599 | if (tg3_mem_tx_acquire(tp) || tg3_mem_rx_acquire(tp)) |
8600 | goto err_out; | |
8601 | ||
1da177e4 LT |
8602 | return 0; |
8603 | ||
8604 | err_out: | |
8605 | tg3_free_consistent(tp); | |
8606 | return -ENOMEM; | |
8607 | } | |
8608 | ||
8609 | #define MAX_WAIT_CNT 1000 | |
8610 | ||
8611 | /* To stop a block, clear the enable bit and poll till it | |
8612 | * clears. tp->lock is held. | |
8613 | */ | |
953c96e0 | 8614 | static int tg3_stop_block(struct tg3 *tp, unsigned long ofs, u32 enable_bit, bool silent) |
1da177e4 LT |
8615 | { |
8616 | unsigned int i; | |
8617 | u32 val; | |
8618 | ||
63c3a66f | 8619 | if (tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
8620 | switch (ofs) { |
8621 | case RCVLSC_MODE: | |
8622 | case DMAC_MODE: | |
8623 | case MBFREE_MODE: | |
8624 | case BUFMGR_MODE: | |
8625 | case MEMARB_MODE: | |
8626 | /* We can't enable/disable these bits of the | |
8627 | * 5705/5750, just say success. | |
8628 | */ | |
8629 | return 0; | |
8630 | ||
8631 | default: | |
8632 | break; | |
855e1111 | 8633 | } |
1da177e4 LT |
8634 | } |
8635 | ||
8636 | val = tr32(ofs); | |
8637 | val &= ~enable_bit; | |
8638 | tw32_f(ofs, val); | |
8639 | ||
8640 | for (i = 0; i < MAX_WAIT_CNT; i++) { | |
6d446ec3 GS |
8641 | if (pci_channel_offline(tp->pdev)) { |
8642 | dev_err(&tp->pdev->dev, | |
8643 | "tg3_stop_block device offline, " | |
8644 | "ofs=%lx enable_bit=%x\n", | |
8645 | ofs, enable_bit); | |
8646 | return -ENODEV; | |
8647 | } | |
8648 | ||
1da177e4 LT |
8649 | udelay(100); |
8650 | val = tr32(ofs); | |
8651 | if ((val & enable_bit) == 0) | |
8652 | break; | |
8653 | } | |
8654 | ||
b3b7d6be | 8655 | if (i == MAX_WAIT_CNT && !silent) { |
2445e461 MC |
8656 | dev_err(&tp->pdev->dev, |
8657 | "tg3_stop_block timed out, ofs=%lx enable_bit=%x\n", | |
8658 | ofs, enable_bit); | |
1da177e4 LT |
8659 | return -ENODEV; |
8660 | } | |
8661 | ||
8662 | return 0; | |
8663 | } | |
8664 | ||
8665 | /* tp->lock is held. */ | |
953c96e0 | 8666 | static int tg3_abort_hw(struct tg3 *tp, bool silent) |
1da177e4 LT |
8667 | { |
8668 | int i, err; | |
8669 | ||
8670 | tg3_disable_ints(tp); | |
8671 | ||
6d446ec3 GS |
8672 | if (pci_channel_offline(tp->pdev)) { |
8673 | tp->rx_mode &= ~(RX_MODE_ENABLE | TX_MODE_ENABLE); | |
8674 | tp->mac_mode &= ~MAC_MODE_TDE_ENABLE; | |
8675 | err = -ENODEV; | |
8676 | goto err_no_dev; | |
8677 | } | |
8678 | ||
1da177e4 LT |
8679 | tp->rx_mode &= ~RX_MODE_ENABLE; |
8680 | tw32_f(MAC_RX_MODE, tp->rx_mode); | |
8681 | udelay(10); | |
8682 | ||
b3b7d6be DM |
8683 | err = tg3_stop_block(tp, RCVBDI_MODE, RCVBDI_MODE_ENABLE, silent); |
8684 | err |= tg3_stop_block(tp, RCVLPC_MODE, RCVLPC_MODE_ENABLE, silent); | |
8685 | err |= tg3_stop_block(tp, RCVLSC_MODE, RCVLSC_MODE_ENABLE, silent); | |
8686 | err |= tg3_stop_block(tp, RCVDBDI_MODE, RCVDBDI_MODE_ENABLE, silent); | |
8687 | err |= tg3_stop_block(tp, RCVDCC_MODE, RCVDCC_MODE_ENABLE, silent); | |
8688 | err |= tg3_stop_block(tp, RCVCC_MODE, RCVCC_MODE_ENABLE, silent); | |
8689 | ||
8690 | err |= tg3_stop_block(tp, SNDBDS_MODE, SNDBDS_MODE_ENABLE, silent); | |
8691 | err |= tg3_stop_block(tp, SNDBDI_MODE, SNDBDI_MODE_ENABLE, silent); | |
8692 | err |= tg3_stop_block(tp, SNDDATAI_MODE, SNDDATAI_MODE_ENABLE, silent); | |
8693 | err |= tg3_stop_block(tp, RDMAC_MODE, RDMAC_MODE_ENABLE, silent); | |
8694 | err |= tg3_stop_block(tp, SNDDATAC_MODE, SNDDATAC_MODE_ENABLE, silent); | |
8695 | err |= tg3_stop_block(tp, DMAC_MODE, DMAC_MODE_ENABLE, silent); | |
8696 | err |= tg3_stop_block(tp, SNDBDC_MODE, SNDBDC_MODE_ENABLE, silent); | |
1da177e4 LT |
8697 | |
8698 | tp->mac_mode &= ~MAC_MODE_TDE_ENABLE; | |
8699 | tw32_f(MAC_MODE, tp->mac_mode); | |
8700 | udelay(40); | |
8701 | ||
8702 | tp->tx_mode &= ~TX_MODE_ENABLE; | |
8703 | tw32_f(MAC_TX_MODE, tp->tx_mode); | |
8704 | ||
8705 | for (i = 0; i < MAX_WAIT_CNT; i++) { | |
8706 | udelay(100); | |
8707 | if (!(tr32(MAC_TX_MODE) & TX_MODE_ENABLE)) | |
8708 | break; | |
8709 | } | |
8710 | if (i >= MAX_WAIT_CNT) { | |
ab96b241 MC |
8711 | dev_err(&tp->pdev->dev, |
8712 | "%s timed out, TX_MODE_ENABLE will not clear " | |
8713 | "MAC_TX_MODE=%08x\n", __func__, tr32(MAC_TX_MODE)); | |
e6de8ad1 | 8714 | err |= -ENODEV; |
1da177e4 LT |
8715 | } |
8716 | ||
e6de8ad1 | 8717 | err |= tg3_stop_block(tp, HOSTCC_MODE, HOSTCC_MODE_ENABLE, silent); |
b3b7d6be DM |
8718 | err |= tg3_stop_block(tp, WDMAC_MODE, WDMAC_MODE_ENABLE, silent); |
8719 | err |= tg3_stop_block(tp, MBFREE_MODE, MBFREE_MODE_ENABLE, silent); | |
1da177e4 LT |
8720 | |
8721 | tw32(FTQ_RESET, 0xffffffff); | |
8722 | tw32(FTQ_RESET, 0x00000000); | |
8723 | ||
b3b7d6be DM |
8724 | err |= tg3_stop_block(tp, BUFMGR_MODE, BUFMGR_MODE_ENABLE, silent); |
8725 | err |= tg3_stop_block(tp, MEMARB_MODE, MEMARB_MODE_ENABLE, silent); | |
1da177e4 | 8726 | |
6d446ec3 | 8727 | err_no_dev: |
f77a6a8e MC |
8728 | for (i = 0; i < tp->irq_cnt; i++) { |
8729 | struct tg3_napi *tnapi = &tp->napi[i]; | |
8730 | if (tnapi->hw_status) | |
8731 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); | |
8732 | } | |
1da177e4 | 8733 | |
1da177e4 LT |
8734 | return err; |
8735 | } | |
8736 | ||
ee6a99b5 MC |
8737 | /* Save PCI command register before chip reset */ |
8738 | static void tg3_save_pci_state(struct tg3 *tp) | |
8739 | { | |
8a6eac90 | 8740 | pci_read_config_word(tp->pdev, PCI_COMMAND, &tp->pci_cmd); |
ee6a99b5 MC |
8741 | } |
8742 | ||
8743 | /* Restore PCI state after chip reset */ | |
8744 | static void tg3_restore_pci_state(struct tg3 *tp) | |
8745 | { | |
8746 | u32 val; | |
8747 | ||
8748 | /* Re-enable indirect register accesses. */ | |
8749 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
8750 | tp->misc_host_ctrl); | |
8751 | ||
8752 | /* Set MAX PCI retry to zero. */ | |
8753 | val = (PCISTATE_ROM_ENABLE | PCISTATE_ROM_RETRY_ENABLE); | |
4153577a | 8754 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5704_A0 && |
63c3a66f | 8755 | tg3_flag(tp, PCIX_MODE)) |
ee6a99b5 | 8756 | val |= PCISTATE_RETRY_SAME_DMA; |
0d3031d9 | 8757 | /* Allow reads and writes to the APE register and memory space. */ |
63c3a66f | 8758 | if (tg3_flag(tp, ENABLE_APE)) |
0d3031d9 | 8759 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | |
f92d9dc1 MC |
8760 | PCISTATE_ALLOW_APE_SHMEM_WR | |
8761 | PCISTATE_ALLOW_APE_PSPACE_WR; | |
ee6a99b5 MC |
8762 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val); |
8763 | ||
8a6eac90 | 8764 | pci_write_config_word(tp->pdev, PCI_COMMAND, tp->pci_cmd); |
ee6a99b5 | 8765 | |
2c55a3d0 MC |
8766 | if (!tg3_flag(tp, PCI_EXPRESS)) { |
8767 | pci_write_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, | |
8768 | tp->pci_cacheline_sz); | |
8769 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, | |
8770 | tp->pci_lat_timer); | |
114342f2 | 8771 | } |
5f5c51e3 | 8772 | |
ee6a99b5 | 8773 | /* Make sure PCI-X relaxed ordering bit is clear. */ |
63c3a66f | 8774 | if (tg3_flag(tp, PCIX_MODE)) { |
9974a356 MC |
8775 | u16 pcix_cmd; |
8776 | ||
8777 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, | |
8778 | &pcix_cmd); | |
8779 | pcix_cmd &= ~PCI_X_CMD_ERO; | |
8780 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, | |
8781 | pcix_cmd); | |
8782 | } | |
ee6a99b5 | 8783 | |
63c3a66f | 8784 | if (tg3_flag(tp, 5780_CLASS)) { |
ee6a99b5 MC |
8785 | |
8786 | /* Chip reset on 5780 will reset MSI enable bit, | |
8787 | * so need to restore it. | |
8788 | */ | |
63c3a66f | 8789 | if (tg3_flag(tp, USING_MSI)) { |
ee6a99b5 MC |
8790 | u16 ctrl; |
8791 | ||
8792 | pci_read_config_word(tp->pdev, | |
8793 | tp->msi_cap + PCI_MSI_FLAGS, | |
8794 | &ctrl); | |
8795 | pci_write_config_word(tp->pdev, | |
8796 | tp->msi_cap + PCI_MSI_FLAGS, | |
8797 | ctrl | PCI_MSI_FLAGS_ENABLE); | |
8798 | val = tr32(MSGINT_MODE); | |
8799 | tw32(MSGINT_MODE, val | MSGINT_MODE_ENABLE); | |
8800 | } | |
8801 | } | |
8802 | } | |
8803 | ||
1da177e4 LT |
8804 | /* tp->lock is held. */ |
8805 | static int tg3_chip_reset(struct tg3 *tp) | |
8806 | { | |
8807 | u32 val; | |
1ee582d8 | 8808 | void (*write_op)(struct tg3 *, u32, u32); |
4f125f42 | 8809 | int i, err; |
1da177e4 | 8810 | |
f49639e6 DM |
8811 | tg3_nvram_lock(tp); |
8812 | ||
77b483f1 MC |
8813 | tg3_ape_lock(tp, TG3_APE_LOCK_GRC); |
8814 | ||
f49639e6 DM |
8815 | /* No matching tg3_nvram_unlock() after this because |
8816 | * chip reset below will undo the nvram lock. | |
8817 | */ | |
8818 | tp->nvram_lock_cnt = 0; | |
1da177e4 | 8819 | |
ee6a99b5 MC |
8820 | /* GRC_MISC_CFG core clock reset will clear the memory |
8821 | * enable bit in PCI register 4 and the MSI enable bit | |
8822 | * on some chips, so we save relevant registers here. | |
8823 | */ | |
8824 | tg3_save_pci_state(tp); | |
8825 | ||
4153577a | 8826 | if (tg3_asic_rev(tp) == ASIC_REV_5752 || |
63c3a66f | 8827 | tg3_flag(tp, 5755_PLUS)) |
d9ab5ad1 MC |
8828 | tw32(GRC_FASTBOOT_PC, 0); |
8829 | ||
1da177e4 LT |
8830 | /* |
8831 | * We must avoid the readl() that normally takes place. | |
8832 | * It locks machines, causes machine checks, and other | |
8833 | * fun things. So, temporarily disable the 5701 | |
8834 | * hardware workaround, while we do the reset. | |
8835 | */ | |
1ee582d8 MC |
8836 | write_op = tp->write32; |
8837 | if (write_op == tg3_write_flush_reg32) | |
8838 | tp->write32 = tg3_write32; | |
1da177e4 | 8839 | |
d18edcb2 MC |
8840 | /* Prevent the irq handler from reading or writing PCI registers |
8841 | * during chip reset when the memory enable bit in the PCI command | |
8842 | * register may be cleared. The chip does not generate interrupt | |
8843 | * at this time, but the irq handler may still be called due to irq | |
8844 | * sharing or irqpoll. | |
8845 | */ | |
63c3a66f | 8846 | tg3_flag_set(tp, CHIP_RESETTING); |
f77a6a8e MC |
8847 | for (i = 0; i < tp->irq_cnt; i++) { |
8848 | struct tg3_napi *tnapi = &tp->napi[i]; | |
8849 | if (tnapi->hw_status) { | |
8850 | tnapi->hw_status->status = 0; | |
8851 | tnapi->hw_status->status_tag = 0; | |
8852 | } | |
8853 | tnapi->last_tag = 0; | |
8854 | tnapi->last_irq_tag = 0; | |
b8fa2f3a | 8855 | } |
d18edcb2 | 8856 | smp_mb(); |
4f125f42 MC |
8857 | |
8858 | for (i = 0; i < tp->irq_cnt; i++) | |
8859 | synchronize_irq(tp->napi[i].irq_vec); | |
d18edcb2 | 8860 | |
4153577a | 8861 | if (tg3_asic_rev(tp) == ASIC_REV_57780) { |
255ca311 MC |
8862 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
8863 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); | |
8864 | } | |
8865 | ||
1da177e4 LT |
8866 | /* do the reset */ |
8867 | val = GRC_MISC_CFG_CORECLK_RESET; | |
8868 | ||
63c3a66f | 8869 | if (tg3_flag(tp, PCI_EXPRESS)) { |
88075d91 | 8870 | /* Force PCIe 1.0a mode */ |
4153577a | 8871 | if (tg3_asic_rev(tp) != ASIC_REV_5785 && |
63c3a66f | 8872 | !tg3_flag(tp, 57765_PLUS) && |
88075d91 MC |
8873 | tr32(TG3_PCIE_PHY_TSTCTL) == |
8874 | (TG3_PCIE_PHY_TSTCTL_PCIE10 | TG3_PCIE_PHY_TSTCTL_PSCRAM)) | |
8875 | tw32(TG3_PCIE_PHY_TSTCTL, TG3_PCIE_PHY_TSTCTL_PSCRAM); | |
8876 | ||
4153577a | 8877 | if (tg3_chip_rev_id(tp) != CHIPREV_ID_5750_A0) { |
1da177e4 LT |
8878 | tw32(GRC_MISC_CFG, (1 << 29)); |
8879 | val |= (1 << 29); | |
8880 | } | |
8881 | } | |
8882 | ||
4153577a | 8883 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
b5d3772c MC |
8884 | tw32(VCPU_STATUS, tr32(VCPU_STATUS) | VCPU_STATUS_DRV_RESET); |
8885 | tw32(GRC_VCPU_EXT_CTRL, | |
8886 | tr32(GRC_VCPU_EXT_CTRL) & ~GRC_VCPU_EXT_CTRL_HALT_CPU); | |
8887 | } | |
8888 | ||
f37500d3 | 8889 | /* Manage gphy power for all CPMU absent PCIe devices. */ |
63c3a66f | 8890 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, CPMU_PRESENT)) |
1da177e4 | 8891 | val |= GRC_MISC_CFG_KEEP_GPHY_POWER; |
f37500d3 | 8892 | |
1da177e4 LT |
8893 | tw32(GRC_MISC_CFG, val); |
8894 | ||
1ee582d8 MC |
8895 | /* restore 5701 hardware bug workaround write method */ |
8896 | tp->write32 = write_op; | |
1da177e4 LT |
8897 | |
8898 | /* Unfortunately, we have to delay before the PCI read back. | |
8899 | * Some 575X chips even will not respond to a PCI cfg access | |
8900 | * when the reset command is given to the chip. | |
8901 | * | |
8902 | * How do these hardware designers expect things to work | |
8903 | * properly if the PCI write is posted for a long period | |
8904 | * of time? It is always necessary to have some method by | |
8905 | * which a register read back can occur to push the write | |
8906 | * out which does the reset. | |
8907 | * | |
8908 | * For most tg3 variants the trick below was working. | |
8909 | * Ho hum... | |
8910 | */ | |
8911 | udelay(120); | |
8912 | ||
8913 | /* Flush PCI posted writes. The normal MMIO registers | |
8914 | * are inaccessible at this time so this is the only | |
8915 | * way to make this reliably (actually, this is no longer | |
8916 | * the case, see above). I tried to use indirect | |
8917 | * register read/write but this upset some 5701 variants. | |
8918 | */ | |
8919 | pci_read_config_dword(tp->pdev, PCI_COMMAND, &val); | |
8920 | ||
8921 | udelay(120); | |
8922 | ||
0f49bfbd | 8923 | if (tg3_flag(tp, PCI_EXPRESS) && pci_is_pcie(tp->pdev)) { |
e7126997 MC |
8924 | u16 val16; |
8925 | ||
4153577a | 8926 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5750_A0) { |
86449944 | 8927 | int j; |
1da177e4 LT |
8928 | u32 cfg_val; |
8929 | ||
8930 | /* Wait for link training to complete. */ | |
86449944 | 8931 | for (j = 0; j < 5000; j++) |
1da177e4 LT |
8932 | udelay(100); |
8933 | ||
8934 | pci_read_config_dword(tp->pdev, 0xc4, &cfg_val); | |
8935 | pci_write_config_dword(tp->pdev, 0xc4, | |
8936 | cfg_val | (1 << 15)); | |
8937 | } | |
5e7dfd0f | 8938 | |
e7126997 | 8939 | /* Clear the "no snoop" and "relaxed ordering" bits. */ |
0f49bfbd | 8940 | val16 = PCI_EXP_DEVCTL_RELAX_EN | PCI_EXP_DEVCTL_NOSNOOP_EN; |
e7126997 MC |
8941 | /* |
8942 | * Older PCIe devices only support the 128 byte | |
8943 | * MPS setting. Enforce the restriction. | |
5e7dfd0f | 8944 | */ |
63c3a66f | 8945 | if (!tg3_flag(tp, CPMU_PRESENT)) |
0f49bfbd JL |
8946 | val16 |= PCI_EXP_DEVCTL_PAYLOAD; |
8947 | pcie_capability_clear_word(tp->pdev, PCI_EXP_DEVCTL, val16); | |
5e7dfd0f | 8948 | |
5e7dfd0f | 8949 | /* Clear error status */ |
0f49bfbd | 8950 | pcie_capability_write_word(tp->pdev, PCI_EXP_DEVSTA, |
5e7dfd0f MC |
8951 | PCI_EXP_DEVSTA_CED | |
8952 | PCI_EXP_DEVSTA_NFED | | |
8953 | PCI_EXP_DEVSTA_FED | | |
8954 | PCI_EXP_DEVSTA_URD); | |
1da177e4 LT |
8955 | } |
8956 | ||
ee6a99b5 | 8957 | tg3_restore_pci_state(tp); |
1da177e4 | 8958 | |
63c3a66f JP |
8959 | tg3_flag_clear(tp, CHIP_RESETTING); |
8960 | tg3_flag_clear(tp, ERROR_PROCESSED); | |
d18edcb2 | 8961 | |
ee6a99b5 | 8962 | val = 0; |
63c3a66f | 8963 | if (tg3_flag(tp, 5780_CLASS)) |
4cf78e4f | 8964 | val = tr32(MEMARB_MODE); |
ee6a99b5 | 8965 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); |
1da177e4 | 8966 | |
4153577a | 8967 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5750_A3) { |
1da177e4 LT |
8968 | tg3_stop_fw(tp); |
8969 | tw32(0x5000, 0x400); | |
8970 | } | |
8971 | ||
7e6c63f0 HM |
8972 | if (tg3_flag(tp, IS_SSB_CORE)) { |
8973 | /* | |
8974 | * BCM4785: In order to avoid repercussions from using | |
8975 | * potentially defective internal ROM, stop the Rx RISC CPU, | |
8976 | * which is not required. | |
8977 | */ | |
8978 | tg3_stop_fw(tp); | |
8979 | tg3_halt_cpu(tp, RX_CPU_BASE); | |
8980 | } | |
8981 | ||
fb03a43f NS |
8982 | err = tg3_poll_fw(tp); |
8983 | if (err) | |
8984 | return err; | |
8985 | ||
1da177e4 LT |
8986 | tw32(GRC_MODE, tp->grc_mode); |
8987 | ||
4153577a | 8988 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5705_A0) { |
ab0049b4 | 8989 | val = tr32(0xc4); |
1da177e4 LT |
8990 | |
8991 | tw32(0xc4, val | (1 << 15)); | |
8992 | } | |
8993 | ||
8994 | if ((tp->nic_sram_data_cfg & NIC_SRAM_DATA_CFG_MINI_PCI) != 0 && | |
4153577a | 8995 | tg3_asic_rev(tp) == ASIC_REV_5705) { |
1da177e4 | 8996 | tp->pci_clock_ctrl |= CLOCK_CTRL_CLKRUN_OENABLE; |
4153577a | 8997 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5705_A0) |
1da177e4 LT |
8998 | tp->pci_clock_ctrl |= CLOCK_CTRL_FORCE_CLKRUN; |
8999 | tw32(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); | |
9000 | } | |
9001 | ||
f07e9af3 | 9002 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
9e975cc2 | 9003 | tp->mac_mode = MAC_MODE_PORT_MODE_TBI; |
d2394e6b | 9004 | val = tp->mac_mode; |
f07e9af3 | 9005 | } else if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
9e975cc2 | 9006 | tp->mac_mode = MAC_MODE_PORT_MODE_GMII; |
d2394e6b | 9007 | val = tp->mac_mode; |
1da177e4 | 9008 | } else |
d2394e6b MC |
9009 | val = 0; |
9010 | ||
9011 | tw32_f(MAC_MODE, val); | |
1da177e4 LT |
9012 | udelay(40); |
9013 | ||
77b483f1 MC |
9014 | tg3_ape_unlock(tp, TG3_APE_LOCK_GRC); |
9015 | ||
0a9140cf MC |
9016 | tg3_mdio_start(tp); |
9017 | ||
63c3a66f | 9018 | if (tg3_flag(tp, PCI_EXPRESS) && |
4153577a JP |
9019 | tg3_chip_rev_id(tp) != CHIPREV_ID_5750_A0 && |
9020 | tg3_asic_rev(tp) != ASIC_REV_5785 && | |
63c3a66f | 9021 | !tg3_flag(tp, 57765_PLUS)) { |
ab0049b4 | 9022 | val = tr32(0x7c00); |
1da177e4 LT |
9023 | |
9024 | tw32(0x7c00, val | (1 << 25)); | |
9025 | } | |
9026 | ||
4153577a | 9027 | if (tg3_asic_rev(tp) == ASIC_REV_5720) { |
d78b59f5 MC |
9028 | val = tr32(TG3_CPMU_CLCK_ORIDE); |
9029 | tw32(TG3_CPMU_CLCK_ORIDE, val & ~CPMU_CLCK_ORIDE_MAC_ORIDE_EN); | |
9030 | } | |
9031 | ||
1da177e4 | 9032 | /* Reprobe ASF enable state. */ |
63c3a66f | 9033 | tg3_flag_clear(tp, ENABLE_ASF); |
942d1af0 NS |
9034 | tp->phy_flags &= ~(TG3_PHYFLG_1G_ON_VAUX_OK | |
9035 | TG3_PHYFLG_KEEP_LINK_ON_PWRDN); | |
9036 | ||
63c3a66f | 9037 | tg3_flag_clear(tp, ASF_NEW_HANDSHAKE); |
1da177e4 LT |
9038 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
9039 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { | |
9040 | u32 nic_cfg; | |
9041 | ||
9042 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); | |
9043 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { | |
63c3a66f | 9044 | tg3_flag_set(tp, ENABLE_ASF); |
4ba526ce | 9045 | tp->last_event_jiffies = jiffies; |
63c3a66f JP |
9046 | if (tg3_flag(tp, 5750_PLUS)) |
9047 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); | |
942d1af0 NS |
9048 | |
9049 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &nic_cfg); | |
9050 | if (nic_cfg & NIC_SRAM_1G_ON_VAUX_OK) | |
9051 | tp->phy_flags |= TG3_PHYFLG_1G_ON_VAUX_OK; | |
9052 | if (nic_cfg & NIC_SRAM_LNK_FLAP_AVOID) | |
9053 | tp->phy_flags |= TG3_PHYFLG_KEEP_LINK_ON_PWRDN; | |
1da177e4 LT |
9054 | } |
9055 | } | |
9056 | ||
9057 | return 0; | |
9058 | } | |
9059 | ||
65ec698d MC |
9060 | static void tg3_get_nstats(struct tg3 *, struct rtnl_link_stats64 *); |
9061 | static void tg3_get_estats(struct tg3 *, struct tg3_ethtool_stats *); | |
92feeabf | 9062 | |
1da177e4 | 9063 | /* tp->lock is held. */ |
953c96e0 | 9064 | static int tg3_halt(struct tg3 *tp, int kind, bool silent) |
1da177e4 LT |
9065 | { |
9066 | int err; | |
9067 | ||
9068 | tg3_stop_fw(tp); | |
9069 | ||
944d980e | 9070 | tg3_write_sig_pre_reset(tp, kind); |
1da177e4 | 9071 | |
b3b7d6be | 9072 | tg3_abort_hw(tp, silent); |
1da177e4 LT |
9073 | err = tg3_chip_reset(tp); |
9074 | ||
953c96e0 | 9075 | __tg3_set_mac_addr(tp, false); |
daba2a63 | 9076 | |
944d980e MC |
9077 | tg3_write_sig_legacy(tp, kind); |
9078 | tg3_write_sig_post_reset(tp, kind); | |
1da177e4 | 9079 | |
92feeabf MC |
9080 | if (tp->hw_stats) { |
9081 | /* Save the stats across chip resets... */ | |
b4017c53 | 9082 | tg3_get_nstats(tp, &tp->net_stats_prev); |
92feeabf MC |
9083 | tg3_get_estats(tp, &tp->estats_prev); |
9084 | ||
9085 | /* And make sure the next sample is new data */ | |
9086 | memset(tp->hw_stats, 0, sizeof(struct tg3_hw_stats)); | |
9087 | } | |
9088 | ||
1da177e4 LT |
9089 | if (err) |
9090 | return err; | |
9091 | ||
9092 | return 0; | |
9093 | } | |
9094 | ||
1da177e4 LT |
9095 | static int tg3_set_mac_addr(struct net_device *dev, void *p) |
9096 | { | |
9097 | struct tg3 *tp = netdev_priv(dev); | |
9098 | struct sockaddr *addr = p; | |
953c96e0 JP |
9099 | int err = 0; |
9100 | bool skip_mac_1 = false; | |
1da177e4 | 9101 | |
f9804ddb | 9102 | if (!is_valid_ether_addr(addr->sa_data)) |
504f9b5a | 9103 | return -EADDRNOTAVAIL; |
f9804ddb | 9104 | |
1da177e4 LT |
9105 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
9106 | ||
e75f7c90 MC |
9107 | if (!netif_running(dev)) |
9108 | return 0; | |
9109 | ||
63c3a66f | 9110 | if (tg3_flag(tp, ENABLE_ASF)) { |
986e0aeb | 9111 | u32 addr0_high, addr0_low, addr1_high, addr1_low; |
58712ef9 | 9112 | |
986e0aeb MC |
9113 | addr0_high = tr32(MAC_ADDR_0_HIGH); |
9114 | addr0_low = tr32(MAC_ADDR_0_LOW); | |
9115 | addr1_high = tr32(MAC_ADDR_1_HIGH); | |
9116 | addr1_low = tr32(MAC_ADDR_1_LOW); | |
9117 | ||
9118 | /* Skip MAC addr 1 if ASF is using it. */ | |
9119 | if ((addr0_high != addr1_high || addr0_low != addr1_low) && | |
9120 | !(addr1_high == 0 && addr1_low == 0)) | |
953c96e0 | 9121 | skip_mac_1 = true; |
58712ef9 | 9122 | } |
986e0aeb MC |
9123 | spin_lock_bh(&tp->lock); |
9124 | __tg3_set_mac_addr(tp, skip_mac_1); | |
9125 | spin_unlock_bh(&tp->lock); | |
1da177e4 | 9126 | |
b9ec6c1b | 9127 | return err; |
1da177e4 LT |
9128 | } |
9129 | ||
9130 | /* tp->lock is held. */ | |
9131 | static void tg3_set_bdinfo(struct tg3 *tp, u32 bdinfo_addr, | |
9132 | dma_addr_t mapping, u32 maxlen_flags, | |
9133 | u32 nic_addr) | |
9134 | { | |
9135 | tg3_write_mem(tp, | |
9136 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH), | |
9137 | ((u64) mapping >> 32)); | |
9138 | tg3_write_mem(tp, | |
9139 | (bdinfo_addr + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW), | |
9140 | ((u64) mapping & 0xffffffff)); | |
9141 | tg3_write_mem(tp, | |
9142 | (bdinfo_addr + TG3_BDINFO_MAXLEN_FLAGS), | |
9143 | maxlen_flags); | |
9144 | ||
63c3a66f | 9145 | if (!tg3_flag(tp, 5705_PLUS)) |
1da177e4 LT |
9146 | tg3_write_mem(tp, |
9147 | (bdinfo_addr + TG3_BDINFO_NIC_ADDR), | |
9148 | nic_addr); | |
9149 | } | |
9150 | ||
a489b6d9 MC |
9151 | |
9152 | static void tg3_coal_tx_init(struct tg3 *tp, struct ethtool_coalesce *ec) | |
15f9850d | 9153 | { |
a489b6d9 | 9154 | int i = 0; |
b6080e12 | 9155 | |
63c3a66f | 9156 | if (!tg3_flag(tp, ENABLE_TSS)) { |
b6080e12 MC |
9157 | tw32(HOSTCC_TXCOL_TICKS, ec->tx_coalesce_usecs); |
9158 | tw32(HOSTCC_TXMAX_FRAMES, ec->tx_max_coalesced_frames); | |
9159 | tw32(HOSTCC_TXCOAL_MAXF_INT, ec->tx_max_coalesced_frames_irq); | |
b6080e12 MC |
9160 | } else { |
9161 | tw32(HOSTCC_TXCOL_TICKS, 0); | |
9162 | tw32(HOSTCC_TXMAX_FRAMES, 0); | |
9163 | tw32(HOSTCC_TXCOAL_MAXF_INT, 0); | |
a489b6d9 MC |
9164 | |
9165 | for (; i < tp->txq_cnt; i++) { | |
9166 | u32 reg; | |
9167 | ||
9168 | reg = HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18; | |
9169 | tw32(reg, ec->tx_coalesce_usecs); | |
9170 | reg = HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18; | |
9171 | tw32(reg, ec->tx_max_coalesced_frames); | |
9172 | reg = HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18; | |
9173 | tw32(reg, ec->tx_max_coalesced_frames_irq); | |
9174 | } | |
19cfaecc | 9175 | } |
b6080e12 | 9176 | |
a489b6d9 MC |
9177 | for (; i < tp->irq_max - 1; i++) { |
9178 | tw32(HOSTCC_TXCOL_TICKS_VEC1 + i * 0x18, 0); | |
9179 | tw32(HOSTCC_TXMAX_FRAMES_VEC1 + i * 0x18, 0); | |
9180 | tw32(HOSTCC_TXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); | |
9181 | } | |
9182 | } | |
9183 | ||
9184 | static void tg3_coal_rx_init(struct tg3 *tp, struct ethtool_coalesce *ec) | |
9185 | { | |
9186 | int i = 0; | |
9187 | u32 limit = tp->rxq_cnt; | |
9188 | ||
63c3a66f | 9189 | if (!tg3_flag(tp, ENABLE_RSS)) { |
19cfaecc MC |
9190 | tw32(HOSTCC_RXCOL_TICKS, ec->rx_coalesce_usecs); |
9191 | tw32(HOSTCC_RXMAX_FRAMES, ec->rx_max_coalesced_frames); | |
9192 | tw32(HOSTCC_RXCOAL_MAXF_INT, ec->rx_max_coalesced_frames_irq); | |
a489b6d9 | 9193 | limit--; |
19cfaecc | 9194 | } else { |
b6080e12 MC |
9195 | tw32(HOSTCC_RXCOL_TICKS, 0); |
9196 | tw32(HOSTCC_RXMAX_FRAMES, 0); | |
9197 | tw32(HOSTCC_RXCOAL_MAXF_INT, 0); | |
15f9850d | 9198 | } |
b6080e12 | 9199 | |
a489b6d9 | 9200 | for (; i < limit; i++) { |
b6080e12 MC |
9201 | u32 reg; |
9202 | ||
9203 | reg = HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18; | |
9204 | tw32(reg, ec->rx_coalesce_usecs); | |
b6080e12 MC |
9205 | reg = HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18; |
9206 | tw32(reg, ec->rx_max_coalesced_frames); | |
b6080e12 MC |
9207 | reg = HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18; |
9208 | tw32(reg, ec->rx_max_coalesced_frames_irq); | |
b6080e12 MC |
9209 | } |
9210 | ||
9211 | for (; i < tp->irq_max - 1; i++) { | |
9212 | tw32(HOSTCC_RXCOL_TICKS_VEC1 + i * 0x18, 0); | |
b6080e12 | 9213 | tw32(HOSTCC_RXMAX_FRAMES_VEC1 + i * 0x18, 0); |
b6080e12 | 9214 | tw32(HOSTCC_RXCOAL_MAXF_INT_VEC1 + i * 0x18, 0); |
a489b6d9 MC |
9215 | } |
9216 | } | |
19cfaecc | 9217 | |
a489b6d9 MC |
9218 | static void __tg3_set_coalesce(struct tg3 *tp, struct ethtool_coalesce *ec) |
9219 | { | |
9220 | tg3_coal_tx_init(tp, ec); | |
9221 | tg3_coal_rx_init(tp, ec); | |
9222 | ||
9223 | if (!tg3_flag(tp, 5705_PLUS)) { | |
9224 | u32 val = ec->stats_block_coalesce_usecs; | |
9225 | ||
9226 | tw32(HOSTCC_RXCOAL_TICK_INT, ec->rx_coalesce_usecs_irq); | |
9227 | tw32(HOSTCC_TXCOAL_TICK_INT, ec->tx_coalesce_usecs_irq); | |
9228 | ||
f4a46d1f | 9229 | if (!tp->link_up) |
a489b6d9 MC |
9230 | val = 0; |
9231 | ||
9232 | tw32(HOSTCC_STAT_COAL_TICKS, val); | |
b6080e12 | 9233 | } |
15f9850d | 9234 | } |
1da177e4 | 9235 | |
2d31ecaf MC |
9236 | /* tp->lock is held. */ |
9237 | static void tg3_rings_reset(struct tg3 *tp) | |
9238 | { | |
9239 | int i; | |
f77a6a8e | 9240 | u32 stblk, txrcb, rxrcb, limit; |
2d31ecaf MC |
9241 | struct tg3_napi *tnapi = &tp->napi[0]; |
9242 | ||
9243 | /* Disable all transmit rings but the first. */ | |
63c3a66f | 9244 | if (!tg3_flag(tp, 5705_PLUS)) |
2d31ecaf | 9245 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 16; |
63c3a66f | 9246 | else if (tg3_flag(tp, 5717_PLUS)) |
3d37728b | 9247 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 4; |
c65a17f4 | 9248 | else if (tg3_flag(tp, 57765_CLASS) || |
4153577a | 9249 | tg3_asic_rev(tp) == ASIC_REV_5762) |
b703df6f | 9250 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE * 2; |
2d31ecaf MC |
9251 | else |
9252 | limit = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; | |
9253 | ||
9254 | for (txrcb = NIC_SRAM_SEND_RCB + TG3_BDINFO_SIZE; | |
9255 | txrcb < limit; txrcb += TG3_BDINFO_SIZE) | |
9256 | tg3_write_mem(tp, txrcb + TG3_BDINFO_MAXLEN_FLAGS, | |
9257 | BDINFO_FLAGS_DISABLED); | |
9258 | ||
9259 | ||
9260 | /* Disable all receive return rings but the first. */ | |
63c3a66f | 9261 | if (tg3_flag(tp, 5717_PLUS)) |
f6eb9b1f | 9262 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 17; |
63c3a66f | 9263 | else if (!tg3_flag(tp, 5705_PLUS)) |
2d31ecaf | 9264 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 16; |
4153577a JP |
9265 | else if (tg3_asic_rev(tp) == ASIC_REV_5755 || |
9266 | tg3_asic_rev(tp) == ASIC_REV_5762 || | |
55086ad9 | 9267 | tg3_flag(tp, 57765_CLASS)) |
2d31ecaf MC |
9268 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE * 4; |
9269 | else | |
9270 | limit = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; | |
9271 | ||
9272 | for (rxrcb = NIC_SRAM_RCV_RET_RCB + TG3_BDINFO_SIZE; | |
9273 | rxrcb < limit; rxrcb += TG3_BDINFO_SIZE) | |
9274 | tg3_write_mem(tp, rxrcb + TG3_BDINFO_MAXLEN_FLAGS, | |
9275 | BDINFO_FLAGS_DISABLED); | |
9276 | ||
9277 | /* Disable interrupts */ | |
9278 | tw32_mailbox_f(tp->napi[0].int_mbox, 1); | |
0e6cf6a9 MC |
9279 | tp->napi[0].chk_msi_cnt = 0; |
9280 | tp->napi[0].last_rx_cons = 0; | |
9281 | tp->napi[0].last_tx_cons = 0; | |
2d31ecaf MC |
9282 | |
9283 | /* Zero mailbox registers. */ | |
63c3a66f | 9284 | if (tg3_flag(tp, SUPPORT_MSIX)) { |
6fd45cb8 | 9285 | for (i = 1; i < tp->irq_max; i++) { |
f77a6a8e MC |
9286 | tp->napi[i].tx_prod = 0; |
9287 | tp->napi[i].tx_cons = 0; | |
63c3a66f | 9288 | if (tg3_flag(tp, ENABLE_TSS)) |
c2353a32 | 9289 | tw32_mailbox(tp->napi[i].prodmbox, 0); |
f77a6a8e MC |
9290 | tw32_rx_mbox(tp->napi[i].consmbox, 0); |
9291 | tw32_mailbox_f(tp->napi[i].int_mbox, 1); | |
7f230735 | 9292 | tp->napi[i].chk_msi_cnt = 0; |
0e6cf6a9 MC |
9293 | tp->napi[i].last_rx_cons = 0; |
9294 | tp->napi[i].last_tx_cons = 0; | |
f77a6a8e | 9295 | } |
63c3a66f | 9296 | if (!tg3_flag(tp, ENABLE_TSS)) |
c2353a32 | 9297 | tw32_mailbox(tp->napi[0].prodmbox, 0); |
f77a6a8e MC |
9298 | } else { |
9299 | tp->napi[0].tx_prod = 0; | |
9300 | tp->napi[0].tx_cons = 0; | |
9301 | tw32_mailbox(tp->napi[0].prodmbox, 0); | |
9302 | tw32_rx_mbox(tp->napi[0].consmbox, 0); | |
9303 | } | |
2d31ecaf MC |
9304 | |
9305 | /* Make sure the NIC-based send BD rings are disabled. */ | |
63c3a66f | 9306 | if (!tg3_flag(tp, 5705_PLUS)) { |
2d31ecaf MC |
9307 | u32 mbox = MAILBOX_SNDNIC_PROD_IDX_0 + TG3_64BIT_REG_LOW; |
9308 | for (i = 0; i < 16; i++) | |
9309 | tw32_tx_mbox(mbox + i * 8, 0); | |
9310 | } | |
9311 | ||
9312 | txrcb = NIC_SRAM_SEND_RCB; | |
9313 | rxrcb = NIC_SRAM_RCV_RET_RCB; | |
9314 | ||
9315 | /* Clear status block in ram. */ | |
9316 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); | |
9317 | ||
9318 | /* Set status block DMA address */ | |
9319 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, | |
9320 | ((u64) tnapi->status_mapping >> 32)); | |
9321 | tw32(HOSTCC_STATUS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, | |
9322 | ((u64) tnapi->status_mapping & 0xffffffff)); | |
9323 | ||
f77a6a8e MC |
9324 | if (tnapi->tx_ring) { |
9325 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, | |
9326 | (TG3_TX_RING_SIZE << | |
9327 | BDINFO_FLAGS_MAXLEN_SHIFT), | |
9328 | NIC_SRAM_TX_BUFFER_DESC); | |
9329 | txrcb += TG3_BDINFO_SIZE; | |
9330 | } | |
9331 | ||
9332 | if (tnapi->rx_rcb) { | |
9333 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, | |
7cb32cf2 MC |
9334 | (tp->rx_ret_ring_mask + 1) << |
9335 | BDINFO_FLAGS_MAXLEN_SHIFT, 0); | |
f77a6a8e MC |
9336 | rxrcb += TG3_BDINFO_SIZE; |
9337 | } | |
9338 | ||
9339 | stblk = HOSTCC_STATBLCK_RING1; | |
2d31ecaf | 9340 | |
f77a6a8e MC |
9341 | for (i = 1, tnapi++; i < tp->irq_cnt; i++, tnapi++) { |
9342 | u64 mapping = (u64)tnapi->status_mapping; | |
9343 | tw32(stblk + TG3_64BIT_REG_HIGH, mapping >> 32); | |
9344 | tw32(stblk + TG3_64BIT_REG_LOW, mapping & 0xffffffff); | |
9345 | ||
9346 | /* Clear status block in ram. */ | |
9347 | memset(tnapi->hw_status, 0, TG3_HW_STATUS_SIZE); | |
9348 | ||
19cfaecc MC |
9349 | if (tnapi->tx_ring) { |
9350 | tg3_set_bdinfo(tp, txrcb, tnapi->tx_desc_mapping, | |
9351 | (TG3_TX_RING_SIZE << | |
9352 | BDINFO_FLAGS_MAXLEN_SHIFT), | |
9353 | NIC_SRAM_TX_BUFFER_DESC); | |
9354 | txrcb += TG3_BDINFO_SIZE; | |
9355 | } | |
f77a6a8e MC |
9356 | |
9357 | tg3_set_bdinfo(tp, rxrcb, tnapi->rx_rcb_mapping, | |
7cb32cf2 | 9358 | ((tp->rx_ret_ring_mask + 1) << |
f77a6a8e MC |
9359 | BDINFO_FLAGS_MAXLEN_SHIFT), 0); |
9360 | ||
9361 | stblk += 8; | |
f77a6a8e MC |
9362 | rxrcb += TG3_BDINFO_SIZE; |
9363 | } | |
2d31ecaf MC |
9364 | } |
9365 | ||
eb07a940 MC |
9366 | static void tg3_setup_rxbd_thresholds(struct tg3 *tp) |
9367 | { | |
9368 | u32 val, bdcache_maxcnt, host_rep_thresh, nic_rep_thresh; | |
9369 | ||
63c3a66f JP |
9370 | if (!tg3_flag(tp, 5750_PLUS) || |
9371 | tg3_flag(tp, 5780_CLASS) || | |
4153577a JP |
9372 | tg3_asic_rev(tp) == ASIC_REV_5750 || |
9373 | tg3_asic_rev(tp) == ASIC_REV_5752 || | |
513aa6ea | 9374 | tg3_flag(tp, 57765_PLUS)) |
eb07a940 | 9375 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5700; |
4153577a JP |
9376 | else if (tg3_asic_rev(tp) == ASIC_REV_5755 || |
9377 | tg3_asic_rev(tp) == ASIC_REV_5787) | |
eb07a940 MC |
9378 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5755; |
9379 | else | |
9380 | bdcache_maxcnt = TG3_SRAM_RX_STD_BDCACHE_SIZE_5906; | |
9381 | ||
9382 | nic_rep_thresh = min(bdcache_maxcnt / 2, tp->rx_std_max_post); | |
9383 | host_rep_thresh = max_t(u32, tp->rx_pending / 8, 1); | |
9384 | ||
9385 | val = min(nic_rep_thresh, host_rep_thresh); | |
9386 | tw32(RCVBDI_STD_THRESH, val); | |
9387 | ||
63c3a66f | 9388 | if (tg3_flag(tp, 57765_PLUS)) |
eb07a940 MC |
9389 | tw32(STD_REPLENISH_LWM, bdcache_maxcnt); |
9390 | ||
63c3a66f | 9391 | if (!tg3_flag(tp, JUMBO_CAPABLE) || tg3_flag(tp, 5780_CLASS)) |
eb07a940 MC |
9392 | return; |
9393 | ||
513aa6ea | 9394 | bdcache_maxcnt = TG3_SRAM_RX_JMB_BDCACHE_SIZE_5700; |
eb07a940 MC |
9395 | |
9396 | host_rep_thresh = max_t(u32, tp->rx_jumbo_pending / 8, 1); | |
9397 | ||
9398 | val = min(bdcache_maxcnt / 2, host_rep_thresh); | |
9399 | tw32(RCVBDI_JUMBO_THRESH, val); | |
9400 | ||
63c3a66f | 9401 | if (tg3_flag(tp, 57765_PLUS)) |
eb07a940 MC |
9402 | tw32(JMB_REPLENISH_LWM, bdcache_maxcnt); |
9403 | } | |
9404 | ||
ccd5ba9d MC |
9405 | static inline u32 calc_crc(unsigned char *buf, int len) |
9406 | { | |
9407 | u32 reg; | |
9408 | u32 tmp; | |
9409 | int j, k; | |
9410 | ||
9411 | reg = 0xffffffff; | |
9412 | ||
9413 | for (j = 0; j < len; j++) { | |
9414 | reg ^= buf[j]; | |
9415 | ||
9416 | for (k = 0; k < 8; k++) { | |
9417 | tmp = reg & 0x01; | |
9418 | ||
9419 | reg >>= 1; | |
9420 | ||
9421 | if (tmp) | |
9422 | reg ^= 0xedb88320; | |
9423 | } | |
9424 | } | |
9425 | ||
9426 | return ~reg; | |
9427 | } | |
9428 | ||
9429 | static void tg3_set_multi(struct tg3 *tp, unsigned int accept_all) | |
9430 | { | |
9431 | /* accept or reject all multicast frames */ | |
9432 | tw32(MAC_HASH_REG_0, accept_all ? 0xffffffff : 0); | |
9433 | tw32(MAC_HASH_REG_1, accept_all ? 0xffffffff : 0); | |
9434 | tw32(MAC_HASH_REG_2, accept_all ? 0xffffffff : 0); | |
9435 | tw32(MAC_HASH_REG_3, accept_all ? 0xffffffff : 0); | |
9436 | } | |
9437 | ||
9438 | static void __tg3_set_rx_mode(struct net_device *dev) | |
9439 | { | |
9440 | struct tg3 *tp = netdev_priv(dev); | |
9441 | u32 rx_mode; | |
9442 | ||
9443 | rx_mode = tp->rx_mode & ~(RX_MODE_PROMISC | | |
9444 | RX_MODE_KEEP_VLAN_TAG); | |
9445 | ||
9446 | #if !defined(CONFIG_VLAN_8021Q) && !defined(CONFIG_VLAN_8021Q_MODULE) | |
9447 | /* When ASF is in use, we always keep the RX_MODE_KEEP_VLAN_TAG | |
9448 | * flag clear. | |
9449 | */ | |
9450 | if (!tg3_flag(tp, ENABLE_ASF)) | |
9451 | rx_mode |= RX_MODE_KEEP_VLAN_TAG; | |
9452 | #endif | |
9453 | ||
9454 | if (dev->flags & IFF_PROMISC) { | |
9455 | /* Promiscuous mode. */ | |
9456 | rx_mode |= RX_MODE_PROMISC; | |
9457 | } else if (dev->flags & IFF_ALLMULTI) { | |
9458 | /* Accept all multicast. */ | |
9459 | tg3_set_multi(tp, 1); | |
9460 | } else if (netdev_mc_empty(dev)) { | |
9461 | /* Reject all multicast. */ | |
9462 | tg3_set_multi(tp, 0); | |
9463 | } else { | |
9464 | /* Accept one or more multicast(s). */ | |
9465 | struct netdev_hw_addr *ha; | |
9466 | u32 mc_filter[4] = { 0, }; | |
9467 | u32 regidx; | |
9468 | u32 bit; | |
9469 | u32 crc; | |
9470 | ||
9471 | netdev_for_each_mc_addr(ha, dev) { | |
9472 | crc = calc_crc(ha->addr, ETH_ALEN); | |
9473 | bit = ~crc & 0x7f; | |
9474 | regidx = (bit & 0x60) >> 5; | |
9475 | bit &= 0x1f; | |
9476 | mc_filter[regidx] |= (1 << bit); | |
9477 | } | |
9478 | ||
9479 | tw32(MAC_HASH_REG_0, mc_filter[0]); | |
9480 | tw32(MAC_HASH_REG_1, mc_filter[1]); | |
9481 | tw32(MAC_HASH_REG_2, mc_filter[2]); | |
9482 | tw32(MAC_HASH_REG_3, mc_filter[3]); | |
9483 | } | |
9484 | ||
9485 | if (rx_mode != tp->rx_mode) { | |
9486 | tp->rx_mode = rx_mode; | |
9487 | tw32_f(MAC_RX_MODE, rx_mode); | |
9488 | udelay(10); | |
9489 | } | |
9490 | } | |
9491 | ||
9102426a | 9492 | static void tg3_rss_init_dflt_indir_tbl(struct tg3 *tp, u32 qcnt) |
90415477 MC |
9493 | { |
9494 | int i; | |
9495 | ||
9496 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) | |
9102426a | 9497 | tp->rss_ind_tbl[i] = ethtool_rxfh_indir_default(i, qcnt); |
90415477 MC |
9498 | } |
9499 | ||
9500 | static void tg3_rss_check_indir_tbl(struct tg3 *tp) | |
bcebcc46 MC |
9501 | { |
9502 | int i; | |
9503 | ||
9504 | if (!tg3_flag(tp, SUPPORT_MSIX)) | |
9505 | return; | |
9506 | ||
0b3ba055 | 9507 | if (tp->rxq_cnt == 1) { |
bcebcc46 | 9508 | memset(&tp->rss_ind_tbl[0], 0, sizeof(tp->rss_ind_tbl)); |
90415477 MC |
9509 | return; |
9510 | } | |
9511 | ||
9512 | /* Validate table against current IRQ count */ | |
9513 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) { | |
0b3ba055 | 9514 | if (tp->rss_ind_tbl[i] >= tp->rxq_cnt) |
90415477 MC |
9515 | break; |
9516 | } | |
9517 | ||
9518 | if (i != TG3_RSS_INDIR_TBL_SIZE) | |
9102426a | 9519 | tg3_rss_init_dflt_indir_tbl(tp, tp->rxq_cnt); |
bcebcc46 MC |
9520 | } |
9521 | ||
90415477 | 9522 | static void tg3_rss_write_indir_tbl(struct tg3 *tp) |
bcebcc46 MC |
9523 | { |
9524 | int i = 0; | |
9525 | u32 reg = MAC_RSS_INDIR_TBL_0; | |
9526 | ||
9527 | while (i < TG3_RSS_INDIR_TBL_SIZE) { | |
9528 | u32 val = tp->rss_ind_tbl[i]; | |
9529 | i++; | |
9530 | for (; i % 8; i++) { | |
9531 | val <<= 4; | |
9532 | val |= tp->rss_ind_tbl[i]; | |
9533 | } | |
9534 | tw32(reg, val); | |
9535 | reg += 4; | |
9536 | } | |
9537 | } | |
9538 | ||
9bc297ea NS |
9539 | static inline u32 tg3_lso_rd_dma_workaround_bit(struct tg3 *tp) |
9540 | { | |
9541 | if (tg3_asic_rev(tp) == ASIC_REV_5719) | |
9542 | return TG3_LSO_RD_DMA_TX_LENGTH_WA_5719; | |
9543 | else | |
9544 | return TG3_LSO_RD_DMA_TX_LENGTH_WA_5720; | |
9545 | } | |
9546 | ||
1da177e4 | 9547 | /* tp->lock is held. */ |
953c96e0 | 9548 | static int tg3_reset_hw(struct tg3 *tp, bool reset_phy) |
1da177e4 LT |
9549 | { |
9550 | u32 val, rdmac_mode; | |
9551 | int i, err, limit; | |
8fea32b9 | 9552 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
1da177e4 LT |
9553 | |
9554 | tg3_disable_ints(tp); | |
9555 | ||
9556 | tg3_stop_fw(tp); | |
9557 | ||
9558 | tg3_write_sig_pre_reset(tp, RESET_KIND_INIT); | |
9559 | ||
63c3a66f | 9560 | if (tg3_flag(tp, INIT_COMPLETE)) |
e6de8ad1 | 9561 | tg3_abort_hw(tp, 1); |
1da177e4 | 9562 | |
699c0193 MC |
9563 | /* Enable MAC control of LPI */ |
9564 | if (tp->phy_flags & TG3_PHYFLG_EEE_CAP) { | |
c65a17f4 MC |
9565 | val = TG3_CPMU_EEE_LNKIDL_PCIE_NL0 | |
9566 | TG3_CPMU_EEE_LNKIDL_UART_IDL; | |
4153577a | 9567 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_57765_A0) |
c65a17f4 MC |
9568 | val |= TG3_CPMU_EEE_LNKIDL_APE_TX_MT; |
9569 | ||
9570 | tw32_f(TG3_CPMU_EEE_LNKIDL_CTRL, val); | |
699c0193 MC |
9571 | |
9572 | tw32_f(TG3_CPMU_EEE_CTRL, | |
9573 | TG3_CPMU_EEE_CTRL_EXIT_20_1_US); | |
9574 | ||
a386b901 MC |
9575 | val = TG3_CPMU_EEEMD_ERLY_L1_XIT_DET | |
9576 | TG3_CPMU_EEEMD_LPI_IN_TX | | |
9577 | TG3_CPMU_EEEMD_LPI_IN_RX | | |
9578 | TG3_CPMU_EEEMD_EEE_ENABLE; | |
9579 | ||
4153577a | 9580 | if (tg3_asic_rev(tp) != ASIC_REV_5717) |
a386b901 MC |
9581 | val |= TG3_CPMU_EEEMD_SND_IDX_DET_EN; |
9582 | ||
63c3a66f | 9583 | if (tg3_flag(tp, ENABLE_APE)) |
a386b901 MC |
9584 | val |= TG3_CPMU_EEEMD_APE_TX_DET_EN; |
9585 | ||
9586 | tw32_f(TG3_CPMU_EEE_MODE, val); | |
9587 | ||
9588 | tw32_f(TG3_CPMU_EEE_DBTMR1, | |
9589 | TG3_CPMU_DBTMR1_PCIEXIT_2047US | | |
9590 | TG3_CPMU_DBTMR1_LNKIDLE_2047US); | |
9591 | ||
9592 | tw32_f(TG3_CPMU_EEE_DBTMR2, | |
d7f2ab20 | 9593 | TG3_CPMU_DBTMR2_APE_TX_2047US | |
a386b901 | 9594 | TG3_CPMU_DBTMR2_TXIDXEQ_2047US); |
699c0193 MC |
9595 | } |
9596 | ||
fdad8de4 NS |
9597 | if ((tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN) && |
9598 | !(tp->phy_flags & TG3_PHYFLG_USER_CONFIGURED)) { | |
9599 | tg3_phy_pull_config(tp); | |
9600 | tp->phy_flags |= TG3_PHYFLG_USER_CONFIGURED; | |
9601 | } | |
9602 | ||
603f1173 | 9603 | if (reset_phy) |
d4d2c558 MC |
9604 | tg3_phy_reset(tp); |
9605 | ||
1da177e4 LT |
9606 | err = tg3_chip_reset(tp); |
9607 | if (err) | |
9608 | return err; | |
9609 | ||
9610 | tg3_write_sig_legacy(tp, RESET_KIND_INIT); | |
9611 | ||
4153577a | 9612 | if (tg3_chip_rev(tp) == CHIPREV_5784_AX) { |
d30cdd28 MC |
9613 | val = tr32(TG3_CPMU_CTRL); |
9614 | val &= ~(CPMU_CTRL_LINK_AWARE_MODE | CPMU_CTRL_LINK_IDLE_MODE); | |
9615 | tw32(TG3_CPMU_CTRL, val); | |
9acb961e MC |
9616 | |
9617 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); | |
9618 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; | |
9619 | val |= CPMU_LSPD_10MB_MACCLK_6_25; | |
9620 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); | |
9621 | ||
9622 | val = tr32(TG3_CPMU_LNK_AWARE_PWRMD); | |
9623 | val &= ~CPMU_LNK_AWARE_MACCLK_MASK; | |
9624 | val |= CPMU_LNK_AWARE_MACCLK_6_25; | |
9625 | tw32(TG3_CPMU_LNK_AWARE_PWRMD, val); | |
9626 | ||
9627 | val = tr32(TG3_CPMU_HST_ACC); | |
9628 | val &= ~CPMU_HST_ACC_MACCLK_MASK; | |
9629 | val |= CPMU_HST_ACC_MACCLK_6_25; | |
9630 | tw32(TG3_CPMU_HST_ACC, val); | |
d30cdd28 MC |
9631 | } |
9632 | ||
4153577a | 9633 | if (tg3_asic_rev(tp) == ASIC_REV_57780) { |
33466d93 MC |
9634 | val = tr32(PCIE_PWR_MGMT_THRESH) & ~PCIE_PWR_MGMT_L1_THRESH_MSK; |
9635 | val |= PCIE_PWR_MGMT_EXT_ASPM_TMR_EN | | |
9636 | PCIE_PWR_MGMT_L1_THRESH_4MS; | |
9637 | tw32(PCIE_PWR_MGMT_THRESH, val); | |
521e6b90 MC |
9638 | |
9639 | val = tr32(TG3_PCIE_EIDLE_DELAY) & ~TG3_PCIE_EIDLE_DELAY_MASK; | |
9640 | tw32(TG3_PCIE_EIDLE_DELAY, val | TG3_PCIE_EIDLE_DELAY_13_CLKS); | |
9641 | ||
9642 | tw32(TG3_CORR_ERR_STAT, TG3_CORR_ERR_STAT_CLEAR); | |
33466d93 | 9643 | |
f40386c8 MC |
9644 | val = tr32(TG3_PCIE_LNKCTL) & ~TG3_PCIE_LNKCTL_L1_PLL_PD_EN; |
9645 | tw32(TG3_PCIE_LNKCTL, val | TG3_PCIE_LNKCTL_L1_PLL_PD_DIS); | |
255ca311 MC |
9646 | } |
9647 | ||
63c3a66f | 9648 | if (tg3_flag(tp, L1PLLPD_EN)) { |
614b0590 MC |
9649 | u32 grc_mode = tr32(GRC_MODE); |
9650 | ||
9651 | /* Access the lower 1K of PL PCIE block registers. */ | |
9652 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; | |
9653 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); | |
9654 | ||
9655 | val = tr32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1); | |
9656 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL1, | |
9657 | val | TG3_PCIE_PL_LO_PHYCTL1_L1PLLPD_EN); | |
9658 | ||
9659 | tw32(GRC_MODE, grc_mode); | |
9660 | } | |
9661 | ||
55086ad9 | 9662 | if (tg3_flag(tp, 57765_CLASS)) { |
4153577a | 9663 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_57765_A0) { |
5093eedc | 9664 | u32 grc_mode = tr32(GRC_MODE); |
cea46462 | 9665 | |
5093eedc MC |
9666 | /* Access the lower 1K of PL PCIE block registers. */ |
9667 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; | |
9668 | tw32(GRC_MODE, val | GRC_MODE_PCIE_PL_SEL); | |
cea46462 | 9669 | |
5093eedc MC |
9670 | val = tr32(TG3_PCIE_TLDLPL_PORT + |
9671 | TG3_PCIE_PL_LO_PHYCTL5); | |
9672 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_PL_LO_PHYCTL5, | |
9673 | val | TG3_PCIE_PL_LO_PHYCTL5_DIS_L2CLKREQ); | |
cea46462 | 9674 | |
5093eedc MC |
9675 | tw32(GRC_MODE, grc_mode); |
9676 | } | |
a977dbe8 | 9677 | |
4153577a | 9678 | if (tg3_chip_rev(tp) != CHIPREV_57765_AX) { |
d3f677af MC |
9679 | u32 grc_mode; |
9680 | ||
9681 | /* Fix transmit hangs */ | |
9682 | val = tr32(TG3_CPMU_PADRNG_CTL); | |
9683 | val |= TG3_CPMU_PADRNG_CTL_RDIV2; | |
9684 | tw32(TG3_CPMU_PADRNG_CTL, val); | |
9685 | ||
9686 | grc_mode = tr32(GRC_MODE); | |
1ff30a59 MC |
9687 | |
9688 | /* Access the lower 1K of DL PCIE block registers. */ | |
9689 | val = grc_mode & ~GRC_MODE_PCIE_PORT_MASK; | |
9690 | tw32(GRC_MODE, val | GRC_MODE_PCIE_DL_SEL); | |
9691 | ||
9692 | val = tr32(TG3_PCIE_TLDLPL_PORT + | |
9693 | TG3_PCIE_DL_LO_FTSMAX); | |
9694 | val &= ~TG3_PCIE_DL_LO_FTSMAX_MSK; | |
9695 | tw32(TG3_PCIE_TLDLPL_PORT + TG3_PCIE_DL_LO_FTSMAX, | |
9696 | val | TG3_PCIE_DL_LO_FTSMAX_VAL); | |
9697 | ||
9698 | tw32(GRC_MODE, grc_mode); | |
9699 | } | |
9700 | ||
a977dbe8 MC |
9701 | val = tr32(TG3_CPMU_LSPD_10MB_CLK); |
9702 | val &= ~CPMU_LSPD_10MB_MACCLK_MASK; | |
9703 | val |= CPMU_LSPD_10MB_MACCLK_6_25; | |
9704 | tw32(TG3_CPMU_LSPD_10MB_CLK, val); | |
cea46462 MC |
9705 | } |
9706 | ||
1da177e4 LT |
9707 | /* This works around an issue with Athlon chipsets on |
9708 | * B3 tigon3 silicon. This bit has no effect on any | |
9709 | * other revision. But do not set this on PCI Express | |
795d01c5 | 9710 | * chips and don't even touch the clocks if the CPMU is present. |
1da177e4 | 9711 | */ |
63c3a66f JP |
9712 | if (!tg3_flag(tp, CPMU_PRESENT)) { |
9713 | if (!tg3_flag(tp, PCI_EXPRESS)) | |
795d01c5 MC |
9714 | tp->pci_clock_ctrl |= CLOCK_CTRL_DELAY_PCI_GRANT; |
9715 | tw32_f(TG3PCI_CLOCK_CTRL, tp->pci_clock_ctrl); | |
9716 | } | |
1da177e4 | 9717 | |
4153577a | 9718 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5704_A0 && |
63c3a66f | 9719 | tg3_flag(tp, PCIX_MODE)) { |
1da177e4 LT |
9720 | val = tr32(TG3PCI_PCISTATE); |
9721 | val |= PCISTATE_RETRY_SAME_DMA; | |
9722 | tw32(TG3PCI_PCISTATE, val); | |
9723 | } | |
9724 | ||
63c3a66f | 9725 | if (tg3_flag(tp, ENABLE_APE)) { |
0d3031d9 MC |
9726 | /* Allow reads and writes to the |
9727 | * APE register and memory space. | |
9728 | */ | |
9729 | val = tr32(TG3PCI_PCISTATE); | |
9730 | val |= PCISTATE_ALLOW_APE_CTLSPC_WR | | |
f92d9dc1 MC |
9731 | PCISTATE_ALLOW_APE_SHMEM_WR | |
9732 | PCISTATE_ALLOW_APE_PSPACE_WR; | |
0d3031d9 MC |
9733 | tw32(TG3PCI_PCISTATE, val); |
9734 | } | |
9735 | ||
4153577a | 9736 | if (tg3_chip_rev(tp) == CHIPREV_5704_BX) { |
1da177e4 LT |
9737 | /* Enable some hw fixes. */ |
9738 | val = tr32(TG3PCI_MSI_DATA); | |
9739 | val |= (1 << 26) | (1 << 28) | (1 << 29); | |
9740 | tw32(TG3PCI_MSI_DATA, val); | |
9741 | } | |
9742 | ||
9743 | /* Descriptor ring init may make accesses to the | |
9744 | * NIC SRAM area to setup the TX descriptors, so we | |
9745 | * can only do this after the hardware has been | |
9746 | * successfully reset. | |
9747 | */ | |
32d8c572 MC |
9748 | err = tg3_init_rings(tp); |
9749 | if (err) | |
9750 | return err; | |
1da177e4 | 9751 | |
63c3a66f | 9752 | if (tg3_flag(tp, 57765_PLUS)) { |
cbf9ca6c MC |
9753 | val = tr32(TG3PCI_DMA_RW_CTRL) & |
9754 | ~DMA_RWCTRL_DIS_CACHE_ALIGNMENT; | |
4153577a | 9755 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_57765_A0) |
1a319025 | 9756 | val &= ~DMA_RWCTRL_CRDRDR_RDMA_MRRS_MSK; |
55086ad9 | 9757 | if (!tg3_flag(tp, 57765_CLASS) && |
4153577a JP |
9758 | tg3_asic_rev(tp) != ASIC_REV_5717 && |
9759 | tg3_asic_rev(tp) != ASIC_REV_5762) | |
0aebff48 | 9760 | val |= DMA_RWCTRL_TAGGED_STAT_WA; |
cbf9ca6c | 9761 | tw32(TG3PCI_DMA_RW_CTRL, val | tp->dma_rwctrl); |
4153577a JP |
9762 | } else if (tg3_asic_rev(tp) != ASIC_REV_5784 && |
9763 | tg3_asic_rev(tp) != ASIC_REV_5761) { | |
d30cdd28 MC |
9764 | /* This value is determined during the probe time DMA |
9765 | * engine test, tg3_test_dma. | |
9766 | */ | |
9767 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); | |
9768 | } | |
1da177e4 LT |
9769 | |
9770 | tp->grc_mode &= ~(GRC_MODE_HOST_SENDBDS | | |
9771 | GRC_MODE_4X_NIC_SEND_RINGS | | |
9772 | GRC_MODE_NO_TX_PHDR_CSUM | | |
9773 | GRC_MODE_NO_RX_PHDR_CSUM); | |
9774 | tp->grc_mode |= GRC_MODE_HOST_SENDBDS; | |
d2d746f8 MC |
9775 | |
9776 | /* Pseudo-header checksum is done by hardware logic and not | |
9777 | * the offload processers, so make the chip do the pseudo- | |
9778 | * header checksums on receive. For transmit it is more | |
9779 | * convenient to do the pseudo-header checksum in software | |
9780 | * as Linux does that on transmit for us in all cases. | |
9781 | */ | |
9782 | tp->grc_mode |= GRC_MODE_NO_TX_PHDR_CSUM; | |
1da177e4 | 9783 | |
fb4ce8ad MC |
9784 | val = GRC_MODE_IRQ_ON_MAC_ATTN | GRC_MODE_HOST_STACKUP; |
9785 | if (tp->rxptpctl) | |
9786 | tw32(TG3_RX_PTP_CTL, | |
9787 | tp->rxptpctl | TG3_RX_PTP_CTL_HWTS_INTERLOCK); | |
9788 | ||
9789 | if (tg3_flag(tp, PTP_CAPABLE)) | |
9790 | val |= GRC_MODE_TIME_SYNC_ENABLE; | |
9791 | ||
9792 | tw32(GRC_MODE, tp->grc_mode | val); | |
1da177e4 LT |
9793 | |
9794 | /* Setup the timer prescalar register. Clock is always 66Mhz. */ | |
9795 | val = tr32(GRC_MISC_CFG); | |
9796 | val &= ~0xff; | |
9797 | val |= (65 << GRC_MISC_CFG_PRESCALAR_SHIFT); | |
9798 | tw32(GRC_MISC_CFG, val); | |
9799 | ||
9800 | /* Initialize MBUF/DESC pool. */ | |
63c3a66f | 9801 | if (tg3_flag(tp, 5750_PLUS)) { |
1da177e4 | 9802 | /* Do nothing. */ |
4153577a | 9803 | } else if (tg3_asic_rev(tp) != ASIC_REV_5705) { |
1da177e4 | 9804 | tw32(BUFMGR_MB_POOL_ADDR, NIC_SRAM_MBUF_POOL_BASE); |
4153577a | 9805 | if (tg3_asic_rev(tp) == ASIC_REV_5704) |
1da177e4 LT |
9806 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE64); |
9807 | else | |
9808 | tw32(BUFMGR_MB_POOL_SIZE, NIC_SRAM_MBUF_POOL_SIZE96); | |
9809 | tw32(BUFMGR_DMA_DESC_POOL_ADDR, NIC_SRAM_DMA_DESC_POOL_BASE); | |
9810 | tw32(BUFMGR_DMA_DESC_POOL_SIZE, NIC_SRAM_DMA_DESC_POOL_SIZE); | |
63c3a66f | 9811 | } else if (tg3_flag(tp, TSO_CAPABLE)) { |
1da177e4 LT |
9812 | int fw_len; |
9813 | ||
077f849d | 9814 | fw_len = tp->fw_len; |
1da177e4 LT |
9815 | fw_len = (fw_len + (0x80 - 1)) & ~(0x80 - 1); |
9816 | tw32(BUFMGR_MB_POOL_ADDR, | |
9817 | NIC_SRAM_MBUF_POOL_BASE5705 + fw_len); | |
9818 | tw32(BUFMGR_MB_POOL_SIZE, | |
9819 | NIC_SRAM_MBUF_POOL_SIZE5705 - fw_len - 0xa00); | |
9820 | } | |
1da177e4 | 9821 | |
0f893dc6 | 9822 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
1da177e4 LT |
9823 | tw32(BUFMGR_MB_RDMA_LOW_WATER, |
9824 | tp->bufmgr_config.mbuf_read_dma_low_water); | |
9825 | tw32(BUFMGR_MB_MACRX_LOW_WATER, | |
9826 | tp->bufmgr_config.mbuf_mac_rx_low_water); | |
9827 | tw32(BUFMGR_MB_HIGH_WATER, | |
9828 | tp->bufmgr_config.mbuf_high_water); | |
9829 | } else { | |
9830 | tw32(BUFMGR_MB_RDMA_LOW_WATER, | |
9831 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo); | |
9832 | tw32(BUFMGR_MB_MACRX_LOW_WATER, | |
9833 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo); | |
9834 | tw32(BUFMGR_MB_HIGH_WATER, | |
9835 | tp->bufmgr_config.mbuf_high_water_jumbo); | |
9836 | } | |
9837 | tw32(BUFMGR_DMA_LOW_WATER, | |
9838 | tp->bufmgr_config.dma_low_water); | |
9839 | tw32(BUFMGR_DMA_HIGH_WATER, | |
9840 | tp->bufmgr_config.dma_high_water); | |
9841 | ||
d309a46e | 9842 | val = BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE; |
4153577a | 9843 | if (tg3_asic_rev(tp) == ASIC_REV_5719) |
d309a46e | 9844 | val |= BUFMGR_MODE_NO_TX_UNDERRUN; |
4153577a JP |
9845 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
9846 | tg3_chip_rev_id(tp) == CHIPREV_ID_5719_A0 || | |
9847 | tg3_chip_rev_id(tp) == CHIPREV_ID_5720_A0) | |
4d958473 | 9848 | val |= BUFMGR_MODE_MBLOW_ATTN_ENAB; |
d309a46e | 9849 | tw32(BUFMGR_MODE, val); |
1da177e4 LT |
9850 | for (i = 0; i < 2000; i++) { |
9851 | if (tr32(BUFMGR_MODE) & BUFMGR_MODE_ENABLE) | |
9852 | break; | |
9853 | udelay(10); | |
9854 | } | |
9855 | if (i >= 2000) { | |
05dbe005 | 9856 | netdev_err(tp->dev, "%s cannot enable BUFMGR\n", __func__); |
1da177e4 LT |
9857 | return -ENODEV; |
9858 | } | |
9859 | ||
4153577a | 9860 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5906_A1) |
eb07a940 | 9861 | tw32(ISO_PKT_TX, (tr32(ISO_PKT_TX) & ~0x3) | 0x2); |
b5d3772c | 9862 | |
eb07a940 | 9863 | tg3_setup_rxbd_thresholds(tp); |
1da177e4 LT |
9864 | |
9865 | /* Initialize TG3_BDINFO's at: | |
9866 | * RCVDBDI_STD_BD: standard eth size rx ring | |
9867 | * RCVDBDI_JUMBO_BD: jumbo frame rx ring | |
9868 | * RCVDBDI_MINI_BD: small frame rx ring (??? does not work) | |
9869 | * | |
9870 | * like so: | |
9871 | * TG3_BDINFO_HOST_ADDR: high/low parts of DMA address of ring | |
9872 | * TG3_BDINFO_MAXLEN_FLAGS: (rx max buffer size << 16) | | |
9873 | * ring attribute flags | |
9874 | * TG3_BDINFO_NIC_ADDR: location of descriptors in nic SRAM | |
9875 | * | |
9876 | * Standard receive ring @ NIC_SRAM_RX_BUFFER_DESC, 512 entries. | |
9877 | * Jumbo receive ring @ NIC_SRAM_RX_JUMBO_BUFFER_DESC, 256 entries. | |
9878 | * | |
9879 | * The size of each ring is fixed in the firmware, but the location is | |
9880 | * configurable. | |
9881 | */ | |
9882 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, | |
21f581a5 | 9883 | ((u64) tpr->rx_std_mapping >> 32)); |
1da177e4 | 9884 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
21f581a5 | 9885 | ((u64) tpr->rx_std_mapping & 0xffffffff)); |
63c3a66f | 9886 | if (!tg3_flag(tp, 5717_PLUS)) |
87668d35 MC |
9887 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_NIC_ADDR, |
9888 | NIC_SRAM_RX_BUFFER_DESC); | |
1da177e4 | 9889 | |
fdb72b38 | 9890 | /* Disable the mini ring */ |
63c3a66f | 9891 | if (!tg3_flag(tp, 5705_PLUS)) |
1da177e4 LT |
9892 | tw32(RCVDBDI_MINI_BD + TG3_BDINFO_MAXLEN_FLAGS, |
9893 | BDINFO_FLAGS_DISABLED); | |
9894 | ||
fdb72b38 MC |
9895 | /* Program the jumbo buffer descriptor ring control |
9896 | * blocks on those devices that have them. | |
9897 | */ | |
4153577a | 9898 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5719_A0 || |
63c3a66f | 9899 | (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS))) { |
1da177e4 | 9900 | |
63c3a66f | 9901 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) { |
1da177e4 | 9902 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_HIGH, |
21f581a5 | 9903 | ((u64) tpr->rx_jmb_mapping >> 32)); |
1da177e4 | 9904 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_HOST_ADDR + TG3_64BIT_REG_LOW, |
21f581a5 | 9905 | ((u64) tpr->rx_jmb_mapping & 0xffffffff)); |
de9f5230 MC |
9906 | val = TG3_RX_JMB_RING_SIZE(tp) << |
9907 | BDINFO_FLAGS_MAXLEN_SHIFT; | |
1da177e4 | 9908 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, |
de9f5230 | 9909 | val | BDINFO_FLAGS_USE_EXT_RECV); |
63c3a66f | 9910 | if (!tg3_flag(tp, USE_JUMBO_BDFLAG) || |
c65a17f4 | 9911 | tg3_flag(tp, 57765_CLASS) || |
4153577a | 9912 | tg3_asic_rev(tp) == ASIC_REV_5762) |
87668d35 MC |
9913 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_NIC_ADDR, |
9914 | NIC_SRAM_RX_JUMBO_BUFFER_DESC); | |
1da177e4 LT |
9915 | } else { |
9916 | tw32(RCVDBDI_JUMBO_BD + TG3_BDINFO_MAXLEN_FLAGS, | |
9917 | BDINFO_FLAGS_DISABLED); | |
9918 | } | |
9919 | ||
63c3a66f | 9920 | if (tg3_flag(tp, 57765_PLUS)) { |
fa6b2aae | 9921 | val = TG3_RX_STD_RING_SIZE(tp); |
7cb32cf2 MC |
9922 | val <<= BDINFO_FLAGS_MAXLEN_SHIFT; |
9923 | val |= (TG3_RX_STD_DMA_SZ << 2); | |
9924 | } else | |
04380d40 | 9925 | val = TG3_RX_STD_DMA_SZ << BDINFO_FLAGS_MAXLEN_SHIFT; |
fdb72b38 | 9926 | } else |
de9f5230 | 9927 | val = TG3_RX_STD_MAX_SIZE_5700 << BDINFO_FLAGS_MAXLEN_SHIFT; |
fdb72b38 MC |
9928 | |
9929 | tw32(RCVDBDI_STD_BD + TG3_BDINFO_MAXLEN_FLAGS, val); | |
1da177e4 | 9930 | |
411da640 | 9931 | tpr->rx_std_prod_idx = tp->rx_pending; |
66711e66 | 9932 | tw32_rx_mbox(TG3_RX_STD_PROD_IDX_REG, tpr->rx_std_prod_idx); |
1da177e4 | 9933 | |
63c3a66f JP |
9934 | tpr->rx_jmb_prod_idx = |
9935 | tg3_flag(tp, JUMBO_RING_ENABLE) ? tp->rx_jumbo_pending : 0; | |
66711e66 | 9936 | tw32_rx_mbox(TG3_RX_JMB_PROD_IDX_REG, tpr->rx_jmb_prod_idx); |
1da177e4 | 9937 | |
2d31ecaf MC |
9938 | tg3_rings_reset(tp); |
9939 | ||
1da177e4 | 9940 | /* Initialize MAC address and backoff seed. */ |
953c96e0 | 9941 | __tg3_set_mac_addr(tp, false); |
1da177e4 LT |
9942 | |
9943 | /* MTU + ethernet header + FCS + optional VLAN tag */ | |
f7b493e0 MC |
9944 | tw32(MAC_RX_MTU_SIZE, |
9945 | tp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN); | |
1da177e4 LT |
9946 | |
9947 | /* The slot time is changed by tg3_setup_phy if we | |
9948 | * run at gigabit with half duplex. | |
9949 | */ | |
f2096f94 MC |
9950 | val = (2 << TX_LENGTHS_IPG_CRS_SHIFT) | |
9951 | (6 << TX_LENGTHS_IPG_SHIFT) | | |
9952 | (32 << TX_LENGTHS_SLOT_TIME_SHIFT); | |
9953 | ||
4153577a JP |
9954 | if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
9955 | tg3_asic_rev(tp) == ASIC_REV_5762) | |
f2096f94 MC |
9956 | val |= tr32(MAC_TX_LENGTHS) & |
9957 | (TX_LENGTHS_JMB_FRM_LEN_MSK | | |
9958 | TX_LENGTHS_CNT_DWN_VAL_MSK); | |
9959 | ||
9960 | tw32(MAC_TX_LENGTHS, val); | |
1da177e4 LT |
9961 | |
9962 | /* Receive rules. */ | |
9963 | tw32(MAC_RCV_RULE_CFG, RCV_RULE_CFG_DEFAULT_CLASS); | |
9964 | tw32(RCVLPC_CONFIG, 0x0181); | |
9965 | ||
9966 | /* Calculate RDMAC_MODE setting early, we need it to determine | |
9967 | * the RCVLPC_STATE_ENABLE mask. | |
9968 | */ | |
9969 | rdmac_mode = (RDMAC_MODE_ENABLE | RDMAC_MODE_TGTABORT_ENAB | | |
9970 | RDMAC_MODE_MSTABORT_ENAB | RDMAC_MODE_PARITYERR_ENAB | | |
9971 | RDMAC_MODE_ADDROFLOW_ENAB | RDMAC_MODE_FIFOOFLOW_ENAB | | |
9972 | RDMAC_MODE_FIFOURUN_ENAB | RDMAC_MODE_FIFOOREAD_ENAB | | |
9973 | RDMAC_MODE_LNGREAD_ENAB); | |
85e94ced | 9974 | |
4153577a | 9975 | if (tg3_asic_rev(tp) == ASIC_REV_5717) |
0339e4e3 MC |
9976 | rdmac_mode |= RDMAC_MODE_MULT_DMA_RD_DIS; |
9977 | ||
4153577a JP |
9978 | if (tg3_asic_rev(tp) == ASIC_REV_5784 || |
9979 | tg3_asic_rev(tp) == ASIC_REV_5785 || | |
9980 | tg3_asic_rev(tp) == ASIC_REV_57780) | |
d30cdd28 MC |
9981 | rdmac_mode |= RDMAC_MODE_BD_SBD_CRPT_ENAB | |
9982 | RDMAC_MODE_MBUF_RBD_CRPT_ENAB | | |
9983 | RDMAC_MODE_MBUF_SBD_CRPT_ENAB; | |
9984 | ||
4153577a JP |
9985 | if (tg3_asic_rev(tp) == ASIC_REV_5705 && |
9986 | tg3_chip_rev_id(tp) != CHIPREV_ID_5705_A0) { | |
63c3a66f | 9987 | if (tg3_flag(tp, TSO_CAPABLE) && |
4153577a | 9988 | tg3_asic_rev(tp) == ASIC_REV_5705) { |
1da177e4 LT |
9989 | rdmac_mode |= RDMAC_MODE_FIFO_SIZE_128; |
9990 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && | |
63c3a66f | 9991 | !tg3_flag(tp, IS_5788)) { |
1da177e4 LT |
9992 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
9993 | } | |
9994 | } | |
9995 | ||
63c3a66f | 9996 | if (tg3_flag(tp, PCI_EXPRESS)) |
85e94ced MC |
9997 | rdmac_mode |= RDMAC_MODE_FIFO_LONG_BURST; |
9998 | ||
4153577a | 9999 | if (tg3_asic_rev(tp) == ASIC_REV_57766) { |
d3f677af MC |
10000 | tp->dma_limit = 0; |
10001 | if (tp->dev->mtu <= ETH_DATA_LEN) { | |
10002 | rdmac_mode |= RDMAC_MODE_JMB_2K_MMRR; | |
10003 | tp->dma_limit = TG3_TX_BD_DMA_MAX_2K; | |
10004 | } | |
10005 | } | |
10006 | ||
63c3a66f JP |
10007 | if (tg3_flag(tp, HW_TSO_1) || |
10008 | tg3_flag(tp, HW_TSO_2) || | |
10009 | tg3_flag(tp, HW_TSO_3)) | |
027455ad MC |
10010 | rdmac_mode |= RDMAC_MODE_IPV4_LSO_EN; |
10011 | ||
108a6c16 | 10012 | if (tg3_flag(tp, 57765_PLUS) || |
4153577a JP |
10013 | tg3_asic_rev(tp) == ASIC_REV_5785 || |
10014 | tg3_asic_rev(tp) == ASIC_REV_57780) | |
027455ad | 10015 | rdmac_mode |= RDMAC_MODE_IPV6_LSO_EN; |
1da177e4 | 10016 | |
4153577a JP |
10017 | if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
10018 | tg3_asic_rev(tp) == ASIC_REV_5762) | |
f2096f94 MC |
10019 | rdmac_mode |= tr32(RDMAC_MODE) & RDMAC_MODE_H2BNC_VLAN_DET; |
10020 | ||
4153577a JP |
10021 | if (tg3_asic_rev(tp) == ASIC_REV_5761 || |
10022 | tg3_asic_rev(tp) == ASIC_REV_5784 || | |
10023 | tg3_asic_rev(tp) == ASIC_REV_5785 || | |
10024 | tg3_asic_rev(tp) == ASIC_REV_57780 || | |
63c3a66f | 10025 | tg3_flag(tp, 57765_PLUS)) { |
c65a17f4 MC |
10026 | u32 tgtreg; |
10027 | ||
4153577a | 10028 | if (tg3_asic_rev(tp) == ASIC_REV_5762) |
c65a17f4 MC |
10029 | tgtreg = TG3_RDMA_RSRVCTRL_REG2; |
10030 | else | |
10031 | tgtreg = TG3_RDMA_RSRVCTRL_REG; | |
10032 | ||
10033 | val = tr32(tgtreg); | |
4153577a JP |
10034 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5719_A0 || |
10035 | tg3_asic_rev(tp) == ASIC_REV_5762) { | |
b4495ed8 MC |
10036 | val &= ~(TG3_RDMA_RSRVCTRL_TXMRGN_MASK | |
10037 | TG3_RDMA_RSRVCTRL_FIFO_LWM_MASK | | |
10038 | TG3_RDMA_RSRVCTRL_FIFO_HWM_MASK); | |
10039 | val |= TG3_RDMA_RSRVCTRL_TXMRGN_320B | | |
10040 | TG3_RDMA_RSRVCTRL_FIFO_LWM_1_5K | | |
10041 | TG3_RDMA_RSRVCTRL_FIFO_HWM_1_5K; | |
b75cc0e4 | 10042 | } |
c65a17f4 | 10043 | tw32(tgtreg, val | TG3_RDMA_RSRVCTRL_FIFO_OFLW_FIX); |
41a8a7ee MC |
10044 | } |
10045 | ||
4153577a JP |
10046 | if (tg3_asic_rev(tp) == ASIC_REV_5719 || |
10047 | tg3_asic_rev(tp) == ASIC_REV_5720 || | |
10048 | tg3_asic_rev(tp) == ASIC_REV_5762) { | |
c65a17f4 MC |
10049 | u32 tgtreg; |
10050 | ||
4153577a | 10051 | if (tg3_asic_rev(tp) == ASIC_REV_5762) |
c65a17f4 MC |
10052 | tgtreg = TG3_LSO_RD_DMA_CRPTEN_CTRL2; |
10053 | else | |
10054 | tgtreg = TG3_LSO_RD_DMA_CRPTEN_CTRL; | |
10055 | ||
10056 | val = tr32(tgtreg); | |
10057 | tw32(tgtreg, val | | |
d309a46e MC |
10058 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_BD_4K | |
10059 | TG3_LSO_RD_DMA_CRPTEN_CTRL_BLEN_LSO_4K); | |
10060 | } | |
10061 | ||
1da177e4 | 10062 | /* Receive/send statistics. */ |
63c3a66f | 10063 | if (tg3_flag(tp, 5750_PLUS)) { |
1661394e MC |
10064 | val = tr32(RCVLPC_STATS_ENABLE); |
10065 | val &= ~RCVLPC_STATSENAB_DACK_FIX; | |
10066 | tw32(RCVLPC_STATS_ENABLE, val); | |
10067 | } else if ((rdmac_mode & RDMAC_MODE_FIFO_SIZE_128) && | |
63c3a66f | 10068 | tg3_flag(tp, TSO_CAPABLE)) { |
1da177e4 LT |
10069 | val = tr32(RCVLPC_STATS_ENABLE); |
10070 | val &= ~RCVLPC_STATSENAB_LNGBRST_RFIX; | |
10071 | tw32(RCVLPC_STATS_ENABLE, val); | |
10072 | } else { | |
10073 | tw32(RCVLPC_STATS_ENABLE, 0xffffff); | |
10074 | } | |
10075 | tw32(RCVLPC_STATSCTRL, RCVLPC_STATSCTRL_ENABLE); | |
10076 | tw32(SNDDATAI_STATSENAB, 0xffffff); | |
10077 | tw32(SNDDATAI_STATSCTRL, | |
10078 | (SNDDATAI_SCTRL_ENABLE | | |
10079 | SNDDATAI_SCTRL_FASTUPD)); | |
10080 | ||
10081 | /* Setup host coalescing engine. */ | |
10082 | tw32(HOSTCC_MODE, 0); | |
10083 | for (i = 0; i < 2000; i++) { | |
10084 | if (!(tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE)) | |
10085 | break; | |
10086 | udelay(10); | |
10087 | } | |
10088 | ||
d244c892 | 10089 | __tg3_set_coalesce(tp, &tp->coal); |
1da177e4 | 10090 | |
63c3a66f | 10091 | if (!tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
10092 | /* Status/statistics block address. See tg3_timer, |
10093 | * the tg3_periodic_fetch_stats call there, and | |
10094 | * tg3_get_stats to see how this works for 5705/5750 chips. | |
10095 | */ | |
1da177e4 LT |
10096 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_HIGH, |
10097 | ((u64) tp->stats_mapping >> 32)); | |
10098 | tw32(HOSTCC_STATS_BLK_HOST_ADDR + TG3_64BIT_REG_LOW, | |
10099 | ((u64) tp->stats_mapping & 0xffffffff)); | |
10100 | tw32(HOSTCC_STATS_BLK_NIC_ADDR, NIC_SRAM_STATS_BLK); | |
2d31ecaf | 10101 | |
1da177e4 | 10102 | tw32(HOSTCC_STATUS_BLK_NIC_ADDR, NIC_SRAM_STATUS_BLK); |
2d31ecaf MC |
10103 | |
10104 | /* Clear statistics and status block memory areas */ | |
10105 | for (i = NIC_SRAM_STATS_BLK; | |
10106 | i < NIC_SRAM_STATUS_BLK + TG3_HW_STATUS_SIZE; | |
10107 | i += sizeof(u32)) { | |
10108 | tg3_write_mem(tp, i, 0); | |
10109 | udelay(40); | |
10110 | } | |
1da177e4 LT |
10111 | } |
10112 | ||
10113 | tw32(HOSTCC_MODE, HOSTCC_MODE_ENABLE | tp->coalesce_mode); | |
10114 | ||
10115 | tw32(RCVCC_MODE, RCVCC_MODE_ENABLE | RCVCC_MODE_ATTN_ENABLE); | |
10116 | tw32(RCVLPC_MODE, RCVLPC_MODE_ENABLE); | |
63c3a66f | 10117 | if (!tg3_flag(tp, 5705_PLUS)) |
1da177e4 LT |
10118 | tw32(RCVLSC_MODE, RCVLSC_MODE_ENABLE | RCVLSC_MODE_ATTN_ENABLE); |
10119 | ||
f07e9af3 MC |
10120 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) { |
10121 | tp->phy_flags &= ~TG3_PHYFLG_PARALLEL_DETECT; | |
c94e3941 MC |
10122 | /* reset to prevent losing 1st rx packet intermittently */ |
10123 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); | |
10124 | udelay(10); | |
10125 | } | |
10126 | ||
3bda1258 | 10127 | tp->mac_mode |= MAC_MODE_TXSTAT_ENABLE | MAC_MODE_RXSTAT_ENABLE | |
9e975cc2 MC |
10128 | MAC_MODE_TDE_ENABLE | MAC_MODE_RDE_ENABLE | |
10129 | MAC_MODE_FHDE_ENABLE; | |
10130 | if (tg3_flag(tp, ENABLE_APE)) | |
10131 | tp->mac_mode |= MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; | |
63c3a66f | 10132 | if (!tg3_flag(tp, 5705_PLUS) && |
f07e9af3 | 10133 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
4153577a | 10134 | tg3_asic_rev(tp) != ASIC_REV_5700) |
e8f3f6ca | 10135 | tp->mac_mode |= MAC_MODE_LINK_POLARITY; |
1da177e4 LT |
10136 | tw32_f(MAC_MODE, tp->mac_mode | MAC_MODE_RXSTAT_CLEAR | MAC_MODE_TXSTAT_CLEAR); |
10137 | udelay(40); | |
10138 | ||
314fba34 | 10139 | /* tp->grc_local_ctrl is partially set up during tg3_get_invariants(). |
63c3a66f | 10140 | * If TG3_FLAG_IS_NIC is zero, we should read the |
314fba34 MC |
10141 | * register to preserve the GPIO settings for LOMs. The GPIOs, |
10142 | * whether used as inputs or outputs, are set by boot code after | |
10143 | * reset. | |
10144 | */ | |
63c3a66f | 10145 | if (!tg3_flag(tp, IS_NIC)) { |
314fba34 MC |
10146 | u32 gpio_mask; |
10147 | ||
9d26e213 MC |
10148 | gpio_mask = GRC_LCLCTRL_GPIO_OE0 | GRC_LCLCTRL_GPIO_OE1 | |
10149 | GRC_LCLCTRL_GPIO_OE2 | GRC_LCLCTRL_GPIO_OUTPUT0 | | |
10150 | GRC_LCLCTRL_GPIO_OUTPUT1 | GRC_LCLCTRL_GPIO_OUTPUT2; | |
3e7d83bc | 10151 | |
4153577a | 10152 | if (tg3_asic_rev(tp) == ASIC_REV_5752) |
3e7d83bc MC |
10153 | gpio_mask |= GRC_LCLCTRL_GPIO_OE3 | |
10154 | GRC_LCLCTRL_GPIO_OUTPUT3; | |
10155 | ||
4153577a | 10156 | if (tg3_asic_rev(tp) == ASIC_REV_5755) |
af36e6b6 MC |
10157 | gpio_mask |= GRC_LCLCTRL_GPIO_UART_SEL; |
10158 | ||
aaf84465 | 10159 | tp->grc_local_ctrl &= ~gpio_mask; |
314fba34 MC |
10160 | tp->grc_local_ctrl |= tr32(GRC_LOCAL_CTRL) & gpio_mask; |
10161 | ||
10162 | /* GPIO1 must be driven high for eeprom write protect */ | |
63c3a66f | 10163 | if (tg3_flag(tp, EEPROM_WRITE_PROT)) |
9d26e213 MC |
10164 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
10165 | GRC_LCLCTRL_GPIO_OUTPUT1); | |
314fba34 | 10166 | } |
1da177e4 LT |
10167 | tw32_f(GRC_LOCAL_CTRL, tp->grc_local_ctrl); |
10168 | udelay(100); | |
10169 | ||
c3b5003b | 10170 | if (tg3_flag(tp, USING_MSIX)) { |
baf8a94a | 10171 | val = tr32(MSGINT_MODE); |
c3b5003b MC |
10172 | val |= MSGINT_MODE_ENABLE; |
10173 | if (tp->irq_cnt > 1) | |
10174 | val |= MSGINT_MODE_MULTIVEC_EN; | |
5b39de91 MC |
10175 | if (!tg3_flag(tp, 1SHOT_MSI)) |
10176 | val |= MSGINT_MODE_ONE_SHOT_DISABLE; | |
baf8a94a MC |
10177 | tw32(MSGINT_MODE, val); |
10178 | } | |
10179 | ||
63c3a66f | 10180 | if (!tg3_flag(tp, 5705_PLUS)) { |
1da177e4 LT |
10181 | tw32_f(DMAC_MODE, DMAC_MODE_ENABLE); |
10182 | udelay(40); | |
10183 | } | |
10184 | ||
10185 | val = (WDMAC_MODE_ENABLE | WDMAC_MODE_TGTABORT_ENAB | | |
10186 | WDMAC_MODE_MSTABORT_ENAB | WDMAC_MODE_PARITYERR_ENAB | | |
10187 | WDMAC_MODE_ADDROFLOW_ENAB | WDMAC_MODE_FIFOOFLOW_ENAB | | |
10188 | WDMAC_MODE_FIFOURUN_ENAB | WDMAC_MODE_FIFOOREAD_ENAB | | |
10189 | WDMAC_MODE_LNGREAD_ENAB); | |
10190 | ||
4153577a JP |
10191 | if (tg3_asic_rev(tp) == ASIC_REV_5705 && |
10192 | tg3_chip_rev_id(tp) != CHIPREV_ID_5705_A0) { | |
63c3a66f | 10193 | if (tg3_flag(tp, TSO_CAPABLE) && |
4153577a JP |
10194 | (tg3_chip_rev_id(tp) == CHIPREV_ID_5705_A1 || |
10195 | tg3_chip_rev_id(tp) == CHIPREV_ID_5705_A2)) { | |
1da177e4 LT |
10196 | /* nothing */ |
10197 | } else if (!(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH) && | |
63c3a66f | 10198 | !tg3_flag(tp, IS_5788)) { |
1da177e4 LT |
10199 | val |= WDMAC_MODE_RX_ACCEL; |
10200 | } | |
10201 | } | |
10202 | ||
d9ab5ad1 | 10203 | /* Enable host coalescing bug fix */ |
63c3a66f | 10204 | if (tg3_flag(tp, 5755_PLUS)) |
f51f3562 | 10205 | val |= WDMAC_MODE_STATUS_TAG_FIX; |
d9ab5ad1 | 10206 | |
4153577a | 10207 | if (tg3_asic_rev(tp) == ASIC_REV_5785) |
788a035e MC |
10208 | val |= WDMAC_MODE_BURST_ALL_DATA; |
10209 | ||
1da177e4 LT |
10210 | tw32_f(WDMAC_MODE, val); |
10211 | udelay(40); | |
10212 | ||
63c3a66f | 10213 | if (tg3_flag(tp, PCIX_MODE)) { |
9974a356 MC |
10214 | u16 pcix_cmd; |
10215 | ||
10216 | pci_read_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, | |
10217 | &pcix_cmd); | |
4153577a | 10218 | if (tg3_asic_rev(tp) == ASIC_REV_5703) { |
9974a356 MC |
10219 | pcix_cmd &= ~PCI_X_CMD_MAX_READ; |
10220 | pcix_cmd |= PCI_X_CMD_READ_2K; | |
4153577a | 10221 | } else if (tg3_asic_rev(tp) == ASIC_REV_5704) { |
9974a356 MC |
10222 | pcix_cmd &= ~(PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ); |
10223 | pcix_cmd |= PCI_X_CMD_READ_2K; | |
1da177e4 | 10224 | } |
9974a356 MC |
10225 | pci_write_config_word(tp->pdev, tp->pcix_cap + PCI_X_CMD, |
10226 | pcix_cmd); | |
1da177e4 LT |
10227 | } |
10228 | ||
10229 | tw32_f(RDMAC_MODE, rdmac_mode); | |
10230 | udelay(40); | |
10231 | ||
9bc297ea NS |
10232 | if (tg3_asic_rev(tp) == ASIC_REV_5719 || |
10233 | tg3_asic_rev(tp) == ASIC_REV_5720) { | |
091f0ea3 MC |
10234 | for (i = 0; i < TG3_NUM_RDMA_CHANNELS; i++) { |
10235 | if (tr32(TG3_RDMA_LENGTH + (i << 2)) > TG3_MAX_MTU(tp)) | |
10236 | break; | |
10237 | } | |
10238 | if (i < TG3_NUM_RDMA_CHANNELS) { | |
10239 | val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); | |
9bc297ea | 10240 | val |= tg3_lso_rd_dma_workaround_bit(tp); |
091f0ea3 | 10241 | tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val); |
9bc297ea | 10242 | tg3_flag_set(tp, 5719_5720_RDMA_BUG); |
091f0ea3 MC |
10243 | } |
10244 | } | |
10245 | ||
1da177e4 | 10246 | tw32(RCVDCC_MODE, RCVDCC_MODE_ENABLE | RCVDCC_MODE_ATTN_ENABLE); |
63c3a66f | 10247 | if (!tg3_flag(tp, 5705_PLUS)) |
1da177e4 | 10248 | tw32(MBFREE_MODE, MBFREE_MODE_ENABLE); |
9936bcf6 | 10249 | |
4153577a | 10250 | if (tg3_asic_rev(tp) == ASIC_REV_5761) |
9936bcf6 MC |
10251 | tw32(SNDDATAC_MODE, |
10252 | SNDDATAC_MODE_ENABLE | SNDDATAC_MODE_CDELAY); | |
10253 | else | |
10254 | tw32(SNDDATAC_MODE, SNDDATAC_MODE_ENABLE); | |
10255 | ||
1da177e4 LT |
10256 | tw32(SNDBDC_MODE, SNDBDC_MODE_ENABLE | SNDBDC_MODE_ATTN_ENABLE); |
10257 | tw32(RCVBDI_MODE, RCVBDI_MODE_ENABLE | RCVBDI_MODE_RCB_ATTN_ENAB); | |
7cb32cf2 | 10258 | val = RCVDBDI_MODE_ENABLE | RCVDBDI_MODE_INV_RING_SZ; |
63c3a66f | 10259 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
7cb32cf2 MC |
10260 | val |= RCVDBDI_MODE_LRG_RING_SZ; |
10261 | tw32(RCVDBDI_MODE, val); | |
1da177e4 | 10262 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE); |
63c3a66f JP |
10263 | if (tg3_flag(tp, HW_TSO_1) || |
10264 | tg3_flag(tp, HW_TSO_2) || | |
10265 | tg3_flag(tp, HW_TSO_3)) | |
1da177e4 | 10266 | tw32(SNDDATAI_MODE, SNDDATAI_MODE_ENABLE | 0x8); |
baf8a94a | 10267 | val = SNDBDI_MODE_ENABLE | SNDBDI_MODE_ATTN_ENABLE; |
63c3a66f | 10268 | if (tg3_flag(tp, ENABLE_TSS)) |
baf8a94a MC |
10269 | val |= SNDBDI_MODE_MULTI_TXQ_EN; |
10270 | tw32(SNDBDI_MODE, val); | |
1da177e4 LT |
10271 | tw32(SNDBDS_MODE, SNDBDS_MODE_ENABLE | SNDBDS_MODE_ATTN_ENABLE); |
10272 | ||
4153577a | 10273 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0) { |
1da177e4 LT |
10274 | err = tg3_load_5701_a0_firmware_fix(tp); |
10275 | if (err) | |
10276 | return err; | |
10277 | } | |
10278 | ||
c4dab506 NS |
10279 | if (tg3_asic_rev(tp) == ASIC_REV_57766) { |
10280 | /* Ignore any errors for the firmware download. If download | |
10281 | * fails, the device will operate with EEE disabled | |
10282 | */ | |
10283 | tg3_load_57766_firmware(tp); | |
10284 | } | |
10285 | ||
63c3a66f | 10286 | if (tg3_flag(tp, TSO_CAPABLE)) { |
1da177e4 LT |
10287 | err = tg3_load_tso_firmware(tp); |
10288 | if (err) | |
10289 | return err; | |
10290 | } | |
1da177e4 LT |
10291 | |
10292 | tp->tx_mode = TX_MODE_ENABLE; | |
f2096f94 | 10293 | |
63c3a66f | 10294 | if (tg3_flag(tp, 5755_PLUS) || |
4153577a | 10295 | tg3_asic_rev(tp) == ASIC_REV_5906) |
b1d05210 | 10296 | tp->tx_mode |= TX_MODE_MBUF_LOCKUP_FIX; |
f2096f94 | 10297 | |
4153577a JP |
10298 | if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
10299 | tg3_asic_rev(tp) == ASIC_REV_5762) { | |
f2096f94 MC |
10300 | val = TX_MODE_JMB_FRM_LEN | TX_MODE_CNT_DN_MODE; |
10301 | tp->tx_mode &= ~val; | |
10302 | tp->tx_mode |= tr32(MAC_TX_MODE) & val; | |
10303 | } | |
10304 | ||
1da177e4 LT |
10305 | tw32_f(MAC_TX_MODE, tp->tx_mode); |
10306 | udelay(100); | |
10307 | ||
63c3a66f | 10308 | if (tg3_flag(tp, ENABLE_RSS)) { |
bcebcc46 | 10309 | tg3_rss_write_indir_tbl(tp); |
baf8a94a MC |
10310 | |
10311 | /* Setup the "secret" hash key. */ | |
10312 | tw32(MAC_RSS_HASH_KEY_0, 0x5f865437); | |
10313 | tw32(MAC_RSS_HASH_KEY_1, 0xe4ac62cc); | |
10314 | tw32(MAC_RSS_HASH_KEY_2, 0x50103a45); | |
10315 | tw32(MAC_RSS_HASH_KEY_3, 0x36621985); | |
10316 | tw32(MAC_RSS_HASH_KEY_4, 0xbf14c0e8); | |
10317 | tw32(MAC_RSS_HASH_KEY_5, 0x1bc27a1e); | |
10318 | tw32(MAC_RSS_HASH_KEY_6, 0x84f4b556); | |
10319 | tw32(MAC_RSS_HASH_KEY_7, 0x094ea6fe); | |
10320 | tw32(MAC_RSS_HASH_KEY_8, 0x7dda01e7); | |
10321 | tw32(MAC_RSS_HASH_KEY_9, 0xc04d7481); | |
10322 | } | |
10323 | ||
1da177e4 | 10324 | tp->rx_mode = RX_MODE_ENABLE; |
63c3a66f | 10325 | if (tg3_flag(tp, 5755_PLUS)) |
af36e6b6 MC |
10326 | tp->rx_mode |= RX_MODE_IPV6_CSUM_ENABLE; |
10327 | ||
63c3a66f | 10328 | if (tg3_flag(tp, ENABLE_RSS)) |
baf8a94a MC |
10329 | tp->rx_mode |= RX_MODE_RSS_ENABLE | |
10330 | RX_MODE_RSS_ITBL_HASH_BITS_7 | | |
10331 | RX_MODE_RSS_IPV6_HASH_EN | | |
10332 | RX_MODE_RSS_TCP_IPV6_HASH_EN | | |
10333 | RX_MODE_RSS_IPV4_HASH_EN | | |
10334 | RX_MODE_RSS_TCP_IPV4_HASH_EN; | |
10335 | ||
1da177e4 LT |
10336 | tw32_f(MAC_RX_MODE, tp->rx_mode); |
10337 | udelay(10); | |
10338 | ||
1da177e4 LT |
10339 | tw32(MAC_LED_CTRL, tp->led_ctrl); |
10340 | ||
10341 | tw32(MAC_MI_STAT, MAC_MI_STAT_LNKSTAT_ATTN_ENAB); | |
f07e9af3 | 10342 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
1da177e4 LT |
10343 | tw32_f(MAC_RX_MODE, RX_MODE_RESET); |
10344 | udelay(10); | |
10345 | } | |
10346 | tw32_f(MAC_RX_MODE, tp->rx_mode); | |
10347 | udelay(10); | |
10348 | ||
f07e9af3 | 10349 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
4153577a JP |
10350 | if ((tg3_asic_rev(tp) == ASIC_REV_5704) && |
10351 | !(tp->phy_flags & TG3_PHYFLG_SERDES_PREEMPHASIS)) { | |
1da177e4 LT |
10352 | /* Set drive transmission level to 1.2V */ |
10353 | /* only if the signal pre-emphasis bit is not set */ | |
10354 | val = tr32(MAC_SERDES_CFG); | |
10355 | val &= 0xfffff000; | |
10356 | val |= 0x880; | |
10357 | tw32(MAC_SERDES_CFG, val); | |
10358 | } | |
4153577a | 10359 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5703_A1) |
1da177e4 LT |
10360 | tw32(MAC_SERDES_CFG, 0x616000); |
10361 | } | |
10362 | ||
10363 | /* Prevent chip from dropping frames when flow control | |
10364 | * is enabled. | |
10365 | */ | |
55086ad9 | 10366 | if (tg3_flag(tp, 57765_CLASS)) |
666bc831 MC |
10367 | val = 1; |
10368 | else | |
10369 | val = 2; | |
10370 | tw32_f(MAC_LOW_WMARK_MAX_RX_FRAME, val); | |
1da177e4 | 10371 | |
4153577a | 10372 | if (tg3_asic_rev(tp) == ASIC_REV_5704 && |
f07e9af3 | 10373 | (tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
1da177e4 | 10374 | /* Use hardware link auto-negotiation */ |
63c3a66f | 10375 | tg3_flag_set(tp, HW_AUTONEG); |
1da177e4 LT |
10376 | } |
10377 | ||
f07e9af3 | 10378 | if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
4153577a | 10379 | tg3_asic_rev(tp) == ASIC_REV_5714) { |
d4d2c558 MC |
10380 | u32 tmp; |
10381 | ||
10382 | tmp = tr32(SERDES_RX_CTRL); | |
10383 | tw32(SERDES_RX_CTRL, tmp | SERDES_RX_SIG_DETECT); | |
10384 | tp->grc_local_ctrl &= ~GRC_LCLCTRL_USE_EXT_SIG_DETECT; | |
10385 | tp->grc_local_ctrl |= GRC_LCLCTRL_USE_SIG_DETECT; | |
10386 | tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl); | |
10387 | } | |
10388 | ||
63c3a66f | 10389 | if (!tg3_flag(tp, USE_PHYLIB)) { |
c6700ce2 | 10390 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
80096068 | 10391 | tp->phy_flags &= ~TG3_PHYFLG_IS_LOW_POWER; |
1da177e4 | 10392 | |
953c96e0 | 10393 | err = tg3_setup_phy(tp, false); |
dd477003 MC |
10394 | if (err) |
10395 | return err; | |
1da177e4 | 10396 | |
f07e9af3 MC |
10397 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
10398 | !(tp->phy_flags & TG3_PHYFLG_IS_FET)) { | |
dd477003 MC |
10399 | u32 tmp; |
10400 | ||
10401 | /* Clear CRC stats. */ | |
10402 | if (!tg3_readphy(tp, MII_TG3_TEST1, &tmp)) { | |
10403 | tg3_writephy(tp, MII_TG3_TEST1, | |
10404 | tmp | MII_TG3_TEST1_CRC_EN); | |
f08aa1a8 | 10405 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &tmp); |
dd477003 | 10406 | } |
1da177e4 LT |
10407 | } |
10408 | } | |
10409 | ||
10410 | __tg3_set_rx_mode(tp->dev); | |
10411 | ||
10412 | /* Initialize receive rules. */ | |
10413 | tw32(MAC_RCV_RULE_0, 0xc2000000 & RCV_RULE_DISABLE_MASK); | |
10414 | tw32(MAC_RCV_VALUE_0, 0xffffffff & RCV_RULE_DISABLE_MASK); | |
10415 | tw32(MAC_RCV_RULE_1, 0x86000004 & RCV_RULE_DISABLE_MASK); | |
10416 | tw32(MAC_RCV_VALUE_1, 0xffffffff & RCV_RULE_DISABLE_MASK); | |
10417 | ||
63c3a66f | 10418 | if (tg3_flag(tp, 5705_PLUS) && !tg3_flag(tp, 5780_CLASS)) |
1da177e4 LT |
10419 | limit = 8; |
10420 | else | |
10421 | limit = 16; | |
63c3a66f | 10422 | if (tg3_flag(tp, ENABLE_ASF)) |
1da177e4 LT |
10423 | limit -= 4; |
10424 | switch (limit) { | |
10425 | case 16: | |
10426 | tw32(MAC_RCV_RULE_15, 0); tw32(MAC_RCV_VALUE_15, 0); | |
10427 | case 15: | |
10428 | tw32(MAC_RCV_RULE_14, 0); tw32(MAC_RCV_VALUE_14, 0); | |
10429 | case 14: | |
10430 | tw32(MAC_RCV_RULE_13, 0); tw32(MAC_RCV_VALUE_13, 0); | |
10431 | case 13: | |
10432 | tw32(MAC_RCV_RULE_12, 0); tw32(MAC_RCV_VALUE_12, 0); | |
10433 | case 12: | |
10434 | tw32(MAC_RCV_RULE_11, 0); tw32(MAC_RCV_VALUE_11, 0); | |
10435 | case 11: | |
10436 | tw32(MAC_RCV_RULE_10, 0); tw32(MAC_RCV_VALUE_10, 0); | |
10437 | case 10: | |
10438 | tw32(MAC_RCV_RULE_9, 0); tw32(MAC_RCV_VALUE_9, 0); | |
10439 | case 9: | |
10440 | tw32(MAC_RCV_RULE_8, 0); tw32(MAC_RCV_VALUE_8, 0); | |
10441 | case 8: | |
10442 | tw32(MAC_RCV_RULE_7, 0); tw32(MAC_RCV_VALUE_7, 0); | |
10443 | case 7: | |
10444 | tw32(MAC_RCV_RULE_6, 0); tw32(MAC_RCV_VALUE_6, 0); | |
10445 | case 6: | |
10446 | tw32(MAC_RCV_RULE_5, 0); tw32(MAC_RCV_VALUE_5, 0); | |
10447 | case 5: | |
10448 | tw32(MAC_RCV_RULE_4, 0); tw32(MAC_RCV_VALUE_4, 0); | |
10449 | case 4: | |
10450 | /* tw32(MAC_RCV_RULE_3, 0); tw32(MAC_RCV_VALUE_3, 0); */ | |
10451 | case 3: | |
10452 | /* tw32(MAC_RCV_RULE_2, 0); tw32(MAC_RCV_VALUE_2, 0); */ | |
10453 | case 2: | |
10454 | case 1: | |
10455 | ||
10456 | default: | |
10457 | break; | |
855e1111 | 10458 | } |
1da177e4 | 10459 | |
63c3a66f | 10460 | if (tg3_flag(tp, ENABLE_APE)) |
9ce768ea MC |
10461 | /* Write our heartbeat update interval to APE. */ |
10462 | tg3_ape_write32(tp, TG3_APE_HOST_HEARTBEAT_INT_MS, | |
10463 | APE_HOST_HEARTBEAT_INT_DISABLE); | |
0d3031d9 | 10464 | |
1da177e4 LT |
10465 | tg3_write_sig_post_reset(tp, RESET_KIND_INIT); |
10466 | ||
1da177e4 LT |
10467 | return 0; |
10468 | } | |
10469 | ||
10470 | /* Called at device open time to get the chip ready for | |
10471 | * packet processing. Invoked with tp->lock held. | |
10472 | */ | |
953c96e0 | 10473 | static int tg3_init_hw(struct tg3 *tp, bool reset_phy) |
1da177e4 | 10474 | { |
df465abf NS |
10475 | /* Chip may have been just powered on. If so, the boot code may still |
10476 | * be running initialization. Wait for it to finish to avoid races in | |
10477 | * accessing the hardware. | |
10478 | */ | |
10479 | tg3_enable_register_access(tp); | |
10480 | tg3_poll_fw(tp); | |
10481 | ||
1da177e4 LT |
10482 | tg3_switch_clocks(tp); |
10483 | ||
10484 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
10485 | ||
2f751b67 | 10486 | return tg3_reset_hw(tp, reset_phy); |
1da177e4 LT |
10487 | } |
10488 | ||
aed93e0b MC |
10489 | static void tg3_sd_scan_scratchpad(struct tg3 *tp, struct tg3_ocir *ocir) |
10490 | { | |
10491 | int i; | |
10492 | ||
10493 | for (i = 0; i < TG3_SD_NUM_RECS; i++, ocir++) { | |
10494 | u32 off = i * TG3_OCIR_LEN, len = TG3_OCIR_LEN; | |
10495 | ||
10496 | tg3_ape_scratchpad_read(tp, (u32 *) ocir, off, len); | |
10497 | off += len; | |
10498 | ||
10499 | if (ocir->signature != TG3_OCIR_SIG_MAGIC || | |
10500 | !(ocir->version_flags & TG3_OCIR_FLAG_ACTIVE)) | |
10501 | memset(ocir, 0, TG3_OCIR_LEN); | |
10502 | } | |
10503 | } | |
10504 | ||
10505 | /* sysfs attributes for hwmon */ | |
10506 | static ssize_t tg3_show_temp(struct device *dev, | |
10507 | struct device_attribute *devattr, char *buf) | |
10508 | { | |
10509 | struct pci_dev *pdev = to_pci_dev(dev); | |
10510 | struct net_device *netdev = pci_get_drvdata(pdev); | |
10511 | struct tg3 *tp = netdev_priv(netdev); | |
10512 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | |
10513 | u32 temperature; | |
10514 | ||
10515 | spin_lock_bh(&tp->lock); | |
10516 | tg3_ape_scratchpad_read(tp, &temperature, attr->index, | |
10517 | sizeof(temperature)); | |
10518 | spin_unlock_bh(&tp->lock); | |
10519 | return sprintf(buf, "%u\n", temperature); | |
10520 | } | |
10521 | ||
10522 | ||
10523 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, tg3_show_temp, NULL, | |
10524 | TG3_TEMP_SENSOR_OFFSET); | |
10525 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, tg3_show_temp, NULL, | |
10526 | TG3_TEMP_CAUTION_OFFSET); | |
10527 | static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, tg3_show_temp, NULL, | |
10528 | TG3_TEMP_MAX_OFFSET); | |
10529 | ||
10530 | static struct attribute *tg3_attributes[] = { | |
10531 | &sensor_dev_attr_temp1_input.dev_attr.attr, | |
10532 | &sensor_dev_attr_temp1_crit.dev_attr.attr, | |
10533 | &sensor_dev_attr_temp1_max.dev_attr.attr, | |
10534 | NULL | |
10535 | }; | |
10536 | ||
10537 | static const struct attribute_group tg3_group = { | |
10538 | .attrs = tg3_attributes, | |
10539 | }; | |
10540 | ||
aed93e0b MC |
10541 | static void tg3_hwmon_close(struct tg3 *tp) |
10542 | { | |
aed93e0b MC |
10543 | if (tp->hwmon_dev) { |
10544 | hwmon_device_unregister(tp->hwmon_dev); | |
10545 | tp->hwmon_dev = NULL; | |
10546 | sysfs_remove_group(&tp->pdev->dev.kobj, &tg3_group); | |
10547 | } | |
aed93e0b MC |
10548 | } |
10549 | ||
10550 | static void tg3_hwmon_open(struct tg3 *tp) | |
10551 | { | |
aed93e0b MC |
10552 | int i, err; |
10553 | u32 size = 0; | |
10554 | struct pci_dev *pdev = tp->pdev; | |
10555 | struct tg3_ocir ocirs[TG3_SD_NUM_RECS]; | |
10556 | ||
10557 | tg3_sd_scan_scratchpad(tp, ocirs); | |
10558 | ||
10559 | for (i = 0; i < TG3_SD_NUM_RECS; i++) { | |
10560 | if (!ocirs[i].src_data_length) | |
10561 | continue; | |
10562 | ||
10563 | size += ocirs[i].src_hdr_length; | |
10564 | size += ocirs[i].src_data_length; | |
10565 | } | |
10566 | ||
10567 | if (!size) | |
10568 | return; | |
10569 | ||
10570 | /* Register hwmon sysfs hooks */ | |
10571 | err = sysfs_create_group(&pdev->dev.kobj, &tg3_group); | |
10572 | if (err) { | |
10573 | dev_err(&pdev->dev, "Cannot create sysfs group, aborting\n"); | |
10574 | return; | |
10575 | } | |
10576 | ||
10577 | tp->hwmon_dev = hwmon_device_register(&pdev->dev); | |
10578 | if (IS_ERR(tp->hwmon_dev)) { | |
10579 | tp->hwmon_dev = NULL; | |
10580 | dev_err(&pdev->dev, "Cannot register hwmon device, aborting\n"); | |
10581 | sysfs_remove_group(&pdev->dev.kobj, &tg3_group); | |
10582 | } | |
aed93e0b MC |
10583 | } |
10584 | ||
10585 | ||
1da177e4 LT |
10586 | #define TG3_STAT_ADD32(PSTAT, REG) \ |
10587 | do { u32 __val = tr32(REG); \ | |
10588 | (PSTAT)->low += __val; \ | |
10589 | if ((PSTAT)->low < __val) \ | |
10590 | (PSTAT)->high += 1; \ | |
10591 | } while (0) | |
10592 | ||
10593 | static void tg3_periodic_fetch_stats(struct tg3 *tp) | |
10594 | { | |
10595 | struct tg3_hw_stats *sp = tp->hw_stats; | |
10596 | ||
f4a46d1f | 10597 | if (!tp->link_up) |
1da177e4 LT |
10598 | return; |
10599 | ||
10600 | TG3_STAT_ADD32(&sp->tx_octets, MAC_TX_STATS_OCTETS); | |
10601 | TG3_STAT_ADD32(&sp->tx_collisions, MAC_TX_STATS_COLLISIONS); | |
10602 | TG3_STAT_ADD32(&sp->tx_xon_sent, MAC_TX_STATS_XON_SENT); | |
10603 | TG3_STAT_ADD32(&sp->tx_xoff_sent, MAC_TX_STATS_XOFF_SENT); | |
10604 | TG3_STAT_ADD32(&sp->tx_mac_errors, MAC_TX_STATS_MAC_ERRORS); | |
10605 | TG3_STAT_ADD32(&sp->tx_single_collisions, MAC_TX_STATS_SINGLE_COLLISIONS); | |
10606 | TG3_STAT_ADD32(&sp->tx_mult_collisions, MAC_TX_STATS_MULT_COLLISIONS); | |
10607 | TG3_STAT_ADD32(&sp->tx_deferred, MAC_TX_STATS_DEFERRED); | |
10608 | TG3_STAT_ADD32(&sp->tx_excessive_collisions, MAC_TX_STATS_EXCESSIVE_COL); | |
10609 | TG3_STAT_ADD32(&sp->tx_late_collisions, MAC_TX_STATS_LATE_COL); | |
10610 | TG3_STAT_ADD32(&sp->tx_ucast_packets, MAC_TX_STATS_UCAST); | |
10611 | TG3_STAT_ADD32(&sp->tx_mcast_packets, MAC_TX_STATS_MCAST); | |
10612 | TG3_STAT_ADD32(&sp->tx_bcast_packets, MAC_TX_STATS_BCAST); | |
9bc297ea | 10613 | if (unlikely(tg3_flag(tp, 5719_5720_RDMA_BUG) && |
091f0ea3 MC |
10614 | (sp->tx_ucast_packets.low + sp->tx_mcast_packets.low + |
10615 | sp->tx_bcast_packets.low) > TG3_NUM_RDMA_CHANNELS)) { | |
10616 | u32 val; | |
10617 | ||
10618 | val = tr32(TG3_LSO_RD_DMA_CRPTEN_CTRL); | |
9bc297ea | 10619 | val &= ~tg3_lso_rd_dma_workaround_bit(tp); |
091f0ea3 | 10620 | tw32(TG3_LSO_RD_DMA_CRPTEN_CTRL, val); |
9bc297ea | 10621 | tg3_flag_clear(tp, 5719_5720_RDMA_BUG); |
091f0ea3 | 10622 | } |
1da177e4 LT |
10623 | |
10624 | TG3_STAT_ADD32(&sp->rx_octets, MAC_RX_STATS_OCTETS); | |
10625 | TG3_STAT_ADD32(&sp->rx_fragments, MAC_RX_STATS_FRAGMENTS); | |
10626 | TG3_STAT_ADD32(&sp->rx_ucast_packets, MAC_RX_STATS_UCAST); | |
10627 | TG3_STAT_ADD32(&sp->rx_mcast_packets, MAC_RX_STATS_MCAST); | |
10628 | TG3_STAT_ADD32(&sp->rx_bcast_packets, MAC_RX_STATS_BCAST); | |
10629 | TG3_STAT_ADD32(&sp->rx_fcs_errors, MAC_RX_STATS_FCS_ERRORS); | |
10630 | TG3_STAT_ADD32(&sp->rx_align_errors, MAC_RX_STATS_ALIGN_ERRORS); | |
10631 | TG3_STAT_ADD32(&sp->rx_xon_pause_rcvd, MAC_RX_STATS_XON_PAUSE_RECVD); | |
10632 | TG3_STAT_ADD32(&sp->rx_xoff_pause_rcvd, MAC_RX_STATS_XOFF_PAUSE_RECVD); | |
10633 | TG3_STAT_ADD32(&sp->rx_mac_ctrl_rcvd, MAC_RX_STATS_MAC_CTRL_RECVD); | |
10634 | TG3_STAT_ADD32(&sp->rx_xoff_entered, MAC_RX_STATS_XOFF_ENTERED); | |
10635 | TG3_STAT_ADD32(&sp->rx_frame_too_long_errors, MAC_RX_STATS_FRAME_TOO_LONG); | |
10636 | TG3_STAT_ADD32(&sp->rx_jabbers, MAC_RX_STATS_JABBERS); | |
10637 | TG3_STAT_ADD32(&sp->rx_undersize_packets, MAC_RX_STATS_UNDERSIZE); | |
463d305b MC |
10638 | |
10639 | TG3_STAT_ADD32(&sp->rxbds_empty, RCVLPC_NO_RCV_BD_CNT); | |
4153577a JP |
10640 | if (tg3_asic_rev(tp) != ASIC_REV_5717 && |
10641 | tg3_chip_rev_id(tp) != CHIPREV_ID_5719_A0 && | |
10642 | tg3_chip_rev_id(tp) != CHIPREV_ID_5720_A0) { | |
4d958473 MC |
10643 | TG3_STAT_ADD32(&sp->rx_discards, RCVLPC_IN_DISCARDS_CNT); |
10644 | } else { | |
10645 | u32 val = tr32(HOSTCC_FLOW_ATTN); | |
10646 | val = (val & HOSTCC_FLOW_ATTN_MBUF_LWM) ? 1 : 0; | |
10647 | if (val) { | |
10648 | tw32(HOSTCC_FLOW_ATTN, HOSTCC_FLOW_ATTN_MBUF_LWM); | |
10649 | sp->rx_discards.low += val; | |
10650 | if (sp->rx_discards.low < val) | |
10651 | sp->rx_discards.high += 1; | |
10652 | } | |
10653 | sp->mbuf_lwm_thresh_hit = sp->rx_discards; | |
10654 | } | |
463d305b | 10655 | TG3_STAT_ADD32(&sp->rx_errors, RCVLPC_IN_ERRORS_CNT); |
1da177e4 LT |
10656 | } |
10657 | ||
0e6cf6a9 MC |
10658 | static void tg3_chk_missed_msi(struct tg3 *tp) |
10659 | { | |
10660 | u32 i; | |
10661 | ||
10662 | for (i = 0; i < tp->irq_cnt; i++) { | |
10663 | struct tg3_napi *tnapi = &tp->napi[i]; | |
10664 | ||
10665 | if (tg3_has_work(tnapi)) { | |
10666 | if (tnapi->last_rx_cons == tnapi->rx_rcb_ptr && | |
10667 | tnapi->last_tx_cons == tnapi->tx_cons) { | |
10668 | if (tnapi->chk_msi_cnt < 1) { | |
10669 | tnapi->chk_msi_cnt++; | |
10670 | return; | |
10671 | } | |
7f230735 | 10672 | tg3_msi(0, tnapi); |
0e6cf6a9 MC |
10673 | } |
10674 | } | |
10675 | tnapi->chk_msi_cnt = 0; | |
10676 | tnapi->last_rx_cons = tnapi->rx_rcb_ptr; | |
10677 | tnapi->last_tx_cons = tnapi->tx_cons; | |
10678 | } | |
10679 | } | |
10680 | ||
1da177e4 LT |
10681 | static void tg3_timer(unsigned long __opaque) |
10682 | { | |
10683 | struct tg3 *tp = (struct tg3 *) __opaque; | |
1da177e4 | 10684 | |
5b190624 | 10685 | if (tp->irq_sync || tg3_flag(tp, RESET_TASK_PENDING)) |
f475f163 MC |
10686 | goto restart_timer; |
10687 | ||
f47c11ee | 10688 | spin_lock(&tp->lock); |
1da177e4 | 10689 | |
4153577a | 10690 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
55086ad9 | 10691 | tg3_flag(tp, 57765_CLASS)) |
0e6cf6a9 MC |
10692 | tg3_chk_missed_msi(tp); |
10693 | ||
7e6c63f0 HM |
10694 | if (tg3_flag(tp, FLUSH_POSTED_WRITES)) { |
10695 | /* BCM4785: Flush posted writes from GbE to host memory. */ | |
10696 | tr32(HOSTCC_MODE); | |
10697 | } | |
10698 | ||
63c3a66f | 10699 | if (!tg3_flag(tp, TAGGED_STATUS)) { |
fac9b83e DM |
10700 | /* All of this garbage is because when using non-tagged |
10701 | * IRQ status the mailbox/status_block protocol the chip | |
10702 | * uses with the cpu is race prone. | |
10703 | */ | |
898a56f8 | 10704 | if (tp->napi[0].hw_status->status & SD_STATUS_UPDATED) { |
fac9b83e DM |
10705 | tw32(GRC_LOCAL_CTRL, |
10706 | tp->grc_local_ctrl | GRC_LCLCTRL_SETINT); | |
10707 | } else { | |
10708 | tw32(HOSTCC_MODE, tp->coalesce_mode | | |
fd2ce37f | 10709 | HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW); |
fac9b83e | 10710 | } |
1da177e4 | 10711 | |
fac9b83e | 10712 | if (!(tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { |
f47c11ee | 10713 | spin_unlock(&tp->lock); |
db219973 | 10714 | tg3_reset_task_schedule(tp); |
5b190624 | 10715 | goto restart_timer; |
fac9b83e | 10716 | } |
1da177e4 LT |
10717 | } |
10718 | ||
1da177e4 LT |
10719 | /* This part only runs once per second. */ |
10720 | if (!--tp->timer_counter) { | |
63c3a66f | 10721 | if (tg3_flag(tp, 5705_PLUS)) |
fac9b83e DM |
10722 | tg3_periodic_fetch_stats(tp); |
10723 | ||
b0c5943f MC |
10724 | if (tp->setlpicnt && !--tp->setlpicnt) |
10725 | tg3_phy_eee_enable(tp); | |
52b02d04 | 10726 | |
63c3a66f | 10727 | if (tg3_flag(tp, USE_LINKCHG_REG)) { |
1da177e4 LT |
10728 | u32 mac_stat; |
10729 | int phy_event; | |
10730 | ||
10731 | mac_stat = tr32(MAC_STATUS); | |
10732 | ||
10733 | phy_event = 0; | |
f07e9af3 | 10734 | if (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) { |
1da177e4 LT |
10735 | if (mac_stat & MAC_STATUS_MI_INTERRUPT) |
10736 | phy_event = 1; | |
10737 | } else if (mac_stat & MAC_STATUS_LNKSTATE_CHANGED) | |
10738 | phy_event = 1; | |
10739 | ||
10740 | if (phy_event) | |
953c96e0 | 10741 | tg3_setup_phy(tp, false); |
63c3a66f | 10742 | } else if (tg3_flag(tp, POLL_SERDES)) { |
1da177e4 LT |
10743 | u32 mac_stat = tr32(MAC_STATUS); |
10744 | int need_setup = 0; | |
10745 | ||
f4a46d1f | 10746 | if (tp->link_up && |
1da177e4 LT |
10747 | (mac_stat & MAC_STATUS_LNKSTATE_CHANGED)) { |
10748 | need_setup = 1; | |
10749 | } | |
f4a46d1f | 10750 | if (!tp->link_up && |
1da177e4 LT |
10751 | (mac_stat & (MAC_STATUS_PCS_SYNCED | |
10752 | MAC_STATUS_SIGNAL_DET))) { | |
10753 | need_setup = 1; | |
10754 | } | |
10755 | if (need_setup) { | |
3d3ebe74 MC |
10756 | if (!tp->serdes_counter) { |
10757 | tw32_f(MAC_MODE, | |
10758 | (tp->mac_mode & | |
10759 | ~MAC_MODE_PORT_MODE_MASK)); | |
10760 | udelay(40); | |
10761 | tw32_f(MAC_MODE, tp->mac_mode); | |
10762 | udelay(40); | |
10763 | } | |
953c96e0 | 10764 | tg3_setup_phy(tp, false); |
1da177e4 | 10765 | } |
f07e9af3 | 10766 | } else if ((tp->phy_flags & TG3_PHYFLG_MII_SERDES) && |
63c3a66f | 10767 | tg3_flag(tp, 5780_CLASS)) { |
747e8f8b | 10768 | tg3_serdes_parallel_detect(tp); |
57d8b880 | 10769 | } |
1da177e4 LT |
10770 | |
10771 | tp->timer_counter = tp->timer_multiplier; | |
10772 | } | |
10773 | ||
130b8e4d MC |
10774 | /* Heartbeat is only sent once every 2 seconds. |
10775 | * | |
10776 | * The heartbeat is to tell the ASF firmware that the host | |
10777 | * driver is still alive. In the event that the OS crashes, | |
10778 | * ASF needs to reset the hardware to free up the FIFO space | |
10779 | * that may be filled with rx packets destined for the host. | |
10780 | * If the FIFO is full, ASF will no longer function properly. | |
10781 | * | |
10782 | * Unintended resets have been reported on real time kernels | |
10783 | * where the timer doesn't run on time. Netpoll will also have | |
10784 | * same problem. | |
10785 | * | |
10786 | * The new FWCMD_NICDRV_ALIVE3 command tells the ASF firmware | |
10787 | * to check the ring condition when the heartbeat is expiring | |
10788 | * before doing the reset. This will prevent most unintended | |
10789 | * resets. | |
10790 | */ | |
1da177e4 | 10791 | if (!--tp->asf_counter) { |
63c3a66f | 10792 | if (tg3_flag(tp, ENABLE_ASF) && !tg3_flag(tp, ENABLE_APE)) { |
7c5026aa MC |
10793 | tg3_wait_for_event_ack(tp); |
10794 | ||
bbadf503 | 10795 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX, |
130b8e4d | 10796 | FWCMD_NICDRV_ALIVE3); |
bbadf503 | 10797 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4); |
c6cdf436 MC |
10798 | tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, |
10799 | TG3_FW_UPDATE_TIMEOUT_SEC); | |
4ba526ce MC |
10800 | |
10801 | tg3_generate_fw_event(tp); | |
1da177e4 LT |
10802 | } |
10803 | tp->asf_counter = tp->asf_multiplier; | |
10804 | } | |
10805 | ||
f47c11ee | 10806 | spin_unlock(&tp->lock); |
1da177e4 | 10807 | |
f475f163 | 10808 | restart_timer: |
1da177e4 LT |
10809 | tp->timer.expires = jiffies + tp->timer_offset; |
10810 | add_timer(&tp->timer); | |
10811 | } | |
10812 | ||
229b1ad1 | 10813 | static void tg3_timer_init(struct tg3 *tp) |
21f7638e MC |
10814 | { |
10815 | if (tg3_flag(tp, TAGGED_STATUS) && | |
4153577a | 10816 | tg3_asic_rev(tp) != ASIC_REV_5717 && |
21f7638e MC |
10817 | !tg3_flag(tp, 57765_CLASS)) |
10818 | tp->timer_offset = HZ; | |
10819 | else | |
10820 | tp->timer_offset = HZ / 10; | |
10821 | ||
10822 | BUG_ON(tp->timer_offset > HZ); | |
10823 | ||
10824 | tp->timer_multiplier = (HZ / tp->timer_offset); | |
10825 | tp->asf_multiplier = (HZ / tp->timer_offset) * | |
10826 | TG3_FW_UPDATE_FREQ_SEC; | |
10827 | ||
10828 | init_timer(&tp->timer); | |
10829 | tp->timer.data = (unsigned long) tp; | |
10830 | tp->timer.function = tg3_timer; | |
10831 | } | |
10832 | ||
10833 | static void tg3_timer_start(struct tg3 *tp) | |
10834 | { | |
10835 | tp->asf_counter = tp->asf_multiplier; | |
10836 | tp->timer_counter = tp->timer_multiplier; | |
10837 | ||
10838 | tp->timer.expires = jiffies + tp->timer_offset; | |
10839 | add_timer(&tp->timer); | |
10840 | } | |
10841 | ||
10842 | static void tg3_timer_stop(struct tg3 *tp) | |
10843 | { | |
10844 | del_timer_sync(&tp->timer); | |
10845 | } | |
10846 | ||
10847 | /* Restart hardware after configuration changes, self-test, etc. | |
10848 | * Invoked with tp->lock held. | |
10849 | */ | |
953c96e0 | 10850 | static int tg3_restart_hw(struct tg3 *tp, bool reset_phy) |
21f7638e MC |
10851 | __releases(tp->lock) |
10852 | __acquires(tp->lock) | |
10853 | { | |
10854 | int err; | |
10855 | ||
10856 | err = tg3_init_hw(tp, reset_phy); | |
10857 | if (err) { | |
10858 | netdev_err(tp->dev, | |
10859 | "Failed to re-initialize device, aborting\n"); | |
10860 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); | |
10861 | tg3_full_unlock(tp); | |
10862 | tg3_timer_stop(tp); | |
10863 | tp->irq_sync = 0; | |
10864 | tg3_napi_enable(tp); | |
10865 | dev_close(tp->dev); | |
10866 | tg3_full_lock(tp, 0); | |
10867 | } | |
10868 | return err; | |
10869 | } | |
10870 | ||
10871 | static void tg3_reset_task(struct work_struct *work) | |
10872 | { | |
10873 | struct tg3 *tp = container_of(work, struct tg3, reset_task); | |
10874 | int err; | |
10875 | ||
10876 | tg3_full_lock(tp, 0); | |
10877 | ||
10878 | if (!netif_running(tp->dev)) { | |
10879 | tg3_flag_clear(tp, RESET_TASK_PENDING); | |
10880 | tg3_full_unlock(tp); | |
10881 | return; | |
10882 | } | |
10883 | ||
10884 | tg3_full_unlock(tp); | |
10885 | ||
10886 | tg3_phy_stop(tp); | |
10887 | ||
10888 | tg3_netif_stop(tp); | |
10889 | ||
10890 | tg3_full_lock(tp, 1); | |
10891 | ||
10892 | if (tg3_flag(tp, TX_RECOVERY_PENDING)) { | |
10893 | tp->write32_tx_mbox = tg3_write32_tx_mbox; | |
10894 | tp->write32_rx_mbox = tg3_write_flush_reg32; | |
10895 | tg3_flag_set(tp, MBOX_WRITE_REORDER); | |
10896 | tg3_flag_clear(tp, TX_RECOVERY_PENDING); | |
10897 | } | |
10898 | ||
10899 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); | |
953c96e0 | 10900 | err = tg3_init_hw(tp, true); |
21f7638e MC |
10901 | if (err) |
10902 | goto out; | |
10903 | ||
10904 | tg3_netif_start(tp); | |
10905 | ||
10906 | out: | |
10907 | tg3_full_unlock(tp); | |
10908 | ||
10909 | if (!err) | |
10910 | tg3_phy_start(tp); | |
10911 | ||
10912 | tg3_flag_clear(tp, RESET_TASK_PENDING); | |
10913 | } | |
10914 | ||
4f125f42 | 10915 | static int tg3_request_irq(struct tg3 *tp, int irq_num) |
fcfa0a32 | 10916 | { |
7d12e780 | 10917 | irq_handler_t fn; |
fcfa0a32 | 10918 | unsigned long flags; |
4f125f42 MC |
10919 | char *name; |
10920 | struct tg3_napi *tnapi = &tp->napi[irq_num]; | |
10921 | ||
10922 | if (tp->irq_cnt == 1) | |
10923 | name = tp->dev->name; | |
10924 | else { | |
10925 | name = &tnapi->irq_lbl[0]; | |
10926 | snprintf(name, IFNAMSIZ, "%s-%d", tp->dev->name, irq_num); | |
10927 | name[IFNAMSIZ-1] = 0; | |
10928 | } | |
fcfa0a32 | 10929 | |
63c3a66f | 10930 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
fcfa0a32 | 10931 | fn = tg3_msi; |
63c3a66f | 10932 | if (tg3_flag(tp, 1SHOT_MSI)) |
fcfa0a32 | 10933 | fn = tg3_msi_1shot; |
ab392d2d | 10934 | flags = 0; |
fcfa0a32 MC |
10935 | } else { |
10936 | fn = tg3_interrupt; | |
63c3a66f | 10937 | if (tg3_flag(tp, TAGGED_STATUS)) |
fcfa0a32 | 10938 | fn = tg3_interrupt_tagged; |
ab392d2d | 10939 | flags = IRQF_SHARED; |
fcfa0a32 | 10940 | } |
4f125f42 MC |
10941 | |
10942 | return request_irq(tnapi->irq_vec, fn, flags, name, tnapi); | |
fcfa0a32 MC |
10943 | } |
10944 | ||
7938109f MC |
10945 | static int tg3_test_interrupt(struct tg3 *tp) |
10946 | { | |
09943a18 | 10947 | struct tg3_napi *tnapi = &tp->napi[0]; |
7938109f | 10948 | struct net_device *dev = tp->dev; |
b16250e3 | 10949 | int err, i, intr_ok = 0; |
f6eb9b1f | 10950 | u32 val; |
7938109f | 10951 | |
d4bc3927 MC |
10952 | if (!netif_running(dev)) |
10953 | return -ENODEV; | |
10954 | ||
7938109f MC |
10955 | tg3_disable_ints(tp); |
10956 | ||
4f125f42 | 10957 | free_irq(tnapi->irq_vec, tnapi); |
7938109f | 10958 | |
f6eb9b1f MC |
10959 | /* |
10960 | * Turn off MSI one shot mode. Otherwise this test has no | |
10961 | * observable way to know whether the interrupt was delivered. | |
10962 | */ | |
3aa1cdf8 | 10963 | if (tg3_flag(tp, 57765_PLUS)) { |
f6eb9b1f MC |
10964 | val = tr32(MSGINT_MODE) | MSGINT_MODE_ONE_SHOT_DISABLE; |
10965 | tw32(MSGINT_MODE, val); | |
10966 | } | |
10967 | ||
4f125f42 | 10968 | err = request_irq(tnapi->irq_vec, tg3_test_isr, |
f274fd9a | 10969 | IRQF_SHARED, dev->name, tnapi); |
7938109f MC |
10970 | if (err) |
10971 | return err; | |
10972 | ||
898a56f8 | 10973 | tnapi->hw_status->status &= ~SD_STATUS_UPDATED; |
7938109f MC |
10974 | tg3_enable_ints(tp); |
10975 | ||
10976 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | | |
fd2ce37f | 10977 | tnapi->coal_now); |
7938109f MC |
10978 | |
10979 | for (i = 0; i < 5; i++) { | |
b16250e3 MC |
10980 | u32 int_mbox, misc_host_ctrl; |
10981 | ||
898a56f8 | 10982 | int_mbox = tr32_mailbox(tnapi->int_mbox); |
b16250e3 MC |
10983 | misc_host_ctrl = tr32(TG3PCI_MISC_HOST_CTRL); |
10984 | ||
10985 | if ((int_mbox != 0) || | |
10986 | (misc_host_ctrl & MISC_HOST_CTRL_MASK_PCI_INT)) { | |
10987 | intr_ok = 1; | |
7938109f | 10988 | break; |
b16250e3 MC |
10989 | } |
10990 | ||
3aa1cdf8 MC |
10991 | if (tg3_flag(tp, 57765_PLUS) && |
10992 | tnapi->hw_status->status_tag != tnapi->last_tag) | |
10993 | tw32_mailbox_f(tnapi->int_mbox, tnapi->last_tag << 24); | |
10994 | ||
7938109f MC |
10995 | msleep(10); |
10996 | } | |
10997 | ||
10998 | tg3_disable_ints(tp); | |
10999 | ||
4f125f42 | 11000 | free_irq(tnapi->irq_vec, tnapi); |
6aa20a22 | 11001 | |
4f125f42 | 11002 | err = tg3_request_irq(tp, 0); |
7938109f MC |
11003 | |
11004 | if (err) | |
11005 | return err; | |
11006 | ||
f6eb9b1f MC |
11007 | if (intr_ok) { |
11008 | /* Reenable MSI one shot mode. */ | |
5b39de91 | 11009 | if (tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, 1SHOT_MSI)) { |
f6eb9b1f MC |
11010 | val = tr32(MSGINT_MODE) & ~MSGINT_MODE_ONE_SHOT_DISABLE; |
11011 | tw32(MSGINT_MODE, val); | |
11012 | } | |
7938109f | 11013 | return 0; |
f6eb9b1f | 11014 | } |
7938109f MC |
11015 | |
11016 | return -EIO; | |
11017 | } | |
11018 | ||
11019 | /* Returns 0 if MSI test succeeds or MSI test fails and INTx mode is | |
11020 | * successfully restored | |
11021 | */ | |
11022 | static int tg3_test_msi(struct tg3 *tp) | |
11023 | { | |
7938109f MC |
11024 | int err; |
11025 | u16 pci_cmd; | |
11026 | ||
63c3a66f | 11027 | if (!tg3_flag(tp, USING_MSI)) |
7938109f MC |
11028 | return 0; |
11029 | ||
11030 | /* Turn off SERR reporting in case MSI terminates with Master | |
11031 | * Abort. | |
11032 | */ | |
11033 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); | |
11034 | pci_write_config_word(tp->pdev, PCI_COMMAND, | |
11035 | pci_cmd & ~PCI_COMMAND_SERR); | |
11036 | ||
11037 | err = tg3_test_interrupt(tp); | |
11038 | ||
11039 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); | |
11040 | ||
11041 | if (!err) | |
11042 | return 0; | |
11043 | ||
11044 | /* other failures */ | |
11045 | if (err != -EIO) | |
11046 | return err; | |
11047 | ||
11048 | /* MSI test failed, go back to INTx mode */ | |
5129c3a3 MC |
11049 | netdev_warn(tp->dev, "No interrupt was generated using MSI. Switching " |
11050 | "to INTx mode. Please report this failure to the PCI " | |
11051 | "maintainer and include system chipset information\n"); | |
7938109f | 11052 | |
4f125f42 | 11053 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
09943a18 | 11054 | |
7938109f MC |
11055 | pci_disable_msi(tp->pdev); |
11056 | ||
63c3a66f | 11057 | tg3_flag_clear(tp, USING_MSI); |
dc8bf1b1 | 11058 | tp->napi[0].irq_vec = tp->pdev->irq; |
7938109f | 11059 | |
4f125f42 | 11060 | err = tg3_request_irq(tp, 0); |
7938109f MC |
11061 | if (err) |
11062 | return err; | |
11063 | ||
11064 | /* Need to reset the chip because the MSI cycle may have terminated | |
11065 | * with Master Abort. | |
11066 | */ | |
f47c11ee | 11067 | tg3_full_lock(tp, 1); |
7938109f | 11068 | |
944d980e | 11069 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
953c96e0 | 11070 | err = tg3_init_hw(tp, true); |
7938109f | 11071 | |
f47c11ee | 11072 | tg3_full_unlock(tp); |
7938109f MC |
11073 | |
11074 | if (err) | |
4f125f42 | 11075 | free_irq(tp->napi[0].irq_vec, &tp->napi[0]); |
7938109f MC |
11076 | |
11077 | return err; | |
11078 | } | |
11079 | ||
9e9fd12d MC |
11080 | static int tg3_request_firmware(struct tg3 *tp) |
11081 | { | |
77997ea3 | 11082 | const struct tg3_firmware_hdr *fw_hdr; |
9e9fd12d MC |
11083 | |
11084 | if (request_firmware(&tp->fw, tp->fw_needed, &tp->pdev->dev)) { | |
05dbe005 JP |
11085 | netdev_err(tp->dev, "Failed to load firmware \"%s\"\n", |
11086 | tp->fw_needed); | |
9e9fd12d MC |
11087 | return -ENOENT; |
11088 | } | |
11089 | ||
77997ea3 | 11090 | fw_hdr = (struct tg3_firmware_hdr *)tp->fw->data; |
9e9fd12d MC |
11091 | |
11092 | /* Firmware blob starts with version numbers, followed by | |
11093 | * start address and _full_ length including BSS sections | |
11094 | * (which must be longer than the actual data, of course | |
11095 | */ | |
11096 | ||
77997ea3 NS |
11097 | tp->fw_len = be32_to_cpu(fw_hdr->len); /* includes bss */ |
11098 | if (tp->fw_len < (tp->fw->size - TG3_FW_HDR_LEN)) { | |
05dbe005 JP |
11099 | netdev_err(tp->dev, "bogus length %d in \"%s\"\n", |
11100 | tp->fw_len, tp->fw_needed); | |
9e9fd12d MC |
11101 | release_firmware(tp->fw); |
11102 | tp->fw = NULL; | |
11103 | return -EINVAL; | |
11104 | } | |
11105 | ||
11106 | /* We no longer need firmware; we have it. */ | |
11107 | tp->fw_needed = NULL; | |
11108 | return 0; | |
11109 | } | |
11110 | ||
9102426a | 11111 | static u32 tg3_irq_count(struct tg3 *tp) |
679563f4 | 11112 | { |
9102426a | 11113 | u32 irq_cnt = max(tp->rxq_cnt, tp->txq_cnt); |
679563f4 | 11114 | |
9102426a | 11115 | if (irq_cnt > 1) { |
c3b5003b MC |
11116 | /* We want as many rx rings enabled as there are cpus. |
11117 | * In multiqueue MSI-X mode, the first MSI-X vector | |
11118 | * only deals with link interrupts, etc, so we add | |
11119 | * one to the number of vectors we are requesting. | |
11120 | */ | |
9102426a | 11121 | irq_cnt = min_t(unsigned, irq_cnt + 1, tp->irq_max); |
c3b5003b | 11122 | } |
679563f4 | 11123 | |
9102426a MC |
11124 | return irq_cnt; |
11125 | } | |
11126 | ||
11127 | static bool tg3_enable_msix(struct tg3 *tp) | |
11128 | { | |
11129 | int i, rc; | |
86449944 | 11130 | struct msix_entry msix_ent[TG3_IRQ_MAX_VECS]; |
9102426a | 11131 | |
0968169c MC |
11132 | tp->txq_cnt = tp->txq_req; |
11133 | tp->rxq_cnt = tp->rxq_req; | |
11134 | if (!tp->rxq_cnt) | |
11135 | tp->rxq_cnt = netif_get_num_default_rss_queues(); | |
9102426a MC |
11136 | if (tp->rxq_cnt > tp->rxq_max) |
11137 | tp->rxq_cnt = tp->rxq_max; | |
cf6d6ea6 MC |
11138 | |
11139 | /* Disable multiple TX rings by default. Simple round-robin hardware | |
11140 | * scheduling of the TX rings can cause starvation of rings with | |
11141 | * small packets when other rings have TSO or jumbo packets. | |
11142 | */ | |
11143 | if (!tp->txq_req) | |
11144 | tp->txq_cnt = 1; | |
9102426a MC |
11145 | |
11146 | tp->irq_cnt = tg3_irq_count(tp); | |
11147 | ||
679563f4 MC |
11148 | for (i = 0; i < tp->irq_max; i++) { |
11149 | msix_ent[i].entry = i; | |
11150 | msix_ent[i].vector = 0; | |
11151 | } | |
11152 | ||
11153 | rc = pci_enable_msix(tp->pdev, msix_ent, tp->irq_cnt); | |
2430b031 MC |
11154 | if (rc < 0) { |
11155 | return false; | |
11156 | } else if (rc != 0) { | |
679563f4 MC |
11157 | if (pci_enable_msix(tp->pdev, msix_ent, rc)) |
11158 | return false; | |
05dbe005 JP |
11159 | netdev_notice(tp->dev, "Requested %d MSI-X vectors, received %d\n", |
11160 | tp->irq_cnt, rc); | |
679563f4 | 11161 | tp->irq_cnt = rc; |
49a359e3 | 11162 | tp->rxq_cnt = max(rc - 1, 1); |
9102426a MC |
11163 | if (tp->txq_cnt) |
11164 | tp->txq_cnt = min(tp->rxq_cnt, tp->txq_max); | |
679563f4 MC |
11165 | } |
11166 | ||
11167 | for (i = 0; i < tp->irq_max; i++) | |
11168 | tp->napi[i].irq_vec = msix_ent[i].vector; | |
11169 | ||
49a359e3 | 11170 | if (netif_set_real_num_rx_queues(tp->dev, tp->rxq_cnt)) { |
2ddaad39 BH |
11171 | pci_disable_msix(tp->pdev); |
11172 | return false; | |
11173 | } | |
b92b9040 | 11174 | |
9102426a MC |
11175 | if (tp->irq_cnt == 1) |
11176 | return true; | |
d78b59f5 | 11177 | |
9102426a MC |
11178 | tg3_flag_set(tp, ENABLE_RSS); |
11179 | ||
11180 | if (tp->txq_cnt > 1) | |
11181 | tg3_flag_set(tp, ENABLE_TSS); | |
11182 | ||
11183 | netif_set_real_num_tx_queues(tp->dev, tp->txq_cnt); | |
2430b031 | 11184 | |
679563f4 MC |
11185 | return true; |
11186 | } | |
11187 | ||
07b0173c MC |
11188 | static void tg3_ints_init(struct tg3 *tp) |
11189 | { | |
63c3a66f JP |
11190 | if ((tg3_flag(tp, SUPPORT_MSI) || tg3_flag(tp, SUPPORT_MSIX)) && |
11191 | !tg3_flag(tp, TAGGED_STATUS)) { | |
07b0173c MC |
11192 | /* All MSI supporting chips should support tagged |
11193 | * status. Assert that this is the case. | |
11194 | */ | |
5129c3a3 MC |
11195 | netdev_warn(tp->dev, |
11196 | "MSI without TAGGED_STATUS? Not using MSI\n"); | |
679563f4 | 11197 | goto defcfg; |
07b0173c | 11198 | } |
4f125f42 | 11199 | |
63c3a66f JP |
11200 | if (tg3_flag(tp, SUPPORT_MSIX) && tg3_enable_msix(tp)) |
11201 | tg3_flag_set(tp, USING_MSIX); | |
11202 | else if (tg3_flag(tp, SUPPORT_MSI) && pci_enable_msi(tp->pdev) == 0) | |
11203 | tg3_flag_set(tp, USING_MSI); | |
679563f4 | 11204 | |
63c3a66f | 11205 | if (tg3_flag(tp, USING_MSI) || tg3_flag(tp, USING_MSIX)) { |
679563f4 | 11206 | u32 msi_mode = tr32(MSGINT_MODE); |
63c3a66f | 11207 | if (tg3_flag(tp, USING_MSIX) && tp->irq_cnt > 1) |
baf8a94a | 11208 | msi_mode |= MSGINT_MODE_MULTIVEC_EN; |
5b39de91 MC |
11209 | if (!tg3_flag(tp, 1SHOT_MSI)) |
11210 | msi_mode |= MSGINT_MODE_ONE_SHOT_DISABLE; | |
679563f4 MC |
11211 | tw32(MSGINT_MODE, msi_mode | MSGINT_MODE_ENABLE); |
11212 | } | |
11213 | defcfg: | |
63c3a66f | 11214 | if (!tg3_flag(tp, USING_MSIX)) { |
679563f4 MC |
11215 | tp->irq_cnt = 1; |
11216 | tp->napi[0].irq_vec = tp->pdev->irq; | |
49a359e3 MC |
11217 | } |
11218 | ||
11219 | if (tp->irq_cnt == 1) { | |
11220 | tp->txq_cnt = 1; | |
11221 | tp->rxq_cnt = 1; | |
2ddaad39 | 11222 | netif_set_real_num_tx_queues(tp->dev, 1); |
85407885 | 11223 | netif_set_real_num_rx_queues(tp->dev, 1); |
679563f4 | 11224 | } |
07b0173c MC |
11225 | } |
11226 | ||
11227 | static void tg3_ints_fini(struct tg3 *tp) | |
11228 | { | |
63c3a66f | 11229 | if (tg3_flag(tp, USING_MSIX)) |
679563f4 | 11230 | pci_disable_msix(tp->pdev); |
63c3a66f | 11231 | else if (tg3_flag(tp, USING_MSI)) |
679563f4 | 11232 | pci_disable_msi(tp->pdev); |
63c3a66f JP |
11233 | tg3_flag_clear(tp, USING_MSI); |
11234 | tg3_flag_clear(tp, USING_MSIX); | |
11235 | tg3_flag_clear(tp, ENABLE_RSS); | |
11236 | tg3_flag_clear(tp, ENABLE_TSS); | |
07b0173c MC |
11237 | } |
11238 | ||
be947307 MC |
11239 | static int tg3_start(struct tg3 *tp, bool reset_phy, bool test_irq, |
11240 | bool init) | |
1da177e4 | 11241 | { |
d8f4cd38 | 11242 | struct net_device *dev = tp->dev; |
4f125f42 | 11243 | int i, err; |
1da177e4 | 11244 | |
679563f4 MC |
11245 | /* |
11246 | * Setup interrupts first so we know how | |
11247 | * many NAPI resources to allocate | |
11248 | */ | |
11249 | tg3_ints_init(tp); | |
11250 | ||
90415477 | 11251 | tg3_rss_check_indir_tbl(tp); |
bcebcc46 | 11252 | |
1da177e4 LT |
11253 | /* The placement of this call is tied |
11254 | * to the setup and use of Host TX descriptors. | |
11255 | */ | |
11256 | err = tg3_alloc_consistent(tp); | |
11257 | if (err) | |
679563f4 | 11258 | goto err_out1; |
88b06bc2 | 11259 | |
66cfd1bd MC |
11260 | tg3_napi_init(tp); |
11261 | ||
fed97810 | 11262 | tg3_napi_enable(tp); |
1da177e4 | 11263 | |
4f125f42 MC |
11264 | for (i = 0; i < tp->irq_cnt; i++) { |
11265 | struct tg3_napi *tnapi = &tp->napi[i]; | |
11266 | err = tg3_request_irq(tp, i); | |
11267 | if (err) { | |
5bc09186 MC |
11268 | for (i--; i >= 0; i--) { |
11269 | tnapi = &tp->napi[i]; | |
4f125f42 | 11270 | free_irq(tnapi->irq_vec, tnapi); |
5bc09186 MC |
11271 | } |
11272 | goto err_out2; | |
4f125f42 MC |
11273 | } |
11274 | } | |
1da177e4 | 11275 | |
f47c11ee | 11276 | tg3_full_lock(tp, 0); |
1da177e4 | 11277 | |
d8f4cd38 | 11278 | err = tg3_init_hw(tp, reset_phy); |
1da177e4 | 11279 | if (err) { |
944d980e | 11280 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
1da177e4 | 11281 | tg3_free_rings(tp); |
1da177e4 LT |
11282 | } |
11283 | ||
f47c11ee | 11284 | tg3_full_unlock(tp); |
1da177e4 | 11285 | |
07b0173c | 11286 | if (err) |
679563f4 | 11287 | goto err_out3; |
1da177e4 | 11288 | |
d8f4cd38 | 11289 | if (test_irq && tg3_flag(tp, USING_MSI)) { |
7938109f | 11290 | err = tg3_test_msi(tp); |
fac9b83e | 11291 | |
7938109f | 11292 | if (err) { |
f47c11ee | 11293 | tg3_full_lock(tp, 0); |
944d980e | 11294 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
7938109f | 11295 | tg3_free_rings(tp); |
f47c11ee | 11296 | tg3_full_unlock(tp); |
7938109f | 11297 | |
679563f4 | 11298 | goto err_out2; |
7938109f | 11299 | } |
fcfa0a32 | 11300 | |
63c3a66f | 11301 | if (!tg3_flag(tp, 57765_PLUS) && tg3_flag(tp, USING_MSI)) { |
f6eb9b1f | 11302 | u32 val = tr32(PCIE_TRANSACTION_CFG); |
fcfa0a32 | 11303 | |
f6eb9b1f MC |
11304 | tw32(PCIE_TRANSACTION_CFG, |
11305 | val | PCIE_TRANS_CFG_1SHOT_MSI); | |
fcfa0a32 | 11306 | } |
7938109f MC |
11307 | } |
11308 | ||
b02fd9e3 MC |
11309 | tg3_phy_start(tp); |
11310 | ||
aed93e0b MC |
11311 | tg3_hwmon_open(tp); |
11312 | ||
f47c11ee | 11313 | tg3_full_lock(tp, 0); |
1da177e4 | 11314 | |
21f7638e | 11315 | tg3_timer_start(tp); |
63c3a66f | 11316 | tg3_flag_set(tp, INIT_COMPLETE); |
1da177e4 LT |
11317 | tg3_enable_ints(tp); |
11318 | ||
be947307 MC |
11319 | if (init) |
11320 | tg3_ptp_init(tp); | |
11321 | else | |
11322 | tg3_ptp_resume(tp); | |
11323 | ||
11324 | ||
f47c11ee | 11325 | tg3_full_unlock(tp); |
1da177e4 | 11326 | |
fe5f5787 | 11327 | netif_tx_start_all_queues(dev); |
1da177e4 | 11328 | |
06c03c02 MB |
11329 | /* |
11330 | * Reset loopback feature if it was turned on while the device was down | |
11331 | * make sure that it's installed properly now. | |
11332 | */ | |
11333 | if (dev->features & NETIF_F_LOOPBACK) | |
11334 | tg3_set_loopback(dev, dev->features); | |
11335 | ||
1da177e4 | 11336 | return 0; |
07b0173c | 11337 | |
679563f4 | 11338 | err_out3: |
4f125f42 MC |
11339 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
11340 | struct tg3_napi *tnapi = &tp->napi[i]; | |
11341 | free_irq(tnapi->irq_vec, tnapi); | |
11342 | } | |
07b0173c | 11343 | |
679563f4 | 11344 | err_out2: |
fed97810 | 11345 | tg3_napi_disable(tp); |
66cfd1bd | 11346 | tg3_napi_fini(tp); |
07b0173c | 11347 | tg3_free_consistent(tp); |
679563f4 MC |
11348 | |
11349 | err_out1: | |
11350 | tg3_ints_fini(tp); | |
d8f4cd38 | 11351 | |
07b0173c | 11352 | return err; |
1da177e4 LT |
11353 | } |
11354 | ||
65138594 | 11355 | static void tg3_stop(struct tg3 *tp) |
1da177e4 | 11356 | { |
4f125f42 | 11357 | int i; |
1da177e4 | 11358 | |
db219973 | 11359 | tg3_reset_task_cancel(tp); |
bd473da3 | 11360 | tg3_netif_stop(tp); |
1da177e4 | 11361 | |
21f7638e | 11362 | tg3_timer_stop(tp); |
1da177e4 | 11363 | |
aed93e0b MC |
11364 | tg3_hwmon_close(tp); |
11365 | ||
24bb4fb6 MC |
11366 | tg3_phy_stop(tp); |
11367 | ||
f47c11ee | 11368 | tg3_full_lock(tp, 1); |
1da177e4 LT |
11369 | |
11370 | tg3_disable_ints(tp); | |
11371 | ||
944d980e | 11372 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
1da177e4 | 11373 | tg3_free_rings(tp); |
63c3a66f | 11374 | tg3_flag_clear(tp, INIT_COMPLETE); |
1da177e4 | 11375 | |
f47c11ee | 11376 | tg3_full_unlock(tp); |
1da177e4 | 11377 | |
4f125f42 MC |
11378 | for (i = tp->irq_cnt - 1; i >= 0; i--) { |
11379 | struct tg3_napi *tnapi = &tp->napi[i]; | |
11380 | free_irq(tnapi->irq_vec, tnapi); | |
11381 | } | |
07b0173c MC |
11382 | |
11383 | tg3_ints_fini(tp); | |
1da177e4 | 11384 | |
66cfd1bd MC |
11385 | tg3_napi_fini(tp); |
11386 | ||
1da177e4 | 11387 | tg3_free_consistent(tp); |
65138594 MC |
11388 | } |
11389 | ||
d8f4cd38 MC |
11390 | static int tg3_open(struct net_device *dev) |
11391 | { | |
11392 | struct tg3 *tp = netdev_priv(dev); | |
11393 | int err; | |
11394 | ||
11395 | if (tp->fw_needed) { | |
11396 | err = tg3_request_firmware(tp); | |
c4dab506 NS |
11397 | if (tg3_asic_rev(tp) == ASIC_REV_57766) { |
11398 | if (err) { | |
11399 | netdev_warn(tp->dev, "EEE capability disabled\n"); | |
11400 | tp->phy_flags &= ~TG3_PHYFLG_EEE_CAP; | |
11401 | } else if (!(tp->phy_flags & TG3_PHYFLG_EEE_CAP)) { | |
11402 | netdev_warn(tp->dev, "EEE capability restored\n"); | |
11403 | tp->phy_flags |= TG3_PHYFLG_EEE_CAP; | |
11404 | } | |
11405 | } else if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0) { | |
d8f4cd38 MC |
11406 | if (err) |
11407 | return err; | |
11408 | } else if (err) { | |
11409 | netdev_warn(tp->dev, "TSO capability disabled\n"); | |
11410 | tg3_flag_clear(tp, TSO_CAPABLE); | |
11411 | } else if (!tg3_flag(tp, TSO_CAPABLE)) { | |
11412 | netdev_notice(tp->dev, "TSO capability restored\n"); | |
11413 | tg3_flag_set(tp, TSO_CAPABLE); | |
11414 | } | |
11415 | } | |
11416 | ||
f4a46d1f | 11417 | tg3_carrier_off(tp); |
d8f4cd38 MC |
11418 | |
11419 | err = tg3_power_up(tp); | |
11420 | if (err) | |
11421 | return err; | |
11422 | ||
11423 | tg3_full_lock(tp, 0); | |
11424 | ||
11425 | tg3_disable_ints(tp); | |
11426 | tg3_flag_clear(tp, INIT_COMPLETE); | |
11427 | ||
11428 | tg3_full_unlock(tp); | |
11429 | ||
942d1af0 NS |
11430 | err = tg3_start(tp, |
11431 | !(tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN), | |
11432 | true, true); | |
d8f4cd38 MC |
11433 | if (err) { |
11434 | tg3_frob_aux_power(tp, false); | |
11435 | pci_set_power_state(tp->pdev, PCI_D3hot); | |
11436 | } | |
be947307 | 11437 | |
7d41e49a MC |
11438 | if (tg3_flag(tp, PTP_CAPABLE)) { |
11439 | tp->ptp_clock = ptp_clock_register(&tp->ptp_info, | |
11440 | &tp->pdev->dev); | |
11441 | if (IS_ERR(tp->ptp_clock)) | |
11442 | tp->ptp_clock = NULL; | |
11443 | } | |
11444 | ||
07b0173c | 11445 | return err; |
1da177e4 LT |
11446 | } |
11447 | ||
1da177e4 LT |
11448 | static int tg3_close(struct net_device *dev) |
11449 | { | |
11450 | struct tg3 *tp = netdev_priv(dev); | |
11451 | ||
be947307 MC |
11452 | tg3_ptp_fini(tp); |
11453 | ||
65138594 | 11454 | tg3_stop(tp); |
1da177e4 | 11455 | |
92feeabf MC |
11456 | /* Clear stats across close / open calls */ |
11457 | memset(&tp->net_stats_prev, 0, sizeof(tp->net_stats_prev)); | |
11458 | memset(&tp->estats_prev, 0, sizeof(tp->estats_prev)); | |
1da177e4 | 11459 | |
c866b7ea | 11460 | tg3_power_down(tp); |
bc1c7567 | 11461 | |
f4a46d1f | 11462 | tg3_carrier_off(tp); |
bc1c7567 | 11463 | |
1da177e4 LT |
11464 | return 0; |
11465 | } | |
11466 | ||
511d2224 | 11467 | static inline u64 get_stat64(tg3_stat64_t *val) |
816f8b86 SB |
11468 | { |
11469 | return ((u64)val->high << 32) | ((u64)val->low); | |
11470 | } | |
11471 | ||
65ec698d | 11472 | static u64 tg3_calc_crc_errors(struct tg3 *tp) |
1da177e4 LT |
11473 | { |
11474 | struct tg3_hw_stats *hw_stats = tp->hw_stats; | |
11475 | ||
f07e9af3 | 11476 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
4153577a JP |
11477 | (tg3_asic_rev(tp) == ASIC_REV_5700 || |
11478 | tg3_asic_rev(tp) == ASIC_REV_5701)) { | |
1da177e4 LT |
11479 | u32 val; |
11480 | ||
569a5df8 MC |
11481 | if (!tg3_readphy(tp, MII_TG3_TEST1, &val)) { |
11482 | tg3_writephy(tp, MII_TG3_TEST1, | |
11483 | val | MII_TG3_TEST1_CRC_EN); | |
f08aa1a8 | 11484 | tg3_readphy(tp, MII_TG3_RXR_COUNTERS, &val); |
1da177e4 LT |
11485 | } else |
11486 | val = 0; | |
1da177e4 LT |
11487 | |
11488 | tp->phy_crc_errors += val; | |
11489 | ||
11490 | return tp->phy_crc_errors; | |
11491 | } | |
11492 | ||
11493 | return get_stat64(&hw_stats->rx_fcs_errors); | |
11494 | } | |
11495 | ||
11496 | #define ESTAT_ADD(member) \ | |
11497 | estats->member = old_estats->member + \ | |
511d2224 | 11498 | get_stat64(&hw_stats->member) |
1da177e4 | 11499 | |
65ec698d | 11500 | static void tg3_get_estats(struct tg3 *tp, struct tg3_ethtool_stats *estats) |
1da177e4 | 11501 | { |
1da177e4 LT |
11502 | struct tg3_ethtool_stats *old_estats = &tp->estats_prev; |
11503 | struct tg3_hw_stats *hw_stats = tp->hw_stats; | |
11504 | ||
1da177e4 LT |
11505 | ESTAT_ADD(rx_octets); |
11506 | ESTAT_ADD(rx_fragments); | |
11507 | ESTAT_ADD(rx_ucast_packets); | |
11508 | ESTAT_ADD(rx_mcast_packets); | |
11509 | ESTAT_ADD(rx_bcast_packets); | |
11510 | ESTAT_ADD(rx_fcs_errors); | |
11511 | ESTAT_ADD(rx_align_errors); | |
11512 | ESTAT_ADD(rx_xon_pause_rcvd); | |
11513 | ESTAT_ADD(rx_xoff_pause_rcvd); | |
11514 | ESTAT_ADD(rx_mac_ctrl_rcvd); | |
11515 | ESTAT_ADD(rx_xoff_entered); | |
11516 | ESTAT_ADD(rx_frame_too_long_errors); | |
11517 | ESTAT_ADD(rx_jabbers); | |
11518 | ESTAT_ADD(rx_undersize_packets); | |
11519 | ESTAT_ADD(rx_in_length_errors); | |
11520 | ESTAT_ADD(rx_out_length_errors); | |
11521 | ESTAT_ADD(rx_64_or_less_octet_packets); | |
11522 | ESTAT_ADD(rx_65_to_127_octet_packets); | |
11523 | ESTAT_ADD(rx_128_to_255_octet_packets); | |
11524 | ESTAT_ADD(rx_256_to_511_octet_packets); | |
11525 | ESTAT_ADD(rx_512_to_1023_octet_packets); | |
11526 | ESTAT_ADD(rx_1024_to_1522_octet_packets); | |
11527 | ESTAT_ADD(rx_1523_to_2047_octet_packets); | |
11528 | ESTAT_ADD(rx_2048_to_4095_octet_packets); | |
11529 | ESTAT_ADD(rx_4096_to_8191_octet_packets); | |
11530 | ESTAT_ADD(rx_8192_to_9022_octet_packets); | |
11531 | ||
11532 | ESTAT_ADD(tx_octets); | |
11533 | ESTAT_ADD(tx_collisions); | |
11534 | ESTAT_ADD(tx_xon_sent); | |
11535 | ESTAT_ADD(tx_xoff_sent); | |
11536 | ESTAT_ADD(tx_flow_control); | |
11537 | ESTAT_ADD(tx_mac_errors); | |
11538 | ESTAT_ADD(tx_single_collisions); | |
11539 | ESTAT_ADD(tx_mult_collisions); | |
11540 | ESTAT_ADD(tx_deferred); | |
11541 | ESTAT_ADD(tx_excessive_collisions); | |
11542 | ESTAT_ADD(tx_late_collisions); | |
11543 | ESTAT_ADD(tx_collide_2times); | |
11544 | ESTAT_ADD(tx_collide_3times); | |
11545 | ESTAT_ADD(tx_collide_4times); | |
11546 | ESTAT_ADD(tx_collide_5times); | |
11547 | ESTAT_ADD(tx_collide_6times); | |
11548 | ESTAT_ADD(tx_collide_7times); | |
11549 | ESTAT_ADD(tx_collide_8times); | |
11550 | ESTAT_ADD(tx_collide_9times); | |
11551 | ESTAT_ADD(tx_collide_10times); | |
11552 | ESTAT_ADD(tx_collide_11times); | |
11553 | ESTAT_ADD(tx_collide_12times); | |
11554 | ESTAT_ADD(tx_collide_13times); | |
11555 | ESTAT_ADD(tx_collide_14times); | |
11556 | ESTAT_ADD(tx_collide_15times); | |
11557 | ESTAT_ADD(tx_ucast_packets); | |
11558 | ESTAT_ADD(tx_mcast_packets); | |
11559 | ESTAT_ADD(tx_bcast_packets); | |
11560 | ESTAT_ADD(tx_carrier_sense_errors); | |
11561 | ESTAT_ADD(tx_discards); | |
11562 | ESTAT_ADD(tx_errors); | |
11563 | ||
11564 | ESTAT_ADD(dma_writeq_full); | |
11565 | ESTAT_ADD(dma_write_prioq_full); | |
11566 | ESTAT_ADD(rxbds_empty); | |
11567 | ESTAT_ADD(rx_discards); | |
11568 | ESTAT_ADD(rx_errors); | |
11569 | ESTAT_ADD(rx_threshold_hit); | |
11570 | ||
11571 | ESTAT_ADD(dma_readq_full); | |
11572 | ESTAT_ADD(dma_read_prioq_full); | |
11573 | ESTAT_ADD(tx_comp_queue_full); | |
11574 | ||
11575 | ESTAT_ADD(ring_set_send_prod_index); | |
11576 | ESTAT_ADD(ring_status_update); | |
11577 | ESTAT_ADD(nic_irqs); | |
11578 | ESTAT_ADD(nic_avoided_irqs); | |
11579 | ESTAT_ADD(nic_tx_threshold_hit); | |
11580 | ||
4452d099 | 11581 | ESTAT_ADD(mbuf_lwm_thresh_hit); |
1da177e4 LT |
11582 | } |
11583 | ||
65ec698d | 11584 | static void tg3_get_nstats(struct tg3 *tp, struct rtnl_link_stats64 *stats) |
1da177e4 | 11585 | { |
511d2224 | 11586 | struct rtnl_link_stats64 *old_stats = &tp->net_stats_prev; |
1da177e4 LT |
11587 | struct tg3_hw_stats *hw_stats = tp->hw_stats; |
11588 | ||
1da177e4 LT |
11589 | stats->rx_packets = old_stats->rx_packets + |
11590 | get_stat64(&hw_stats->rx_ucast_packets) + | |
11591 | get_stat64(&hw_stats->rx_mcast_packets) + | |
11592 | get_stat64(&hw_stats->rx_bcast_packets); | |
6aa20a22 | 11593 | |
1da177e4 LT |
11594 | stats->tx_packets = old_stats->tx_packets + |
11595 | get_stat64(&hw_stats->tx_ucast_packets) + | |
11596 | get_stat64(&hw_stats->tx_mcast_packets) + | |
11597 | get_stat64(&hw_stats->tx_bcast_packets); | |
11598 | ||
11599 | stats->rx_bytes = old_stats->rx_bytes + | |
11600 | get_stat64(&hw_stats->rx_octets); | |
11601 | stats->tx_bytes = old_stats->tx_bytes + | |
11602 | get_stat64(&hw_stats->tx_octets); | |
11603 | ||
11604 | stats->rx_errors = old_stats->rx_errors + | |
4f63b877 | 11605 | get_stat64(&hw_stats->rx_errors); |
1da177e4 LT |
11606 | stats->tx_errors = old_stats->tx_errors + |
11607 | get_stat64(&hw_stats->tx_errors) + | |
11608 | get_stat64(&hw_stats->tx_mac_errors) + | |
11609 | get_stat64(&hw_stats->tx_carrier_sense_errors) + | |
11610 | get_stat64(&hw_stats->tx_discards); | |
11611 | ||
11612 | stats->multicast = old_stats->multicast + | |
11613 | get_stat64(&hw_stats->rx_mcast_packets); | |
11614 | stats->collisions = old_stats->collisions + | |
11615 | get_stat64(&hw_stats->tx_collisions); | |
11616 | ||
11617 | stats->rx_length_errors = old_stats->rx_length_errors + | |
11618 | get_stat64(&hw_stats->rx_frame_too_long_errors) + | |
11619 | get_stat64(&hw_stats->rx_undersize_packets); | |
11620 | ||
11621 | stats->rx_over_errors = old_stats->rx_over_errors + | |
11622 | get_stat64(&hw_stats->rxbds_empty); | |
11623 | stats->rx_frame_errors = old_stats->rx_frame_errors + | |
11624 | get_stat64(&hw_stats->rx_align_errors); | |
11625 | stats->tx_aborted_errors = old_stats->tx_aborted_errors + | |
11626 | get_stat64(&hw_stats->tx_discards); | |
11627 | stats->tx_carrier_errors = old_stats->tx_carrier_errors + | |
11628 | get_stat64(&hw_stats->tx_carrier_sense_errors); | |
11629 | ||
11630 | stats->rx_crc_errors = old_stats->rx_crc_errors + | |
65ec698d | 11631 | tg3_calc_crc_errors(tp); |
1da177e4 | 11632 | |
4f63b877 JL |
11633 | stats->rx_missed_errors = old_stats->rx_missed_errors + |
11634 | get_stat64(&hw_stats->rx_discards); | |
11635 | ||
b0057c51 | 11636 | stats->rx_dropped = tp->rx_dropped; |
48855432 | 11637 | stats->tx_dropped = tp->tx_dropped; |
1da177e4 LT |
11638 | } |
11639 | ||
1da177e4 LT |
11640 | static int tg3_get_regs_len(struct net_device *dev) |
11641 | { | |
97bd8e49 | 11642 | return TG3_REG_BLK_SIZE; |
1da177e4 LT |
11643 | } |
11644 | ||
11645 | static void tg3_get_regs(struct net_device *dev, | |
11646 | struct ethtool_regs *regs, void *_p) | |
11647 | { | |
1da177e4 | 11648 | struct tg3 *tp = netdev_priv(dev); |
1da177e4 LT |
11649 | |
11650 | regs->version = 0; | |
11651 | ||
97bd8e49 | 11652 | memset(_p, 0, TG3_REG_BLK_SIZE); |
1da177e4 | 11653 | |
80096068 | 11654 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
bc1c7567 MC |
11655 | return; |
11656 | ||
f47c11ee | 11657 | tg3_full_lock(tp, 0); |
1da177e4 | 11658 | |
97bd8e49 | 11659 | tg3_dump_legacy_regs(tp, (u32 *)_p); |
1da177e4 | 11660 | |
f47c11ee | 11661 | tg3_full_unlock(tp); |
1da177e4 LT |
11662 | } |
11663 | ||
11664 | static int tg3_get_eeprom_len(struct net_device *dev) | |
11665 | { | |
11666 | struct tg3 *tp = netdev_priv(dev); | |
11667 | ||
11668 | return tp->nvram_size; | |
11669 | } | |
11670 | ||
1da177e4 LT |
11671 | static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
11672 | { | |
11673 | struct tg3 *tp = netdev_priv(dev); | |
11674 | int ret; | |
11675 | u8 *pd; | |
b9fc7dc5 | 11676 | u32 i, offset, len, b_offset, b_count; |
a9dc529d | 11677 | __be32 val; |
1da177e4 | 11678 | |
63c3a66f | 11679 | if (tg3_flag(tp, NO_NVRAM)) |
df259d8c MC |
11680 | return -EINVAL; |
11681 | ||
80096068 | 11682 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
bc1c7567 MC |
11683 | return -EAGAIN; |
11684 | ||
1da177e4 LT |
11685 | offset = eeprom->offset; |
11686 | len = eeprom->len; | |
11687 | eeprom->len = 0; | |
11688 | ||
11689 | eeprom->magic = TG3_EEPROM_MAGIC; | |
11690 | ||
11691 | if (offset & 3) { | |
11692 | /* adjustments to start on required 4 byte boundary */ | |
11693 | b_offset = offset & 3; | |
11694 | b_count = 4 - b_offset; | |
11695 | if (b_count > len) { | |
11696 | /* i.e. offset=1 len=2 */ | |
11697 | b_count = len; | |
11698 | } | |
a9dc529d | 11699 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &val); |
1da177e4 LT |
11700 | if (ret) |
11701 | return ret; | |
be98da6a | 11702 | memcpy(data, ((char *)&val) + b_offset, b_count); |
1da177e4 LT |
11703 | len -= b_count; |
11704 | offset += b_count; | |
c6cdf436 | 11705 | eeprom->len += b_count; |
1da177e4 LT |
11706 | } |
11707 | ||
25985edc | 11708 | /* read bytes up to the last 4 byte boundary */ |
1da177e4 LT |
11709 | pd = &data[eeprom->len]; |
11710 | for (i = 0; i < (len - (len & 3)); i += 4) { | |
a9dc529d | 11711 | ret = tg3_nvram_read_be32(tp, offset + i, &val); |
1da177e4 LT |
11712 | if (ret) { |
11713 | eeprom->len += i; | |
11714 | return ret; | |
11715 | } | |
1da177e4 LT |
11716 | memcpy(pd + i, &val, 4); |
11717 | } | |
11718 | eeprom->len += i; | |
11719 | ||
11720 | if (len & 3) { | |
11721 | /* read last bytes not ending on 4 byte boundary */ | |
11722 | pd = &data[eeprom->len]; | |
11723 | b_count = len & 3; | |
11724 | b_offset = offset + len - b_count; | |
a9dc529d | 11725 | ret = tg3_nvram_read_be32(tp, b_offset, &val); |
1da177e4 LT |
11726 | if (ret) |
11727 | return ret; | |
b9fc7dc5 | 11728 | memcpy(pd, &val, b_count); |
1da177e4 LT |
11729 | eeprom->len += b_count; |
11730 | } | |
11731 | return 0; | |
11732 | } | |
11733 | ||
1da177e4 LT |
11734 | static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) |
11735 | { | |
11736 | struct tg3 *tp = netdev_priv(dev); | |
11737 | int ret; | |
b9fc7dc5 | 11738 | u32 offset, len, b_offset, odd_len; |
1da177e4 | 11739 | u8 *buf; |
a9dc529d | 11740 | __be32 start, end; |
1da177e4 | 11741 | |
80096068 | 11742 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
bc1c7567 MC |
11743 | return -EAGAIN; |
11744 | ||
63c3a66f | 11745 | if (tg3_flag(tp, NO_NVRAM) || |
df259d8c | 11746 | eeprom->magic != TG3_EEPROM_MAGIC) |
1da177e4 LT |
11747 | return -EINVAL; |
11748 | ||
11749 | offset = eeprom->offset; | |
11750 | len = eeprom->len; | |
11751 | ||
11752 | if ((b_offset = (offset & 3))) { | |
11753 | /* adjustments to start on required 4 byte boundary */ | |
a9dc529d | 11754 | ret = tg3_nvram_read_be32(tp, offset-b_offset, &start); |
1da177e4 LT |
11755 | if (ret) |
11756 | return ret; | |
1da177e4 LT |
11757 | len += b_offset; |
11758 | offset &= ~3; | |
1c8594b4 MC |
11759 | if (len < 4) |
11760 | len = 4; | |
1da177e4 LT |
11761 | } |
11762 | ||
11763 | odd_len = 0; | |
1c8594b4 | 11764 | if (len & 3) { |
1da177e4 LT |
11765 | /* adjustments to end on required 4 byte boundary */ |
11766 | odd_len = 1; | |
11767 | len = (len + 3) & ~3; | |
a9dc529d | 11768 | ret = tg3_nvram_read_be32(tp, offset+len-4, &end); |
1da177e4 LT |
11769 | if (ret) |
11770 | return ret; | |
1da177e4 LT |
11771 | } |
11772 | ||
11773 | buf = data; | |
11774 | if (b_offset || odd_len) { | |
11775 | buf = kmalloc(len, GFP_KERNEL); | |
ab0049b4 | 11776 | if (!buf) |
1da177e4 LT |
11777 | return -ENOMEM; |
11778 | if (b_offset) | |
11779 | memcpy(buf, &start, 4); | |
11780 | if (odd_len) | |
11781 | memcpy(buf+len-4, &end, 4); | |
11782 | memcpy(buf + b_offset, data, eeprom->len); | |
11783 | } | |
11784 | ||
11785 | ret = tg3_nvram_write_block(tp, offset, len, buf); | |
11786 | ||
11787 | if (buf != data) | |
11788 | kfree(buf); | |
11789 | ||
11790 | return ret; | |
11791 | } | |
11792 | ||
11793 | static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) | |
11794 | { | |
b02fd9e3 MC |
11795 | struct tg3 *tp = netdev_priv(dev); |
11796 | ||
63c3a66f | 11797 | if (tg3_flag(tp, USE_PHYLIB)) { |
3f0e3ad7 | 11798 | struct phy_device *phydev; |
f07e9af3 | 11799 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 | 11800 | return -EAGAIN; |
3f0e3ad7 MC |
11801 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
11802 | return phy_ethtool_gset(phydev, cmd); | |
b02fd9e3 | 11803 | } |
6aa20a22 | 11804 | |
1da177e4 LT |
11805 | cmd->supported = (SUPPORTED_Autoneg); |
11806 | ||
f07e9af3 | 11807 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
1da177e4 LT |
11808 | cmd->supported |= (SUPPORTED_1000baseT_Half | |
11809 | SUPPORTED_1000baseT_Full); | |
11810 | ||
f07e9af3 | 11811 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
1da177e4 LT |
11812 | cmd->supported |= (SUPPORTED_100baseT_Half | |
11813 | SUPPORTED_100baseT_Full | | |
11814 | SUPPORTED_10baseT_Half | | |
11815 | SUPPORTED_10baseT_Full | | |
3bebab59 | 11816 | SUPPORTED_TP); |
ef348144 KK |
11817 | cmd->port = PORT_TP; |
11818 | } else { | |
1da177e4 | 11819 | cmd->supported |= SUPPORTED_FIBRE; |
ef348144 KK |
11820 | cmd->port = PORT_FIBRE; |
11821 | } | |
6aa20a22 | 11822 | |
1da177e4 | 11823 | cmd->advertising = tp->link_config.advertising; |
5bb09778 MC |
11824 | if (tg3_flag(tp, PAUSE_AUTONEG)) { |
11825 | if (tp->link_config.flowctrl & FLOW_CTRL_RX) { | |
11826 | if (tp->link_config.flowctrl & FLOW_CTRL_TX) { | |
11827 | cmd->advertising |= ADVERTISED_Pause; | |
11828 | } else { | |
11829 | cmd->advertising |= ADVERTISED_Pause | | |
11830 | ADVERTISED_Asym_Pause; | |
11831 | } | |
11832 | } else if (tp->link_config.flowctrl & FLOW_CTRL_TX) { | |
11833 | cmd->advertising |= ADVERTISED_Asym_Pause; | |
11834 | } | |
11835 | } | |
f4a46d1f | 11836 | if (netif_running(dev) && tp->link_up) { |
70739497 | 11837 | ethtool_cmd_speed_set(cmd, tp->link_config.active_speed); |
1da177e4 | 11838 | cmd->duplex = tp->link_config.active_duplex; |
859edb26 | 11839 | cmd->lp_advertising = tp->link_config.rmt_adv; |
e348c5e7 MC |
11840 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) { |
11841 | if (tp->phy_flags & TG3_PHYFLG_MDIX_STATE) | |
11842 | cmd->eth_tp_mdix = ETH_TP_MDI_X; | |
11843 | else | |
11844 | cmd->eth_tp_mdix = ETH_TP_MDI; | |
11845 | } | |
64c22182 | 11846 | } else { |
e740522e MC |
11847 | ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN); |
11848 | cmd->duplex = DUPLEX_UNKNOWN; | |
e348c5e7 | 11849 | cmd->eth_tp_mdix = ETH_TP_MDI_INVALID; |
1da177e4 | 11850 | } |
882e9793 | 11851 | cmd->phy_address = tp->phy_addr; |
7e5856bd | 11852 | cmd->transceiver = XCVR_INTERNAL; |
1da177e4 LT |
11853 | cmd->autoneg = tp->link_config.autoneg; |
11854 | cmd->maxtxpkt = 0; | |
11855 | cmd->maxrxpkt = 0; | |
11856 | return 0; | |
11857 | } | |
6aa20a22 | 11858 | |
1da177e4 LT |
11859 | static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
11860 | { | |
11861 | struct tg3 *tp = netdev_priv(dev); | |
25db0338 | 11862 | u32 speed = ethtool_cmd_speed(cmd); |
6aa20a22 | 11863 | |
63c3a66f | 11864 | if (tg3_flag(tp, USE_PHYLIB)) { |
3f0e3ad7 | 11865 | struct phy_device *phydev; |
f07e9af3 | 11866 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 | 11867 | return -EAGAIN; |
3f0e3ad7 MC |
11868 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
11869 | return phy_ethtool_sset(phydev, cmd); | |
b02fd9e3 MC |
11870 | } |
11871 | ||
7e5856bd MC |
11872 | if (cmd->autoneg != AUTONEG_ENABLE && |
11873 | cmd->autoneg != AUTONEG_DISABLE) | |
37ff238d | 11874 | return -EINVAL; |
7e5856bd MC |
11875 | |
11876 | if (cmd->autoneg == AUTONEG_DISABLE && | |
11877 | cmd->duplex != DUPLEX_FULL && | |
11878 | cmd->duplex != DUPLEX_HALF) | |
37ff238d | 11879 | return -EINVAL; |
1da177e4 | 11880 | |
7e5856bd MC |
11881 | if (cmd->autoneg == AUTONEG_ENABLE) { |
11882 | u32 mask = ADVERTISED_Autoneg | | |
11883 | ADVERTISED_Pause | | |
11884 | ADVERTISED_Asym_Pause; | |
11885 | ||
f07e9af3 | 11886 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) |
7e5856bd MC |
11887 | mask |= ADVERTISED_1000baseT_Half | |
11888 | ADVERTISED_1000baseT_Full; | |
11889 | ||
f07e9af3 | 11890 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) |
7e5856bd MC |
11891 | mask |= ADVERTISED_100baseT_Half | |
11892 | ADVERTISED_100baseT_Full | | |
11893 | ADVERTISED_10baseT_Half | | |
11894 | ADVERTISED_10baseT_Full | | |
11895 | ADVERTISED_TP; | |
11896 | else | |
11897 | mask |= ADVERTISED_FIBRE; | |
11898 | ||
11899 | if (cmd->advertising & ~mask) | |
11900 | return -EINVAL; | |
11901 | ||
11902 | mask &= (ADVERTISED_1000baseT_Half | | |
11903 | ADVERTISED_1000baseT_Full | | |
11904 | ADVERTISED_100baseT_Half | | |
11905 | ADVERTISED_100baseT_Full | | |
11906 | ADVERTISED_10baseT_Half | | |
11907 | ADVERTISED_10baseT_Full); | |
11908 | ||
11909 | cmd->advertising &= mask; | |
11910 | } else { | |
f07e9af3 | 11911 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) { |
25db0338 | 11912 | if (speed != SPEED_1000) |
7e5856bd MC |
11913 | return -EINVAL; |
11914 | ||
11915 | if (cmd->duplex != DUPLEX_FULL) | |
11916 | return -EINVAL; | |
11917 | } else { | |
25db0338 DD |
11918 | if (speed != SPEED_100 && |
11919 | speed != SPEED_10) | |
7e5856bd MC |
11920 | return -EINVAL; |
11921 | } | |
11922 | } | |
11923 | ||
f47c11ee | 11924 | tg3_full_lock(tp, 0); |
1da177e4 LT |
11925 | |
11926 | tp->link_config.autoneg = cmd->autoneg; | |
11927 | if (cmd->autoneg == AUTONEG_ENABLE) { | |
405d8e5c AG |
11928 | tp->link_config.advertising = (cmd->advertising | |
11929 | ADVERTISED_Autoneg); | |
e740522e MC |
11930 | tp->link_config.speed = SPEED_UNKNOWN; |
11931 | tp->link_config.duplex = DUPLEX_UNKNOWN; | |
1da177e4 LT |
11932 | } else { |
11933 | tp->link_config.advertising = 0; | |
25db0338 | 11934 | tp->link_config.speed = speed; |
1da177e4 | 11935 | tp->link_config.duplex = cmd->duplex; |
b02fd9e3 | 11936 | } |
6aa20a22 | 11937 | |
fdad8de4 NS |
11938 | tp->phy_flags |= TG3_PHYFLG_USER_CONFIGURED; |
11939 | ||
ce20f161 NS |
11940 | tg3_warn_mgmt_link_flap(tp); |
11941 | ||
1da177e4 | 11942 | if (netif_running(dev)) |
953c96e0 | 11943 | tg3_setup_phy(tp, true); |
1da177e4 | 11944 | |
f47c11ee | 11945 | tg3_full_unlock(tp); |
6aa20a22 | 11946 | |
1da177e4 LT |
11947 | return 0; |
11948 | } | |
6aa20a22 | 11949 | |
1da177e4 LT |
11950 | static void tg3_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
11951 | { | |
11952 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 11953 | |
68aad78c RJ |
11954 | strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); |
11955 | strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); | |
11956 | strlcpy(info->fw_version, tp->fw_ver, sizeof(info->fw_version)); | |
11957 | strlcpy(info->bus_info, pci_name(tp->pdev), sizeof(info->bus_info)); | |
1da177e4 | 11958 | } |
6aa20a22 | 11959 | |
1da177e4 LT |
11960 | static void tg3_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
11961 | { | |
11962 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 11963 | |
63c3a66f | 11964 | if (tg3_flag(tp, WOL_CAP) && device_can_wakeup(&tp->pdev->dev)) |
a85feb8c GZ |
11965 | wol->supported = WAKE_MAGIC; |
11966 | else | |
11967 | wol->supported = 0; | |
1da177e4 | 11968 | wol->wolopts = 0; |
63c3a66f | 11969 | if (tg3_flag(tp, WOL_ENABLE) && device_can_wakeup(&tp->pdev->dev)) |
1da177e4 LT |
11970 | wol->wolopts = WAKE_MAGIC; |
11971 | memset(&wol->sopass, 0, sizeof(wol->sopass)); | |
11972 | } | |
6aa20a22 | 11973 | |
1da177e4 LT |
11974 | static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
11975 | { | |
11976 | struct tg3 *tp = netdev_priv(dev); | |
12dac075 | 11977 | struct device *dp = &tp->pdev->dev; |
6aa20a22 | 11978 | |
1da177e4 LT |
11979 | if (wol->wolopts & ~WAKE_MAGIC) |
11980 | return -EINVAL; | |
11981 | if ((wol->wolopts & WAKE_MAGIC) && | |
63c3a66f | 11982 | !(tg3_flag(tp, WOL_CAP) && device_can_wakeup(dp))) |
1da177e4 | 11983 | return -EINVAL; |
6aa20a22 | 11984 | |
f2dc0d18 RW |
11985 | device_set_wakeup_enable(dp, wol->wolopts & WAKE_MAGIC); |
11986 | ||
f47c11ee | 11987 | spin_lock_bh(&tp->lock); |
f2dc0d18 | 11988 | if (device_may_wakeup(dp)) |
63c3a66f | 11989 | tg3_flag_set(tp, WOL_ENABLE); |
f2dc0d18 | 11990 | else |
63c3a66f | 11991 | tg3_flag_clear(tp, WOL_ENABLE); |
f47c11ee | 11992 | spin_unlock_bh(&tp->lock); |
6aa20a22 | 11993 | |
1da177e4 LT |
11994 | return 0; |
11995 | } | |
6aa20a22 | 11996 | |
1da177e4 LT |
11997 | static u32 tg3_get_msglevel(struct net_device *dev) |
11998 | { | |
11999 | struct tg3 *tp = netdev_priv(dev); | |
12000 | return tp->msg_enable; | |
12001 | } | |
6aa20a22 | 12002 | |
1da177e4 LT |
12003 | static void tg3_set_msglevel(struct net_device *dev, u32 value) |
12004 | { | |
12005 | struct tg3 *tp = netdev_priv(dev); | |
12006 | tp->msg_enable = value; | |
12007 | } | |
6aa20a22 | 12008 | |
1da177e4 LT |
12009 | static int tg3_nway_reset(struct net_device *dev) |
12010 | { | |
12011 | struct tg3 *tp = netdev_priv(dev); | |
1da177e4 | 12012 | int r; |
6aa20a22 | 12013 | |
1da177e4 LT |
12014 | if (!netif_running(dev)) |
12015 | return -EAGAIN; | |
12016 | ||
f07e9af3 | 12017 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
c94e3941 MC |
12018 | return -EINVAL; |
12019 | ||
ce20f161 NS |
12020 | tg3_warn_mgmt_link_flap(tp); |
12021 | ||
63c3a66f | 12022 | if (tg3_flag(tp, USE_PHYLIB)) { |
f07e9af3 | 12023 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 | 12024 | return -EAGAIN; |
3f0e3ad7 | 12025 | r = phy_start_aneg(tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]); |
b02fd9e3 MC |
12026 | } else { |
12027 | u32 bmcr; | |
12028 | ||
12029 | spin_lock_bh(&tp->lock); | |
12030 | r = -EINVAL; | |
12031 | tg3_readphy(tp, MII_BMCR, &bmcr); | |
12032 | if (!tg3_readphy(tp, MII_BMCR, &bmcr) && | |
12033 | ((bmcr & BMCR_ANENABLE) || | |
f07e9af3 | 12034 | (tp->phy_flags & TG3_PHYFLG_PARALLEL_DETECT))) { |
b02fd9e3 MC |
12035 | tg3_writephy(tp, MII_BMCR, bmcr | BMCR_ANRESTART | |
12036 | BMCR_ANENABLE); | |
12037 | r = 0; | |
12038 | } | |
12039 | spin_unlock_bh(&tp->lock); | |
1da177e4 | 12040 | } |
6aa20a22 | 12041 | |
1da177e4 LT |
12042 | return r; |
12043 | } | |
6aa20a22 | 12044 | |
1da177e4 LT |
12045 | static void tg3_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
12046 | { | |
12047 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 12048 | |
2c49a44d | 12049 | ering->rx_max_pending = tp->rx_std_ring_mask; |
63c3a66f | 12050 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
2c49a44d | 12051 | ering->rx_jumbo_max_pending = tp->rx_jmb_ring_mask; |
4f81c32b MC |
12052 | else |
12053 | ering->rx_jumbo_max_pending = 0; | |
12054 | ||
12055 | ering->tx_max_pending = TG3_TX_RING_SIZE - 1; | |
1da177e4 LT |
12056 | |
12057 | ering->rx_pending = tp->rx_pending; | |
63c3a66f | 12058 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) |
4f81c32b MC |
12059 | ering->rx_jumbo_pending = tp->rx_jumbo_pending; |
12060 | else | |
12061 | ering->rx_jumbo_pending = 0; | |
12062 | ||
f3f3f27e | 12063 | ering->tx_pending = tp->napi[0].tx_pending; |
1da177e4 | 12064 | } |
6aa20a22 | 12065 | |
1da177e4 LT |
12066 | static int tg3_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering) |
12067 | { | |
12068 | struct tg3 *tp = netdev_priv(dev); | |
646c9edd | 12069 | int i, irq_sync = 0, err = 0; |
6aa20a22 | 12070 | |
2c49a44d MC |
12071 | if ((ering->rx_pending > tp->rx_std_ring_mask) || |
12072 | (ering->rx_jumbo_pending > tp->rx_jmb_ring_mask) || | |
bc3a9254 MC |
12073 | (ering->tx_pending > TG3_TX_RING_SIZE - 1) || |
12074 | (ering->tx_pending <= MAX_SKB_FRAGS) || | |
63c3a66f | 12075 | (tg3_flag(tp, TSO_BUG) && |
bc3a9254 | 12076 | (ering->tx_pending <= (MAX_SKB_FRAGS * 3)))) |
1da177e4 | 12077 | return -EINVAL; |
6aa20a22 | 12078 | |
bbe832c0 | 12079 | if (netif_running(dev)) { |
b02fd9e3 | 12080 | tg3_phy_stop(tp); |
1da177e4 | 12081 | tg3_netif_stop(tp); |
bbe832c0 MC |
12082 | irq_sync = 1; |
12083 | } | |
1da177e4 | 12084 | |
bbe832c0 | 12085 | tg3_full_lock(tp, irq_sync); |
6aa20a22 | 12086 | |
1da177e4 LT |
12087 | tp->rx_pending = ering->rx_pending; |
12088 | ||
63c3a66f | 12089 | if (tg3_flag(tp, MAX_RXPEND_64) && |
1da177e4 LT |
12090 | tp->rx_pending > 63) |
12091 | tp->rx_pending = 63; | |
d923c843 IV |
12092 | |
12093 | if (tg3_flag(tp, JUMBO_RING_ENABLE)) | |
12094 | tp->rx_jumbo_pending = ering->rx_jumbo_pending; | |
646c9edd | 12095 | |
6fd45cb8 | 12096 | for (i = 0; i < tp->irq_max; i++) |
646c9edd | 12097 | tp->napi[i].tx_pending = ering->tx_pending; |
1da177e4 LT |
12098 | |
12099 | if (netif_running(dev)) { | |
944d980e | 12100 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
953c96e0 | 12101 | err = tg3_restart_hw(tp, false); |
b9ec6c1b MC |
12102 | if (!err) |
12103 | tg3_netif_start(tp); | |
1da177e4 LT |
12104 | } |
12105 | ||
f47c11ee | 12106 | tg3_full_unlock(tp); |
6aa20a22 | 12107 | |
b02fd9e3 MC |
12108 | if (irq_sync && !err) |
12109 | tg3_phy_start(tp); | |
12110 | ||
b9ec6c1b | 12111 | return err; |
1da177e4 | 12112 | } |
6aa20a22 | 12113 | |
1da177e4 LT |
12114 | static void tg3_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
12115 | { | |
12116 | struct tg3 *tp = netdev_priv(dev); | |
6aa20a22 | 12117 | |
63c3a66f | 12118 | epause->autoneg = !!tg3_flag(tp, PAUSE_AUTONEG); |
8d018621 | 12119 | |
4a2db503 | 12120 | if (tp->link_config.flowctrl & FLOW_CTRL_RX) |
8d018621 MC |
12121 | epause->rx_pause = 1; |
12122 | else | |
12123 | epause->rx_pause = 0; | |
12124 | ||
4a2db503 | 12125 | if (tp->link_config.flowctrl & FLOW_CTRL_TX) |
8d018621 MC |
12126 | epause->tx_pause = 1; |
12127 | else | |
12128 | epause->tx_pause = 0; | |
1da177e4 | 12129 | } |
6aa20a22 | 12130 | |
1da177e4 LT |
12131 | static int tg3_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) |
12132 | { | |
12133 | struct tg3 *tp = netdev_priv(dev); | |
b02fd9e3 | 12134 | int err = 0; |
6aa20a22 | 12135 | |
ce20f161 NS |
12136 | if (tp->link_config.autoneg == AUTONEG_ENABLE) |
12137 | tg3_warn_mgmt_link_flap(tp); | |
12138 | ||
63c3a66f | 12139 | if (tg3_flag(tp, USE_PHYLIB)) { |
2712168f MC |
12140 | u32 newadv; |
12141 | struct phy_device *phydev; | |
1da177e4 | 12142 | |
2712168f | 12143 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
f47c11ee | 12144 | |
2712168f MC |
12145 | if (!(phydev->supported & SUPPORTED_Pause) || |
12146 | (!(phydev->supported & SUPPORTED_Asym_Pause) && | |
2259dca3 | 12147 | (epause->rx_pause != epause->tx_pause))) |
2712168f | 12148 | return -EINVAL; |
1da177e4 | 12149 | |
2712168f MC |
12150 | tp->link_config.flowctrl = 0; |
12151 | if (epause->rx_pause) { | |
12152 | tp->link_config.flowctrl |= FLOW_CTRL_RX; | |
12153 | ||
12154 | if (epause->tx_pause) { | |
12155 | tp->link_config.flowctrl |= FLOW_CTRL_TX; | |
12156 | newadv = ADVERTISED_Pause; | |
b02fd9e3 | 12157 | } else |
2712168f MC |
12158 | newadv = ADVERTISED_Pause | |
12159 | ADVERTISED_Asym_Pause; | |
12160 | } else if (epause->tx_pause) { | |
12161 | tp->link_config.flowctrl |= FLOW_CTRL_TX; | |
12162 | newadv = ADVERTISED_Asym_Pause; | |
12163 | } else | |
12164 | newadv = 0; | |
12165 | ||
12166 | if (epause->autoneg) | |
63c3a66f | 12167 | tg3_flag_set(tp, PAUSE_AUTONEG); |
2712168f | 12168 | else |
63c3a66f | 12169 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
2712168f | 12170 | |
f07e9af3 | 12171 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
2712168f MC |
12172 | u32 oldadv = phydev->advertising & |
12173 | (ADVERTISED_Pause | ADVERTISED_Asym_Pause); | |
12174 | if (oldadv != newadv) { | |
12175 | phydev->advertising &= | |
12176 | ~(ADVERTISED_Pause | | |
12177 | ADVERTISED_Asym_Pause); | |
12178 | phydev->advertising |= newadv; | |
12179 | if (phydev->autoneg) { | |
12180 | /* | |
12181 | * Always renegotiate the link to | |
12182 | * inform our link partner of our | |
12183 | * flow control settings, even if the | |
12184 | * flow control is forced. Let | |
12185 | * tg3_adjust_link() do the final | |
12186 | * flow control setup. | |
12187 | */ | |
12188 | return phy_start_aneg(phydev); | |
b02fd9e3 | 12189 | } |
b02fd9e3 | 12190 | } |
b02fd9e3 | 12191 | |
2712168f | 12192 | if (!epause->autoneg) |
b02fd9e3 | 12193 | tg3_setup_flow_control(tp, 0, 0); |
2712168f | 12194 | } else { |
c6700ce2 | 12195 | tp->link_config.advertising &= |
2712168f MC |
12196 | ~(ADVERTISED_Pause | |
12197 | ADVERTISED_Asym_Pause); | |
c6700ce2 | 12198 | tp->link_config.advertising |= newadv; |
b02fd9e3 MC |
12199 | } |
12200 | } else { | |
12201 | int irq_sync = 0; | |
12202 | ||
12203 | if (netif_running(dev)) { | |
12204 | tg3_netif_stop(tp); | |
12205 | irq_sync = 1; | |
12206 | } | |
12207 | ||
12208 | tg3_full_lock(tp, irq_sync); | |
12209 | ||
12210 | if (epause->autoneg) | |
63c3a66f | 12211 | tg3_flag_set(tp, PAUSE_AUTONEG); |
b02fd9e3 | 12212 | else |
63c3a66f | 12213 | tg3_flag_clear(tp, PAUSE_AUTONEG); |
b02fd9e3 | 12214 | if (epause->rx_pause) |
e18ce346 | 12215 | tp->link_config.flowctrl |= FLOW_CTRL_RX; |
b02fd9e3 | 12216 | else |
e18ce346 | 12217 | tp->link_config.flowctrl &= ~FLOW_CTRL_RX; |
b02fd9e3 | 12218 | if (epause->tx_pause) |
e18ce346 | 12219 | tp->link_config.flowctrl |= FLOW_CTRL_TX; |
b02fd9e3 | 12220 | else |
e18ce346 | 12221 | tp->link_config.flowctrl &= ~FLOW_CTRL_TX; |
b02fd9e3 MC |
12222 | |
12223 | if (netif_running(dev)) { | |
12224 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); | |
953c96e0 | 12225 | err = tg3_restart_hw(tp, false); |
b02fd9e3 MC |
12226 | if (!err) |
12227 | tg3_netif_start(tp); | |
12228 | } | |
12229 | ||
12230 | tg3_full_unlock(tp); | |
12231 | } | |
6aa20a22 | 12232 | |
fdad8de4 NS |
12233 | tp->phy_flags |= TG3_PHYFLG_USER_CONFIGURED; |
12234 | ||
b9ec6c1b | 12235 | return err; |
1da177e4 | 12236 | } |
6aa20a22 | 12237 | |
de6f31eb | 12238 | static int tg3_get_sset_count(struct net_device *dev, int sset) |
1da177e4 | 12239 | { |
b9f2c044 JG |
12240 | switch (sset) { |
12241 | case ETH_SS_TEST: | |
12242 | return TG3_NUM_TEST; | |
12243 | case ETH_SS_STATS: | |
12244 | return TG3_NUM_STATS; | |
12245 | default: | |
12246 | return -EOPNOTSUPP; | |
12247 | } | |
4cafd3f5 MC |
12248 | } |
12249 | ||
90415477 MC |
12250 | static int tg3_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info, |
12251 | u32 *rules __always_unused) | |
12252 | { | |
12253 | struct tg3 *tp = netdev_priv(dev); | |
12254 | ||
12255 | if (!tg3_flag(tp, SUPPORT_MSIX)) | |
12256 | return -EOPNOTSUPP; | |
12257 | ||
12258 | switch (info->cmd) { | |
12259 | case ETHTOOL_GRXRINGS: | |
12260 | if (netif_running(tp->dev)) | |
9102426a | 12261 | info->data = tp->rxq_cnt; |
90415477 MC |
12262 | else { |
12263 | info->data = num_online_cpus(); | |
9102426a MC |
12264 | if (info->data > TG3_RSS_MAX_NUM_QS) |
12265 | info->data = TG3_RSS_MAX_NUM_QS; | |
90415477 MC |
12266 | } |
12267 | ||
12268 | /* The first interrupt vector only | |
12269 | * handles link interrupts. | |
12270 | */ | |
12271 | info->data -= 1; | |
12272 | return 0; | |
12273 | ||
12274 | default: | |
12275 | return -EOPNOTSUPP; | |
12276 | } | |
12277 | } | |
12278 | ||
12279 | static u32 tg3_get_rxfh_indir_size(struct net_device *dev) | |
12280 | { | |
12281 | u32 size = 0; | |
12282 | struct tg3 *tp = netdev_priv(dev); | |
12283 | ||
12284 | if (tg3_flag(tp, SUPPORT_MSIX)) | |
12285 | size = TG3_RSS_INDIR_TBL_SIZE; | |
12286 | ||
12287 | return size; | |
12288 | } | |
12289 | ||
12290 | static int tg3_get_rxfh_indir(struct net_device *dev, u32 *indir) | |
12291 | { | |
12292 | struct tg3 *tp = netdev_priv(dev); | |
12293 | int i; | |
12294 | ||
12295 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) | |
12296 | indir[i] = tp->rss_ind_tbl[i]; | |
12297 | ||
12298 | return 0; | |
12299 | } | |
12300 | ||
12301 | static int tg3_set_rxfh_indir(struct net_device *dev, const u32 *indir) | |
12302 | { | |
12303 | struct tg3 *tp = netdev_priv(dev); | |
12304 | size_t i; | |
12305 | ||
12306 | for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++) | |
12307 | tp->rss_ind_tbl[i] = indir[i]; | |
12308 | ||
12309 | if (!netif_running(dev) || !tg3_flag(tp, ENABLE_RSS)) | |
12310 | return 0; | |
12311 | ||
12312 | /* It is legal to write the indirection | |
12313 | * table while the device is running. | |
12314 | */ | |
12315 | tg3_full_lock(tp, 0); | |
12316 | tg3_rss_write_indir_tbl(tp); | |
12317 | tg3_full_unlock(tp); | |
12318 | ||
12319 | return 0; | |
12320 | } | |
12321 | ||
0968169c MC |
12322 | static void tg3_get_channels(struct net_device *dev, |
12323 | struct ethtool_channels *channel) | |
12324 | { | |
12325 | struct tg3 *tp = netdev_priv(dev); | |
12326 | u32 deflt_qs = netif_get_num_default_rss_queues(); | |
12327 | ||
12328 | channel->max_rx = tp->rxq_max; | |
12329 | channel->max_tx = tp->txq_max; | |
12330 | ||
12331 | if (netif_running(dev)) { | |
12332 | channel->rx_count = tp->rxq_cnt; | |
12333 | channel->tx_count = tp->txq_cnt; | |
12334 | } else { | |
12335 | if (tp->rxq_req) | |
12336 | channel->rx_count = tp->rxq_req; | |
12337 | else | |
12338 | channel->rx_count = min(deflt_qs, tp->rxq_max); | |
12339 | ||
12340 | if (tp->txq_req) | |
12341 | channel->tx_count = tp->txq_req; | |
12342 | else | |
12343 | channel->tx_count = min(deflt_qs, tp->txq_max); | |
12344 | } | |
12345 | } | |
12346 | ||
12347 | static int tg3_set_channels(struct net_device *dev, | |
12348 | struct ethtool_channels *channel) | |
12349 | { | |
12350 | struct tg3 *tp = netdev_priv(dev); | |
12351 | ||
12352 | if (!tg3_flag(tp, SUPPORT_MSIX)) | |
12353 | return -EOPNOTSUPP; | |
12354 | ||
12355 | if (channel->rx_count > tp->rxq_max || | |
12356 | channel->tx_count > tp->txq_max) | |
12357 | return -EINVAL; | |
12358 | ||
12359 | tp->rxq_req = channel->rx_count; | |
12360 | tp->txq_req = channel->tx_count; | |
12361 | ||
12362 | if (!netif_running(dev)) | |
12363 | return 0; | |
12364 | ||
12365 | tg3_stop(tp); | |
12366 | ||
f4a46d1f | 12367 | tg3_carrier_off(tp); |
0968169c | 12368 | |
be947307 | 12369 | tg3_start(tp, true, false, false); |
0968169c MC |
12370 | |
12371 | return 0; | |
12372 | } | |
12373 | ||
de6f31eb | 12374 | static void tg3_get_strings(struct net_device *dev, u32 stringset, u8 *buf) |
1da177e4 LT |
12375 | { |
12376 | switch (stringset) { | |
12377 | case ETH_SS_STATS: | |
12378 | memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys)); | |
12379 | break; | |
4cafd3f5 MC |
12380 | case ETH_SS_TEST: |
12381 | memcpy(buf, ðtool_test_keys, sizeof(ethtool_test_keys)); | |
12382 | break; | |
1da177e4 LT |
12383 | default: |
12384 | WARN_ON(1); /* we need a WARN() */ | |
12385 | break; | |
12386 | } | |
12387 | } | |
12388 | ||
81b8709c | 12389 | static int tg3_set_phys_id(struct net_device *dev, |
12390 | enum ethtool_phys_id_state state) | |
4009a93d MC |
12391 | { |
12392 | struct tg3 *tp = netdev_priv(dev); | |
4009a93d MC |
12393 | |
12394 | if (!netif_running(tp->dev)) | |
12395 | return -EAGAIN; | |
12396 | ||
81b8709c | 12397 | switch (state) { |
12398 | case ETHTOOL_ID_ACTIVE: | |
fce55922 | 12399 | return 1; /* cycle on/off once per second */ |
4009a93d | 12400 | |
81b8709c | 12401 | case ETHTOOL_ID_ON: |
12402 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | | |
12403 | LED_CTRL_1000MBPS_ON | | |
12404 | LED_CTRL_100MBPS_ON | | |
12405 | LED_CTRL_10MBPS_ON | | |
12406 | LED_CTRL_TRAFFIC_OVERRIDE | | |
12407 | LED_CTRL_TRAFFIC_BLINK | | |
12408 | LED_CTRL_TRAFFIC_LED); | |
12409 | break; | |
6aa20a22 | 12410 | |
81b8709c | 12411 | case ETHTOOL_ID_OFF: |
12412 | tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE | | |
12413 | LED_CTRL_TRAFFIC_OVERRIDE); | |
12414 | break; | |
4009a93d | 12415 | |
81b8709c | 12416 | case ETHTOOL_ID_INACTIVE: |
12417 | tw32(MAC_LED_CTRL, tp->led_ctrl); | |
12418 | break; | |
4009a93d | 12419 | } |
81b8709c | 12420 | |
4009a93d MC |
12421 | return 0; |
12422 | } | |
12423 | ||
de6f31eb | 12424 | static void tg3_get_ethtool_stats(struct net_device *dev, |
1da177e4 LT |
12425 | struct ethtool_stats *estats, u64 *tmp_stats) |
12426 | { | |
12427 | struct tg3 *tp = netdev_priv(dev); | |
0e6c9da3 | 12428 | |
b546e46f MC |
12429 | if (tp->hw_stats) |
12430 | tg3_get_estats(tp, (struct tg3_ethtool_stats *)tmp_stats); | |
12431 | else | |
12432 | memset(tmp_stats, 0, sizeof(struct tg3_ethtool_stats)); | |
1da177e4 LT |
12433 | } |
12434 | ||
535a490e | 12435 | static __be32 *tg3_vpd_readblock(struct tg3 *tp, u32 *vpdlen) |
c3e94500 MC |
12436 | { |
12437 | int i; | |
12438 | __be32 *buf; | |
12439 | u32 offset = 0, len = 0; | |
12440 | u32 magic, val; | |
12441 | ||
63c3a66f | 12442 | if (tg3_flag(tp, NO_NVRAM) || tg3_nvram_read(tp, 0, &magic)) |
c3e94500 MC |
12443 | return NULL; |
12444 | ||
12445 | if (magic == TG3_EEPROM_MAGIC) { | |
12446 | for (offset = TG3_NVM_DIR_START; | |
12447 | offset < TG3_NVM_DIR_END; | |
12448 | offset += TG3_NVM_DIRENT_SIZE) { | |
12449 | if (tg3_nvram_read(tp, offset, &val)) | |
12450 | return NULL; | |
12451 | ||
12452 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == | |
12453 | TG3_NVM_DIRTYPE_EXTVPD) | |
12454 | break; | |
12455 | } | |
12456 | ||
12457 | if (offset != TG3_NVM_DIR_END) { | |
12458 | len = (val & TG3_NVM_DIRTYPE_LENMSK) * 4; | |
12459 | if (tg3_nvram_read(tp, offset + 4, &offset)) | |
12460 | return NULL; | |
12461 | ||
12462 | offset = tg3_nvram_logical_addr(tp, offset); | |
12463 | } | |
12464 | } | |
12465 | ||
12466 | if (!offset || !len) { | |
12467 | offset = TG3_NVM_VPD_OFF; | |
12468 | len = TG3_NVM_VPD_LEN; | |
12469 | } | |
12470 | ||
12471 | buf = kmalloc(len, GFP_KERNEL); | |
12472 | if (buf == NULL) | |
12473 | return NULL; | |
12474 | ||
12475 | if (magic == TG3_EEPROM_MAGIC) { | |
12476 | for (i = 0; i < len; i += 4) { | |
12477 | /* The data is in little-endian format in NVRAM. | |
12478 | * Use the big-endian read routines to preserve | |
12479 | * the byte order as it exists in NVRAM. | |
12480 | */ | |
12481 | if (tg3_nvram_read_be32(tp, offset + i, &buf[i/4])) | |
12482 | goto error; | |
12483 | } | |
12484 | } else { | |
12485 | u8 *ptr; | |
12486 | ssize_t cnt; | |
12487 | unsigned int pos = 0; | |
12488 | ||
12489 | ptr = (u8 *)&buf[0]; | |
12490 | for (i = 0; pos < len && i < 3; i++, pos += cnt, ptr += cnt) { | |
12491 | cnt = pci_read_vpd(tp->pdev, pos, | |
12492 | len - pos, ptr); | |
12493 | if (cnt == -ETIMEDOUT || cnt == -EINTR) | |
12494 | cnt = 0; | |
12495 | else if (cnt < 0) | |
12496 | goto error; | |
12497 | } | |
12498 | if (pos != len) | |
12499 | goto error; | |
12500 | } | |
12501 | ||
535a490e MC |
12502 | *vpdlen = len; |
12503 | ||
c3e94500 MC |
12504 | return buf; |
12505 | ||
12506 | error: | |
12507 | kfree(buf); | |
12508 | return NULL; | |
12509 | } | |
12510 | ||
566f86ad | 12511 | #define NVRAM_TEST_SIZE 0x100 |
a5767dec MC |
12512 | #define NVRAM_SELFBOOT_FORMAT1_0_SIZE 0x14 |
12513 | #define NVRAM_SELFBOOT_FORMAT1_2_SIZE 0x18 | |
12514 | #define NVRAM_SELFBOOT_FORMAT1_3_SIZE 0x1c | |
727a6d9f MC |
12515 | #define NVRAM_SELFBOOT_FORMAT1_4_SIZE 0x20 |
12516 | #define NVRAM_SELFBOOT_FORMAT1_5_SIZE 0x24 | |
bda18faf | 12517 | #define NVRAM_SELFBOOT_FORMAT1_6_SIZE 0x50 |
b16250e3 MC |
12518 | #define NVRAM_SELFBOOT_HW_SIZE 0x20 |
12519 | #define NVRAM_SELFBOOT_DATA_SIZE 0x1c | |
566f86ad MC |
12520 | |
12521 | static int tg3_test_nvram(struct tg3 *tp) | |
12522 | { | |
535a490e | 12523 | u32 csum, magic, len; |
a9dc529d | 12524 | __be32 *buf; |
ab0049b4 | 12525 | int i, j, k, err = 0, size; |
566f86ad | 12526 | |
63c3a66f | 12527 | if (tg3_flag(tp, NO_NVRAM)) |
df259d8c MC |
12528 | return 0; |
12529 | ||
e4f34110 | 12530 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
1b27777a MC |
12531 | return -EIO; |
12532 | ||
1b27777a MC |
12533 | if (magic == TG3_EEPROM_MAGIC) |
12534 | size = NVRAM_TEST_SIZE; | |
b16250e3 | 12535 | else if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) { |
a5767dec MC |
12536 | if ((magic & TG3_EEPROM_SB_FORMAT_MASK) == |
12537 | TG3_EEPROM_SB_FORMAT_1) { | |
12538 | switch (magic & TG3_EEPROM_SB_REVISION_MASK) { | |
12539 | case TG3_EEPROM_SB_REVISION_0: | |
12540 | size = NVRAM_SELFBOOT_FORMAT1_0_SIZE; | |
12541 | break; | |
12542 | case TG3_EEPROM_SB_REVISION_2: | |
12543 | size = NVRAM_SELFBOOT_FORMAT1_2_SIZE; | |
12544 | break; | |
12545 | case TG3_EEPROM_SB_REVISION_3: | |
12546 | size = NVRAM_SELFBOOT_FORMAT1_3_SIZE; | |
12547 | break; | |
727a6d9f MC |
12548 | case TG3_EEPROM_SB_REVISION_4: |
12549 | size = NVRAM_SELFBOOT_FORMAT1_4_SIZE; | |
12550 | break; | |
12551 | case TG3_EEPROM_SB_REVISION_5: | |
12552 | size = NVRAM_SELFBOOT_FORMAT1_5_SIZE; | |
12553 | break; | |
12554 | case TG3_EEPROM_SB_REVISION_6: | |
12555 | size = NVRAM_SELFBOOT_FORMAT1_6_SIZE; | |
12556 | break; | |
a5767dec | 12557 | default: |
727a6d9f | 12558 | return -EIO; |
a5767dec MC |
12559 | } |
12560 | } else | |
1b27777a | 12561 | return 0; |
b16250e3 MC |
12562 | } else if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
12563 | size = NVRAM_SELFBOOT_HW_SIZE; | |
12564 | else | |
1b27777a MC |
12565 | return -EIO; |
12566 | ||
12567 | buf = kmalloc(size, GFP_KERNEL); | |
566f86ad MC |
12568 | if (buf == NULL) |
12569 | return -ENOMEM; | |
12570 | ||
1b27777a MC |
12571 | err = -EIO; |
12572 | for (i = 0, j = 0; i < size; i += 4, j++) { | |
a9dc529d MC |
12573 | err = tg3_nvram_read_be32(tp, i, &buf[j]); |
12574 | if (err) | |
566f86ad | 12575 | break; |
566f86ad | 12576 | } |
1b27777a | 12577 | if (i < size) |
566f86ad MC |
12578 | goto out; |
12579 | ||
1b27777a | 12580 | /* Selfboot format */ |
a9dc529d | 12581 | magic = be32_to_cpu(buf[0]); |
b9fc7dc5 | 12582 | if ((magic & TG3_EEPROM_MAGIC_FW_MSK) == |
b16250e3 | 12583 | TG3_EEPROM_MAGIC_FW) { |
1b27777a MC |
12584 | u8 *buf8 = (u8 *) buf, csum8 = 0; |
12585 | ||
b9fc7dc5 | 12586 | if ((magic & TG3_EEPROM_SB_REVISION_MASK) == |
a5767dec MC |
12587 | TG3_EEPROM_SB_REVISION_2) { |
12588 | /* For rev 2, the csum doesn't include the MBA. */ | |
12589 | for (i = 0; i < TG3_EEPROM_SB_F1R2_MBA_OFF; i++) | |
12590 | csum8 += buf8[i]; | |
12591 | for (i = TG3_EEPROM_SB_F1R2_MBA_OFF + 4; i < size; i++) | |
12592 | csum8 += buf8[i]; | |
12593 | } else { | |
12594 | for (i = 0; i < size; i++) | |
12595 | csum8 += buf8[i]; | |
12596 | } | |
1b27777a | 12597 | |
ad96b485 AB |
12598 | if (csum8 == 0) { |
12599 | err = 0; | |
12600 | goto out; | |
12601 | } | |
12602 | ||
12603 | err = -EIO; | |
12604 | goto out; | |
1b27777a | 12605 | } |
566f86ad | 12606 | |
b9fc7dc5 | 12607 | if ((magic & TG3_EEPROM_MAGIC_HW_MSK) == |
b16250e3 MC |
12608 | TG3_EEPROM_MAGIC_HW) { |
12609 | u8 data[NVRAM_SELFBOOT_DATA_SIZE]; | |
a9dc529d | 12610 | u8 parity[NVRAM_SELFBOOT_DATA_SIZE]; |
b16250e3 | 12611 | u8 *buf8 = (u8 *) buf; |
b16250e3 MC |
12612 | |
12613 | /* Separate the parity bits and the data bytes. */ | |
12614 | for (i = 0, j = 0, k = 0; i < NVRAM_SELFBOOT_HW_SIZE; i++) { | |
12615 | if ((i == 0) || (i == 8)) { | |
12616 | int l; | |
12617 | u8 msk; | |
12618 | ||
12619 | for (l = 0, msk = 0x80; l < 7; l++, msk >>= 1) | |
12620 | parity[k++] = buf8[i] & msk; | |
12621 | i++; | |
859a5887 | 12622 | } else if (i == 16) { |
b16250e3 MC |
12623 | int l; |
12624 | u8 msk; | |
12625 | ||
12626 | for (l = 0, msk = 0x20; l < 6; l++, msk >>= 1) | |
12627 | parity[k++] = buf8[i] & msk; | |
12628 | i++; | |
12629 | ||
12630 | for (l = 0, msk = 0x80; l < 8; l++, msk >>= 1) | |
12631 | parity[k++] = buf8[i] & msk; | |
12632 | i++; | |
12633 | } | |
12634 | data[j++] = buf8[i]; | |
12635 | } | |
12636 | ||
12637 | err = -EIO; | |
12638 | for (i = 0; i < NVRAM_SELFBOOT_DATA_SIZE; i++) { | |
12639 | u8 hw8 = hweight8(data[i]); | |
12640 | ||
12641 | if ((hw8 & 0x1) && parity[i]) | |
12642 | goto out; | |
12643 | else if (!(hw8 & 0x1) && !parity[i]) | |
12644 | goto out; | |
12645 | } | |
12646 | err = 0; | |
12647 | goto out; | |
12648 | } | |
12649 | ||
01c3a392 MC |
12650 | err = -EIO; |
12651 | ||
566f86ad MC |
12652 | /* Bootstrap checksum at offset 0x10 */ |
12653 | csum = calc_crc((unsigned char *) buf, 0x10); | |
01c3a392 | 12654 | if (csum != le32_to_cpu(buf[0x10/4])) |
566f86ad MC |
12655 | goto out; |
12656 | ||
12657 | /* Manufacturing block starts at offset 0x74, checksum at 0xfc */ | |
12658 | csum = calc_crc((unsigned char *) &buf[0x74/4], 0x88); | |
01c3a392 | 12659 | if (csum != le32_to_cpu(buf[0xfc/4])) |
a9dc529d | 12660 | goto out; |
566f86ad | 12661 | |
c3e94500 MC |
12662 | kfree(buf); |
12663 | ||
535a490e | 12664 | buf = tg3_vpd_readblock(tp, &len); |
c3e94500 MC |
12665 | if (!buf) |
12666 | return -ENOMEM; | |
d4894f3e | 12667 | |
535a490e | 12668 | i = pci_vpd_find_tag((u8 *)buf, 0, len, PCI_VPD_LRDT_RO_DATA); |
d4894f3e MC |
12669 | if (i > 0) { |
12670 | j = pci_vpd_lrdt_size(&((u8 *)buf)[i]); | |
12671 | if (j < 0) | |
12672 | goto out; | |
12673 | ||
535a490e | 12674 | if (i + PCI_VPD_LRDT_TAG_SIZE + j > len) |
d4894f3e MC |
12675 | goto out; |
12676 | ||
12677 | i += PCI_VPD_LRDT_TAG_SIZE; | |
12678 | j = pci_vpd_find_info_keyword((u8 *)buf, i, j, | |
12679 | PCI_VPD_RO_KEYWORD_CHKSUM); | |
12680 | if (j > 0) { | |
12681 | u8 csum8 = 0; | |
12682 | ||
12683 | j += PCI_VPD_INFO_FLD_HDR_SIZE; | |
12684 | ||
12685 | for (i = 0; i <= j; i++) | |
12686 | csum8 += ((u8 *)buf)[i]; | |
12687 | ||
12688 | if (csum8) | |
12689 | goto out; | |
12690 | } | |
12691 | } | |
12692 | ||
566f86ad MC |
12693 | err = 0; |
12694 | ||
12695 | out: | |
12696 | kfree(buf); | |
12697 | return err; | |
12698 | } | |
12699 | ||
ca43007a MC |
12700 | #define TG3_SERDES_TIMEOUT_SEC 2 |
12701 | #define TG3_COPPER_TIMEOUT_SEC 6 | |
12702 | ||
12703 | static int tg3_test_link(struct tg3 *tp) | |
12704 | { | |
12705 | int i, max; | |
12706 | ||
12707 | if (!netif_running(tp->dev)) | |
12708 | return -ENODEV; | |
12709 | ||
f07e9af3 | 12710 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) |
ca43007a MC |
12711 | max = TG3_SERDES_TIMEOUT_SEC; |
12712 | else | |
12713 | max = TG3_COPPER_TIMEOUT_SEC; | |
12714 | ||
12715 | for (i = 0; i < max; i++) { | |
f4a46d1f | 12716 | if (tp->link_up) |
ca43007a MC |
12717 | return 0; |
12718 | ||
12719 | if (msleep_interruptible(1000)) | |
12720 | break; | |
12721 | } | |
12722 | ||
12723 | return -EIO; | |
12724 | } | |
12725 | ||
a71116d1 | 12726 | /* Only test the commonly used registers */ |
30ca3e37 | 12727 | static int tg3_test_registers(struct tg3 *tp) |
a71116d1 | 12728 | { |
b16250e3 | 12729 | int i, is_5705, is_5750; |
a71116d1 MC |
12730 | u32 offset, read_mask, write_mask, val, save_val, read_val; |
12731 | static struct { | |
12732 | u16 offset; | |
12733 | u16 flags; | |
12734 | #define TG3_FL_5705 0x1 | |
12735 | #define TG3_FL_NOT_5705 0x2 | |
12736 | #define TG3_FL_NOT_5788 0x4 | |
b16250e3 | 12737 | #define TG3_FL_NOT_5750 0x8 |
a71116d1 MC |
12738 | u32 read_mask; |
12739 | u32 write_mask; | |
12740 | } reg_tbl[] = { | |
12741 | /* MAC Control Registers */ | |
12742 | { MAC_MODE, TG3_FL_NOT_5705, | |
12743 | 0x00000000, 0x00ef6f8c }, | |
12744 | { MAC_MODE, TG3_FL_5705, | |
12745 | 0x00000000, 0x01ef6b8c }, | |
12746 | { MAC_STATUS, TG3_FL_NOT_5705, | |
12747 | 0x03800107, 0x00000000 }, | |
12748 | { MAC_STATUS, TG3_FL_5705, | |
12749 | 0x03800100, 0x00000000 }, | |
12750 | { MAC_ADDR_0_HIGH, 0x0000, | |
12751 | 0x00000000, 0x0000ffff }, | |
12752 | { MAC_ADDR_0_LOW, 0x0000, | |
c6cdf436 | 12753 | 0x00000000, 0xffffffff }, |
a71116d1 MC |
12754 | { MAC_RX_MTU_SIZE, 0x0000, |
12755 | 0x00000000, 0x0000ffff }, | |
12756 | { MAC_TX_MODE, 0x0000, | |
12757 | 0x00000000, 0x00000070 }, | |
12758 | { MAC_TX_LENGTHS, 0x0000, | |
12759 | 0x00000000, 0x00003fff }, | |
12760 | { MAC_RX_MODE, TG3_FL_NOT_5705, | |
12761 | 0x00000000, 0x000007fc }, | |
12762 | { MAC_RX_MODE, TG3_FL_5705, | |
12763 | 0x00000000, 0x000007dc }, | |
12764 | { MAC_HASH_REG_0, 0x0000, | |
12765 | 0x00000000, 0xffffffff }, | |
12766 | { MAC_HASH_REG_1, 0x0000, | |
12767 | 0x00000000, 0xffffffff }, | |
12768 | { MAC_HASH_REG_2, 0x0000, | |
12769 | 0x00000000, 0xffffffff }, | |
12770 | { MAC_HASH_REG_3, 0x0000, | |
12771 | 0x00000000, 0xffffffff }, | |
12772 | ||
12773 | /* Receive Data and Receive BD Initiator Control Registers. */ | |
12774 | { RCVDBDI_JUMBO_BD+0, TG3_FL_NOT_5705, | |
12775 | 0x00000000, 0xffffffff }, | |
12776 | { RCVDBDI_JUMBO_BD+4, TG3_FL_NOT_5705, | |
12777 | 0x00000000, 0xffffffff }, | |
12778 | { RCVDBDI_JUMBO_BD+8, TG3_FL_NOT_5705, | |
12779 | 0x00000000, 0x00000003 }, | |
12780 | { RCVDBDI_JUMBO_BD+0xc, TG3_FL_NOT_5705, | |
12781 | 0x00000000, 0xffffffff }, | |
12782 | { RCVDBDI_STD_BD+0, 0x0000, | |
12783 | 0x00000000, 0xffffffff }, | |
12784 | { RCVDBDI_STD_BD+4, 0x0000, | |
12785 | 0x00000000, 0xffffffff }, | |
12786 | { RCVDBDI_STD_BD+8, 0x0000, | |
12787 | 0x00000000, 0xffff0002 }, | |
12788 | { RCVDBDI_STD_BD+0xc, 0x0000, | |
12789 | 0x00000000, 0xffffffff }, | |
6aa20a22 | 12790 | |
a71116d1 MC |
12791 | /* Receive BD Initiator Control Registers. */ |
12792 | { RCVBDI_STD_THRESH, TG3_FL_NOT_5705, | |
12793 | 0x00000000, 0xffffffff }, | |
12794 | { RCVBDI_STD_THRESH, TG3_FL_5705, | |
12795 | 0x00000000, 0x000003ff }, | |
12796 | { RCVBDI_JUMBO_THRESH, TG3_FL_NOT_5705, | |
12797 | 0x00000000, 0xffffffff }, | |
6aa20a22 | 12798 | |
a71116d1 MC |
12799 | /* Host Coalescing Control Registers. */ |
12800 | { HOSTCC_MODE, TG3_FL_NOT_5705, | |
12801 | 0x00000000, 0x00000004 }, | |
12802 | { HOSTCC_MODE, TG3_FL_5705, | |
12803 | 0x00000000, 0x000000f6 }, | |
12804 | { HOSTCC_RXCOL_TICKS, TG3_FL_NOT_5705, | |
12805 | 0x00000000, 0xffffffff }, | |
12806 | { HOSTCC_RXCOL_TICKS, TG3_FL_5705, | |
12807 | 0x00000000, 0x000003ff }, | |
12808 | { HOSTCC_TXCOL_TICKS, TG3_FL_NOT_5705, | |
12809 | 0x00000000, 0xffffffff }, | |
12810 | { HOSTCC_TXCOL_TICKS, TG3_FL_5705, | |
12811 | 0x00000000, 0x000003ff }, | |
12812 | { HOSTCC_RXMAX_FRAMES, TG3_FL_NOT_5705, | |
12813 | 0x00000000, 0xffffffff }, | |
12814 | { HOSTCC_RXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, | |
12815 | 0x00000000, 0x000000ff }, | |
12816 | { HOSTCC_TXMAX_FRAMES, TG3_FL_NOT_5705, | |
12817 | 0x00000000, 0xffffffff }, | |
12818 | { HOSTCC_TXMAX_FRAMES, TG3_FL_5705 | TG3_FL_NOT_5788, | |
12819 | 0x00000000, 0x000000ff }, | |
12820 | { HOSTCC_RXCOAL_TICK_INT, TG3_FL_NOT_5705, | |
12821 | 0x00000000, 0xffffffff }, | |
12822 | { HOSTCC_TXCOAL_TICK_INT, TG3_FL_NOT_5705, | |
12823 | 0x00000000, 0xffffffff }, | |
12824 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_NOT_5705, | |
12825 | 0x00000000, 0xffffffff }, | |
12826 | { HOSTCC_RXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, | |
12827 | 0x00000000, 0x000000ff }, | |
12828 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_NOT_5705, | |
12829 | 0x00000000, 0xffffffff }, | |
12830 | { HOSTCC_TXCOAL_MAXF_INT, TG3_FL_5705 | TG3_FL_NOT_5788, | |
12831 | 0x00000000, 0x000000ff }, | |
12832 | { HOSTCC_STAT_COAL_TICKS, TG3_FL_NOT_5705, | |
12833 | 0x00000000, 0xffffffff }, | |
12834 | { HOSTCC_STATS_BLK_HOST_ADDR, TG3_FL_NOT_5705, | |
12835 | 0x00000000, 0xffffffff }, | |
12836 | { HOSTCC_STATS_BLK_HOST_ADDR+4, TG3_FL_NOT_5705, | |
12837 | 0x00000000, 0xffffffff }, | |
12838 | { HOSTCC_STATUS_BLK_HOST_ADDR, 0x0000, | |
12839 | 0x00000000, 0xffffffff }, | |
12840 | { HOSTCC_STATUS_BLK_HOST_ADDR+4, 0x0000, | |
12841 | 0x00000000, 0xffffffff }, | |
12842 | { HOSTCC_STATS_BLK_NIC_ADDR, 0x0000, | |
12843 | 0xffffffff, 0x00000000 }, | |
12844 | { HOSTCC_STATUS_BLK_NIC_ADDR, 0x0000, | |
12845 | 0xffffffff, 0x00000000 }, | |
12846 | ||
12847 | /* Buffer Manager Control Registers. */ | |
b16250e3 | 12848 | { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750, |
a71116d1 | 12849 | 0x00000000, 0x007fff80 }, |
b16250e3 | 12850 | { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750, |
a71116d1 MC |
12851 | 0x00000000, 0x007fffff }, |
12852 | { BUFMGR_MB_RDMA_LOW_WATER, 0x0000, | |
12853 | 0x00000000, 0x0000003f }, | |
12854 | { BUFMGR_MB_MACRX_LOW_WATER, 0x0000, | |
12855 | 0x00000000, 0x000001ff }, | |
12856 | { BUFMGR_MB_HIGH_WATER, 0x0000, | |
12857 | 0x00000000, 0x000001ff }, | |
12858 | { BUFMGR_DMA_DESC_POOL_ADDR, TG3_FL_NOT_5705, | |
12859 | 0xffffffff, 0x00000000 }, | |
12860 | { BUFMGR_DMA_DESC_POOL_SIZE, TG3_FL_NOT_5705, | |
12861 | 0xffffffff, 0x00000000 }, | |
6aa20a22 | 12862 | |
a71116d1 MC |
12863 | /* Mailbox Registers */ |
12864 | { GRCMBOX_RCVSTD_PROD_IDX+4, 0x0000, | |
12865 | 0x00000000, 0x000001ff }, | |
12866 | { GRCMBOX_RCVJUMBO_PROD_IDX+4, TG3_FL_NOT_5705, | |
12867 | 0x00000000, 0x000001ff }, | |
12868 | { GRCMBOX_RCVRET_CON_IDX_0+4, 0x0000, | |
12869 | 0x00000000, 0x000007ff }, | |
12870 | { GRCMBOX_SNDHOST_PROD_IDX_0+4, 0x0000, | |
12871 | 0x00000000, 0x000001ff }, | |
12872 | ||
12873 | { 0xffff, 0x0000, 0x00000000, 0x00000000 }, | |
12874 | }; | |
12875 | ||
b16250e3 | 12876 | is_5705 = is_5750 = 0; |
63c3a66f | 12877 | if (tg3_flag(tp, 5705_PLUS)) { |
a71116d1 | 12878 | is_5705 = 1; |
63c3a66f | 12879 | if (tg3_flag(tp, 5750_PLUS)) |
b16250e3 MC |
12880 | is_5750 = 1; |
12881 | } | |
a71116d1 MC |
12882 | |
12883 | for (i = 0; reg_tbl[i].offset != 0xffff; i++) { | |
12884 | if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705)) | |
12885 | continue; | |
12886 | ||
12887 | if (!is_5705 && (reg_tbl[i].flags & TG3_FL_5705)) | |
12888 | continue; | |
12889 | ||
63c3a66f | 12890 | if (tg3_flag(tp, IS_5788) && |
a71116d1 MC |
12891 | (reg_tbl[i].flags & TG3_FL_NOT_5788)) |
12892 | continue; | |
12893 | ||
b16250e3 MC |
12894 | if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750)) |
12895 | continue; | |
12896 | ||
a71116d1 MC |
12897 | offset = (u32) reg_tbl[i].offset; |
12898 | read_mask = reg_tbl[i].read_mask; | |
12899 | write_mask = reg_tbl[i].write_mask; | |
12900 | ||
12901 | /* Save the original register content */ | |
12902 | save_val = tr32(offset); | |
12903 | ||
12904 | /* Determine the read-only value. */ | |
12905 | read_val = save_val & read_mask; | |
12906 | ||
12907 | /* Write zero to the register, then make sure the read-only bits | |
12908 | * are not changed and the read/write bits are all zeros. | |
12909 | */ | |
12910 | tw32(offset, 0); | |
12911 | ||
12912 | val = tr32(offset); | |
12913 | ||
12914 | /* Test the read-only and read/write bits. */ | |
12915 | if (((val & read_mask) != read_val) || (val & write_mask)) | |
12916 | goto out; | |
12917 | ||
12918 | /* Write ones to all the bits defined by RdMask and WrMask, then | |
12919 | * make sure the read-only bits are not changed and the | |
12920 | * read/write bits are all ones. | |
12921 | */ | |
12922 | tw32(offset, read_mask | write_mask); | |
12923 | ||
12924 | val = tr32(offset); | |
12925 | ||
12926 | /* Test the read-only bits. */ | |
12927 | if ((val & read_mask) != read_val) | |
12928 | goto out; | |
12929 | ||
12930 | /* Test the read/write bits. */ | |
12931 | if ((val & write_mask) != write_mask) | |
12932 | goto out; | |
12933 | ||
12934 | tw32(offset, save_val); | |
12935 | } | |
12936 | ||
12937 | return 0; | |
12938 | ||
12939 | out: | |
9f88f29f | 12940 | if (netif_msg_hw(tp)) |
2445e461 MC |
12941 | netdev_err(tp->dev, |
12942 | "Register test failed at offset %x\n", offset); | |
a71116d1 MC |
12943 | tw32(offset, save_val); |
12944 | return -EIO; | |
12945 | } | |
12946 | ||
7942e1db MC |
12947 | static int tg3_do_mem_test(struct tg3 *tp, u32 offset, u32 len) |
12948 | { | |
f71e1309 | 12949 | static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0xaa55a55a }; |
7942e1db MC |
12950 | int i; |
12951 | u32 j; | |
12952 | ||
e9edda69 | 12953 | for (i = 0; i < ARRAY_SIZE(test_pattern); i++) { |
7942e1db MC |
12954 | for (j = 0; j < len; j += 4) { |
12955 | u32 val; | |
12956 | ||
12957 | tg3_write_mem(tp, offset + j, test_pattern[i]); | |
12958 | tg3_read_mem(tp, offset + j, &val); | |
12959 | if (val != test_pattern[i]) | |
12960 | return -EIO; | |
12961 | } | |
12962 | } | |
12963 | return 0; | |
12964 | } | |
12965 | ||
12966 | static int tg3_test_memory(struct tg3 *tp) | |
12967 | { | |
12968 | static struct mem_entry { | |
12969 | u32 offset; | |
12970 | u32 len; | |
12971 | } mem_tbl_570x[] = { | |
38690194 | 12972 | { 0x00000000, 0x00b50}, |
7942e1db MC |
12973 | { 0x00002000, 0x1c000}, |
12974 | { 0xffffffff, 0x00000} | |
12975 | }, mem_tbl_5705[] = { | |
12976 | { 0x00000100, 0x0000c}, | |
12977 | { 0x00000200, 0x00008}, | |
7942e1db MC |
12978 | { 0x00004000, 0x00800}, |
12979 | { 0x00006000, 0x01000}, | |
12980 | { 0x00008000, 0x02000}, | |
12981 | { 0x00010000, 0x0e000}, | |
12982 | { 0xffffffff, 0x00000} | |
79f4d13a MC |
12983 | }, mem_tbl_5755[] = { |
12984 | { 0x00000200, 0x00008}, | |
12985 | { 0x00004000, 0x00800}, | |
12986 | { 0x00006000, 0x00800}, | |
12987 | { 0x00008000, 0x02000}, | |
12988 | { 0x00010000, 0x0c000}, | |
12989 | { 0xffffffff, 0x00000} | |
b16250e3 MC |
12990 | }, mem_tbl_5906[] = { |
12991 | { 0x00000200, 0x00008}, | |
12992 | { 0x00004000, 0x00400}, | |
12993 | { 0x00006000, 0x00400}, | |
12994 | { 0x00008000, 0x01000}, | |
12995 | { 0x00010000, 0x01000}, | |
12996 | { 0xffffffff, 0x00000} | |
8b5a6c42 MC |
12997 | }, mem_tbl_5717[] = { |
12998 | { 0x00000200, 0x00008}, | |
12999 | { 0x00010000, 0x0a000}, | |
13000 | { 0x00020000, 0x13c00}, | |
13001 | { 0xffffffff, 0x00000} | |
13002 | }, mem_tbl_57765[] = { | |
13003 | { 0x00000200, 0x00008}, | |
13004 | { 0x00004000, 0x00800}, | |
13005 | { 0x00006000, 0x09800}, | |
13006 | { 0x00010000, 0x0a000}, | |
13007 | { 0xffffffff, 0x00000} | |
7942e1db MC |
13008 | }; |
13009 | struct mem_entry *mem_tbl; | |
13010 | int err = 0; | |
13011 | int i; | |
13012 | ||
63c3a66f | 13013 | if (tg3_flag(tp, 5717_PLUS)) |
8b5a6c42 | 13014 | mem_tbl = mem_tbl_5717; |
c65a17f4 | 13015 | else if (tg3_flag(tp, 57765_CLASS) || |
4153577a | 13016 | tg3_asic_rev(tp) == ASIC_REV_5762) |
8b5a6c42 | 13017 | mem_tbl = mem_tbl_57765; |
63c3a66f | 13018 | else if (tg3_flag(tp, 5755_PLUS)) |
321d32a0 | 13019 | mem_tbl = mem_tbl_5755; |
4153577a | 13020 | else if (tg3_asic_rev(tp) == ASIC_REV_5906) |
321d32a0 | 13021 | mem_tbl = mem_tbl_5906; |
63c3a66f | 13022 | else if (tg3_flag(tp, 5705_PLUS)) |
321d32a0 MC |
13023 | mem_tbl = mem_tbl_5705; |
13024 | else | |
7942e1db MC |
13025 | mem_tbl = mem_tbl_570x; |
13026 | ||
13027 | for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) { | |
be98da6a MC |
13028 | err = tg3_do_mem_test(tp, mem_tbl[i].offset, mem_tbl[i].len); |
13029 | if (err) | |
7942e1db MC |
13030 | break; |
13031 | } | |
6aa20a22 | 13032 | |
7942e1db MC |
13033 | return err; |
13034 | } | |
13035 | ||
bb158d69 MC |
13036 | #define TG3_TSO_MSS 500 |
13037 | ||
13038 | #define TG3_TSO_IP_HDR_LEN 20 | |
13039 | #define TG3_TSO_TCP_HDR_LEN 20 | |
13040 | #define TG3_TSO_TCP_OPT_LEN 12 | |
13041 | ||
13042 | static const u8 tg3_tso_header[] = { | |
13043 | 0x08, 0x00, | |
13044 | 0x45, 0x00, 0x00, 0x00, | |
13045 | 0x00, 0x00, 0x40, 0x00, | |
13046 | 0x40, 0x06, 0x00, 0x00, | |
13047 | 0x0a, 0x00, 0x00, 0x01, | |
13048 | 0x0a, 0x00, 0x00, 0x02, | |
13049 | 0x0d, 0x00, 0xe0, 0x00, | |
13050 | 0x00, 0x00, 0x01, 0x00, | |
13051 | 0x00, 0x00, 0x02, 0x00, | |
13052 | 0x80, 0x10, 0x10, 0x00, | |
13053 | 0x14, 0x09, 0x00, 0x00, | |
13054 | 0x01, 0x01, 0x08, 0x0a, | |
13055 | 0x11, 0x11, 0x11, 0x11, | |
13056 | 0x11, 0x11, 0x11, 0x11, | |
13057 | }; | |
9f40dead | 13058 | |
28a45957 | 13059 | static int tg3_run_loopback(struct tg3 *tp, u32 pktsz, bool tso_loopback) |
c76949a6 | 13060 | { |
5e5a7f37 | 13061 | u32 rx_start_idx, rx_idx, tx_idx, opaque_key; |
bb158d69 | 13062 | u32 base_flags = 0, mss = 0, desc_idx, coal_now, data_off, val; |
84b67b27 | 13063 | u32 budget; |
9205fd9c ED |
13064 | struct sk_buff *skb; |
13065 | u8 *tx_data, *rx_data; | |
c76949a6 MC |
13066 | dma_addr_t map; |
13067 | int num_pkts, tx_len, rx_len, i, err; | |
13068 | struct tg3_rx_buffer_desc *desc; | |
898a56f8 | 13069 | struct tg3_napi *tnapi, *rnapi; |
8fea32b9 | 13070 | struct tg3_rx_prodring_set *tpr = &tp->napi[0].prodring; |
c76949a6 | 13071 | |
c8873405 MC |
13072 | tnapi = &tp->napi[0]; |
13073 | rnapi = &tp->napi[0]; | |
0c1d0e2b | 13074 | if (tp->irq_cnt > 1) { |
63c3a66f | 13075 | if (tg3_flag(tp, ENABLE_RSS)) |
1da85aa3 | 13076 | rnapi = &tp->napi[1]; |
63c3a66f | 13077 | if (tg3_flag(tp, ENABLE_TSS)) |
c8873405 | 13078 | tnapi = &tp->napi[1]; |
0c1d0e2b | 13079 | } |
fd2ce37f | 13080 | coal_now = tnapi->coal_now | rnapi->coal_now; |
898a56f8 | 13081 | |
c76949a6 MC |
13082 | err = -EIO; |
13083 | ||
4852a861 | 13084 | tx_len = pktsz; |
a20e9c62 | 13085 | skb = netdev_alloc_skb(tp->dev, tx_len); |
a50bb7b9 JJ |
13086 | if (!skb) |
13087 | return -ENOMEM; | |
13088 | ||
c76949a6 MC |
13089 | tx_data = skb_put(skb, tx_len); |
13090 | memcpy(tx_data, tp->dev->dev_addr, 6); | |
13091 | memset(tx_data + 6, 0x0, 8); | |
13092 | ||
4852a861 | 13093 | tw32(MAC_RX_MTU_SIZE, tx_len + ETH_FCS_LEN); |
c76949a6 | 13094 | |
28a45957 | 13095 | if (tso_loopback) { |
bb158d69 MC |
13096 | struct iphdr *iph = (struct iphdr *)&tx_data[ETH_HLEN]; |
13097 | ||
13098 | u32 hdr_len = TG3_TSO_IP_HDR_LEN + TG3_TSO_TCP_HDR_LEN + | |
13099 | TG3_TSO_TCP_OPT_LEN; | |
13100 | ||
13101 | memcpy(tx_data + ETH_ALEN * 2, tg3_tso_header, | |
13102 | sizeof(tg3_tso_header)); | |
13103 | mss = TG3_TSO_MSS; | |
13104 | ||
13105 | val = tx_len - ETH_ALEN * 2 - sizeof(tg3_tso_header); | |
13106 | num_pkts = DIV_ROUND_UP(val, TG3_TSO_MSS); | |
13107 | ||
13108 | /* Set the total length field in the IP header */ | |
13109 | iph->tot_len = htons((u16)(mss + hdr_len)); | |
13110 | ||
13111 | base_flags = (TXD_FLAG_CPU_PRE_DMA | | |
13112 | TXD_FLAG_CPU_POST_DMA); | |
13113 | ||
63c3a66f JP |
13114 | if (tg3_flag(tp, HW_TSO_1) || |
13115 | tg3_flag(tp, HW_TSO_2) || | |
13116 | tg3_flag(tp, HW_TSO_3)) { | |
bb158d69 MC |
13117 | struct tcphdr *th; |
13118 | val = ETH_HLEN + TG3_TSO_IP_HDR_LEN; | |
13119 | th = (struct tcphdr *)&tx_data[val]; | |
13120 | th->check = 0; | |
13121 | } else | |
13122 | base_flags |= TXD_FLAG_TCPUDP_CSUM; | |
13123 | ||
63c3a66f | 13124 | if (tg3_flag(tp, HW_TSO_3)) { |
bb158d69 MC |
13125 | mss |= (hdr_len & 0xc) << 12; |
13126 | if (hdr_len & 0x10) | |
13127 | base_flags |= 0x00000010; | |
13128 | base_flags |= (hdr_len & 0x3e0) << 5; | |
63c3a66f | 13129 | } else if (tg3_flag(tp, HW_TSO_2)) |
bb158d69 | 13130 | mss |= hdr_len << 9; |
63c3a66f | 13131 | else if (tg3_flag(tp, HW_TSO_1) || |
4153577a | 13132 | tg3_asic_rev(tp) == ASIC_REV_5705) { |
bb158d69 MC |
13133 | mss |= (TG3_TSO_TCP_OPT_LEN << 9); |
13134 | } else { | |
13135 | base_flags |= (TG3_TSO_TCP_OPT_LEN << 10); | |
13136 | } | |
13137 | ||
13138 | data_off = ETH_ALEN * 2 + sizeof(tg3_tso_header); | |
13139 | } else { | |
13140 | num_pkts = 1; | |
13141 | data_off = ETH_HLEN; | |
c441b456 MC |
13142 | |
13143 | if (tg3_flag(tp, USE_JUMBO_BDFLAG) && | |
13144 | tx_len > VLAN_ETH_FRAME_LEN) | |
13145 | base_flags |= TXD_FLAG_JMB_PKT; | |
bb158d69 MC |
13146 | } |
13147 | ||
13148 | for (i = data_off; i < tx_len; i++) | |
c76949a6 MC |
13149 | tx_data[i] = (u8) (i & 0xff); |
13150 | ||
f4188d8a AD |
13151 | map = pci_map_single(tp->pdev, skb->data, tx_len, PCI_DMA_TODEVICE); |
13152 | if (pci_dma_mapping_error(tp->pdev, map)) { | |
a21771dd MC |
13153 | dev_kfree_skb(skb); |
13154 | return -EIO; | |
13155 | } | |
c76949a6 | 13156 | |
0d681b27 MC |
13157 | val = tnapi->tx_prod; |
13158 | tnapi->tx_buffers[val].skb = skb; | |
13159 | dma_unmap_addr_set(&tnapi->tx_buffers[val], mapping, map); | |
13160 | ||
c76949a6 | 13161 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
fd2ce37f | 13162 | rnapi->coal_now); |
c76949a6 MC |
13163 | |
13164 | udelay(10); | |
13165 | ||
898a56f8 | 13166 | rx_start_idx = rnapi->hw_status->idx[0].rx_producer; |
c76949a6 | 13167 | |
84b67b27 MC |
13168 | budget = tg3_tx_avail(tnapi); |
13169 | if (tg3_tx_frag_set(tnapi, &val, &budget, map, tx_len, | |
d1a3b737 MC |
13170 | base_flags | TXD_FLAG_END, mss, 0)) { |
13171 | tnapi->tx_buffers[val].skb = NULL; | |
13172 | dev_kfree_skb(skb); | |
13173 | return -EIO; | |
13174 | } | |
c76949a6 | 13175 | |
f3f3f27e | 13176 | tnapi->tx_prod++; |
c76949a6 | 13177 | |
6541b806 MC |
13178 | /* Sync BD data before updating mailbox */ |
13179 | wmb(); | |
13180 | ||
f3f3f27e MC |
13181 | tw32_tx_mbox(tnapi->prodmbox, tnapi->tx_prod); |
13182 | tr32_mailbox(tnapi->prodmbox); | |
c76949a6 MC |
13183 | |
13184 | udelay(10); | |
13185 | ||
303fc921 MC |
13186 | /* 350 usec to allow enough time on some 10/100 Mbps devices. */ |
13187 | for (i = 0; i < 35; i++) { | |
c76949a6 | 13188 | tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE | |
fd2ce37f | 13189 | coal_now); |
c76949a6 MC |
13190 | |
13191 | udelay(10); | |
13192 | ||
898a56f8 MC |
13193 | tx_idx = tnapi->hw_status->idx[0].tx_consumer; |
13194 | rx_idx = rnapi->hw_status->idx[0].rx_producer; | |
f3f3f27e | 13195 | if ((tx_idx == tnapi->tx_prod) && |
c76949a6 MC |
13196 | (rx_idx == (rx_start_idx + num_pkts))) |
13197 | break; | |
13198 | } | |
13199 | ||
ba1142e4 | 13200 | tg3_tx_skb_unmap(tnapi, tnapi->tx_prod - 1, -1); |
c76949a6 MC |
13201 | dev_kfree_skb(skb); |
13202 | ||
f3f3f27e | 13203 | if (tx_idx != tnapi->tx_prod) |
c76949a6 MC |
13204 | goto out; |
13205 | ||
13206 | if (rx_idx != rx_start_idx + num_pkts) | |
13207 | goto out; | |
13208 | ||
bb158d69 MC |
13209 | val = data_off; |
13210 | while (rx_idx != rx_start_idx) { | |
13211 | desc = &rnapi->rx_rcb[rx_start_idx++]; | |
13212 | desc_idx = desc->opaque & RXD_OPAQUE_INDEX_MASK; | |
13213 | opaque_key = desc->opaque & RXD_OPAQUE_RING_MASK; | |
c76949a6 | 13214 | |
bb158d69 MC |
13215 | if ((desc->err_vlan & RXD_ERR_MASK) != 0 && |
13216 | (desc->err_vlan != RXD_ERR_ODD_NIBBLE_RCVD_MII)) | |
13217 | goto out; | |
c76949a6 | 13218 | |
bb158d69 MC |
13219 | rx_len = ((desc->idx_len & RXD_LEN_MASK) >> RXD_LEN_SHIFT) |
13220 | - ETH_FCS_LEN; | |
c76949a6 | 13221 | |
28a45957 | 13222 | if (!tso_loopback) { |
bb158d69 MC |
13223 | if (rx_len != tx_len) |
13224 | goto out; | |
4852a861 | 13225 | |
bb158d69 MC |
13226 | if (pktsz <= TG3_RX_STD_DMA_SZ - ETH_FCS_LEN) { |
13227 | if (opaque_key != RXD_OPAQUE_RING_STD) | |
13228 | goto out; | |
13229 | } else { | |
13230 | if (opaque_key != RXD_OPAQUE_RING_JUMBO) | |
13231 | goto out; | |
13232 | } | |
13233 | } else if ((desc->type_flags & RXD_FLAG_TCPUDP_CSUM) && | |
13234 | (desc->ip_tcp_csum & RXD_TCPCSUM_MASK) | |
54e0a67f | 13235 | >> RXD_TCPCSUM_SHIFT != 0xffff) { |
4852a861 | 13236 | goto out; |
bb158d69 | 13237 | } |
4852a861 | 13238 | |
bb158d69 | 13239 | if (opaque_key == RXD_OPAQUE_RING_STD) { |
9205fd9c | 13240 | rx_data = tpr->rx_std_buffers[desc_idx].data; |
bb158d69 MC |
13241 | map = dma_unmap_addr(&tpr->rx_std_buffers[desc_idx], |
13242 | mapping); | |
13243 | } else if (opaque_key == RXD_OPAQUE_RING_JUMBO) { | |
9205fd9c | 13244 | rx_data = tpr->rx_jmb_buffers[desc_idx].data; |
bb158d69 MC |
13245 | map = dma_unmap_addr(&tpr->rx_jmb_buffers[desc_idx], |
13246 | mapping); | |
13247 | } else | |
13248 | goto out; | |
c76949a6 | 13249 | |
bb158d69 MC |
13250 | pci_dma_sync_single_for_cpu(tp->pdev, map, rx_len, |
13251 | PCI_DMA_FROMDEVICE); | |
c76949a6 | 13252 | |
9205fd9c | 13253 | rx_data += TG3_RX_OFFSET(tp); |
bb158d69 | 13254 | for (i = data_off; i < rx_len; i++, val++) { |
9205fd9c | 13255 | if (*(rx_data + i) != (u8) (val & 0xff)) |
bb158d69 MC |
13256 | goto out; |
13257 | } | |
c76949a6 | 13258 | } |
bb158d69 | 13259 | |
c76949a6 | 13260 | err = 0; |
6aa20a22 | 13261 | |
9205fd9c | 13262 | /* tg3_free_rings will unmap and free the rx_data */ |
c76949a6 MC |
13263 | out: |
13264 | return err; | |
13265 | } | |
13266 | ||
00c266b7 MC |
13267 | #define TG3_STD_LOOPBACK_FAILED 1 |
13268 | #define TG3_JMB_LOOPBACK_FAILED 2 | |
bb158d69 | 13269 | #define TG3_TSO_LOOPBACK_FAILED 4 |
28a45957 MC |
13270 | #define TG3_LOOPBACK_FAILED \ |
13271 | (TG3_STD_LOOPBACK_FAILED | \ | |
13272 | TG3_JMB_LOOPBACK_FAILED | \ | |
13273 | TG3_TSO_LOOPBACK_FAILED) | |
00c266b7 | 13274 | |
941ec90f | 13275 | static int tg3_test_loopback(struct tg3 *tp, u64 *data, bool do_extlpbk) |
9f40dead | 13276 | { |
28a45957 | 13277 | int err = -EIO; |
2215e24c | 13278 | u32 eee_cap; |
c441b456 MC |
13279 | u32 jmb_pkt_sz = 9000; |
13280 | ||
13281 | if (tp->dma_limit) | |
13282 | jmb_pkt_sz = tp->dma_limit - ETH_HLEN; | |
9f40dead | 13283 | |
ab789046 MC |
13284 | eee_cap = tp->phy_flags & TG3_PHYFLG_EEE_CAP; |
13285 | tp->phy_flags &= ~TG3_PHYFLG_EEE_CAP; | |
13286 | ||
28a45957 | 13287 | if (!netif_running(tp->dev)) { |
93df8b8f NNS |
13288 | data[TG3_MAC_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
13289 | data[TG3_PHY_LOOPB_TEST] = TG3_LOOPBACK_FAILED; | |
941ec90f | 13290 | if (do_extlpbk) |
93df8b8f | 13291 | data[TG3_EXT_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
28a45957 MC |
13292 | goto done; |
13293 | } | |
13294 | ||
953c96e0 | 13295 | err = tg3_reset_hw(tp, true); |
ab789046 | 13296 | if (err) { |
93df8b8f NNS |
13297 | data[TG3_MAC_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
13298 | data[TG3_PHY_LOOPB_TEST] = TG3_LOOPBACK_FAILED; | |
941ec90f | 13299 | if (do_extlpbk) |
93df8b8f | 13300 | data[TG3_EXT_LOOPB_TEST] = TG3_LOOPBACK_FAILED; |
ab789046 MC |
13301 | goto done; |
13302 | } | |
9f40dead | 13303 | |
63c3a66f | 13304 | if (tg3_flag(tp, ENABLE_RSS)) { |
4a85f098 MC |
13305 | int i; |
13306 | ||
13307 | /* Reroute all rx packets to the 1st queue */ | |
13308 | for (i = MAC_RSS_INDIR_TBL_0; | |
13309 | i < MAC_RSS_INDIR_TBL_0 + TG3_RSS_INDIR_TBL_SIZE; i += 4) | |
13310 | tw32(i, 0x0); | |
13311 | } | |
13312 | ||
6e01b20b MC |
13313 | /* HW errata - mac loopback fails in some cases on 5780. |
13314 | * Normal traffic and PHY loopback are not affected by | |
13315 | * errata. Also, the MAC loopback test is deprecated for | |
13316 | * all newer ASIC revisions. | |
13317 | */ | |
4153577a | 13318 | if (tg3_asic_rev(tp) != ASIC_REV_5780 && |
6e01b20b MC |
13319 | !tg3_flag(tp, CPMU_PRESENT)) { |
13320 | tg3_mac_loopback(tp, true); | |
9936bcf6 | 13321 | |
28a45957 | 13322 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
93df8b8f | 13323 | data[TG3_MAC_LOOPB_TEST] |= TG3_STD_LOOPBACK_FAILED; |
6e01b20b MC |
13324 | |
13325 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && | |
c441b456 | 13326 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
93df8b8f | 13327 | data[TG3_MAC_LOOPB_TEST] |= TG3_JMB_LOOPBACK_FAILED; |
6e01b20b MC |
13328 | |
13329 | tg3_mac_loopback(tp, false); | |
13330 | } | |
4852a861 | 13331 | |
f07e9af3 | 13332 | if (!(tp->phy_flags & TG3_PHYFLG_PHY_SERDES) && |
63c3a66f | 13333 | !tg3_flag(tp, USE_PHYLIB)) { |
5e5a7f37 MC |
13334 | int i; |
13335 | ||
941ec90f | 13336 | tg3_phy_lpbk_set(tp, 0, false); |
5e5a7f37 MC |
13337 | |
13338 | /* Wait for link */ | |
13339 | for (i = 0; i < 100; i++) { | |
13340 | if (tr32(MAC_TX_STATUS) & TX_STATUS_LINK_UP) | |
13341 | break; | |
13342 | mdelay(1); | |
13343 | } | |
13344 | ||
28a45957 | 13345 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) |
93df8b8f | 13346 | data[TG3_PHY_LOOPB_TEST] |= TG3_STD_LOOPBACK_FAILED; |
63c3a66f | 13347 | if (tg3_flag(tp, TSO_CAPABLE) && |
28a45957 | 13348 | tg3_run_loopback(tp, ETH_FRAME_LEN, true)) |
93df8b8f | 13349 | data[TG3_PHY_LOOPB_TEST] |= TG3_TSO_LOOPBACK_FAILED; |
63c3a66f | 13350 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
c441b456 | 13351 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
93df8b8f | 13352 | data[TG3_PHY_LOOPB_TEST] |= TG3_JMB_LOOPBACK_FAILED; |
9f40dead | 13353 | |
941ec90f MC |
13354 | if (do_extlpbk) { |
13355 | tg3_phy_lpbk_set(tp, 0, true); | |
13356 | ||
13357 | /* All link indications report up, but the hardware | |
13358 | * isn't really ready for about 20 msec. Double it | |
13359 | * to be sure. | |
13360 | */ | |
13361 | mdelay(40); | |
13362 | ||
13363 | if (tg3_run_loopback(tp, ETH_FRAME_LEN, false)) | |
93df8b8f NNS |
13364 | data[TG3_EXT_LOOPB_TEST] |= |
13365 | TG3_STD_LOOPBACK_FAILED; | |
941ec90f MC |
13366 | if (tg3_flag(tp, TSO_CAPABLE) && |
13367 | tg3_run_loopback(tp, ETH_FRAME_LEN, true)) | |
93df8b8f NNS |
13368 | data[TG3_EXT_LOOPB_TEST] |= |
13369 | TG3_TSO_LOOPBACK_FAILED; | |
941ec90f | 13370 | if (tg3_flag(tp, JUMBO_RING_ENABLE) && |
c441b456 | 13371 | tg3_run_loopback(tp, jmb_pkt_sz + ETH_HLEN, false)) |
93df8b8f NNS |
13372 | data[TG3_EXT_LOOPB_TEST] |= |
13373 | TG3_JMB_LOOPBACK_FAILED; | |
941ec90f MC |
13374 | } |
13375 | ||
5e5a7f37 MC |
13376 | /* Re-enable gphy autopowerdown. */ |
13377 | if (tp->phy_flags & TG3_PHYFLG_ENABLE_APD) | |
13378 | tg3_phy_toggle_apd(tp, true); | |
13379 | } | |
6833c043 | 13380 | |
93df8b8f NNS |
13381 | err = (data[TG3_MAC_LOOPB_TEST] | data[TG3_PHY_LOOPB_TEST] | |
13382 | data[TG3_EXT_LOOPB_TEST]) ? -EIO : 0; | |
28a45957 | 13383 | |
ab789046 MC |
13384 | done: |
13385 | tp->phy_flags |= eee_cap; | |
13386 | ||
9f40dead MC |
13387 | return err; |
13388 | } | |
13389 | ||
4cafd3f5 MC |
13390 | static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest, |
13391 | u64 *data) | |
13392 | { | |
566f86ad | 13393 | struct tg3 *tp = netdev_priv(dev); |
941ec90f | 13394 | bool doextlpbk = etest->flags & ETH_TEST_FL_EXTERNAL_LB; |
566f86ad | 13395 | |
bed9829f MC |
13396 | if ((tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) && |
13397 | tg3_power_up(tp)) { | |
13398 | etest->flags |= ETH_TEST_FL_FAILED; | |
13399 | memset(data, 1, sizeof(u64) * TG3_NUM_TEST); | |
13400 | return; | |
13401 | } | |
bc1c7567 | 13402 | |
566f86ad MC |
13403 | memset(data, 0, sizeof(u64) * TG3_NUM_TEST); |
13404 | ||
13405 | if (tg3_test_nvram(tp) != 0) { | |
13406 | etest->flags |= ETH_TEST_FL_FAILED; | |
93df8b8f | 13407 | data[TG3_NVRAM_TEST] = 1; |
566f86ad | 13408 | } |
941ec90f | 13409 | if (!doextlpbk && tg3_test_link(tp)) { |
ca43007a | 13410 | etest->flags |= ETH_TEST_FL_FAILED; |
93df8b8f | 13411 | data[TG3_LINK_TEST] = 1; |
ca43007a | 13412 | } |
a71116d1 | 13413 | if (etest->flags & ETH_TEST_FL_OFFLINE) { |
b02fd9e3 | 13414 | int err, err2 = 0, irq_sync = 0; |
bbe832c0 MC |
13415 | |
13416 | if (netif_running(dev)) { | |
b02fd9e3 | 13417 | tg3_phy_stop(tp); |
a71116d1 | 13418 | tg3_netif_stop(tp); |
bbe832c0 MC |
13419 | irq_sync = 1; |
13420 | } | |
a71116d1 | 13421 | |
bbe832c0 | 13422 | tg3_full_lock(tp, irq_sync); |
a71116d1 | 13423 | tg3_halt(tp, RESET_KIND_SUSPEND, 1); |
ec41c7df | 13424 | err = tg3_nvram_lock(tp); |
a71116d1 | 13425 | tg3_halt_cpu(tp, RX_CPU_BASE); |
63c3a66f | 13426 | if (!tg3_flag(tp, 5705_PLUS)) |
a71116d1 | 13427 | tg3_halt_cpu(tp, TX_CPU_BASE); |
ec41c7df MC |
13428 | if (!err) |
13429 | tg3_nvram_unlock(tp); | |
a71116d1 | 13430 | |
f07e9af3 | 13431 | if (tp->phy_flags & TG3_PHYFLG_MII_SERDES) |
d9ab5ad1 MC |
13432 | tg3_phy_reset(tp); |
13433 | ||
a71116d1 MC |
13434 | if (tg3_test_registers(tp) != 0) { |
13435 | etest->flags |= ETH_TEST_FL_FAILED; | |
93df8b8f | 13436 | data[TG3_REGISTER_TEST] = 1; |
a71116d1 | 13437 | } |
28a45957 | 13438 | |
7942e1db MC |
13439 | if (tg3_test_memory(tp) != 0) { |
13440 | etest->flags |= ETH_TEST_FL_FAILED; | |
93df8b8f | 13441 | data[TG3_MEMORY_TEST] = 1; |
7942e1db | 13442 | } |
28a45957 | 13443 | |
941ec90f MC |
13444 | if (doextlpbk) |
13445 | etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE; | |
13446 | ||
93df8b8f | 13447 | if (tg3_test_loopback(tp, data, doextlpbk)) |
c76949a6 | 13448 | etest->flags |= ETH_TEST_FL_FAILED; |
a71116d1 | 13449 | |
f47c11ee DM |
13450 | tg3_full_unlock(tp); |
13451 | ||
d4bc3927 MC |
13452 | if (tg3_test_interrupt(tp) != 0) { |
13453 | etest->flags |= ETH_TEST_FL_FAILED; | |
93df8b8f | 13454 | data[TG3_INTERRUPT_TEST] = 1; |
d4bc3927 | 13455 | } |
f47c11ee DM |
13456 | |
13457 | tg3_full_lock(tp, 0); | |
d4bc3927 | 13458 | |
a71116d1 MC |
13459 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
13460 | if (netif_running(dev)) { | |
63c3a66f | 13461 | tg3_flag_set(tp, INIT_COMPLETE); |
953c96e0 | 13462 | err2 = tg3_restart_hw(tp, true); |
b02fd9e3 | 13463 | if (!err2) |
b9ec6c1b | 13464 | tg3_netif_start(tp); |
a71116d1 | 13465 | } |
f47c11ee DM |
13466 | |
13467 | tg3_full_unlock(tp); | |
b02fd9e3 MC |
13468 | |
13469 | if (irq_sync && !err2) | |
13470 | tg3_phy_start(tp); | |
a71116d1 | 13471 | } |
80096068 | 13472 | if (tp->phy_flags & TG3_PHYFLG_IS_LOW_POWER) |
c866b7ea | 13473 | tg3_power_down(tp); |
bc1c7567 | 13474 | |
4cafd3f5 MC |
13475 | } |
13476 | ||
0a633ac2 MC |
13477 | static int tg3_hwtstamp_ioctl(struct net_device *dev, |
13478 | struct ifreq *ifr, int cmd) | |
13479 | { | |
13480 | struct tg3 *tp = netdev_priv(dev); | |
13481 | struct hwtstamp_config stmpconf; | |
13482 | ||
13483 | if (!tg3_flag(tp, PTP_CAPABLE)) | |
13484 | return -EINVAL; | |
13485 | ||
13486 | if (copy_from_user(&stmpconf, ifr->ifr_data, sizeof(stmpconf))) | |
13487 | return -EFAULT; | |
13488 | ||
13489 | if (stmpconf.flags) | |
13490 | return -EINVAL; | |
13491 | ||
13492 | switch (stmpconf.tx_type) { | |
13493 | case HWTSTAMP_TX_ON: | |
13494 | tg3_flag_set(tp, TX_TSTAMP_EN); | |
13495 | break; | |
13496 | case HWTSTAMP_TX_OFF: | |
13497 | tg3_flag_clear(tp, TX_TSTAMP_EN); | |
13498 | break; | |
13499 | default: | |
13500 | return -ERANGE; | |
13501 | } | |
13502 | ||
13503 | switch (stmpconf.rx_filter) { | |
13504 | case HWTSTAMP_FILTER_NONE: | |
13505 | tp->rxptpctl = 0; | |
13506 | break; | |
13507 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: | |
13508 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V1_EN | | |
13509 | TG3_RX_PTP_CTL_ALL_V1_EVENTS; | |
13510 | break; | |
13511 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: | |
13512 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V1_EN | | |
13513 | TG3_RX_PTP_CTL_SYNC_EVNT; | |
13514 | break; | |
13515 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: | |
13516 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V1_EN | | |
13517 | TG3_RX_PTP_CTL_DELAY_REQ; | |
13518 | break; | |
13519 | case HWTSTAMP_FILTER_PTP_V2_EVENT: | |
13520 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_EN | | |
13521 | TG3_RX_PTP_CTL_ALL_V2_EVENTS; | |
13522 | break; | |
13523 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: | |
13524 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L2_EN | | |
13525 | TG3_RX_PTP_CTL_ALL_V2_EVENTS; | |
13526 | break; | |
13527 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: | |
13528 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L4_EN | | |
13529 | TG3_RX_PTP_CTL_ALL_V2_EVENTS; | |
13530 | break; | |
13531 | case HWTSTAMP_FILTER_PTP_V2_SYNC: | |
13532 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_EN | | |
13533 | TG3_RX_PTP_CTL_SYNC_EVNT; | |
13534 | break; | |
13535 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: | |
13536 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L2_EN | | |
13537 | TG3_RX_PTP_CTL_SYNC_EVNT; | |
13538 | break; | |
13539 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: | |
13540 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L4_EN | | |
13541 | TG3_RX_PTP_CTL_SYNC_EVNT; | |
13542 | break; | |
13543 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: | |
13544 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_EN | | |
13545 | TG3_RX_PTP_CTL_DELAY_REQ; | |
13546 | break; | |
13547 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: | |
13548 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L2_EN | | |
13549 | TG3_RX_PTP_CTL_DELAY_REQ; | |
13550 | break; | |
13551 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: | |
13552 | tp->rxptpctl = TG3_RX_PTP_CTL_RX_PTP_V2_L4_EN | | |
13553 | TG3_RX_PTP_CTL_DELAY_REQ; | |
13554 | break; | |
13555 | default: | |
13556 | return -ERANGE; | |
13557 | } | |
13558 | ||
13559 | if (netif_running(dev) && tp->rxptpctl) | |
13560 | tw32(TG3_RX_PTP_CTL, | |
13561 | tp->rxptpctl | TG3_RX_PTP_CTL_HWTS_INTERLOCK); | |
13562 | ||
13563 | return copy_to_user(ifr->ifr_data, &stmpconf, sizeof(stmpconf)) ? | |
13564 | -EFAULT : 0; | |
13565 | } | |
13566 | ||
1da177e4 LT |
13567 | static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
13568 | { | |
13569 | struct mii_ioctl_data *data = if_mii(ifr); | |
13570 | struct tg3 *tp = netdev_priv(dev); | |
13571 | int err; | |
13572 | ||
63c3a66f | 13573 | if (tg3_flag(tp, USE_PHYLIB)) { |
3f0e3ad7 | 13574 | struct phy_device *phydev; |
f07e9af3 | 13575 | if (!(tp->phy_flags & TG3_PHYFLG_IS_CONNECTED)) |
b02fd9e3 | 13576 | return -EAGAIN; |
3f0e3ad7 | 13577 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; |
28b04113 | 13578 | return phy_mii_ioctl(phydev, ifr, cmd); |
b02fd9e3 MC |
13579 | } |
13580 | ||
33f401ae | 13581 | switch (cmd) { |
1da177e4 | 13582 | case SIOCGMIIPHY: |
882e9793 | 13583 | data->phy_id = tp->phy_addr; |
1da177e4 LT |
13584 | |
13585 | /* fallthru */ | |
13586 | case SIOCGMIIREG: { | |
13587 | u32 mii_regval; | |
13588 | ||
f07e9af3 | 13589 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
1da177e4 LT |
13590 | break; /* We have no PHY */ |
13591 | ||
34eea5ac | 13592 | if (!netif_running(dev)) |
bc1c7567 MC |
13593 | return -EAGAIN; |
13594 | ||
f47c11ee | 13595 | spin_lock_bh(&tp->lock); |
5c358045 HM |
13596 | err = __tg3_readphy(tp, data->phy_id & 0x1f, |
13597 | data->reg_num & 0x1f, &mii_regval); | |
f47c11ee | 13598 | spin_unlock_bh(&tp->lock); |
1da177e4 LT |
13599 | |
13600 | data->val_out = mii_regval; | |
13601 | ||
13602 | return err; | |
13603 | } | |
13604 | ||
13605 | case SIOCSMIIREG: | |
f07e9af3 | 13606 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
1da177e4 LT |
13607 | break; /* We have no PHY */ |
13608 | ||
34eea5ac | 13609 | if (!netif_running(dev)) |
bc1c7567 MC |
13610 | return -EAGAIN; |
13611 | ||
f47c11ee | 13612 | spin_lock_bh(&tp->lock); |
5c358045 HM |
13613 | err = __tg3_writephy(tp, data->phy_id & 0x1f, |
13614 | data->reg_num & 0x1f, data->val_in); | |
f47c11ee | 13615 | spin_unlock_bh(&tp->lock); |
1da177e4 LT |
13616 | |
13617 | return err; | |
13618 | ||
0a633ac2 MC |
13619 | case SIOCSHWTSTAMP: |
13620 | return tg3_hwtstamp_ioctl(dev, ifr, cmd); | |
13621 | ||
1da177e4 LT |
13622 | default: |
13623 | /* do nothing */ | |
13624 | break; | |
13625 | } | |
13626 | return -EOPNOTSUPP; | |
13627 | } | |
13628 | ||
15f9850d DM |
13629 | static int tg3_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
13630 | { | |
13631 | struct tg3 *tp = netdev_priv(dev); | |
13632 | ||
13633 | memcpy(ec, &tp->coal, sizeof(*ec)); | |
13634 | return 0; | |
13635 | } | |
13636 | ||
d244c892 MC |
13637 | static int tg3_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
13638 | { | |
13639 | struct tg3 *tp = netdev_priv(dev); | |
13640 | u32 max_rxcoal_tick_int = 0, max_txcoal_tick_int = 0; | |
13641 | u32 max_stat_coal_ticks = 0, min_stat_coal_ticks = 0; | |
13642 | ||
63c3a66f | 13643 | if (!tg3_flag(tp, 5705_PLUS)) { |
d244c892 MC |
13644 | max_rxcoal_tick_int = MAX_RXCOAL_TICK_INT; |
13645 | max_txcoal_tick_int = MAX_TXCOAL_TICK_INT; | |
13646 | max_stat_coal_ticks = MAX_STAT_COAL_TICKS; | |
13647 | min_stat_coal_ticks = MIN_STAT_COAL_TICKS; | |
13648 | } | |
13649 | ||
13650 | if ((ec->rx_coalesce_usecs > MAX_RXCOL_TICKS) || | |
13651 | (ec->tx_coalesce_usecs > MAX_TXCOL_TICKS) || | |
13652 | (ec->rx_max_coalesced_frames > MAX_RXMAX_FRAMES) || | |
13653 | (ec->tx_max_coalesced_frames > MAX_TXMAX_FRAMES) || | |
13654 | (ec->rx_coalesce_usecs_irq > max_rxcoal_tick_int) || | |
13655 | (ec->tx_coalesce_usecs_irq > max_txcoal_tick_int) || | |
13656 | (ec->rx_max_coalesced_frames_irq > MAX_RXCOAL_MAXF_INT) || | |
13657 | (ec->tx_max_coalesced_frames_irq > MAX_TXCOAL_MAXF_INT) || | |
13658 | (ec->stats_block_coalesce_usecs > max_stat_coal_ticks) || | |
13659 | (ec->stats_block_coalesce_usecs < min_stat_coal_ticks)) | |
13660 | return -EINVAL; | |
13661 | ||
13662 | /* No rx interrupts will be generated if both are zero */ | |
13663 | if ((ec->rx_coalesce_usecs == 0) && | |
13664 | (ec->rx_max_coalesced_frames == 0)) | |
13665 | return -EINVAL; | |
13666 | ||
13667 | /* No tx interrupts will be generated if both are zero */ | |
13668 | if ((ec->tx_coalesce_usecs == 0) && | |
13669 | (ec->tx_max_coalesced_frames == 0)) | |
13670 | return -EINVAL; | |
13671 | ||
13672 | /* Only copy relevant parameters, ignore all others. */ | |
13673 | tp->coal.rx_coalesce_usecs = ec->rx_coalesce_usecs; | |
13674 | tp->coal.tx_coalesce_usecs = ec->tx_coalesce_usecs; | |
13675 | tp->coal.rx_max_coalesced_frames = ec->rx_max_coalesced_frames; | |
13676 | tp->coal.tx_max_coalesced_frames = ec->tx_max_coalesced_frames; | |
13677 | tp->coal.rx_coalesce_usecs_irq = ec->rx_coalesce_usecs_irq; | |
13678 | tp->coal.tx_coalesce_usecs_irq = ec->tx_coalesce_usecs_irq; | |
13679 | tp->coal.rx_max_coalesced_frames_irq = ec->rx_max_coalesced_frames_irq; | |
13680 | tp->coal.tx_max_coalesced_frames_irq = ec->tx_max_coalesced_frames_irq; | |
13681 | tp->coal.stats_block_coalesce_usecs = ec->stats_block_coalesce_usecs; | |
13682 | ||
13683 | if (netif_running(dev)) { | |
13684 | tg3_full_lock(tp, 0); | |
13685 | __tg3_set_coalesce(tp, &tp->coal); | |
13686 | tg3_full_unlock(tp); | |
13687 | } | |
13688 | return 0; | |
13689 | } | |
13690 | ||
7282d491 | 13691 | static const struct ethtool_ops tg3_ethtool_ops = { |
1da177e4 LT |
13692 | .get_settings = tg3_get_settings, |
13693 | .set_settings = tg3_set_settings, | |
13694 | .get_drvinfo = tg3_get_drvinfo, | |
13695 | .get_regs_len = tg3_get_regs_len, | |
13696 | .get_regs = tg3_get_regs, | |
13697 | .get_wol = tg3_get_wol, | |
13698 | .set_wol = tg3_set_wol, | |
13699 | .get_msglevel = tg3_get_msglevel, | |
13700 | .set_msglevel = tg3_set_msglevel, | |
13701 | .nway_reset = tg3_nway_reset, | |
13702 | .get_link = ethtool_op_get_link, | |
13703 | .get_eeprom_len = tg3_get_eeprom_len, | |
13704 | .get_eeprom = tg3_get_eeprom, | |
13705 | .set_eeprom = tg3_set_eeprom, | |
13706 | .get_ringparam = tg3_get_ringparam, | |
13707 | .set_ringparam = tg3_set_ringparam, | |
13708 | .get_pauseparam = tg3_get_pauseparam, | |
13709 | .set_pauseparam = tg3_set_pauseparam, | |
4cafd3f5 | 13710 | .self_test = tg3_self_test, |
1da177e4 | 13711 | .get_strings = tg3_get_strings, |
81b8709c | 13712 | .set_phys_id = tg3_set_phys_id, |
1da177e4 | 13713 | .get_ethtool_stats = tg3_get_ethtool_stats, |
15f9850d | 13714 | .get_coalesce = tg3_get_coalesce, |
d244c892 | 13715 | .set_coalesce = tg3_set_coalesce, |
b9f2c044 | 13716 | .get_sset_count = tg3_get_sset_count, |
90415477 MC |
13717 | .get_rxnfc = tg3_get_rxnfc, |
13718 | .get_rxfh_indir_size = tg3_get_rxfh_indir_size, | |
13719 | .get_rxfh_indir = tg3_get_rxfh_indir, | |
13720 | .set_rxfh_indir = tg3_set_rxfh_indir, | |
0968169c MC |
13721 | .get_channels = tg3_get_channels, |
13722 | .set_channels = tg3_set_channels, | |
7d41e49a | 13723 | .get_ts_info = tg3_get_ts_info, |
1da177e4 LT |
13724 | }; |
13725 | ||
b4017c53 DM |
13726 | static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *dev, |
13727 | struct rtnl_link_stats64 *stats) | |
13728 | { | |
13729 | struct tg3 *tp = netdev_priv(dev); | |
13730 | ||
0f566b20 MC |
13731 | spin_lock_bh(&tp->lock); |
13732 | if (!tp->hw_stats) { | |
13733 | spin_unlock_bh(&tp->lock); | |
b4017c53 | 13734 | return &tp->net_stats_prev; |
0f566b20 | 13735 | } |
b4017c53 | 13736 | |
b4017c53 DM |
13737 | tg3_get_nstats(tp, stats); |
13738 | spin_unlock_bh(&tp->lock); | |
13739 | ||
13740 | return stats; | |
13741 | } | |
13742 | ||
ccd5ba9d MC |
13743 | static void tg3_set_rx_mode(struct net_device *dev) |
13744 | { | |
13745 | struct tg3 *tp = netdev_priv(dev); | |
13746 | ||
13747 | if (!netif_running(dev)) | |
13748 | return; | |
13749 | ||
13750 | tg3_full_lock(tp, 0); | |
13751 | __tg3_set_rx_mode(dev); | |
13752 | tg3_full_unlock(tp); | |
13753 | } | |
13754 | ||
faf1627a MC |
13755 | static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp, |
13756 | int new_mtu) | |
13757 | { | |
13758 | dev->mtu = new_mtu; | |
13759 | ||
13760 | if (new_mtu > ETH_DATA_LEN) { | |
13761 | if (tg3_flag(tp, 5780_CLASS)) { | |
13762 | netdev_update_features(dev); | |
13763 | tg3_flag_clear(tp, TSO_CAPABLE); | |
13764 | } else { | |
13765 | tg3_flag_set(tp, JUMBO_RING_ENABLE); | |
13766 | } | |
13767 | } else { | |
13768 | if (tg3_flag(tp, 5780_CLASS)) { | |
13769 | tg3_flag_set(tp, TSO_CAPABLE); | |
13770 | netdev_update_features(dev); | |
13771 | } | |
13772 | tg3_flag_clear(tp, JUMBO_RING_ENABLE); | |
13773 | } | |
13774 | } | |
13775 | ||
13776 | static int tg3_change_mtu(struct net_device *dev, int new_mtu) | |
13777 | { | |
13778 | struct tg3 *tp = netdev_priv(dev); | |
953c96e0 JP |
13779 | int err; |
13780 | bool reset_phy = false; | |
faf1627a MC |
13781 | |
13782 | if (new_mtu < TG3_MIN_MTU || new_mtu > TG3_MAX_MTU(tp)) | |
13783 | return -EINVAL; | |
13784 | ||
13785 | if (!netif_running(dev)) { | |
13786 | /* We'll just catch it later when the | |
13787 | * device is up'd. | |
13788 | */ | |
13789 | tg3_set_mtu(dev, tp, new_mtu); | |
13790 | return 0; | |
13791 | } | |
13792 | ||
13793 | tg3_phy_stop(tp); | |
13794 | ||
13795 | tg3_netif_stop(tp); | |
13796 | ||
1c13ac55 NS |
13797 | tg3_set_mtu(dev, tp, new_mtu); |
13798 | ||
faf1627a MC |
13799 | tg3_full_lock(tp, 1); |
13800 | ||
13801 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); | |
13802 | ||
2fae5e36 MC |
13803 | /* Reset PHY, otherwise the read DMA engine will be in a mode that |
13804 | * breaks all requests to 256 bytes. | |
13805 | */ | |
4153577a | 13806 | if (tg3_asic_rev(tp) == ASIC_REV_57766) |
953c96e0 | 13807 | reset_phy = true; |
2fae5e36 MC |
13808 | |
13809 | err = tg3_restart_hw(tp, reset_phy); | |
faf1627a MC |
13810 | |
13811 | if (!err) | |
13812 | tg3_netif_start(tp); | |
13813 | ||
13814 | tg3_full_unlock(tp); | |
13815 | ||
13816 | if (!err) | |
13817 | tg3_phy_start(tp); | |
13818 | ||
13819 | return err; | |
13820 | } | |
13821 | ||
13822 | static const struct net_device_ops tg3_netdev_ops = { | |
13823 | .ndo_open = tg3_open, | |
13824 | .ndo_stop = tg3_close, | |
13825 | .ndo_start_xmit = tg3_start_xmit, | |
13826 | .ndo_get_stats64 = tg3_get_stats64, | |
13827 | .ndo_validate_addr = eth_validate_addr, | |
13828 | .ndo_set_rx_mode = tg3_set_rx_mode, | |
13829 | .ndo_set_mac_address = tg3_set_mac_addr, | |
13830 | .ndo_do_ioctl = tg3_ioctl, | |
13831 | .ndo_tx_timeout = tg3_tx_timeout, | |
13832 | .ndo_change_mtu = tg3_change_mtu, | |
13833 | .ndo_fix_features = tg3_fix_features, | |
13834 | .ndo_set_features = tg3_set_features, | |
13835 | #ifdef CONFIG_NET_POLL_CONTROLLER | |
13836 | .ndo_poll_controller = tg3_poll_controller, | |
13837 | #endif | |
13838 | }; | |
13839 | ||
229b1ad1 | 13840 | static void tg3_get_eeprom_size(struct tg3 *tp) |
1da177e4 | 13841 | { |
1b27777a | 13842 | u32 cursize, val, magic; |
1da177e4 LT |
13843 | |
13844 | tp->nvram_size = EEPROM_CHIP_SIZE; | |
13845 | ||
e4f34110 | 13846 | if (tg3_nvram_read(tp, 0, &magic) != 0) |
1da177e4 LT |
13847 | return; |
13848 | ||
b16250e3 MC |
13849 | if ((magic != TG3_EEPROM_MAGIC) && |
13850 | ((magic & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) && | |
13851 | ((magic & TG3_EEPROM_MAGIC_HW_MSK) != TG3_EEPROM_MAGIC_HW)) | |
1da177e4 LT |
13852 | return; |
13853 | ||
13854 | /* | |
13855 | * Size the chip by reading offsets at increasing powers of two. | |
13856 | * When we encounter our validation signature, we know the addressing | |
13857 | * has wrapped around, and thus have our chip size. | |
13858 | */ | |
1b27777a | 13859 | cursize = 0x10; |
1da177e4 LT |
13860 | |
13861 | while (cursize < tp->nvram_size) { | |
e4f34110 | 13862 | if (tg3_nvram_read(tp, cursize, &val) != 0) |
1da177e4 LT |
13863 | return; |
13864 | ||
1820180b | 13865 | if (val == magic) |
1da177e4 LT |
13866 | break; |
13867 | ||
13868 | cursize <<= 1; | |
13869 | } | |
13870 | ||
13871 | tp->nvram_size = cursize; | |
13872 | } | |
6aa20a22 | 13873 | |
229b1ad1 | 13874 | static void tg3_get_nvram_size(struct tg3 *tp) |
1da177e4 LT |
13875 | { |
13876 | u32 val; | |
13877 | ||
63c3a66f | 13878 | if (tg3_flag(tp, NO_NVRAM) || tg3_nvram_read(tp, 0, &val) != 0) |
1b27777a MC |
13879 | return; |
13880 | ||
13881 | /* Selfboot format */ | |
1820180b | 13882 | if (val != TG3_EEPROM_MAGIC) { |
1b27777a MC |
13883 | tg3_get_eeprom_size(tp); |
13884 | return; | |
13885 | } | |
13886 | ||
6d348f2c | 13887 | if (tg3_nvram_read(tp, 0xf0, &val) == 0) { |
1da177e4 | 13888 | if (val != 0) { |
6d348f2c MC |
13889 | /* This is confusing. We want to operate on the |
13890 | * 16-bit value at offset 0xf2. The tg3_nvram_read() | |
13891 | * call will read from NVRAM and byteswap the data | |
13892 | * according to the byteswapping settings for all | |
13893 | * other register accesses. This ensures the data we | |
13894 | * want will always reside in the lower 16-bits. | |
13895 | * However, the data in NVRAM is in LE format, which | |
13896 | * means the data from the NVRAM read will always be | |
13897 | * opposite the endianness of the CPU. The 16-bit | |
13898 | * byteswap then brings the data to CPU endianness. | |
13899 | */ | |
13900 | tp->nvram_size = swab16((u16)(val & 0x0000ffff)) * 1024; | |
1da177e4 LT |
13901 | return; |
13902 | } | |
13903 | } | |
fd1122a2 | 13904 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; |
1da177e4 LT |
13905 | } |
13906 | ||
229b1ad1 | 13907 | static void tg3_get_nvram_info(struct tg3 *tp) |
1da177e4 LT |
13908 | { |
13909 | u32 nvcfg1; | |
13910 | ||
13911 | nvcfg1 = tr32(NVRAM_CFG1); | |
13912 | if (nvcfg1 & NVRAM_CFG1_FLASHIF_ENAB) { | |
63c3a66f | 13913 | tg3_flag_set(tp, FLASH); |
8590a603 | 13914 | } else { |
1da177e4 LT |
13915 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
13916 | tw32(NVRAM_CFG1, nvcfg1); | |
13917 | } | |
13918 | ||
4153577a | 13919 | if (tg3_asic_rev(tp) == ASIC_REV_5750 || |
63c3a66f | 13920 | tg3_flag(tp, 5780_CLASS)) { |
1da177e4 | 13921 | switch (nvcfg1 & NVRAM_CFG1_VENDOR_MASK) { |
8590a603 MC |
13922 | case FLASH_VENDOR_ATMEL_FLASH_BUFFERED: |
13923 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
13924 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; | |
63c3a66f | 13925 | tg3_flag_set(tp, NVRAM_BUFFERED); |
8590a603 MC |
13926 | break; |
13927 | case FLASH_VENDOR_ATMEL_FLASH_UNBUFFERED: | |
13928 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
13929 | tp->nvram_pagesize = ATMEL_AT25F512_PAGE_SIZE; | |
13930 | break; | |
13931 | case FLASH_VENDOR_ATMEL_EEPROM: | |
13932 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
13933 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; | |
63c3a66f | 13934 | tg3_flag_set(tp, NVRAM_BUFFERED); |
8590a603 MC |
13935 | break; |
13936 | case FLASH_VENDOR_ST: | |
13937 | tp->nvram_jedecnum = JEDEC_ST; | |
13938 | tp->nvram_pagesize = ST_M45PEX0_PAGE_SIZE; | |
63c3a66f | 13939 | tg3_flag_set(tp, NVRAM_BUFFERED); |
8590a603 MC |
13940 | break; |
13941 | case FLASH_VENDOR_SAIFUN: | |
13942 | tp->nvram_jedecnum = JEDEC_SAIFUN; | |
13943 | tp->nvram_pagesize = SAIFUN_SA25F0XX_PAGE_SIZE; | |
13944 | break; | |
13945 | case FLASH_VENDOR_SST_SMALL: | |
13946 | case FLASH_VENDOR_SST_LARGE: | |
13947 | tp->nvram_jedecnum = JEDEC_SST; | |
13948 | tp->nvram_pagesize = SST_25VF0X0_PAGE_SIZE; | |
13949 | break; | |
1da177e4 | 13950 | } |
8590a603 | 13951 | } else { |
1da177e4 LT |
13952 | tp->nvram_jedecnum = JEDEC_ATMEL; |
13953 | tp->nvram_pagesize = ATMEL_AT45DB0X1B_PAGE_SIZE; | |
63c3a66f | 13954 | tg3_flag_set(tp, NVRAM_BUFFERED); |
1da177e4 LT |
13955 | } |
13956 | } | |
13957 | ||
229b1ad1 | 13958 | static void tg3_nvram_get_pagesize(struct tg3 *tp, u32 nvmcfg1) |
a1b950d5 MC |
13959 | { |
13960 | switch (nvmcfg1 & NVRAM_CFG1_5752PAGE_SIZE_MASK) { | |
13961 | case FLASH_5752PAGE_SIZE_256: | |
13962 | tp->nvram_pagesize = 256; | |
13963 | break; | |
13964 | case FLASH_5752PAGE_SIZE_512: | |
13965 | tp->nvram_pagesize = 512; | |
13966 | break; | |
13967 | case FLASH_5752PAGE_SIZE_1K: | |
13968 | tp->nvram_pagesize = 1024; | |
13969 | break; | |
13970 | case FLASH_5752PAGE_SIZE_2K: | |
13971 | tp->nvram_pagesize = 2048; | |
13972 | break; | |
13973 | case FLASH_5752PAGE_SIZE_4K: | |
13974 | tp->nvram_pagesize = 4096; | |
13975 | break; | |
13976 | case FLASH_5752PAGE_SIZE_264: | |
13977 | tp->nvram_pagesize = 264; | |
13978 | break; | |
13979 | case FLASH_5752PAGE_SIZE_528: | |
13980 | tp->nvram_pagesize = 528; | |
13981 | break; | |
13982 | } | |
13983 | } | |
13984 | ||
229b1ad1 | 13985 | static void tg3_get_5752_nvram_info(struct tg3 *tp) |
361b4ac2 MC |
13986 | { |
13987 | u32 nvcfg1; | |
13988 | ||
13989 | nvcfg1 = tr32(NVRAM_CFG1); | |
13990 | ||
e6af301b MC |
13991 | /* NVRAM protection for TPM */ |
13992 | if (nvcfg1 & (1 << 27)) | |
63c3a66f | 13993 | tg3_flag_set(tp, PROTECTED_NVRAM); |
e6af301b | 13994 | |
361b4ac2 | 13995 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { |
8590a603 MC |
13996 | case FLASH_5752VENDOR_ATMEL_EEPROM_64KHZ: |
13997 | case FLASH_5752VENDOR_ATMEL_EEPROM_376KHZ: | |
13998 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 13999 | tg3_flag_set(tp, NVRAM_BUFFERED); |
8590a603 MC |
14000 | break; |
14001 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: | |
14002 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
14003 | tg3_flag_set(tp, NVRAM_BUFFERED); |
14004 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
14005 | break; |
14006 | case FLASH_5752VENDOR_ST_M45PE10: | |
14007 | case FLASH_5752VENDOR_ST_M45PE20: | |
14008 | case FLASH_5752VENDOR_ST_M45PE40: | |
14009 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
14010 | tg3_flag_set(tp, NVRAM_BUFFERED); |
14011 | tg3_flag_set(tp, FLASH); | |
8590a603 | 14012 | break; |
361b4ac2 MC |
14013 | } |
14014 | ||
63c3a66f | 14015 | if (tg3_flag(tp, FLASH)) { |
a1b950d5 | 14016 | tg3_nvram_get_pagesize(tp, nvcfg1); |
8590a603 | 14017 | } else { |
361b4ac2 MC |
14018 | /* For eeprom, set pagesize to maximum eeprom size */ |
14019 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; | |
14020 | ||
14021 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; | |
14022 | tw32(NVRAM_CFG1, nvcfg1); | |
14023 | } | |
14024 | } | |
14025 | ||
229b1ad1 | 14026 | static void tg3_get_5755_nvram_info(struct tg3 *tp) |
d3c7b886 | 14027 | { |
989a9d23 | 14028 | u32 nvcfg1, protect = 0; |
d3c7b886 MC |
14029 | |
14030 | nvcfg1 = tr32(NVRAM_CFG1); | |
14031 | ||
14032 | /* NVRAM protection for TPM */ | |
989a9d23 | 14033 | if (nvcfg1 & (1 << 27)) { |
63c3a66f | 14034 | tg3_flag_set(tp, PROTECTED_NVRAM); |
989a9d23 MC |
14035 | protect = 1; |
14036 | } | |
d3c7b886 | 14037 | |
989a9d23 MC |
14038 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; |
14039 | switch (nvcfg1) { | |
8590a603 MC |
14040 | case FLASH_5755VENDOR_ATMEL_FLASH_1: |
14041 | case FLASH_5755VENDOR_ATMEL_FLASH_2: | |
14042 | case FLASH_5755VENDOR_ATMEL_FLASH_3: | |
14043 | case FLASH_5755VENDOR_ATMEL_FLASH_5: | |
14044 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
14045 | tg3_flag_set(tp, NVRAM_BUFFERED); |
14046 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
14047 | tp->nvram_pagesize = 264; |
14048 | if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_1 || | |
14049 | nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_5) | |
14050 | tp->nvram_size = (protect ? 0x3e200 : | |
14051 | TG3_NVRAM_SIZE_512KB); | |
14052 | else if (nvcfg1 == FLASH_5755VENDOR_ATMEL_FLASH_2) | |
14053 | tp->nvram_size = (protect ? 0x1f200 : | |
14054 | TG3_NVRAM_SIZE_256KB); | |
14055 | else | |
14056 | tp->nvram_size = (protect ? 0x1f200 : | |
14057 | TG3_NVRAM_SIZE_128KB); | |
14058 | break; | |
14059 | case FLASH_5752VENDOR_ST_M45PE10: | |
14060 | case FLASH_5752VENDOR_ST_M45PE20: | |
14061 | case FLASH_5752VENDOR_ST_M45PE40: | |
14062 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
14063 | tg3_flag_set(tp, NVRAM_BUFFERED); |
14064 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
14065 | tp->nvram_pagesize = 256; |
14066 | if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE10) | |
14067 | tp->nvram_size = (protect ? | |
14068 | TG3_NVRAM_SIZE_64KB : | |
14069 | TG3_NVRAM_SIZE_128KB); | |
14070 | else if (nvcfg1 == FLASH_5752VENDOR_ST_M45PE20) | |
14071 | tp->nvram_size = (protect ? | |
14072 | TG3_NVRAM_SIZE_64KB : | |
14073 | TG3_NVRAM_SIZE_256KB); | |
14074 | else | |
14075 | tp->nvram_size = (protect ? | |
14076 | TG3_NVRAM_SIZE_128KB : | |
14077 | TG3_NVRAM_SIZE_512KB); | |
14078 | break; | |
d3c7b886 MC |
14079 | } |
14080 | } | |
14081 | ||
229b1ad1 | 14082 | static void tg3_get_5787_nvram_info(struct tg3 *tp) |
1b27777a MC |
14083 | { |
14084 | u32 nvcfg1; | |
14085 | ||
14086 | nvcfg1 = tr32(NVRAM_CFG1); | |
14087 | ||
14088 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
8590a603 MC |
14089 | case FLASH_5787VENDOR_ATMEL_EEPROM_64KHZ: |
14090 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: | |
14091 | case FLASH_5787VENDOR_MICRO_EEPROM_64KHZ: | |
14092 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: | |
14093 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 14094 | tg3_flag_set(tp, NVRAM_BUFFERED); |
8590a603 | 14095 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
1b27777a | 14096 | |
8590a603 MC |
14097 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; |
14098 | tw32(NVRAM_CFG1, nvcfg1); | |
14099 | break; | |
14100 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: | |
14101 | case FLASH_5755VENDOR_ATMEL_FLASH_1: | |
14102 | case FLASH_5755VENDOR_ATMEL_FLASH_2: | |
14103 | case FLASH_5755VENDOR_ATMEL_FLASH_3: | |
14104 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
14105 | tg3_flag_set(tp, NVRAM_BUFFERED); |
14106 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
14107 | tp->nvram_pagesize = 264; |
14108 | break; | |
14109 | case FLASH_5752VENDOR_ST_M45PE10: | |
14110 | case FLASH_5752VENDOR_ST_M45PE20: | |
14111 | case FLASH_5752VENDOR_ST_M45PE40: | |
14112 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
14113 | tg3_flag_set(tp, NVRAM_BUFFERED); |
14114 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
14115 | tp->nvram_pagesize = 256; |
14116 | break; | |
1b27777a MC |
14117 | } |
14118 | } | |
14119 | ||
229b1ad1 | 14120 | static void tg3_get_5761_nvram_info(struct tg3 *tp) |
6b91fa02 MC |
14121 | { |
14122 | u32 nvcfg1, protect = 0; | |
14123 | ||
14124 | nvcfg1 = tr32(NVRAM_CFG1); | |
14125 | ||
14126 | /* NVRAM protection for TPM */ | |
14127 | if (nvcfg1 & (1 << 27)) { | |
63c3a66f | 14128 | tg3_flag_set(tp, PROTECTED_NVRAM); |
6b91fa02 MC |
14129 | protect = 1; |
14130 | } | |
14131 | ||
14132 | nvcfg1 &= NVRAM_CFG1_5752VENDOR_MASK; | |
14133 | switch (nvcfg1) { | |
8590a603 MC |
14134 | case FLASH_5761VENDOR_ATMEL_ADB021D: |
14135 | case FLASH_5761VENDOR_ATMEL_ADB041D: | |
14136 | case FLASH_5761VENDOR_ATMEL_ADB081D: | |
14137 | case FLASH_5761VENDOR_ATMEL_ADB161D: | |
14138 | case FLASH_5761VENDOR_ATMEL_MDB021D: | |
14139 | case FLASH_5761VENDOR_ATMEL_MDB041D: | |
14140 | case FLASH_5761VENDOR_ATMEL_MDB081D: | |
14141 | case FLASH_5761VENDOR_ATMEL_MDB161D: | |
14142 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
14143 | tg3_flag_set(tp, NVRAM_BUFFERED); |
14144 | tg3_flag_set(tp, FLASH); | |
14145 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); | |
8590a603 MC |
14146 | tp->nvram_pagesize = 256; |
14147 | break; | |
14148 | case FLASH_5761VENDOR_ST_A_M45PE20: | |
14149 | case FLASH_5761VENDOR_ST_A_M45PE40: | |
14150 | case FLASH_5761VENDOR_ST_A_M45PE80: | |
14151 | case FLASH_5761VENDOR_ST_A_M45PE16: | |
14152 | case FLASH_5761VENDOR_ST_M_M45PE20: | |
14153 | case FLASH_5761VENDOR_ST_M_M45PE40: | |
14154 | case FLASH_5761VENDOR_ST_M_M45PE80: | |
14155 | case FLASH_5761VENDOR_ST_M_M45PE16: | |
14156 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
14157 | tg3_flag_set(tp, NVRAM_BUFFERED); |
14158 | tg3_flag_set(tp, FLASH); | |
8590a603 MC |
14159 | tp->nvram_pagesize = 256; |
14160 | break; | |
6b91fa02 MC |
14161 | } |
14162 | ||
14163 | if (protect) { | |
14164 | tp->nvram_size = tr32(NVRAM_ADDR_LOCKOUT); | |
14165 | } else { | |
14166 | switch (nvcfg1) { | |
8590a603 MC |
14167 | case FLASH_5761VENDOR_ATMEL_ADB161D: |
14168 | case FLASH_5761VENDOR_ATMEL_MDB161D: | |
14169 | case FLASH_5761VENDOR_ST_A_M45PE16: | |
14170 | case FLASH_5761VENDOR_ST_M_M45PE16: | |
14171 | tp->nvram_size = TG3_NVRAM_SIZE_2MB; | |
14172 | break; | |
14173 | case FLASH_5761VENDOR_ATMEL_ADB081D: | |
14174 | case FLASH_5761VENDOR_ATMEL_MDB081D: | |
14175 | case FLASH_5761VENDOR_ST_A_M45PE80: | |
14176 | case FLASH_5761VENDOR_ST_M_M45PE80: | |
14177 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; | |
14178 | break; | |
14179 | case FLASH_5761VENDOR_ATMEL_ADB041D: | |
14180 | case FLASH_5761VENDOR_ATMEL_MDB041D: | |
14181 | case FLASH_5761VENDOR_ST_A_M45PE40: | |
14182 | case FLASH_5761VENDOR_ST_M_M45PE40: | |
14183 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
14184 | break; | |
14185 | case FLASH_5761VENDOR_ATMEL_ADB021D: | |
14186 | case FLASH_5761VENDOR_ATMEL_MDB021D: | |
14187 | case FLASH_5761VENDOR_ST_A_M45PE20: | |
14188 | case FLASH_5761VENDOR_ST_M_M45PE20: | |
14189 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
14190 | break; | |
6b91fa02 MC |
14191 | } |
14192 | } | |
14193 | } | |
14194 | ||
229b1ad1 | 14195 | static void tg3_get_5906_nvram_info(struct tg3 *tp) |
b5d3772c MC |
14196 | { |
14197 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 14198 | tg3_flag_set(tp, NVRAM_BUFFERED); |
b5d3772c MC |
14199 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
14200 | } | |
14201 | ||
229b1ad1 | 14202 | static void tg3_get_57780_nvram_info(struct tg3 *tp) |
321d32a0 MC |
14203 | { |
14204 | u32 nvcfg1; | |
14205 | ||
14206 | nvcfg1 = tr32(NVRAM_CFG1); | |
14207 | ||
14208 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
14209 | case FLASH_5787VENDOR_ATMEL_EEPROM_376KHZ: | |
14210 | case FLASH_5787VENDOR_MICRO_EEPROM_376KHZ: | |
14211 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 14212 | tg3_flag_set(tp, NVRAM_BUFFERED); |
321d32a0 MC |
14213 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
14214 | ||
14215 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; | |
14216 | tw32(NVRAM_CFG1, nvcfg1); | |
14217 | return; | |
14218 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: | |
14219 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: | |
14220 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: | |
14221 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: | |
14222 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: | |
14223 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: | |
14224 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: | |
14225 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
14226 | tg3_flag_set(tp, NVRAM_BUFFERED); |
14227 | tg3_flag_set(tp, FLASH); | |
321d32a0 MC |
14228 | |
14229 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
14230 | case FLASH_5752VENDOR_ATMEL_FLASH_BUFFERED: | |
14231 | case FLASH_57780VENDOR_ATMEL_AT45DB011D: | |
14232 | case FLASH_57780VENDOR_ATMEL_AT45DB011B: | |
14233 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
14234 | break; | |
14235 | case FLASH_57780VENDOR_ATMEL_AT45DB021D: | |
14236 | case FLASH_57780VENDOR_ATMEL_AT45DB021B: | |
14237 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
14238 | break; | |
14239 | case FLASH_57780VENDOR_ATMEL_AT45DB041D: | |
14240 | case FLASH_57780VENDOR_ATMEL_AT45DB041B: | |
14241 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
14242 | break; | |
14243 | } | |
14244 | break; | |
14245 | case FLASH_5752VENDOR_ST_M45PE10: | |
14246 | case FLASH_5752VENDOR_ST_M45PE20: | |
14247 | case FLASH_5752VENDOR_ST_M45PE40: | |
14248 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
14249 | tg3_flag_set(tp, NVRAM_BUFFERED); |
14250 | tg3_flag_set(tp, FLASH); | |
321d32a0 MC |
14251 | |
14252 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
14253 | case FLASH_5752VENDOR_ST_M45PE10: | |
14254 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
14255 | break; | |
14256 | case FLASH_5752VENDOR_ST_M45PE20: | |
14257 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
14258 | break; | |
14259 | case FLASH_5752VENDOR_ST_M45PE40: | |
14260 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
14261 | break; | |
14262 | } | |
14263 | break; | |
14264 | default: | |
63c3a66f | 14265 | tg3_flag_set(tp, NO_NVRAM); |
321d32a0 MC |
14266 | return; |
14267 | } | |
14268 | ||
a1b950d5 MC |
14269 | tg3_nvram_get_pagesize(tp, nvcfg1); |
14270 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) | |
63c3a66f | 14271 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
a1b950d5 MC |
14272 | } |
14273 | ||
14274 | ||
229b1ad1 | 14275 | static void tg3_get_5717_nvram_info(struct tg3 *tp) |
a1b950d5 MC |
14276 | { |
14277 | u32 nvcfg1; | |
14278 | ||
14279 | nvcfg1 = tr32(NVRAM_CFG1); | |
14280 | ||
14281 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
14282 | case FLASH_5717VENDOR_ATMEL_EEPROM: | |
14283 | case FLASH_5717VENDOR_MICRO_EEPROM: | |
14284 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 14285 | tg3_flag_set(tp, NVRAM_BUFFERED); |
a1b950d5 MC |
14286 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; |
14287 | ||
14288 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; | |
14289 | tw32(NVRAM_CFG1, nvcfg1); | |
14290 | return; | |
14291 | case FLASH_5717VENDOR_ATMEL_MDB011D: | |
14292 | case FLASH_5717VENDOR_ATMEL_ADB011B: | |
14293 | case FLASH_5717VENDOR_ATMEL_ADB011D: | |
14294 | case FLASH_5717VENDOR_ATMEL_MDB021D: | |
14295 | case FLASH_5717VENDOR_ATMEL_ADB021B: | |
14296 | case FLASH_5717VENDOR_ATMEL_ADB021D: | |
14297 | case FLASH_5717VENDOR_ATMEL_45USPT: | |
14298 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
14299 | tg3_flag_set(tp, NVRAM_BUFFERED); |
14300 | tg3_flag_set(tp, FLASH); | |
a1b950d5 MC |
14301 | |
14302 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
14303 | case FLASH_5717VENDOR_ATMEL_MDB021D: | |
66ee33bf MC |
14304 | /* Detect size with tg3_nvram_get_size() */ |
14305 | break; | |
a1b950d5 MC |
14306 | case FLASH_5717VENDOR_ATMEL_ADB021B: |
14307 | case FLASH_5717VENDOR_ATMEL_ADB021D: | |
14308 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
14309 | break; | |
14310 | default: | |
14311 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
14312 | break; | |
14313 | } | |
321d32a0 | 14314 | break; |
a1b950d5 MC |
14315 | case FLASH_5717VENDOR_ST_M_M25PE10: |
14316 | case FLASH_5717VENDOR_ST_A_M25PE10: | |
14317 | case FLASH_5717VENDOR_ST_M_M45PE10: | |
14318 | case FLASH_5717VENDOR_ST_A_M45PE10: | |
14319 | case FLASH_5717VENDOR_ST_M_M25PE20: | |
14320 | case FLASH_5717VENDOR_ST_A_M25PE20: | |
14321 | case FLASH_5717VENDOR_ST_M_M45PE20: | |
14322 | case FLASH_5717VENDOR_ST_A_M45PE20: | |
14323 | case FLASH_5717VENDOR_ST_25USPT: | |
14324 | case FLASH_5717VENDOR_ST_45USPT: | |
14325 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
14326 | tg3_flag_set(tp, NVRAM_BUFFERED); |
14327 | tg3_flag_set(tp, FLASH); | |
a1b950d5 MC |
14328 | |
14329 | switch (nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK) { | |
14330 | case FLASH_5717VENDOR_ST_M_M25PE20: | |
a1b950d5 | 14331 | case FLASH_5717VENDOR_ST_M_M45PE20: |
66ee33bf MC |
14332 | /* Detect size with tg3_nvram_get_size() */ |
14333 | break; | |
14334 | case FLASH_5717VENDOR_ST_A_M25PE20: | |
a1b950d5 MC |
14335 | case FLASH_5717VENDOR_ST_A_M45PE20: |
14336 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
14337 | break; | |
14338 | default: | |
14339 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; | |
14340 | break; | |
14341 | } | |
321d32a0 | 14342 | break; |
a1b950d5 | 14343 | default: |
63c3a66f | 14344 | tg3_flag_set(tp, NO_NVRAM); |
a1b950d5 | 14345 | return; |
321d32a0 | 14346 | } |
a1b950d5 MC |
14347 | |
14348 | tg3_nvram_get_pagesize(tp, nvcfg1); | |
14349 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) | |
63c3a66f | 14350 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
321d32a0 MC |
14351 | } |
14352 | ||
229b1ad1 | 14353 | static void tg3_get_5720_nvram_info(struct tg3 *tp) |
9b91b5f1 MC |
14354 | { |
14355 | u32 nvcfg1, nvmpinstrp; | |
14356 | ||
14357 | nvcfg1 = tr32(NVRAM_CFG1); | |
14358 | nvmpinstrp = nvcfg1 & NVRAM_CFG1_5752VENDOR_MASK; | |
14359 | ||
4153577a | 14360 | if (tg3_asic_rev(tp) == ASIC_REV_5762) { |
c86a8560 MC |
14361 | if (!(nvcfg1 & NVRAM_CFG1_5762VENDOR_MASK)) { |
14362 | tg3_flag_set(tp, NO_NVRAM); | |
14363 | return; | |
14364 | } | |
14365 | ||
14366 | switch (nvmpinstrp) { | |
14367 | case FLASH_5762_EEPROM_HD: | |
14368 | nvmpinstrp = FLASH_5720_EEPROM_HD; | |
17e1a42f | 14369 | break; |
c86a8560 MC |
14370 | case FLASH_5762_EEPROM_LD: |
14371 | nvmpinstrp = FLASH_5720_EEPROM_LD; | |
17e1a42f | 14372 | break; |
f6334bb8 MC |
14373 | case FLASH_5720VENDOR_M_ST_M45PE20: |
14374 | /* This pinstrap supports multiple sizes, so force it | |
14375 | * to read the actual size from location 0xf0. | |
14376 | */ | |
14377 | nvmpinstrp = FLASH_5720VENDOR_ST_45USPT; | |
14378 | break; | |
c86a8560 MC |
14379 | } |
14380 | } | |
14381 | ||
9b91b5f1 MC |
14382 | switch (nvmpinstrp) { |
14383 | case FLASH_5720_EEPROM_HD: | |
14384 | case FLASH_5720_EEPROM_LD: | |
14385 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f | 14386 | tg3_flag_set(tp, NVRAM_BUFFERED); |
9b91b5f1 MC |
14387 | |
14388 | nvcfg1 &= ~NVRAM_CFG1_COMPAT_BYPASS; | |
14389 | tw32(NVRAM_CFG1, nvcfg1); | |
14390 | if (nvmpinstrp == FLASH_5720_EEPROM_HD) | |
14391 | tp->nvram_pagesize = ATMEL_AT24C512_CHIP_SIZE; | |
14392 | else | |
14393 | tp->nvram_pagesize = ATMEL_AT24C02_CHIP_SIZE; | |
14394 | return; | |
14395 | case FLASH_5720VENDOR_M_ATMEL_DB011D: | |
14396 | case FLASH_5720VENDOR_A_ATMEL_DB011B: | |
14397 | case FLASH_5720VENDOR_A_ATMEL_DB011D: | |
14398 | case FLASH_5720VENDOR_M_ATMEL_DB021D: | |
14399 | case FLASH_5720VENDOR_A_ATMEL_DB021B: | |
14400 | case FLASH_5720VENDOR_A_ATMEL_DB021D: | |
14401 | case FLASH_5720VENDOR_M_ATMEL_DB041D: | |
14402 | case FLASH_5720VENDOR_A_ATMEL_DB041B: | |
14403 | case FLASH_5720VENDOR_A_ATMEL_DB041D: | |
14404 | case FLASH_5720VENDOR_M_ATMEL_DB081D: | |
14405 | case FLASH_5720VENDOR_A_ATMEL_DB081D: | |
14406 | case FLASH_5720VENDOR_ATMEL_45USPT: | |
14407 | tp->nvram_jedecnum = JEDEC_ATMEL; | |
63c3a66f JP |
14408 | tg3_flag_set(tp, NVRAM_BUFFERED); |
14409 | tg3_flag_set(tp, FLASH); | |
9b91b5f1 MC |
14410 | |
14411 | switch (nvmpinstrp) { | |
14412 | case FLASH_5720VENDOR_M_ATMEL_DB021D: | |
14413 | case FLASH_5720VENDOR_A_ATMEL_DB021B: | |
14414 | case FLASH_5720VENDOR_A_ATMEL_DB021D: | |
14415 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
14416 | break; | |
14417 | case FLASH_5720VENDOR_M_ATMEL_DB041D: | |
14418 | case FLASH_5720VENDOR_A_ATMEL_DB041B: | |
14419 | case FLASH_5720VENDOR_A_ATMEL_DB041D: | |
14420 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
14421 | break; | |
14422 | case FLASH_5720VENDOR_M_ATMEL_DB081D: | |
14423 | case FLASH_5720VENDOR_A_ATMEL_DB081D: | |
14424 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; | |
14425 | break; | |
14426 | default: | |
4153577a | 14427 | if (tg3_asic_rev(tp) != ASIC_REV_5762) |
c5d0b72e | 14428 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
9b91b5f1 MC |
14429 | break; |
14430 | } | |
14431 | break; | |
14432 | case FLASH_5720VENDOR_M_ST_M25PE10: | |
14433 | case FLASH_5720VENDOR_M_ST_M45PE10: | |
14434 | case FLASH_5720VENDOR_A_ST_M25PE10: | |
14435 | case FLASH_5720VENDOR_A_ST_M45PE10: | |
14436 | case FLASH_5720VENDOR_M_ST_M25PE20: | |
14437 | case FLASH_5720VENDOR_M_ST_M45PE20: | |
14438 | case FLASH_5720VENDOR_A_ST_M25PE20: | |
14439 | case FLASH_5720VENDOR_A_ST_M45PE20: | |
14440 | case FLASH_5720VENDOR_M_ST_M25PE40: | |
14441 | case FLASH_5720VENDOR_M_ST_M45PE40: | |
14442 | case FLASH_5720VENDOR_A_ST_M25PE40: | |
14443 | case FLASH_5720VENDOR_A_ST_M45PE40: | |
14444 | case FLASH_5720VENDOR_M_ST_M25PE80: | |
14445 | case FLASH_5720VENDOR_M_ST_M45PE80: | |
14446 | case FLASH_5720VENDOR_A_ST_M25PE80: | |
14447 | case FLASH_5720VENDOR_A_ST_M45PE80: | |
14448 | case FLASH_5720VENDOR_ST_25USPT: | |
14449 | case FLASH_5720VENDOR_ST_45USPT: | |
14450 | tp->nvram_jedecnum = JEDEC_ST; | |
63c3a66f JP |
14451 | tg3_flag_set(tp, NVRAM_BUFFERED); |
14452 | tg3_flag_set(tp, FLASH); | |
9b91b5f1 MC |
14453 | |
14454 | switch (nvmpinstrp) { | |
14455 | case FLASH_5720VENDOR_M_ST_M25PE20: | |
14456 | case FLASH_5720VENDOR_M_ST_M45PE20: | |
14457 | case FLASH_5720VENDOR_A_ST_M25PE20: | |
14458 | case FLASH_5720VENDOR_A_ST_M45PE20: | |
14459 | tp->nvram_size = TG3_NVRAM_SIZE_256KB; | |
14460 | break; | |
14461 | case FLASH_5720VENDOR_M_ST_M25PE40: | |
14462 | case FLASH_5720VENDOR_M_ST_M45PE40: | |
14463 | case FLASH_5720VENDOR_A_ST_M25PE40: | |
14464 | case FLASH_5720VENDOR_A_ST_M45PE40: | |
14465 | tp->nvram_size = TG3_NVRAM_SIZE_512KB; | |
14466 | break; | |
14467 | case FLASH_5720VENDOR_M_ST_M25PE80: | |
14468 | case FLASH_5720VENDOR_M_ST_M45PE80: | |
14469 | case FLASH_5720VENDOR_A_ST_M25PE80: | |
14470 | case FLASH_5720VENDOR_A_ST_M45PE80: | |
14471 | tp->nvram_size = TG3_NVRAM_SIZE_1MB; | |
14472 | break; | |
14473 | default: | |
4153577a | 14474 | if (tg3_asic_rev(tp) != ASIC_REV_5762) |
c5d0b72e | 14475 | tp->nvram_size = TG3_NVRAM_SIZE_128KB; |
9b91b5f1 MC |
14476 | break; |
14477 | } | |
14478 | break; | |
14479 | default: | |
63c3a66f | 14480 | tg3_flag_set(tp, NO_NVRAM); |
9b91b5f1 MC |
14481 | return; |
14482 | } | |
14483 | ||
14484 | tg3_nvram_get_pagesize(tp, nvcfg1); | |
14485 | if (tp->nvram_pagesize != 264 && tp->nvram_pagesize != 528) | |
63c3a66f | 14486 | tg3_flag_set(tp, NO_NVRAM_ADDR_TRANS); |
c86a8560 | 14487 | |
4153577a | 14488 | if (tg3_asic_rev(tp) == ASIC_REV_5762) { |
c86a8560 MC |
14489 | u32 val; |
14490 | ||
14491 | if (tg3_nvram_read(tp, 0, &val)) | |
14492 | return; | |
14493 | ||
14494 | if (val != TG3_EEPROM_MAGIC && | |
14495 | (val & TG3_EEPROM_MAGIC_FW_MSK) != TG3_EEPROM_MAGIC_FW) | |
14496 | tg3_flag_set(tp, NO_NVRAM); | |
14497 | } | |
9b91b5f1 MC |
14498 | } |
14499 | ||
1da177e4 | 14500 | /* Chips other than 5700/5701 use the NVRAM for fetching info. */ |
229b1ad1 | 14501 | static void tg3_nvram_init(struct tg3 *tp) |
1da177e4 | 14502 | { |
7e6c63f0 HM |
14503 | if (tg3_flag(tp, IS_SSB_CORE)) { |
14504 | /* No NVRAM and EEPROM on the SSB Broadcom GigE core. */ | |
14505 | tg3_flag_clear(tp, NVRAM); | |
14506 | tg3_flag_clear(tp, NVRAM_BUFFERED); | |
14507 | tg3_flag_set(tp, NO_NVRAM); | |
14508 | return; | |
14509 | } | |
14510 | ||
1da177e4 LT |
14511 | tw32_f(GRC_EEPROM_ADDR, |
14512 | (EEPROM_ADDR_FSM_RESET | | |
14513 | (EEPROM_DEFAULT_CLOCK_PERIOD << | |
14514 | EEPROM_ADDR_CLKPERD_SHIFT))); | |
14515 | ||
9d57f01c | 14516 | msleep(1); |
1da177e4 LT |
14517 | |
14518 | /* Enable seeprom accesses. */ | |
14519 | tw32_f(GRC_LOCAL_CTRL, | |
14520 | tr32(GRC_LOCAL_CTRL) | GRC_LCLCTRL_AUTO_SEEPROM); | |
14521 | udelay(100); | |
14522 | ||
4153577a JP |
14523 | if (tg3_asic_rev(tp) != ASIC_REV_5700 && |
14524 | tg3_asic_rev(tp) != ASIC_REV_5701) { | |
63c3a66f | 14525 | tg3_flag_set(tp, NVRAM); |
1da177e4 | 14526 | |
ec41c7df | 14527 | if (tg3_nvram_lock(tp)) { |
5129c3a3 MC |
14528 | netdev_warn(tp->dev, |
14529 | "Cannot get nvram lock, %s failed\n", | |
05dbe005 | 14530 | __func__); |
ec41c7df MC |
14531 | return; |
14532 | } | |
e6af301b | 14533 | tg3_enable_nvram_access(tp); |
1da177e4 | 14534 | |
989a9d23 MC |
14535 | tp->nvram_size = 0; |
14536 | ||
4153577a | 14537 | if (tg3_asic_rev(tp) == ASIC_REV_5752) |
361b4ac2 | 14538 | tg3_get_5752_nvram_info(tp); |
4153577a | 14539 | else if (tg3_asic_rev(tp) == ASIC_REV_5755) |
d3c7b886 | 14540 | tg3_get_5755_nvram_info(tp); |
4153577a JP |
14541 | else if (tg3_asic_rev(tp) == ASIC_REV_5787 || |
14542 | tg3_asic_rev(tp) == ASIC_REV_5784 || | |
14543 | tg3_asic_rev(tp) == ASIC_REV_5785) | |
1b27777a | 14544 | tg3_get_5787_nvram_info(tp); |
4153577a | 14545 | else if (tg3_asic_rev(tp) == ASIC_REV_5761) |
6b91fa02 | 14546 | tg3_get_5761_nvram_info(tp); |
4153577a | 14547 | else if (tg3_asic_rev(tp) == ASIC_REV_5906) |
b5d3772c | 14548 | tg3_get_5906_nvram_info(tp); |
4153577a | 14549 | else if (tg3_asic_rev(tp) == ASIC_REV_57780 || |
55086ad9 | 14550 | tg3_flag(tp, 57765_CLASS)) |
321d32a0 | 14551 | tg3_get_57780_nvram_info(tp); |
4153577a JP |
14552 | else if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
14553 | tg3_asic_rev(tp) == ASIC_REV_5719) | |
a1b950d5 | 14554 | tg3_get_5717_nvram_info(tp); |
4153577a JP |
14555 | else if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
14556 | tg3_asic_rev(tp) == ASIC_REV_5762) | |
9b91b5f1 | 14557 | tg3_get_5720_nvram_info(tp); |
361b4ac2 MC |
14558 | else |
14559 | tg3_get_nvram_info(tp); | |
14560 | ||
989a9d23 MC |
14561 | if (tp->nvram_size == 0) |
14562 | tg3_get_nvram_size(tp); | |
1da177e4 | 14563 | |
e6af301b | 14564 | tg3_disable_nvram_access(tp); |
381291b7 | 14565 | tg3_nvram_unlock(tp); |
1da177e4 LT |
14566 | |
14567 | } else { | |
63c3a66f JP |
14568 | tg3_flag_clear(tp, NVRAM); |
14569 | tg3_flag_clear(tp, NVRAM_BUFFERED); | |
1da177e4 LT |
14570 | |
14571 | tg3_get_eeprom_size(tp); | |
14572 | } | |
14573 | } | |
14574 | ||
1da177e4 LT |
14575 | struct subsys_tbl_ent { |
14576 | u16 subsys_vendor, subsys_devid; | |
14577 | u32 phy_id; | |
14578 | }; | |
14579 | ||
229b1ad1 | 14580 | static struct subsys_tbl_ent subsys_id_to_phy_id[] = { |
1da177e4 | 14581 | /* Broadcom boards. */ |
24daf2b0 | 14582 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 14583 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A6, TG3_PHY_ID_BCM5401 }, |
24daf2b0 | 14584 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 14585 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A5, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 14586 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 14587 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700T6, TG3_PHY_ID_BCM8002 }, |
24daf2b0 MC |
14588 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
14589 | TG3PCI_SUBDEVICE_ID_BROADCOM_95700A9, 0 }, | |
14590 | { TG3PCI_SUBVENDOR_ID_BROADCOM, | |
79eb6904 | 14591 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T1, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 14592 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 14593 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701T8, TG3_PHY_ID_BCM5701 }, |
24daf2b0 MC |
14594 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
14595 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A7, 0 }, | |
14596 | { TG3PCI_SUBVENDOR_ID_BROADCOM, | |
79eb6904 | 14597 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A10, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 14598 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 14599 | TG3PCI_SUBDEVICE_ID_BROADCOM_95701A12, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 14600 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 14601 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX1, TG3_PHY_ID_BCM5703 }, |
24daf2b0 | 14602 | { TG3PCI_SUBVENDOR_ID_BROADCOM, |
79eb6904 | 14603 | TG3PCI_SUBDEVICE_ID_BROADCOM_95703AX2, TG3_PHY_ID_BCM5703 }, |
1da177e4 LT |
14604 | |
14605 | /* 3com boards. */ | |
24daf2b0 | 14606 | { TG3PCI_SUBVENDOR_ID_3COM, |
79eb6904 | 14607 | TG3PCI_SUBDEVICE_ID_3COM_3C996T, TG3_PHY_ID_BCM5401 }, |
24daf2b0 | 14608 | { TG3PCI_SUBVENDOR_ID_3COM, |
79eb6904 | 14609 | TG3PCI_SUBDEVICE_ID_3COM_3C996BT, TG3_PHY_ID_BCM5701 }, |
24daf2b0 MC |
14610 | { TG3PCI_SUBVENDOR_ID_3COM, |
14611 | TG3PCI_SUBDEVICE_ID_3COM_3C996SX, 0 }, | |
14612 | { TG3PCI_SUBVENDOR_ID_3COM, | |
79eb6904 | 14613 | TG3PCI_SUBDEVICE_ID_3COM_3C1000T, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 14614 | { TG3PCI_SUBVENDOR_ID_3COM, |
79eb6904 | 14615 | TG3PCI_SUBDEVICE_ID_3COM_3C940BR01, TG3_PHY_ID_BCM5701 }, |
1da177e4 LT |
14616 | |
14617 | /* DELL boards. */ | |
24daf2b0 | 14618 | { TG3PCI_SUBVENDOR_ID_DELL, |
79eb6904 | 14619 | TG3PCI_SUBDEVICE_ID_DELL_VIPER, TG3_PHY_ID_BCM5401 }, |
24daf2b0 | 14620 | { TG3PCI_SUBVENDOR_ID_DELL, |
79eb6904 | 14621 | TG3PCI_SUBDEVICE_ID_DELL_JAGUAR, TG3_PHY_ID_BCM5401 }, |
24daf2b0 | 14622 | { TG3PCI_SUBVENDOR_ID_DELL, |
79eb6904 | 14623 | TG3PCI_SUBDEVICE_ID_DELL_MERLOT, TG3_PHY_ID_BCM5411 }, |
24daf2b0 | 14624 | { TG3PCI_SUBVENDOR_ID_DELL, |
79eb6904 | 14625 | TG3PCI_SUBDEVICE_ID_DELL_SLIM_MERLOT, TG3_PHY_ID_BCM5411 }, |
1da177e4 LT |
14626 | |
14627 | /* Compaq boards. */ | |
24daf2b0 | 14628 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
79eb6904 | 14629 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 14630 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
79eb6904 | 14631 | TG3PCI_SUBDEVICE_ID_COMPAQ_BANSHEE_2, TG3_PHY_ID_BCM5701 }, |
24daf2b0 MC |
14632 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
14633 | TG3PCI_SUBDEVICE_ID_COMPAQ_CHANGELING, 0 }, | |
14634 | { TG3PCI_SUBVENDOR_ID_COMPAQ, | |
79eb6904 | 14635 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780, TG3_PHY_ID_BCM5701 }, |
24daf2b0 | 14636 | { TG3PCI_SUBVENDOR_ID_COMPAQ, |
79eb6904 | 14637 | TG3PCI_SUBDEVICE_ID_COMPAQ_NC7780_2, TG3_PHY_ID_BCM5701 }, |
1da177e4 LT |
14638 | |
14639 | /* IBM boards. */ | |
24daf2b0 MC |
14640 | { TG3PCI_SUBVENDOR_ID_IBM, |
14641 | TG3PCI_SUBDEVICE_ID_IBM_5703SAX2, 0 } | |
1da177e4 LT |
14642 | }; |
14643 | ||
229b1ad1 | 14644 | static struct subsys_tbl_ent *tg3_lookup_by_subsys(struct tg3 *tp) |
1da177e4 LT |
14645 | { |
14646 | int i; | |
14647 | ||
14648 | for (i = 0; i < ARRAY_SIZE(subsys_id_to_phy_id); i++) { | |
14649 | if ((subsys_id_to_phy_id[i].subsys_vendor == | |
14650 | tp->pdev->subsystem_vendor) && | |
14651 | (subsys_id_to_phy_id[i].subsys_devid == | |
14652 | tp->pdev->subsystem_device)) | |
14653 | return &subsys_id_to_phy_id[i]; | |
14654 | } | |
14655 | return NULL; | |
14656 | } | |
14657 | ||
229b1ad1 | 14658 | static void tg3_get_eeprom_hw_cfg(struct tg3 *tp) |
1da177e4 | 14659 | { |
1da177e4 | 14660 | u32 val; |
f49639e6 | 14661 | |
79eb6904 | 14662 | tp->phy_id = TG3_PHY_ID_INVALID; |
7d0c41ef MC |
14663 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
14664 | ||
a85feb8c | 14665 | /* Assume an onboard device and WOL capable by default. */ |
63c3a66f JP |
14666 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
14667 | tg3_flag_set(tp, WOL_CAP); | |
72b845e0 | 14668 | |
4153577a | 14669 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
9d26e213 | 14670 | if (!(tr32(PCIE_TRANSACTION_CFG) & PCIE_TRANS_CFG_LOM)) { |
63c3a66f JP |
14671 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
14672 | tg3_flag_set(tp, IS_NIC); | |
9d26e213 | 14673 | } |
0527ba35 MC |
14674 | val = tr32(VCPU_CFGSHDW); |
14675 | if (val & VCPU_CFGSHDW_ASPM_DBNC) | |
63c3a66f | 14676 | tg3_flag_set(tp, ASPM_WORKAROUND); |
0527ba35 | 14677 | if ((val & VCPU_CFGSHDW_WOL_ENABLE) && |
6fdbab9d | 14678 | (val & VCPU_CFGSHDW_WOL_MAGPKT)) { |
63c3a66f | 14679 | tg3_flag_set(tp, WOL_ENABLE); |
6fdbab9d RW |
14680 | device_set_wakeup_enable(&tp->pdev->dev, true); |
14681 | } | |
05ac4cb7 | 14682 | goto done; |
b5d3772c MC |
14683 | } |
14684 | ||
1da177e4 LT |
14685 | tg3_read_mem(tp, NIC_SRAM_DATA_SIG, &val); |
14686 | if (val == NIC_SRAM_DATA_SIG_MAGIC) { | |
14687 | u32 nic_cfg, led_cfg; | |
a9daf367 | 14688 | u32 nic_phy_id, ver, cfg2 = 0, cfg4 = 0, eeprom_phy_id; |
7d0c41ef | 14689 | int eeprom_phy_serdes = 0; |
1da177e4 LT |
14690 | |
14691 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG, &nic_cfg); | |
14692 | tp->nic_sram_data_cfg = nic_cfg; | |
14693 | ||
14694 | tg3_read_mem(tp, NIC_SRAM_DATA_VER, &ver); | |
14695 | ver >>= NIC_SRAM_DATA_VER_SHIFT; | |
4153577a JP |
14696 | if (tg3_asic_rev(tp) != ASIC_REV_5700 && |
14697 | tg3_asic_rev(tp) != ASIC_REV_5701 && | |
14698 | tg3_asic_rev(tp) != ASIC_REV_5703 && | |
1da177e4 LT |
14699 | (ver > 0) && (ver < 0x100)) |
14700 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_2, &cfg2); | |
14701 | ||
4153577a | 14702 | if (tg3_asic_rev(tp) == ASIC_REV_5785) |
a9daf367 MC |
14703 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_4, &cfg4); |
14704 | ||
1da177e4 LT |
14705 | if ((nic_cfg & NIC_SRAM_DATA_CFG_PHY_TYPE_MASK) == |
14706 | NIC_SRAM_DATA_CFG_PHY_TYPE_FIBER) | |
14707 | eeprom_phy_serdes = 1; | |
14708 | ||
14709 | tg3_read_mem(tp, NIC_SRAM_DATA_PHY_ID, &nic_phy_id); | |
14710 | if (nic_phy_id != 0) { | |
14711 | u32 id1 = nic_phy_id & NIC_SRAM_DATA_PHY_ID1_MASK; | |
14712 | u32 id2 = nic_phy_id & NIC_SRAM_DATA_PHY_ID2_MASK; | |
14713 | ||
14714 | eeprom_phy_id = (id1 >> 16) << 10; | |
14715 | eeprom_phy_id |= (id2 & 0xfc00) << 16; | |
14716 | eeprom_phy_id |= (id2 & 0x03ff) << 0; | |
14717 | } else | |
14718 | eeprom_phy_id = 0; | |
14719 | ||
7d0c41ef | 14720 | tp->phy_id = eeprom_phy_id; |
747e8f8b | 14721 | if (eeprom_phy_serdes) { |
63c3a66f | 14722 | if (!tg3_flag(tp, 5705_PLUS)) |
f07e9af3 | 14723 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
a50d0796 | 14724 | else |
f07e9af3 | 14725 | tp->phy_flags |= TG3_PHYFLG_MII_SERDES; |
747e8f8b | 14726 | } |
7d0c41ef | 14727 | |
63c3a66f | 14728 | if (tg3_flag(tp, 5750_PLUS)) |
1da177e4 LT |
14729 | led_cfg = cfg2 & (NIC_SRAM_DATA_CFG_LED_MODE_MASK | |
14730 | SHASTA_EXT_LED_MODE_MASK); | |
cbf46853 | 14731 | else |
1da177e4 LT |
14732 | led_cfg = nic_cfg & NIC_SRAM_DATA_CFG_LED_MODE_MASK; |
14733 | ||
14734 | switch (led_cfg) { | |
14735 | default: | |
14736 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_1: | |
14737 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; | |
14738 | break; | |
14739 | ||
14740 | case NIC_SRAM_DATA_CFG_LED_MODE_PHY_2: | |
14741 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; | |
14742 | break; | |
14743 | ||
14744 | case NIC_SRAM_DATA_CFG_LED_MODE_MAC: | |
14745 | tp->led_ctrl = LED_CTRL_MODE_MAC; | |
9ba27794 MC |
14746 | |
14747 | /* Default to PHY_1_MODE if 0 (MAC_MODE) is | |
14748 | * read on some older 5700/5701 bootcode. | |
14749 | */ | |
4153577a JP |
14750 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
14751 | tg3_asic_rev(tp) == ASIC_REV_5701) | |
9ba27794 MC |
14752 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
14753 | ||
1da177e4 LT |
14754 | break; |
14755 | ||
14756 | case SHASTA_EXT_LED_SHARED: | |
14757 | tp->led_ctrl = LED_CTRL_MODE_SHARED; | |
4153577a JP |
14758 | if (tg3_chip_rev_id(tp) != CHIPREV_ID_5750_A0 && |
14759 | tg3_chip_rev_id(tp) != CHIPREV_ID_5750_A1) | |
1da177e4 LT |
14760 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
14761 | LED_CTRL_MODE_PHY_2); | |
14762 | break; | |
14763 | ||
14764 | case SHASTA_EXT_LED_MAC: | |
14765 | tp->led_ctrl = LED_CTRL_MODE_SHASTA_MAC; | |
14766 | break; | |
14767 | ||
14768 | case SHASTA_EXT_LED_COMBO: | |
14769 | tp->led_ctrl = LED_CTRL_MODE_COMBO; | |
4153577a | 14770 | if (tg3_chip_rev_id(tp) != CHIPREV_ID_5750_A0) |
1da177e4 LT |
14771 | tp->led_ctrl |= (LED_CTRL_MODE_PHY_1 | |
14772 | LED_CTRL_MODE_PHY_2); | |
14773 | break; | |
14774 | ||
855e1111 | 14775 | } |
1da177e4 | 14776 | |
4153577a JP |
14777 | if ((tg3_asic_rev(tp) == ASIC_REV_5700 || |
14778 | tg3_asic_rev(tp) == ASIC_REV_5701) && | |
1da177e4 LT |
14779 | tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL) |
14780 | tp->led_ctrl = LED_CTRL_MODE_PHY_2; | |
14781 | ||
4153577a | 14782 | if (tg3_chip_rev(tp) == CHIPREV_5784_AX) |
b2a5c19c | 14783 | tp->led_ctrl = LED_CTRL_MODE_PHY_1; |
5f60891b | 14784 | |
9d26e213 | 14785 | if (nic_cfg & NIC_SRAM_DATA_CFG_EEPROM_WP) { |
63c3a66f | 14786 | tg3_flag_set(tp, EEPROM_WRITE_PROT); |
9d26e213 MC |
14787 | if ((tp->pdev->subsystem_vendor == |
14788 | PCI_VENDOR_ID_ARIMA) && | |
14789 | (tp->pdev->subsystem_device == 0x205a || | |
14790 | tp->pdev->subsystem_device == 0x2063)) | |
63c3a66f | 14791 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
9d26e213 | 14792 | } else { |
63c3a66f JP |
14793 | tg3_flag_clear(tp, EEPROM_WRITE_PROT); |
14794 | tg3_flag_set(tp, IS_NIC); | |
9d26e213 | 14795 | } |
1da177e4 LT |
14796 | |
14797 | if (nic_cfg & NIC_SRAM_DATA_CFG_ASF_ENABLE) { | |
63c3a66f JP |
14798 | tg3_flag_set(tp, ENABLE_ASF); |
14799 | if (tg3_flag(tp, 5750_PLUS)) | |
14800 | tg3_flag_set(tp, ASF_NEW_HANDSHAKE); | |
1da177e4 | 14801 | } |
b2b98d4a MC |
14802 | |
14803 | if ((nic_cfg & NIC_SRAM_DATA_CFG_APE_ENABLE) && | |
63c3a66f JP |
14804 | tg3_flag(tp, 5750_PLUS)) |
14805 | tg3_flag_set(tp, ENABLE_APE); | |
b2b98d4a | 14806 | |
f07e9af3 | 14807 | if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES && |
a85feb8c | 14808 | !(nic_cfg & NIC_SRAM_DATA_CFG_FIBER_WOL)) |
63c3a66f | 14809 | tg3_flag_clear(tp, WOL_CAP); |
1da177e4 | 14810 | |
63c3a66f | 14811 | if (tg3_flag(tp, WOL_CAP) && |
6fdbab9d | 14812 | (nic_cfg & NIC_SRAM_DATA_CFG_WOL_ENABLE)) { |
63c3a66f | 14813 | tg3_flag_set(tp, WOL_ENABLE); |
6fdbab9d RW |
14814 | device_set_wakeup_enable(&tp->pdev->dev, true); |
14815 | } | |
0527ba35 | 14816 | |
1da177e4 | 14817 | if (cfg2 & (1 << 17)) |
f07e9af3 | 14818 | tp->phy_flags |= TG3_PHYFLG_CAPACITIVE_COUPLING; |
1da177e4 LT |
14819 | |
14820 | /* serdes signal pre-emphasis in register 0x590 set by */ | |
14821 | /* bootcode if bit 18 is set */ | |
14822 | if (cfg2 & (1 << 18)) | |
f07e9af3 | 14823 | tp->phy_flags |= TG3_PHYFLG_SERDES_PREEMPHASIS; |
8ed5d97e | 14824 | |
63c3a66f | 14825 | if ((tg3_flag(tp, 57765_PLUS) || |
4153577a JP |
14826 | (tg3_asic_rev(tp) == ASIC_REV_5784 && |
14827 | tg3_chip_rev(tp) != CHIPREV_5784_AX)) && | |
6833c043 | 14828 | (cfg2 & NIC_SRAM_DATA_CFG_2_APD_EN)) |
f07e9af3 | 14829 | tp->phy_flags |= TG3_PHYFLG_ENABLE_APD; |
6833c043 | 14830 | |
942d1af0 | 14831 | if (tg3_flag(tp, PCI_EXPRESS)) { |
8ed5d97e MC |
14832 | u32 cfg3; |
14833 | ||
14834 | tg3_read_mem(tp, NIC_SRAM_DATA_CFG_3, &cfg3); | |
942d1af0 NS |
14835 | if (tg3_asic_rev(tp) != ASIC_REV_5785 && |
14836 | !tg3_flag(tp, 57765_PLUS) && | |
14837 | (cfg3 & NIC_SRAM_ASPM_DEBOUNCE)) | |
63c3a66f | 14838 | tg3_flag_set(tp, ASPM_WORKAROUND); |
942d1af0 NS |
14839 | if (cfg3 & NIC_SRAM_LNK_FLAP_AVOID) |
14840 | tp->phy_flags |= TG3_PHYFLG_KEEP_LINK_ON_PWRDN; | |
14841 | if (cfg3 & NIC_SRAM_1G_ON_VAUX_OK) | |
14842 | tp->phy_flags |= TG3_PHYFLG_1G_ON_VAUX_OK; | |
8ed5d97e | 14843 | } |
a9daf367 | 14844 | |
14417063 | 14845 | if (cfg4 & NIC_SRAM_RGMII_INBAND_DISABLE) |
63c3a66f | 14846 | tg3_flag_set(tp, RGMII_INBAND_DISABLE); |
a9daf367 | 14847 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_RX_EN) |
63c3a66f | 14848 | tg3_flag_set(tp, RGMII_EXT_IBND_RX_EN); |
a9daf367 | 14849 | if (cfg4 & NIC_SRAM_RGMII_EXT_IBND_TX_EN) |
63c3a66f | 14850 | tg3_flag_set(tp, RGMII_EXT_IBND_TX_EN); |
1da177e4 | 14851 | } |
05ac4cb7 | 14852 | done: |
63c3a66f | 14853 | if (tg3_flag(tp, WOL_CAP)) |
43067ed8 | 14854 | device_set_wakeup_enable(&tp->pdev->dev, |
63c3a66f | 14855 | tg3_flag(tp, WOL_ENABLE)); |
43067ed8 RW |
14856 | else |
14857 | device_set_wakeup_capable(&tp->pdev->dev, false); | |
7d0c41ef MC |
14858 | } |
14859 | ||
c86a8560 MC |
14860 | static int tg3_ape_otp_read(struct tg3 *tp, u32 offset, u32 *val) |
14861 | { | |
14862 | int i, err; | |
14863 | u32 val2, off = offset * 8; | |
14864 | ||
14865 | err = tg3_nvram_lock(tp); | |
14866 | if (err) | |
14867 | return err; | |
14868 | ||
14869 | tg3_ape_write32(tp, TG3_APE_OTP_ADDR, off | APE_OTP_ADDR_CPU_ENABLE); | |
14870 | tg3_ape_write32(tp, TG3_APE_OTP_CTRL, APE_OTP_CTRL_PROG_EN | | |
14871 | APE_OTP_CTRL_CMD_RD | APE_OTP_CTRL_START); | |
14872 | tg3_ape_read32(tp, TG3_APE_OTP_CTRL); | |
14873 | udelay(10); | |
14874 | ||
14875 | for (i = 0; i < 100; i++) { | |
14876 | val2 = tg3_ape_read32(tp, TG3_APE_OTP_STATUS); | |
14877 | if (val2 & APE_OTP_STATUS_CMD_DONE) { | |
14878 | *val = tg3_ape_read32(tp, TG3_APE_OTP_RD_DATA); | |
14879 | break; | |
14880 | } | |
14881 | udelay(10); | |
14882 | } | |
14883 | ||
14884 | tg3_ape_write32(tp, TG3_APE_OTP_CTRL, 0); | |
14885 | ||
14886 | tg3_nvram_unlock(tp); | |
14887 | if (val2 & APE_OTP_STATUS_CMD_DONE) | |
14888 | return 0; | |
14889 | ||
14890 | return -EBUSY; | |
14891 | } | |
14892 | ||
229b1ad1 | 14893 | static int tg3_issue_otp_command(struct tg3 *tp, u32 cmd) |
b2a5c19c MC |
14894 | { |
14895 | int i; | |
14896 | u32 val; | |
14897 | ||
14898 | tw32(OTP_CTRL, cmd | OTP_CTRL_OTP_CMD_START); | |
14899 | tw32(OTP_CTRL, cmd); | |
14900 | ||
14901 | /* Wait for up to 1 ms for command to execute. */ | |
14902 | for (i = 0; i < 100; i++) { | |
14903 | val = tr32(OTP_STATUS); | |
14904 | if (val & OTP_STATUS_CMD_DONE) | |
14905 | break; | |
14906 | udelay(10); | |
14907 | } | |
14908 | ||
14909 | return (val & OTP_STATUS_CMD_DONE) ? 0 : -EBUSY; | |
14910 | } | |
14911 | ||
14912 | /* Read the gphy configuration from the OTP region of the chip. The gphy | |
14913 | * configuration is a 32-bit value that straddles the alignment boundary. | |
14914 | * We do two 32-bit reads and then shift and merge the results. | |
14915 | */ | |
229b1ad1 | 14916 | static u32 tg3_read_otp_phycfg(struct tg3 *tp) |
b2a5c19c MC |
14917 | { |
14918 | u32 bhalf_otp, thalf_otp; | |
14919 | ||
14920 | tw32(OTP_MODE, OTP_MODE_OTP_THRU_GRC); | |
14921 | ||
14922 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_INIT)) | |
14923 | return 0; | |
14924 | ||
14925 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC1); | |
14926 | ||
14927 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) | |
14928 | return 0; | |
14929 | ||
14930 | thalf_otp = tr32(OTP_READ_DATA); | |
14931 | ||
14932 | tw32(OTP_ADDRESS, OTP_ADDRESS_MAGIC2); | |
14933 | ||
14934 | if (tg3_issue_otp_command(tp, OTP_CTRL_OTP_CMD_READ)) | |
14935 | return 0; | |
14936 | ||
14937 | bhalf_otp = tr32(OTP_READ_DATA); | |
14938 | ||
14939 | return ((thalf_otp & 0x0000ffff) << 16) | (bhalf_otp >> 16); | |
14940 | } | |
14941 | ||
229b1ad1 | 14942 | static void tg3_phy_init_link_config(struct tg3 *tp) |
e256f8a3 | 14943 | { |
202ff1c2 | 14944 | u32 adv = ADVERTISED_Autoneg; |
e256f8a3 MC |
14945 | |
14946 | if (!(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) | |
14947 | adv |= ADVERTISED_1000baseT_Half | | |
14948 | ADVERTISED_1000baseT_Full; | |
14949 | ||
14950 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) | |
14951 | adv |= ADVERTISED_100baseT_Half | | |
14952 | ADVERTISED_100baseT_Full | | |
14953 | ADVERTISED_10baseT_Half | | |
14954 | ADVERTISED_10baseT_Full | | |
14955 | ADVERTISED_TP; | |
14956 | else | |
14957 | adv |= ADVERTISED_FIBRE; | |
14958 | ||
14959 | tp->link_config.advertising = adv; | |
e740522e MC |
14960 | tp->link_config.speed = SPEED_UNKNOWN; |
14961 | tp->link_config.duplex = DUPLEX_UNKNOWN; | |
e256f8a3 | 14962 | tp->link_config.autoneg = AUTONEG_ENABLE; |
e740522e MC |
14963 | tp->link_config.active_speed = SPEED_UNKNOWN; |
14964 | tp->link_config.active_duplex = DUPLEX_UNKNOWN; | |
34655ad6 MC |
14965 | |
14966 | tp->old_link = -1; | |
e256f8a3 MC |
14967 | } |
14968 | ||
229b1ad1 | 14969 | static int tg3_phy_probe(struct tg3 *tp) |
7d0c41ef MC |
14970 | { |
14971 | u32 hw_phy_id_1, hw_phy_id_2; | |
14972 | u32 hw_phy_id, hw_phy_id_masked; | |
14973 | int err; | |
1da177e4 | 14974 | |
e256f8a3 | 14975 | /* flow control autonegotiation is default behavior */ |
63c3a66f | 14976 | tg3_flag_set(tp, PAUSE_AUTONEG); |
e256f8a3 MC |
14977 | tp->link_config.flowctrl = FLOW_CTRL_TX | FLOW_CTRL_RX; |
14978 | ||
8151ad57 MC |
14979 | if (tg3_flag(tp, ENABLE_APE)) { |
14980 | switch (tp->pci_fn) { | |
14981 | case 0: | |
14982 | tp->phy_ape_lock = TG3_APE_LOCK_PHY0; | |
14983 | break; | |
14984 | case 1: | |
14985 | tp->phy_ape_lock = TG3_APE_LOCK_PHY1; | |
14986 | break; | |
14987 | case 2: | |
14988 | tp->phy_ape_lock = TG3_APE_LOCK_PHY2; | |
14989 | break; | |
14990 | case 3: | |
14991 | tp->phy_ape_lock = TG3_APE_LOCK_PHY3; | |
14992 | break; | |
14993 | } | |
14994 | } | |
14995 | ||
942d1af0 NS |
14996 | if (!tg3_flag(tp, ENABLE_ASF) && |
14997 | !(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && | |
14998 | !(tp->phy_flags & TG3_PHYFLG_10_100_ONLY)) | |
14999 | tp->phy_flags &= ~(TG3_PHYFLG_1G_ON_VAUX_OK | | |
15000 | TG3_PHYFLG_KEEP_LINK_ON_PWRDN); | |
15001 | ||
63c3a66f | 15002 | if (tg3_flag(tp, USE_PHYLIB)) |
b02fd9e3 MC |
15003 | return tg3_phy_init(tp); |
15004 | ||
1da177e4 | 15005 | /* Reading the PHY ID register can conflict with ASF |
877d0310 | 15006 | * firmware access to the PHY hardware. |
1da177e4 LT |
15007 | */ |
15008 | err = 0; | |
63c3a66f | 15009 | if (tg3_flag(tp, ENABLE_ASF) || tg3_flag(tp, ENABLE_APE)) { |
79eb6904 | 15010 | hw_phy_id = hw_phy_id_masked = TG3_PHY_ID_INVALID; |
1da177e4 LT |
15011 | } else { |
15012 | /* Now read the physical PHY_ID from the chip and verify | |
15013 | * that it is sane. If it doesn't look good, we fall back | |
15014 | * to either the hard-coded table based PHY_ID and failing | |
15015 | * that the value found in the eeprom area. | |
15016 | */ | |
15017 | err |= tg3_readphy(tp, MII_PHYSID1, &hw_phy_id_1); | |
15018 | err |= tg3_readphy(tp, MII_PHYSID2, &hw_phy_id_2); | |
15019 | ||
15020 | hw_phy_id = (hw_phy_id_1 & 0xffff) << 10; | |
15021 | hw_phy_id |= (hw_phy_id_2 & 0xfc00) << 16; | |
15022 | hw_phy_id |= (hw_phy_id_2 & 0x03ff) << 0; | |
15023 | ||
79eb6904 | 15024 | hw_phy_id_masked = hw_phy_id & TG3_PHY_ID_MASK; |
1da177e4 LT |
15025 | } |
15026 | ||
79eb6904 | 15027 | if (!err && TG3_KNOWN_PHY_ID(hw_phy_id_masked)) { |
1da177e4 | 15028 | tp->phy_id = hw_phy_id; |
79eb6904 | 15029 | if (hw_phy_id_masked == TG3_PHY_ID_BCM8002) |
f07e9af3 | 15030 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
da6b2d01 | 15031 | else |
f07e9af3 | 15032 | tp->phy_flags &= ~TG3_PHYFLG_PHY_SERDES; |
1da177e4 | 15033 | } else { |
79eb6904 | 15034 | if (tp->phy_id != TG3_PHY_ID_INVALID) { |
7d0c41ef MC |
15035 | /* Do nothing, phy ID already set up in |
15036 | * tg3_get_eeprom_hw_cfg(). | |
15037 | */ | |
1da177e4 LT |
15038 | } else { |
15039 | struct subsys_tbl_ent *p; | |
15040 | ||
15041 | /* No eeprom signature? Try the hardcoded | |
15042 | * subsys device table. | |
15043 | */ | |
24daf2b0 | 15044 | p = tg3_lookup_by_subsys(tp); |
7e6c63f0 HM |
15045 | if (p) { |
15046 | tp->phy_id = p->phy_id; | |
15047 | } else if (!tg3_flag(tp, IS_SSB_CORE)) { | |
15048 | /* For now we saw the IDs 0xbc050cd0, | |
15049 | * 0xbc050f80 and 0xbc050c30 on devices | |
15050 | * connected to an BCM4785 and there are | |
15051 | * probably more. Just assume that the phy is | |
15052 | * supported when it is connected to a SSB core | |
15053 | * for now. | |
15054 | */ | |
1da177e4 | 15055 | return -ENODEV; |
7e6c63f0 | 15056 | } |
1da177e4 | 15057 | |
1da177e4 | 15058 | if (!tp->phy_id || |
79eb6904 | 15059 | tp->phy_id == TG3_PHY_ID_BCM8002) |
f07e9af3 | 15060 | tp->phy_flags |= TG3_PHYFLG_PHY_SERDES; |
1da177e4 LT |
15061 | } |
15062 | } | |
15063 | ||
a6b68dab | 15064 | if (!(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && |
4153577a JP |
15065 | (tg3_asic_rev(tp) == ASIC_REV_5719 || |
15066 | tg3_asic_rev(tp) == ASIC_REV_5720 || | |
c4dab506 | 15067 | tg3_asic_rev(tp) == ASIC_REV_57766 || |
4153577a JP |
15068 | tg3_asic_rev(tp) == ASIC_REV_5762 || |
15069 | (tg3_asic_rev(tp) == ASIC_REV_5717 && | |
15070 | tg3_chip_rev_id(tp) != CHIPREV_ID_5717_A0) || | |
15071 | (tg3_asic_rev(tp) == ASIC_REV_57765 && | |
15072 | tg3_chip_rev_id(tp) != CHIPREV_ID_57765_A0))) | |
52b02d04 MC |
15073 | tp->phy_flags |= TG3_PHYFLG_EEE_CAP; |
15074 | ||
e256f8a3 MC |
15075 | tg3_phy_init_link_config(tp); |
15076 | ||
942d1af0 NS |
15077 | if (!(tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN) && |
15078 | !(tp->phy_flags & TG3_PHYFLG_ANY_SERDES) && | |
63c3a66f JP |
15079 | !tg3_flag(tp, ENABLE_APE) && |
15080 | !tg3_flag(tp, ENABLE_ASF)) { | |
e2bf73e7 | 15081 | u32 bmsr, dummy; |
1da177e4 LT |
15082 | |
15083 | tg3_readphy(tp, MII_BMSR, &bmsr); | |
15084 | if (!tg3_readphy(tp, MII_BMSR, &bmsr) && | |
15085 | (bmsr & BMSR_LSTATUS)) | |
15086 | goto skip_phy_reset; | |
6aa20a22 | 15087 | |
1da177e4 LT |
15088 | err = tg3_phy_reset(tp); |
15089 | if (err) | |
15090 | return err; | |
15091 | ||
42b64a45 | 15092 | tg3_phy_set_wirespeed(tp); |
1da177e4 | 15093 | |
e2bf73e7 | 15094 | if (!tg3_phy_copper_an_config_ok(tp, &dummy)) { |
42b64a45 MC |
15095 | tg3_phy_autoneg_cfg(tp, tp->link_config.advertising, |
15096 | tp->link_config.flowctrl); | |
1da177e4 LT |
15097 | |
15098 | tg3_writephy(tp, MII_BMCR, | |
15099 | BMCR_ANENABLE | BMCR_ANRESTART); | |
15100 | } | |
1da177e4 LT |
15101 | } |
15102 | ||
15103 | skip_phy_reset: | |
79eb6904 | 15104 | if ((tp->phy_id & TG3_PHY_ID_MASK) == TG3_PHY_ID_BCM5401) { |
1da177e4 LT |
15105 | err = tg3_init_5401phy_dsp(tp); |
15106 | if (err) | |
15107 | return err; | |
1da177e4 | 15108 | |
1da177e4 LT |
15109 | err = tg3_init_5401phy_dsp(tp); |
15110 | } | |
15111 | ||
1da177e4 LT |
15112 | return err; |
15113 | } | |
15114 | ||
229b1ad1 | 15115 | static void tg3_read_vpd(struct tg3 *tp) |
1da177e4 | 15116 | { |
a4a8bb15 | 15117 | u8 *vpd_data; |
4181b2c8 | 15118 | unsigned int block_end, rosize, len; |
535a490e | 15119 | u32 vpdlen; |
184b8904 | 15120 | int j, i = 0; |
a4a8bb15 | 15121 | |
535a490e | 15122 | vpd_data = (u8 *)tg3_vpd_readblock(tp, &vpdlen); |
a4a8bb15 MC |
15123 | if (!vpd_data) |
15124 | goto out_no_vpd; | |
1da177e4 | 15125 | |
535a490e | 15126 | i = pci_vpd_find_tag(vpd_data, 0, vpdlen, PCI_VPD_LRDT_RO_DATA); |
4181b2c8 MC |
15127 | if (i < 0) |
15128 | goto out_not_found; | |
1da177e4 | 15129 | |
4181b2c8 MC |
15130 | rosize = pci_vpd_lrdt_size(&vpd_data[i]); |
15131 | block_end = i + PCI_VPD_LRDT_TAG_SIZE + rosize; | |
15132 | i += PCI_VPD_LRDT_TAG_SIZE; | |
1da177e4 | 15133 | |
535a490e | 15134 | if (block_end > vpdlen) |
4181b2c8 | 15135 | goto out_not_found; |
af2c6a4a | 15136 | |
184b8904 MC |
15137 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
15138 | PCI_VPD_RO_KEYWORD_MFR_ID); | |
15139 | if (j > 0) { | |
15140 | len = pci_vpd_info_field_size(&vpd_data[j]); | |
15141 | ||
15142 | j += PCI_VPD_INFO_FLD_HDR_SIZE; | |
15143 | if (j + len > block_end || len != 4 || | |
15144 | memcmp(&vpd_data[j], "1028", 4)) | |
15145 | goto partno; | |
15146 | ||
15147 | j = pci_vpd_find_info_keyword(vpd_data, i, rosize, | |
15148 | PCI_VPD_RO_KEYWORD_VENDOR0); | |
15149 | if (j < 0) | |
15150 | goto partno; | |
15151 | ||
15152 | len = pci_vpd_info_field_size(&vpd_data[j]); | |
15153 | ||
15154 | j += PCI_VPD_INFO_FLD_HDR_SIZE; | |
15155 | if (j + len > block_end) | |
15156 | goto partno; | |
15157 | ||
715230a4 KC |
15158 | if (len >= sizeof(tp->fw_ver)) |
15159 | len = sizeof(tp->fw_ver) - 1; | |
15160 | memset(tp->fw_ver, 0, sizeof(tp->fw_ver)); | |
15161 | snprintf(tp->fw_ver, sizeof(tp->fw_ver), "%.*s bc ", len, | |
15162 | &vpd_data[j]); | |
184b8904 MC |
15163 | } |
15164 | ||
15165 | partno: | |
4181b2c8 MC |
15166 | i = pci_vpd_find_info_keyword(vpd_data, i, rosize, |
15167 | PCI_VPD_RO_KEYWORD_PARTNO); | |
15168 | if (i < 0) | |
15169 | goto out_not_found; | |
af2c6a4a | 15170 | |
4181b2c8 | 15171 | len = pci_vpd_info_field_size(&vpd_data[i]); |
1da177e4 | 15172 | |
4181b2c8 MC |
15173 | i += PCI_VPD_INFO_FLD_HDR_SIZE; |
15174 | if (len > TG3_BPN_SIZE || | |
535a490e | 15175 | (len + i) > vpdlen) |
4181b2c8 | 15176 | goto out_not_found; |
1da177e4 | 15177 | |
4181b2c8 | 15178 | memcpy(tp->board_part_number, &vpd_data[i], len); |
1da177e4 | 15179 | |
1da177e4 | 15180 | out_not_found: |
a4a8bb15 | 15181 | kfree(vpd_data); |
37a949c5 | 15182 | if (tp->board_part_number[0]) |
a4a8bb15 MC |
15183 | return; |
15184 | ||
15185 | out_no_vpd: | |
4153577a | 15186 | if (tg3_asic_rev(tp) == ASIC_REV_5717) { |
79d49695 MC |
15187 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || |
15188 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717_C) | |
37a949c5 MC |
15189 | strcpy(tp->board_part_number, "BCM5717"); |
15190 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718) | |
15191 | strcpy(tp->board_part_number, "BCM5718"); | |
15192 | else | |
15193 | goto nomatch; | |
4153577a | 15194 | } else if (tg3_asic_rev(tp) == ASIC_REV_57780) { |
37a949c5 MC |
15195 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57780) |
15196 | strcpy(tp->board_part_number, "BCM57780"); | |
15197 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57760) | |
15198 | strcpy(tp->board_part_number, "BCM57760"); | |
15199 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57790) | |
15200 | strcpy(tp->board_part_number, "BCM57790"); | |
15201 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57788) | |
15202 | strcpy(tp->board_part_number, "BCM57788"); | |
15203 | else | |
15204 | goto nomatch; | |
4153577a | 15205 | } else if (tg3_asic_rev(tp) == ASIC_REV_57765) { |
37a949c5 MC |
15206 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761) |
15207 | strcpy(tp->board_part_number, "BCM57761"); | |
15208 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765) | |
15209 | strcpy(tp->board_part_number, "BCM57765"); | |
15210 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781) | |
15211 | strcpy(tp->board_part_number, "BCM57781"); | |
15212 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785) | |
15213 | strcpy(tp->board_part_number, "BCM57785"); | |
15214 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791) | |
15215 | strcpy(tp->board_part_number, "BCM57791"); | |
15216 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795) | |
15217 | strcpy(tp->board_part_number, "BCM57795"); | |
15218 | else | |
15219 | goto nomatch; | |
4153577a | 15220 | } else if (tg3_asic_rev(tp) == ASIC_REV_57766) { |
55086ad9 MC |
15221 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57762) |
15222 | strcpy(tp->board_part_number, "BCM57762"); | |
15223 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57766) | |
15224 | strcpy(tp->board_part_number, "BCM57766"); | |
15225 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57782) | |
15226 | strcpy(tp->board_part_number, "BCM57782"); | |
15227 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57786) | |
15228 | strcpy(tp->board_part_number, "BCM57786"); | |
15229 | else | |
15230 | goto nomatch; | |
4153577a | 15231 | } else if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
b5d3772c | 15232 | strcpy(tp->board_part_number, "BCM95906"); |
37a949c5 MC |
15233 | } else { |
15234 | nomatch: | |
b5d3772c | 15235 | strcpy(tp->board_part_number, "none"); |
37a949c5 | 15236 | } |
1da177e4 LT |
15237 | } |
15238 | ||
229b1ad1 | 15239 | static int tg3_fw_img_is_valid(struct tg3 *tp, u32 offset) |
9c8a620e MC |
15240 | { |
15241 | u32 val; | |
15242 | ||
e4f34110 | 15243 | if (tg3_nvram_read(tp, offset, &val) || |
9c8a620e | 15244 | (val & 0xfc000000) != 0x0c000000 || |
e4f34110 | 15245 | tg3_nvram_read(tp, offset + 4, &val) || |
9c8a620e MC |
15246 | val != 0) |
15247 | return 0; | |
15248 | ||
15249 | return 1; | |
15250 | } | |
15251 | ||
229b1ad1 | 15252 | static void tg3_read_bc_ver(struct tg3 *tp) |
acd9c119 | 15253 | { |
ff3a7cb2 | 15254 | u32 val, offset, start, ver_offset; |
75f9936e | 15255 | int i, dst_off; |
ff3a7cb2 | 15256 | bool newver = false; |
acd9c119 MC |
15257 | |
15258 | if (tg3_nvram_read(tp, 0xc, &offset) || | |
15259 | tg3_nvram_read(tp, 0x4, &start)) | |
15260 | return; | |
15261 | ||
15262 | offset = tg3_nvram_logical_addr(tp, offset); | |
15263 | ||
ff3a7cb2 | 15264 | if (tg3_nvram_read(tp, offset, &val)) |
acd9c119 MC |
15265 | return; |
15266 | ||
ff3a7cb2 MC |
15267 | if ((val & 0xfc000000) == 0x0c000000) { |
15268 | if (tg3_nvram_read(tp, offset + 4, &val)) | |
acd9c119 MC |
15269 | return; |
15270 | ||
ff3a7cb2 MC |
15271 | if (val == 0) |
15272 | newver = true; | |
15273 | } | |
15274 | ||
75f9936e MC |
15275 | dst_off = strlen(tp->fw_ver); |
15276 | ||
ff3a7cb2 | 15277 | if (newver) { |
75f9936e MC |
15278 | if (TG3_VER_SIZE - dst_off < 16 || |
15279 | tg3_nvram_read(tp, offset + 8, &ver_offset)) | |
ff3a7cb2 MC |
15280 | return; |
15281 | ||
15282 | offset = offset + ver_offset - start; | |
15283 | for (i = 0; i < 16; i += 4) { | |
15284 | __be32 v; | |
15285 | if (tg3_nvram_read_be32(tp, offset + i, &v)) | |
15286 | return; | |
15287 | ||
75f9936e | 15288 | memcpy(tp->fw_ver + dst_off + i, &v, sizeof(v)); |
ff3a7cb2 MC |
15289 | } |
15290 | } else { | |
15291 | u32 major, minor; | |
15292 | ||
15293 | if (tg3_nvram_read(tp, TG3_NVM_PTREV_BCVER, &ver_offset)) | |
15294 | return; | |
15295 | ||
15296 | major = (ver_offset & TG3_NVM_BCVER_MAJMSK) >> | |
15297 | TG3_NVM_BCVER_MAJSFT; | |
15298 | minor = ver_offset & TG3_NVM_BCVER_MINMSK; | |
75f9936e MC |
15299 | snprintf(&tp->fw_ver[dst_off], TG3_VER_SIZE - dst_off, |
15300 | "v%d.%02d", major, minor); | |
acd9c119 MC |
15301 | } |
15302 | } | |
15303 | ||
229b1ad1 | 15304 | static void tg3_read_hwsb_ver(struct tg3 *tp) |
a6f6cb1c MC |
15305 | { |
15306 | u32 val, major, minor; | |
15307 | ||
15308 | /* Use native endian representation */ | |
15309 | if (tg3_nvram_read(tp, TG3_NVM_HWSB_CFG1, &val)) | |
15310 | return; | |
15311 | ||
15312 | major = (val & TG3_NVM_HWSB_CFG1_MAJMSK) >> | |
15313 | TG3_NVM_HWSB_CFG1_MAJSFT; | |
15314 | minor = (val & TG3_NVM_HWSB_CFG1_MINMSK) >> | |
15315 | TG3_NVM_HWSB_CFG1_MINSFT; | |
15316 | ||
15317 | snprintf(&tp->fw_ver[0], 32, "sb v%d.%02d", major, minor); | |
15318 | } | |
15319 | ||
229b1ad1 | 15320 | static void tg3_read_sb_ver(struct tg3 *tp, u32 val) |
dfe00d7d MC |
15321 | { |
15322 | u32 offset, major, minor, build; | |
15323 | ||
75f9936e | 15324 | strncat(tp->fw_ver, "sb", TG3_VER_SIZE - strlen(tp->fw_ver) - 1); |
dfe00d7d MC |
15325 | |
15326 | if ((val & TG3_EEPROM_SB_FORMAT_MASK) != TG3_EEPROM_SB_FORMAT_1) | |
15327 | return; | |
15328 | ||
15329 | switch (val & TG3_EEPROM_SB_REVISION_MASK) { | |
15330 | case TG3_EEPROM_SB_REVISION_0: | |
15331 | offset = TG3_EEPROM_SB_F1R0_EDH_OFF; | |
15332 | break; | |
15333 | case TG3_EEPROM_SB_REVISION_2: | |
15334 | offset = TG3_EEPROM_SB_F1R2_EDH_OFF; | |
15335 | break; | |
15336 | case TG3_EEPROM_SB_REVISION_3: | |
15337 | offset = TG3_EEPROM_SB_F1R3_EDH_OFF; | |
15338 | break; | |
a4153d40 MC |
15339 | case TG3_EEPROM_SB_REVISION_4: |
15340 | offset = TG3_EEPROM_SB_F1R4_EDH_OFF; | |
15341 | break; | |
15342 | case TG3_EEPROM_SB_REVISION_5: | |
15343 | offset = TG3_EEPROM_SB_F1R5_EDH_OFF; | |
15344 | break; | |
bba226ac MC |
15345 | case TG3_EEPROM_SB_REVISION_6: |
15346 | offset = TG3_EEPROM_SB_F1R6_EDH_OFF; | |
15347 | break; | |
dfe00d7d MC |
15348 | default: |
15349 | return; | |
15350 | } | |
15351 | ||
e4f34110 | 15352 | if (tg3_nvram_read(tp, offset, &val)) |
dfe00d7d MC |
15353 | return; |
15354 | ||
15355 | build = (val & TG3_EEPROM_SB_EDH_BLD_MASK) >> | |
15356 | TG3_EEPROM_SB_EDH_BLD_SHFT; | |
15357 | major = (val & TG3_EEPROM_SB_EDH_MAJ_MASK) >> | |
15358 | TG3_EEPROM_SB_EDH_MAJ_SHFT; | |
15359 | minor = val & TG3_EEPROM_SB_EDH_MIN_MASK; | |
15360 | ||
15361 | if (minor > 99 || build > 26) | |
15362 | return; | |
15363 | ||
75f9936e MC |
15364 | offset = strlen(tp->fw_ver); |
15365 | snprintf(&tp->fw_ver[offset], TG3_VER_SIZE - offset, | |
15366 | " v%d.%02d", major, minor); | |
dfe00d7d MC |
15367 | |
15368 | if (build > 0) { | |
75f9936e MC |
15369 | offset = strlen(tp->fw_ver); |
15370 | if (offset < TG3_VER_SIZE - 1) | |
15371 | tp->fw_ver[offset] = 'a' + build - 1; | |
dfe00d7d MC |
15372 | } |
15373 | } | |
15374 | ||
229b1ad1 | 15375 | static void tg3_read_mgmtfw_ver(struct tg3 *tp) |
c4e6575c MC |
15376 | { |
15377 | u32 val, offset, start; | |
acd9c119 | 15378 | int i, vlen; |
9c8a620e MC |
15379 | |
15380 | for (offset = TG3_NVM_DIR_START; | |
15381 | offset < TG3_NVM_DIR_END; | |
15382 | offset += TG3_NVM_DIRENT_SIZE) { | |
e4f34110 | 15383 | if (tg3_nvram_read(tp, offset, &val)) |
c4e6575c MC |
15384 | return; |
15385 | ||
9c8a620e MC |
15386 | if ((val >> TG3_NVM_DIRTYPE_SHIFT) == TG3_NVM_DIRTYPE_ASFINI) |
15387 | break; | |
15388 | } | |
15389 | ||
15390 | if (offset == TG3_NVM_DIR_END) | |
15391 | return; | |
15392 | ||
63c3a66f | 15393 | if (!tg3_flag(tp, 5705_PLUS)) |
9c8a620e | 15394 | start = 0x08000000; |
e4f34110 | 15395 | else if (tg3_nvram_read(tp, offset - 4, &start)) |
9c8a620e MC |
15396 | return; |
15397 | ||
e4f34110 | 15398 | if (tg3_nvram_read(tp, offset + 4, &offset) || |
9c8a620e | 15399 | !tg3_fw_img_is_valid(tp, offset) || |
e4f34110 | 15400 | tg3_nvram_read(tp, offset + 8, &val)) |
9c8a620e MC |
15401 | return; |
15402 | ||
15403 | offset += val - start; | |
15404 | ||
acd9c119 | 15405 | vlen = strlen(tp->fw_ver); |
9c8a620e | 15406 | |
acd9c119 MC |
15407 | tp->fw_ver[vlen++] = ','; |
15408 | tp->fw_ver[vlen++] = ' '; | |
9c8a620e MC |
15409 | |
15410 | for (i = 0; i < 4; i++) { | |
a9dc529d MC |
15411 | __be32 v; |
15412 | if (tg3_nvram_read_be32(tp, offset, &v)) | |
c4e6575c MC |
15413 | return; |
15414 | ||
b9fc7dc5 | 15415 | offset += sizeof(v); |
c4e6575c | 15416 | |
acd9c119 MC |
15417 | if (vlen > TG3_VER_SIZE - sizeof(v)) { |
15418 | memcpy(&tp->fw_ver[vlen], &v, TG3_VER_SIZE - vlen); | |
9c8a620e | 15419 | break; |
c4e6575c | 15420 | } |
9c8a620e | 15421 | |
acd9c119 MC |
15422 | memcpy(&tp->fw_ver[vlen], &v, sizeof(v)); |
15423 | vlen += sizeof(v); | |
c4e6575c | 15424 | } |
acd9c119 MC |
15425 | } |
15426 | ||
229b1ad1 | 15427 | static void tg3_probe_ncsi(struct tg3 *tp) |
7fd76445 | 15428 | { |
7fd76445 | 15429 | u32 apedata; |
7fd76445 MC |
15430 | |
15431 | apedata = tg3_ape_read32(tp, TG3_APE_SEG_SIG); | |
15432 | if (apedata != APE_SEG_SIG_MAGIC) | |
15433 | return; | |
15434 | ||
15435 | apedata = tg3_ape_read32(tp, TG3_APE_FW_STATUS); | |
15436 | if (!(apedata & APE_FW_STATUS_READY)) | |
15437 | return; | |
15438 | ||
165f4d1c MC |
15439 | if (tg3_ape_read32(tp, TG3_APE_FW_FEATURES) & TG3_APE_FW_FEATURE_NCSI) |
15440 | tg3_flag_set(tp, APE_HAS_NCSI); | |
15441 | } | |
15442 | ||
229b1ad1 | 15443 | static void tg3_read_dash_ver(struct tg3 *tp) |
165f4d1c MC |
15444 | { |
15445 | int vlen; | |
15446 | u32 apedata; | |
15447 | char *fwtype; | |
15448 | ||
7fd76445 MC |
15449 | apedata = tg3_ape_read32(tp, TG3_APE_FW_VERSION); |
15450 | ||
165f4d1c | 15451 | if (tg3_flag(tp, APE_HAS_NCSI)) |
ecc79648 | 15452 | fwtype = "NCSI"; |
c86a8560 MC |
15453 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5725) |
15454 | fwtype = "SMASH"; | |
165f4d1c | 15455 | else |
ecc79648 MC |
15456 | fwtype = "DASH"; |
15457 | ||
7fd76445 MC |
15458 | vlen = strlen(tp->fw_ver); |
15459 | ||
ecc79648 MC |
15460 | snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " %s v%d.%d.%d.%d", |
15461 | fwtype, | |
7fd76445 MC |
15462 | (apedata & APE_FW_VERSION_MAJMSK) >> APE_FW_VERSION_MAJSFT, |
15463 | (apedata & APE_FW_VERSION_MINMSK) >> APE_FW_VERSION_MINSFT, | |
15464 | (apedata & APE_FW_VERSION_REVMSK) >> APE_FW_VERSION_REVSFT, | |
15465 | (apedata & APE_FW_VERSION_BLDMSK)); | |
15466 | } | |
15467 | ||
c86a8560 MC |
15468 | static void tg3_read_otp_ver(struct tg3 *tp) |
15469 | { | |
15470 | u32 val, val2; | |
15471 | ||
4153577a | 15472 | if (tg3_asic_rev(tp) != ASIC_REV_5762) |
c86a8560 MC |
15473 | return; |
15474 | ||
15475 | if (!tg3_ape_otp_read(tp, OTP_ADDRESS_MAGIC0, &val) && | |
15476 | !tg3_ape_otp_read(tp, OTP_ADDRESS_MAGIC0 + 4, &val2) && | |
15477 | TG3_OTP_MAGIC0_VALID(val)) { | |
15478 | u64 val64 = (u64) val << 32 | val2; | |
15479 | u32 ver = 0; | |
15480 | int i, vlen; | |
15481 | ||
15482 | for (i = 0; i < 7; i++) { | |
15483 | if ((val64 & 0xff) == 0) | |
15484 | break; | |
15485 | ver = val64 & 0xff; | |
15486 | val64 >>= 8; | |
15487 | } | |
15488 | vlen = strlen(tp->fw_ver); | |
15489 | snprintf(&tp->fw_ver[vlen], TG3_VER_SIZE - vlen, " .%02d", ver); | |
15490 | } | |
15491 | } | |
15492 | ||
229b1ad1 | 15493 | static void tg3_read_fw_ver(struct tg3 *tp) |
acd9c119 MC |
15494 | { |
15495 | u32 val; | |
75f9936e | 15496 | bool vpd_vers = false; |
acd9c119 | 15497 | |
75f9936e MC |
15498 | if (tp->fw_ver[0] != 0) |
15499 | vpd_vers = true; | |
df259d8c | 15500 | |
63c3a66f | 15501 | if (tg3_flag(tp, NO_NVRAM)) { |
75f9936e | 15502 | strcat(tp->fw_ver, "sb"); |
c86a8560 | 15503 | tg3_read_otp_ver(tp); |
df259d8c MC |
15504 | return; |
15505 | } | |
15506 | ||
acd9c119 MC |
15507 | if (tg3_nvram_read(tp, 0, &val)) |
15508 | return; | |
15509 | ||
15510 | if (val == TG3_EEPROM_MAGIC) | |
15511 | tg3_read_bc_ver(tp); | |
15512 | else if ((val & TG3_EEPROM_MAGIC_FW_MSK) == TG3_EEPROM_MAGIC_FW) | |
15513 | tg3_read_sb_ver(tp, val); | |
a6f6cb1c MC |
15514 | else if ((val & TG3_EEPROM_MAGIC_HW_MSK) == TG3_EEPROM_MAGIC_HW) |
15515 | tg3_read_hwsb_ver(tp); | |
acd9c119 | 15516 | |
165f4d1c MC |
15517 | if (tg3_flag(tp, ENABLE_ASF)) { |
15518 | if (tg3_flag(tp, ENABLE_APE)) { | |
15519 | tg3_probe_ncsi(tp); | |
15520 | if (!vpd_vers) | |
15521 | tg3_read_dash_ver(tp); | |
15522 | } else if (!vpd_vers) { | |
15523 | tg3_read_mgmtfw_ver(tp); | |
15524 | } | |
c9cab24e | 15525 | } |
9c8a620e MC |
15526 | |
15527 | tp->fw_ver[TG3_VER_SIZE - 1] = 0; | |
c4e6575c MC |
15528 | } |
15529 | ||
7cb32cf2 MC |
15530 | static inline u32 tg3_rx_ret_ring_size(struct tg3 *tp) |
15531 | { | |
63c3a66f | 15532 | if (tg3_flag(tp, LRG_PROD_RING_CAP)) |
de9f5230 | 15533 | return TG3_RX_RET_MAX_SIZE_5717; |
63c3a66f | 15534 | else if (tg3_flag(tp, JUMBO_CAPABLE) && !tg3_flag(tp, 5780_CLASS)) |
de9f5230 | 15535 | return TG3_RX_RET_MAX_SIZE_5700; |
7cb32cf2 | 15536 | else |
de9f5230 | 15537 | return TG3_RX_RET_MAX_SIZE_5705; |
7cb32cf2 MC |
15538 | } |
15539 | ||
4143470c | 15540 | static DEFINE_PCI_DEVICE_TABLE(tg3_write_reorder_chipsets) = { |
895950c2 JP |
15541 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C) }, |
15542 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE) }, | |
15543 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8385_0) }, | |
15544 | { }, | |
15545 | }; | |
15546 | ||
229b1ad1 | 15547 | static struct pci_dev *tg3_find_peer(struct tg3 *tp) |
16c7fa7d MC |
15548 | { |
15549 | struct pci_dev *peer; | |
15550 | unsigned int func, devnr = tp->pdev->devfn & ~7; | |
15551 | ||
15552 | for (func = 0; func < 8; func++) { | |
15553 | peer = pci_get_slot(tp->pdev->bus, devnr | func); | |
15554 | if (peer && peer != tp->pdev) | |
15555 | break; | |
15556 | pci_dev_put(peer); | |
15557 | } | |
15558 | /* 5704 can be configured in single-port mode, set peer to | |
15559 | * tp->pdev in that case. | |
15560 | */ | |
15561 | if (!peer) { | |
15562 | peer = tp->pdev; | |
15563 | return peer; | |
15564 | } | |
15565 | ||
15566 | /* | |
15567 | * We don't need to keep the refcount elevated; there's no way | |
15568 | * to remove one half of this device without removing the other | |
15569 | */ | |
15570 | pci_dev_put(peer); | |
15571 | ||
15572 | return peer; | |
15573 | } | |
15574 | ||
229b1ad1 | 15575 | static void tg3_detect_asic_rev(struct tg3 *tp, u32 misc_ctrl_reg) |
42b123b1 MC |
15576 | { |
15577 | tp->pci_chip_rev_id = misc_ctrl_reg >> MISC_HOST_CTRL_CHIPREV_SHIFT; | |
4153577a | 15578 | if (tg3_asic_rev(tp) == ASIC_REV_USE_PROD_ID_REG) { |
42b123b1 MC |
15579 | u32 reg; |
15580 | ||
15581 | /* All devices that use the alternate | |
15582 | * ASIC REV location have a CPMU. | |
15583 | */ | |
15584 | tg3_flag_set(tp, CPMU_PRESENT); | |
15585 | ||
15586 | if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || | |
79d49695 | 15587 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717_C || |
42b123b1 MC |
15588 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
15589 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || | |
c65a17f4 MC |
15590 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720 || |
15591 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5762 || | |
15592 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5725 || | |
15593 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5727) | |
42b123b1 MC |
15594 | reg = TG3PCI_GEN2_PRODID_ASICREV; |
15595 | else if (tp->pdev->device == TG3PCI_DEVICE_TIGON3_57781 || | |
15596 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57785 || | |
15597 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57761 || | |
15598 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57765 || | |
15599 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57791 || | |
15600 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57795 || | |
15601 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57762 || | |
15602 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57766 || | |
15603 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57782 || | |
15604 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_57786) | |
15605 | reg = TG3PCI_GEN15_PRODID_ASICREV; | |
15606 | else | |
15607 | reg = TG3PCI_PRODID_ASICREV; | |
15608 | ||
15609 | pci_read_config_dword(tp->pdev, reg, &tp->pci_chip_rev_id); | |
15610 | } | |
15611 | ||
15612 | /* Wrong chip ID in 5752 A0. This code can be removed later | |
15613 | * as A0 is not in production. | |
15614 | */ | |
4153577a | 15615 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5752_A0_HW) |
42b123b1 MC |
15616 | tp->pci_chip_rev_id = CHIPREV_ID_5752_A0; |
15617 | ||
4153577a | 15618 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5717_C0) |
79d49695 MC |
15619 | tp->pci_chip_rev_id = CHIPREV_ID_5720_A0; |
15620 | ||
4153577a JP |
15621 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
15622 | tg3_asic_rev(tp) == ASIC_REV_5719 || | |
15623 | tg3_asic_rev(tp) == ASIC_REV_5720) | |
42b123b1 MC |
15624 | tg3_flag_set(tp, 5717_PLUS); |
15625 | ||
4153577a JP |
15626 | if (tg3_asic_rev(tp) == ASIC_REV_57765 || |
15627 | tg3_asic_rev(tp) == ASIC_REV_57766) | |
42b123b1 MC |
15628 | tg3_flag_set(tp, 57765_CLASS); |
15629 | ||
c65a17f4 | 15630 | if (tg3_flag(tp, 57765_CLASS) || tg3_flag(tp, 5717_PLUS) || |
4153577a | 15631 | tg3_asic_rev(tp) == ASIC_REV_5762) |
42b123b1 MC |
15632 | tg3_flag_set(tp, 57765_PLUS); |
15633 | ||
15634 | /* Intentionally exclude ASIC_REV_5906 */ | |
4153577a JP |
15635 | if (tg3_asic_rev(tp) == ASIC_REV_5755 || |
15636 | tg3_asic_rev(tp) == ASIC_REV_5787 || | |
15637 | tg3_asic_rev(tp) == ASIC_REV_5784 || | |
15638 | tg3_asic_rev(tp) == ASIC_REV_5761 || | |
15639 | tg3_asic_rev(tp) == ASIC_REV_5785 || | |
15640 | tg3_asic_rev(tp) == ASIC_REV_57780 || | |
42b123b1 MC |
15641 | tg3_flag(tp, 57765_PLUS)) |
15642 | tg3_flag_set(tp, 5755_PLUS); | |
15643 | ||
4153577a JP |
15644 | if (tg3_asic_rev(tp) == ASIC_REV_5780 || |
15645 | tg3_asic_rev(tp) == ASIC_REV_5714) | |
42b123b1 MC |
15646 | tg3_flag_set(tp, 5780_CLASS); |
15647 | ||
4153577a JP |
15648 | if (tg3_asic_rev(tp) == ASIC_REV_5750 || |
15649 | tg3_asic_rev(tp) == ASIC_REV_5752 || | |
15650 | tg3_asic_rev(tp) == ASIC_REV_5906 || | |
42b123b1 MC |
15651 | tg3_flag(tp, 5755_PLUS) || |
15652 | tg3_flag(tp, 5780_CLASS)) | |
15653 | tg3_flag_set(tp, 5750_PLUS); | |
15654 | ||
4153577a | 15655 | if (tg3_asic_rev(tp) == ASIC_REV_5705 || |
42b123b1 MC |
15656 | tg3_flag(tp, 5750_PLUS)) |
15657 | tg3_flag_set(tp, 5705_PLUS); | |
15658 | } | |
15659 | ||
3d567e0e NNS |
15660 | static bool tg3_10_100_only_device(struct tg3 *tp, |
15661 | const struct pci_device_id *ent) | |
15662 | { | |
15663 | u32 grc_misc_cfg = tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK; | |
15664 | ||
4153577a JP |
15665 | if ((tg3_asic_rev(tp) == ASIC_REV_5703 && |
15666 | (grc_misc_cfg == 0x8000 || grc_misc_cfg == 0x4000)) || | |
3d567e0e NNS |
15667 | (tp->phy_flags & TG3_PHYFLG_IS_FET)) |
15668 | return true; | |
15669 | ||
15670 | if (ent->driver_data & TG3_DRV_DATA_FLAG_10_100_ONLY) { | |
4153577a | 15671 | if (tg3_asic_rev(tp) == ASIC_REV_5705) { |
3d567e0e NNS |
15672 | if (ent->driver_data & TG3_DRV_DATA_FLAG_5705_10_100) |
15673 | return true; | |
15674 | } else { | |
15675 | return true; | |
15676 | } | |
15677 | } | |
15678 | ||
15679 | return false; | |
15680 | } | |
15681 | ||
1dd06ae8 | 15682 | static int tg3_get_invariants(struct tg3 *tp, const struct pci_device_id *ent) |
1da177e4 | 15683 | { |
1da177e4 | 15684 | u32 misc_ctrl_reg; |
1da177e4 LT |
15685 | u32 pci_state_reg, grc_misc_cfg; |
15686 | u32 val; | |
15687 | u16 pci_cmd; | |
5e7dfd0f | 15688 | int err; |
1da177e4 | 15689 | |
1da177e4 LT |
15690 | /* Force memory write invalidate off. If we leave it on, |
15691 | * then on 5700_BX chips we have to enable a workaround. | |
15692 | * The workaround is to set the TG3PCI_DMA_RW_CTRL boundary | |
15693 | * to match the cacheline size. The Broadcom driver have this | |
15694 | * workaround but turns MWI off all the times so never uses | |
15695 | * it. This seems to suggest that the workaround is insufficient. | |
15696 | */ | |
15697 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); | |
15698 | pci_cmd &= ~PCI_COMMAND_INVALIDATE; | |
15699 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); | |
15700 | ||
16821285 MC |
15701 | /* Important! -- Make sure register accesses are byteswapped |
15702 | * correctly. Also, for those chips that require it, make | |
15703 | * sure that indirect register accesses are enabled before | |
15704 | * the first operation. | |
1da177e4 LT |
15705 | */ |
15706 | pci_read_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
15707 | &misc_ctrl_reg); | |
16821285 MC |
15708 | tp->misc_host_ctrl |= (misc_ctrl_reg & |
15709 | MISC_HOST_CTRL_CHIPREV); | |
15710 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
15711 | tp->misc_host_ctrl); | |
1da177e4 | 15712 | |
42b123b1 | 15713 | tg3_detect_asic_rev(tp, misc_ctrl_reg); |
ff645bec | 15714 | |
6892914f MC |
15715 | /* If we have 5702/03 A1 or A2 on certain ICH chipsets, |
15716 | * we need to disable memory and use config. cycles | |
15717 | * only to access all registers. The 5702/03 chips | |
15718 | * can mistakenly decode the special cycles from the | |
15719 | * ICH chipsets as memory write cycles, causing corruption | |
15720 | * of register and memory space. Only certain ICH bridges | |
15721 | * will drive special cycles with non-zero data during the | |
15722 | * address phase which can fall within the 5703's address | |
15723 | * range. This is not an ICH bug as the PCI spec allows | |
15724 | * non-zero address during special cycles. However, only | |
15725 | * these ICH bridges are known to drive non-zero addresses | |
15726 | * during special cycles. | |
15727 | * | |
15728 | * Since special cycles do not cross PCI bridges, we only | |
15729 | * enable this workaround if the 5703 is on the secondary | |
15730 | * bus of these ICH bridges. | |
15731 | */ | |
4153577a JP |
15732 | if ((tg3_chip_rev_id(tp) == CHIPREV_ID_5703_A1) || |
15733 | (tg3_chip_rev_id(tp) == CHIPREV_ID_5703_A2)) { | |
6892914f MC |
15734 | static struct tg3_dev_id { |
15735 | u32 vendor; | |
15736 | u32 device; | |
15737 | u32 rev; | |
15738 | } ich_chipsets[] = { | |
15739 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_8, | |
15740 | PCI_ANY_ID }, | |
15741 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_8, | |
15742 | PCI_ANY_ID }, | |
15743 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_11, | |
15744 | 0xa }, | |
15745 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_6, | |
15746 | PCI_ANY_ID }, | |
15747 | { }, | |
15748 | }; | |
15749 | struct tg3_dev_id *pci_id = &ich_chipsets[0]; | |
15750 | struct pci_dev *bridge = NULL; | |
15751 | ||
15752 | while (pci_id->vendor != 0) { | |
15753 | bridge = pci_get_device(pci_id->vendor, pci_id->device, | |
15754 | bridge); | |
15755 | if (!bridge) { | |
15756 | pci_id++; | |
15757 | continue; | |
15758 | } | |
15759 | if (pci_id->rev != PCI_ANY_ID) { | |
44c10138 | 15760 | if (bridge->revision > pci_id->rev) |
6892914f MC |
15761 | continue; |
15762 | } | |
15763 | if (bridge->subordinate && | |
15764 | (bridge->subordinate->number == | |
15765 | tp->pdev->bus->number)) { | |
63c3a66f | 15766 | tg3_flag_set(tp, ICH_WORKAROUND); |
6892914f MC |
15767 | pci_dev_put(bridge); |
15768 | break; | |
15769 | } | |
15770 | } | |
15771 | } | |
15772 | ||
4153577a | 15773 | if (tg3_asic_rev(tp) == ASIC_REV_5701) { |
41588ba1 MC |
15774 | static struct tg3_dev_id { |
15775 | u32 vendor; | |
15776 | u32 device; | |
15777 | } bridge_chipsets[] = { | |
15778 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0 }, | |
15779 | { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1 }, | |
15780 | { }, | |
15781 | }; | |
15782 | struct tg3_dev_id *pci_id = &bridge_chipsets[0]; | |
15783 | struct pci_dev *bridge = NULL; | |
15784 | ||
15785 | while (pci_id->vendor != 0) { | |
15786 | bridge = pci_get_device(pci_id->vendor, | |
15787 | pci_id->device, | |
15788 | bridge); | |
15789 | if (!bridge) { | |
15790 | pci_id++; | |
15791 | continue; | |
15792 | } | |
15793 | if (bridge->subordinate && | |
15794 | (bridge->subordinate->number <= | |
15795 | tp->pdev->bus->number) && | |
b918c62e | 15796 | (bridge->subordinate->busn_res.end >= |
41588ba1 | 15797 | tp->pdev->bus->number)) { |
63c3a66f | 15798 | tg3_flag_set(tp, 5701_DMA_BUG); |
41588ba1 MC |
15799 | pci_dev_put(bridge); |
15800 | break; | |
15801 | } | |
15802 | } | |
15803 | } | |
15804 | ||
4a29cc2e MC |
15805 | /* The EPB bridge inside 5714, 5715, and 5780 cannot support |
15806 | * DMA addresses > 40-bit. This bridge may have other additional | |
15807 | * 57xx devices behind it in some 4-port NIC designs for example. | |
15808 | * Any tg3 device found behind the bridge will also need the 40-bit | |
15809 | * DMA workaround. | |
15810 | */ | |
42b123b1 | 15811 | if (tg3_flag(tp, 5780_CLASS)) { |
63c3a66f | 15812 | tg3_flag_set(tp, 40BIT_DMA_BUG); |
4cf78e4f | 15813 | tp->msi_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_MSI); |
859a5887 | 15814 | } else { |
4a29cc2e MC |
15815 | struct pci_dev *bridge = NULL; |
15816 | ||
15817 | do { | |
15818 | bridge = pci_get_device(PCI_VENDOR_ID_SERVERWORKS, | |
15819 | PCI_DEVICE_ID_SERVERWORKS_EPB, | |
15820 | bridge); | |
15821 | if (bridge && bridge->subordinate && | |
15822 | (bridge->subordinate->number <= | |
15823 | tp->pdev->bus->number) && | |
b918c62e | 15824 | (bridge->subordinate->busn_res.end >= |
4a29cc2e | 15825 | tp->pdev->bus->number)) { |
63c3a66f | 15826 | tg3_flag_set(tp, 40BIT_DMA_BUG); |
4a29cc2e MC |
15827 | pci_dev_put(bridge); |
15828 | break; | |
15829 | } | |
15830 | } while (bridge); | |
15831 | } | |
4cf78e4f | 15832 | |
4153577a JP |
15833 | if (tg3_asic_rev(tp) == ASIC_REV_5704 || |
15834 | tg3_asic_rev(tp) == ASIC_REV_5714) | |
7544b097 MC |
15835 | tp->pdev_peer = tg3_find_peer(tp); |
15836 | ||
507399f1 | 15837 | /* Determine TSO capabilities */ |
4153577a | 15838 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5719_A0) |
4d163b75 | 15839 | ; /* Do nothing. HW bug. */ |
63c3a66f JP |
15840 | else if (tg3_flag(tp, 57765_PLUS)) |
15841 | tg3_flag_set(tp, HW_TSO_3); | |
15842 | else if (tg3_flag(tp, 5755_PLUS) || | |
4153577a | 15843 | tg3_asic_rev(tp) == ASIC_REV_5906) |
63c3a66f JP |
15844 | tg3_flag_set(tp, HW_TSO_2); |
15845 | else if (tg3_flag(tp, 5750_PLUS)) { | |
15846 | tg3_flag_set(tp, HW_TSO_1); | |
15847 | tg3_flag_set(tp, TSO_BUG); | |
4153577a JP |
15848 | if (tg3_asic_rev(tp) == ASIC_REV_5750 && |
15849 | tg3_chip_rev_id(tp) >= CHIPREV_ID_5750_C2) | |
63c3a66f | 15850 | tg3_flag_clear(tp, TSO_BUG); |
4153577a JP |
15851 | } else if (tg3_asic_rev(tp) != ASIC_REV_5700 && |
15852 | tg3_asic_rev(tp) != ASIC_REV_5701 && | |
15853 | tg3_chip_rev_id(tp) != CHIPREV_ID_5705_A0) { | |
1caf13eb MC |
15854 | tg3_flag_set(tp, FW_TSO); |
15855 | tg3_flag_set(tp, TSO_BUG); | |
4153577a | 15856 | if (tg3_asic_rev(tp) == ASIC_REV_5705) |
507399f1 MC |
15857 | tp->fw_needed = FIRMWARE_TG3TSO5; |
15858 | else | |
15859 | tp->fw_needed = FIRMWARE_TG3TSO; | |
15860 | } | |
15861 | ||
dabc5c67 | 15862 | /* Selectively allow TSO based on operating conditions */ |
6ff6f81d MC |
15863 | if (tg3_flag(tp, HW_TSO_1) || |
15864 | tg3_flag(tp, HW_TSO_2) || | |
15865 | tg3_flag(tp, HW_TSO_3) || | |
1caf13eb | 15866 | tg3_flag(tp, FW_TSO)) { |
cf9ecf4b MC |
15867 | /* For firmware TSO, assume ASF is disabled. |
15868 | * We'll disable TSO later if we discover ASF | |
15869 | * is enabled in tg3_get_eeprom_hw_cfg(). | |
15870 | */ | |
dabc5c67 | 15871 | tg3_flag_set(tp, TSO_CAPABLE); |
cf9ecf4b | 15872 | } else { |
dabc5c67 MC |
15873 | tg3_flag_clear(tp, TSO_CAPABLE); |
15874 | tg3_flag_clear(tp, TSO_BUG); | |
15875 | tp->fw_needed = NULL; | |
15876 | } | |
15877 | ||
4153577a | 15878 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0) |
dabc5c67 MC |
15879 | tp->fw_needed = FIRMWARE_TG3; |
15880 | ||
c4dab506 NS |
15881 | if (tg3_asic_rev(tp) == ASIC_REV_57766) |
15882 | tp->fw_needed = FIRMWARE_TG357766; | |
15883 | ||
507399f1 MC |
15884 | tp->irq_max = 1; |
15885 | ||
63c3a66f JP |
15886 | if (tg3_flag(tp, 5750_PLUS)) { |
15887 | tg3_flag_set(tp, SUPPORT_MSI); | |
4153577a JP |
15888 | if (tg3_chip_rev(tp) == CHIPREV_5750_AX || |
15889 | tg3_chip_rev(tp) == CHIPREV_5750_BX || | |
15890 | (tg3_asic_rev(tp) == ASIC_REV_5714 && | |
15891 | tg3_chip_rev_id(tp) <= CHIPREV_ID_5714_A2 && | |
7544b097 | 15892 | tp->pdev_peer == tp->pdev)) |
63c3a66f | 15893 | tg3_flag_clear(tp, SUPPORT_MSI); |
7544b097 | 15894 | |
63c3a66f | 15895 | if (tg3_flag(tp, 5755_PLUS) || |
4153577a | 15896 | tg3_asic_rev(tp) == ASIC_REV_5906) { |
63c3a66f | 15897 | tg3_flag_set(tp, 1SHOT_MSI); |
52c0fd83 | 15898 | } |
4f125f42 | 15899 | |
63c3a66f JP |
15900 | if (tg3_flag(tp, 57765_PLUS)) { |
15901 | tg3_flag_set(tp, SUPPORT_MSIX); | |
507399f1 MC |
15902 | tp->irq_max = TG3_IRQ_MAX_VECS; |
15903 | } | |
f6eb9b1f | 15904 | } |
0e1406dd | 15905 | |
9102426a MC |
15906 | tp->txq_max = 1; |
15907 | tp->rxq_max = 1; | |
15908 | if (tp->irq_max > 1) { | |
15909 | tp->rxq_max = TG3_RSS_MAX_NUM_QS; | |
15910 | tg3_rss_init_dflt_indir_tbl(tp, TG3_RSS_MAX_NUM_QS); | |
15911 | ||
4153577a JP |
15912 | if (tg3_asic_rev(tp) == ASIC_REV_5719 || |
15913 | tg3_asic_rev(tp) == ASIC_REV_5720) | |
9102426a MC |
15914 | tp->txq_max = tp->irq_max - 1; |
15915 | } | |
15916 | ||
b7abee6e | 15917 | if (tg3_flag(tp, 5755_PLUS) || |
4153577a | 15918 | tg3_asic_rev(tp) == ASIC_REV_5906) |
63c3a66f | 15919 | tg3_flag_set(tp, SHORT_DMA_BUG); |
f6eb9b1f | 15920 | |
4153577a | 15921 | if (tg3_asic_rev(tp) == ASIC_REV_5719) |
a4cb428d | 15922 | tp->dma_limit = TG3_TX_BD_DMA_MAX_4K; |
e31aa987 | 15923 | |
4153577a JP |
15924 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
15925 | tg3_asic_rev(tp) == ASIC_REV_5719 || | |
15926 | tg3_asic_rev(tp) == ASIC_REV_5720 || | |
15927 | tg3_asic_rev(tp) == ASIC_REV_5762) | |
63c3a66f | 15928 | tg3_flag_set(tp, LRG_PROD_RING_CAP); |
de9f5230 | 15929 | |
63c3a66f | 15930 | if (tg3_flag(tp, 57765_PLUS) && |
4153577a | 15931 | tg3_chip_rev_id(tp) != CHIPREV_ID_5719_A0) |
63c3a66f | 15932 | tg3_flag_set(tp, USE_JUMBO_BDFLAG); |
b703df6f | 15933 | |
63c3a66f JP |
15934 | if (!tg3_flag(tp, 5705_PLUS) || |
15935 | tg3_flag(tp, 5780_CLASS) || | |
15936 | tg3_flag(tp, USE_JUMBO_BDFLAG)) | |
15937 | tg3_flag_set(tp, JUMBO_CAPABLE); | |
0f893dc6 | 15938 | |
52f4490c MC |
15939 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
15940 | &pci_state_reg); | |
15941 | ||
708ebb3a | 15942 | if (pci_is_pcie(tp->pdev)) { |
5e7dfd0f MC |
15943 | u16 lnkctl; |
15944 | ||
63c3a66f | 15945 | tg3_flag_set(tp, PCI_EXPRESS); |
5f5c51e3 | 15946 | |
0f49bfbd | 15947 | pcie_capability_read_word(tp->pdev, PCI_EXP_LNKCTL, &lnkctl); |
5e7dfd0f | 15948 | if (lnkctl & PCI_EXP_LNKCTL_CLKREQ_EN) { |
4153577a | 15949 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
63c3a66f | 15950 | tg3_flag_clear(tp, HW_TSO_2); |
dabc5c67 | 15951 | tg3_flag_clear(tp, TSO_CAPABLE); |
7196cd6c | 15952 | } |
4153577a JP |
15953 | if (tg3_asic_rev(tp) == ASIC_REV_5784 || |
15954 | tg3_asic_rev(tp) == ASIC_REV_5761 || | |
15955 | tg3_chip_rev_id(tp) == CHIPREV_ID_57780_A0 || | |
15956 | tg3_chip_rev_id(tp) == CHIPREV_ID_57780_A1) | |
63c3a66f | 15957 | tg3_flag_set(tp, CLKREQ_BUG); |
4153577a | 15958 | } else if (tg3_chip_rev_id(tp) == CHIPREV_ID_5717_A0) { |
63c3a66f | 15959 | tg3_flag_set(tp, L1PLLPD_EN); |
c7835a77 | 15960 | } |
4153577a | 15961 | } else if (tg3_asic_rev(tp) == ASIC_REV_5785) { |
708ebb3a JM |
15962 | /* BCM5785 devices are effectively PCIe devices, and should |
15963 | * follow PCIe codepaths, but do not have a PCIe capabilities | |
15964 | * section. | |
93a700a9 | 15965 | */ |
63c3a66f JP |
15966 | tg3_flag_set(tp, PCI_EXPRESS); |
15967 | } else if (!tg3_flag(tp, 5705_PLUS) || | |
15968 | tg3_flag(tp, 5780_CLASS)) { | |
52f4490c MC |
15969 | tp->pcix_cap = pci_find_capability(tp->pdev, PCI_CAP_ID_PCIX); |
15970 | if (!tp->pcix_cap) { | |
2445e461 MC |
15971 | dev_err(&tp->pdev->dev, |
15972 | "Cannot find PCI-X capability, aborting\n"); | |
52f4490c MC |
15973 | return -EIO; |
15974 | } | |
15975 | ||
15976 | if (!(pci_state_reg & PCISTATE_CONV_PCI_MODE)) | |
63c3a66f | 15977 | tg3_flag_set(tp, PCIX_MODE); |
52f4490c | 15978 | } |
1da177e4 | 15979 | |
399de50b MC |
15980 | /* If we have an AMD 762 or VIA K8T800 chipset, write |
15981 | * reordering to the mailbox registers done by the host | |
15982 | * controller can cause major troubles. We read back from | |
15983 | * every mailbox register write to force the writes to be | |
15984 | * posted to the chip in order. | |
15985 | */ | |
4143470c | 15986 | if (pci_dev_present(tg3_write_reorder_chipsets) && |
63c3a66f JP |
15987 | !tg3_flag(tp, PCI_EXPRESS)) |
15988 | tg3_flag_set(tp, MBOX_WRITE_REORDER); | |
399de50b | 15989 | |
69fc4053 MC |
15990 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, |
15991 | &tp->pci_cacheline_sz); | |
15992 | pci_read_config_byte(tp->pdev, PCI_LATENCY_TIMER, | |
15993 | &tp->pci_lat_timer); | |
4153577a | 15994 | if (tg3_asic_rev(tp) == ASIC_REV_5703 && |
1da177e4 LT |
15995 | tp->pci_lat_timer < 64) { |
15996 | tp->pci_lat_timer = 64; | |
69fc4053 MC |
15997 | pci_write_config_byte(tp->pdev, PCI_LATENCY_TIMER, |
15998 | tp->pci_lat_timer); | |
1da177e4 LT |
15999 | } |
16000 | ||
16821285 MC |
16001 | /* Important! -- It is critical that the PCI-X hw workaround |
16002 | * situation is decided before the first MMIO register access. | |
16003 | */ | |
4153577a | 16004 | if (tg3_chip_rev(tp) == CHIPREV_5700_BX) { |
52f4490c MC |
16005 | /* 5700 BX chips need to have their TX producer index |
16006 | * mailboxes written twice to workaround a bug. | |
16007 | */ | |
63c3a66f | 16008 | tg3_flag_set(tp, TXD_MBOX_HWBUG); |
1da177e4 | 16009 | |
52f4490c | 16010 | /* If we are in PCI-X mode, enable register write workaround. |
1da177e4 LT |
16011 | * |
16012 | * The workaround is to use indirect register accesses | |
16013 | * for all chip writes not to mailbox registers. | |
16014 | */ | |
63c3a66f | 16015 | if (tg3_flag(tp, PCIX_MODE)) { |
1da177e4 | 16016 | u32 pm_reg; |
1da177e4 | 16017 | |
63c3a66f | 16018 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
1da177e4 LT |
16019 | |
16020 | /* The chip can have it's power management PCI config | |
16021 | * space registers clobbered due to this bug. | |
16022 | * So explicitly force the chip into D0 here. | |
16023 | */ | |
9974a356 MC |
16024 | pci_read_config_dword(tp->pdev, |
16025 | tp->pm_cap + PCI_PM_CTRL, | |
1da177e4 LT |
16026 | &pm_reg); |
16027 | pm_reg &= ~PCI_PM_CTRL_STATE_MASK; | |
16028 | pm_reg |= PCI_PM_CTRL_PME_ENABLE | 0 /* D0 */; | |
9974a356 MC |
16029 | pci_write_config_dword(tp->pdev, |
16030 | tp->pm_cap + PCI_PM_CTRL, | |
1da177e4 LT |
16031 | pm_reg); |
16032 | ||
16033 | /* Also, force SERR#/PERR# in PCI command. */ | |
16034 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); | |
16035 | pci_cmd |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR; | |
16036 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); | |
16037 | } | |
16038 | } | |
16039 | ||
1da177e4 | 16040 | if ((pci_state_reg & PCISTATE_BUS_SPEED_HIGH) != 0) |
63c3a66f | 16041 | tg3_flag_set(tp, PCI_HIGH_SPEED); |
1da177e4 | 16042 | if ((pci_state_reg & PCISTATE_BUS_32BIT) != 0) |
63c3a66f | 16043 | tg3_flag_set(tp, PCI_32BIT); |
1da177e4 LT |
16044 | |
16045 | /* Chip-specific fixup from Broadcom driver */ | |
4153577a | 16046 | if ((tg3_chip_rev_id(tp) == CHIPREV_ID_5704_A0) && |
1da177e4 LT |
16047 | (!(pci_state_reg & PCISTATE_RETRY_SAME_DMA))) { |
16048 | pci_state_reg |= PCISTATE_RETRY_SAME_DMA; | |
16049 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, pci_state_reg); | |
16050 | } | |
16051 | ||
1ee582d8 | 16052 | /* Default fast path register access methods */ |
20094930 | 16053 | tp->read32 = tg3_read32; |
1ee582d8 | 16054 | tp->write32 = tg3_write32; |
09ee929c | 16055 | tp->read32_mbox = tg3_read32; |
20094930 | 16056 | tp->write32_mbox = tg3_write32; |
1ee582d8 MC |
16057 | tp->write32_tx_mbox = tg3_write32; |
16058 | tp->write32_rx_mbox = tg3_write32; | |
16059 | ||
16060 | /* Various workaround register access methods */ | |
63c3a66f | 16061 | if (tg3_flag(tp, PCIX_TARGET_HWBUG)) |
1ee582d8 | 16062 | tp->write32 = tg3_write_indirect_reg32; |
4153577a | 16063 | else if (tg3_asic_rev(tp) == ASIC_REV_5701 || |
63c3a66f | 16064 | (tg3_flag(tp, PCI_EXPRESS) && |
4153577a | 16065 | tg3_chip_rev_id(tp) == CHIPREV_ID_5750_A0)) { |
98efd8a6 MC |
16066 | /* |
16067 | * Back to back register writes can cause problems on these | |
16068 | * chips, the workaround is to read back all reg writes | |
16069 | * except those to mailbox regs. | |
16070 | * | |
16071 | * See tg3_write_indirect_reg32(). | |
16072 | */ | |
1ee582d8 | 16073 | tp->write32 = tg3_write_flush_reg32; |
98efd8a6 MC |
16074 | } |
16075 | ||
63c3a66f | 16076 | if (tg3_flag(tp, TXD_MBOX_HWBUG) || tg3_flag(tp, MBOX_WRITE_REORDER)) { |
1ee582d8 | 16077 | tp->write32_tx_mbox = tg3_write32_tx_mbox; |
63c3a66f | 16078 | if (tg3_flag(tp, MBOX_WRITE_REORDER)) |
1ee582d8 MC |
16079 | tp->write32_rx_mbox = tg3_write_flush_reg32; |
16080 | } | |
20094930 | 16081 | |
63c3a66f | 16082 | if (tg3_flag(tp, ICH_WORKAROUND)) { |
6892914f MC |
16083 | tp->read32 = tg3_read_indirect_reg32; |
16084 | tp->write32 = tg3_write_indirect_reg32; | |
16085 | tp->read32_mbox = tg3_read_indirect_mbox; | |
16086 | tp->write32_mbox = tg3_write_indirect_mbox; | |
16087 | tp->write32_tx_mbox = tg3_write_indirect_mbox; | |
16088 | tp->write32_rx_mbox = tg3_write_indirect_mbox; | |
16089 | ||
16090 | iounmap(tp->regs); | |
22abe310 | 16091 | tp->regs = NULL; |
6892914f MC |
16092 | |
16093 | pci_read_config_word(tp->pdev, PCI_COMMAND, &pci_cmd); | |
16094 | pci_cmd &= ~PCI_COMMAND_MEMORY; | |
16095 | pci_write_config_word(tp->pdev, PCI_COMMAND, pci_cmd); | |
16096 | } | |
4153577a | 16097 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
b5d3772c MC |
16098 | tp->read32_mbox = tg3_read32_mbox_5906; |
16099 | tp->write32_mbox = tg3_write32_mbox_5906; | |
16100 | tp->write32_tx_mbox = tg3_write32_mbox_5906; | |
16101 | tp->write32_rx_mbox = tg3_write32_mbox_5906; | |
16102 | } | |
6892914f | 16103 | |
bbadf503 | 16104 | if (tp->write32 == tg3_write_indirect_reg32 || |
63c3a66f | 16105 | (tg3_flag(tp, PCIX_MODE) && |
4153577a JP |
16106 | (tg3_asic_rev(tp) == ASIC_REV_5700 || |
16107 | tg3_asic_rev(tp) == ASIC_REV_5701))) | |
63c3a66f | 16108 | tg3_flag_set(tp, SRAM_USE_CONFIG); |
bbadf503 | 16109 | |
16821285 MC |
16110 | /* The memory arbiter has to be enabled in order for SRAM accesses |
16111 | * to succeed. Normally on powerup the tg3 chip firmware will make | |
16112 | * sure it is enabled, but other entities such as system netboot | |
16113 | * code might disable it. | |
16114 | */ | |
16115 | val = tr32(MEMARB_MODE); | |
16116 | tw32(MEMARB_MODE, val | MEMARB_MODE_ENABLE); | |
16117 | ||
9dc5e342 | 16118 | tp->pci_fn = PCI_FUNC(tp->pdev->devfn) & 3; |
4153577a | 16119 | if (tg3_asic_rev(tp) == ASIC_REV_5704 || |
9dc5e342 MC |
16120 | tg3_flag(tp, 5780_CLASS)) { |
16121 | if (tg3_flag(tp, PCIX_MODE)) { | |
16122 | pci_read_config_dword(tp->pdev, | |
16123 | tp->pcix_cap + PCI_X_STATUS, | |
16124 | &val); | |
16125 | tp->pci_fn = val & 0x7; | |
16126 | } | |
4153577a JP |
16127 | } else if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
16128 | tg3_asic_rev(tp) == ASIC_REV_5719 || | |
16129 | tg3_asic_rev(tp) == ASIC_REV_5720) { | |
9dc5e342 | 16130 | tg3_read_mem(tp, NIC_SRAM_CPMU_STATUS, &val); |
857001f0 MC |
16131 | if ((val & NIC_SRAM_CPMUSTAT_SIG_MSK) != NIC_SRAM_CPMUSTAT_SIG) |
16132 | val = tr32(TG3_CPMU_STATUS); | |
16133 | ||
4153577a | 16134 | if (tg3_asic_rev(tp) == ASIC_REV_5717) |
857001f0 MC |
16135 | tp->pci_fn = (val & TG3_CPMU_STATUS_FMSK_5717) ? 1 : 0; |
16136 | else | |
9dc5e342 MC |
16137 | tp->pci_fn = (val & TG3_CPMU_STATUS_FMSK_5719) >> |
16138 | TG3_CPMU_STATUS_FSHFT_5719; | |
69f11c99 MC |
16139 | } |
16140 | ||
7e6c63f0 HM |
16141 | if (tg3_flag(tp, FLUSH_POSTED_WRITES)) { |
16142 | tp->write32_tx_mbox = tg3_write_flush_reg32; | |
16143 | tp->write32_rx_mbox = tg3_write_flush_reg32; | |
16144 | } | |
16145 | ||
7d0c41ef | 16146 | /* Get eeprom hw config before calling tg3_set_power_state(). |
63c3a66f | 16147 | * In particular, the TG3_FLAG_IS_NIC flag must be |
7d0c41ef MC |
16148 | * determined before calling tg3_set_power_state() so that |
16149 | * we know whether or not to switch out of Vaux power. | |
16150 | * When the flag is set, it means that GPIO1 is used for eeprom | |
16151 | * write protect and also implies that it is a LOM where GPIOs | |
16152 | * are not used to switch power. | |
6aa20a22 | 16153 | */ |
7d0c41ef MC |
16154 | tg3_get_eeprom_hw_cfg(tp); |
16155 | ||
1caf13eb | 16156 | if (tg3_flag(tp, FW_TSO) && tg3_flag(tp, ENABLE_ASF)) { |
cf9ecf4b MC |
16157 | tg3_flag_clear(tp, TSO_CAPABLE); |
16158 | tg3_flag_clear(tp, TSO_BUG); | |
16159 | tp->fw_needed = NULL; | |
16160 | } | |
16161 | ||
63c3a66f | 16162 | if (tg3_flag(tp, ENABLE_APE)) { |
0d3031d9 MC |
16163 | /* Allow reads and writes to the |
16164 | * APE register and memory space. | |
16165 | */ | |
16166 | pci_state_reg |= PCISTATE_ALLOW_APE_CTLSPC_WR | | |
f92d9dc1 MC |
16167 | PCISTATE_ALLOW_APE_SHMEM_WR | |
16168 | PCISTATE_ALLOW_APE_PSPACE_WR; | |
0d3031d9 MC |
16169 | pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, |
16170 | pci_state_reg); | |
c9cab24e MC |
16171 | |
16172 | tg3_ape_lock_init(tp); | |
0d3031d9 MC |
16173 | } |
16174 | ||
16821285 MC |
16175 | /* Set up tp->grc_local_ctrl before calling |
16176 | * tg3_pwrsrc_switch_to_vmain(). GPIO1 driven high | |
16177 | * will bring 5700's external PHY out of reset. | |
314fba34 MC |
16178 | * It is also used as eeprom write protect on LOMs. |
16179 | */ | |
16180 | tp->grc_local_ctrl = GRC_LCLCTRL_INT_ON_ATTN | GRC_LCLCTRL_AUTO_SEEPROM; | |
4153577a | 16181 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
63c3a66f | 16182 | tg3_flag(tp, EEPROM_WRITE_PROT)) |
314fba34 MC |
16183 | tp->grc_local_ctrl |= (GRC_LCLCTRL_GPIO_OE1 | |
16184 | GRC_LCLCTRL_GPIO_OUTPUT1); | |
3e7d83bc MC |
16185 | /* Unused GPIO3 must be driven as output on 5752 because there |
16186 | * are no pull-up resistors on unused GPIO pins. | |
16187 | */ | |
4153577a | 16188 | else if (tg3_asic_rev(tp) == ASIC_REV_5752) |
3e7d83bc | 16189 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE3; |
314fba34 | 16190 | |
4153577a JP |
16191 | if (tg3_asic_rev(tp) == ASIC_REV_5755 || |
16192 | tg3_asic_rev(tp) == ASIC_REV_57780 || | |
55086ad9 | 16193 | tg3_flag(tp, 57765_CLASS)) |
af36e6b6 MC |
16194 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; |
16195 | ||
8d519ab2 MC |
16196 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
16197 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S) { | |
5f0c4a3c MC |
16198 | /* Turn off the debug UART. */ |
16199 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_UART_SEL; | |
63c3a66f | 16200 | if (tg3_flag(tp, IS_NIC)) |
5f0c4a3c MC |
16201 | /* Keep VMain power. */ |
16202 | tp->grc_local_ctrl |= GRC_LCLCTRL_GPIO_OE0 | | |
16203 | GRC_LCLCTRL_GPIO_OUTPUT0; | |
16204 | } | |
16205 | ||
4153577a | 16206 | if (tg3_asic_rev(tp) == ASIC_REV_5762) |
c86a8560 MC |
16207 | tp->grc_local_ctrl |= |
16208 | tr32(GRC_LOCAL_CTRL) & GRC_LCLCTRL_GPIO_UART_SEL; | |
16209 | ||
16821285 MC |
16210 | /* Switch out of Vaux if it is a NIC */ |
16211 | tg3_pwrsrc_switch_to_vmain(tp); | |
1da177e4 | 16212 | |
1da177e4 LT |
16213 | /* Derive initial jumbo mode from MTU assigned in |
16214 | * ether_setup() via the alloc_etherdev() call | |
16215 | */ | |
63c3a66f JP |
16216 | if (tp->dev->mtu > ETH_DATA_LEN && !tg3_flag(tp, 5780_CLASS)) |
16217 | tg3_flag_set(tp, JUMBO_RING_ENABLE); | |
1da177e4 LT |
16218 | |
16219 | /* Determine WakeOnLan speed to use. */ | |
4153577a JP |
16220 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
16221 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0 || | |
16222 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B0 || | |
16223 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B2) { | |
63c3a66f | 16224 | tg3_flag_clear(tp, WOL_SPEED_100MB); |
1da177e4 | 16225 | } else { |
63c3a66f | 16226 | tg3_flag_set(tp, WOL_SPEED_100MB); |
1da177e4 LT |
16227 | } |
16228 | ||
4153577a | 16229 | if (tg3_asic_rev(tp) == ASIC_REV_5906) |
f07e9af3 | 16230 | tp->phy_flags |= TG3_PHYFLG_IS_FET; |
7f97a4bd | 16231 | |
1da177e4 | 16232 | /* A few boards don't want Ethernet@WireSpeed phy feature */ |
4153577a JP |
16233 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
16234 | (tg3_asic_rev(tp) == ASIC_REV_5705 && | |
16235 | (tg3_chip_rev_id(tp) != CHIPREV_ID_5705_A0) && | |
16236 | (tg3_chip_rev_id(tp) != CHIPREV_ID_5705_A1)) || | |
f07e9af3 MC |
16237 | (tp->phy_flags & TG3_PHYFLG_IS_FET) || |
16238 | (tp->phy_flags & TG3_PHYFLG_ANY_SERDES)) | |
16239 | tp->phy_flags |= TG3_PHYFLG_NO_ETH_WIRE_SPEED; | |
1da177e4 | 16240 | |
4153577a JP |
16241 | if (tg3_chip_rev(tp) == CHIPREV_5703_AX || |
16242 | tg3_chip_rev(tp) == CHIPREV_5704_AX) | |
f07e9af3 | 16243 | tp->phy_flags |= TG3_PHYFLG_ADC_BUG; |
4153577a | 16244 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5704_A0) |
f07e9af3 | 16245 | tp->phy_flags |= TG3_PHYFLG_5704_A0_BUG; |
1da177e4 | 16246 | |
63c3a66f | 16247 | if (tg3_flag(tp, 5705_PLUS) && |
f07e9af3 | 16248 | !(tp->phy_flags & TG3_PHYFLG_IS_FET) && |
4153577a JP |
16249 | tg3_asic_rev(tp) != ASIC_REV_5785 && |
16250 | tg3_asic_rev(tp) != ASIC_REV_57780 && | |
63c3a66f | 16251 | !tg3_flag(tp, 57765_PLUS)) { |
4153577a JP |
16252 | if (tg3_asic_rev(tp) == ASIC_REV_5755 || |
16253 | tg3_asic_rev(tp) == ASIC_REV_5787 || | |
16254 | tg3_asic_rev(tp) == ASIC_REV_5784 || | |
16255 | tg3_asic_rev(tp) == ASIC_REV_5761) { | |
d4011ada MC |
16256 | if (tp->pdev->device != PCI_DEVICE_ID_TIGON3_5756 && |
16257 | tp->pdev->device != PCI_DEVICE_ID_TIGON3_5722) | |
f07e9af3 | 16258 | tp->phy_flags |= TG3_PHYFLG_JITTER_BUG; |
c1d2a196 | 16259 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5755M) |
f07e9af3 | 16260 | tp->phy_flags |= TG3_PHYFLG_ADJUST_TRIM; |
321d32a0 | 16261 | } else |
f07e9af3 | 16262 | tp->phy_flags |= TG3_PHYFLG_BER_BUG; |
c424cb24 | 16263 | } |
1da177e4 | 16264 | |
4153577a JP |
16265 | if (tg3_asic_rev(tp) == ASIC_REV_5784 && |
16266 | tg3_chip_rev(tp) != CHIPREV_5784_AX) { | |
b2a5c19c MC |
16267 | tp->phy_otp = tg3_read_otp_phycfg(tp); |
16268 | if (tp->phy_otp == 0) | |
16269 | tp->phy_otp = TG3_OTP_DEFAULT; | |
16270 | } | |
16271 | ||
63c3a66f | 16272 | if (tg3_flag(tp, CPMU_PRESENT)) |
8ef21428 MC |
16273 | tp->mi_mode = MAC_MI_MODE_500KHZ_CONST; |
16274 | else | |
16275 | tp->mi_mode = MAC_MI_MODE_BASE; | |
16276 | ||
1da177e4 | 16277 | tp->coalesce_mode = 0; |
4153577a JP |
16278 | if (tg3_chip_rev(tp) != CHIPREV_5700_AX && |
16279 | tg3_chip_rev(tp) != CHIPREV_5700_BX) | |
1da177e4 LT |
16280 | tp->coalesce_mode |= HOSTCC_MODE_32BYTE; |
16281 | ||
4d958473 | 16282 | /* Set these bits to enable statistics workaround. */ |
4153577a JP |
16283 | if (tg3_asic_rev(tp) == ASIC_REV_5717 || |
16284 | tg3_chip_rev_id(tp) == CHIPREV_ID_5719_A0 || | |
16285 | tg3_chip_rev_id(tp) == CHIPREV_ID_5720_A0) { | |
4d958473 MC |
16286 | tp->coalesce_mode |= HOSTCC_MODE_ATTN; |
16287 | tp->grc_mode |= GRC_MODE_IRQ_ON_FLOW_ATTN; | |
16288 | } | |
16289 | ||
4153577a JP |
16290 | if (tg3_asic_rev(tp) == ASIC_REV_5785 || |
16291 | tg3_asic_rev(tp) == ASIC_REV_57780) | |
63c3a66f | 16292 | tg3_flag_set(tp, USE_PHYLIB); |
57e6983c | 16293 | |
158d7abd MC |
16294 | err = tg3_mdio_init(tp); |
16295 | if (err) | |
16296 | return err; | |
1da177e4 LT |
16297 | |
16298 | /* Initialize data/descriptor byte/word swapping. */ | |
16299 | val = tr32(GRC_MODE); | |
4153577a JP |
16300 | if (tg3_asic_rev(tp) == ASIC_REV_5720 || |
16301 | tg3_asic_rev(tp) == ASIC_REV_5762) | |
f2096f94 MC |
16302 | val &= (GRC_MODE_BYTE_SWAP_B2HRX_DATA | |
16303 | GRC_MODE_WORD_SWAP_B2HRX_DATA | | |
16304 | GRC_MODE_B2HRX_ENABLE | | |
16305 | GRC_MODE_HTX2B_ENABLE | | |
16306 | GRC_MODE_HOST_STACKUP); | |
16307 | else | |
16308 | val &= GRC_MODE_HOST_STACKUP; | |
16309 | ||
1da177e4 LT |
16310 | tw32(GRC_MODE, val | tp->grc_mode); |
16311 | ||
16312 | tg3_switch_clocks(tp); | |
16313 | ||
16314 | /* Clear this out for sanity. */ | |
16315 | tw32(TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
16316 | ||
fa57cd8a NG |
16317 | /* Clear TG3PCI_REG_BASE_ADDR to prevent hangs. */ |
16318 | tw32(TG3PCI_REG_BASE_ADDR, 0); | |
16319 | ||
1da177e4 LT |
16320 | pci_read_config_dword(tp->pdev, TG3PCI_PCISTATE, |
16321 | &pci_state_reg); | |
16322 | if ((pci_state_reg & PCISTATE_CONV_PCI_MODE) == 0 && | |
63c3a66f | 16323 | !tg3_flag(tp, PCIX_TARGET_HWBUG)) { |
4153577a JP |
16324 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5701_A0 || |
16325 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B0 || | |
16326 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B2 || | |
16327 | tg3_chip_rev_id(tp) == CHIPREV_ID_5701_B5) { | |
1da177e4 LT |
16328 | void __iomem *sram_base; |
16329 | ||
16330 | /* Write some dummy words into the SRAM status block | |
16331 | * area, see if it reads back correctly. If the return | |
16332 | * value is bad, force enable the PCIX workaround. | |
16333 | */ | |
16334 | sram_base = tp->regs + NIC_SRAM_WIN_BASE + NIC_SRAM_STATS_BLK; | |
16335 | ||
16336 | writel(0x00000000, sram_base); | |
16337 | writel(0x00000000, sram_base + 4); | |
16338 | writel(0xffffffff, sram_base + 4); | |
16339 | if (readl(sram_base) != 0x00000000) | |
63c3a66f | 16340 | tg3_flag_set(tp, PCIX_TARGET_HWBUG); |
1da177e4 LT |
16341 | } |
16342 | } | |
16343 | ||
16344 | udelay(50); | |
16345 | tg3_nvram_init(tp); | |
16346 | ||
c4dab506 NS |
16347 | /* If the device has an NVRAM, no need to load patch firmware */ |
16348 | if (tg3_asic_rev(tp) == ASIC_REV_57766 && | |
16349 | !tg3_flag(tp, NO_NVRAM)) | |
16350 | tp->fw_needed = NULL; | |
16351 | ||
1da177e4 LT |
16352 | grc_misc_cfg = tr32(GRC_MISC_CFG); |
16353 | grc_misc_cfg &= GRC_MISC_CFG_BOARD_ID_MASK; | |
16354 | ||
4153577a | 16355 | if (tg3_asic_rev(tp) == ASIC_REV_5705 && |
1da177e4 LT |
16356 | (grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788 || |
16357 | grc_misc_cfg == GRC_MISC_CFG_BOARD_ID_5788M)) | |
63c3a66f | 16358 | tg3_flag_set(tp, IS_5788); |
1da177e4 | 16359 | |
63c3a66f | 16360 | if (!tg3_flag(tp, IS_5788) && |
4153577a | 16361 | tg3_asic_rev(tp) != ASIC_REV_5700) |
63c3a66f JP |
16362 | tg3_flag_set(tp, TAGGED_STATUS); |
16363 | if (tg3_flag(tp, TAGGED_STATUS)) { | |
fac9b83e DM |
16364 | tp->coalesce_mode |= (HOSTCC_MODE_CLRTICK_RXBD | |
16365 | HOSTCC_MODE_CLRTICK_TXBD); | |
16366 | ||
16367 | tp->misc_host_ctrl |= MISC_HOST_CTRL_TAGGED_STATUS; | |
16368 | pci_write_config_dword(tp->pdev, TG3PCI_MISC_HOST_CTRL, | |
16369 | tp->misc_host_ctrl); | |
16370 | } | |
16371 | ||
3bda1258 | 16372 | /* Preserve the APE MAC_MODE bits */ |
63c3a66f | 16373 | if (tg3_flag(tp, ENABLE_APE)) |
d2394e6b | 16374 | tp->mac_mode = MAC_MODE_APE_TX_EN | MAC_MODE_APE_RX_EN; |
3bda1258 | 16375 | else |
6e01b20b | 16376 | tp->mac_mode = 0; |
3bda1258 | 16377 | |
3d567e0e | 16378 | if (tg3_10_100_only_device(tp, ent)) |
f07e9af3 | 16379 | tp->phy_flags |= TG3_PHYFLG_10_100_ONLY; |
1da177e4 LT |
16380 | |
16381 | err = tg3_phy_probe(tp); | |
16382 | if (err) { | |
2445e461 | 16383 | dev_err(&tp->pdev->dev, "phy probe failed, err %d\n", err); |
1da177e4 | 16384 | /* ... but do not return immediately ... */ |
b02fd9e3 | 16385 | tg3_mdio_fini(tp); |
1da177e4 LT |
16386 | } |
16387 | ||
184b8904 | 16388 | tg3_read_vpd(tp); |
c4e6575c | 16389 | tg3_read_fw_ver(tp); |
1da177e4 | 16390 | |
f07e9af3 MC |
16391 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) { |
16392 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; | |
1da177e4 | 16393 | } else { |
4153577a | 16394 | if (tg3_asic_rev(tp) == ASIC_REV_5700) |
f07e9af3 | 16395 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; |
1da177e4 | 16396 | else |
f07e9af3 | 16397 | tp->phy_flags &= ~TG3_PHYFLG_USE_MI_INTERRUPT; |
1da177e4 LT |
16398 | } |
16399 | ||
16400 | /* 5700 {AX,BX} chips have a broken status block link | |
16401 | * change bit implementation, so we must use the | |
16402 | * status register in those cases. | |
16403 | */ | |
4153577a | 16404 | if (tg3_asic_rev(tp) == ASIC_REV_5700) |
63c3a66f | 16405 | tg3_flag_set(tp, USE_LINKCHG_REG); |
1da177e4 | 16406 | else |
63c3a66f | 16407 | tg3_flag_clear(tp, USE_LINKCHG_REG); |
1da177e4 LT |
16408 | |
16409 | /* The led_ctrl is set during tg3_phy_probe, here we might | |
16410 | * have to force the link status polling mechanism based | |
16411 | * upon subsystem IDs. | |
16412 | */ | |
16413 | if (tp->pdev->subsystem_vendor == PCI_VENDOR_ID_DELL && | |
4153577a | 16414 | tg3_asic_rev(tp) == ASIC_REV_5701 && |
f07e9af3 MC |
16415 | !(tp->phy_flags & TG3_PHYFLG_PHY_SERDES)) { |
16416 | tp->phy_flags |= TG3_PHYFLG_USE_MI_INTERRUPT; | |
63c3a66f | 16417 | tg3_flag_set(tp, USE_LINKCHG_REG); |
1da177e4 LT |
16418 | } |
16419 | ||
16420 | /* For all SERDES we poll the MAC status register. */ | |
f07e9af3 | 16421 | if (tp->phy_flags & TG3_PHYFLG_PHY_SERDES) |
63c3a66f | 16422 | tg3_flag_set(tp, POLL_SERDES); |
1da177e4 | 16423 | else |
63c3a66f | 16424 | tg3_flag_clear(tp, POLL_SERDES); |
1da177e4 | 16425 | |
9205fd9c | 16426 | tp->rx_offset = NET_SKB_PAD + NET_IP_ALIGN; |
d2757fc4 | 16427 | tp->rx_copy_thresh = TG3_RX_COPY_THRESHOLD; |
4153577a | 16428 | if (tg3_asic_rev(tp) == ASIC_REV_5701 && |
63c3a66f | 16429 | tg3_flag(tp, PCIX_MODE)) { |
9205fd9c | 16430 | tp->rx_offset = NET_SKB_PAD; |
d2757fc4 | 16431 | #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS |
9dc7a113 | 16432 | tp->rx_copy_thresh = ~(u16)0; |
d2757fc4 MC |
16433 | #endif |
16434 | } | |
1da177e4 | 16435 | |
2c49a44d MC |
16436 | tp->rx_std_ring_mask = TG3_RX_STD_RING_SIZE(tp) - 1; |
16437 | tp->rx_jmb_ring_mask = TG3_RX_JMB_RING_SIZE(tp) - 1; | |
7cb32cf2 MC |
16438 | tp->rx_ret_ring_mask = tg3_rx_ret_ring_size(tp) - 1; |
16439 | ||
2c49a44d | 16440 | tp->rx_std_max_post = tp->rx_std_ring_mask + 1; |
f92905de MC |
16441 | |
16442 | /* Increment the rx prod index on the rx std ring by at most | |
16443 | * 8 for these chips to workaround hw errata. | |
16444 | */ | |
4153577a JP |
16445 | if (tg3_asic_rev(tp) == ASIC_REV_5750 || |
16446 | tg3_asic_rev(tp) == ASIC_REV_5752 || | |
16447 | tg3_asic_rev(tp) == ASIC_REV_5755) | |
f92905de MC |
16448 | tp->rx_std_max_post = 8; |
16449 | ||
63c3a66f | 16450 | if (tg3_flag(tp, ASPM_WORKAROUND)) |
8ed5d97e MC |
16451 | tp->pwrmgmt_thresh = tr32(PCIE_PWR_MGMT_THRESH) & |
16452 | PCIE_PWR_MGMT_L1_THRESH_MSK; | |
16453 | ||
1da177e4 LT |
16454 | return err; |
16455 | } | |
16456 | ||
49b6e95f | 16457 | #ifdef CONFIG_SPARC |
229b1ad1 | 16458 | static int tg3_get_macaddr_sparc(struct tg3 *tp) |
1da177e4 LT |
16459 | { |
16460 | struct net_device *dev = tp->dev; | |
16461 | struct pci_dev *pdev = tp->pdev; | |
49b6e95f | 16462 | struct device_node *dp = pci_device_to_OF_node(pdev); |
374d4cac | 16463 | const unsigned char *addr; |
49b6e95f DM |
16464 | int len; |
16465 | ||
16466 | addr = of_get_property(dp, "local-mac-address", &len); | |
16467 | if (addr && len == 6) { | |
16468 | memcpy(dev->dev_addr, addr, 6); | |
49b6e95f | 16469 | return 0; |
1da177e4 LT |
16470 | } |
16471 | return -ENODEV; | |
16472 | } | |
16473 | ||
229b1ad1 | 16474 | static int tg3_get_default_macaddr_sparc(struct tg3 *tp) |
1da177e4 LT |
16475 | { |
16476 | struct net_device *dev = tp->dev; | |
16477 | ||
16478 | memcpy(dev->dev_addr, idprom->id_ethaddr, 6); | |
16479 | return 0; | |
16480 | } | |
16481 | #endif | |
16482 | ||
229b1ad1 | 16483 | static int tg3_get_device_address(struct tg3 *tp) |
1da177e4 LT |
16484 | { |
16485 | struct net_device *dev = tp->dev; | |
16486 | u32 hi, lo, mac_offset; | |
008652b3 | 16487 | int addr_ok = 0; |
7e6c63f0 | 16488 | int err; |
1da177e4 | 16489 | |
49b6e95f | 16490 | #ifdef CONFIG_SPARC |
1da177e4 LT |
16491 | if (!tg3_get_macaddr_sparc(tp)) |
16492 | return 0; | |
16493 | #endif | |
16494 | ||
7e6c63f0 HM |
16495 | if (tg3_flag(tp, IS_SSB_CORE)) { |
16496 | err = ssb_gige_get_macaddr(tp->pdev, &dev->dev_addr[0]); | |
16497 | if (!err && is_valid_ether_addr(&dev->dev_addr[0])) | |
16498 | return 0; | |
16499 | } | |
16500 | ||
1da177e4 | 16501 | mac_offset = 0x7c; |
4153577a | 16502 | if (tg3_asic_rev(tp) == ASIC_REV_5704 || |
63c3a66f | 16503 | tg3_flag(tp, 5780_CLASS)) { |
1da177e4 LT |
16504 | if (tr32(TG3PCI_DUAL_MAC_CTRL) & DUAL_MAC_CTRL_ID) |
16505 | mac_offset = 0xcc; | |
16506 | if (tg3_nvram_lock(tp)) | |
16507 | tw32_f(NVRAM_CMD, NVRAM_CMD_RESET); | |
16508 | else | |
16509 | tg3_nvram_unlock(tp); | |
63c3a66f | 16510 | } else if (tg3_flag(tp, 5717_PLUS)) { |
69f11c99 | 16511 | if (tp->pci_fn & 1) |
a1b950d5 | 16512 | mac_offset = 0xcc; |
69f11c99 | 16513 | if (tp->pci_fn > 1) |
a50d0796 | 16514 | mac_offset += 0x18c; |
4153577a | 16515 | } else if (tg3_asic_rev(tp) == ASIC_REV_5906) |
b5d3772c | 16516 | mac_offset = 0x10; |
1da177e4 LT |
16517 | |
16518 | /* First try to get it from MAC address mailbox. */ | |
16519 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_HIGH_MBOX, &hi); | |
16520 | if ((hi >> 16) == 0x484b) { | |
16521 | dev->dev_addr[0] = (hi >> 8) & 0xff; | |
16522 | dev->dev_addr[1] = (hi >> 0) & 0xff; | |
16523 | ||
16524 | tg3_read_mem(tp, NIC_SRAM_MAC_ADDR_LOW_MBOX, &lo); | |
16525 | dev->dev_addr[2] = (lo >> 24) & 0xff; | |
16526 | dev->dev_addr[3] = (lo >> 16) & 0xff; | |
16527 | dev->dev_addr[4] = (lo >> 8) & 0xff; | |
16528 | dev->dev_addr[5] = (lo >> 0) & 0xff; | |
1da177e4 | 16529 | |
008652b3 MC |
16530 | /* Some old bootcode may report a 0 MAC address in SRAM */ |
16531 | addr_ok = is_valid_ether_addr(&dev->dev_addr[0]); | |
16532 | } | |
16533 | if (!addr_ok) { | |
16534 | /* Next, try NVRAM. */ | |
63c3a66f | 16535 | if (!tg3_flag(tp, NO_NVRAM) && |
df259d8c | 16536 | !tg3_nvram_read_be32(tp, mac_offset + 0, &hi) && |
6d348f2c | 16537 | !tg3_nvram_read_be32(tp, mac_offset + 4, &lo)) { |
62cedd11 MC |
16538 | memcpy(&dev->dev_addr[0], ((char *)&hi) + 2, 2); |
16539 | memcpy(&dev->dev_addr[2], (char *)&lo, sizeof(lo)); | |
008652b3 MC |
16540 | } |
16541 | /* Finally just fetch it out of the MAC control regs. */ | |
16542 | else { | |
16543 | hi = tr32(MAC_ADDR_0_HIGH); | |
16544 | lo = tr32(MAC_ADDR_0_LOW); | |
16545 | ||
16546 | dev->dev_addr[5] = lo & 0xff; | |
16547 | dev->dev_addr[4] = (lo >> 8) & 0xff; | |
16548 | dev->dev_addr[3] = (lo >> 16) & 0xff; | |
16549 | dev->dev_addr[2] = (lo >> 24) & 0xff; | |
16550 | dev->dev_addr[1] = hi & 0xff; | |
16551 | dev->dev_addr[0] = (hi >> 8) & 0xff; | |
16552 | } | |
1da177e4 LT |
16553 | } |
16554 | ||
16555 | if (!is_valid_ether_addr(&dev->dev_addr[0])) { | |
7582a335 | 16556 | #ifdef CONFIG_SPARC |
1da177e4 LT |
16557 | if (!tg3_get_default_macaddr_sparc(tp)) |
16558 | return 0; | |
16559 | #endif | |
16560 | return -EINVAL; | |
16561 | } | |
16562 | return 0; | |
16563 | } | |
16564 | ||
59e6b434 DM |
16565 | #define BOUNDARY_SINGLE_CACHELINE 1 |
16566 | #define BOUNDARY_MULTI_CACHELINE 2 | |
16567 | ||
229b1ad1 | 16568 | static u32 tg3_calc_dma_bndry(struct tg3 *tp, u32 val) |
59e6b434 DM |
16569 | { |
16570 | int cacheline_size; | |
16571 | u8 byte; | |
16572 | int goal; | |
16573 | ||
16574 | pci_read_config_byte(tp->pdev, PCI_CACHE_LINE_SIZE, &byte); | |
16575 | if (byte == 0) | |
16576 | cacheline_size = 1024; | |
16577 | else | |
16578 | cacheline_size = (int) byte * 4; | |
16579 | ||
16580 | /* On 5703 and later chips, the boundary bits have no | |
16581 | * effect. | |
16582 | */ | |
4153577a JP |
16583 | if (tg3_asic_rev(tp) != ASIC_REV_5700 && |
16584 | tg3_asic_rev(tp) != ASIC_REV_5701 && | |
63c3a66f | 16585 | !tg3_flag(tp, PCI_EXPRESS)) |
59e6b434 DM |
16586 | goto out; |
16587 | ||
16588 | #if defined(CONFIG_PPC64) || defined(CONFIG_IA64) || defined(CONFIG_PARISC) | |
16589 | goal = BOUNDARY_MULTI_CACHELINE; | |
16590 | #else | |
16591 | #if defined(CONFIG_SPARC64) || defined(CONFIG_ALPHA) | |
16592 | goal = BOUNDARY_SINGLE_CACHELINE; | |
16593 | #else | |
16594 | goal = 0; | |
16595 | #endif | |
16596 | #endif | |
16597 | ||
63c3a66f | 16598 | if (tg3_flag(tp, 57765_PLUS)) { |
cbf9ca6c MC |
16599 | val = goal ? 0 : DMA_RWCTRL_DIS_CACHE_ALIGNMENT; |
16600 | goto out; | |
16601 | } | |
16602 | ||
59e6b434 DM |
16603 | if (!goal) |
16604 | goto out; | |
16605 | ||
16606 | /* PCI controllers on most RISC systems tend to disconnect | |
16607 | * when a device tries to burst across a cache-line boundary. | |
16608 | * Therefore, letting tg3 do so just wastes PCI bandwidth. | |
16609 | * | |
16610 | * Unfortunately, for PCI-E there are only limited | |
16611 | * write-side controls for this, and thus for reads | |
16612 | * we will still get the disconnects. We'll also waste | |
16613 | * these PCI cycles for both read and write for chips | |
16614 | * other than 5700 and 5701 which do not implement the | |
16615 | * boundary bits. | |
16616 | */ | |
63c3a66f | 16617 | if (tg3_flag(tp, PCIX_MODE) && !tg3_flag(tp, PCI_EXPRESS)) { |
59e6b434 DM |
16618 | switch (cacheline_size) { |
16619 | case 16: | |
16620 | case 32: | |
16621 | case 64: | |
16622 | case 128: | |
16623 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
16624 | val |= (DMA_RWCTRL_READ_BNDRY_128_PCIX | | |
16625 | DMA_RWCTRL_WRITE_BNDRY_128_PCIX); | |
16626 | } else { | |
16627 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | | |
16628 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); | |
16629 | } | |
16630 | break; | |
16631 | ||
16632 | case 256: | |
16633 | val |= (DMA_RWCTRL_READ_BNDRY_256_PCIX | | |
16634 | DMA_RWCTRL_WRITE_BNDRY_256_PCIX); | |
16635 | break; | |
16636 | ||
16637 | default: | |
16638 | val |= (DMA_RWCTRL_READ_BNDRY_384_PCIX | | |
16639 | DMA_RWCTRL_WRITE_BNDRY_384_PCIX); | |
16640 | break; | |
855e1111 | 16641 | } |
63c3a66f | 16642 | } else if (tg3_flag(tp, PCI_EXPRESS)) { |
59e6b434 DM |
16643 | switch (cacheline_size) { |
16644 | case 16: | |
16645 | case 32: | |
16646 | case 64: | |
16647 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
16648 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; | |
16649 | val |= DMA_RWCTRL_WRITE_BNDRY_64_PCIE; | |
16650 | break; | |
16651 | } | |
16652 | /* fallthrough */ | |
16653 | case 128: | |
16654 | default: | |
16655 | val &= ~DMA_RWCTRL_WRITE_BNDRY_DISAB_PCIE; | |
16656 | val |= DMA_RWCTRL_WRITE_BNDRY_128_PCIE; | |
16657 | break; | |
855e1111 | 16658 | } |
59e6b434 DM |
16659 | } else { |
16660 | switch (cacheline_size) { | |
16661 | case 16: | |
16662 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
16663 | val |= (DMA_RWCTRL_READ_BNDRY_16 | | |
16664 | DMA_RWCTRL_WRITE_BNDRY_16); | |
16665 | break; | |
16666 | } | |
16667 | /* fallthrough */ | |
16668 | case 32: | |
16669 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
16670 | val |= (DMA_RWCTRL_READ_BNDRY_32 | | |
16671 | DMA_RWCTRL_WRITE_BNDRY_32); | |
16672 | break; | |
16673 | } | |
16674 | /* fallthrough */ | |
16675 | case 64: | |
16676 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
16677 | val |= (DMA_RWCTRL_READ_BNDRY_64 | | |
16678 | DMA_RWCTRL_WRITE_BNDRY_64); | |
16679 | break; | |
16680 | } | |
16681 | /* fallthrough */ | |
16682 | case 128: | |
16683 | if (goal == BOUNDARY_SINGLE_CACHELINE) { | |
16684 | val |= (DMA_RWCTRL_READ_BNDRY_128 | | |
16685 | DMA_RWCTRL_WRITE_BNDRY_128); | |
16686 | break; | |
16687 | } | |
16688 | /* fallthrough */ | |
16689 | case 256: | |
16690 | val |= (DMA_RWCTRL_READ_BNDRY_256 | | |
16691 | DMA_RWCTRL_WRITE_BNDRY_256); | |
16692 | break; | |
16693 | case 512: | |
16694 | val |= (DMA_RWCTRL_READ_BNDRY_512 | | |
16695 | DMA_RWCTRL_WRITE_BNDRY_512); | |
16696 | break; | |
16697 | case 1024: | |
16698 | default: | |
16699 | val |= (DMA_RWCTRL_READ_BNDRY_1024 | | |
16700 | DMA_RWCTRL_WRITE_BNDRY_1024); | |
16701 | break; | |
855e1111 | 16702 | } |
59e6b434 DM |
16703 | } |
16704 | ||
16705 | out: | |
16706 | return val; | |
16707 | } | |
16708 | ||
229b1ad1 | 16709 | static int tg3_do_test_dma(struct tg3 *tp, u32 *buf, dma_addr_t buf_dma, |
953c96e0 | 16710 | int size, bool to_device) |
1da177e4 LT |
16711 | { |
16712 | struct tg3_internal_buffer_desc test_desc; | |
16713 | u32 sram_dma_descs; | |
16714 | int i, ret; | |
16715 | ||
16716 | sram_dma_descs = NIC_SRAM_DMA_DESC_POOL_BASE; | |
16717 | ||
16718 | tw32(FTQ_RCVBD_COMP_FIFO_ENQDEQ, 0); | |
16719 | tw32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ, 0); | |
16720 | tw32(RDMAC_STATUS, 0); | |
16721 | tw32(WDMAC_STATUS, 0); | |
16722 | ||
16723 | tw32(BUFMGR_MODE, 0); | |
16724 | tw32(FTQ_RESET, 0); | |
16725 | ||
16726 | test_desc.addr_hi = ((u64) buf_dma) >> 32; | |
16727 | test_desc.addr_lo = buf_dma & 0xffffffff; | |
16728 | test_desc.nic_mbuf = 0x00002100; | |
16729 | test_desc.len = size; | |
16730 | ||
16731 | /* | |
16732 | * HP ZX1 was seeing test failures for 5701 cards running at 33Mhz | |
16733 | * the *second* time the tg3 driver was getting loaded after an | |
16734 | * initial scan. | |
16735 | * | |
16736 | * Broadcom tells me: | |
16737 | * ...the DMA engine is connected to the GRC block and a DMA | |
16738 | * reset may affect the GRC block in some unpredictable way... | |
16739 | * The behavior of resets to individual blocks has not been tested. | |
16740 | * | |
16741 | * Broadcom noted the GRC reset will also reset all sub-components. | |
16742 | */ | |
16743 | if (to_device) { | |
16744 | test_desc.cqid_sqid = (13 << 8) | 2; | |
16745 | ||
16746 | tw32_f(RDMAC_MODE, RDMAC_MODE_ENABLE); | |
16747 | udelay(40); | |
16748 | } else { | |
16749 | test_desc.cqid_sqid = (16 << 8) | 7; | |
16750 | ||
16751 | tw32_f(WDMAC_MODE, WDMAC_MODE_ENABLE); | |
16752 | udelay(40); | |
16753 | } | |
16754 | test_desc.flags = 0x00000005; | |
16755 | ||
16756 | for (i = 0; i < (sizeof(test_desc) / sizeof(u32)); i++) { | |
16757 | u32 val; | |
16758 | ||
16759 | val = *(((u32 *)&test_desc) + i); | |
16760 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, | |
16761 | sram_dma_descs + (i * sizeof(u32))); | |
16762 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_DATA, val); | |
16763 | } | |
16764 | pci_write_config_dword(tp->pdev, TG3PCI_MEM_WIN_BASE_ADDR, 0); | |
16765 | ||
859a5887 | 16766 | if (to_device) |
1da177e4 | 16767 | tw32(FTQ_DMA_HIGH_READ_FIFO_ENQDEQ, sram_dma_descs); |
859a5887 | 16768 | else |
1da177e4 | 16769 | tw32(FTQ_DMA_HIGH_WRITE_FIFO_ENQDEQ, sram_dma_descs); |
1da177e4 LT |
16770 | |
16771 | ret = -ENODEV; | |
16772 | for (i = 0; i < 40; i++) { | |
16773 | u32 val; | |
16774 | ||
16775 | if (to_device) | |
16776 | val = tr32(FTQ_RCVBD_COMP_FIFO_ENQDEQ); | |
16777 | else | |
16778 | val = tr32(FTQ_RCVDATA_COMP_FIFO_ENQDEQ); | |
16779 | if ((val & 0xffff) == sram_dma_descs) { | |
16780 | ret = 0; | |
16781 | break; | |
16782 | } | |
16783 | ||
16784 | udelay(100); | |
16785 | } | |
16786 | ||
16787 | return ret; | |
16788 | } | |
16789 | ||
ded7340d | 16790 | #define TEST_BUFFER_SIZE 0x2000 |
1da177e4 | 16791 | |
4143470c | 16792 | static DEFINE_PCI_DEVICE_TABLE(tg3_dma_wait_state_chipsets) = { |
895950c2 JP |
16793 | { PCI_DEVICE(PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_PCI15) }, |
16794 | { }, | |
16795 | }; | |
16796 | ||
229b1ad1 | 16797 | static int tg3_test_dma(struct tg3 *tp) |
1da177e4 LT |
16798 | { |
16799 | dma_addr_t buf_dma; | |
59e6b434 | 16800 | u32 *buf, saved_dma_rwctrl; |
cbf9ca6c | 16801 | int ret = 0; |
1da177e4 | 16802 | |
4bae65c8 MC |
16803 | buf = dma_alloc_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, |
16804 | &buf_dma, GFP_KERNEL); | |
1da177e4 LT |
16805 | if (!buf) { |
16806 | ret = -ENOMEM; | |
16807 | goto out_nofree; | |
16808 | } | |
16809 | ||
16810 | tp->dma_rwctrl = ((0x7 << DMA_RWCTRL_PCI_WRITE_CMD_SHIFT) | | |
16811 | (0x6 << DMA_RWCTRL_PCI_READ_CMD_SHIFT)); | |
16812 | ||
59e6b434 | 16813 | tp->dma_rwctrl = tg3_calc_dma_bndry(tp, tp->dma_rwctrl); |
1da177e4 | 16814 | |
63c3a66f | 16815 | if (tg3_flag(tp, 57765_PLUS)) |
cbf9ca6c MC |
16816 | goto out; |
16817 | ||
63c3a66f | 16818 | if (tg3_flag(tp, PCI_EXPRESS)) { |
1da177e4 LT |
16819 | /* DMA read watermark not used on PCIE */ |
16820 | tp->dma_rwctrl |= 0x00180000; | |
63c3a66f | 16821 | } else if (!tg3_flag(tp, PCIX_MODE)) { |
4153577a JP |
16822 | if (tg3_asic_rev(tp) == ASIC_REV_5705 || |
16823 | tg3_asic_rev(tp) == ASIC_REV_5750) | |
1da177e4 LT |
16824 | tp->dma_rwctrl |= 0x003f0000; |
16825 | else | |
16826 | tp->dma_rwctrl |= 0x003f000f; | |
16827 | } else { | |
4153577a JP |
16828 | if (tg3_asic_rev(tp) == ASIC_REV_5703 || |
16829 | tg3_asic_rev(tp) == ASIC_REV_5704) { | |
1da177e4 | 16830 | u32 ccval = (tr32(TG3PCI_CLOCK_CTRL) & 0x1f); |
49afdeb6 | 16831 | u32 read_water = 0x7; |
1da177e4 | 16832 | |
4a29cc2e MC |
16833 | /* If the 5704 is behind the EPB bridge, we can |
16834 | * do the less restrictive ONE_DMA workaround for | |
16835 | * better performance. | |
16836 | */ | |
63c3a66f | 16837 | if (tg3_flag(tp, 40BIT_DMA_BUG) && |
4153577a | 16838 | tg3_asic_rev(tp) == ASIC_REV_5704) |
4a29cc2e MC |
16839 | tp->dma_rwctrl |= 0x8000; |
16840 | else if (ccval == 0x6 || ccval == 0x7) | |
1da177e4 LT |
16841 | tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; |
16842 | ||
4153577a | 16843 | if (tg3_asic_rev(tp) == ASIC_REV_5703) |
49afdeb6 | 16844 | read_water = 4; |
59e6b434 | 16845 | /* Set bit 23 to enable PCIX hw bug fix */ |
49afdeb6 MC |
16846 | tp->dma_rwctrl |= |
16847 | (read_water << DMA_RWCTRL_READ_WATER_SHIFT) | | |
16848 | (0x3 << DMA_RWCTRL_WRITE_WATER_SHIFT) | | |
16849 | (1 << 23); | |
4153577a | 16850 | } else if (tg3_asic_rev(tp) == ASIC_REV_5780) { |
4cf78e4f MC |
16851 | /* 5780 always in PCIX mode */ |
16852 | tp->dma_rwctrl |= 0x00144000; | |
4153577a | 16853 | } else if (tg3_asic_rev(tp) == ASIC_REV_5714) { |
a4e2b347 MC |
16854 | /* 5714 always in PCIX mode */ |
16855 | tp->dma_rwctrl |= 0x00148000; | |
1da177e4 LT |
16856 | } else { |
16857 | tp->dma_rwctrl |= 0x001b000f; | |
16858 | } | |
16859 | } | |
7e6c63f0 HM |
16860 | if (tg3_flag(tp, ONE_DMA_AT_ONCE)) |
16861 | tp->dma_rwctrl |= DMA_RWCTRL_ONE_DMA; | |
1da177e4 | 16862 | |
4153577a JP |
16863 | if (tg3_asic_rev(tp) == ASIC_REV_5703 || |
16864 | tg3_asic_rev(tp) == ASIC_REV_5704) | |
1da177e4 LT |
16865 | tp->dma_rwctrl &= 0xfffffff0; |
16866 | ||
4153577a JP |
16867 | if (tg3_asic_rev(tp) == ASIC_REV_5700 || |
16868 | tg3_asic_rev(tp) == ASIC_REV_5701) { | |
1da177e4 LT |
16869 | /* Remove this if it causes problems for some boards. */ |
16870 | tp->dma_rwctrl |= DMA_RWCTRL_USE_MEM_READ_MULT; | |
16871 | ||
16872 | /* On 5700/5701 chips, we need to set this bit. | |
16873 | * Otherwise the chip will issue cacheline transactions | |
16874 | * to streamable DMA memory with not all the byte | |
16875 | * enables turned on. This is an error on several | |
16876 | * RISC PCI controllers, in particular sparc64. | |
16877 | * | |
16878 | * On 5703/5704 chips, this bit has been reassigned | |
16879 | * a different meaning. In particular, it is used | |
16880 | * on those chips to enable a PCI-X workaround. | |
16881 | */ | |
16882 | tp->dma_rwctrl |= DMA_RWCTRL_ASSERT_ALL_BE; | |
16883 | } | |
16884 | ||
16885 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); | |
16886 | ||
16887 | #if 0 | |
16888 | /* Unneeded, already done by tg3_get_invariants. */ | |
16889 | tg3_switch_clocks(tp); | |
16890 | #endif | |
16891 | ||
4153577a JP |
16892 | if (tg3_asic_rev(tp) != ASIC_REV_5700 && |
16893 | tg3_asic_rev(tp) != ASIC_REV_5701) | |
1da177e4 LT |
16894 | goto out; |
16895 | ||
59e6b434 DM |
16896 | /* It is best to perform DMA test with maximum write burst size |
16897 | * to expose the 5700/5701 write DMA bug. | |
16898 | */ | |
16899 | saved_dma_rwctrl = tp->dma_rwctrl; | |
16900 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; | |
16901 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); | |
16902 | ||
1da177e4 LT |
16903 | while (1) { |
16904 | u32 *p = buf, i; | |
16905 | ||
16906 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) | |
16907 | p[i] = i; | |
16908 | ||
16909 | /* Send the buffer to the chip. */ | |
953c96e0 | 16910 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, true); |
1da177e4 | 16911 | if (ret) { |
2445e461 MC |
16912 | dev_err(&tp->pdev->dev, |
16913 | "%s: Buffer write failed. err = %d\n", | |
16914 | __func__, ret); | |
1da177e4 LT |
16915 | break; |
16916 | } | |
16917 | ||
16918 | #if 0 | |
16919 | /* validate data reached card RAM correctly. */ | |
16920 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { | |
16921 | u32 val; | |
16922 | tg3_read_mem(tp, 0x2100 + (i*4), &val); | |
16923 | if (le32_to_cpu(val) != p[i]) { | |
2445e461 MC |
16924 | dev_err(&tp->pdev->dev, |
16925 | "%s: Buffer corrupted on device! " | |
16926 | "(%d != %d)\n", __func__, val, i); | |
1da177e4 LT |
16927 | /* ret = -ENODEV here? */ |
16928 | } | |
16929 | p[i] = 0; | |
16930 | } | |
16931 | #endif | |
16932 | /* Now read it back. */ | |
953c96e0 | 16933 | ret = tg3_do_test_dma(tp, buf, buf_dma, TEST_BUFFER_SIZE, false); |
1da177e4 | 16934 | if (ret) { |
5129c3a3 MC |
16935 | dev_err(&tp->pdev->dev, "%s: Buffer read failed. " |
16936 | "err = %d\n", __func__, ret); | |
1da177e4 LT |
16937 | break; |
16938 | } | |
16939 | ||
16940 | /* Verify it. */ | |
16941 | for (i = 0; i < TEST_BUFFER_SIZE / sizeof(u32); i++) { | |
16942 | if (p[i] == i) | |
16943 | continue; | |
16944 | ||
59e6b434 DM |
16945 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
16946 | DMA_RWCTRL_WRITE_BNDRY_16) { | |
16947 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; | |
1da177e4 LT |
16948 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; |
16949 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); | |
16950 | break; | |
16951 | } else { | |
2445e461 MC |
16952 | dev_err(&tp->pdev->dev, |
16953 | "%s: Buffer corrupted on read back! " | |
16954 | "(%d != %d)\n", __func__, p[i], i); | |
1da177e4 LT |
16955 | ret = -ENODEV; |
16956 | goto out; | |
16957 | } | |
16958 | } | |
16959 | ||
16960 | if (i == (TEST_BUFFER_SIZE / sizeof(u32))) { | |
16961 | /* Success. */ | |
16962 | ret = 0; | |
16963 | break; | |
16964 | } | |
16965 | } | |
59e6b434 DM |
16966 | if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) != |
16967 | DMA_RWCTRL_WRITE_BNDRY_16) { | |
16968 | /* DMA test passed without adjusting DMA boundary, | |
6d1cfbab MC |
16969 | * now look for chipsets that are known to expose the |
16970 | * DMA bug without failing the test. | |
59e6b434 | 16971 | */ |
4143470c | 16972 | if (pci_dev_present(tg3_dma_wait_state_chipsets)) { |
6d1cfbab MC |
16973 | tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK; |
16974 | tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16; | |
859a5887 | 16975 | } else { |
6d1cfbab MC |
16976 | /* Safe to use the calculated DMA boundary. */ |
16977 | tp->dma_rwctrl = saved_dma_rwctrl; | |
859a5887 | 16978 | } |
6d1cfbab | 16979 | |
59e6b434 DM |
16980 | tw32(TG3PCI_DMA_RW_CTRL, tp->dma_rwctrl); |
16981 | } | |
1da177e4 LT |
16982 | |
16983 | out: | |
4bae65c8 | 16984 | dma_free_coherent(&tp->pdev->dev, TEST_BUFFER_SIZE, buf, buf_dma); |
1da177e4 LT |
16985 | out_nofree: |
16986 | return ret; | |
16987 | } | |
16988 | ||
229b1ad1 | 16989 | static void tg3_init_bufmgr_config(struct tg3 *tp) |
1da177e4 | 16990 | { |
63c3a66f | 16991 | if (tg3_flag(tp, 57765_PLUS)) { |
666bc831 MC |
16992 | tp->bufmgr_config.mbuf_read_dma_low_water = |
16993 | DEFAULT_MB_RDMA_LOW_WATER_5705; | |
16994 | tp->bufmgr_config.mbuf_mac_rx_low_water = | |
16995 | DEFAULT_MB_MACRX_LOW_WATER_57765; | |
16996 | tp->bufmgr_config.mbuf_high_water = | |
16997 | DEFAULT_MB_HIGH_WATER_57765; | |
16998 | ||
16999 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = | |
17000 | DEFAULT_MB_RDMA_LOW_WATER_5705; | |
17001 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = | |
17002 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_57765; | |
17003 | tp->bufmgr_config.mbuf_high_water_jumbo = | |
17004 | DEFAULT_MB_HIGH_WATER_JUMBO_57765; | |
63c3a66f | 17005 | } else if (tg3_flag(tp, 5705_PLUS)) { |
fdfec172 MC |
17006 | tp->bufmgr_config.mbuf_read_dma_low_water = |
17007 | DEFAULT_MB_RDMA_LOW_WATER_5705; | |
17008 | tp->bufmgr_config.mbuf_mac_rx_low_water = | |
17009 | DEFAULT_MB_MACRX_LOW_WATER_5705; | |
17010 | tp->bufmgr_config.mbuf_high_water = | |
17011 | DEFAULT_MB_HIGH_WATER_5705; | |
4153577a | 17012 | if (tg3_asic_rev(tp) == ASIC_REV_5906) { |
b5d3772c MC |
17013 | tp->bufmgr_config.mbuf_mac_rx_low_water = |
17014 | DEFAULT_MB_MACRX_LOW_WATER_5906; | |
17015 | tp->bufmgr_config.mbuf_high_water = | |
17016 | DEFAULT_MB_HIGH_WATER_5906; | |
17017 | } | |
fdfec172 MC |
17018 | |
17019 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = | |
17020 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO_5780; | |
17021 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = | |
17022 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO_5780; | |
17023 | tp->bufmgr_config.mbuf_high_water_jumbo = | |
17024 | DEFAULT_MB_HIGH_WATER_JUMBO_5780; | |
17025 | } else { | |
17026 | tp->bufmgr_config.mbuf_read_dma_low_water = | |
17027 | DEFAULT_MB_RDMA_LOW_WATER; | |
17028 | tp->bufmgr_config.mbuf_mac_rx_low_water = | |
17029 | DEFAULT_MB_MACRX_LOW_WATER; | |
17030 | tp->bufmgr_config.mbuf_high_water = | |
17031 | DEFAULT_MB_HIGH_WATER; | |
17032 | ||
17033 | tp->bufmgr_config.mbuf_read_dma_low_water_jumbo = | |
17034 | DEFAULT_MB_RDMA_LOW_WATER_JUMBO; | |
17035 | tp->bufmgr_config.mbuf_mac_rx_low_water_jumbo = | |
17036 | DEFAULT_MB_MACRX_LOW_WATER_JUMBO; | |
17037 | tp->bufmgr_config.mbuf_high_water_jumbo = | |
17038 | DEFAULT_MB_HIGH_WATER_JUMBO; | |
17039 | } | |
1da177e4 LT |
17040 | |
17041 | tp->bufmgr_config.dma_low_water = DEFAULT_DMA_LOW_WATER; | |
17042 | tp->bufmgr_config.dma_high_water = DEFAULT_DMA_HIGH_WATER; | |
17043 | } | |
17044 | ||
229b1ad1 | 17045 | static char *tg3_phy_string(struct tg3 *tp) |
1da177e4 | 17046 | { |
79eb6904 MC |
17047 | switch (tp->phy_id & TG3_PHY_ID_MASK) { |
17048 | case TG3_PHY_ID_BCM5400: return "5400"; | |
17049 | case TG3_PHY_ID_BCM5401: return "5401"; | |
17050 | case TG3_PHY_ID_BCM5411: return "5411"; | |
17051 | case TG3_PHY_ID_BCM5701: return "5701"; | |
17052 | case TG3_PHY_ID_BCM5703: return "5703"; | |
17053 | case TG3_PHY_ID_BCM5704: return "5704"; | |
17054 | case TG3_PHY_ID_BCM5705: return "5705"; | |
17055 | case TG3_PHY_ID_BCM5750: return "5750"; | |
17056 | case TG3_PHY_ID_BCM5752: return "5752"; | |
17057 | case TG3_PHY_ID_BCM5714: return "5714"; | |
17058 | case TG3_PHY_ID_BCM5780: return "5780"; | |
17059 | case TG3_PHY_ID_BCM5755: return "5755"; | |
17060 | case TG3_PHY_ID_BCM5787: return "5787"; | |
17061 | case TG3_PHY_ID_BCM5784: return "5784"; | |
17062 | case TG3_PHY_ID_BCM5756: return "5722/5756"; | |
17063 | case TG3_PHY_ID_BCM5906: return "5906"; | |
17064 | case TG3_PHY_ID_BCM5761: return "5761"; | |
17065 | case TG3_PHY_ID_BCM5718C: return "5718C"; | |
17066 | case TG3_PHY_ID_BCM5718S: return "5718S"; | |
17067 | case TG3_PHY_ID_BCM57765: return "57765"; | |
302b500b | 17068 | case TG3_PHY_ID_BCM5719C: return "5719C"; |
6418f2c1 | 17069 | case TG3_PHY_ID_BCM5720C: return "5720C"; |
c65a17f4 | 17070 | case TG3_PHY_ID_BCM5762: return "5762C"; |
79eb6904 | 17071 | case TG3_PHY_ID_BCM8002: return "8002/serdes"; |
1da177e4 LT |
17072 | case 0: return "serdes"; |
17073 | default: return "unknown"; | |
855e1111 | 17074 | } |
1da177e4 LT |
17075 | } |
17076 | ||
229b1ad1 | 17077 | static char *tg3_bus_string(struct tg3 *tp, char *str) |
f9804ddb | 17078 | { |
63c3a66f | 17079 | if (tg3_flag(tp, PCI_EXPRESS)) { |
f9804ddb MC |
17080 | strcpy(str, "PCI Express"); |
17081 | return str; | |
63c3a66f | 17082 | } else if (tg3_flag(tp, PCIX_MODE)) { |
f9804ddb MC |
17083 | u32 clock_ctrl = tr32(TG3PCI_CLOCK_CTRL) & 0x1f; |
17084 | ||
17085 | strcpy(str, "PCIX:"); | |
17086 | ||
17087 | if ((clock_ctrl == 7) || | |
17088 | ((tr32(GRC_MISC_CFG) & GRC_MISC_CFG_BOARD_ID_MASK) == | |
17089 | GRC_MISC_CFG_BOARD_ID_5704CIOBE)) | |
17090 | strcat(str, "133MHz"); | |
17091 | else if (clock_ctrl == 0) | |
17092 | strcat(str, "33MHz"); | |
17093 | else if (clock_ctrl == 2) | |
17094 | strcat(str, "50MHz"); | |
17095 | else if (clock_ctrl == 4) | |
17096 | strcat(str, "66MHz"); | |
17097 | else if (clock_ctrl == 6) | |
17098 | strcat(str, "100MHz"); | |
f9804ddb MC |
17099 | } else { |
17100 | strcpy(str, "PCI:"); | |
63c3a66f | 17101 | if (tg3_flag(tp, PCI_HIGH_SPEED)) |
f9804ddb MC |
17102 | strcat(str, "66MHz"); |
17103 | else | |
17104 | strcat(str, "33MHz"); | |
17105 | } | |
63c3a66f | 17106 | if (tg3_flag(tp, PCI_32BIT)) |
f9804ddb MC |
17107 | strcat(str, ":32-bit"); |
17108 | else | |
17109 | strcat(str, ":64-bit"); | |
17110 | return str; | |
17111 | } | |
17112 | ||
229b1ad1 | 17113 | static void tg3_init_coal(struct tg3 *tp) |
15f9850d DM |
17114 | { |
17115 | struct ethtool_coalesce *ec = &tp->coal; | |
17116 | ||
17117 | memset(ec, 0, sizeof(*ec)); | |
17118 | ec->cmd = ETHTOOL_GCOALESCE; | |
17119 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS; | |
17120 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS; | |
17121 | ec->rx_max_coalesced_frames = LOW_RXMAX_FRAMES; | |
17122 | ec->tx_max_coalesced_frames = LOW_TXMAX_FRAMES; | |
17123 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT; | |
17124 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT; | |
17125 | ec->rx_max_coalesced_frames_irq = DEFAULT_RXCOAL_MAXF_INT; | |
17126 | ec->tx_max_coalesced_frames_irq = DEFAULT_TXCOAL_MAXF_INT; | |
17127 | ec->stats_block_coalesce_usecs = DEFAULT_STAT_COAL_TICKS; | |
17128 | ||
17129 | if (tp->coalesce_mode & (HOSTCC_MODE_CLRTICK_RXBD | | |
17130 | HOSTCC_MODE_CLRTICK_TXBD)) { | |
17131 | ec->rx_coalesce_usecs = LOW_RXCOL_TICKS_CLRTCKS; | |
17132 | ec->rx_coalesce_usecs_irq = DEFAULT_RXCOAL_TICK_INT_CLRTCKS; | |
17133 | ec->tx_coalesce_usecs = LOW_TXCOL_TICKS_CLRTCKS; | |
17134 | ec->tx_coalesce_usecs_irq = DEFAULT_TXCOAL_TICK_INT_CLRTCKS; | |
17135 | } | |
d244c892 | 17136 | |
63c3a66f | 17137 | if (tg3_flag(tp, 5705_PLUS)) { |
d244c892 MC |
17138 | ec->rx_coalesce_usecs_irq = 0; |
17139 | ec->tx_coalesce_usecs_irq = 0; | |
17140 | ec->stats_block_coalesce_usecs = 0; | |
17141 | } | |
15f9850d DM |
17142 | } |
17143 | ||
229b1ad1 | 17144 | static int tg3_init_one(struct pci_dev *pdev, |
1da177e4 LT |
17145 | const struct pci_device_id *ent) |
17146 | { | |
1da177e4 LT |
17147 | struct net_device *dev; |
17148 | struct tg3 *tp; | |
646c9edd MC |
17149 | int i, err, pm_cap; |
17150 | u32 sndmbx, rcvmbx, intmbx; | |
f9804ddb | 17151 | char str[40]; |
72f2afb8 | 17152 | u64 dma_mask, persist_dma_mask; |
c8f44aff | 17153 | netdev_features_t features = 0; |
1da177e4 | 17154 | |
05dbe005 | 17155 | printk_once(KERN_INFO "%s\n", version); |
1da177e4 LT |
17156 | |
17157 | err = pci_enable_device(pdev); | |
17158 | if (err) { | |
2445e461 | 17159 | dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
1da177e4 LT |
17160 | return err; |
17161 | } | |
17162 | ||
1da177e4 LT |
17163 | err = pci_request_regions(pdev, DRV_MODULE_NAME); |
17164 | if (err) { | |
2445e461 | 17165 | dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
1da177e4 LT |
17166 | goto err_out_disable_pdev; |
17167 | } | |
17168 | ||
17169 | pci_set_master(pdev); | |
17170 | ||
17171 | /* Find power-management capability. */ | |
17172 | pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); | |
17173 | if (pm_cap == 0) { | |
2445e461 MC |
17174 | dev_err(&pdev->dev, |
17175 | "Cannot find Power Management capability, aborting\n"); | |
1da177e4 LT |
17176 | err = -EIO; |
17177 | goto err_out_free_res; | |
17178 | } | |
17179 | ||
16821285 MC |
17180 | err = pci_set_power_state(pdev, PCI_D0); |
17181 | if (err) { | |
17182 | dev_err(&pdev->dev, "Transition to D0 failed, aborting\n"); | |
17183 | goto err_out_free_res; | |
17184 | } | |
17185 | ||
fe5f5787 | 17186 | dev = alloc_etherdev_mq(sizeof(*tp), TG3_IRQ_MAX_VECS); |
1da177e4 | 17187 | if (!dev) { |
1da177e4 | 17188 | err = -ENOMEM; |
16821285 | 17189 | goto err_out_power_down; |
1da177e4 LT |
17190 | } |
17191 | ||
1da177e4 LT |
17192 | SET_NETDEV_DEV(dev, &pdev->dev); |
17193 | ||
1da177e4 LT |
17194 | tp = netdev_priv(dev); |
17195 | tp->pdev = pdev; | |
17196 | tp->dev = dev; | |
17197 | tp->pm_cap = pm_cap; | |
1da177e4 LT |
17198 | tp->rx_mode = TG3_DEF_RX_MODE; |
17199 | tp->tx_mode = TG3_DEF_TX_MODE; | |
9c13cb8b | 17200 | tp->irq_sync = 1; |
8ef21428 | 17201 | |
1da177e4 LT |
17202 | if (tg3_debug > 0) |
17203 | tp->msg_enable = tg3_debug; | |
17204 | else | |
17205 | tp->msg_enable = TG3_DEF_MSG_ENABLE; | |
17206 | ||
7e6c63f0 HM |
17207 | if (pdev_is_ssb_gige_core(pdev)) { |
17208 | tg3_flag_set(tp, IS_SSB_CORE); | |
17209 | if (ssb_gige_must_flush_posted_writes(pdev)) | |
17210 | tg3_flag_set(tp, FLUSH_POSTED_WRITES); | |
17211 | if (ssb_gige_one_dma_at_once(pdev)) | |
17212 | tg3_flag_set(tp, ONE_DMA_AT_ONCE); | |
17213 | if (ssb_gige_have_roboswitch(pdev)) | |
17214 | tg3_flag_set(tp, ROBOSWITCH); | |
17215 | if (ssb_gige_is_rgmii(pdev)) | |
17216 | tg3_flag_set(tp, RGMII_MODE); | |
17217 | } | |
17218 | ||
1da177e4 LT |
17219 | /* The word/byte swap controls here control register access byte |
17220 | * swapping. DMA data byte swapping is controlled in the GRC_MODE | |
17221 | * setting below. | |
17222 | */ | |
17223 | tp->misc_host_ctrl = | |
17224 | MISC_HOST_CTRL_MASK_PCI_INT | | |
17225 | MISC_HOST_CTRL_WORD_SWAP | | |
17226 | MISC_HOST_CTRL_INDIR_ACCESS | | |
17227 | MISC_HOST_CTRL_PCISTATE_RW; | |
17228 | ||
17229 | /* The NONFRM (non-frame) byte/word swap controls take effect | |
17230 | * on descriptor entries, anything which isn't packet data. | |
17231 | * | |
17232 | * The StrongARM chips on the board (one for tx, one for rx) | |
17233 | * are running in big-endian mode. | |
17234 | */ | |
17235 | tp->grc_mode = (GRC_MODE_WSWAP_DATA | GRC_MODE_BSWAP_DATA | | |
17236 | GRC_MODE_WSWAP_NONFRM_DATA); | |
17237 | #ifdef __BIG_ENDIAN | |
17238 | tp->grc_mode |= GRC_MODE_BSWAP_NONFRM_DATA; | |
17239 | #endif | |
17240 | spin_lock_init(&tp->lock); | |
1da177e4 | 17241 | spin_lock_init(&tp->indirect_lock); |
c4028958 | 17242 | INIT_WORK(&tp->reset_task, tg3_reset_task); |
1da177e4 | 17243 | |
d5fe488a | 17244 | tp->regs = pci_ioremap_bar(pdev, BAR_0); |
ab0049b4 | 17245 | if (!tp->regs) { |
ab96b241 | 17246 | dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
1da177e4 LT |
17247 | err = -ENOMEM; |
17248 | goto err_out_free_dev; | |
17249 | } | |
17250 | ||
c9cab24e MC |
17251 | if (tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761 || |
17252 | tp->pdev->device == PCI_DEVICE_ID_TIGON3_5761E || | |
17253 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761S || | |
17254 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5761SE || | |
17255 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717 || | |
79d49695 | 17256 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5717_C || |
c9cab24e MC |
17257 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5718 || |
17258 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5719 || | |
c65a17f4 MC |
17259 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5720 || |
17260 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5762 || | |
17261 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5725 || | |
17262 | tp->pdev->device == TG3PCI_DEVICE_TIGON3_5727) { | |
c9cab24e MC |
17263 | tg3_flag_set(tp, ENABLE_APE); |
17264 | tp->aperegs = pci_ioremap_bar(pdev, BAR_2); | |
17265 | if (!tp->aperegs) { | |
17266 | dev_err(&pdev->dev, | |
17267 | "Cannot map APE registers, aborting\n"); | |
17268 | err = -ENOMEM; | |
17269 | goto err_out_iounmap; | |
17270 | } | |
17271 | } | |
17272 | ||
1da177e4 LT |
17273 | tp->rx_pending = TG3_DEF_RX_RING_PENDING; |
17274 | tp->rx_jumbo_pending = TG3_DEF_RX_JUMBO_RING_PENDING; | |
1da177e4 | 17275 | |
1da177e4 | 17276 | dev->ethtool_ops = &tg3_ethtool_ops; |
1da177e4 | 17277 | dev->watchdog_timeo = TG3_TX_TIMEOUT; |
2ffcc981 | 17278 | dev->netdev_ops = &tg3_netdev_ops; |
1da177e4 | 17279 | dev->irq = pdev->irq; |
1da177e4 | 17280 | |
3d567e0e | 17281 | err = tg3_get_invariants(tp, ent); |
1da177e4 | 17282 | if (err) { |
ab96b241 MC |
17283 | dev_err(&pdev->dev, |
17284 | "Problem fetching invariants of chip, aborting\n"); | |
c9cab24e | 17285 | goto err_out_apeunmap; |
1da177e4 LT |
17286 | } |
17287 | ||
4a29cc2e MC |
17288 | /* The EPB bridge inside 5714, 5715, and 5780 and any |
17289 | * device behind the EPB cannot support DMA addresses > 40-bit. | |
72f2afb8 MC |
17290 | * On 64-bit systems with IOMMU, use 40-bit dma_mask. |
17291 | * On 64-bit systems without IOMMU, use 64-bit dma_mask and | |
17292 | * do DMA address check in tg3_start_xmit(). | |
17293 | */ | |
63c3a66f | 17294 | if (tg3_flag(tp, IS_5788)) |
284901a9 | 17295 | persist_dma_mask = dma_mask = DMA_BIT_MASK(32); |
63c3a66f | 17296 | else if (tg3_flag(tp, 40BIT_DMA_BUG)) { |
50cf156a | 17297 | persist_dma_mask = dma_mask = DMA_BIT_MASK(40); |
72f2afb8 | 17298 | #ifdef CONFIG_HIGHMEM |
6a35528a | 17299 | dma_mask = DMA_BIT_MASK(64); |
72f2afb8 | 17300 | #endif |
4a29cc2e | 17301 | } else |
6a35528a | 17302 | persist_dma_mask = dma_mask = DMA_BIT_MASK(64); |
72f2afb8 MC |
17303 | |
17304 | /* Configure DMA attributes. */ | |
284901a9 | 17305 | if (dma_mask > DMA_BIT_MASK(32)) { |
72f2afb8 MC |
17306 | err = pci_set_dma_mask(pdev, dma_mask); |
17307 | if (!err) { | |
0da0606f | 17308 | features |= NETIF_F_HIGHDMA; |
72f2afb8 MC |
17309 | err = pci_set_consistent_dma_mask(pdev, |
17310 | persist_dma_mask); | |
17311 | if (err < 0) { | |
ab96b241 MC |
17312 | dev_err(&pdev->dev, "Unable to obtain 64 bit " |
17313 | "DMA for consistent allocations\n"); | |
c9cab24e | 17314 | goto err_out_apeunmap; |
72f2afb8 MC |
17315 | } |
17316 | } | |
17317 | } | |
284901a9 YH |
17318 | if (err || dma_mask == DMA_BIT_MASK(32)) { |
17319 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); | |
72f2afb8 | 17320 | if (err) { |
ab96b241 MC |
17321 | dev_err(&pdev->dev, |
17322 | "No usable DMA configuration, aborting\n"); | |
c9cab24e | 17323 | goto err_out_apeunmap; |
72f2afb8 MC |
17324 | } |
17325 | } | |
17326 | ||
fdfec172 | 17327 | tg3_init_bufmgr_config(tp); |
1da177e4 | 17328 | |
0da0606f MC |
17329 | /* 5700 B0 chips do not support checksumming correctly due |
17330 | * to hardware bugs. | |
17331 | */ | |
4153577a | 17332 | if (tg3_chip_rev_id(tp) != CHIPREV_ID_5700_B0) { |
0da0606f MC |
17333 | features |= NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM; |
17334 | ||
17335 | if (tg3_flag(tp, 5755_PLUS)) | |
17336 | features |= NETIF_F_IPV6_CSUM; | |
17337 | } | |
17338 | ||
4e3a7aaa MC |
17339 | /* TSO is on by default on chips that support hardware TSO. |
17340 | * Firmware TSO on older chips gives lower performance, so it | |
17341 | * is off by default, but can be enabled using ethtool. | |
17342 | */ | |
63c3a66f JP |
17343 | if ((tg3_flag(tp, HW_TSO_1) || |
17344 | tg3_flag(tp, HW_TSO_2) || | |
17345 | tg3_flag(tp, HW_TSO_3)) && | |
0da0606f MC |
17346 | (features & NETIF_F_IP_CSUM)) |
17347 | features |= NETIF_F_TSO; | |
63c3a66f | 17348 | if (tg3_flag(tp, HW_TSO_2) || tg3_flag(tp, HW_TSO_3)) { |
0da0606f MC |
17349 | if (features & NETIF_F_IPV6_CSUM) |
17350 | features |= NETIF_F_TSO6; | |
63c3a66f | 17351 | if (tg3_flag(tp, HW_TSO_3) || |
4153577a JP |
17352 | tg3_asic_rev(tp) == ASIC_REV_5761 || |
17353 | (tg3_asic_rev(tp) == ASIC_REV_5784 && | |
17354 | tg3_chip_rev(tp) != CHIPREV_5784_AX) || | |
17355 | tg3_asic_rev(tp) == ASIC_REV_5785 || | |
17356 | tg3_asic_rev(tp) == ASIC_REV_57780) | |
0da0606f | 17357 | features |= NETIF_F_TSO_ECN; |
b0026624 | 17358 | } |
1da177e4 | 17359 | |
8d450881 VY |
17360 | dev->features |= features | NETIF_F_HW_VLAN_CTAG_TX | |
17361 | NETIF_F_HW_VLAN_CTAG_RX; | |
d542fe27 MC |
17362 | dev->vlan_features |= features; |
17363 | ||
06c03c02 MB |
17364 | /* |
17365 | * Add loopback capability only for a subset of devices that support | |
17366 | * MAC-LOOPBACK. Eventually this need to be enhanced to allow INT-PHY | |
17367 | * loopback for the remaining devices. | |
17368 | */ | |
4153577a | 17369 | if (tg3_asic_rev(tp) != ASIC_REV_5780 && |
06c03c02 MB |
17370 | !tg3_flag(tp, CPMU_PRESENT)) |
17371 | /* Add the loopback capability */ | |
0da0606f MC |
17372 | features |= NETIF_F_LOOPBACK; |
17373 | ||
0da0606f | 17374 | dev->hw_features |= features; |
06c03c02 | 17375 | |
4153577a | 17376 | if (tg3_chip_rev_id(tp) == CHIPREV_ID_5705_A1 && |
63c3a66f | 17377 | !tg3_flag(tp, TSO_CAPABLE) && |
1da177e4 | 17378 | !(tr32(TG3PCI_PCISTATE) & PCISTATE_BUS_SPEED_HIGH)) { |
63c3a66f | 17379 | tg3_flag_set(tp, MAX_RXPEND_64); |
1da177e4 LT |
17380 | tp->rx_pending = 63; |
17381 | } | |
17382 | ||
1da177e4 LT |
17383 | err = tg3_get_device_address(tp); |
17384 | if (err) { | |
ab96b241 MC |
17385 | dev_err(&pdev->dev, |
17386 | "Could not obtain valid ethernet address, aborting\n"); | |
c9cab24e | 17387 | goto err_out_apeunmap; |
c88864df MC |
17388 | } |
17389 | ||
1da177e4 LT |
17390 | /* |
17391 | * Reset chip in case UNDI or EFI driver did not shutdown | |
17392 | * DMA self test will enable WDMAC and we'll see (spurious) | |
17393 | * pending DMA on the PCI bus at that point. | |
17394 | */ | |
17395 | if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) || | |
17396 | (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) { | |
1da177e4 | 17397 | tw32(MEMARB_MODE, MEMARB_MODE_ENABLE); |
944d980e | 17398 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
1da177e4 LT |
17399 | } |
17400 | ||
17401 | err = tg3_test_dma(tp); | |
17402 | if (err) { | |
ab96b241 | 17403 | dev_err(&pdev->dev, "DMA engine test failed, aborting\n"); |
c88864df | 17404 | goto err_out_apeunmap; |
1da177e4 LT |
17405 | } |
17406 | ||
78f90dcf MC |
17407 | intmbx = MAILBOX_INTERRUPT_0 + TG3_64BIT_REG_LOW; |
17408 | rcvmbx = MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW; | |
17409 | sndmbx = MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW; | |
6fd45cb8 | 17410 | for (i = 0; i < tp->irq_max; i++) { |
78f90dcf MC |
17411 | struct tg3_napi *tnapi = &tp->napi[i]; |
17412 | ||
17413 | tnapi->tp = tp; | |
17414 | tnapi->tx_pending = TG3_DEF_TX_RING_PENDING; | |
17415 | ||
17416 | tnapi->int_mbox = intmbx; | |
93a700a9 | 17417 | if (i <= 4) |
78f90dcf MC |
17418 | intmbx += 0x8; |
17419 | else | |
17420 | intmbx += 0x4; | |
17421 | ||
17422 | tnapi->consmbox = rcvmbx; | |
17423 | tnapi->prodmbox = sndmbx; | |
17424 | ||
66cfd1bd | 17425 | if (i) |
78f90dcf | 17426 | tnapi->coal_now = HOSTCC_MODE_COAL_VEC1_NOW << (i - 1); |
66cfd1bd | 17427 | else |
78f90dcf | 17428 | tnapi->coal_now = HOSTCC_MODE_NOW; |
78f90dcf | 17429 | |
63c3a66f | 17430 | if (!tg3_flag(tp, SUPPORT_MSIX)) |
78f90dcf MC |
17431 | break; |
17432 | ||
17433 | /* | |
17434 | * If we support MSIX, we'll be using RSS. If we're using | |
17435 | * RSS, the first vector only handles link interrupts and the | |
17436 | * remaining vectors handle rx and tx interrupts. Reuse the | |
17437 | * mailbox values for the next iteration. The values we setup | |
17438 | * above are still useful for the single vectored mode. | |
17439 | */ | |
17440 | if (!i) | |
17441 | continue; | |
17442 | ||
17443 | rcvmbx += 0x8; | |
17444 | ||
17445 | if (sndmbx & 0x4) | |
17446 | sndmbx -= 0x4; | |
17447 | else | |
17448 | sndmbx += 0xc; | |
17449 | } | |
17450 | ||
15f9850d DM |
17451 | tg3_init_coal(tp); |
17452 | ||
c49a1561 MC |
17453 | pci_set_drvdata(pdev, dev); |
17454 | ||
4153577a JP |
17455 | if (tg3_asic_rev(tp) == ASIC_REV_5719 || |
17456 | tg3_asic_rev(tp) == ASIC_REV_5720 || | |
17457 | tg3_asic_rev(tp) == ASIC_REV_5762) | |
fb4ce8ad MC |
17458 | tg3_flag_set(tp, PTP_CAPABLE); |
17459 | ||
cd0d7228 MC |
17460 | if (tg3_flag(tp, 5717_PLUS)) { |
17461 | /* Resume a low-power mode */ | |
17462 | tg3_frob_aux_power(tp, false); | |
17463 | } | |
17464 | ||
21f7638e MC |
17465 | tg3_timer_init(tp); |
17466 | ||
402e1398 MC |
17467 | tg3_carrier_off(tp); |
17468 | ||
1da177e4 LT |
17469 | err = register_netdev(dev); |
17470 | if (err) { | |
ab96b241 | 17471 | dev_err(&pdev->dev, "Cannot register net device, aborting\n"); |
0d3031d9 | 17472 | goto err_out_apeunmap; |
1da177e4 LT |
17473 | } |
17474 | ||
05dbe005 JP |
17475 | netdev_info(dev, "Tigon3 [partno(%s) rev %04x] (%s) MAC address %pM\n", |
17476 | tp->board_part_number, | |
4153577a | 17477 | tg3_chip_rev_id(tp), |
05dbe005 JP |
17478 | tg3_bus_string(tp, str), |
17479 | dev->dev_addr); | |
1da177e4 | 17480 | |
f07e9af3 | 17481 | if (tp->phy_flags & TG3_PHYFLG_IS_CONNECTED) { |
3f0e3ad7 MC |
17482 | struct phy_device *phydev; |
17483 | phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR]; | |
5129c3a3 MC |
17484 | netdev_info(dev, |
17485 | "attached PHY driver [%s] (mii_bus:phy_addr=%s)\n", | |
05dbe005 | 17486 | phydev->drv->name, dev_name(&phydev->dev)); |
f07e9af3 MC |
17487 | } else { |
17488 | char *ethtype; | |
17489 | ||
17490 | if (tp->phy_flags & TG3_PHYFLG_10_100_ONLY) | |
17491 | ethtype = "10/100Base-TX"; | |
17492 | else if (tp->phy_flags & TG3_PHYFLG_ANY_SERDES) | |
17493 | ethtype = "1000Base-SX"; | |
17494 | else | |
17495 | ethtype = "10/100/1000Base-T"; | |
17496 | ||
5129c3a3 | 17497 | netdev_info(dev, "attached PHY is %s (%s Ethernet) " |
47007831 MC |
17498 | "(WireSpeed[%d], EEE[%d])\n", |
17499 | tg3_phy_string(tp), ethtype, | |
17500 | (tp->phy_flags & TG3_PHYFLG_NO_ETH_WIRE_SPEED) == 0, | |
17501 | (tp->phy_flags & TG3_PHYFLG_EEE_CAP) != 0); | |
f07e9af3 | 17502 | } |
05dbe005 JP |
17503 | |
17504 | netdev_info(dev, "RXcsums[%d] LinkChgREG[%d] MIirq[%d] ASF[%d] TSOcap[%d]\n", | |
dc668910 | 17505 | (dev->features & NETIF_F_RXCSUM) != 0, |
63c3a66f | 17506 | tg3_flag(tp, USE_LINKCHG_REG) != 0, |
f07e9af3 | 17507 | (tp->phy_flags & TG3_PHYFLG_USE_MI_INTERRUPT) != 0, |
63c3a66f JP |
17508 | tg3_flag(tp, ENABLE_ASF) != 0, |
17509 | tg3_flag(tp, TSO_CAPABLE) != 0); | |
05dbe005 JP |
17510 | netdev_info(dev, "dma_rwctrl[%08x] dma_mask[%d-bit]\n", |
17511 | tp->dma_rwctrl, | |
17512 | pdev->dma_mask == DMA_BIT_MASK(32) ? 32 : | |
17513 | ((u64)pdev->dma_mask) == DMA_BIT_MASK(40) ? 40 : 64); | |
1da177e4 | 17514 | |
b45aa2f6 MC |
17515 | pci_save_state(pdev); |
17516 | ||
1da177e4 LT |
17517 | return 0; |
17518 | ||
0d3031d9 MC |
17519 | err_out_apeunmap: |
17520 | if (tp->aperegs) { | |
17521 | iounmap(tp->aperegs); | |
17522 | tp->aperegs = NULL; | |
17523 | } | |
17524 | ||
1da177e4 | 17525 | err_out_iounmap: |
6892914f MC |
17526 | if (tp->regs) { |
17527 | iounmap(tp->regs); | |
22abe310 | 17528 | tp->regs = NULL; |
6892914f | 17529 | } |
1da177e4 LT |
17530 | |
17531 | err_out_free_dev: | |
17532 | free_netdev(dev); | |
17533 | ||
16821285 MC |
17534 | err_out_power_down: |
17535 | pci_set_power_state(pdev, PCI_D3hot); | |
17536 | ||
1da177e4 LT |
17537 | err_out_free_res: |
17538 | pci_release_regions(pdev); | |
17539 | ||
17540 | err_out_disable_pdev: | |
17541 | pci_disable_device(pdev); | |
17542 | pci_set_drvdata(pdev, NULL); | |
17543 | return err; | |
17544 | } | |
17545 | ||
229b1ad1 | 17546 | static void tg3_remove_one(struct pci_dev *pdev) |
1da177e4 LT |
17547 | { |
17548 | struct net_device *dev = pci_get_drvdata(pdev); | |
17549 | ||
17550 | if (dev) { | |
17551 | struct tg3 *tp = netdev_priv(dev); | |
17552 | ||
e3c5530b | 17553 | release_firmware(tp->fw); |
077f849d | 17554 | |
db219973 | 17555 | tg3_reset_task_cancel(tp); |
158d7abd | 17556 | |
e730c823 | 17557 | if (tg3_flag(tp, USE_PHYLIB)) { |
b02fd9e3 | 17558 | tg3_phy_fini(tp); |
158d7abd | 17559 | tg3_mdio_fini(tp); |
b02fd9e3 | 17560 | } |
158d7abd | 17561 | |
1da177e4 | 17562 | unregister_netdev(dev); |
0d3031d9 MC |
17563 | if (tp->aperegs) { |
17564 | iounmap(tp->aperegs); | |
17565 | tp->aperegs = NULL; | |
17566 | } | |
6892914f MC |
17567 | if (tp->regs) { |
17568 | iounmap(tp->regs); | |
22abe310 | 17569 | tp->regs = NULL; |
6892914f | 17570 | } |
1da177e4 LT |
17571 | free_netdev(dev); |
17572 | pci_release_regions(pdev); | |
17573 | pci_disable_device(pdev); | |
17574 | pci_set_drvdata(pdev, NULL); | |
17575 | } | |
17576 | } | |
17577 | ||
aa6027ca | 17578 | #ifdef CONFIG_PM_SLEEP |
c866b7ea | 17579 | static int tg3_suspend(struct device *device) |
1da177e4 | 17580 | { |
c866b7ea | 17581 | struct pci_dev *pdev = to_pci_dev(device); |
1da177e4 LT |
17582 | struct net_device *dev = pci_get_drvdata(pdev); |
17583 | struct tg3 *tp = netdev_priv(dev); | |
17584 | int err; | |
17585 | ||
17586 | if (!netif_running(dev)) | |
17587 | return 0; | |
17588 | ||
db219973 | 17589 | tg3_reset_task_cancel(tp); |
b02fd9e3 | 17590 | tg3_phy_stop(tp); |
1da177e4 LT |
17591 | tg3_netif_stop(tp); |
17592 | ||
21f7638e | 17593 | tg3_timer_stop(tp); |
1da177e4 | 17594 | |
f47c11ee | 17595 | tg3_full_lock(tp, 1); |
1da177e4 | 17596 | tg3_disable_ints(tp); |
f47c11ee | 17597 | tg3_full_unlock(tp); |
1da177e4 LT |
17598 | |
17599 | netif_device_detach(dev); | |
17600 | ||
f47c11ee | 17601 | tg3_full_lock(tp, 0); |
944d980e | 17602 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 1); |
63c3a66f | 17603 | tg3_flag_clear(tp, INIT_COMPLETE); |
f47c11ee | 17604 | tg3_full_unlock(tp); |
1da177e4 | 17605 | |
c866b7ea | 17606 | err = tg3_power_down_prepare(tp); |
1da177e4 | 17607 | if (err) { |
b02fd9e3 MC |
17608 | int err2; |
17609 | ||
f47c11ee | 17610 | tg3_full_lock(tp, 0); |
1da177e4 | 17611 | |
63c3a66f | 17612 | tg3_flag_set(tp, INIT_COMPLETE); |
953c96e0 | 17613 | err2 = tg3_restart_hw(tp, true); |
b02fd9e3 | 17614 | if (err2) |
b9ec6c1b | 17615 | goto out; |
1da177e4 | 17616 | |
21f7638e | 17617 | tg3_timer_start(tp); |
1da177e4 LT |
17618 | |
17619 | netif_device_attach(dev); | |
17620 | tg3_netif_start(tp); | |
17621 | ||
b9ec6c1b | 17622 | out: |
f47c11ee | 17623 | tg3_full_unlock(tp); |
b02fd9e3 MC |
17624 | |
17625 | if (!err2) | |
17626 | tg3_phy_start(tp); | |
1da177e4 LT |
17627 | } |
17628 | ||
17629 | return err; | |
17630 | } | |
17631 | ||
c866b7ea | 17632 | static int tg3_resume(struct device *device) |
1da177e4 | 17633 | { |
c866b7ea | 17634 | struct pci_dev *pdev = to_pci_dev(device); |
1da177e4 LT |
17635 | struct net_device *dev = pci_get_drvdata(pdev); |
17636 | struct tg3 *tp = netdev_priv(dev); | |
17637 | int err; | |
17638 | ||
17639 | if (!netif_running(dev)) | |
17640 | return 0; | |
17641 | ||
1da177e4 LT |
17642 | netif_device_attach(dev); |
17643 | ||
f47c11ee | 17644 | tg3_full_lock(tp, 0); |
1da177e4 | 17645 | |
63c3a66f | 17646 | tg3_flag_set(tp, INIT_COMPLETE); |
942d1af0 NS |
17647 | err = tg3_restart_hw(tp, |
17648 | !(tp->phy_flags & TG3_PHYFLG_KEEP_LINK_ON_PWRDN)); | |
b9ec6c1b MC |
17649 | if (err) |
17650 | goto out; | |
1da177e4 | 17651 | |
21f7638e | 17652 | tg3_timer_start(tp); |
1da177e4 | 17653 | |
1da177e4 LT |
17654 | tg3_netif_start(tp); |
17655 | ||
b9ec6c1b | 17656 | out: |
f47c11ee | 17657 | tg3_full_unlock(tp); |
1da177e4 | 17658 | |
b02fd9e3 MC |
17659 | if (!err) |
17660 | tg3_phy_start(tp); | |
17661 | ||
b9ec6c1b | 17662 | return err; |
1da177e4 | 17663 | } |
42df36a6 | 17664 | #endif /* CONFIG_PM_SLEEP */ |
1da177e4 | 17665 | |
c866b7ea RW |
17666 | static SIMPLE_DEV_PM_OPS(tg3_pm_ops, tg3_suspend, tg3_resume); |
17667 | ||
b45aa2f6 MC |
17668 | /** |
17669 | * tg3_io_error_detected - called when PCI error is detected | |
17670 | * @pdev: Pointer to PCI device | |
17671 | * @state: The current pci connection state | |
17672 | * | |
17673 | * This function is called after a PCI bus error affecting | |
17674 | * this device has been detected. | |
17675 | */ | |
17676 | static pci_ers_result_t tg3_io_error_detected(struct pci_dev *pdev, | |
17677 | pci_channel_state_t state) | |
17678 | { | |
17679 | struct net_device *netdev = pci_get_drvdata(pdev); | |
17680 | struct tg3 *tp = netdev_priv(netdev); | |
17681 | pci_ers_result_t err = PCI_ERS_RESULT_NEED_RESET; | |
17682 | ||
17683 | netdev_info(netdev, "PCI I/O error detected\n"); | |
17684 | ||
17685 | rtnl_lock(); | |
17686 | ||
17687 | if (!netif_running(netdev)) | |
17688 | goto done; | |
17689 | ||
17690 | tg3_phy_stop(tp); | |
17691 | ||
17692 | tg3_netif_stop(tp); | |
17693 | ||
21f7638e | 17694 | tg3_timer_stop(tp); |
b45aa2f6 MC |
17695 | |
17696 | /* Want to make sure that the reset task doesn't run */ | |
db219973 | 17697 | tg3_reset_task_cancel(tp); |
b45aa2f6 MC |
17698 | |
17699 | netif_device_detach(netdev); | |
17700 | ||
17701 | /* Clean up software state, even if MMIO is blocked */ | |
17702 | tg3_full_lock(tp, 0); | |
17703 | tg3_halt(tp, RESET_KIND_SHUTDOWN, 0); | |
17704 | tg3_full_unlock(tp); | |
17705 | ||
17706 | done: | |
17707 | if (state == pci_channel_io_perm_failure) | |
17708 | err = PCI_ERS_RESULT_DISCONNECT; | |
17709 | else | |
17710 | pci_disable_device(pdev); | |
17711 | ||
17712 | rtnl_unlock(); | |
17713 | ||
17714 | return err; | |
17715 | } | |
17716 | ||
17717 | /** | |
17718 | * tg3_io_slot_reset - called after the pci bus has been reset. | |
17719 | * @pdev: Pointer to PCI device | |
17720 | * | |
17721 | * Restart the card from scratch, as if from a cold-boot. | |
17722 | * At this point, the card has exprienced a hard reset, | |
17723 | * followed by fixups by BIOS, and has its config space | |
17724 | * set up identically to what it was at cold boot. | |
17725 | */ | |
17726 | static pci_ers_result_t tg3_io_slot_reset(struct pci_dev *pdev) | |
17727 | { | |
17728 | struct net_device *netdev = pci_get_drvdata(pdev); | |
17729 | struct tg3 *tp = netdev_priv(netdev); | |
17730 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
17731 | int err; | |
17732 | ||
17733 | rtnl_lock(); | |
17734 | ||
17735 | if (pci_enable_device(pdev)) { | |
17736 | netdev_err(netdev, "Cannot re-enable PCI device after reset.\n"); | |
17737 | goto done; | |
17738 | } | |
17739 | ||
17740 | pci_set_master(pdev); | |
17741 | pci_restore_state(pdev); | |
17742 | pci_save_state(pdev); | |
17743 | ||
17744 | if (!netif_running(netdev)) { | |
17745 | rc = PCI_ERS_RESULT_RECOVERED; | |
17746 | goto done; | |
17747 | } | |
17748 | ||
17749 | err = tg3_power_up(tp); | |
bed9829f | 17750 | if (err) |
b45aa2f6 | 17751 | goto done; |
b45aa2f6 MC |
17752 | |
17753 | rc = PCI_ERS_RESULT_RECOVERED; | |
17754 | ||
17755 | done: | |
17756 | rtnl_unlock(); | |
17757 | ||
17758 | return rc; | |
17759 | } | |
17760 | ||
17761 | /** | |
17762 | * tg3_io_resume - called when traffic can start flowing again. | |
17763 | * @pdev: Pointer to PCI device | |
17764 | * | |
17765 | * This callback is called when the error recovery driver tells | |
17766 | * us that its OK to resume normal operation. | |
17767 | */ | |
17768 | static void tg3_io_resume(struct pci_dev *pdev) | |
17769 | { | |
17770 | struct net_device *netdev = pci_get_drvdata(pdev); | |
17771 | struct tg3 *tp = netdev_priv(netdev); | |
17772 | int err; | |
17773 | ||
17774 | rtnl_lock(); | |
17775 | ||
17776 | if (!netif_running(netdev)) | |
17777 | goto done; | |
17778 | ||
17779 | tg3_full_lock(tp, 0); | |
63c3a66f | 17780 | tg3_flag_set(tp, INIT_COMPLETE); |
953c96e0 | 17781 | err = tg3_restart_hw(tp, true); |
b45aa2f6 | 17782 | if (err) { |
35763066 | 17783 | tg3_full_unlock(tp); |
b45aa2f6 MC |
17784 | netdev_err(netdev, "Cannot restart hardware after reset.\n"); |
17785 | goto done; | |
17786 | } | |
17787 | ||
17788 | netif_device_attach(netdev); | |
17789 | ||
21f7638e | 17790 | tg3_timer_start(tp); |
b45aa2f6 MC |
17791 | |
17792 | tg3_netif_start(tp); | |
17793 | ||
35763066 NNS |
17794 | tg3_full_unlock(tp); |
17795 | ||
b45aa2f6 MC |
17796 | tg3_phy_start(tp); |
17797 | ||
17798 | done: | |
17799 | rtnl_unlock(); | |
17800 | } | |
17801 | ||
3646f0e5 | 17802 | static const struct pci_error_handlers tg3_err_handler = { |
b45aa2f6 MC |
17803 | .error_detected = tg3_io_error_detected, |
17804 | .slot_reset = tg3_io_slot_reset, | |
17805 | .resume = tg3_io_resume | |
17806 | }; | |
17807 | ||
1da177e4 LT |
17808 | static struct pci_driver tg3_driver = { |
17809 | .name = DRV_MODULE_NAME, | |
17810 | .id_table = tg3_pci_tbl, | |
17811 | .probe = tg3_init_one, | |
229b1ad1 | 17812 | .remove = tg3_remove_one, |
b45aa2f6 | 17813 | .err_handler = &tg3_err_handler, |
42df36a6 | 17814 | .driver.pm = &tg3_pm_ops, |
1da177e4 LT |
17815 | }; |
17816 | ||
17817 | static int __init tg3_init(void) | |
17818 | { | |
29917620 | 17819 | return pci_register_driver(&tg3_driver); |
1da177e4 LT |
17820 | } |
17821 | ||
17822 | static void __exit tg3_cleanup(void) | |
17823 | { | |
17824 | pci_unregister_driver(&tg3_driver); | |
17825 | } | |
17826 | ||
17827 | module_init(tg3_init); | |
17828 | module_exit(tg3_cleanup); |