diff options
Diffstat (limited to 'drivers/net/e1000e/ethtool.c')
-rw-r--r-- | drivers/net/e1000e/ethtool.c | 2082 |
1 files changed, 2082 insertions, 0 deletions
diff --git a/drivers/net/e1000e/ethtool.c b/drivers/net/e1000e/ethtool.c new file mode 100644 index 00000000000..6a0526a59a8 --- /dev/null +++ b/drivers/net/e1000e/ethtool.c | |||
@@ -0,0 +1,2082 @@ | |||
1 | /******************************************************************************* | ||
2 | |||
3 | Intel PRO/1000 Linux driver | ||
4 | Copyright(c) 1999 - 2011 Intel Corporation. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify it | ||
7 | under the terms and conditions of the GNU General Public License, | ||
8 | version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License along with | ||
16 | this program; if not, write to the Free Software Foundation, Inc., | ||
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | |||
19 | The full GNU General Public License is included in this distribution in | ||
20 | the file called "COPYING". | ||
21 | |||
22 | Contact Information: | ||
23 | Linux NICS <linux.nics@intel.com> | ||
24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> | ||
25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
26 | |||
27 | *******************************************************************************/ | ||
28 | |||
29 | /* ethtool support for e1000 */ | ||
30 | |||
31 | #include <linux/netdevice.h> | ||
32 | #include <linux/interrupt.h> | ||
33 | #include <linux/ethtool.h> | ||
34 | #include <linux/pci.h> | ||
35 | #include <linux/slab.h> | ||
36 | #include <linux/delay.h> | ||
37 | |||
38 | #include "e1000.h" | ||
39 | |||
40 | enum {NETDEV_STATS, E1000_STATS}; | ||
41 | |||
42 | struct e1000_stats { | ||
43 | char stat_string[ETH_GSTRING_LEN]; | ||
44 | int type; | ||
45 | int sizeof_stat; | ||
46 | int stat_offset; | ||
47 | }; | ||
48 | |||
49 | #define E1000_STAT(str, m) { \ | ||
50 | .stat_string = str, \ | ||
51 | .type = E1000_STATS, \ | ||
52 | .sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \ | ||
53 | .stat_offset = offsetof(struct e1000_adapter, m) } | ||
54 | #define E1000_NETDEV_STAT(str, m) { \ | ||
55 | .stat_string = str, \ | ||
56 | .type = NETDEV_STATS, \ | ||
57 | .sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \ | ||
58 | .stat_offset = offsetof(struct rtnl_link_stats64, m) } | ||
59 | |||
60 | static const struct e1000_stats e1000_gstrings_stats[] = { | ||
61 | E1000_STAT("rx_packets", stats.gprc), | ||
62 | E1000_STAT("tx_packets", stats.gptc), | ||
63 | E1000_STAT("rx_bytes", stats.gorc), | ||
64 | E1000_STAT("tx_bytes", stats.gotc), | ||
65 | E1000_STAT("rx_broadcast", stats.bprc), | ||
66 | E1000_STAT("tx_broadcast", stats.bptc), | ||
67 | E1000_STAT("rx_multicast", stats.mprc), | ||
68 | E1000_STAT("tx_multicast", stats.mptc), | ||
69 | E1000_NETDEV_STAT("rx_errors", rx_errors), | ||
70 | E1000_NETDEV_STAT("tx_errors", tx_errors), | ||
71 | E1000_NETDEV_STAT("tx_dropped", tx_dropped), | ||
72 | E1000_STAT("multicast", stats.mprc), | ||
73 | E1000_STAT("collisions", stats.colc), | ||
74 | E1000_NETDEV_STAT("rx_length_errors", rx_length_errors), | ||
75 | E1000_NETDEV_STAT("rx_over_errors", rx_over_errors), | ||
76 | E1000_STAT("rx_crc_errors", stats.crcerrs), | ||
77 | E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors), | ||
78 | E1000_STAT("rx_no_buffer_count", stats.rnbc), | ||
79 | E1000_STAT("rx_missed_errors", stats.mpc), | ||
80 | E1000_STAT("tx_aborted_errors", stats.ecol), | ||
81 | E1000_STAT("tx_carrier_errors", stats.tncrs), | ||
82 | E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors), | ||
83 | E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors), | ||
84 | E1000_STAT("tx_window_errors", stats.latecol), | ||
85 | E1000_STAT("tx_abort_late_coll", stats.latecol), | ||
86 | E1000_STAT("tx_deferred_ok", stats.dc), | ||
87 | E1000_STAT("tx_single_coll_ok", stats.scc), | ||
88 | E1000_STAT("tx_multi_coll_ok", stats.mcc), | ||
89 | E1000_STAT("tx_timeout_count", tx_timeout_count), | ||
90 | E1000_STAT("tx_restart_queue", restart_queue), | ||
91 | E1000_STAT("rx_long_length_errors", stats.roc), | ||
92 | E1000_STAT("rx_short_length_errors", stats.ruc), | ||
93 | E1000_STAT("rx_align_errors", stats.algnerrc), | ||
94 | E1000_STAT("tx_tcp_seg_good", stats.tsctc), | ||
95 | E1000_STAT("tx_tcp_seg_failed", stats.tsctfc), | ||
96 | E1000_STAT("rx_flow_control_xon", stats.xonrxc), | ||
97 | E1000_STAT("rx_flow_control_xoff", stats.xoffrxc), | ||
98 | E1000_STAT("tx_flow_control_xon", stats.xontxc), | ||
99 | E1000_STAT("tx_flow_control_xoff", stats.xofftxc), | ||
100 | E1000_STAT("rx_long_byte_count", stats.gorc), | ||
101 | E1000_STAT("rx_csum_offload_good", hw_csum_good), | ||
102 | E1000_STAT("rx_csum_offload_errors", hw_csum_err), | ||
103 | E1000_STAT("rx_header_split", rx_hdr_split), | ||
104 | E1000_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed), | ||
105 | E1000_STAT("tx_smbus", stats.mgptc), | ||
106 | E1000_STAT("rx_smbus", stats.mgprc), | ||
107 | E1000_STAT("dropped_smbus", stats.mgpdc), | ||
108 | E1000_STAT("rx_dma_failed", rx_dma_failed), | ||
109 | E1000_STAT("tx_dma_failed", tx_dma_failed), | ||
110 | }; | ||
111 | |||
112 | #define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats) | ||
113 | #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN) | ||
114 | static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = { | ||
115 | "Register test (offline)", "Eeprom test (offline)", | ||
116 | "Interrupt test (offline)", "Loopback test (offline)", | ||
117 | "Link test (on/offline)" | ||
118 | }; | ||
119 | #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test) | ||
120 | |||
121 | static int e1000_get_settings(struct net_device *netdev, | ||
122 | struct ethtool_cmd *ecmd) | ||
123 | { | ||
124 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
125 | struct e1000_hw *hw = &adapter->hw; | ||
126 | u32 speed; | ||
127 | |||
128 | if (hw->phy.media_type == e1000_media_type_copper) { | ||
129 | |||
130 | ecmd->supported = (SUPPORTED_10baseT_Half | | ||
131 | SUPPORTED_10baseT_Full | | ||
132 | SUPPORTED_100baseT_Half | | ||
133 | SUPPORTED_100baseT_Full | | ||
134 | SUPPORTED_1000baseT_Full | | ||
135 | SUPPORTED_Autoneg | | ||
136 | SUPPORTED_TP); | ||
137 | if (hw->phy.type == e1000_phy_ife) | ||
138 | ecmd->supported &= ~SUPPORTED_1000baseT_Full; | ||
139 | ecmd->advertising = ADVERTISED_TP; | ||
140 | |||
141 | if (hw->mac.autoneg == 1) { | ||
142 | ecmd->advertising |= ADVERTISED_Autoneg; | ||
143 | /* the e1000 autoneg seems to match ethtool nicely */ | ||
144 | ecmd->advertising |= hw->phy.autoneg_advertised; | ||
145 | } | ||
146 | |||
147 | ecmd->port = PORT_TP; | ||
148 | ecmd->phy_address = hw->phy.addr; | ||
149 | ecmd->transceiver = XCVR_INTERNAL; | ||
150 | |||
151 | } else { | ||
152 | ecmd->supported = (SUPPORTED_1000baseT_Full | | ||
153 | SUPPORTED_FIBRE | | ||
154 | SUPPORTED_Autoneg); | ||
155 | |||
156 | ecmd->advertising = (ADVERTISED_1000baseT_Full | | ||
157 | ADVERTISED_FIBRE | | ||
158 | ADVERTISED_Autoneg); | ||
159 | |||
160 | ecmd->port = PORT_FIBRE; | ||
161 | ecmd->transceiver = XCVR_EXTERNAL; | ||
162 | } | ||
163 | |||
164 | speed = -1; | ||
165 | ecmd->duplex = -1; | ||
166 | |||
167 | if (netif_running(netdev)) { | ||
168 | if (netif_carrier_ok(netdev)) { | ||
169 | speed = adapter->link_speed; | ||
170 | ecmd->duplex = adapter->link_duplex - 1; | ||
171 | } | ||
172 | } else { | ||
173 | u32 status = er32(STATUS); | ||
174 | if (status & E1000_STATUS_LU) { | ||
175 | if (status & E1000_STATUS_SPEED_1000) | ||
176 | speed = SPEED_1000; | ||
177 | else if (status & E1000_STATUS_SPEED_100) | ||
178 | speed = SPEED_100; | ||
179 | else | ||
180 | speed = SPEED_10; | ||
181 | |||
182 | if (status & E1000_STATUS_FD) | ||
183 | ecmd->duplex = DUPLEX_FULL; | ||
184 | else | ||
185 | ecmd->duplex = DUPLEX_HALF; | ||
186 | } | ||
187 | } | ||
188 | |||
189 | ethtool_cmd_speed_set(ecmd, speed); | ||
190 | ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) || | ||
191 | hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE; | ||
192 | |||
193 | /* MDI-X => 2; MDI =>1; Invalid =>0 */ | ||
194 | if ((hw->phy.media_type == e1000_media_type_copper) && | ||
195 | netif_carrier_ok(netdev)) | ||
196 | ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X : | ||
197 | ETH_TP_MDI; | ||
198 | else | ||
199 | ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID; | ||
200 | |||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx) | ||
205 | { | ||
206 | struct e1000_mac_info *mac = &adapter->hw.mac; | ||
207 | |||
208 | mac->autoneg = 0; | ||
209 | |||
210 | /* Make sure dplx is at most 1 bit and lsb of speed is not set | ||
211 | * for the switch() below to work */ | ||
212 | if ((spd & 1) || (dplx & ~1)) | ||
213 | goto err_inval; | ||
214 | |||
215 | /* Fiber NICs only allow 1000 gbps Full duplex */ | ||
216 | if ((adapter->hw.phy.media_type == e1000_media_type_fiber) && | ||
217 | spd != SPEED_1000 && | ||
218 | dplx != DUPLEX_FULL) { | ||
219 | goto err_inval; | ||
220 | } | ||
221 | |||
222 | switch (spd + dplx) { | ||
223 | case SPEED_10 + DUPLEX_HALF: | ||
224 | mac->forced_speed_duplex = ADVERTISE_10_HALF; | ||
225 | break; | ||
226 | case SPEED_10 + DUPLEX_FULL: | ||
227 | mac->forced_speed_duplex = ADVERTISE_10_FULL; | ||
228 | break; | ||
229 | case SPEED_100 + DUPLEX_HALF: | ||
230 | mac->forced_speed_duplex = ADVERTISE_100_HALF; | ||
231 | break; | ||
232 | case SPEED_100 + DUPLEX_FULL: | ||
233 | mac->forced_speed_duplex = ADVERTISE_100_FULL; | ||
234 | break; | ||
235 | case SPEED_1000 + DUPLEX_FULL: | ||
236 | mac->autoneg = 1; | ||
237 | adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL; | ||
238 | break; | ||
239 | case SPEED_1000 + DUPLEX_HALF: /* not supported */ | ||
240 | default: | ||
241 | goto err_inval; | ||
242 | } | ||
243 | return 0; | ||
244 | |||
245 | err_inval: | ||
246 | e_err("Unsupported Speed/Duplex configuration\n"); | ||
247 | return -EINVAL; | ||
248 | } | ||
249 | |||
250 | static int e1000_set_settings(struct net_device *netdev, | ||
251 | struct ethtool_cmd *ecmd) | ||
252 | { | ||
253 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
254 | struct e1000_hw *hw = &adapter->hw; | ||
255 | |||
256 | /* | ||
257 | * When SoL/IDER sessions are active, autoneg/speed/duplex | ||
258 | * cannot be changed | ||
259 | */ | ||
260 | if (e1000_check_reset_block(hw)) { | ||
261 | e_err("Cannot change link characteristics when SoL/IDER is " | ||
262 | "active.\n"); | ||
263 | return -EINVAL; | ||
264 | } | ||
265 | |||
266 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) | ||
267 | usleep_range(1000, 2000); | ||
268 | |||
269 | if (ecmd->autoneg == AUTONEG_ENABLE) { | ||
270 | hw->mac.autoneg = 1; | ||
271 | if (hw->phy.media_type == e1000_media_type_fiber) | ||
272 | hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full | | ||
273 | ADVERTISED_FIBRE | | ||
274 | ADVERTISED_Autoneg; | ||
275 | else | ||
276 | hw->phy.autoneg_advertised = ecmd->advertising | | ||
277 | ADVERTISED_TP | | ||
278 | ADVERTISED_Autoneg; | ||
279 | ecmd->advertising = hw->phy.autoneg_advertised; | ||
280 | if (adapter->fc_autoneg) | ||
281 | hw->fc.requested_mode = e1000_fc_default; | ||
282 | } else { | ||
283 | u32 speed = ethtool_cmd_speed(ecmd); | ||
284 | if (e1000_set_spd_dplx(adapter, speed, ecmd->duplex)) { | ||
285 | clear_bit(__E1000_RESETTING, &adapter->state); | ||
286 | return -EINVAL; | ||
287 | } | ||
288 | } | ||
289 | |||
290 | /* reset the link */ | ||
291 | |||
292 | if (netif_running(adapter->netdev)) { | ||
293 | e1000e_down(adapter); | ||
294 | e1000e_up(adapter); | ||
295 | } else { | ||
296 | e1000e_reset(adapter); | ||
297 | } | ||
298 | |||
299 | clear_bit(__E1000_RESETTING, &adapter->state); | ||
300 | return 0; | ||
301 | } | ||
302 | |||
303 | static void e1000_get_pauseparam(struct net_device *netdev, | ||
304 | struct ethtool_pauseparam *pause) | ||
305 | { | ||
306 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
307 | struct e1000_hw *hw = &adapter->hw; | ||
308 | |||
309 | pause->autoneg = | ||
310 | (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE); | ||
311 | |||
312 | if (hw->fc.current_mode == e1000_fc_rx_pause) { | ||
313 | pause->rx_pause = 1; | ||
314 | } else if (hw->fc.current_mode == e1000_fc_tx_pause) { | ||
315 | pause->tx_pause = 1; | ||
316 | } else if (hw->fc.current_mode == e1000_fc_full) { | ||
317 | pause->rx_pause = 1; | ||
318 | pause->tx_pause = 1; | ||
319 | } | ||
320 | } | ||
321 | |||
322 | static int e1000_set_pauseparam(struct net_device *netdev, | ||
323 | struct ethtool_pauseparam *pause) | ||
324 | { | ||
325 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
326 | struct e1000_hw *hw = &adapter->hw; | ||
327 | int retval = 0; | ||
328 | |||
329 | adapter->fc_autoneg = pause->autoneg; | ||
330 | |||
331 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) | ||
332 | usleep_range(1000, 2000); | ||
333 | |||
334 | if (adapter->fc_autoneg == AUTONEG_ENABLE) { | ||
335 | hw->fc.requested_mode = e1000_fc_default; | ||
336 | if (netif_running(adapter->netdev)) { | ||
337 | e1000e_down(adapter); | ||
338 | e1000e_up(adapter); | ||
339 | } else { | ||
340 | e1000e_reset(adapter); | ||
341 | } | ||
342 | } else { | ||
343 | if (pause->rx_pause && pause->tx_pause) | ||
344 | hw->fc.requested_mode = e1000_fc_full; | ||
345 | else if (pause->rx_pause && !pause->tx_pause) | ||
346 | hw->fc.requested_mode = e1000_fc_rx_pause; | ||
347 | else if (!pause->rx_pause && pause->tx_pause) | ||
348 | hw->fc.requested_mode = e1000_fc_tx_pause; | ||
349 | else if (!pause->rx_pause && !pause->tx_pause) | ||
350 | hw->fc.requested_mode = e1000_fc_none; | ||
351 | |||
352 | hw->fc.current_mode = hw->fc.requested_mode; | ||
353 | |||
354 | if (hw->phy.media_type == e1000_media_type_fiber) { | ||
355 | retval = hw->mac.ops.setup_link(hw); | ||
356 | /* implicit goto out */ | ||
357 | } else { | ||
358 | retval = e1000e_force_mac_fc(hw); | ||
359 | if (retval) | ||
360 | goto out; | ||
361 | e1000e_set_fc_watermarks(hw); | ||
362 | } | ||
363 | } | ||
364 | |||
365 | out: | ||
366 | clear_bit(__E1000_RESETTING, &adapter->state); | ||
367 | return retval; | ||
368 | } | ||
369 | |||
370 | static u32 e1000_get_rx_csum(struct net_device *netdev) | ||
371 | { | ||
372 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
373 | return adapter->flags & FLAG_RX_CSUM_ENABLED; | ||
374 | } | ||
375 | |||
376 | static int e1000_set_rx_csum(struct net_device *netdev, u32 data) | ||
377 | { | ||
378 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
379 | |||
380 | if (data) | ||
381 | adapter->flags |= FLAG_RX_CSUM_ENABLED; | ||
382 | else | ||
383 | adapter->flags &= ~FLAG_RX_CSUM_ENABLED; | ||
384 | |||
385 | if (netif_running(netdev)) | ||
386 | e1000e_reinit_locked(adapter); | ||
387 | else | ||
388 | e1000e_reset(adapter); | ||
389 | return 0; | ||
390 | } | ||
391 | |||
392 | static u32 e1000_get_tx_csum(struct net_device *netdev) | ||
393 | { | ||
394 | return (netdev->features & NETIF_F_HW_CSUM) != 0; | ||
395 | } | ||
396 | |||
397 | static int e1000_set_tx_csum(struct net_device *netdev, u32 data) | ||
398 | { | ||
399 | if (data) | ||
400 | netdev->features |= NETIF_F_HW_CSUM; | ||
401 | else | ||
402 | netdev->features &= ~NETIF_F_HW_CSUM; | ||
403 | |||
404 | return 0; | ||
405 | } | ||
406 | |||
407 | static int e1000_set_tso(struct net_device *netdev, u32 data) | ||
408 | { | ||
409 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
410 | |||
411 | if (data) { | ||
412 | netdev->features |= NETIF_F_TSO; | ||
413 | netdev->features |= NETIF_F_TSO6; | ||
414 | } else { | ||
415 | netdev->features &= ~NETIF_F_TSO; | ||
416 | netdev->features &= ~NETIF_F_TSO6; | ||
417 | } | ||
418 | |||
419 | adapter->flags |= FLAG_TSO_FORCE; | ||
420 | return 0; | ||
421 | } | ||
422 | |||
423 | static u32 e1000_get_msglevel(struct net_device *netdev) | ||
424 | { | ||
425 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
426 | return adapter->msg_enable; | ||
427 | } | ||
428 | |||
429 | static void e1000_set_msglevel(struct net_device *netdev, u32 data) | ||
430 | { | ||
431 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
432 | adapter->msg_enable = data; | ||
433 | } | ||
434 | |||
435 | static int e1000_get_regs_len(struct net_device *netdev) | ||
436 | { | ||
437 | #define E1000_REGS_LEN 32 /* overestimate */ | ||
438 | return E1000_REGS_LEN * sizeof(u32); | ||
439 | } | ||
440 | |||
441 | static void e1000_get_regs(struct net_device *netdev, | ||
442 | struct ethtool_regs *regs, void *p) | ||
443 | { | ||
444 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
445 | struct e1000_hw *hw = &adapter->hw; | ||
446 | u32 *regs_buff = p; | ||
447 | u16 phy_data; | ||
448 | |||
449 | memset(p, 0, E1000_REGS_LEN * sizeof(u32)); | ||
450 | |||
451 | regs->version = (1 << 24) | (adapter->pdev->revision << 16) | | ||
452 | adapter->pdev->device; | ||
453 | |||
454 | regs_buff[0] = er32(CTRL); | ||
455 | regs_buff[1] = er32(STATUS); | ||
456 | |||
457 | regs_buff[2] = er32(RCTL); | ||
458 | regs_buff[3] = er32(RDLEN); | ||
459 | regs_buff[4] = er32(RDH); | ||
460 | regs_buff[5] = er32(RDT); | ||
461 | regs_buff[6] = er32(RDTR); | ||
462 | |||
463 | regs_buff[7] = er32(TCTL); | ||
464 | regs_buff[8] = er32(TDLEN); | ||
465 | regs_buff[9] = er32(TDH); | ||
466 | regs_buff[10] = er32(TDT); | ||
467 | regs_buff[11] = er32(TIDV); | ||
468 | |||
469 | regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */ | ||
470 | |||
471 | /* ethtool doesn't use anything past this point, so all this | ||
472 | * code is likely legacy junk for apps that may or may not | ||
473 | * exist */ | ||
474 | if (hw->phy.type == e1000_phy_m88) { | ||
475 | e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); | ||
476 | regs_buff[13] = (u32)phy_data; /* cable length */ | ||
477 | regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */ | ||
478 | regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */ | ||
479 | regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */ | ||
480 | e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); | ||
481 | regs_buff[17] = (u32)phy_data; /* extended 10bt distance */ | ||
482 | regs_buff[18] = regs_buff[13]; /* cable polarity */ | ||
483 | regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */ | ||
484 | regs_buff[20] = regs_buff[17]; /* polarity correction */ | ||
485 | /* phy receive errors */ | ||
486 | regs_buff[22] = adapter->phy_stats.receive_errors; | ||
487 | regs_buff[23] = regs_buff[13]; /* mdix mode */ | ||
488 | } | ||
489 | regs_buff[21] = 0; /* was idle_errors */ | ||
490 | e1e_rphy(hw, PHY_1000T_STATUS, &phy_data); | ||
491 | regs_buff[24] = (u32)phy_data; /* phy local receiver status */ | ||
492 | regs_buff[25] = regs_buff[24]; /* phy remote receiver status */ | ||
493 | } | ||
494 | |||
495 | static int e1000_get_eeprom_len(struct net_device *netdev) | ||
496 | { | ||
497 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
498 | return adapter->hw.nvm.word_size * 2; | ||
499 | } | ||
500 | |||
501 | static int e1000_get_eeprom(struct net_device *netdev, | ||
502 | struct ethtool_eeprom *eeprom, u8 *bytes) | ||
503 | { | ||
504 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
505 | struct e1000_hw *hw = &adapter->hw; | ||
506 | u16 *eeprom_buff; | ||
507 | int first_word; | ||
508 | int last_word; | ||
509 | int ret_val = 0; | ||
510 | u16 i; | ||
511 | |||
512 | if (eeprom->len == 0) | ||
513 | return -EINVAL; | ||
514 | |||
515 | eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16); | ||
516 | |||
517 | first_word = eeprom->offset >> 1; | ||
518 | last_word = (eeprom->offset + eeprom->len - 1) >> 1; | ||
519 | |||
520 | eeprom_buff = kmalloc(sizeof(u16) * | ||
521 | (last_word - first_word + 1), GFP_KERNEL); | ||
522 | if (!eeprom_buff) | ||
523 | return -ENOMEM; | ||
524 | |||
525 | if (hw->nvm.type == e1000_nvm_eeprom_spi) { | ||
526 | ret_val = e1000_read_nvm(hw, first_word, | ||
527 | last_word - first_word + 1, | ||
528 | eeprom_buff); | ||
529 | } else { | ||
530 | for (i = 0; i < last_word - first_word + 1; i++) { | ||
531 | ret_val = e1000_read_nvm(hw, first_word + i, 1, | ||
532 | &eeprom_buff[i]); | ||
533 | if (ret_val) | ||
534 | break; | ||
535 | } | ||
536 | } | ||
537 | |||
538 | if (ret_val) { | ||
539 | /* a read error occurred, throw away the result */ | ||
540 | memset(eeprom_buff, 0xff, sizeof(u16) * | ||
541 | (last_word - first_word + 1)); | ||
542 | } else { | ||
543 | /* Device's eeprom is always little-endian, word addressable */ | ||
544 | for (i = 0; i < last_word - first_word + 1; i++) | ||
545 | le16_to_cpus(&eeprom_buff[i]); | ||
546 | } | ||
547 | |||
548 | memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len); | ||
549 | kfree(eeprom_buff); | ||
550 | |||
551 | return ret_val; | ||
552 | } | ||
553 | |||
554 | static int e1000_set_eeprom(struct net_device *netdev, | ||
555 | struct ethtool_eeprom *eeprom, u8 *bytes) | ||
556 | { | ||
557 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
558 | struct e1000_hw *hw = &adapter->hw; | ||
559 | u16 *eeprom_buff; | ||
560 | void *ptr; | ||
561 | int max_len; | ||
562 | int first_word; | ||
563 | int last_word; | ||
564 | int ret_val = 0; | ||
565 | u16 i; | ||
566 | |||
567 | if (eeprom->len == 0) | ||
568 | return -EOPNOTSUPP; | ||
569 | |||
570 | if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16))) | ||
571 | return -EFAULT; | ||
572 | |||
573 | if (adapter->flags & FLAG_READ_ONLY_NVM) | ||
574 | return -EINVAL; | ||
575 | |||
576 | max_len = hw->nvm.word_size * 2; | ||
577 | |||
578 | first_word = eeprom->offset >> 1; | ||
579 | last_word = (eeprom->offset + eeprom->len - 1) >> 1; | ||
580 | eeprom_buff = kmalloc(max_len, GFP_KERNEL); | ||
581 | if (!eeprom_buff) | ||
582 | return -ENOMEM; | ||
583 | |||
584 | ptr = (void *)eeprom_buff; | ||
585 | |||
586 | if (eeprom->offset & 1) { | ||
587 | /* need read/modify/write of first changed EEPROM word */ | ||
588 | /* only the second byte of the word is being modified */ | ||
589 | ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]); | ||
590 | ptr++; | ||
591 | } | ||
592 | if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) | ||
593 | /* need read/modify/write of last changed EEPROM word */ | ||
594 | /* only the first byte of the word is being modified */ | ||
595 | ret_val = e1000_read_nvm(hw, last_word, 1, | ||
596 | &eeprom_buff[last_word - first_word]); | ||
597 | |||
598 | if (ret_val) | ||
599 | goto out; | ||
600 | |||
601 | /* Device's eeprom is always little-endian, word addressable */ | ||
602 | for (i = 0; i < last_word - first_word + 1; i++) | ||
603 | le16_to_cpus(&eeprom_buff[i]); | ||
604 | |||
605 | memcpy(ptr, bytes, eeprom->len); | ||
606 | |||
607 | for (i = 0; i < last_word - first_word + 1; i++) | ||
608 | eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]); | ||
609 | |||
610 | ret_val = e1000_write_nvm(hw, first_word, | ||
611 | last_word - first_word + 1, eeprom_buff); | ||
612 | |||
613 | if (ret_val) | ||
614 | goto out; | ||
615 | |||
616 | /* | ||
617 | * Update the checksum over the first part of the EEPROM if needed | ||
618 | * and flush shadow RAM for applicable controllers | ||
619 | */ | ||
620 | if ((first_word <= NVM_CHECKSUM_REG) || | ||
621 | (hw->mac.type == e1000_82583) || | ||
622 | (hw->mac.type == e1000_82574) || | ||
623 | (hw->mac.type == e1000_82573)) | ||
624 | ret_val = e1000e_update_nvm_checksum(hw); | ||
625 | |||
626 | out: | ||
627 | kfree(eeprom_buff); | ||
628 | return ret_val; | ||
629 | } | ||
630 | |||
631 | static void e1000_get_drvinfo(struct net_device *netdev, | ||
632 | struct ethtool_drvinfo *drvinfo) | ||
633 | { | ||
634 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
635 | char firmware_version[32]; | ||
636 | |||
637 | strncpy(drvinfo->driver, e1000e_driver_name, | ||
638 | sizeof(drvinfo->driver) - 1); | ||
639 | strncpy(drvinfo->version, e1000e_driver_version, | ||
640 | sizeof(drvinfo->version) - 1); | ||
641 | |||
642 | /* | ||
643 | * EEPROM image version # is reported as firmware version # for | ||
644 | * PCI-E controllers | ||
645 | */ | ||
646 | snprintf(firmware_version, sizeof(firmware_version), "%d.%d-%d", | ||
647 | (adapter->eeprom_vers & 0xF000) >> 12, | ||
648 | (adapter->eeprom_vers & 0x0FF0) >> 4, | ||
649 | (adapter->eeprom_vers & 0x000F)); | ||
650 | |||
651 | strncpy(drvinfo->fw_version, firmware_version, | ||
652 | sizeof(drvinfo->fw_version) - 1); | ||
653 | strncpy(drvinfo->bus_info, pci_name(adapter->pdev), | ||
654 | sizeof(drvinfo->bus_info) - 1); | ||
655 | drvinfo->regdump_len = e1000_get_regs_len(netdev); | ||
656 | drvinfo->eedump_len = e1000_get_eeprom_len(netdev); | ||
657 | } | ||
658 | |||
659 | static void e1000_get_ringparam(struct net_device *netdev, | ||
660 | struct ethtool_ringparam *ring) | ||
661 | { | ||
662 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
663 | struct e1000_ring *tx_ring = adapter->tx_ring; | ||
664 | struct e1000_ring *rx_ring = adapter->rx_ring; | ||
665 | |||
666 | ring->rx_max_pending = E1000_MAX_RXD; | ||
667 | ring->tx_max_pending = E1000_MAX_TXD; | ||
668 | ring->rx_mini_max_pending = 0; | ||
669 | ring->rx_jumbo_max_pending = 0; | ||
670 | ring->rx_pending = rx_ring->count; | ||
671 | ring->tx_pending = tx_ring->count; | ||
672 | ring->rx_mini_pending = 0; | ||
673 | ring->rx_jumbo_pending = 0; | ||
674 | } | ||
675 | |||
676 | static int e1000_set_ringparam(struct net_device *netdev, | ||
677 | struct ethtool_ringparam *ring) | ||
678 | { | ||
679 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
680 | struct e1000_ring *tx_ring, *tx_old; | ||
681 | struct e1000_ring *rx_ring, *rx_old; | ||
682 | int err; | ||
683 | |||
684 | if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) | ||
685 | return -EINVAL; | ||
686 | |||
687 | while (test_and_set_bit(__E1000_RESETTING, &adapter->state)) | ||
688 | usleep_range(1000, 2000); | ||
689 | |||
690 | if (netif_running(adapter->netdev)) | ||
691 | e1000e_down(adapter); | ||
692 | |||
693 | tx_old = adapter->tx_ring; | ||
694 | rx_old = adapter->rx_ring; | ||
695 | |||
696 | err = -ENOMEM; | ||
697 | tx_ring = kmemdup(tx_old, sizeof(struct e1000_ring), GFP_KERNEL); | ||
698 | if (!tx_ring) | ||
699 | goto err_alloc_tx; | ||
700 | |||
701 | rx_ring = kmemdup(rx_old, sizeof(struct e1000_ring), GFP_KERNEL); | ||
702 | if (!rx_ring) | ||
703 | goto err_alloc_rx; | ||
704 | |||
705 | adapter->tx_ring = tx_ring; | ||
706 | adapter->rx_ring = rx_ring; | ||
707 | |||
708 | rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD); | ||
709 | rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD)); | ||
710 | rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE); | ||
711 | |||
712 | tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD); | ||
713 | tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD)); | ||
714 | tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE); | ||
715 | |||
716 | if (netif_running(adapter->netdev)) { | ||
717 | /* Try to get new resources before deleting old */ | ||
718 | err = e1000e_setup_rx_resources(adapter); | ||
719 | if (err) | ||
720 | goto err_setup_rx; | ||
721 | err = e1000e_setup_tx_resources(adapter); | ||
722 | if (err) | ||
723 | goto err_setup_tx; | ||
724 | |||
725 | /* | ||
726 | * restore the old in order to free it, | ||
727 | * then add in the new | ||
728 | */ | ||
729 | adapter->rx_ring = rx_old; | ||
730 | adapter->tx_ring = tx_old; | ||
731 | e1000e_free_rx_resources(adapter); | ||
732 | e1000e_free_tx_resources(adapter); | ||
733 | kfree(tx_old); | ||
734 | kfree(rx_old); | ||
735 | adapter->rx_ring = rx_ring; | ||
736 | adapter->tx_ring = tx_ring; | ||
737 | err = e1000e_up(adapter); | ||
738 | if (err) | ||
739 | goto err_setup; | ||
740 | } | ||
741 | |||
742 | clear_bit(__E1000_RESETTING, &adapter->state); | ||
743 | return 0; | ||
744 | err_setup_tx: | ||
745 | e1000e_free_rx_resources(adapter); | ||
746 | err_setup_rx: | ||
747 | adapter->rx_ring = rx_old; | ||
748 | adapter->tx_ring = tx_old; | ||
749 | kfree(rx_ring); | ||
750 | err_alloc_rx: | ||
751 | kfree(tx_ring); | ||
752 | err_alloc_tx: | ||
753 | e1000e_up(adapter); | ||
754 | err_setup: | ||
755 | clear_bit(__E1000_RESETTING, &adapter->state); | ||
756 | return err; | ||
757 | } | ||
758 | |||
759 | static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data, | ||
760 | int reg, int offset, u32 mask, u32 write) | ||
761 | { | ||
762 | u32 pat, val; | ||
763 | static const u32 test[] = { | ||
764 | 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF}; | ||
765 | for (pat = 0; pat < ARRAY_SIZE(test); pat++) { | ||
766 | E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset, | ||
767 | (test[pat] & write)); | ||
768 | val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset); | ||
769 | if (val != (test[pat] & write & mask)) { | ||
770 | e_err("pattern test reg %04X failed: got 0x%08X " | ||
771 | "expected 0x%08X\n", reg + offset, val, | ||
772 | (test[pat] & write & mask)); | ||
773 | *data = reg; | ||
774 | return 1; | ||
775 | } | ||
776 | } | ||
777 | return 0; | ||
778 | } | ||
779 | |||
780 | static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data, | ||
781 | int reg, u32 mask, u32 write) | ||
782 | { | ||
783 | u32 val; | ||
784 | __ew32(&adapter->hw, reg, write & mask); | ||
785 | val = __er32(&adapter->hw, reg); | ||
786 | if ((write & mask) != (val & mask)) { | ||
787 | e_err("set/check reg %04X test failed: got 0x%08X " | ||
788 | "expected 0x%08X\n", reg, (val & mask), (write & mask)); | ||
789 | *data = reg; | ||
790 | return 1; | ||
791 | } | ||
792 | return 0; | ||
793 | } | ||
794 | #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \ | ||
795 | do { \ | ||
796 | if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \ | ||
797 | return 1; \ | ||
798 | } while (0) | ||
799 | #define REG_PATTERN_TEST(reg, mask, write) \ | ||
800 | REG_PATTERN_TEST_ARRAY(reg, 0, mask, write) | ||
801 | |||
802 | #define REG_SET_AND_CHECK(reg, mask, write) \ | ||
803 | do { \ | ||
804 | if (reg_set_and_check(adapter, data, reg, mask, write)) \ | ||
805 | return 1; \ | ||
806 | } while (0) | ||
807 | |||
808 | static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data) | ||
809 | { | ||
810 | struct e1000_hw *hw = &adapter->hw; | ||
811 | struct e1000_mac_info *mac = &adapter->hw.mac; | ||
812 | u32 value; | ||
813 | u32 before; | ||
814 | u32 after; | ||
815 | u32 i; | ||
816 | u32 toggle; | ||
817 | u32 mask; | ||
818 | |||
819 | /* | ||
820 | * The status register is Read Only, so a write should fail. | ||
821 | * Some bits that get toggled are ignored. | ||
822 | */ | ||
823 | switch (mac->type) { | ||
824 | /* there are several bits on newer hardware that are r/w */ | ||
825 | case e1000_82571: | ||
826 | case e1000_82572: | ||
827 | case e1000_80003es2lan: | ||
828 | toggle = 0x7FFFF3FF; | ||
829 | break; | ||
830 | default: | ||
831 | toggle = 0x7FFFF033; | ||
832 | break; | ||
833 | } | ||
834 | |||
835 | before = er32(STATUS); | ||
836 | value = (er32(STATUS) & toggle); | ||
837 | ew32(STATUS, toggle); | ||
838 | after = er32(STATUS) & toggle; | ||
839 | if (value != after) { | ||
840 | e_err("failed STATUS register test got: 0x%08X expected: " | ||
841 | "0x%08X\n", after, value); | ||
842 | *data = 1; | ||
843 | return 1; | ||
844 | } | ||
845 | /* restore previous status */ | ||
846 | ew32(STATUS, before); | ||
847 | |||
848 | if (!(adapter->flags & FLAG_IS_ICH)) { | ||
849 | REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF); | ||
850 | REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF); | ||
851 | REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF); | ||
852 | REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF); | ||
853 | } | ||
854 | |||
855 | REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF); | ||
856 | REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF); | ||
857 | REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF); | ||
858 | REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF); | ||
859 | REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF); | ||
860 | REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8); | ||
861 | REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF); | ||
862 | REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF); | ||
863 | REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF); | ||
864 | REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF); | ||
865 | |||
866 | REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000); | ||
867 | |||
868 | before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE); | ||
869 | REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB); | ||
870 | REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000); | ||
871 | |||
872 | REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF); | ||
873 | REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF); | ||
874 | if (!(adapter->flags & FLAG_IS_ICH)) | ||
875 | REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF); | ||
876 | REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF); | ||
877 | REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF); | ||
878 | mask = 0x8003FFFF; | ||
879 | switch (mac->type) { | ||
880 | case e1000_ich10lan: | ||
881 | case e1000_pchlan: | ||
882 | case e1000_pch2lan: | ||
883 | mask |= (1 << 18); | ||
884 | break; | ||
885 | default: | ||
886 | break; | ||
887 | } | ||
888 | for (i = 0; i < mac->rar_entry_count; i++) | ||
889 | REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1), | ||
890 | mask, 0xFFFFFFFF); | ||
891 | |||
892 | for (i = 0; i < mac->mta_reg_count; i++) | ||
893 | REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF); | ||
894 | |||
895 | *data = 0; | ||
896 | return 0; | ||
897 | } | ||
898 | |||
899 | static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data) | ||
900 | { | ||
901 | u16 temp; | ||
902 | u16 checksum = 0; | ||
903 | u16 i; | ||
904 | |||
905 | *data = 0; | ||
906 | /* Read and add up the contents of the EEPROM */ | ||
907 | for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) { | ||
908 | if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) { | ||
909 | *data = 1; | ||
910 | return *data; | ||
911 | } | ||
912 | checksum += temp; | ||
913 | } | ||
914 | |||
915 | /* If Checksum is not Correct return error else test passed */ | ||
916 | if ((checksum != (u16) NVM_SUM) && !(*data)) | ||
917 | *data = 2; | ||
918 | |||
919 | return *data; | ||
920 | } | ||
921 | |||
922 | static irqreturn_t e1000_test_intr(int irq, void *data) | ||
923 | { | ||
924 | struct net_device *netdev = (struct net_device *) data; | ||
925 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
926 | struct e1000_hw *hw = &adapter->hw; | ||
927 | |||
928 | adapter->test_icr |= er32(ICR); | ||
929 | |||
930 | return IRQ_HANDLED; | ||
931 | } | ||
932 | |||
933 | static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data) | ||
934 | { | ||
935 | struct net_device *netdev = adapter->netdev; | ||
936 | struct e1000_hw *hw = &adapter->hw; | ||
937 | u32 mask; | ||
938 | u32 shared_int = 1; | ||
939 | u32 irq = adapter->pdev->irq; | ||
940 | int i; | ||
941 | int ret_val = 0; | ||
942 | int int_mode = E1000E_INT_MODE_LEGACY; | ||
943 | |||
944 | *data = 0; | ||
945 | |||
946 | /* NOTE: we don't test MSI/MSI-X interrupts here, yet */ | ||
947 | if (adapter->int_mode == E1000E_INT_MODE_MSIX) { | ||
948 | int_mode = adapter->int_mode; | ||
949 | e1000e_reset_interrupt_capability(adapter); | ||
950 | adapter->int_mode = E1000E_INT_MODE_LEGACY; | ||
951 | e1000e_set_interrupt_capability(adapter); | ||
952 | } | ||
953 | /* Hook up test interrupt handler just for this test */ | ||
954 | if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name, | ||
955 | netdev)) { | ||
956 | shared_int = 0; | ||
957 | } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED, | ||
958 | netdev->name, netdev)) { | ||
959 | *data = 1; | ||
960 | ret_val = -1; | ||
961 | goto out; | ||
962 | } | ||
963 | e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared")); | ||
964 | |||
965 | /* Disable all the interrupts */ | ||
966 | ew32(IMC, 0xFFFFFFFF); | ||
967 | e1e_flush(); | ||
968 | usleep_range(10000, 20000); | ||
969 | |||
970 | /* Test each interrupt */ | ||
971 | for (i = 0; i < 10; i++) { | ||
972 | /* Interrupt to test */ | ||
973 | mask = 1 << i; | ||
974 | |||
975 | if (adapter->flags & FLAG_IS_ICH) { | ||
976 | switch (mask) { | ||
977 | case E1000_ICR_RXSEQ: | ||
978 | continue; | ||
979 | case 0x00000100: | ||
980 | if (adapter->hw.mac.type == e1000_ich8lan || | ||
981 | adapter->hw.mac.type == e1000_ich9lan) | ||
982 | continue; | ||
983 | break; | ||
984 | default: | ||
985 | break; | ||
986 | } | ||
987 | } | ||
988 | |||
989 | if (!shared_int) { | ||
990 | /* | ||
991 | * Disable the interrupt to be reported in | ||
992 | * the cause register and then force the same | ||
993 | * interrupt and see if one gets posted. If | ||
994 | * an interrupt was posted to the bus, the | ||
995 | * test failed. | ||
996 | */ | ||
997 | adapter->test_icr = 0; | ||
998 | ew32(IMC, mask); | ||
999 | ew32(ICS, mask); | ||
1000 | e1e_flush(); | ||
1001 | usleep_range(10000, 20000); | ||
1002 | |||
1003 | if (adapter->test_icr & mask) { | ||
1004 | *data = 3; | ||
1005 | break; | ||
1006 | } | ||
1007 | } | ||
1008 | |||
1009 | /* | ||
1010 | * Enable the interrupt to be reported in | ||
1011 | * the cause register and then force the same | ||
1012 | * interrupt and see if one gets posted. If | ||
1013 | * an interrupt was not posted to the bus, the | ||
1014 | * test failed. | ||
1015 | */ | ||
1016 | adapter->test_icr = 0; | ||
1017 | ew32(IMS, mask); | ||
1018 | ew32(ICS, mask); | ||
1019 | e1e_flush(); | ||
1020 | usleep_range(10000, 20000); | ||
1021 | |||
1022 | if (!(adapter->test_icr & mask)) { | ||
1023 | *data = 4; | ||
1024 | break; | ||
1025 | } | ||
1026 | |||
1027 | if (!shared_int) { | ||
1028 | /* | ||
1029 | * Disable the other interrupts to be reported in | ||
1030 | * the cause register and then force the other | ||
1031 | * interrupts and see if any get posted. If | ||
1032 | * an interrupt was posted to the bus, the | ||
1033 | * test failed. | ||
1034 | */ | ||
1035 | adapter->test_icr = 0; | ||
1036 | ew32(IMC, ~mask & 0x00007FFF); | ||
1037 | ew32(ICS, ~mask & 0x00007FFF); | ||
1038 | e1e_flush(); | ||
1039 | usleep_range(10000, 20000); | ||
1040 | |||
1041 | if (adapter->test_icr) { | ||
1042 | *data = 5; | ||
1043 | break; | ||
1044 | } | ||
1045 | } | ||
1046 | } | ||
1047 | |||
1048 | /* Disable all the interrupts */ | ||
1049 | ew32(IMC, 0xFFFFFFFF); | ||
1050 | e1e_flush(); | ||
1051 | usleep_range(10000, 20000); | ||
1052 | |||
1053 | /* Unhook test interrupt handler */ | ||
1054 | free_irq(irq, netdev); | ||
1055 | |||
1056 | out: | ||
1057 | if (int_mode == E1000E_INT_MODE_MSIX) { | ||
1058 | e1000e_reset_interrupt_capability(adapter); | ||
1059 | adapter->int_mode = int_mode; | ||
1060 | e1000e_set_interrupt_capability(adapter); | ||
1061 | } | ||
1062 | |||
1063 | return ret_val; | ||
1064 | } | ||
1065 | |||
1066 | static void e1000_free_desc_rings(struct e1000_adapter *adapter) | ||
1067 | { | ||
1068 | struct e1000_ring *tx_ring = &adapter->test_tx_ring; | ||
1069 | struct e1000_ring *rx_ring = &adapter->test_rx_ring; | ||
1070 | struct pci_dev *pdev = adapter->pdev; | ||
1071 | int i; | ||
1072 | |||
1073 | if (tx_ring->desc && tx_ring->buffer_info) { | ||
1074 | for (i = 0; i < tx_ring->count; i++) { | ||
1075 | if (tx_ring->buffer_info[i].dma) | ||
1076 | dma_unmap_single(&pdev->dev, | ||
1077 | tx_ring->buffer_info[i].dma, | ||
1078 | tx_ring->buffer_info[i].length, | ||
1079 | DMA_TO_DEVICE); | ||
1080 | if (tx_ring->buffer_info[i].skb) | ||
1081 | dev_kfree_skb(tx_ring->buffer_info[i].skb); | ||
1082 | } | ||
1083 | } | ||
1084 | |||
1085 | if (rx_ring->desc && rx_ring->buffer_info) { | ||
1086 | for (i = 0; i < rx_ring->count; i++) { | ||
1087 | if (rx_ring->buffer_info[i].dma) | ||
1088 | dma_unmap_single(&pdev->dev, | ||
1089 | rx_ring->buffer_info[i].dma, | ||
1090 | 2048, DMA_FROM_DEVICE); | ||
1091 | if (rx_ring->buffer_info[i].skb) | ||
1092 | dev_kfree_skb(rx_ring->buffer_info[i].skb); | ||
1093 | } | ||
1094 | } | ||
1095 | |||
1096 | if (tx_ring->desc) { | ||
1097 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, | ||
1098 | tx_ring->dma); | ||
1099 | tx_ring->desc = NULL; | ||
1100 | } | ||
1101 | if (rx_ring->desc) { | ||
1102 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, | ||
1103 | rx_ring->dma); | ||
1104 | rx_ring->desc = NULL; | ||
1105 | } | ||
1106 | |||
1107 | kfree(tx_ring->buffer_info); | ||
1108 | tx_ring->buffer_info = NULL; | ||
1109 | kfree(rx_ring->buffer_info); | ||
1110 | rx_ring->buffer_info = NULL; | ||
1111 | } | ||
1112 | |||
1113 | static int e1000_setup_desc_rings(struct e1000_adapter *adapter) | ||
1114 | { | ||
1115 | struct e1000_ring *tx_ring = &adapter->test_tx_ring; | ||
1116 | struct e1000_ring *rx_ring = &adapter->test_rx_ring; | ||
1117 | struct pci_dev *pdev = adapter->pdev; | ||
1118 | struct e1000_hw *hw = &adapter->hw; | ||
1119 | u32 rctl; | ||
1120 | int i; | ||
1121 | int ret_val; | ||
1122 | |||
1123 | /* Setup Tx descriptor ring and Tx buffers */ | ||
1124 | |||
1125 | if (!tx_ring->count) | ||
1126 | tx_ring->count = E1000_DEFAULT_TXD; | ||
1127 | |||
1128 | tx_ring->buffer_info = kcalloc(tx_ring->count, | ||
1129 | sizeof(struct e1000_buffer), | ||
1130 | GFP_KERNEL); | ||
1131 | if (!(tx_ring->buffer_info)) { | ||
1132 | ret_val = 1; | ||
1133 | goto err_nomem; | ||
1134 | } | ||
1135 | |||
1136 | tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); | ||
1137 | tx_ring->size = ALIGN(tx_ring->size, 4096); | ||
1138 | tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size, | ||
1139 | &tx_ring->dma, GFP_KERNEL); | ||
1140 | if (!tx_ring->desc) { | ||
1141 | ret_val = 2; | ||
1142 | goto err_nomem; | ||
1143 | } | ||
1144 | tx_ring->next_to_use = 0; | ||
1145 | tx_ring->next_to_clean = 0; | ||
1146 | |||
1147 | ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF)); | ||
1148 | ew32(TDBAH, ((u64) tx_ring->dma >> 32)); | ||
1149 | ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc)); | ||
1150 | ew32(TDH, 0); | ||
1151 | ew32(TDT, 0); | ||
1152 | ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR | | ||
1153 | E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT | | ||
1154 | E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT); | ||
1155 | |||
1156 | for (i = 0; i < tx_ring->count; i++) { | ||
1157 | struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i); | ||
1158 | struct sk_buff *skb; | ||
1159 | unsigned int skb_size = 1024; | ||
1160 | |||
1161 | skb = alloc_skb(skb_size, GFP_KERNEL); | ||
1162 | if (!skb) { | ||
1163 | ret_val = 3; | ||
1164 | goto err_nomem; | ||
1165 | } | ||
1166 | skb_put(skb, skb_size); | ||
1167 | tx_ring->buffer_info[i].skb = skb; | ||
1168 | tx_ring->buffer_info[i].length = skb->len; | ||
1169 | tx_ring->buffer_info[i].dma = | ||
1170 | dma_map_single(&pdev->dev, skb->data, skb->len, | ||
1171 | DMA_TO_DEVICE); | ||
1172 | if (dma_mapping_error(&pdev->dev, | ||
1173 | tx_ring->buffer_info[i].dma)) { | ||
1174 | ret_val = 4; | ||
1175 | goto err_nomem; | ||
1176 | } | ||
1177 | tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma); | ||
1178 | tx_desc->lower.data = cpu_to_le32(skb->len); | ||
1179 | tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP | | ||
1180 | E1000_TXD_CMD_IFCS | | ||
1181 | E1000_TXD_CMD_RS); | ||
1182 | tx_desc->upper.data = 0; | ||
1183 | } | ||
1184 | |||
1185 | /* Setup Rx descriptor ring and Rx buffers */ | ||
1186 | |||
1187 | if (!rx_ring->count) | ||
1188 | rx_ring->count = E1000_DEFAULT_RXD; | ||
1189 | |||
1190 | rx_ring->buffer_info = kcalloc(rx_ring->count, | ||
1191 | sizeof(struct e1000_buffer), | ||
1192 | GFP_KERNEL); | ||
1193 | if (!(rx_ring->buffer_info)) { | ||
1194 | ret_val = 5; | ||
1195 | goto err_nomem; | ||
1196 | } | ||
1197 | |||
1198 | rx_ring->size = rx_ring->count * sizeof(struct e1000_rx_desc); | ||
1199 | rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size, | ||
1200 | &rx_ring->dma, GFP_KERNEL); | ||
1201 | if (!rx_ring->desc) { | ||
1202 | ret_val = 6; | ||
1203 | goto err_nomem; | ||
1204 | } | ||
1205 | rx_ring->next_to_use = 0; | ||
1206 | rx_ring->next_to_clean = 0; | ||
1207 | |||
1208 | rctl = er32(RCTL); | ||
1209 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) | ||
1210 | ew32(RCTL, rctl & ~E1000_RCTL_EN); | ||
1211 | ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF)); | ||
1212 | ew32(RDBAH, ((u64) rx_ring->dma >> 32)); | ||
1213 | ew32(RDLEN, rx_ring->size); | ||
1214 | ew32(RDH, 0); | ||
1215 | ew32(RDT, 0); | ||
1216 | rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 | | ||
1217 | E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE | | ||
1218 | E1000_RCTL_SBP | E1000_RCTL_SECRC | | ||
1219 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | | ||
1220 | (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT); | ||
1221 | ew32(RCTL, rctl); | ||
1222 | |||
1223 | for (i = 0; i < rx_ring->count; i++) { | ||
1224 | struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i); | ||
1225 | struct sk_buff *skb; | ||
1226 | |||
1227 | skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL); | ||
1228 | if (!skb) { | ||
1229 | ret_val = 7; | ||
1230 | goto err_nomem; | ||
1231 | } | ||
1232 | skb_reserve(skb, NET_IP_ALIGN); | ||
1233 | rx_ring->buffer_info[i].skb = skb; | ||
1234 | rx_ring->buffer_info[i].dma = | ||
1235 | dma_map_single(&pdev->dev, skb->data, 2048, | ||
1236 | DMA_FROM_DEVICE); | ||
1237 | if (dma_mapping_error(&pdev->dev, | ||
1238 | rx_ring->buffer_info[i].dma)) { | ||
1239 | ret_val = 8; | ||
1240 | goto err_nomem; | ||
1241 | } | ||
1242 | rx_desc->buffer_addr = | ||
1243 | cpu_to_le64(rx_ring->buffer_info[i].dma); | ||
1244 | memset(skb->data, 0x00, skb->len); | ||
1245 | } | ||
1246 | |||
1247 | return 0; | ||
1248 | |||
1249 | err_nomem: | ||
1250 | e1000_free_desc_rings(adapter); | ||
1251 | return ret_val; | ||
1252 | } | ||
1253 | |||
1254 | static void e1000_phy_disable_receiver(struct e1000_adapter *adapter) | ||
1255 | { | ||
1256 | /* Write out to PHY registers 29 and 30 to disable the Receiver. */ | ||
1257 | e1e_wphy(&adapter->hw, 29, 0x001F); | ||
1258 | e1e_wphy(&adapter->hw, 30, 0x8FFC); | ||
1259 | e1e_wphy(&adapter->hw, 29, 0x001A); | ||
1260 | e1e_wphy(&adapter->hw, 30, 0x8FF0); | ||
1261 | } | ||
1262 | |||
1263 | static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter) | ||
1264 | { | ||
1265 | struct e1000_hw *hw = &adapter->hw; | ||
1266 | u32 ctrl_reg = 0; | ||
1267 | u16 phy_reg = 0; | ||
1268 | s32 ret_val = 0; | ||
1269 | |||
1270 | hw->mac.autoneg = 0; | ||
1271 | |||
1272 | if (hw->phy.type == e1000_phy_ife) { | ||
1273 | /* force 100, set loopback */ | ||
1274 | e1e_wphy(hw, PHY_CONTROL, 0x6100); | ||
1275 | |||
1276 | /* Now set up the MAC to the same speed/duplex as the PHY. */ | ||
1277 | ctrl_reg = er32(CTRL); | ||
1278 | ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ | ||
1279 | ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ | ||
1280 | E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ | ||
1281 | E1000_CTRL_SPD_100 |/* Force Speed to 100 */ | ||
1282 | E1000_CTRL_FD); /* Force Duplex to FULL */ | ||
1283 | |||
1284 | ew32(CTRL, ctrl_reg); | ||
1285 | e1e_flush(); | ||
1286 | udelay(500); | ||
1287 | |||
1288 | return 0; | ||
1289 | } | ||
1290 | |||
1291 | /* Specific PHY configuration for loopback */ | ||
1292 | switch (hw->phy.type) { | ||
1293 | case e1000_phy_m88: | ||
1294 | /* Auto-MDI/MDIX Off */ | ||
1295 | e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808); | ||
1296 | /* reset to update Auto-MDI/MDIX */ | ||
1297 | e1e_wphy(hw, PHY_CONTROL, 0x9140); | ||
1298 | /* autoneg off */ | ||
1299 | e1e_wphy(hw, PHY_CONTROL, 0x8140); | ||
1300 | break; | ||
1301 | case e1000_phy_gg82563: | ||
1302 | e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC); | ||
1303 | break; | ||
1304 | case e1000_phy_bm: | ||
1305 | /* Set Default MAC Interface speed to 1GB */ | ||
1306 | e1e_rphy(hw, PHY_REG(2, 21), &phy_reg); | ||
1307 | phy_reg &= ~0x0007; | ||
1308 | phy_reg |= 0x006; | ||
1309 | e1e_wphy(hw, PHY_REG(2, 21), phy_reg); | ||
1310 | /* Assert SW reset for above settings to take effect */ | ||
1311 | e1000e_commit_phy(hw); | ||
1312 | mdelay(1); | ||
1313 | /* Force Full Duplex */ | ||
1314 | e1e_rphy(hw, PHY_REG(769, 16), &phy_reg); | ||
1315 | e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C); | ||
1316 | /* Set Link Up (in force link) */ | ||
1317 | e1e_rphy(hw, PHY_REG(776, 16), &phy_reg); | ||
1318 | e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040); | ||
1319 | /* Force Link */ | ||
1320 | e1e_rphy(hw, PHY_REG(769, 16), &phy_reg); | ||
1321 | e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040); | ||
1322 | /* Set Early Link Enable */ | ||
1323 | e1e_rphy(hw, PHY_REG(769, 20), &phy_reg); | ||
1324 | e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400); | ||
1325 | break; | ||
1326 | case e1000_phy_82577: | ||
1327 | case e1000_phy_82578: | ||
1328 | /* Workaround: K1 must be disabled for stable 1Gbps operation */ | ||
1329 | ret_val = hw->phy.ops.acquire(hw); | ||
1330 | if (ret_val) { | ||
1331 | e_err("Cannot setup 1Gbps loopback.\n"); | ||
1332 | return ret_val; | ||
1333 | } | ||
1334 | e1000_configure_k1_ich8lan(hw, false); | ||
1335 | hw->phy.ops.release(hw); | ||
1336 | break; | ||
1337 | case e1000_phy_82579: | ||
1338 | /* Disable PHY energy detect power down */ | ||
1339 | e1e_rphy(hw, PHY_REG(0, 21), &phy_reg); | ||
1340 | e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3)); | ||
1341 | /* Disable full chip energy detect */ | ||
1342 | e1e_rphy(hw, PHY_REG(776, 18), &phy_reg); | ||
1343 | e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1); | ||
1344 | /* Enable loopback on the PHY */ | ||
1345 | #define I82577_PHY_LBK_CTRL 19 | ||
1346 | e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001); | ||
1347 | break; | ||
1348 | default: | ||
1349 | break; | ||
1350 | } | ||
1351 | |||
1352 | /* force 1000, set loopback */ | ||
1353 | e1e_wphy(hw, PHY_CONTROL, 0x4140); | ||
1354 | mdelay(250); | ||
1355 | |||
1356 | /* Now set up the MAC to the same speed/duplex as the PHY. */ | ||
1357 | ctrl_reg = er32(CTRL); | ||
1358 | ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ | ||
1359 | ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ | ||
1360 | E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ | ||
1361 | E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */ | ||
1362 | E1000_CTRL_FD); /* Force Duplex to FULL */ | ||
1363 | |||
1364 | if (adapter->flags & FLAG_IS_ICH) | ||
1365 | ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */ | ||
1366 | |||
1367 | if (hw->phy.media_type == e1000_media_type_copper && | ||
1368 | hw->phy.type == e1000_phy_m88) { | ||
1369 | ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */ | ||
1370 | } else { | ||
1371 | /* | ||
1372 | * Set the ILOS bit on the fiber Nic if half duplex link is | ||
1373 | * detected. | ||
1374 | */ | ||
1375 | if ((er32(STATUS) & E1000_STATUS_FD) == 0) | ||
1376 | ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU); | ||
1377 | } | ||
1378 | |||
1379 | ew32(CTRL, ctrl_reg); | ||
1380 | |||
1381 | /* | ||
1382 | * Disable the receiver on the PHY so when a cable is plugged in, the | ||
1383 | * PHY does not begin to autoneg when a cable is reconnected to the NIC. | ||
1384 | */ | ||
1385 | if (hw->phy.type == e1000_phy_m88) | ||
1386 | e1000_phy_disable_receiver(adapter); | ||
1387 | |||
1388 | udelay(500); | ||
1389 | |||
1390 | return 0; | ||
1391 | } | ||
1392 | |||
1393 | static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter) | ||
1394 | { | ||
1395 | struct e1000_hw *hw = &adapter->hw; | ||
1396 | u32 ctrl = er32(CTRL); | ||
1397 | int link = 0; | ||
1398 | |||
1399 | /* special requirements for 82571/82572 fiber adapters */ | ||
1400 | |||
1401 | /* | ||
1402 | * jump through hoops to make sure link is up because serdes | ||
1403 | * link is hardwired up | ||
1404 | */ | ||
1405 | ctrl |= E1000_CTRL_SLU; | ||
1406 | ew32(CTRL, ctrl); | ||
1407 | |||
1408 | /* disable autoneg */ | ||
1409 | ctrl = er32(TXCW); | ||
1410 | ctrl &= ~(1 << 31); | ||
1411 | ew32(TXCW, ctrl); | ||
1412 | |||
1413 | link = (er32(STATUS) & E1000_STATUS_LU); | ||
1414 | |||
1415 | if (!link) { | ||
1416 | /* set invert loss of signal */ | ||
1417 | ctrl = er32(CTRL); | ||
1418 | ctrl |= E1000_CTRL_ILOS; | ||
1419 | ew32(CTRL, ctrl); | ||
1420 | } | ||
1421 | |||
1422 | /* | ||
1423 | * special write to serdes control register to enable SerDes analog | ||
1424 | * loopback | ||
1425 | */ | ||
1426 | #define E1000_SERDES_LB_ON 0x410 | ||
1427 | ew32(SCTL, E1000_SERDES_LB_ON); | ||
1428 | e1e_flush(); | ||
1429 | usleep_range(10000, 20000); | ||
1430 | |||
1431 | return 0; | ||
1432 | } | ||
1433 | |||
1434 | /* only call this for fiber/serdes connections to es2lan */ | ||
1435 | static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter) | ||
1436 | { | ||
1437 | struct e1000_hw *hw = &adapter->hw; | ||
1438 | u32 ctrlext = er32(CTRL_EXT); | ||
1439 | u32 ctrl = er32(CTRL); | ||
1440 | |||
1441 | /* | ||
1442 | * save CTRL_EXT to restore later, reuse an empty variable (unused | ||
1443 | * on mac_type 80003es2lan) | ||
1444 | */ | ||
1445 | adapter->tx_fifo_head = ctrlext; | ||
1446 | |||
1447 | /* clear the serdes mode bits, putting the device into mac loopback */ | ||
1448 | ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES; | ||
1449 | ew32(CTRL_EXT, ctrlext); | ||
1450 | |||
1451 | /* force speed to 1000/FD, link up */ | ||
1452 | ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100); | ||
1453 | ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | | ||
1454 | E1000_CTRL_SPD_1000 | E1000_CTRL_FD); | ||
1455 | ew32(CTRL, ctrl); | ||
1456 | |||
1457 | /* set mac loopback */ | ||
1458 | ctrl = er32(RCTL); | ||
1459 | ctrl |= E1000_RCTL_LBM_MAC; | ||
1460 | ew32(RCTL, ctrl); | ||
1461 | |||
1462 | /* set testing mode parameters (no need to reset later) */ | ||
1463 | #define KMRNCTRLSTA_OPMODE (0x1F << 16) | ||
1464 | #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582 | ||
1465 | ew32(KMRNCTRLSTA, | ||
1466 | (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII)); | ||
1467 | |||
1468 | return 0; | ||
1469 | } | ||
1470 | |||
1471 | static int e1000_setup_loopback_test(struct e1000_adapter *adapter) | ||
1472 | { | ||
1473 | struct e1000_hw *hw = &adapter->hw; | ||
1474 | u32 rctl; | ||
1475 | |||
1476 | if (hw->phy.media_type == e1000_media_type_fiber || | ||
1477 | hw->phy.media_type == e1000_media_type_internal_serdes) { | ||
1478 | switch (hw->mac.type) { | ||
1479 | case e1000_80003es2lan: | ||
1480 | return e1000_set_es2lan_mac_loopback(adapter); | ||
1481 | break; | ||
1482 | case e1000_82571: | ||
1483 | case e1000_82572: | ||
1484 | return e1000_set_82571_fiber_loopback(adapter); | ||
1485 | break; | ||
1486 | default: | ||
1487 | rctl = er32(RCTL); | ||
1488 | rctl |= E1000_RCTL_LBM_TCVR; | ||
1489 | ew32(RCTL, rctl); | ||
1490 | return 0; | ||
1491 | } | ||
1492 | } else if (hw->phy.media_type == e1000_media_type_copper) { | ||
1493 | return e1000_integrated_phy_loopback(adapter); | ||
1494 | } | ||
1495 | |||
1496 | return 7; | ||
1497 | } | ||
1498 | |||
1499 | static void e1000_loopback_cleanup(struct e1000_adapter *adapter) | ||
1500 | { | ||
1501 | struct e1000_hw *hw = &adapter->hw; | ||
1502 | u32 rctl; | ||
1503 | u16 phy_reg; | ||
1504 | |||
1505 | rctl = er32(RCTL); | ||
1506 | rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC); | ||
1507 | ew32(RCTL, rctl); | ||
1508 | |||
1509 | switch (hw->mac.type) { | ||
1510 | case e1000_80003es2lan: | ||
1511 | if (hw->phy.media_type == e1000_media_type_fiber || | ||
1512 | hw->phy.media_type == e1000_media_type_internal_serdes) { | ||
1513 | /* restore CTRL_EXT, stealing space from tx_fifo_head */ | ||
1514 | ew32(CTRL_EXT, adapter->tx_fifo_head); | ||
1515 | adapter->tx_fifo_head = 0; | ||
1516 | } | ||
1517 | /* fall through */ | ||
1518 | case e1000_82571: | ||
1519 | case e1000_82572: | ||
1520 | if (hw->phy.media_type == e1000_media_type_fiber || | ||
1521 | hw->phy.media_type == e1000_media_type_internal_serdes) { | ||
1522 | #define E1000_SERDES_LB_OFF 0x400 | ||
1523 | ew32(SCTL, E1000_SERDES_LB_OFF); | ||
1524 | e1e_flush(); | ||
1525 | usleep_range(10000, 20000); | ||
1526 | break; | ||
1527 | } | ||
1528 | /* Fall Through */ | ||
1529 | default: | ||
1530 | hw->mac.autoneg = 1; | ||
1531 | if (hw->phy.type == e1000_phy_gg82563) | ||
1532 | e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180); | ||
1533 | e1e_rphy(hw, PHY_CONTROL, &phy_reg); | ||
1534 | if (phy_reg & MII_CR_LOOPBACK) { | ||
1535 | phy_reg &= ~MII_CR_LOOPBACK; | ||
1536 | e1e_wphy(hw, PHY_CONTROL, phy_reg); | ||
1537 | e1000e_commit_phy(hw); | ||
1538 | } | ||
1539 | break; | ||
1540 | } | ||
1541 | } | ||
1542 | |||
1543 | static void e1000_create_lbtest_frame(struct sk_buff *skb, | ||
1544 | unsigned int frame_size) | ||
1545 | { | ||
1546 | memset(skb->data, 0xFF, frame_size); | ||
1547 | frame_size &= ~1; | ||
1548 | memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1); | ||
1549 | memset(&skb->data[frame_size / 2 + 10], 0xBE, 1); | ||
1550 | memset(&skb->data[frame_size / 2 + 12], 0xAF, 1); | ||
1551 | } | ||
1552 | |||
1553 | static int e1000_check_lbtest_frame(struct sk_buff *skb, | ||
1554 | unsigned int frame_size) | ||
1555 | { | ||
1556 | frame_size &= ~1; | ||
1557 | if (*(skb->data + 3) == 0xFF) | ||
1558 | if ((*(skb->data + frame_size / 2 + 10) == 0xBE) && | ||
1559 | (*(skb->data + frame_size / 2 + 12) == 0xAF)) | ||
1560 | return 0; | ||
1561 | return 13; | ||
1562 | } | ||
1563 | |||
1564 | static int e1000_run_loopback_test(struct e1000_adapter *adapter) | ||
1565 | { | ||
1566 | struct e1000_ring *tx_ring = &adapter->test_tx_ring; | ||
1567 | struct e1000_ring *rx_ring = &adapter->test_rx_ring; | ||
1568 | struct pci_dev *pdev = adapter->pdev; | ||
1569 | struct e1000_hw *hw = &adapter->hw; | ||
1570 | int i, j, k, l; | ||
1571 | int lc; | ||
1572 | int good_cnt; | ||
1573 | int ret_val = 0; | ||
1574 | unsigned long time; | ||
1575 | |||
1576 | ew32(RDT, rx_ring->count - 1); | ||
1577 | |||
1578 | /* | ||
1579 | * Calculate the loop count based on the largest descriptor ring | ||
1580 | * The idea is to wrap the largest ring a number of times using 64 | ||
1581 | * send/receive pairs during each loop | ||
1582 | */ | ||
1583 | |||
1584 | if (rx_ring->count <= tx_ring->count) | ||
1585 | lc = ((tx_ring->count / 64) * 2) + 1; | ||
1586 | else | ||
1587 | lc = ((rx_ring->count / 64) * 2) + 1; | ||
1588 | |||
1589 | k = 0; | ||
1590 | l = 0; | ||
1591 | for (j = 0; j <= lc; j++) { /* loop count loop */ | ||
1592 | for (i = 0; i < 64; i++) { /* send the packets */ | ||
1593 | e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb, | ||
1594 | 1024); | ||
1595 | dma_sync_single_for_device(&pdev->dev, | ||
1596 | tx_ring->buffer_info[k].dma, | ||
1597 | tx_ring->buffer_info[k].length, | ||
1598 | DMA_TO_DEVICE); | ||
1599 | k++; | ||
1600 | if (k == tx_ring->count) | ||
1601 | k = 0; | ||
1602 | } | ||
1603 | ew32(TDT, k); | ||
1604 | e1e_flush(); | ||
1605 | msleep(200); | ||
1606 | time = jiffies; /* set the start time for the receive */ | ||
1607 | good_cnt = 0; | ||
1608 | do { /* receive the sent packets */ | ||
1609 | dma_sync_single_for_cpu(&pdev->dev, | ||
1610 | rx_ring->buffer_info[l].dma, 2048, | ||
1611 | DMA_FROM_DEVICE); | ||
1612 | |||
1613 | ret_val = e1000_check_lbtest_frame( | ||
1614 | rx_ring->buffer_info[l].skb, 1024); | ||
1615 | if (!ret_val) | ||
1616 | good_cnt++; | ||
1617 | l++; | ||
1618 | if (l == rx_ring->count) | ||
1619 | l = 0; | ||
1620 | /* | ||
1621 | * time + 20 msecs (200 msecs on 2.4) is more than | ||
1622 | * enough time to complete the receives, if it's | ||
1623 | * exceeded, break and error off | ||
1624 | */ | ||
1625 | } while ((good_cnt < 64) && !time_after(jiffies, time + 20)); | ||
1626 | if (good_cnt != 64) { | ||
1627 | ret_val = 13; /* ret_val is the same as mis-compare */ | ||
1628 | break; | ||
1629 | } | ||
1630 | if (jiffies >= (time + 20)) { | ||
1631 | ret_val = 14; /* error code for time out error */ | ||
1632 | break; | ||
1633 | } | ||
1634 | } /* end loop count loop */ | ||
1635 | return ret_val; | ||
1636 | } | ||
1637 | |||
1638 | static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data) | ||
1639 | { | ||
1640 | /* | ||
1641 | * PHY loopback cannot be performed if SoL/IDER | ||
1642 | * sessions are active | ||
1643 | */ | ||
1644 | if (e1000_check_reset_block(&adapter->hw)) { | ||
1645 | e_err("Cannot do PHY loopback test when SoL/IDER is active.\n"); | ||
1646 | *data = 0; | ||
1647 | goto out; | ||
1648 | } | ||
1649 | |||
1650 | *data = e1000_setup_desc_rings(adapter); | ||
1651 | if (*data) | ||
1652 | goto out; | ||
1653 | |||
1654 | *data = e1000_setup_loopback_test(adapter); | ||
1655 | if (*data) | ||
1656 | goto err_loopback; | ||
1657 | |||
1658 | *data = e1000_run_loopback_test(adapter); | ||
1659 | e1000_loopback_cleanup(adapter); | ||
1660 | |||
1661 | err_loopback: | ||
1662 | e1000_free_desc_rings(adapter); | ||
1663 | out: | ||
1664 | return *data; | ||
1665 | } | ||
1666 | |||
1667 | static int e1000_link_test(struct e1000_adapter *adapter, u64 *data) | ||
1668 | { | ||
1669 | struct e1000_hw *hw = &adapter->hw; | ||
1670 | |||
1671 | *data = 0; | ||
1672 | if (hw->phy.media_type == e1000_media_type_internal_serdes) { | ||
1673 | int i = 0; | ||
1674 | hw->mac.serdes_has_link = false; | ||
1675 | |||
1676 | /* | ||
1677 | * On some blade server designs, link establishment | ||
1678 | * could take as long as 2-3 minutes | ||
1679 | */ | ||
1680 | do { | ||
1681 | hw->mac.ops.check_for_link(hw); | ||
1682 | if (hw->mac.serdes_has_link) | ||
1683 | return *data; | ||
1684 | msleep(20); | ||
1685 | } while (i++ < 3750); | ||
1686 | |||
1687 | *data = 1; | ||
1688 | } else { | ||
1689 | hw->mac.ops.check_for_link(hw); | ||
1690 | if (hw->mac.autoneg) | ||
1691 | /* | ||
1692 | * On some Phy/switch combinations, link establishment | ||
1693 | * can take a few seconds more than expected. | ||
1694 | */ | ||
1695 | msleep(5000); | ||
1696 | |||
1697 | if (!(er32(STATUS) & E1000_STATUS_LU)) | ||
1698 | *data = 1; | ||
1699 | } | ||
1700 | return *data; | ||
1701 | } | ||
1702 | |||
1703 | static int e1000e_get_sset_count(struct net_device *netdev, int sset) | ||
1704 | { | ||
1705 | switch (sset) { | ||
1706 | case ETH_SS_TEST: | ||
1707 | return E1000_TEST_LEN; | ||
1708 | case ETH_SS_STATS: | ||
1709 | return E1000_STATS_LEN; | ||
1710 | default: | ||
1711 | return -EOPNOTSUPP; | ||
1712 | } | ||
1713 | } | ||
1714 | |||
1715 | static void e1000_diag_test(struct net_device *netdev, | ||
1716 | struct ethtool_test *eth_test, u64 *data) | ||
1717 | { | ||
1718 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
1719 | u16 autoneg_advertised; | ||
1720 | u8 forced_speed_duplex; | ||
1721 | u8 autoneg; | ||
1722 | bool if_running = netif_running(netdev); | ||
1723 | |||
1724 | set_bit(__E1000_TESTING, &adapter->state); | ||
1725 | |||
1726 | if (!if_running) { | ||
1727 | /* Get control of and reset hardware */ | ||
1728 | if (adapter->flags & FLAG_HAS_AMT) | ||
1729 | e1000e_get_hw_control(adapter); | ||
1730 | |||
1731 | e1000e_power_up_phy(adapter); | ||
1732 | |||
1733 | adapter->hw.phy.autoneg_wait_to_complete = 1; | ||
1734 | e1000e_reset(adapter); | ||
1735 | adapter->hw.phy.autoneg_wait_to_complete = 0; | ||
1736 | } | ||
1737 | |||
1738 | if (eth_test->flags == ETH_TEST_FL_OFFLINE) { | ||
1739 | /* Offline tests */ | ||
1740 | |||
1741 | /* save speed, duplex, autoneg settings */ | ||
1742 | autoneg_advertised = adapter->hw.phy.autoneg_advertised; | ||
1743 | forced_speed_duplex = adapter->hw.mac.forced_speed_duplex; | ||
1744 | autoneg = adapter->hw.mac.autoneg; | ||
1745 | |||
1746 | e_info("offline testing starting\n"); | ||
1747 | |||
1748 | if (if_running) | ||
1749 | /* indicate we're in test mode */ | ||
1750 | dev_close(netdev); | ||
1751 | |||
1752 | if (e1000_reg_test(adapter, &data[0])) | ||
1753 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
1754 | |||
1755 | e1000e_reset(adapter); | ||
1756 | if (e1000_eeprom_test(adapter, &data[1])) | ||
1757 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
1758 | |||
1759 | e1000e_reset(adapter); | ||
1760 | if (e1000_intr_test(adapter, &data[2])) | ||
1761 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
1762 | |||
1763 | e1000e_reset(adapter); | ||
1764 | if (e1000_loopback_test(adapter, &data[3])) | ||
1765 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
1766 | |||
1767 | /* force this routine to wait until autoneg complete/timeout */ | ||
1768 | adapter->hw.phy.autoneg_wait_to_complete = 1; | ||
1769 | e1000e_reset(adapter); | ||
1770 | adapter->hw.phy.autoneg_wait_to_complete = 0; | ||
1771 | |||
1772 | if (e1000_link_test(adapter, &data[4])) | ||
1773 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
1774 | |||
1775 | /* restore speed, duplex, autoneg settings */ | ||
1776 | adapter->hw.phy.autoneg_advertised = autoneg_advertised; | ||
1777 | adapter->hw.mac.forced_speed_duplex = forced_speed_duplex; | ||
1778 | adapter->hw.mac.autoneg = autoneg; | ||
1779 | e1000e_reset(adapter); | ||
1780 | |||
1781 | clear_bit(__E1000_TESTING, &adapter->state); | ||
1782 | if (if_running) | ||
1783 | dev_open(netdev); | ||
1784 | } else { | ||
1785 | /* Online tests */ | ||
1786 | |||
1787 | e_info("online testing starting\n"); | ||
1788 | |||
1789 | /* register, eeprom, intr and loopback tests not run online */ | ||
1790 | data[0] = 0; | ||
1791 | data[1] = 0; | ||
1792 | data[2] = 0; | ||
1793 | data[3] = 0; | ||
1794 | |||
1795 | if (e1000_link_test(adapter, &data[4])) | ||
1796 | eth_test->flags |= ETH_TEST_FL_FAILED; | ||
1797 | |||
1798 | clear_bit(__E1000_TESTING, &adapter->state); | ||
1799 | } | ||
1800 | |||
1801 | if (!if_running) { | ||
1802 | e1000e_reset(adapter); | ||
1803 | |||
1804 | if (adapter->flags & FLAG_HAS_AMT) | ||
1805 | e1000e_release_hw_control(adapter); | ||
1806 | } | ||
1807 | |||
1808 | msleep_interruptible(4 * 1000); | ||
1809 | } | ||
1810 | |||
1811 | static void e1000_get_wol(struct net_device *netdev, | ||
1812 | struct ethtool_wolinfo *wol) | ||
1813 | { | ||
1814 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
1815 | |||
1816 | wol->supported = 0; | ||
1817 | wol->wolopts = 0; | ||
1818 | |||
1819 | if (!(adapter->flags & FLAG_HAS_WOL) || | ||
1820 | !device_can_wakeup(&adapter->pdev->dev)) | ||
1821 | return; | ||
1822 | |||
1823 | wol->supported = WAKE_UCAST | WAKE_MCAST | | ||
1824 | WAKE_BCAST | WAKE_MAGIC | WAKE_PHY; | ||
1825 | |||
1826 | /* apply any specific unsupported masks here */ | ||
1827 | if (adapter->flags & FLAG_NO_WAKE_UCAST) { | ||
1828 | wol->supported &= ~WAKE_UCAST; | ||
1829 | |||
1830 | if (adapter->wol & E1000_WUFC_EX) | ||
1831 | e_err("Interface does not support directed (unicast) " | ||
1832 | "frame wake-up packets\n"); | ||
1833 | } | ||
1834 | |||
1835 | if (adapter->wol & E1000_WUFC_EX) | ||
1836 | wol->wolopts |= WAKE_UCAST; | ||
1837 | if (adapter->wol & E1000_WUFC_MC) | ||
1838 | wol->wolopts |= WAKE_MCAST; | ||
1839 | if (adapter->wol & E1000_WUFC_BC) | ||
1840 | wol->wolopts |= WAKE_BCAST; | ||
1841 | if (adapter->wol & E1000_WUFC_MAG) | ||
1842 | wol->wolopts |= WAKE_MAGIC; | ||
1843 | if (adapter->wol & E1000_WUFC_LNKC) | ||
1844 | wol->wolopts |= WAKE_PHY; | ||
1845 | } | ||
1846 | |||
1847 | static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) | ||
1848 | { | ||
1849 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
1850 | |||
1851 | if (!(adapter->flags & FLAG_HAS_WOL) || | ||
1852 | !device_can_wakeup(&adapter->pdev->dev) || | ||
1853 | (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | | ||
1854 | WAKE_MAGIC | WAKE_PHY))) | ||
1855 | return -EOPNOTSUPP; | ||
1856 | |||
1857 | /* these settings will always override what we currently have */ | ||
1858 | adapter->wol = 0; | ||
1859 | |||
1860 | if (wol->wolopts & WAKE_UCAST) | ||
1861 | adapter->wol |= E1000_WUFC_EX; | ||
1862 | if (wol->wolopts & WAKE_MCAST) | ||
1863 | adapter->wol |= E1000_WUFC_MC; | ||
1864 | if (wol->wolopts & WAKE_BCAST) | ||
1865 | adapter->wol |= E1000_WUFC_BC; | ||
1866 | if (wol->wolopts & WAKE_MAGIC) | ||
1867 | adapter->wol |= E1000_WUFC_MAG; | ||
1868 | if (wol->wolopts & WAKE_PHY) | ||
1869 | adapter->wol |= E1000_WUFC_LNKC; | ||
1870 | |||
1871 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); | ||
1872 | |||
1873 | return 0; | ||
1874 | } | ||
1875 | |||
1876 | static int e1000_set_phys_id(struct net_device *netdev, | ||
1877 | enum ethtool_phys_id_state state) | ||
1878 | { | ||
1879 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
1880 | struct e1000_hw *hw = &adapter->hw; | ||
1881 | |||
1882 | switch (state) { | ||
1883 | case ETHTOOL_ID_ACTIVE: | ||
1884 | if (!hw->mac.ops.blink_led) | ||
1885 | return 2; /* cycle on/off twice per second */ | ||
1886 | |||
1887 | hw->mac.ops.blink_led(hw); | ||
1888 | break; | ||
1889 | |||
1890 | case ETHTOOL_ID_INACTIVE: | ||
1891 | if (hw->phy.type == e1000_phy_ife) | ||
1892 | e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0); | ||
1893 | hw->mac.ops.led_off(hw); | ||
1894 | hw->mac.ops.cleanup_led(hw); | ||
1895 | break; | ||
1896 | |||
1897 | case ETHTOOL_ID_ON: | ||
1898 | adapter->hw.mac.ops.led_on(&adapter->hw); | ||
1899 | break; | ||
1900 | |||
1901 | case ETHTOOL_ID_OFF: | ||
1902 | adapter->hw.mac.ops.led_off(&adapter->hw); | ||
1903 | break; | ||
1904 | } | ||
1905 | return 0; | ||
1906 | } | ||
1907 | |||
1908 | static int e1000_get_coalesce(struct net_device *netdev, | ||
1909 | struct ethtool_coalesce *ec) | ||
1910 | { | ||
1911 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
1912 | |||
1913 | if (adapter->itr_setting <= 4) | ||
1914 | ec->rx_coalesce_usecs = adapter->itr_setting; | ||
1915 | else | ||
1916 | ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting; | ||
1917 | |||
1918 | return 0; | ||
1919 | } | ||
1920 | |||
1921 | static int e1000_set_coalesce(struct net_device *netdev, | ||
1922 | struct ethtool_coalesce *ec) | ||
1923 | { | ||
1924 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
1925 | struct e1000_hw *hw = &adapter->hw; | ||
1926 | |||
1927 | if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) || | ||
1928 | ((ec->rx_coalesce_usecs > 4) && | ||
1929 | (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) || | ||
1930 | (ec->rx_coalesce_usecs == 2)) | ||
1931 | return -EINVAL; | ||
1932 | |||
1933 | if (ec->rx_coalesce_usecs == 4) { | ||
1934 | adapter->itr = adapter->itr_setting = 4; | ||
1935 | } else if (ec->rx_coalesce_usecs <= 3) { | ||
1936 | adapter->itr = 20000; | ||
1937 | adapter->itr_setting = ec->rx_coalesce_usecs; | ||
1938 | } else { | ||
1939 | adapter->itr = (1000000 / ec->rx_coalesce_usecs); | ||
1940 | adapter->itr_setting = adapter->itr & ~3; | ||
1941 | } | ||
1942 | |||
1943 | if (adapter->itr_setting != 0) | ||
1944 | ew32(ITR, 1000000000 / (adapter->itr * 256)); | ||
1945 | else | ||
1946 | ew32(ITR, 0); | ||
1947 | |||
1948 | return 0; | ||
1949 | } | ||
1950 | |||
1951 | static int e1000_nway_reset(struct net_device *netdev) | ||
1952 | { | ||
1953 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
1954 | |||
1955 | if (!netif_running(netdev)) | ||
1956 | return -EAGAIN; | ||
1957 | |||
1958 | if (!adapter->hw.mac.autoneg) | ||
1959 | return -EINVAL; | ||
1960 | |||
1961 | e1000e_reinit_locked(adapter); | ||
1962 | |||
1963 | return 0; | ||
1964 | } | ||
1965 | |||
1966 | static void e1000_get_ethtool_stats(struct net_device *netdev, | ||
1967 | struct ethtool_stats *stats, | ||
1968 | u64 *data) | ||
1969 | { | ||
1970 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
1971 | struct rtnl_link_stats64 net_stats; | ||
1972 | int i; | ||
1973 | char *p = NULL; | ||
1974 | |||
1975 | e1000e_get_stats64(netdev, &net_stats); | ||
1976 | for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) { | ||
1977 | switch (e1000_gstrings_stats[i].type) { | ||
1978 | case NETDEV_STATS: | ||
1979 | p = (char *) &net_stats + | ||
1980 | e1000_gstrings_stats[i].stat_offset; | ||
1981 | break; | ||
1982 | case E1000_STATS: | ||
1983 | p = (char *) adapter + | ||
1984 | e1000_gstrings_stats[i].stat_offset; | ||
1985 | break; | ||
1986 | default: | ||
1987 | data[i] = 0; | ||
1988 | continue; | ||
1989 | } | ||
1990 | |||
1991 | data[i] = (e1000_gstrings_stats[i].sizeof_stat == | ||
1992 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; | ||
1993 | } | ||
1994 | } | ||
1995 | |||
1996 | static void e1000_get_strings(struct net_device *netdev, u32 stringset, | ||
1997 | u8 *data) | ||
1998 | { | ||
1999 | u8 *p = data; | ||
2000 | int i; | ||
2001 | |||
2002 | switch (stringset) { | ||
2003 | case ETH_SS_TEST: | ||
2004 | memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test)); | ||
2005 | break; | ||
2006 | case ETH_SS_STATS: | ||
2007 | for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) { | ||
2008 | memcpy(p, e1000_gstrings_stats[i].stat_string, | ||
2009 | ETH_GSTRING_LEN); | ||
2010 | p += ETH_GSTRING_LEN; | ||
2011 | } | ||
2012 | break; | ||
2013 | } | ||
2014 | } | ||
2015 | |||
2016 | static int e1000e_set_flags(struct net_device *netdev, u32 data) | ||
2017 | { | ||
2018 | struct e1000_adapter *adapter = netdev_priv(netdev); | ||
2019 | bool need_reset = false; | ||
2020 | int rc; | ||
2021 | |||
2022 | need_reset = (data & ETH_FLAG_RXVLAN) != | ||
2023 | (netdev->features & NETIF_F_HW_VLAN_RX); | ||
2024 | |||
2025 | rc = ethtool_op_set_flags(netdev, data, ETH_FLAG_RXVLAN | | ||
2026 | ETH_FLAG_TXVLAN); | ||
2027 | |||
2028 | if (rc) | ||
2029 | return rc; | ||
2030 | |||
2031 | if (need_reset) { | ||
2032 | if (netif_running(netdev)) | ||
2033 | e1000e_reinit_locked(adapter); | ||
2034 | else | ||
2035 | e1000e_reset(adapter); | ||
2036 | } | ||
2037 | |||
2038 | return 0; | ||
2039 | } | ||
2040 | |||
2041 | static const struct ethtool_ops e1000_ethtool_ops = { | ||
2042 | .get_settings = e1000_get_settings, | ||
2043 | .set_settings = e1000_set_settings, | ||
2044 | .get_drvinfo = e1000_get_drvinfo, | ||
2045 | .get_regs_len = e1000_get_regs_len, | ||
2046 | .get_regs = e1000_get_regs, | ||
2047 | .get_wol = e1000_get_wol, | ||
2048 | .set_wol = e1000_set_wol, | ||
2049 | .get_msglevel = e1000_get_msglevel, | ||
2050 | .set_msglevel = e1000_set_msglevel, | ||
2051 | .nway_reset = e1000_nway_reset, | ||
2052 | .get_link = ethtool_op_get_link, | ||
2053 | .get_eeprom_len = e1000_get_eeprom_len, | ||
2054 | .get_eeprom = e1000_get_eeprom, | ||
2055 | .set_eeprom = e1000_set_eeprom, | ||
2056 | .get_ringparam = e1000_get_ringparam, | ||
2057 | .set_ringparam = e1000_set_ringparam, | ||
2058 | .get_pauseparam = e1000_get_pauseparam, | ||
2059 | .set_pauseparam = e1000_set_pauseparam, | ||
2060 | .get_rx_csum = e1000_get_rx_csum, | ||
2061 | .set_rx_csum = e1000_set_rx_csum, | ||
2062 | .get_tx_csum = e1000_get_tx_csum, | ||
2063 | .set_tx_csum = e1000_set_tx_csum, | ||
2064 | .get_sg = ethtool_op_get_sg, | ||
2065 | .set_sg = ethtool_op_set_sg, | ||
2066 | .get_tso = ethtool_op_get_tso, | ||
2067 | .set_tso = e1000_set_tso, | ||
2068 | .self_test = e1000_diag_test, | ||
2069 | .get_strings = e1000_get_strings, | ||
2070 | .set_phys_id = e1000_set_phys_id, | ||
2071 | .get_ethtool_stats = e1000_get_ethtool_stats, | ||
2072 | .get_sset_count = e1000e_get_sset_count, | ||
2073 | .get_coalesce = e1000_get_coalesce, | ||
2074 | .set_coalesce = e1000_set_coalesce, | ||
2075 | .get_flags = ethtool_op_get_flags, | ||
2076 | .set_flags = e1000e_set_flags, | ||
2077 | }; | ||
2078 | |||
2079 | void e1000e_set_ethtool_ops(struct net_device *netdev) | ||
2080 | { | ||
2081 | SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops); | ||
2082 | } | ||