blob: cb1a3623253e8704f6d724a53b8ab8ad896eaa6a [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
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000031#include <linux/interrupt.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070032#include <linux/netdevice.h>
33#include <linux/ethtool.h>
34#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070036#include <linux/delay.h>
37
38#include "e1000.h"
39
Ajit Khapardee0f36a92009-10-13 01:45:09 +000040enum {NETDEV_STATS, E1000_STATS};
41
Auke Kokbc7f75f2007-09-17 12:30:59 -070042struct e1000_stats {
43 char stat_string[ETH_GSTRING_LEN];
Ajit Khapardee0f36a92009-10-13 01:45:09 +000044 int type;
Auke Kokbc7f75f2007-09-17 12:30:59 -070045 int sizeof_stat;
46 int stat_offset;
47};
48
Bruce Allanf0f1a172010-12-11 05:53:32 +000049#define E1000_STAT(str, m) { \
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000050 .stat_string = str, \
51 .type = E1000_STATS, \
52 .sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
53 .stat_offset = offsetof(struct e1000_adapter, m) }
Bruce Allanf0f1a172010-12-11 05:53:32 +000054#define E1000_NETDEV_STAT(str, m) { \
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000055 .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) }
Ajit Khapardee0f36a92009-10-13 01:45:09 +000059
Auke Kokbc7f75f2007-09-17 12:30:59 -070060static const struct e1000_stats e1000_gstrings_stats[] = {
Bruce Allanf0f1a172010-12-11 05:53:32 +000061 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),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000069 E1000_NETDEV_STAT("rx_errors", rx_errors),
70 E1000_NETDEV_STAT("tx_errors", tx_errors),
71 E1000_NETDEV_STAT("tx_dropped", tx_dropped),
Bruce Allanf0f1a172010-12-11 05:53:32 +000072 E1000_STAT("multicast", stats.mprc),
73 E1000_STAT("collisions", stats.colc),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000074 E1000_NETDEV_STAT("rx_length_errors", rx_length_errors),
75 E1000_NETDEV_STAT("rx_over_errors", rx_over_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000076 E1000_STAT("rx_crc_errors", stats.crcerrs),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000077 E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000078 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),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000082 E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
83 E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000084 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),
Auke Kokbc7f75f2007-09-17 12:30:59 -0700110};
111
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200112#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700113#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
114static 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};
Bruce Allanad680762008-03-28 09:15:03 -0700119#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700120
121static 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;
David Decotigny70739492011-04-27 18:32:40 +0000126 u32 speed;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700127
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700128 if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700129
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
David Decotigny70739492011-04-27 18:32:40 +0000164 speed = -1;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000165 ecmd->duplex = -1;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700166
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000167 if (netif_running(netdev)) {
168 if (netif_carrier_ok(netdev)) {
David Decotigny70739492011-04-27 18:32:40 +0000169 speed = adapter->link_speed;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000170 ecmd->duplex = adapter->link_duplex - 1;
171 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700172 } else {
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000173 u32 status = er32(STATUS);
174 if (status & E1000_STATUS_LU) {
175 if (status & E1000_STATUS_SPEED_1000)
David Decotigny70739492011-04-27 18:32:40 +0000176 speed = SPEED_1000;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000177 else if (status & E1000_STATUS_SPEED_100)
David Decotigny70739492011-04-27 18:32:40 +0000178 speed = SPEED_100;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000179 else
David Decotigny70739492011-04-27 18:32:40 +0000180 speed = SPEED_10;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000181
182 if (status & E1000_STATUS_FD)
183 ecmd->duplex = DUPLEX_FULL;
184 else
185 ecmd->duplex = DUPLEX_HALF;
186 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700187 }
188
David Decotigny70739492011-04-27 18:32:40 +0000189 ethtool_cmd_speed_set(ecmd, speed);
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700190 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -0700191 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000192
193 /* MDI-X => 2; MDI =>1; Invalid =>0 */
194 if ((hw->phy.media_type == e1000_media_type_copper) &&
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000195 netif_carrier_ok(netdev))
Chaitanya Lala18760f12009-06-08 14:28:54 +0000196 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
Auke Kokbc7f75f2007-09-17 12:30:59 -0700201 return 0;
202}
203
David Decotigny14ad2512011-04-27 18:32:43 +0000204static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700205{
206 struct e1000_mac_info *mac = &adapter->hw.mac;
207
208 mac->autoneg = 0;
209
David Decotigny14ad2512011-04-27 18:32:43 +0000210 /* 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
Auke Kokbc7f75f2007-09-17 12:30:59 -0700215 /* Fiber NICs only allow 1000 gbps Full duplex */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700216 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
David Decotigny14ad2512011-04-27 18:32:43 +0000217 spd != SPEED_1000 &&
218 dplx != DUPLEX_FULL) {
219 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700220 }
221
David Decotigny14ad2512011-04-27 18:32:43 +0000222 switch (spd + dplx) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700223 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:
David Decotigny14ad2512011-04-27 18:32:43 +0000241 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700242 }
243 return 0;
David Decotigny14ad2512011-04-27 18:32:43 +0000244
245err_inval:
246 e_err("Unsupported Speed/Duplex configuration\n");
247 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700248}
249
250static 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
Bruce Allanad680762008-03-28 09:15:03 -0700256 /*
257 * When SoL/IDER sessions are active, autoneg/speed/duplex
258 * cannot be changed
259 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700260 if (e1000_check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700261 e_err("Cannot change link characteristics when SoL/IDER is "
262 "active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700263 return -EINVAL;
264 }
265
266 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000267 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700268
269 if (ecmd->autoneg == AUTONEG_ENABLE) {
270 hw->mac.autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700271 if (hw->phy.media_type == e1000_media_type_fiber)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700272 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;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700280 if (adapter->fc_autoneg)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800281 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700282 } else {
David Decotigny25db0332011-04-27 18:32:39 +0000283 u32 speed = ethtool_cmd_speed(ecmd);
David Decotigny14ad2512011-04-27 18:32:43 +0000284 if (e1000_set_spd_dplx(adapter, speed, ecmd->duplex)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700285 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
303static 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
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800312 if (hw->fc.current_mode == e1000_fc_rx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700313 pause->rx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800314 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700315 pause->tx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800316 } else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700317 pause->rx_pause = 1;
318 pause->tx_pause = 1;
319 }
320}
321
322static 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))
Bruce Allan1bba4382011-03-19 00:27:20 +0000332 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700333
Auke Kokbc7f75f2007-09-17 12:30:59 -0700334 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800335 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700336 if (netif_running(adapter->netdev)) {
337 e1000e_down(adapter);
338 e1000e_up(adapter);
339 } else {
340 e1000e_reset(adapter);
341 }
342 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800343 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
Bruce Allan945eb312009-10-28 18:28:30 +0000354 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 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700363 }
364
Bruce Allan945eb312009-10-28 18:28:30 +0000365out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700366 clear_bit(__E1000_RESETTING, &adapter->state);
367 return retval;
368}
369
370static u32 e1000_get_rx_csum(struct net_device *netdev)
371{
372 struct e1000_adapter *adapter = netdev_priv(netdev);
Eric Dumazet807540b2010-09-23 05:40:09 +0000373 return adapter->flags & FLAG_RX_CSUM_ENABLED;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700374}
375
376static 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
392static u32 e1000_get_tx_csum(struct net_device *netdev)
393{
Eric Dumazet807540b2010-09-23 05:40:09 +0000394 return (netdev->features & NETIF_F_HW_CSUM) != 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700395}
396
397static 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
407static 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
Auke Kokbc7f75f2007-09-17 12:30:59 -0700419 adapter->flags |= FLAG_TSO_FORCE;
420 return 0;
421}
422
423static u32 e1000_get_msglevel(struct net_device *netdev)
424{
425 struct e1000_adapter *adapter = netdev_priv(netdev);
426 return adapter->msg_enable;
427}
428
429static 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
435static 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
441static 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;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700448
449 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
450
Sergei Shtylyovff938e42011-02-28 11:57:33 -0800451 regs->version = (1 << 24) | (adapter->pdev->revision << 16) |
452 adapter->pdev->device;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700453
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) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700470
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 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700474 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 }
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700489 regs_buff[21] = 0; /* was idle_errors */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700490 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
495static 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
501static 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]);
Bruce Allane2434552008-11-21 17:02:41 -0800533 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700534 break;
535 }
536 }
537
Bruce Allane2434552008-11-21 17:02:41 -0800538 if (ret_val) {
539 /* a read error occurred, throw away the result */
Roel Kluin8528b012009-12-01 15:54:24 +0000540 memset(eeprom_buff, 0xff, sizeof(u16) *
541 (last_word - first_word + 1));
Bruce Allane2434552008-11-21 17:02:41 -0800542 } 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 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700547
548 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
549 kfree(eeprom_buff);
550
551 return ret_val;
552}
553
554static 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
Bruce Allan4a770352008-10-01 17:18:35 -0700573 if (adapter->flags & FLAG_READ_ONLY_NVM)
574 return -EINVAL;
575
Auke Kokbc7f75f2007-09-17 12:30:59 -0700576 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
Bruce Allane2434552008-11-21 17:02:41 -0800598 if (ret_val)
599 goto out;
600
Auke Kokbc7f75f2007-09-17 12:30:59 -0700601 /* 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
Bruce Allane2434552008-11-21 17:02:41 -0800613 if (ret_val)
614 goto out;
615
Bruce Allanad680762008-03-28 09:15:03 -0700616 /*
617 * Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800618 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700619 */
Bruce Allane2434552008-11-21 17:02:41 -0800620 if ((first_word <= NVM_CHECKSUM_REG) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +0000621 (hw->mac.type == e1000_82583) ||
622 (hw->mac.type == e1000_82574) ||
623 (hw->mac.type == e1000_82573))
Bruce Allane2434552008-11-21 17:02:41 -0800624 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700625
Bruce Allane2434552008-11-21 17:02:41 -0800626out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700627 kfree(eeprom_buff);
628 return ret_val;
629}
630
631static 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];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700636
Bruce Allane0dc4f12011-01-06 14:29:50 +0000637 strncpy(drvinfo->driver, e1000e_driver_name,
638 sizeof(drvinfo->driver) - 1);
639 strncpy(drvinfo->version, e1000e_driver_version,
640 sizeof(drvinfo->version) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700641
Bruce Allanad680762008-03-28 09:15:03 -0700642 /*
643 * EEPROM image version # is reported as firmware version # for
644 * PCI-E controllers
645 */
Bruce Allane0dc4f12011-01-06 14:29:50 +0000646 snprintf(firmware_version, sizeof(firmware_version), "%d.%d-%d",
Bruce Allan84527592008-11-21 17:00:22 -0800647 (adapter->eeprom_vers & 0xF000) >> 12,
648 (adapter->eeprom_vers & 0x0FF0) >> 4,
649 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700650
Bruce Allane0dc4f12011-01-06 14:29:50 +0000651 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);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700655 drvinfo->regdump_len = e1000_get_regs_len(netdev);
656 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
657}
658
659static 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
676static 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))
Bruce Allan1bba4382011-03-19 00:27:20 +0000688 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700689
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;
Bruce Allan05b93212011-01-05 07:10:38 +0000697 tx_ring = kmemdup(tx_old, sizeof(struct e1000_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700698 if (!tx_ring)
699 goto err_alloc_tx;
700
Bruce Allan05b93212011-01-05 07:10:38 +0000701 rx_ring = kmemdup(rx_old, sizeof(struct e1000_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700702 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
Bruce Allanad680762008-03-28 09:15:03 -0700725 /*
726 * restore the old in order to free it,
727 * then add in the new
728 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700729 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;
744err_setup_tx:
745 e1000e_free_rx_resources(adapter);
746err_setup_rx:
747 adapter->rx_ring = rx_old;
748 adapter->tx_ring = tx_old;
749 kfree(rx_ring);
750err_alloc_rx:
751 kfree(tx_ring);
752err_alloc_tx:
753 e1000e_up(adapter);
754err_setup:
755 clear_bit(__E1000_RESETTING, &adapter->state);
756 return err;
757}
758
Bruce Allancef8c792008-04-02 13:48:23 -0700759static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
760 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800761{
Bruce Allancef8c792008-04-02 13:48:23 -0700762 u32 pat, val;
Bruce Allan64806412010-12-11 05:53:42 +0000763 static const u32 test[] = {
764 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Bruce Allancef8c792008-04-02 13:48:23 -0700765 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800766 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700767 (test[pat] & write));
768 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
769 if (val != (test[pat] & write & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700770 e_err("pattern test reg %04X failed: got 0x%08X "
771 "expected 0x%08X\n", reg + offset, val,
772 (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800773 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700774 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800775 }
776 }
Bruce Allancef8c792008-04-02 13:48:23 -0700777 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700778}
779
Joe Perches2a887192007-11-13 20:53:51 -0800780static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
781 int reg, u32 mask, u32 write)
782{
Bruce Allancef8c792008-04-02 13:48:23 -0700783 u32 val;
Joe Perches2a887192007-11-13 20:53:51 -0800784 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700785 val = __er32(&adapter->hw, reg);
786 if ((write & mask) != (val & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700787 e_err("set/check reg %04X test failed: got 0x%08X "
788 "expected 0x%08X\n", reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800789 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700790 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800791 }
Bruce Allancef8c792008-04-02 13:48:23 -0700792 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700793}
Bruce Allancef8c792008-04-02 13:48:23 -0700794#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; \
Joe Perches2a887192007-11-13 20:53:51 -0800798 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700799#define REG_PATTERN_TEST(reg, mask, write) \
800 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800801
Bruce Allancef8c792008-04-02 13:48:23 -0700802#define REG_SET_AND_CHECK(reg, mask, write) \
803 do { \
804 if (reg_set_and_check(adapter, data, reg, mask, write)) \
805 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800806 } while (0)
807
Auke Kokbc7f75f2007-09-17 12:30:59 -0700808static 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;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700812 u32 value;
813 u32 before;
814 u32 after;
815 u32 i;
816 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000817 u32 mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700818
Bruce Allanad680762008-03-28 09:15:03 -0700819 /*
820 * The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700821 * 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;
Bruce Allana4f58f52009-06-02 11:29:18 +0000830 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700831 toggle = 0x7FFFF033;
832 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700833 }
834
835 before = er32(STATUS);
836 value = (er32(STATUS) & toggle);
837 ew32(STATUS, toggle);
838 after = er32(STATUS) & toggle;
839 if (value != after) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700840 e_err("failed STATUS register test got: 0x%08X expected: "
841 "0x%08X\n", after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700842 *data = 1;
843 return 1;
844 }
845 /* restore previous status */
846 ew32(STATUS, before);
847
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700848 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700849 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
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700868 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700869 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
870 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
871
Auke Kok86582512007-10-04 15:00:08 -0700872 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
873 REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700874 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700875 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
876 REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
877 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000878 mask = 0x8003FFFF;
879 switch (mac->type) {
880 case e1000_ich10lan:
881 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000882 case e1000_pch2lan:
Bruce Allana4f58f52009-06-02 11:29:18 +0000883 mask |= (1 << 18);
884 break;
885 default:
886 break;
887 }
Auke Kok86582512007-10-04 15:00:08 -0700888 for (i = 0; i < mac->rar_entry_count; i++)
889 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
Bruce Allana4f58f52009-06-02 11:29:18 +0000890 mask, 0xFFFFFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700891
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
899static 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;
Bruce Allane2434552008-11-21 17:02:41 -0800910 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700911 }
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
922static 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
933static 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;
Bruce Allan4662e822008-08-26 18:37:06 -0700941 int ret_val = 0;
942 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700943
944 *data = 0;
945
Bruce Allan4662e822008-08-26 18:37:06 -0700946 /* 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 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700953 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800954 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700955 netdev)) {
956 shared_int = 0;
Joe Perchesa0607fd2009-11-18 23:29:17 -0800957 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700958 netdev->name, netdev)) {
959 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700960 ret_val = -1;
961 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700962 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700963 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700964
965 /* Disable all the interrupts */
966 ew32(IMC, 0xFFFFFFFF);
Bruce Allan1bba4382011-03-19 00:27:20 +0000967 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700968
969 /* Test each interrupt */
970 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700971 /* Interrupt to test */
972 mask = 1 << i;
973
Bruce Allanf4187b52008-08-26 18:36:50 -0700974 if (adapter->flags & FLAG_IS_ICH) {
975 switch (mask) {
976 case E1000_ICR_RXSEQ:
977 continue;
978 case 0x00000100:
979 if (adapter->hw.mac.type == e1000_ich8lan ||
980 adapter->hw.mac.type == e1000_ich9lan)
981 continue;
982 break;
983 default:
984 break;
985 }
986 }
987
Auke Kokbc7f75f2007-09-17 12:30:59 -0700988 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700989 /*
990 * Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700991 * the cause register and then force the same
992 * interrupt and see if one gets posted. If
993 * an interrupt was posted to the bus, the
994 * test failed.
995 */
996 adapter->test_icr = 0;
997 ew32(IMC, mask);
998 ew32(ICS, mask);
Bruce Allan1bba4382011-03-19 00:27:20 +0000999 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001000
1001 if (adapter->test_icr & mask) {
1002 *data = 3;
1003 break;
1004 }
1005 }
1006
Bruce Allanad680762008-03-28 09:15:03 -07001007 /*
1008 * Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001009 * the cause register and then force the same
1010 * interrupt and see if one gets posted. If
1011 * an interrupt was not posted to the bus, the
1012 * test failed.
1013 */
1014 adapter->test_icr = 0;
1015 ew32(IMS, mask);
1016 ew32(ICS, mask);
Bruce Allan1bba4382011-03-19 00:27:20 +00001017 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001018
1019 if (!(adapter->test_icr & mask)) {
1020 *data = 4;
1021 break;
1022 }
1023
1024 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -07001025 /*
1026 * Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001027 * the cause register and then force the other
1028 * interrupts and see if any get posted. If
1029 * an interrupt was posted to the bus, the
1030 * test failed.
1031 */
1032 adapter->test_icr = 0;
1033 ew32(IMC, ~mask & 0x00007FFF);
1034 ew32(ICS, ~mask & 0x00007FFF);
Bruce Allan1bba4382011-03-19 00:27:20 +00001035 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001036
1037 if (adapter->test_icr) {
1038 *data = 5;
1039 break;
1040 }
1041 }
1042 }
1043
1044 /* Disable all the interrupts */
1045 ew32(IMC, 0xFFFFFFFF);
Bruce Allan1bba4382011-03-19 00:27:20 +00001046 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001047
1048 /* Unhook test interrupt handler */
1049 free_irq(irq, netdev);
1050
Bruce Allan4662e822008-08-26 18:37:06 -07001051out:
1052 if (int_mode == E1000E_INT_MODE_MSIX) {
1053 e1000e_reset_interrupt_capability(adapter);
1054 adapter->int_mode = int_mode;
1055 e1000e_set_interrupt_capability(adapter);
1056 }
1057
1058 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001059}
1060
1061static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1062{
1063 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1064 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1065 struct pci_dev *pdev = adapter->pdev;
1066 int i;
1067
1068 if (tx_ring->desc && tx_ring->buffer_info) {
1069 for (i = 0; i < tx_ring->count; i++) {
1070 if (tx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001071 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001072 tx_ring->buffer_info[i].dma,
1073 tx_ring->buffer_info[i].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001074 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001075 if (tx_ring->buffer_info[i].skb)
1076 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1077 }
1078 }
1079
1080 if (rx_ring->desc && rx_ring->buffer_info) {
1081 for (i = 0; i < rx_ring->count; i++) {
1082 if (rx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001083 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001084 rx_ring->buffer_info[i].dma,
Nick Nunley0be3f552010-04-27 13:09:05 +00001085 2048, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001086 if (rx_ring->buffer_info[i].skb)
1087 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1088 }
1089 }
1090
1091 if (tx_ring->desc) {
1092 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1093 tx_ring->dma);
1094 tx_ring->desc = NULL;
1095 }
1096 if (rx_ring->desc) {
1097 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1098 rx_ring->dma);
1099 rx_ring->desc = NULL;
1100 }
1101
1102 kfree(tx_ring->buffer_info);
1103 tx_ring->buffer_info = NULL;
1104 kfree(rx_ring->buffer_info);
1105 rx_ring->buffer_info = NULL;
1106}
1107
1108static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1109{
1110 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1111 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1112 struct pci_dev *pdev = adapter->pdev;
1113 struct e1000_hw *hw = &adapter->hw;
1114 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001115 int i;
1116 int ret_val;
1117
1118 /* Setup Tx descriptor ring and Tx buffers */
1119
1120 if (!tx_ring->count)
1121 tx_ring->count = E1000_DEFAULT_TXD;
1122
Bruce Allancef8c792008-04-02 13:48:23 -07001123 tx_ring->buffer_info = kcalloc(tx_ring->count,
1124 sizeof(struct e1000_buffer),
1125 GFP_KERNEL);
1126 if (!(tx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001127 ret_val = 1;
1128 goto err_nomem;
1129 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001130
1131 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1132 tx_ring->size = ALIGN(tx_ring->size, 4096);
1133 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1134 &tx_ring->dma, GFP_KERNEL);
1135 if (!tx_ring->desc) {
1136 ret_val = 2;
1137 goto err_nomem;
1138 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001139 tx_ring->next_to_use = 0;
1140 tx_ring->next_to_clean = 0;
1141
Bruce Allancef8c792008-04-02 13:48:23 -07001142 ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001143 ew32(TDBAH, ((u64) tx_ring->dma >> 32));
Bruce Allancef8c792008-04-02 13:48:23 -07001144 ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001145 ew32(TDH, 0);
1146 ew32(TDT, 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001147 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1148 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1149 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001150
1151 for (i = 0; i < tx_ring->count; i++) {
1152 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1153 struct sk_buff *skb;
1154 unsigned int skb_size = 1024;
1155
1156 skb = alloc_skb(skb_size, GFP_KERNEL);
1157 if (!skb) {
1158 ret_val = 3;
1159 goto err_nomem;
1160 }
1161 skb_put(skb, skb_size);
1162 tx_ring->buffer_info[i].skb = skb;
1163 tx_ring->buffer_info[i].length = skb->len;
1164 tx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001165 dma_map_single(&pdev->dev, skb->data, skb->len,
1166 DMA_TO_DEVICE);
1167 if (dma_mapping_error(&pdev->dev,
1168 tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001169 ret_val = 4;
1170 goto err_nomem;
1171 }
Bruce Allancef8c792008-04-02 13:48:23 -07001172 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001173 tx_desc->lower.data = cpu_to_le32(skb->len);
1174 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1175 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001176 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001177 tx_desc->upper.data = 0;
1178 }
1179
1180 /* Setup Rx descriptor ring and Rx buffers */
1181
1182 if (!rx_ring->count)
1183 rx_ring->count = E1000_DEFAULT_RXD;
1184
Bruce Allancef8c792008-04-02 13:48:23 -07001185 rx_ring->buffer_info = kcalloc(rx_ring->count,
1186 sizeof(struct e1000_buffer),
1187 GFP_KERNEL);
1188 if (!(rx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001189 ret_val = 5;
1190 goto err_nomem;
1191 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001192
1193 rx_ring->size = rx_ring->count * sizeof(struct e1000_rx_desc);
1194 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1195 &rx_ring->dma, GFP_KERNEL);
1196 if (!rx_ring->desc) {
1197 ret_val = 6;
1198 goto err_nomem;
1199 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001200 rx_ring->next_to_use = 0;
1201 rx_ring->next_to_clean = 0;
1202
1203 rctl = er32(RCTL);
1204 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1205 ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
1206 ew32(RDBAH, ((u64) rx_ring->dma >> 32));
1207 ew32(RDLEN, rx_ring->size);
1208 ew32(RDH, 0);
1209 ew32(RDT, 0);
1210 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allancef8c792008-04-02 13:48:23 -07001211 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1212 E1000_RCTL_SBP | E1000_RCTL_SECRC |
Auke Kokbc7f75f2007-09-17 12:30:59 -07001213 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1214 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1215 ew32(RCTL, rctl);
1216
1217 for (i = 0; i < rx_ring->count; i++) {
1218 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
1219 struct sk_buff *skb;
1220
1221 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1222 if (!skb) {
1223 ret_val = 7;
1224 goto err_nomem;
1225 }
1226 skb_reserve(skb, NET_IP_ALIGN);
1227 rx_ring->buffer_info[i].skb = skb;
1228 rx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001229 dma_map_single(&pdev->dev, skb->data, 2048,
1230 DMA_FROM_DEVICE);
1231 if (dma_mapping_error(&pdev->dev,
1232 rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001233 ret_val = 8;
1234 goto err_nomem;
1235 }
1236 rx_desc->buffer_addr =
1237 cpu_to_le64(rx_ring->buffer_info[i].dma);
1238 memset(skb->data, 0x00, skb->len);
1239 }
1240
1241 return 0;
1242
1243err_nomem:
1244 e1000_free_desc_rings(adapter);
1245 return ret_val;
1246}
1247
1248static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1249{
1250 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1251 e1e_wphy(&adapter->hw, 29, 0x001F);
1252 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1253 e1e_wphy(&adapter->hw, 29, 0x001A);
1254 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1255}
1256
1257static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1258{
1259 struct e1000_hw *hw = &adapter->hw;
1260 u32 ctrl_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001261 u16 phy_reg = 0;
Bruce Allancbd006c2010-11-24 06:01:30 +00001262 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001263
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001264 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001265
Bruce Allan3af50482010-06-16 13:25:55 +00001266 if (hw->phy.type == e1000_phy_ife) {
1267 /* force 100, set loopback */
1268 e1e_wphy(hw, PHY_CONTROL, 0x6100);
Bruce Allanbb436b22009-11-20 23:24:11 +00001269
Bruce Allan3af50482010-06-16 13:25:55 +00001270 /* Now set up the MAC to the same speed/duplex as the PHY. */
1271 ctrl_reg = er32(CTRL);
1272 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1273 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1274 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1275 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1276 E1000_CTRL_FD); /* Force Duplex to FULL */
1277
1278 ew32(CTRL, ctrl_reg);
1279 udelay(500);
1280
1281 return 0;
1282 }
1283
1284 /* Specific PHY configuration for loopback */
1285 switch (hw->phy.type) {
1286 case e1000_phy_m88:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001287 /* Auto-MDI/MDIX Off */
1288 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1289 /* reset to update Auto-MDI/MDIX */
1290 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1291 /* autoneg off */
1292 e1e_wphy(hw, PHY_CONTROL, 0x8140);
Bruce Allan3af50482010-06-16 13:25:55 +00001293 break;
1294 case e1000_phy_gg82563:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001295 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
Bruce Allancef8c792008-04-02 13:48:23 -07001296 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001297 case e1000_phy_bm:
1298 /* Set Default MAC Interface speed to 1GB */
1299 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1300 phy_reg &= ~0x0007;
1301 phy_reg |= 0x006;
1302 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1303 /* Assert SW reset for above settings to take effect */
1304 e1000e_commit_phy(hw);
1305 mdelay(1);
1306 /* Force Full Duplex */
1307 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1308 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1309 /* Set Link Up (in force link) */
1310 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1311 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1312 /* Force Link */
1313 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1314 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1315 /* Set Early Link Enable */
1316 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1317 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
Bruce Allan3af50482010-06-16 13:25:55 +00001318 break;
1319 case e1000_phy_82577:
1320 case e1000_phy_82578:
1321 /* Workaround: K1 must be disabled for stable 1Gbps operation */
Bruce Allancbd006c2010-11-24 06:01:30 +00001322 ret_val = hw->phy.ops.acquire(hw);
1323 if (ret_val) {
1324 e_err("Cannot setup 1Gbps loopback.\n");
1325 return ret_val;
1326 }
Bruce Allan3af50482010-06-16 13:25:55 +00001327 e1000_configure_k1_ich8lan(hw, false);
Bruce Allancbd006c2010-11-24 06:01:30 +00001328 hw->phy.ops.release(hw);
Bruce Allan3af50482010-06-16 13:25:55 +00001329 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001330 case e1000_phy_82579:
1331 /* Disable PHY energy detect power down */
1332 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1333 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
1334 /* Disable full chip energy detect */
1335 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1336 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1337 /* Enable loopback on the PHY */
1338#define I82577_PHY_LBK_CTRL 19
1339 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1340 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001341 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001342 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001343 }
1344
Bruce Allan3af50482010-06-16 13:25:55 +00001345 /* force 1000, set loopback */
1346 e1e_wphy(hw, PHY_CONTROL, 0x4140);
1347 mdelay(250);
1348
1349 /* Now set up the MAC to the same speed/duplex as the PHY. */
1350 ctrl_reg = er32(CTRL);
1351 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1352 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1353 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1354 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1355 E1000_CTRL_FD); /* Force Duplex to FULL */
1356
1357 if (adapter->flags & FLAG_IS_ICH)
1358 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1359
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001360 if (hw->phy.media_type == e1000_media_type_copper &&
1361 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001362 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1363 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001364 /*
1365 * Set the ILOS bit on the fiber Nic if half duplex link is
1366 * detected.
1367 */
Bruce Allan90da0662011-01-06 07:02:53 +00001368 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001369 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1370 }
1371
1372 ew32(CTRL, ctrl_reg);
1373
Bruce Allanad680762008-03-28 09:15:03 -07001374 /*
1375 * Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001376 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1377 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001378 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001379 e1000_phy_disable_receiver(adapter);
1380
1381 udelay(500);
1382
1383 return 0;
1384}
1385
1386static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1387{
1388 struct e1000_hw *hw = &adapter->hw;
1389 u32 ctrl = er32(CTRL);
1390 int link = 0;
1391
1392 /* special requirements for 82571/82572 fiber adapters */
1393
Bruce Allanad680762008-03-28 09:15:03 -07001394 /*
1395 * jump through hoops to make sure link is up because serdes
1396 * link is hardwired up
1397 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001398 ctrl |= E1000_CTRL_SLU;
1399 ew32(CTRL, ctrl);
1400
1401 /* disable autoneg */
1402 ctrl = er32(TXCW);
1403 ctrl &= ~(1 << 31);
1404 ew32(TXCW, ctrl);
1405
1406 link = (er32(STATUS) & E1000_STATUS_LU);
1407
1408 if (!link) {
1409 /* set invert loss of signal */
1410 ctrl = er32(CTRL);
1411 ctrl |= E1000_CTRL_ILOS;
1412 ew32(CTRL, ctrl);
1413 }
1414
Bruce Allanad680762008-03-28 09:15:03 -07001415 /*
1416 * special write to serdes control register to enable SerDes analog
1417 * loopback
1418 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001419#define E1000_SERDES_LB_ON 0x410
1420 ew32(SCTL, E1000_SERDES_LB_ON);
Bruce Allan1bba4382011-03-19 00:27:20 +00001421 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001422
1423 return 0;
1424}
1425
1426/* only call this for fiber/serdes connections to es2lan */
1427static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1428{
1429 struct e1000_hw *hw = &adapter->hw;
1430 u32 ctrlext = er32(CTRL_EXT);
1431 u32 ctrl = er32(CTRL);
1432
Bruce Allanad680762008-03-28 09:15:03 -07001433 /*
1434 * save CTRL_EXT to restore later, reuse an empty variable (unused
1435 * on mac_type 80003es2lan)
1436 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001437 adapter->tx_fifo_head = ctrlext;
1438
1439 /* clear the serdes mode bits, putting the device into mac loopback */
1440 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1441 ew32(CTRL_EXT, ctrlext);
1442
1443 /* force speed to 1000/FD, link up */
1444 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1445 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1446 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1447 ew32(CTRL, ctrl);
1448
1449 /* set mac loopback */
1450 ctrl = er32(RCTL);
1451 ctrl |= E1000_RCTL_LBM_MAC;
1452 ew32(RCTL, ctrl);
1453
1454 /* set testing mode parameters (no need to reset later) */
1455#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1456#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1457 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001458 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001459
1460 return 0;
1461}
1462
1463static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1464{
1465 struct e1000_hw *hw = &adapter->hw;
1466 u32 rctl;
1467
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001468 if (hw->phy.media_type == e1000_media_type_fiber ||
1469 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001470 switch (hw->mac.type) {
1471 case e1000_80003es2lan:
1472 return e1000_set_es2lan_mac_loopback(adapter);
1473 break;
1474 case e1000_82571:
1475 case e1000_82572:
1476 return e1000_set_82571_fiber_loopback(adapter);
1477 break;
1478 default:
1479 rctl = er32(RCTL);
1480 rctl |= E1000_RCTL_LBM_TCVR;
1481 ew32(RCTL, rctl);
1482 return 0;
1483 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001484 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001485 return e1000_integrated_phy_loopback(adapter);
1486 }
1487
1488 return 7;
1489}
1490
1491static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1492{
1493 struct e1000_hw *hw = &adapter->hw;
1494 u32 rctl;
1495 u16 phy_reg;
1496
1497 rctl = er32(RCTL);
1498 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1499 ew32(RCTL, rctl);
1500
1501 switch (hw->mac.type) {
1502 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001503 if (hw->phy.media_type == e1000_media_type_fiber ||
1504 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001505 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001506 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001507 adapter->tx_fifo_head = 0;
1508 }
1509 /* fall through */
1510 case e1000_82571:
1511 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001512 if (hw->phy.media_type == e1000_media_type_fiber ||
1513 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001514#define E1000_SERDES_LB_OFF 0x400
1515 ew32(SCTL, E1000_SERDES_LB_OFF);
Bruce Allan1bba4382011-03-19 00:27:20 +00001516 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001517 break;
1518 }
1519 /* Fall Through */
1520 default:
1521 hw->mac.autoneg = 1;
1522 if (hw->phy.type == e1000_phy_gg82563)
1523 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1524 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1525 if (phy_reg & MII_CR_LOOPBACK) {
1526 phy_reg &= ~MII_CR_LOOPBACK;
1527 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1528 e1000e_commit_phy(hw);
1529 }
1530 break;
1531 }
1532}
1533
1534static void e1000_create_lbtest_frame(struct sk_buff *skb,
1535 unsigned int frame_size)
1536{
1537 memset(skb->data, 0xFF, frame_size);
1538 frame_size &= ~1;
1539 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1540 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1541 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1542}
1543
1544static int e1000_check_lbtest_frame(struct sk_buff *skb,
1545 unsigned int frame_size)
1546{
1547 frame_size &= ~1;
1548 if (*(skb->data + 3) == 0xFF)
1549 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1550 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1551 return 0;
1552 return 13;
1553}
1554
1555static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1556{
1557 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1558 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1559 struct pci_dev *pdev = adapter->pdev;
1560 struct e1000_hw *hw = &adapter->hw;
1561 int i, j, k, l;
1562 int lc;
1563 int good_cnt;
1564 int ret_val = 0;
1565 unsigned long time;
1566
1567 ew32(RDT, rx_ring->count - 1);
1568
Bruce Allanad680762008-03-28 09:15:03 -07001569 /*
1570 * Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001571 * The idea is to wrap the largest ring a number of times using 64
1572 * send/receive pairs during each loop
1573 */
1574
1575 if (rx_ring->count <= tx_ring->count)
1576 lc = ((tx_ring->count / 64) * 2) + 1;
1577 else
1578 lc = ((rx_ring->count / 64) * 2) + 1;
1579
1580 k = 0;
1581 l = 0;
1582 for (j = 0; j <= lc; j++) { /* loop count loop */
1583 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001584 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1585 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001586 dma_sync_single_for_device(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001587 tx_ring->buffer_info[k].dma,
1588 tx_ring->buffer_info[k].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001589 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001590 k++;
1591 if (k == tx_ring->count)
1592 k = 0;
1593 }
1594 ew32(TDT, k);
1595 msleep(200);
1596 time = jiffies; /* set the start time for the receive */
1597 good_cnt = 0;
1598 do { /* receive the sent packets */
Nick Nunley0be3f552010-04-27 13:09:05 +00001599 dma_sync_single_for_cpu(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001600 rx_ring->buffer_info[l].dma, 2048,
Nick Nunley0be3f552010-04-27 13:09:05 +00001601 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001602
1603 ret_val = e1000_check_lbtest_frame(
1604 rx_ring->buffer_info[l].skb, 1024);
1605 if (!ret_val)
1606 good_cnt++;
1607 l++;
1608 if (l == rx_ring->count)
1609 l = 0;
Bruce Allanad680762008-03-28 09:15:03 -07001610 /*
1611 * time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001612 * enough time to complete the receives, if it's
1613 * exceeded, break and error off
1614 */
1615 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1616 if (good_cnt != 64) {
1617 ret_val = 13; /* ret_val is the same as mis-compare */
1618 break;
1619 }
Bruce Allancef8c792008-04-02 13:48:23 -07001620 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001621 ret_val = 14; /* error code for time out error */
1622 break;
1623 }
1624 } /* end loop count loop */
1625 return ret_val;
1626}
1627
1628static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1629{
Bruce Allanad680762008-03-28 09:15:03 -07001630 /*
1631 * PHY loopback cannot be performed if SoL/IDER
1632 * sessions are active
1633 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001634 if (e1000_check_reset_block(&adapter->hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001635 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001636 *data = 0;
1637 goto out;
1638 }
1639
1640 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001641 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001642 goto out;
1643
1644 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001645 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001646 goto err_loopback;
1647
1648 *data = e1000_run_loopback_test(adapter);
1649 e1000_loopback_cleanup(adapter);
1650
1651err_loopback:
1652 e1000_free_desc_rings(adapter);
1653out:
1654 return *data;
1655}
1656
1657static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1658{
1659 struct e1000_hw *hw = &adapter->hw;
1660
1661 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001662 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001663 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001664 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001665
Bruce Allanad680762008-03-28 09:15:03 -07001666 /*
1667 * On some blade server designs, link establishment
1668 * could take as long as 2-3 minutes
1669 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001670 do {
1671 hw->mac.ops.check_for_link(hw);
1672 if (hw->mac.serdes_has_link)
1673 return *data;
1674 msleep(20);
1675 } while (i++ < 3750);
1676
1677 *data = 1;
1678 } else {
1679 hw->mac.ops.check_for_link(hw);
1680 if (hw->mac.autoneg)
Bruce Allan5661aeb2011-02-25 06:36:25 +00001681 /*
1682 * On some Phy/switch combinations, link establishment
1683 * can take a few seconds more than expected.
1684 */
1685 msleep(5000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001686
Bruce Allan5661aeb2011-02-25 06:36:25 +00001687 if (!(er32(STATUS) & E1000_STATUS_LU))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001688 *data = 1;
1689 }
1690 return *data;
1691}
1692
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001693static int e1000e_get_sset_count(struct net_device *netdev, int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001694{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001695 switch (sset) {
1696 case ETH_SS_TEST:
1697 return E1000_TEST_LEN;
1698 case ETH_SS_STATS:
1699 return E1000_STATS_LEN;
1700 default:
1701 return -EOPNOTSUPP;
1702 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001703}
1704
1705static void e1000_diag_test(struct net_device *netdev,
1706 struct ethtool_test *eth_test, u64 *data)
1707{
1708 struct e1000_adapter *adapter = netdev_priv(netdev);
1709 u16 autoneg_advertised;
1710 u8 forced_speed_duplex;
1711 u8 autoneg;
1712 bool if_running = netif_running(netdev);
1713
1714 set_bit(__E1000_TESTING, &adapter->state);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001715
1716 if (!if_running) {
1717 /* Get control of and reset hardware */
1718 if (adapter->flags & FLAG_HAS_AMT)
1719 e1000e_get_hw_control(adapter);
1720
1721 e1000e_power_up_phy(adapter);
1722
1723 adapter->hw.phy.autoneg_wait_to_complete = 1;
1724 e1000e_reset(adapter);
1725 adapter->hw.phy.autoneg_wait_to_complete = 0;
1726 }
1727
Auke Kokbc7f75f2007-09-17 12:30:59 -07001728 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1729 /* Offline tests */
1730
1731 /* save speed, duplex, autoneg settings */
1732 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1733 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1734 autoneg = adapter->hw.mac.autoneg;
1735
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001736 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001737
Auke Kokbc7f75f2007-09-17 12:30:59 -07001738 if (if_running)
1739 /* indicate we're in test mode */
1740 dev_close(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001741
1742 if (e1000_reg_test(adapter, &data[0]))
1743 eth_test->flags |= ETH_TEST_FL_FAILED;
1744
1745 e1000e_reset(adapter);
1746 if (e1000_eeprom_test(adapter, &data[1]))
1747 eth_test->flags |= ETH_TEST_FL_FAILED;
1748
1749 e1000e_reset(adapter);
1750 if (e1000_intr_test(adapter, &data[2]))
1751 eth_test->flags |= ETH_TEST_FL_FAILED;
1752
1753 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001754 if (e1000_loopback_test(adapter, &data[3]))
1755 eth_test->flags |= ETH_TEST_FL_FAILED;
1756
Auke Kokbc7f75f2007-09-17 12:30:59 -07001757 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001758 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001759 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001760 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001761
Carolyn Wybornyc6ce3852010-10-15 17:35:31 +00001762 if (e1000_link_test(adapter, &data[4]))
1763 eth_test->flags |= ETH_TEST_FL_FAILED;
1764
1765 /* restore speed, duplex, autoneg settings */
1766 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1767 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1768 adapter->hw.mac.autoneg = autoneg;
1769 e1000e_reset(adapter);
1770
Auke Kokbc7f75f2007-09-17 12:30:59 -07001771 clear_bit(__E1000_TESTING, &adapter->state);
1772 if (if_running)
1773 dev_open(netdev);
1774 } else {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001775 /* Online tests */
Bruce Allan11b08be2010-05-10 14:59:31 +00001776
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001777 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001778
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001779 /* register, eeprom, intr and loopback tests not run online */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001780 data[0] = 0;
1781 data[1] = 0;
1782 data[2] = 0;
1783 data[3] = 0;
1784
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001785 if (e1000_link_test(adapter, &data[4]))
1786 eth_test->flags |= ETH_TEST_FL_FAILED;
Bruce Allan11b08be2010-05-10 14:59:31 +00001787
Auke Kokbc7f75f2007-09-17 12:30:59 -07001788 clear_bit(__E1000_TESTING, &adapter->state);
1789 }
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001790
1791 if (!if_running) {
1792 e1000e_reset(adapter);
1793
1794 if (adapter->flags & FLAG_HAS_AMT)
1795 e1000e_release_hw_control(adapter);
1796 }
1797
Auke Kokbc7f75f2007-09-17 12:30:59 -07001798 msleep_interruptible(4 * 1000);
1799}
1800
1801static void e1000_get_wol(struct net_device *netdev,
1802 struct ethtool_wolinfo *wol)
1803{
1804 struct e1000_adapter *adapter = netdev_priv(netdev);
1805
1806 wol->supported = 0;
1807 wol->wolopts = 0;
1808
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001809 if (!(adapter->flags & FLAG_HAS_WOL) ||
1810 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001811 return;
1812
1813 wol->supported = WAKE_UCAST | WAKE_MCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001814 WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001815
1816 /* apply any specific unsupported masks here */
1817 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1818 wol->supported &= ~WAKE_UCAST;
1819
1820 if (adapter->wol & E1000_WUFC_EX)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001821 e_err("Interface does not support directed (unicast) "
1822 "frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001823 }
1824
1825 if (adapter->wol & E1000_WUFC_EX)
1826 wol->wolopts |= WAKE_UCAST;
1827 if (adapter->wol & E1000_WUFC_MC)
1828 wol->wolopts |= WAKE_MCAST;
1829 if (adapter->wol & E1000_WUFC_BC)
1830 wol->wolopts |= WAKE_BCAST;
1831 if (adapter->wol & E1000_WUFC_MAG)
1832 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001833 if (adapter->wol & E1000_WUFC_LNKC)
1834 wol->wolopts |= WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001835}
1836
Bruce Allan4a29e152011-03-04 09:07:01 +00001837static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001838{
1839 struct e1000_adapter *adapter = netdev_priv(netdev);
1840
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001841 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001842 !device_can_wakeup(&adapter->pdev->dev) ||
1843 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001844 WAKE_MAGIC | WAKE_PHY)))
Bruce Allan1fbfca32009-11-20 23:22:01 +00001845 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001846
1847 /* these settings will always override what we currently have */
1848 adapter->wol = 0;
1849
1850 if (wol->wolopts & WAKE_UCAST)
1851 adapter->wol |= E1000_WUFC_EX;
1852 if (wol->wolopts & WAKE_MCAST)
1853 adapter->wol |= E1000_WUFC_MC;
1854 if (wol->wolopts & WAKE_BCAST)
1855 adapter->wol |= E1000_WUFC_BC;
1856 if (wol->wolopts & WAKE_MAGIC)
1857 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001858 if (wol->wolopts & WAKE_PHY)
1859 adapter->wol |= E1000_WUFC_LNKC;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001860
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001861 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1862
Auke Kokbc7f75f2007-09-17 12:30:59 -07001863 return 0;
1864}
1865
Bruce Allandbf80dc2011-04-16 00:34:40 +00001866static int e1000_set_phys_id(struct net_device *netdev,
1867 enum ethtool_phys_id_state state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001868{
1869 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001870 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001871
Bruce Allandbf80dc2011-04-16 00:34:40 +00001872 switch (state) {
1873 case ETHTOOL_ID_ACTIVE:
1874 if (!hw->mac.ops.blink_led)
1875 return 2; /* cycle on/off twice per second */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001876
Bruce Allandbf80dc2011-04-16 00:34:40 +00001877 hw->mac.ops.blink_led(hw);
1878 break;
1879
1880 case ETHTOOL_ID_INACTIVE:
Bruce Allan4662e822008-08-26 18:37:06 -07001881 if (hw->phy.type == e1000_phy_ife)
1882 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001883 hw->mac.ops.led_off(hw);
1884 hw->mac.ops.cleanup_led(hw);
1885 break;
1886
1887 case ETHTOOL_ID_ON:
1888 adapter->hw.mac.ops.led_on(&adapter->hw);
1889 break;
1890
1891 case ETHTOOL_ID_OFF:
1892 adapter->hw.mac.ops.led_off(&adapter->hw);
1893 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001894 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001895 return 0;
1896}
1897
Auke Kokde5b3072008-04-23 11:09:08 -07001898static int e1000_get_coalesce(struct net_device *netdev,
1899 struct ethtool_coalesce *ec)
1900{
1901 struct e1000_adapter *adapter = netdev_priv(netdev);
1902
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001903 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07001904 ec->rx_coalesce_usecs = adapter->itr_setting;
1905 else
1906 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1907
1908 return 0;
1909}
1910
1911static int e1000_set_coalesce(struct net_device *netdev,
1912 struct ethtool_coalesce *ec)
1913{
1914 struct e1000_adapter *adapter = netdev_priv(netdev);
1915 struct e1000_hw *hw = &adapter->hw;
1916
1917 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001918 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07001919 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1920 (ec->rx_coalesce_usecs == 2))
1921 return -EINVAL;
1922
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001923 if (ec->rx_coalesce_usecs == 4) {
1924 adapter->itr = adapter->itr_setting = 4;
1925 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07001926 adapter->itr = 20000;
1927 adapter->itr_setting = ec->rx_coalesce_usecs;
1928 } else {
1929 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1930 adapter->itr_setting = adapter->itr & ~3;
1931 }
1932
1933 if (adapter->itr_setting != 0)
1934 ew32(ITR, 1000000000 / (adapter->itr * 256));
1935 else
1936 ew32(ITR, 0);
1937
1938 return 0;
1939}
1940
Auke Kokbc7f75f2007-09-17 12:30:59 -07001941static int e1000_nway_reset(struct net_device *netdev)
1942{
1943 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan5962bc22011-01-20 06:58:07 +00001944
1945 if (!netif_running(netdev))
1946 return -EAGAIN;
1947
1948 if (!adapter->hw.mac.autoneg)
1949 return -EINVAL;
1950
1951 e1000e_reinit_locked(adapter);
1952
Auke Kokbc7f75f2007-09-17 12:30:59 -07001953 return 0;
1954}
1955
Auke Kokbc7f75f2007-09-17 12:30:59 -07001956static void e1000_get_ethtool_stats(struct net_device *netdev,
1957 struct ethtool_stats *stats,
1958 u64 *data)
1959{
1960 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001961 struct rtnl_link_stats64 net_stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001962 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001963 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001964
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001965 e1000e_get_stats64(netdev, &net_stats);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001966 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001967 switch (e1000_gstrings_stats[i].type) {
1968 case NETDEV_STATS:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001969 p = (char *) &net_stats +
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001970 e1000_gstrings_stats[i].stat_offset;
1971 break;
1972 case E1000_STATS:
1973 p = (char *) adapter +
1974 e1000_gstrings_stats[i].stat_offset;
1975 break;
Bruce Allan61c75812010-12-09 23:04:25 +00001976 default:
1977 data[i] = 0;
1978 continue;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001979 }
1980
Auke Kokbc7f75f2007-09-17 12:30:59 -07001981 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1982 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1983 }
1984}
1985
1986static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1987 u8 *data)
1988{
1989 u8 *p = data;
1990 int i;
1991
1992 switch (stringset) {
1993 case ETH_SS_TEST:
Bruce Allan5c1bda02011-01-19 04:23:39 +00001994 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001995 break;
1996 case ETH_SS_STATS:
1997 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1998 memcpy(p, e1000_gstrings_stats[i].stat_string,
1999 ETH_GSTRING_LEN);
2000 p += ETH_GSTRING_LEN;
2001 }
2002 break;
2003 }
2004}
2005
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002006static int e1000e_set_flags(struct net_device *netdev, u32 data)
2007{
2008 struct e1000_adapter *adapter = netdev_priv(netdev);
2009 bool need_reset = false;
2010 int rc;
2011
2012 need_reset = (data & ETH_FLAG_RXVLAN) !=
2013 (netdev->features & NETIF_F_HW_VLAN_RX);
2014
2015 rc = ethtool_op_set_flags(netdev, data, ETH_FLAG_RXVLAN |
2016 ETH_FLAG_TXVLAN);
2017
2018 if (rc)
2019 return rc;
2020
2021 if (need_reset) {
2022 if (netif_running(netdev))
2023 e1000e_reinit_locked(adapter);
2024 else
2025 e1000e_reset(adapter);
2026 }
2027
2028 return 0;
2029}
2030
Auke Kokbc7f75f2007-09-17 12:30:59 -07002031static const struct ethtool_ops e1000_ethtool_ops = {
2032 .get_settings = e1000_get_settings,
2033 .set_settings = e1000_set_settings,
2034 .get_drvinfo = e1000_get_drvinfo,
2035 .get_regs_len = e1000_get_regs_len,
2036 .get_regs = e1000_get_regs,
2037 .get_wol = e1000_get_wol,
2038 .set_wol = e1000_set_wol,
2039 .get_msglevel = e1000_get_msglevel,
2040 .set_msglevel = e1000_set_msglevel,
2041 .nway_reset = e1000_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00002042 .get_link = ethtool_op_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002043 .get_eeprom_len = e1000_get_eeprom_len,
2044 .get_eeprom = e1000_get_eeprom,
2045 .set_eeprom = e1000_set_eeprom,
2046 .get_ringparam = e1000_get_ringparam,
2047 .set_ringparam = e1000_set_ringparam,
2048 .get_pauseparam = e1000_get_pauseparam,
2049 .set_pauseparam = e1000_set_pauseparam,
2050 .get_rx_csum = e1000_get_rx_csum,
2051 .set_rx_csum = e1000_set_rx_csum,
2052 .get_tx_csum = e1000_get_tx_csum,
2053 .set_tx_csum = e1000_set_tx_csum,
2054 .get_sg = ethtool_op_get_sg,
2055 .set_sg = ethtool_op_set_sg,
2056 .get_tso = ethtool_op_get_tso,
2057 .set_tso = e1000_set_tso,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002058 .self_test = e1000_diag_test,
2059 .get_strings = e1000_get_strings,
Bruce Allandbf80dc2011-04-16 00:34:40 +00002060 .set_phys_id = e1000_set_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002061 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07002062 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07002063 .get_coalesce = e1000_get_coalesce,
2064 .set_coalesce = e1000_set_coalesce,
Bruce Allane7d906f2009-11-20 23:22:57 +00002065 .get_flags = ethtool_op_get_flags,
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002066 .set_flags = e1000e_set_flags,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002067};
2068
2069void e1000e_set_ethtool_ops(struct net_device *netdev)
2070{
2071 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
2072}