blob: 859d0d3af6c95f71a3312b212e66ed3bf570b2b2 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allan0d6057e2011-01-04 01:16:44 +00004 Copyright(c) 1999 - 2011 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
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/ethtool.h>
33#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070035#include <linux/delay.h>
36
37#include "e1000.h"
38
Ajit Khapardee0f36a92009-10-13 01:45:09 +000039enum {NETDEV_STATS, E1000_STATS};
40
Auke Kokbc7f75f2007-09-17 12:30:59 -070041struct e1000_stats {
42 char stat_string[ETH_GSTRING_LEN];
Ajit Khapardee0f36a92009-10-13 01:45:09 +000043 int type;
Auke Kokbc7f75f2007-09-17 12:30:59 -070044 int sizeof_stat;
45 int stat_offset;
46};
47
Bruce Allanf0f1a172010-12-11 05:53:32 +000048#define E1000_STAT(str, m) { \
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000049 .stat_string = str, \
50 .type = E1000_STATS, \
51 .sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
52 .stat_offset = offsetof(struct e1000_adapter, m) }
Bruce Allanf0f1a172010-12-11 05:53:32 +000053#define E1000_NETDEV_STAT(str, m) { \
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000054 .stat_string = str, \
55 .type = NETDEV_STATS, \
56 .sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \
57 .stat_offset = offsetof(struct rtnl_link_stats64, m) }
Ajit Khapardee0f36a92009-10-13 01:45:09 +000058
Auke Kokbc7f75f2007-09-17 12:30:59 -070059static const struct e1000_stats e1000_gstrings_stats[] = {
Bruce Allanf0f1a172010-12-11 05:53:32 +000060 E1000_STAT("rx_packets", stats.gprc),
61 E1000_STAT("tx_packets", stats.gptc),
62 E1000_STAT("rx_bytes", stats.gorc),
63 E1000_STAT("tx_bytes", stats.gotc),
64 E1000_STAT("rx_broadcast", stats.bprc),
65 E1000_STAT("tx_broadcast", stats.bptc),
66 E1000_STAT("rx_multicast", stats.mprc),
67 E1000_STAT("tx_multicast", stats.mptc),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000068 E1000_NETDEV_STAT("rx_errors", rx_errors),
69 E1000_NETDEV_STAT("tx_errors", tx_errors),
70 E1000_NETDEV_STAT("tx_dropped", tx_dropped),
Bruce Allanf0f1a172010-12-11 05:53:32 +000071 E1000_STAT("multicast", stats.mprc),
72 E1000_STAT("collisions", stats.colc),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000073 E1000_NETDEV_STAT("rx_length_errors", rx_length_errors),
74 E1000_NETDEV_STAT("rx_over_errors", rx_over_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000075 E1000_STAT("rx_crc_errors", stats.crcerrs),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000076 E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000077 E1000_STAT("rx_no_buffer_count", stats.rnbc),
78 E1000_STAT("rx_missed_errors", stats.mpc),
79 E1000_STAT("tx_aborted_errors", stats.ecol),
80 E1000_STAT("tx_carrier_errors", stats.tncrs),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000081 E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
82 E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000083 E1000_STAT("tx_window_errors", stats.latecol),
84 E1000_STAT("tx_abort_late_coll", stats.latecol),
85 E1000_STAT("tx_deferred_ok", stats.dc),
86 E1000_STAT("tx_single_coll_ok", stats.scc),
87 E1000_STAT("tx_multi_coll_ok", stats.mcc),
88 E1000_STAT("tx_timeout_count", tx_timeout_count),
89 E1000_STAT("tx_restart_queue", restart_queue),
90 E1000_STAT("rx_long_length_errors", stats.roc),
91 E1000_STAT("rx_short_length_errors", stats.ruc),
92 E1000_STAT("rx_align_errors", stats.algnerrc),
93 E1000_STAT("tx_tcp_seg_good", stats.tsctc),
94 E1000_STAT("tx_tcp_seg_failed", stats.tsctfc),
95 E1000_STAT("rx_flow_control_xon", stats.xonrxc),
96 E1000_STAT("rx_flow_control_xoff", stats.xoffrxc),
97 E1000_STAT("tx_flow_control_xon", stats.xontxc),
98 E1000_STAT("tx_flow_control_xoff", stats.xofftxc),
99 E1000_STAT("rx_long_byte_count", stats.gorc),
100 E1000_STAT("rx_csum_offload_good", hw_csum_good),
101 E1000_STAT("rx_csum_offload_errors", hw_csum_err),
102 E1000_STAT("rx_header_split", rx_hdr_split),
103 E1000_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),
104 E1000_STAT("tx_smbus", stats.mgptc),
105 E1000_STAT("rx_smbus", stats.mgprc),
106 E1000_STAT("dropped_smbus", stats.mgpdc),
107 E1000_STAT("rx_dma_failed", rx_dma_failed),
108 E1000_STAT("tx_dma_failed", tx_dma_failed),
Auke Kokbc7f75f2007-09-17 12:30:59 -0700109};
110
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200111#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700112#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
113static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
114 "Register test (offline)", "Eeprom test (offline)",
115 "Interrupt test (offline)", "Loopback test (offline)",
116 "Link test (on/offline)"
117};
Bruce Allanad680762008-03-28 09:15:03 -0700118#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700119
120static int e1000_get_settings(struct net_device *netdev,
121 struct ethtool_cmd *ecmd)
122{
123 struct e1000_adapter *adapter = netdev_priv(netdev);
124 struct e1000_hw *hw = &adapter->hw;
David Decotigny70739492011-04-27 18:32:40 +0000125 u32 speed;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700126
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700127 if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700128
129 ecmd->supported = (SUPPORTED_10baseT_Half |
130 SUPPORTED_10baseT_Full |
131 SUPPORTED_100baseT_Half |
132 SUPPORTED_100baseT_Full |
133 SUPPORTED_1000baseT_Full |
134 SUPPORTED_Autoneg |
135 SUPPORTED_TP);
136 if (hw->phy.type == e1000_phy_ife)
137 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
138 ecmd->advertising = ADVERTISED_TP;
139
140 if (hw->mac.autoneg == 1) {
141 ecmd->advertising |= ADVERTISED_Autoneg;
142 /* the e1000 autoneg seems to match ethtool nicely */
143 ecmd->advertising |= hw->phy.autoneg_advertised;
144 }
145
146 ecmd->port = PORT_TP;
147 ecmd->phy_address = hw->phy.addr;
148 ecmd->transceiver = XCVR_INTERNAL;
149
150 } else {
151 ecmd->supported = (SUPPORTED_1000baseT_Full |
152 SUPPORTED_FIBRE |
153 SUPPORTED_Autoneg);
154
155 ecmd->advertising = (ADVERTISED_1000baseT_Full |
156 ADVERTISED_FIBRE |
157 ADVERTISED_Autoneg);
158
159 ecmd->port = PORT_FIBRE;
160 ecmd->transceiver = XCVR_EXTERNAL;
161 }
162
David Decotigny70739492011-04-27 18:32:40 +0000163 speed = -1;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000164 ecmd->duplex = -1;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700165
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000166 if (netif_running(netdev)) {
167 if (netif_carrier_ok(netdev)) {
David Decotigny70739492011-04-27 18:32:40 +0000168 speed = adapter->link_speed;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000169 ecmd->duplex = adapter->link_duplex - 1;
170 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700171 } else {
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000172 u32 status = er32(STATUS);
173 if (status & E1000_STATUS_LU) {
174 if (status & E1000_STATUS_SPEED_1000)
David Decotigny70739492011-04-27 18:32:40 +0000175 speed = SPEED_1000;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000176 else if (status & E1000_STATUS_SPEED_100)
David Decotigny70739492011-04-27 18:32:40 +0000177 speed = SPEED_100;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000178 else
David Decotigny70739492011-04-27 18:32:40 +0000179 speed = SPEED_10;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000180
181 if (status & E1000_STATUS_FD)
182 ecmd->duplex = DUPLEX_FULL;
183 else
184 ecmd->duplex = DUPLEX_HALF;
185 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700186 }
187
David Decotigny70739492011-04-27 18:32:40 +0000188 ethtool_cmd_speed_set(ecmd, speed);
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700189 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -0700190 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000191
192 /* MDI-X => 2; MDI =>1; Invalid =>0 */
193 if ((hw->phy.media_type == e1000_media_type_copper) &&
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000194 netif_carrier_ok(netdev))
Chaitanya Lala18760f12009-06-08 14:28:54 +0000195 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
196 ETH_TP_MDI;
197 else
198 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
199
Auke Kokbc7f75f2007-09-17 12:30:59 -0700200 return 0;
201}
202
David Decotigny14ad2512011-04-27 18:32:43 +0000203static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700204{
205 struct e1000_mac_info *mac = &adapter->hw.mac;
206
207 mac->autoneg = 0;
208
David Decotigny14ad2512011-04-27 18:32:43 +0000209 /* Make sure dplx is at most 1 bit and lsb of speed is not set
210 * for the switch() below to work */
211 if ((spd & 1) || (dplx & ~1))
212 goto err_inval;
213
Auke Kokbc7f75f2007-09-17 12:30:59 -0700214 /* Fiber NICs only allow 1000 gbps Full duplex */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700215 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
David Decotigny14ad2512011-04-27 18:32:43 +0000216 spd != SPEED_1000 &&
217 dplx != DUPLEX_FULL) {
218 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700219 }
220
David Decotigny14ad2512011-04-27 18:32:43 +0000221 switch (spd + dplx) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700222 case SPEED_10 + DUPLEX_HALF:
223 mac->forced_speed_duplex = ADVERTISE_10_HALF;
224 break;
225 case SPEED_10 + DUPLEX_FULL:
226 mac->forced_speed_duplex = ADVERTISE_10_FULL;
227 break;
228 case SPEED_100 + DUPLEX_HALF:
229 mac->forced_speed_duplex = ADVERTISE_100_HALF;
230 break;
231 case SPEED_100 + DUPLEX_FULL:
232 mac->forced_speed_duplex = ADVERTISE_100_FULL;
233 break;
234 case SPEED_1000 + DUPLEX_FULL:
235 mac->autoneg = 1;
236 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
237 break;
238 case SPEED_1000 + DUPLEX_HALF: /* not supported */
239 default:
David Decotigny14ad2512011-04-27 18:32:43 +0000240 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700241 }
242 return 0;
David Decotigny14ad2512011-04-27 18:32:43 +0000243
244err_inval:
245 e_err("Unsupported Speed/Duplex configuration\n");
246 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700247}
248
249static int e1000_set_settings(struct net_device *netdev,
250 struct ethtool_cmd *ecmd)
251{
252 struct e1000_adapter *adapter = netdev_priv(netdev);
253 struct e1000_hw *hw = &adapter->hw;
254
Bruce Allanad680762008-03-28 09:15:03 -0700255 /*
256 * When SoL/IDER sessions are active, autoneg/speed/duplex
257 * cannot be changed
258 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700259 if (e1000_check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700260 e_err("Cannot change link characteristics when SoL/IDER is "
261 "active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700262 return -EINVAL;
263 }
264
265 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000266 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700267
268 if (ecmd->autoneg == AUTONEG_ENABLE) {
269 hw->mac.autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700270 if (hw->phy.media_type == e1000_media_type_fiber)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700271 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
272 ADVERTISED_FIBRE |
273 ADVERTISED_Autoneg;
274 else
275 hw->phy.autoneg_advertised = ecmd->advertising |
276 ADVERTISED_TP |
277 ADVERTISED_Autoneg;
278 ecmd->advertising = hw->phy.autoneg_advertised;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700279 if (adapter->fc_autoneg)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800280 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700281 } else {
David Decotigny25db0332011-04-27 18:32:39 +0000282 u32 speed = ethtool_cmd_speed(ecmd);
David Decotigny14ad2512011-04-27 18:32:43 +0000283 if (e1000_set_spd_dplx(adapter, speed, ecmd->duplex)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700284 clear_bit(__E1000_RESETTING, &adapter->state);
285 return -EINVAL;
286 }
287 }
288
289 /* reset the link */
290
291 if (netif_running(adapter->netdev)) {
292 e1000e_down(adapter);
293 e1000e_up(adapter);
294 } else {
295 e1000e_reset(adapter);
296 }
297
298 clear_bit(__E1000_RESETTING, &adapter->state);
299 return 0;
300}
301
302static void e1000_get_pauseparam(struct net_device *netdev,
303 struct ethtool_pauseparam *pause)
304{
305 struct e1000_adapter *adapter = netdev_priv(netdev);
306 struct e1000_hw *hw = &adapter->hw;
307
308 pause->autoneg =
309 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
310
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800311 if (hw->fc.current_mode == e1000_fc_rx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700312 pause->rx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800313 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700314 pause->tx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800315 } else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700316 pause->rx_pause = 1;
317 pause->tx_pause = 1;
318 }
319}
320
321static int e1000_set_pauseparam(struct net_device *netdev,
322 struct ethtool_pauseparam *pause)
323{
324 struct e1000_adapter *adapter = netdev_priv(netdev);
325 struct e1000_hw *hw = &adapter->hw;
326 int retval = 0;
327
328 adapter->fc_autoneg = pause->autoneg;
329
330 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000331 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700332
Auke Kokbc7f75f2007-09-17 12:30:59 -0700333 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800334 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700335 if (netif_running(adapter->netdev)) {
336 e1000e_down(adapter);
337 e1000e_up(adapter);
338 } else {
339 e1000e_reset(adapter);
340 }
341 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800342 if (pause->rx_pause && pause->tx_pause)
343 hw->fc.requested_mode = e1000_fc_full;
344 else if (pause->rx_pause && !pause->tx_pause)
345 hw->fc.requested_mode = e1000_fc_rx_pause;
346 else if (!pause->rx_pause && pause->tx_pause)
347 hw->fc.requested_mode = e1000_fc_tx_pause;
348 else if (!pause->rx_pause && !pause->tx_pause)
349 hw->fc.requested_mode = e1000_fc_none;
350
351 hw->fc.current_mode = hw->fc.requested_mode;
352
Bruce Allan945eb312009-10-28 18:28:30 +0000353 if (hw->phy.media_type == e1000_media_type_fiber) {
354 retval = hw->mac.ops.setup_link(hw);
355 /* implicit goto out */
356 } else {
357 retval = e1000e_force_mac_fc(hw);
358 if (retval)
359 goto out;
360 e1000e_set_fc_watermarks(hw);
361 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700362 }
363
Bruce Allan945eb312009-10-28 18:28:30 +0000364out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700365 clear_bit(__E1000_RESETTING, &adapter->state);
366 return retval;
367}
368
369static u32 e1000_get_rx_csum(struct net_device *netdev)
370{
371 struct e1000_adapter *adapter = netdev_priv(netdev);
Eric Dumazet807540b2010-09-23 05:40:09 +0000372 return adapter->flags & FLAG_RX_CSUM_ENABLED;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700373}
374
375static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
376{
377 struct e1000_adapter *adapter = netdev_priv(netdev);
378
379 if (data)
380 adapter->flags |= FLAG_RX_CSUM_ENABLED;
381 else
382 adapter->flags &= ~FLAG_RX_CSUM_ENABLED;
383
384 if (netif_running(netdev))
385 e1000e_reinit_locked(adapter);
386 else
387 e1000e_reset(adapter);
388 return 0;
389}
390
391static u32 e1000_get_tx_csum(struct net_device *netdev)
392{
Eric Dumazet807540b2010-09-23 05:40:09 +0000393 return (netdev->features & NETIF_F_HW_CSUM) != 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700394}
395
396static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
397{
398 if (data)
399 netdev->features |= NETIF_F_HW_CSUM;
400 else
401 netdev->features &= ~NETIF_F_HW_CSUM;
402
403 return 0;
404}
405
406static int e1000_set_tso(struct net_device *netdev, u32 data)
407{
408 struct e1000_adapter *adapter = netdev_priv(netdev);
409
410 if (data) {
411 netdev->features |= NETIF_F_TSO;
412 netdev->features |= NETIF_F_TSO6;
413 } else {
414 netdev->features &= ~NETIF_F_TSO;
415 netdev->features &= ~NETIF_F_TSO6;
416 }
417
Auke Kokbc7f75f2007-09-17 12:30:59 -0700418 adapter->flags |= FLAG_TSO_FORCE;
419 return 0;
420}
421
422static u32 e1000_get_msglevel(struct net_device *netdev)
423{
424 struct e1000_adapter *adapter = netdev_priv(netdev);
425 return adapter->msg_enable;
426}
427
428static void e1000_set_msglevel(struct net_device *netdev, u32 data)
429{
430 struct e1000_adapter *adapter = netdev_priv(netdev);
431 adapter->msg_enable = data;
432}
433
434static int e1000_get_regs_len(struct net_device *netdev)
435{
436#define E1000_REGS_LEN 32 /* overestimate */
437 return E1000_REGS_LEN * sizeof(u32);
438}
439
440static void e1000_get_regs(struct net_device *netdev,
441 struct ethtool_regs *regs, void *p)
442{
443 struct e1000_adapter *adapter = netdev_priv(netdev);
444 struct e1000_hw *hw = &adapter->hw;
445 u32 *regs_buff = p;
446 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700447
448 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
449
Sergei Shtylyovff938e42011-02-28 11:57:33 -0800450 regs->version = (1 << 24) | (adapter->pdev->revision << 16) |
451 adapter->pdev->device;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700452
453 regs_buff[0] = er32(CTRL);
454 regs_buff[1] = er32(STATUS);
455
456 regs_buff[2] = er32(RCTL);
457 regs_buff[3] = er32(RDLEN);
458 regs_buff[4] = er32(RDH);
459 regs_buff[5] = er32(RDT);
460 regs_buff[6] = er32(RDTR);
461
462 regs_buff[7] = er32(TCTL);
463 regs_buff[8] = er32(TDLEN);
464 regs_buff[9] = er32(TDH);
465 regs_buff[10] = er32(TDT);
466 regs_buff[11] = er32(TIDV);
467
468 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700469
470 /* ethtool doesn't use anything past this point, so all this
471 * code is likely legacy junk for apps that may or may not
472 * exist */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700473 if (hw->phy.type == e1000_phy_m88) {
474 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
475 regs_buff[13] = (u32)phy_data; /* cable length */
476 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
477 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
478 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
479 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
480 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
481 regs_buff[18] = regs_buff[13]; /* cable polarity */
482 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
483 regs_buff[20] = regs_buff[17]; /* polarity correction */
484 /* phy receive errors */
485 regs_buff[22] = adapter->phy_stats.receive_errors;
486 regs_buff[23] = regs_buff[13]; /* mdix mode */
487 }
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700488 regs_buff[21] = 0; /* was idle_errors */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700489 e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
490 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
491 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
492}
493
494static int e1000_get_eeprom_len(struct net_device *netdev)
495{
496 struct e1000_adapter *adapter = netdev_priv(netdev);
497 return adapter->hw.nvm.word_size * 2;
498}
499
500static int e1000_get_eeprom(struct net_device *netdev,
501 struct ethtool_eeprom *eeprom, u8 *bytes)
502{
503 struct e1000_adapter *adapter = netdev_priv(netdev);
504 struct e1000_hw *hw = &adapter->hw;
505 u16 *eeprom_buff;
506 int first_word;
507 int last_word;
508 int ret_val = 0;
509 u16 i;
510
511 if (eeprom->len == 0)
512 return -EINVAL;
513
514 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
515
516 first_word = eeprom->offset >> 1;
517 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
518
519 eeprom_buff = kmalloc(sizeof(u16) *
520 (last_word - first_word + 1), GFP_KERNEL);
521 if (!eeprom_buff)
522 return -ENOMEM;
523
524 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
525 ret_val = e1000_read_nvm(hw, first_word,
526 last_word - first_word + 1,
527 eeprom_buff);
528 } else {
529 for (i = 0; i < last_word - first_word + 1; i++) {
530 ret_val = e1000_read_nvm(hw, first_word + i, 1,
531 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800532 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700533 break;
534 }
535 }
536
Bruce Allane2434552008-11-21 17:02:41 -0800537 if (ret_val) {
538 /* a read error occurred, throw away the result */
Roel Kluin8528b012009-12-01 15:54:24 +0000539 memset(eeprom_buff, 0xff, sizeof(u16) *
540 (last_word - first_word + 1));
Bruce Allane2434552008-11-21 17:02:41 -0800541 } else {
542 /* Device's eeprom is always little-endian, word addressable */
543 for (i = 0; i < last_word - first_word + 1; i++)
544 le16_to_cpus(&eeprom_buff[i]);
545 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700546
547 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
548 kfree(eeprom_buff);
549
550 return ret_val;
551}
552
553static int e1000_set_eeprom(struct net_device *netdev,
554 struct ethtool_eeprom *eeprom, u8 *bytes)
555{
556 struct e1000_adapter *adapter = netdev_priv(netdev);
557 struct e1000_hw *hw = &adapter->hw;
558 u16 *eeprom_buff;
559 void *ptr;
560 int max_len;
561 int first_word;
562 int last_word;
563 int ret_val = 0;
564 u16 i;
565
566 if (eeprom->len == 0)
567 return -EOPNOTSUPP;
568
569 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
570 return -EFAULT;
571
Bruce Allan4a770352008-10-01 17:18:35 -0700572 if (adapter->flags & FLAG_READ_ONLY_NVM)
573 return -EINVAL;
574
Auke Kokbc7f75f2007-09-17 12:30:59 -0700575 max_len = hw->nvm.word_size * 2;
576
577 first_word = eeprom->offset >> 1;
578 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
579 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
580 if (!eeprom_buff)
581 return -ENOMEM;
582
583 ptr = (void *)eeprom_buff;
584
585 if (eeprom->offset & 1) {
586 /* need read/modify/write of first changed EEPROM word */
587 /* only the second byte of the word is being modified */
588 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
589 ptr++;
590 }
591 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0))
592 /* need read/modify/write of last changed EEPROM word */
593 /* only the first byte of the word is being modified */
594 ret_val = e1000_read_nvm(hw, last_word, 1,
595 &eeprom_buff[last_word - first_word]);
596
Bruce Allane2434552008-11-21 17:02:41 -0800597 if (ret_val)
598 goto out;
599
Auke Kokbc7f75f2007-09-17 12:30:59 -0700600 /* Device's eeprom is always little-endian, word addressable */
601 for (i = 0; i < last_word - first_word + 1; i++)
602 le16_to_cpus(&eeprom_buff[i]);
603
604 memcpy(ptr, bytes, eeprom->len);
605
606 for (i = 0; i < last_word - first_word + 1; i++)
607 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
608
609 ret_val = e1000_write_nvm(hw, first_word,
610 last_word - first_word + 1, eeprom_buff);
611
Bruce Allane2434552008-11-21 17:02:41 -0800612 if (ret_val)
613 goto out;
614
Bruce Allanad680762008-03-28 09:15:03 -0700615 /*
616 * Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800617 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700618 */
Bruce Allane2434552008-11-21 17:02:41 -0800619 if ((first_word <= NVM_CHECKSUM_REG) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +0000620 (hw->mac.type == e1000_82583) ||
621 (hw->mac.type == e1000_82574) ||
622 (hw->mac.type == e1000_82573))
Bruce Allane2434552008-11-21 17:02:41 -0800623 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700624
Bruce Allane2434552008-11-21 17:02:41 -0800625out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700626 kfree(eeprom_buff);
627 return ret_val;
628}
629
630static void e1000_get_drvinfo(struct net_device *netdev,
631 struct ethtool_drvinfo *drvinfo)
632{
633 struct e1000_adapter *adapter = netdev_priv(netdev);
634 char firmware_version[32];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700635
Bruce Allane0dc4f12011-01-06 14:29:50 +0000636 strncpy(drvinfo->driver, e1000e_driver_name,
637 sizeof(drvinfo->driver) - 1);
638 strncpy(drvinfo->version, e1000e_driver_version,
639 sizeof(drvinfo->version) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700640
Bruce Allanad680762008-03-28 09:15:03 -0700641 /*
642 * EEPROM image version # is reported as firmware version # for
643 * PCI-E controllers
644 */
Bruce Allane0dc4f12011-01-06 14:29:50 +0000645 snprintf(firmware_version, sizeof(firmware_version), "%d.%d-%d",
Bruce Allan84527592008-11-21 17:00:22 -0800646 (adapter->eeprom_vers & 0xF000) >> 12,
647 (adapter->eeprom_vers & 0x0FF0) >> 4,
648 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700649
Bruce Allane0dc4f12011-01-06 14:29:50 +0000650 strncpy(drvinfo->fw_version, firmware_version,
651 sizeof(drvinfo->fw_version) - 1);
652 strncpy(drvinfo->bus_info, pci_name(adapter->pdev),
653 sizeof(drvinfo->bus_info) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700654 drvinfo->regdump_len = e1000_get_regs_len(netdev);
655 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
656}
657
658static void e1000_get_ringparam(struct net_device *netdev,
659 struct ethtool_ringparam *ring)
660{
661 struct e1000_adapter *adapter = netdev_priv(netdev);
662 struct e1000_ring *tx_ring = adapter->tx_ring;
663 struct e1000_ring *rx_ring = adapter->rx_ring;
664
665 ring->rx_max_pending = E1000_MAX_RXD;
666 ring->tx_max_pending = E1000_MAX_TXD;
667 ring->rx_mini_max_pending = 0;
668 ring->rx_jumbo_max_pending = 0;
669 ring->rx_pending = rx_ring->count;
670 ring->tx_pending = tx_ring->count;
671 ring->rx_mini_pending = 0;
672 ring->rx_jumbo_pending = 0;
673}
674
675static int e1000_set_ringparam(struct net_device *netdev,
676 struct ethtool_ringparam *ring)
677{
678 struct e1000_adapter *adapter = netdev_priv(netdev);
679 struct e1000_ring *tx_ring, *tx_old;
680 struct e1000_ring *rx_ring, *rx_old;
681 int err;
682
683 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
684 return -EINVAL;
685
686 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000687 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700688
689 if (netif_running(adapter->netdev))
690 e1000e_down(adapter);
691
692 tx_old = adapter->tx_ring;
693 rx_old = adapter->rx_ring;
694
695 err = -ENOMEM;
Bruce Allan05b93212011-01-05 07:10:38 +0000696 tx_ring = kmemdup(tx_old, sizeof(struct e1000_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700697 if (!tx_ring)
698 goto err_alloc_tx;
699
Bruce Allan05b93212011-01-05 07:10:38 +0000700 rx_ring = kmemdup(rx_old, sizeof(struct e1000_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700701 if (!rx_ring)
702 goto err_alloc_rx;
703
704 adapter->tx_ring = tx_ring;
705 adapter->rx_ring = rx_ring;
706
707 rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
708 rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD));
709 rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
710
711 tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
712 tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
713 tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
714
715 if (netif_running(adapter->netdev)) {
716 /* Try to get new resources before deleting old */
717 err = e1000e_setup_rx_resources(adapter);
718 if (err)
719 goto err_setup_rx;
720 err = e1000e_setup_tx_resources(adapter);
721 if (err)
722 goto err_setup_tx;
723
Bruce Allanad680762008-03-28 09:15:03 -0700724 /*
725 * restore the old in order to free it,
726 * then add in the new
727 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700728 adapter->rx_ring = rx_old;
729 adapter->tx_ring = tx_old;
730 e1000e_free_rx_resources(adapter);
731 e1000e_free_tx_resources(adapter);
732 kfree(tx_old);
733 kfree(rx_old);
734 adapter->rx_ring = rx_ring;
735 adapter->tx_ring = tx_ring;
736 err = e1000e_up(adapter);
737 if (err)
738 goto err_setup;
739 }
740
741 clear_bit(__E1000_RESETTING, &adapter->state);
742 return 0;
743err_setup_tx:
744 e1000e_free_rx_resources(adapter);
745err_setup_rx:
746 adapter->rx_ring = rx_old;
747 adapter->tx_ring = tx_old;
748 kfree(rx_ring);
749err_alloc_rx:
750 kfree(tx_ring);
751err_alloc_tx:
752 e1000e_up(adapter);
753err_setup:
754 clear_bit(__E1000_RESETTING, &adapter->state);
755 return err;
756}
757
Bruce Allancef8c792008-04-02 13:48:23 -0700758static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
759 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800760{
Bruce Allancef8c792008-04-02 13:48:23 -0700761 u32 pat, val;
Bruce Allan64806412010-12-11 05:53:42 +0000762 static const u32 test[] = {
763 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Bruce Allancef8c792008-04-02 13:48:23 -0700764 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800765 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700766 (test[pat] & write));
767 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
768 if (val != (test[pat] & write & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700769 e_err("pattern test reg %04X failed: got 0x%08X "
770 "expected 0x%08X\n", reg + offset, val,
771 (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800772 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700773 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800774 }
775 }
Bruce Allancef8c792008-04-02 13:48:23 -0700776 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700777}
778
Joe Perches2a887192007-11-13 20:53:51 -0800779static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
780 int reg, u32 mask, u32 write)
781{
Bruce Allancef8c792008-04-02 13:48:23 -0700782 u32 val;
Joe Perches2a887192007-11-13 20:53:51 -0800783 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700784 val = __er32(&adapter->hw, reg);
785 if ((write & mask) != (val & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700786 e_err("set/check reg %04X test failed: got 0x%08X "
787 "expected 0x%08X\n", reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800788 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700789 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800790 }
Bruce Allancef8c792008-04-02 13:48:23 -0700791 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700792}
Bruce Allancef8c792008-04-02 13:48:23 -0700793#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
794 do { \
795 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
796 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800797 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700798#define REG_PATTERN_TEST(reg, mask, write) \
799 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800800
Bruce Allancef8c792008-04-02 13:48:23 -0700801#define REG_SET_AND_CHECK(reg, mask, write) \
802 do { \
803 if (reg_set_and_check(adapter, data, reg, mask, write)) \
804 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800805 } while (0)
806
Auke Kokbc7f75f2007-09-17 12:30:59 -0700807static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
808{
809 struct e1000_hw *hw = &adapter->hw;
810 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700811 u32 value;
812 u32 before;
813 u32 after;
814 u32 i;
815 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000816 u32 mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700817
Bruce Allanad680762008-03-28 09:15:03 -0700818 /*
819 * The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700820 * Some bits that get toggled are ignored.
821 */
822 switch (mac->type) {
823 /* there are several bits on newer hardware that are r/w */
824 case e1000_82571:
825 case e1000_82572:
826 case e1000_80003es2lan:
827 toggle = 0x7FFFF3FF;
828 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000829 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700830 toggle = 0x7FFFF033;
831 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700832 }
833
834 before = er32(STATUS);
835 value = (er32(STATUS) & toggle);
836 ew32(STATUS, toggle);
837 after = er32(STATUS) & toggle;
838 if (value != after) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700839 e_err("failed STATUS register test got: 0x%08X expected: "
840 "0x%08X\n", after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700841 *data = 1;
842 return 1;
843 }
844 /* restore previous status */
845 ew32(STATUS, before);
846
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700847 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700848 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
849 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
850 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
851 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
852 }
853
854 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
855 REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
856 REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF);
857 REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF);
858 REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF);
859 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
860 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
861 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
862 REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
863 REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF);
864
865 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
866
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700867 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700868 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
869 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
870
Auke Kok86582512007-10-04 15:00:08 -0700871 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
872 REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700873 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700874 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
875 REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
876 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000877 mask = 0x8003FFFF;
878 switch (mac->type) {
879 case e1000_ich10lan:
880 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000881 case e1000_pch2lan:
Bruce Allana4f58f52009-06-02 11:29:18 +0000882 mask |= (1 << 18);
883 break;
884 default:
885 break;
886 }
Auke Kok86582512007-10-04 15:00:08 -0700887 for (i = 0; i < mac->rar_entry_count; i++)
888 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
Bruce Allana4f58f52009-06-02 11:29:18 +0000889 mask, 0xFFFFFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700890
891 for (i = 0; i < mac->mta_reg_count; i++)
892 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
893
894 *data = 0;
895 return 0;
896}
897
898static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
899{
900 u16 temp;
901 u16 checksum = 0;
902 u16 i;
903
904 *data = 0;
905 /* Read and add up the contents of the EEPROM */
906 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
907 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
908 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800909 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700910 }
911 checksum += temp;
912 }
913
914 /* If Checksum is not Correct return error else test passed */
915 if ((checksum != (u16) NVM_SUM) && !(*data))
916 *data = 2;
917
918 return *data;
919}
920
921static irqreturn_t e1000_test_intr(int irq, void *data)
922{
923 struct net_device *netdev = (struct net_device *) data;
924 struct e1000_adapter *adapter = netdev_priv(netdev);
925 struct e1000_hw *hw = &adapter->hw;
926
927 adapter->test_icr |= er32(ICR);
928
929 return IRQ_HANDLED;
930}
931
932static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
933{
934 struct net_device *netdev = adapter->netdev;
935 struct e1000_hw *hw = &adapter->hw;
936 u32 mask;
937 u32 shared_int = 1;
938 u32 irq = adapter->pdev->irq;
939 int i;
Bruce Allan4662e822008-08-26 18:37:06 -0700940 int ret_val = 0;
941 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700942
943 *data = 0;
944
Bruce Allan4662e822008-08-26 18:37:06 -0700945 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
946 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
947 int_mode = adapter->int_mode;
948 e1000e_reset_interrupt_capability(adapter);
949 adapter->int_mode = E1000E_INT_MODE_LEGACY;
950 e1000e_set_interrupt_capability(adapter);
951 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700952 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800953 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700954 netdev)) {
955 shared_int = 0;
Joe Perchesa0607fd2009-11-18 23:29:17 -0800956 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700957 netdev->name, netdev)) {
958 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700959 ret_val = -1;
960 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700961 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700962 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700963
964 /* Disable all the interrupts */
965 ew32(IMC, 0xFFFFFFFF);
Bruce Allan1bba4382011-03-19 00:27:20 +0000966 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700967
968 /* Test each interrupt */
969 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700970 /* Interrupt to test */
971 mask = 1 << i;
972
Bruce Allanf4187b52008-08-26 18:36:50 -0700973 if (adapter->flags & FLAG_IS_ICH) {
974 switch (mask) {
975 case E1000_ICR_RXSEQ:
976 continue;
977 case 0x00000100:
978 if (adapter->hw.mac.type == e1000_ich8lan ||
979 adapter->hw.mac.type == e1000_ich9lan)
980 continue;
981 break;
982 default:
983 break;
984 }
985 }
986
Auke Kokbc7f75f2007-09-17 12:30:59 -0700987 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700988 /*
989 * Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700990 * the cause register and then force the same
991 * interrupt and see if one gets posted. If
992 * an interrupt was posted to the bus, the
993 * test failed.
994 */
995 adapter->test_icr = 0;
996 ew32(IMC, mask);
997 ew32(ICS, mask);
Bruce Allan1bba4382011-03-19 00:27:20 +0000998 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700999
1000 if (adapter->test_icr & mask) {
1001 *data = 3;
1002 break;
1003 }
1004 }
1005
Bruce Allanad680762008-03-28 09:15:03 -07001006 /*
1007 * Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001008 * the cause register and then force the same
1009 * interrupt and see if one gets posted. If
1010 * an interrupt was not posted to the bus, the
1011 * test failed.
1012 */
1013 adapter->test_icr = 0;
1014 ew32(IMS, mask);
1015 ew32(ICS, mask);
Bruce Allan1bba4382011-03-19 00:27:20 +00001016 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001017
1018 if (!(adapter->test_icr & mask)) {
1019 *data = 4;
1020 break;
1021 }
1022
1023 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -07001024 /*
1025 * Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001026 * the cause register and then force the other
1027 * interrupts and see if any get posted. If
1028 * an interrupt was posted to the bus, the
1029 * test failed.
1030 */
1031 adapter->test_icr = 0;
1032 ew32(IMC, ~mask & 0x00007FFF);
1033 ew32(ICS, ~mask & 0x00007FFF);
Bruce Allan1bba4382011-03-19 00:27:20 +00001034 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001035
1036 if (adapter->test_icr) {
1037 *data = 5;
1038 break;
1039 }
1040 }
1041 }
1042
1043 /* Disable all the interrupts */
1044 ew32(IMC, 0xFFFFFFFF);
Bruce Allan1bba4382011-03-19 00:27:20 +00001045 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001046
1047 /* Unhook test interrupt handler */
1048 free_irq(irq, netdev);
1049
Bruce Allan4662e822008-08-26 18:37:06 -07001050out:
1051 if (int_mode == E1000E_INT_MODE_MSIX) {
1052 e1000e_reset_interrupt_capability(adapter);
1053 adapter->int_mode = int_mode;
1054 e1000e_set_interrupt_capability(adapter);
1055 }
1056
1057 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001058}
1059
1060static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1061{
1062 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1063 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1064 struct pci_dev *pdev = adapter->pdev;
1065 int i;
1066
1067 if (tx_ring->desc && tx_ring->buffer_info) {
1068 for (i = 0; i < tx_ring->count; i++) {
1069 if (tx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001070 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001071 tx_ring->buffer_info[i].dma,
1072 tx_ring->buffer_info[i].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001073 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001074 if (tx_ring->buffer_info[i].skb)
1075 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1076 }
1077 }
1078
1079 if (rx_ring->desc && rx_ring->buffer_info) {
1080 for (i = 0; i < rx_ring->count; i++) {
1081 if (rx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001082 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001083 rx_ring->buffer_info[i].dma,
Nick Nunley0be3f552010-04-27 13:09:05 +00001084 2048, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001085 if (rx_ring->buffer_info[i].skb)
1086 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1087 }
1088 }
1089
1090 if (tx_ring->desc) {
1091 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1092 tx_ring->dma);
1093 tx_ring->desc = NULL;
1094 }
1095 if (rx_ring->desc) {
1096 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1097 rx_ring->dma);
1098 rx_ring->desc = NULL;
1099 }
1100
1101 kfree(tx_ring->buffer_info);
1102 tx_ring->buffer_info = NULL;
1103 kfree(rx_ring->buffer_info);
1104 rx_ring->buffer_info = NULL;
1105}
1106
1107static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1108{
1109 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1110 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1111 struct pci_dev *pdev = adapter->pdev;
1112 struct e1000_hw *hw = &adapter->hw;
1113 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001114 int i;
1115 int ret_val;
1116
1117 /* Setup Tx descriptor ring and Tx buffers */
1118
1119 if (!tx_ring->count)
1120 tx_ring->count = E1000_DEFAULT_TXD;
1121
Bruce Allancef8c792008-04-02 13:48:23 -07001122 tx_ring->buffer_info = kcalloc(tx_ring->count,
1123 sizeof(struct e1000_buffer),
1124 GFP_KERNEL);
1125 if (!(tx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001126 ret_val = 1;
1127 goto err_nomem;
1128 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001129
1130 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1131 tx_ring->size = ALIGN(tx_ring->size, 4096);
1132 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1133 &tx_ring->dma, GFP_KERNEL);
1134 if (!tx_ring->desc) {
1135 ret_val = 2;
1136 goto err_nomem;
1137 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001138 tx_ring->next_to_use = 0;
1139 tx_ring->next_to_clean = 0;
1140
Bruce Allancef8c792008-04-02 13:48:23 -07001141 ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001142 ew32(TDBAH, ((u64) tx_ring->dma >> 32));
Bruce Allancef8c792008-04-02 13:48:23 -07001143 ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001144 ew32(TDH, 0);
1145 ew32(TDT, 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001146 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1147 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1148 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001149
1150 for (i = 0; i < tx_ring->count; i++) {
1151 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1152 struct sk_buff *skb;
1153 unsigned int skb_size = 1024;
1154
1155 skb = alloc_skb(skb_size, GFP_KERNEL);
1156 if (!skb) {
1157 ret_val = 3;
1158 goto err_nomem;
1159 }
1160 skb_put(skb, skb_size);
1161 tx_ring->buffer_info[i].skb = skb;
1162 tx_ring->buffer_info[i].length = skb->len;
1163 tx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001164 dma_map_single(&pdev->dev, skb->data, skb->len,
1165 DMA_TO_DEVICE);
1166 if (dma_mapping_error(&pdev->dev,
1167 tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001168 ret_val = 4;
1169 goto err_nomem;
1170 }
Bruce Allancef8c792008-04-02 13:48:23 -07001171 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001172 tx_desc->lower.data = cpu_to_le32(skb->len);
1173 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1174 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001175 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001176 tx_desc->upper.data = 0;
1177 }
1178
1179 /* Setup Rx descriptor ring and Rx buffers */
1180
1181 if (!rx_ring->count)
1182 rx_ring->count = E1000_DEFAULT_RXD;
1183
Bruce Allancef8c792008-04-02 13:48:23 -07001184 rx_ring->buffer_info = kcalloc(rx_ring->count,
1185 sizeof(struct e1000_buffer),
1186 GFP_KERNEL);
1187 if (!(rx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001188 ret_val = 5;
1189 goto err_nomem;
1190 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001191
1192 rx_ring->size = rx_ring->count * sizeof(struct e1000_rx_desc);
1193 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1194 &rx_ring->dma, GFP_KERNEL);
1195 if (!rx_ring->desc) {
1196 ret_val = 6;
1197 goto err_nomem;
1198 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001199 rx_ring->next_to_use = 0;
1200 rx_ring->next_to_clean = 0;
1201
1202 rctl = er32(RCTL);
1203 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1204 ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
1205 ew32(RDBAH, ((u64) rx_ring->dma >> 32));
1206 ew32(RDLEN, rx_ring->size);
1207 ew32(RDH, 0);
1208 ew32(RDT, 0);
1209 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allancef8c792008-04-02 13:48:23 -07001210 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1211 E1000_RCTL_SBP | E1000_RCTL_SECRC |
Auke Kokbc7f75f2007-09-17 12:30:59 -07001212 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1213 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1214 ew32(RCTL, rctl);
1215
1216 for (i = 0; i < rx_ring->count; i++) {
1217 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
1218 struct sk_buff *skb;
1219
1220 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1221 if (!skb) {
1222 ret_val = 7;
1223 goto err_nomem;
1224 }
1225 skb_reserve(skb, NET_IP_ALIGN);
1226 rx_ring->buffer_info[i].skb = skb;
1227 rx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001228 dma_map_single(&pdev->dev, skb->data, 2048,
1229 DMA_FROM_DEVICE);
1230 if (dma_mapping_error(&pdev->dev,
1231 rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001232 ret_val = 8;
1233 goto err_nomem;
1234 }
1235 rx_desc->buffer_addr =
1236 cpu_to_le64(rx_ring->buffer_info[i].dma);
1237 memset(skb->data, 0x00, skb->len);
1238 }
1239
1240 return 0;
1241
1242err_nomem:
1243 e1000_free_desc_rings(adapter);
1244 return ret_val;
1245}
1246
1247static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1248{
1249 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1250 e1e_wphy(&adapter->hw, 29, 0x001F);
1251 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1252 e1e_wphy(&adapter->hw, 29, 0x001A);
1253 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1254}
1255
1256static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1257{
1258 struct e1000_hw *hw = &adapter->hw;
1259 u32 ctrl_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001260 u16 phy_reg = 0;
Bruce Allancbd006c2010-11-24 06:01:30 +00001261 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001262
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001263 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001264
Bruce Allan3af50482010-06-16 13:25:55 +00001265 if (hw->phy.type == e1000_phy_ife) {
1266 /* force 100, set loopback */
1267 e1e_wphy(hw, PHY_CONTROL, 0x6100);
Bruce Allanbb436b22009-11-20 23:24:11 +00001268
Bruce Allan3af50482010-06-16 13:25:55 +00001269 /* Now set up the MAC to the same speed/duplex as the PHY. */
1270 ctrl_reg = er32(CTRL);
1271 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1272 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1273 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1274 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1275 E1000_CTRL_FD); /* Force Duplex to FULL */
1276
1277 ew32(CTRL, ctrl_reg);
1278 udelay(500);
1279
1280 return 0;
1281 }
1282
1283 /* Specific PHY configuration for loopback */
1284 switch (hw->phy.type) {
1285 case e1000_phy_m88:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001286 /* Auto-MDI/MDIX Off */
1287 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1288 /* reset to update Auto-MDI/MDIX */
1289 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1290 /* autoneg off */
1291 e1e_wphy(hw, PHY_CONTROL, 0x8140);
Bruce Allan3af50482010-06-16 13:25:55 +00001292 break;
1293 case e1000_phy_gg82563:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001294 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
Bruce Allancef8c792008-04-02 13:48:23 -07001295 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001296 case e1000_phy_bm:
1297 /* Set Default MAC Interface speed to 1GB */
1298 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1299 phy_reg &= ~0x0007;
1300 phy_reg |= 0x006;
1301 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1302 /* Assert SW reset for above settings to take effect */
1303 e1000e_commit_phy(hw);
1304 mdelay(1);
1305 /* Force Full Duplex */
1306 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1307 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1308 /* Set Link Up (in force link) */
1309 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1310 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1311 /* Force Link */
1312 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1313 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1314 /* Set Early Link Enable */
1315 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1316 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
Bruce Allan3af50482010-06-16 13:25:55 +00001317 break;
1318 case e1000_phy_82577:
1319 case e1000_phy_82578:
1320 /* Workaround: K1 must be disabled for stable 1Gbps operation */
Bruce Allancbd006c2010-11-24 06:01:30 +00001321 ret_val = hw->phy.ops.acquire(hw);
1322 if (ret_val) {
1323 e_err("Cannot setup 1Gbps loopback.\n");
1324 return ret_val;
1325 }
Bruce Allan3af50482010-06-16 13:25:55 +00001326 e1000_configure_k1_ich8lan(hw, false);
Bruce Allancbd006c2010-11-24 06:01:30 +00001327 hw->phy.ops.release(hw);
Bruce Allan3af50482010-06-16 13:25:55 +00001328 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001329 case e1000_phy_82579:
1330 /* Disable PHY energy detect power down */
1331 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1332 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
1333 /* Disable full chip energy detect */
1334 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1335 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1336 /* Enable loopback on the PHY */
1337#define I82577_PHY_LBK_CTRL 19
1338 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1339 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001340 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001341 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001342 }
1343
Bruce Allan3af50482010-06-16 13:25:55 +00001344 /* force 1000, set loopback */
1345 e1e_wphy(hw, PHY_CONTROL, 0x4140);
1346 mdelay(250);
1347
1348 /* Now set up the MAC to the same speed/duplex as the PHY. */
1349 ctrl_reg = er32(CTRL);
1350 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1351 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1352 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1353 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1354 E1000_CTRL_FD); /* Force Duplex to FULL */
1355
1356 if (adapter->flags & FLAG_IS_ICH)
1357 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1358
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001359 if (hw->phy.media_type == e1000_media_type_copper &&
1360 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001361 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1362 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001363 /*
1364 * Set the ILOS bit on the fiber Nic if half duplex link is
1365 * detected.
1366 */
Bruce Allan90da0662011-01-06 07:02:53 +00001367 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001368 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1369 }
1370
1371 ew32(CTRL, ctrl_reg);
1372
Bruce Allanad680762008-03-28 09:15:03 -07001373 /*
1374 * Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001375 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1376 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001377 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001378 e1000_phy_disable_receiver(adapter);
1379
1380 udelay(500);
1381
1382 return 0;
1383}
1384
1385static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1386{
1387 struct e1000_hw *hw = &adapter->hw;
1388 u32 ctrl = er32(CTRL);
1389 int link = 0;
1390
1391 /* special requirements for 82571/82572 fiber adapters */
1392
Bruce Allanad680762008-03-28 09:15:03 -07001393 /*
1394 * jump through hoops to make sure link is up because serdes
1395 * link is hardwired up
1396 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001397 ctrl |= E1000_CTRL_SLU;
1398 ew32(CTRL, ctrl);
1399
1400 /* disable autoneg */
1401 ctrl = er32(TXCW);
1402 ctrl &= ~(1 << 31);
1403 ew32(TXCW, ctrl);
1404
1405 link = (er32(STATUS) & E1000_STATUS_LU);
1406
1407 if (!link) {
1408 /* set invert loss of signal */
1409 ctrl = er32(CTRL);
1410 ctrl |= E1000_CTRL_ILOS;
1411 ew32(CTRL, ctrl);
1412 }
1413
Bruce Allanad680762008-03-28 09:15:03 -07001414 /*
1415 * special write to serdes control register to enable SerDes analog
1416 * loopback
1417 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001418#define E1000_SERDES_LB_ON 0x410
1419 ew32(SCTL, E1000_SERDES_LB_ON);
Bruce Allan1bba4382011-03-19 00:27:20 +00001420 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001421
1422 return 0;
1423}
1424
1425/* only call this for fiber/serdes connections to es2lan */
1426static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1427{
1428 struct e1000_hw *hw = &adapter->hw;
1429 u32 ctrlext = er32(CTRL_EXT);
1430 u32 ctrl = er32(CTRL);
1431
Bruce Allanad680762008-03-28 09:15:03 -07001432 /*
1433 * save CTRL_EXT to restore later, reuse an empty variable (unused
1434 * on mac_type 80003es2lan)
1435 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001436 adapter->tx_fifo_head = ctrlext;
1437
1438 /* clear the serdes mode bits, putting the device into mac loopback */
1439 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1440 ew32(CTRL_EXT, ctrlext);
1441
1442 /* force speed to 1000/FD, link up */
1443 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1444 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1445 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1446 ew32(CTRL, ctrl);
1447
1448 /* set mac loopback */
1449 ctrl = er32(RCTL);
1450 ctrl |= E1000_RCTL_LBM_MAC;
1451 ew32(RCTL, ctrl);
1452
1453 /* set testing mode parameters (no need to reset later) */
1454#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1455#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1456 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001457 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001458
1459 return 0;
1460}
1461
1462static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1463{
1464 struct e1000_hw *hw = &adapter->hw;
1465 u32 rctl;
1466
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001467 if (hw->phy.media_type == e1000_media_type_fiber ||
1468 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001469 switch (hw->mac.type) {
1470 case e1000_80003es2lan:
1471 return e1000_set_es2lan_mac_loopback(adapter);
1472 break;
1473 case e1000_82571:
1474 case e1000_82572:
1475 return e1000_set_82571_fiber_loopback(adapter);
1476 break;
1477 default:
1478 rctl = er32(RCTL);
1479 rctl |= E1000_RCTL_LBM_TCVR;
1480 ew32(RCTL, rctl);
1481 return 0;
1482 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001483 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001484 return e1000_integrated_phy_loopback(adapter);
1485 }
1486
1487 return 7;
1488}
1489
1490static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1491{
1492 struct e1000_hw *hw = &adapter->hw;
1493 u32 rctl;
1494 u16 phy_reg;
1495
1496 rctl = er32(RCTL);
1497 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1498 ew32(RCTL, rctl);
1499
1500 switch (hw->mac.type) {
1501 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001502 if (hw->phy.media_type == e1000_media_type_fiber ||
1503 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001504 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001505 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001506 adapter->tx_fifo_head = 0;
1507 }
1508 /* fall through */
1509 case e1000_82571:
1510 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001511 if (hw->phy.media_type == e1000_media_type_fiber ||
1512 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001513#define E1000_SERDES_LB_OFF 0x400
1514 ew32(SCTL, E1000_SERDES_LB_OFF);
Bruce Allan1bba4382011-03-19 00:27:20 +00001515 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001516 break;
1517 }
1518 /* Fall Through */
1519 default:
1520 hw->mac.autoneg = 1;
1521 if (hw->phy.type == e1000_phy_gg82563)
1522 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1523 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1524 if (phy_reg & MII_CR_LOOPBACK) {
1525 phy_reg &= ~MII_CR_LOOPBACK;
1526 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1527 e1000e_commit_phy(hw);
1528 }
1529 break;
1530 }
1531}
1532
1533static void e1000_create_lbtest_frame(struct sk_buff *skb,
1534 unsigned int frame_size)
1535{
1536 memset(skb->data, 0xFF, frame_size);
1537 frame_size &= ~1;
1538 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1539 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1540 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1541}
1542
1543static int e1000_check_lbtest_frame(struct sk_buff *skb,
1544 unsigned int frame_size)
1545{
1546 frame_size &= ~1;
1547 if (*(skb->data + 3) == 0xFF)
1548 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1549 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1550 return 0;
1551 return 13;
1552}
1553
1554static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1555{
1556 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1557 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1558 struct pci_dev *pdev = adapter->pdev;
1559 struct e1000_hw *hw = &adapter->hw;
1560 int i, j, k, l;
1561 int lc;
1562 int good_cnt;
1563 int ret_val = 0;
1564 unsigned long time;
1565
1566 ew32(RDT, rx_ring->count - 1);
1567
Bruce Allanad680762008-03-28 09:15:03 -07001568 /*
1569 * Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001570 * The idea is to wrap the largest ring a number of times using 64
1571 * send/receive pairs during each loop
1572 */
1573
1574 if (rx_ring->count <= tx_ring->count)
1575 lc = ((tx_ring->count / 64) * 2) + 1;
1576 else
1577 lc = ((rx_ring->count / 64) * 2) + 1;
1578
1579 k = 0;
1580 l = 0;
1581 for (j = 0; j <= lc; j++) { /* loop count loop */
1582 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001583 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1584 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001585 dma_sync_single_for_device(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001586 tx_ring->buffer_info[k].dma,
1587 tx_ring->buffer_info[k].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001588 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001589 k++;
1590 if (k == tx_ring->count)
1591 k = 0;
1592 }
1593 ew32(TDT, k);
1594 msleep(200);
1595 time = jiffies; /* set the start time for the receive */
1596 good_cnt = 0;
1597 do { /* receive the sent packets */
Nick Nunley0be3f552010-04-27 13:09:05 +00001598 dma_sync_single_for_cpu(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001599 rx_ring->buffer_info[l].dma, 2048,
Nick Nunley0be3f552010-04-27 13:09:05 +00001600 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001601
1602 ret_val = e1000_check_lbtest_frame(
1603 rx_ring->buffer_info[l].skb, 1024);
1604 if (!ret_val)
1605 good_cnt++;
1606 l++;
1607 if (l == rx_ring->count)
1608 l = 0;
Bruce Allanad680762008-03-28 09:15:03 -07001609 /*
1610 * time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001611 * enough time to complete the receives, if it's
1612 * exceeded, break and error off
1613 */
1614 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1615 if (good_cnt != 64) {
1616 ret_val = 13; /* ret_val is the same as mis-compare */
1617 break;
1618 }
Bruce Allancef8c792008-04-02 13:48:23 -07001619 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001620 ret_val = 14; /* error code for time out error */
1621 break;
1622 }
1623 } /* end loop count loop */
1624 return ret_val;
1625}
1626
1627static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1628{
Bruce Allanad680762008-03-28 09:15:03 -07001629 /*
1630 * PHY loopback cannot be performed if SoL/IDER
1631 * sessions are active
1632 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001633 if (e1000_check_reset_block(&adapter->hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001634 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001635 *data = 0;
1636 goto out;
1637 }
1638
1639 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001640 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001641 goto out;
1642
1643 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001644 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001645 goto err_loopback;
1646
1647 *data = e1000_run_loopback_test(adapter);
1648 e1000_loopback_cleanup(adapter);
1649
1650err_loopback:
1651 e1000_free_desc_rings(adapter);
1652out:
1653 return *data;
1654}
1655
1656static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1657{
1658 struct e1000_hw *hw = &adapter->hw;
1659
1660 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001661 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001662 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001663 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001664
Bruce Allanad680762008-03-28 09:15:03 -07001665 /*
1666 * On some blade server designs, link establishment
1667 * could take as long as 2-3 minutes
1668 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001669 do {
1670 hw->mac.ops.check_for_link(hw);
1671 if (hw->mac.serdes_has_link)
1672 return *data;
1673 msleep(20);
1674 } while (i++ < 3750);
1675
1676 *data = 1;
1677 } else {
1678 hw->mac.ops.check_for_link(hw);
1679 if (hw->mac.autoneg)
Bruce Allan5661aeb2011-02-25 06:36:25 +00001680 /*
1681 * On some Phy/switch combinations, link establishment
1682 * can take a few seconds more than expected.
1683 */
1684 msleep(5000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001685
Bruce Allan5661aeb2011-02-25 06:36:25 +00001686 if (!(er32(STATUS) & E1000_STATUS_LU))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001687 *data = 1;
1688 }
1689 return *data;
1690}
1691
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001692static int e1000e_get_sset_count(struct net_device *netdev, int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001693{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001694 switch (sset) {
1695 case ETH_SS_TEST:
1696 return E1000_TEST_LEN;
1697 case ETH_SS_STATS:
1698 return E1000_STATS_LEN;
1699 default:
1700 return -EOPNOTSUPP;
1701 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001702}
1703
1704static void e1000_diag_test(struct net_device *netdev,
1705 struct ethtool_test *eth_test, u64 *data)
1706{
1707 struct e1000_adapter *adapter = netdev_priv(netdev);
1708 u16 autoneg_advertised;
1709 u8 forced_speed_duplex;
1710 u8 autoneg;
1711 bool if_running = netif_running(netdev);
1712
1713 set_bit(__E1000_TESTING, &adapter->state);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001714
1715 if (!if_running) {
1716 /* Get control of and reset hardware */
1717 if (adapter->flags & FLAG_HAS_AMT)
1718 e1000e_get_hw_control(adapter);
1719
1720 e1000e_power_up_phy(adapter);
1721
1722 adapter->hw.phy.autoneg_wait_to_complete = 1;
1723 e1000e_reset(adapter);
1724 adapter->hw.phy.autoneg_wait_to_complete = 0;
1725 }
1726
Auke Kokbc7f75f2007-09-17 12:30:59 -07001727 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1728 /* Offline tests */
1729
1730 /* save speed, duplex, autoneg settings */
1731 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1732 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1733 autoneg = adapter->hw.mac.autoneg;
1734
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001735 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001736
Auke Kokbc7f75f2007-09-17 12:30:59 -07001737 if (if_running)
1738 /* indicate we're in test mode */
1739 dev_close(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001740
1741 if (e1000_reg_test(adapter, &data[0]))
1742 eth_test->flags |= ETH_TEST_FL_FAILED;
1743
1744 e1000e_reset(adapter);
1745 if (e1000_eeprom_test(adapter, &data[1]))
1746 eth_test->flags |= ETH_TEST_FL_FAILED;
1747
1748 e1000e_reset(adapter);
1749 if (e1000_intr_test(adapter, &data[2]))
1750 eth_test->flags |= ETH_TEST_FL_FAILED;
1751
1752 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001753 if (e1000_loopback_test(adapter, &data[3]))
1754 eth_test->flags |= ETH_TEST_FL_FAILED;
1755
Auke Kokbc7f75f2007-09-17 12:30:59 -07001756 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001757 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001758 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001759 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001760
Carolyn Wybornyc6ce3852010-10-15 17:35:31 +00001761 if (e1000_link_test(adapter, &data[4]))
1762 eth_test->flags |= ETH_TEST_FL_FAILED;
1763
1764 /* restore speed, duplex, autoneg settings */
1765 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1766 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1767 adapter->hw.mac.autoneg = autoneg;
1768 e1000e_reset(adapter);
1769
Auke Kokbc7f75f2007-09-17 12:30:59 -07001770 clear_bit(__E1000_TESTING, &adapter->state);
1771 if (if_running)
1772 dev_open(netdev);
1773 } else {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001774 /* Online tests */
Bruce Allan11b08be2010-05-10 14:59:31 +00001775
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001776 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001777
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001778 /* register, eeprom, intr and loopback tests not run online */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001779 data[0] = 0;
1780 data[1] = 0;
1781 data[2] = 0;
1782 data[3] = 0;
1783
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001784 if (e1000_link_test(adapter, &data[4]))
1785 eth_test->flags |= ETH_TEST_FL_FAILED;
Bruce Allan11b08be2010-05-10 14:59:31 +00001786
Auke Kokbc7f75f2007-09-17 12:30:59 -07001787 clear_bit(__E1000_TESTING, &adapter->state);
1788 }
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001789
1790 if (!if_running) {
1791 e1000e_reset(adapter);
1792
1793 if (adapter->flags & FLAG_HAS_AMT)
1794 e1000e_release_hw_control(adapter);
1795 }
1796
Auke Kokbc7f75f2007-09-17 12:30:59 -07001797 msleep_interruptible(4 * 1000);
1798}
1799
1800static void e1000_get_wol(struct net_device *netdev,
1801 struct ethtool_wolinfo *wol)
1802{
1803 struct e1000_adapter *adapter = netdev_priv(netdev);
1804
1805 wol->supported = 0;
1806 wol->wolopts = 0;
1807
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001808 if (!(adapter->flags & FLAG_HAS_WOL) ||
1809 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001810 return;
1811
1812 wol->supported = WAKE_UCAST | WAKE_MCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001813 WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001814
1815 /* apply any specific unsupported masks here */
1816 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1817 wol->supported &= ~WAKE_UCAST;
1818
1819 if (adapter->wol & E1000_WUFC_EX)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001820 e_err("Interface does not support directed (unicast) "
1821 "frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001822 }
1823
1824 if (adapter->wol & E1000_WUFC_EX)
1825 wol->wolopts |= WAKE_UCAST;
1826 if (adapter->wol & E1000_WUFC_MC)
1827 wol->wolopts |= WAKE_MCAST;
1828 if (adapter->wol & E1000_WUFC_BC)
1829 wol->wolopts |= WAKE_BCAST;
1830 if (adapter->wol & E1000_WUFC_MAG)
1831 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001832 if (adapter->wol & E1000_WUFC_LNKC)
1833 wol->wolopts |= WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001834}
1835
Bruce Allan4a29e152011-03-04 09:07:01 +00001836static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001837{
1838 struct e1000_adapter *adapter = netdev_priv(netdev);
1839
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001840 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001841 !device_can_wakeup(&adapter->pdev->dev) ||
1842 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001843 WAKE_MAGIC | WAKE_PHY)))
Bruce Allan1fbfca32009-11-20 23:22:01 +00001844 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001845
1846 /* these settings will always override what we currently have */
1847 adapter->wol = 0;
1848
1849 if (wol->wolopts & WAKE_UCAST)
1850 adapter->wol |= E1000_WUFC_EX;
1851 if (wol->wolopts & WAKE_MCAST)
1852 adapter->wol |= E1000_WUFC_MC;
1853 if (wol->wolopts & WAKE_BCAST)
1854 adapter->wol |= E1000_WUFC_BC;
1855 if (wol->wolopts & WAKE_MAGIC)
1856 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001857 if (wol->wolopts & WAKE_PHY)
1858 adapter->wol |= E1000_WUFC_LNKC;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001859
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001860 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1861
Auke Kokbc7f75f2007-09-17 12:30:59 -07001862 return 0;
1863}
1864
Bruce Allandbf80dc2011-04-16 00:34:40 +00001865static int e1000_set_phys_id(struct net_device *netdev,
1866 enum ethtool_phys_id_state state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001867{
1868 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001869 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001870
Bruce Allandbf80dc2011-04-16 00:34:40 +00001871 switch (state) {
1872 case ETHTOOL_ID_ACTIVE:
1873 if (!hw->mac.ops.blink_led)
1874 return 2; /* cycle on/off twice per second */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001875
Bruce Allandbf80dc2011-04-16 00:34:40 +00001876 hw->mac.ops.blink_led(hw);
1877 break;
1878
1879 case ETHTOOL_ID_INACTIVE:
Bruce Allan4662e822008-08-26 18:37:06 -07001880 if (hw->phy.type == e1000_phy_ife)
1881 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001882 hw->mac.ops.led_off(hw);
1883 hw->mac.ops.cleanup_led(hw);
1884 break;
1885
1886 case ETHTOOL_ID_ON:
1887 adapter->hw.mac.ops.led_on(&adapter->hw);
1888 break;
1889
1890 case ETHTOOL_ID_OFF:
1891 adapter->hw.mac.ops.led_off(&adapter->hw);
1892 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001893 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001894 return 0;
1895}
1896
Auke Kokde5b3072008-04-23 11:09:08 -07001897static int e1000_get_coalesce(struct net_device *netdev,
1898 struct ethtool_coalesce *ec)
1899{
1900 struct e1000_adapter *adapter = netdev_priv(netdev);
1901
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001902 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07001903 ec->rx_coalesce_usecs = adapter->itr_setting;
1904 else
1905 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1906
1907 return 0;
1908}
1909
1910static int e1000_set_coalesce(struct net_device *netdev,
1911 struct ethtool_coalesce *ec)
1912{
1913 struct e1000_adapter *adapter = netdev_priv(netdev);
1914 struct e1000_hw *hw = &adapter->hw;
1915
1916 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001917 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07001918 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1919 (ec->rx_coalesce_usecs == 2))
1920 return -EINVAL;
1921
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001922 if (ec->rx_coalesce_usecs == 4) {
1923 adapter->itr = adapter->itr_setting = 4;
1924 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07001925 adapter->itr = 20000;
1926 adapter->itr_setting = ec->rx_coalesce_usecs;
1927 } else {
1928 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1929 adapter->itr_setting = adapter->itr & ~3;
1930 }
1931
1932 if (adapter->itr_setting != 0)
1933 ew32(ITR, 1000000000 / (adapter->itr * 256));
1934 else
1935 ew32(ITR, 0);
1936
1937 return 0;
1938}
1939
Auke Kokbc7f75f2007-09-17 12:30:59 -07001940static int e1000_nway_reset(struct net_device *netdev)
1941{
1942 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan5962bc22011-01-20 06:58:07 +00001943
1944 if (!netif_running(netdev))
1945 return -EAGAIN;
1946
1947 if (!adapter->hw.mac.autoneg)
1948 return -EINVAL;
1949
1950 e1000e_reinit_locked(adapter);
1951
Auke Kokbc7f75f2007-09-17 12:30:59 -07001952 return 0;
1953}
1954
Auke Kokbc7f75f2007-09-17 12:30:59 -07001955static void e1000_get_ethtool_stats(struct net_device *netdev,
1956 struct ethtool_stats *stats,
1957 u64 *data)
1958{
1959 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001960 struct rtnl_link_stats64 net_stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001961 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001962 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001963
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001964 e1000e_get_stats64(netdev, &net_stats);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001965 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001966 switch (e1000_gstrings_stats[i].type) {
1967 case NETDEV_STATS:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001968 p = (char *) &net_stats +
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001969 e1000_gstrings_stats[i].stat_offset;
1970 break;
1971 case E1000_STATS:
1972 p = (char *) adapter +
1973 e1000_gstrings_stats[i].stat_offset;
1974 break;
Bruce Allan61c75812010-12-09 23:04:25 +00001975 default:
1976 data[i] = 0;
1977 continue;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001978 }
1979
Auke Kokbc7f75f2007-09-17 12:30:59 -07001980 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1981 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1982 }
1983}
1984
1985static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1986 u8 *data)
1987{
1988 u8 *p = data;
1989 int i;
1990
1991 switch (stringset) {
1992 case ETH_SS_TEST:
Bruce Allan5c1bda02011-01-19 04:23:39 +00001993 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001994 break;
1995 case ETH_SS_STATS:
1996 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1997 memcpy(p, e1000_gstrings_stats[i].stat_string,
1998 ETH_GSTRING_LEN);
1999 p += ETH_GSTRING_LEN;
2000 }
2001 break;
2002 }
2003}
2004
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002005static int e1000e_set_flags(struct net_device *netdev, u32 data)
2006{
2007 struct e1000_adapter *adapter = netdev_priv(netdev);
2008 bool need_reset = false;
2009 int rc;
2010
2011 need_reset = (data & ETH_FLAG_RXVLAN) !=
2012 (netdev->features & NETIF_F_HW_VLAN_RX);
2013
2014 rc = ethtool_op_set_flags(netdev, data, ETH_FLAG_RXVLAN |
2015 ETH_FLAG_TXVLAN);
2016
2017 if (rc)
2018 return rc;
2019
2020 if (need_reset) {
2021 if (netif_running(netdev))
2022 e1000e_reinit_locked(adapter);
2023 else
2024 e1000e_reset(adapter);
2025 }
2026
2027 return 0;
2028}
2029
Auke Kokbc7f75f2007-09-17 12:30:59 -07002030static const struct ethtool_ops e1000_ethtool_ops = {
2031 .get_settings = e1000_get_settings,
2032 .set_settings = e1000_set_settings,
2033 .get_drvinfo = e1000_get_drvinfo,
2034 .get_regs_len = e1000_get_regs_len,
2035 .get_regs = e1000_get_regs,
2036 .get_wol = e1000_get_wol,
2037 .set_wol = e1000_set_wol,
2038 .get_msglevel = e1000_get_msglevel,
2039 .set_msglevel = e1000_set_msglevel,
2040 .nway_reset = e1000_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00002041 .get_link = ethtool_op_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002042 .get_eeprom_len = e1000_get_eeprom_len,
2043 .get_eeprom = e1000_get_eeprom,
2044 .set_eeprom = e1000_set_eeprom,
2045 .get_ringparam = e1000_get_ringparam,
2046 .set_ringparam = e1000_set_ringparam,
2047 .get_pauseparam = e1000_get_pauseparam,
2048 .set_pauseparam = e1000_set_pauseparam,
2049 .get_rx_csum = e1000_get_rx_csum,
2050 .set_rx_csum = e1000_set_rx_csum,
2051 .get_tx_csum = e1000_get_tx_csum,
2052 .set_tx_csum = e1000_set_tx_csum,
2053 .get_sg = ethtool_op_get_sg,
2054 .set_sg = ethtool_op_set_sg,
2055 .get_tso = ethtool_op_get_tso,
2056 .set_tso = e1000_set_tso,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002057 .self_test = e1000_diag_test,
2058 .get_strings = e1000_get_strings,
Bruce Allandbf80dc2011-04-16 00:34:40 +00002059 .set_phys_id = e1000_set_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002060 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07002061 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07002062 .get_coalesce = e1000_get_coalesce,
2063 .set_coalesce = e1000_set_coalesce,
Bruce Allane7d906f2009-11-20 23:22:57 +00002064 .get_flags = ethtool_op_get_flags,
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002065 .set_flags = e1000e_set_flags,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002066};
2067
2068void e1000e_set_ethtool_ops(struct net_device *netdev)
2069{
2070 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
2071}