blob: d863075df7a407cc59e194feebd652c622729384 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanf5e261e2012-01-01 16:00:03 +00004 Copyright(c) 1999 - 2012 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>
Bruce Allan9fb7a5f2011-07-29 05:52:51 +000032#include <linux/interrupt.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070033#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>
David S. Millerc85c21a2012-01-26 16:25:55 -050037#include <linux/vmalloc.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070038
39#include "e1000.h"
40
Ajit Khapardee0f36a92009-10-13 01:45:09 +000041enum {NETDEV_STATS, E1000_STATS};
42
Auke Kokbc7f75f2007-09-17 12:30:59 -070043struct e1000_stats {
44 char stat_string[ETH_GSTRING_LEN];
Ajit Khapardee0f36a92009-10-13 01:45:09 +000045 int type;
Auke Kokbc7f75f2007-09-17 12:30:59 -070046 int sizeof_stat;
47 int stat_offset;
48};
49
Bruce Allanf0f1a172010-12-11 05:53:32 +000050#define E1000_STAT(str, m) { \
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000051 .stat_string = str, \
52 .type = E1000_STATS, \
53 .sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
54 .stat_offset = offsetof(struct e1000_adapter, m) }
Bruce Allanf0f1a172010-12-11 05:53:32 +000055#define E1000_NETDEV_STAT(str, m) { \
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000056 .stat_string = str, \
57 .type = NETDEV_STATS, \
58 .sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \
59 .stat_offset = offsetof(struct rtnl_link_stats64, m) }
Ajit Khapardee0f36a92009-10-13 01:45:09 +000060
Auke Kokbc7f75f2007-09-17 12:30:59 -070061static const struct e1000_stats e1000_gstrings_stats[] = {
Bruce Allanf0f1a172010-12-11 05:53:32 +000062 E1000_STAT("rx_packets", stats.gprc),
63 E1000_STAT("tx_packets", stats.gptc),
64 E1000_STAT("rx_bytes", stats.gorc),
65 E1000_STAT("tx_bytes", stats.gotc),
66 E1000_STAT("rx_broadcast", stats.bprc),
67 E1000_STAT("tx_broadcast", stats.bptc),
68 E1000_STAT("rx_multicast", stats.mprc),
69 E1000_STAT("tx_multicast", stats.mptc),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000070 E1000_NETDEV_STAT("rx_errors", rx_errors),
71 E1000_NETDEV_STAT("tx_errors", tx_errors),
72 E1000_NETDEV_STAT("tx_dropped", tx_dropped),
Bruce Allanf0f1a172010-12-11 05:53:32 +000073 E1000_STAT("multicast", stats.mprc),
74 E1000_STAT("collisions", stats.colc),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000075 E1000_NETDEV_STAT("rx_length_errors", rx_length_errors),
76 E1000_NETDEV_STAT("rx_over_errors", rx_over_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000077 E1000_STAT("rx_crc_errors", stats.crcerrs),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000078 E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000079 E1000_STAT("rx_no_buffer_count", stats.rnbc),
80 E1000_STAT("rx_missed_errors", stats.mpc),
81 E1000_STAT("tx_aborted_errors", stats.ecol),
82 E1000_STAT("tx_carrier_errors", stats.tncrs),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000083 E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
84 E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000085 E1000_STAT("tx_window_errors", stats.latecol),
86 E1000_STAT("tx_abort_late_coll", stats.latecol),
87 E1000_STAT("tx_deferred_ok", stats.dc),
88 E1000_STAT("tx_single_coll_ok", stats.scc),
89 E1000_STAT("tx_multi_coll_ok", stats.mcc),
90 E1000_STAT("tx_timeout_count", tx_timeout_count),
91 E1000_STAT("tx_restart_queue", restart_queue),
92 E1000_STAT("rx_long_length_errors", stats.roc),
93 E1000_STAT("rx_short_length_errors", stats.ruc),
94 E1000_STAT("rx_align_errors", stats.algnerrc),
95 E1000_STAT("tx_tcp_seg_good", stats.tsctc),
96 E1000_STAT("tx_tcp_seg_failed", stats.tsctfc),
97 E1000_STAT("rx_flow_control_xon", stats.xonrxc),
98 E1000_STAT("rx_flow_control_xoff", stats.xoffrxc),
99 E1000_STAT("tx_flow_control_xon", stats.xontxc),
100 E1000_STAT("tx_flow_control_xoff", stats.xofftxc),
101 E1000_STAT("rx_long_byte_count", stats.gorc),
102 E1000_STAT("rx_csum_offload_good", hw_csum_good),
103 E1000_STAT("rx_csum_offload_errors", hw_csum_err),
104 E1000_STAT("rx_header_split", rx_hdr_split),
105 E1000_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),
106 E1000_STAT("tx_smbus", stats.mgptc),
107 E1000_STAT("rx_smbus", stats.mgprc),
108 E1000_STAT("dropped_smbus", stats.mgpdc),
109 E1000_STAT("rx_dma_failed", rx_dma_failed),
110 E1000_STAT("tx_dma_failed", tx_dma_failed),
Auke Kokbc7f75f2007-09-17 12:30:59 -0700111};
112
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200113#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700114#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
115static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
116 "Register test (offline)", "Eeprom test (offline)",
117 "Interrupt test (offline)", "Loopback test (offline)",
118 "Link test (on/offline)"
119};
Bruce Allanad680762008-03-28 09:15:03 -0700120#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700121
122static int e1000_get_settings(struct net_device *netdev,
123 struct ethtool_cmd *ecmd)
124{
125 struct e1000_adapter *adapter = netdev_priv(netdev);
126 struct e1000_hw *hw = &adapter->hw;
David Decotigny70739492011-04-27 18:32:40 +0000127 u32 speed;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700128
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700129 if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700130
131 ecmd->supported = (SUPPORTED_10baseT_Half |
132 SUPPORTED_10baseT_Full |
133 SUPPORTED_100baseT_Half |
134 SUPPORTED_100baseT_Full |
135 SUPPORTED_1000baseT_Full |
136 SUPPORTED_Autoneg |
137 SUPPORTED_TP);
138 if (hw->phy.type == e1000_phy_ife)
139 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
140 ecmd->advertising = ADVERTISED_TP;
141
142 if (hw->mac.autoneg == 1) {
143 ecmd->advertising |= ADVERTISED_Autoneg;
144 /* the e1000 autoneg seems to match ethtool nicely */
145 ecmd->advertising |= hw->phy.autoneg_advertised;
146 }
147
148 ecmd->port = PORT_TP;
149 ecmd->phy_address = hw->phy.addr;
150 ecmd->transceiver = XCVR_INTERNAL;
151
152 } else {
153 ecmd->supported = (SUPPORTED_1000baseT_Full |
154 SUPPORTED_FIBRE |
155 SUPPORTED_Autoneg);
156
157 ecmd->advertising = (ADVERTISED_1000baseT_Full |
158 ADVERTISED_FIBRE |
159 ADVERTISED_Autoneg);
160
161 ecmd->port = PORT_FIBRE;
162 ecmd->transceiver = XCVR_EXTERNAL;
163 }
164
David Decotigny70739492011-04-27 18:32:40 +0000165 speed = -1;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000166 ecmd->duplex = -1;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700167
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000168 if (netif_running(netdev)) {
169 if (netif_carrier_ok(netdev)) {
David Decotigny70739492011-04-27 18:32:40 +0000170 speed = adapter->link_speed;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000171 ecmd->duplex = adapter->link_duplex - 1;
172 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700173 } else {
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000174 u32 status = er32(STATUS);
175 if (status & E1000_STATUS_LU) {
176 if (status & E1000_STATUS_SPEED_1000)
David Decotigny70739492011-04-27 18:32:40 +0000177 speed = SPEED_1000;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000178 else if (status & E1000_STATUS_SPEED_100)
David Decotigny70739492011-04-27 18:32:40 +0000179 speed = SPEED_100;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000180 else
David Decotigny70739492011-04-27 18:32:40 +0000181 speed = SPEED_10;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000182
183 if (status & E1000_STATUS_FD)
184 ecmd->duplex = DUPLEX_FULL;
185 else
186 ecmd->duplex = DUPLEX_HALF;
187 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700188 }
189
David Decotigny70739492011-04-27 18:32:40 +0000190 ethtool_cmd_speed_set(ecmd, speed);
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700191 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -0700192 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000193
194 /* MDI-X => 2; MDI =>1; Invalid =>0 */
195 if ((hw->phy.media_type == e1000_media_type_copper) &&
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000196 netif_carrier_ok(netdev))
Chaitanya Lala18760f12009-06-08 14:28:54 +0000197 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
198 ETH_TP_MDI;
199 else
200 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
201
Auke Kokbc7f75f2007-09-17 12:30:59 -0700202 return 0;
203}
204
David Decotigny14ad2512011-04-27 18:32:43 +0000205static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700206{
207 struct e1000_mac_info *mac = &adapter->hw.mac;
208
209 mac->autoneg = 0;
210
David Decotigny14ad2512011-04-27 18:32:43 +0000211 /* Make sure dplx is at most 1 bit and lsb of speed is not set
212 * for the switch() below to work */
213 if ((spd & 1) || (dplx & ~1))
214 goto err_inval;
215
Auke Kokbc7f75f2007-09-17 12:30:59 -0700216 /* Fiber NICs only allow 1000 gbps Full duplex */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700217 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
David Decotigny14ad2512011-04-27 18:32:43 +0000218 spd != SPEED_1000 &&
219 dplx != DUPLEX_FULL) {
220 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700221 }
222
David Decotigny14ad2512011-04-27 18:32:43 +0000223 switch (spd + dplx) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700224 case SPEED_10 + DUPLEX_HALF:
225 mac->forced_speed_duplex = ADVERTISE_10_HALF;
226 break;
227 case SPEED_10 + DUPLEX_FULL:
228 mac->forced_speed_duplex = ADVERTISE_10_FULL;
229 break;
230 case SPEED_100 + DUPLEX_HALF:
231 mac->forced_speed_duplex = ADVERTISE_100_HALF;
232 break;
233 case SPEED_100 + DUPLEX_FULL:
234 mac->forced_speed_duplex = ADVERTISE_100_FULL;
235 break;
236 case SPEED_1000 + DUPLEX_FULL:
237 mac->autoneg = 1;
238 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
239 break;
240 case SPEED_1000 + DUPLEX_HALF: /* not supported */
241 default:
David Decotigny14ad2512011-04-27 18:32:43 +0000242 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700243 }
244 return 0;
David Decotigny14ad2512011-04-27 18:32:43 +0000245
246err_inval:
247 e_err("Unsupported Speed/Duplex configuration\n");
248 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700249}
250
251static int e1000_set_settings(struct net_device *netdev,
252 struct ethtool_cmd *ecmd)
253{
254 struct e1000_adapter *adapter = netdev_priv(netdev);
255 struct e1000_hw *hw = &adapter->hw;
256
Bruce Allanad680762008-03-28 09:15:03 -0700257 /*
258 * When SoL/IDER sessions are active, autoneg/speed/duplex
259 * cannot be changed
260 */
Bruce Allan44abd5c2012-02-22 09:02:37 +0000261 if (hw->phy.ops.check_reset_block(hw)) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000262 e_err("Cannot change link characteristics when SoL/IDER is 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
Auke Kokbc7f75f2007-09-17 12:30:59 -0700370static u32 e1000_get_msglevel(struct net_device *netdev)
371{
372 struct e1000_adapter *adapter = netdev_priv(netdev);
373 return adapter->msg_enable;
374}
375
376static void e1000_set_msglevel(struct net_device *netdev, u32 data)
377{
378 struct e1000_adapter *adapter = netdev_priv(netdev);
379 adapter->msg_enable = data;
380}
381
382static int e1000_get_regs_len(struct net_device *netdev)
383{
384#define E1000_REGS_LEN 32 /* overestimate */
385 return E1000_REGS_LEN * sizeof(u32);
386}
387
388static void e1000_get_regs(struct net_device *netdev,
389 struct ethtool_regs *regs, void *p)
390{
391 struct e1000_adapter *adapter = netdev_priv(netdev);
392 struct e1000_hw *hw = &adapter->hw;
393 u32 *regs_buff = p;
394 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700395
396 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
397
Sergei Shtylyovff938e42011-02-28 11:57:33 -0800398 regs->version = (1 << 24) | (adapter->pdev->revision << 16) |
399 adapter->pdev->device;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700400
401 regs_buff[0] = er32(CTRL);
402 regs_buff[1] = er32(STATUS);
403
404 regs_buff[2] = er32(RCTL);
Bruce Allan1e360522012-03-20 03:48:13 +0000405 regs_buff[3] = er32(RDLEN(0));
406 regs_buff[4] = er32(RDH(0));
407 regs_buff[5] = er32(RDT(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700408 regs_buff[6] = er32(RDTR);
409
410 regs_buff[7] = er32(TCTL);
Bruce Allan1e360522012-03-20 03:48:13 +0000411 regs_buff[8] = er32(TDLEN(0));
412 regs_buff[9] = er32(TDH(0));
413 regs_buff[10] = er32(TDT(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700414 regs_buff[11] = er32(TIDV);
415
416 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700417
418 /* ethtool doesn't use anything past this point, so all this
419 * code is likely legacy junk for apps that may or may not
420 * exist */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700421 if (hw->phy.type == e1000_phy_m88) {
422 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
423 regs_buff[13] = (u32)phy_data; /* cable length */
424 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
425 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
426 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
427 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
428 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
429 regs_buff[18] = regs_buff[13]; /* cable polarity */
430 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
431 regs_buff[20] = regs_buff[17]; /* polarity correction */
432 /* phy receive errors */
433 regs_buff[22] = adapter->phy_stats.receive_errors;
434 regs_buff[23] = regs_buff[13]; /* mdix mode */
435 }
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700436 regs_buff[21] = 0; /* was idle_errors */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700437 e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
438 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
439 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
440}
441
442static int e1000_get_eeprom_len(struct net_device *netdev)
443{
444 struct e1000_adapter *adapter = netdev_priv(netdev);
445 return adapter->hw.nvm.word_size * 2;
446}
447
448static int e1000_get_eeprom(struct net_device *netdev,
449 struct ethtool_eeprom *eeprom, u8 *bytes)
450{
451 struct e1000_adapter *adapter = netdev_priv(netdev);
452 struct e1000_hw *hw = &adapter->hw;
453 u16 *eeprom_buff;
454 int first_word;
455 int last_word;
456 int ret_val = 0;
457 u16 i;
458
459 if (eeprom->len == 0)
460 return -EINVAL;
461
462 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
463
464 first_word = eeprom->offset >> 1;
465 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
466
467 eeprom_buff = kmalloc(sizeof(u16) *
468 (last_word - first_word + 1), GFP_KERNEL);
469 if (!eeprom_buff)
470 return -ENOMEM;
471
472 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
473 ret_val = e1000_read_nvm(hw, first_word,
474 last_word - first_word + 1,
475 eeprom_buff);
476 } else {
477 for (i = 0; i < last_word - first_word + 1; i++) {
478 ret_val = e1000_read_nvm(hw, first_word + i, 1,
479 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800480 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700481 break;
482 }
483 }
484
Bruce Allane2434552008-11-21 17:02:41 -0800485 if (ret_val) {
486 /* a read error occurred, throw away the result */
Roel Kluin8528b012009-12-01 15:54:24 +0000487 memset(eeprom_buff, 0xff, sizeof(u16) *
488 (last_word - first_word + 1));
Bruce Allane2434552008-11-21 17:02:41 -0800489 } else {
490 /* Device's eeprom is always little-endian, word addressable */
491 for (i = 0; i < last_word - first_word + 1; i++)
492 le16_to_cpus(&eeprom_buff[i]);
493 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700494
495 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
496 kfree(eeprom_buff);
497
498 return ret_val;
499}
500
501static int e1000_set_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 void *ptr;
508 int max_len;
509 int first_word;
510 int last_word;
511 int ret_val = 0;
512 u16 i;
513
514 if (eeprom->len == 0)
515 return -EOPNOTSUPP;
516
517 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
518 return -EFAULT;
519
Bruce Allan4a770352008-10-01 17:18:35 -0700520 if (adapter->flags & FLAG_READ_ONLY_NVM)
521 return -EINVAL;
522
Auke Kokbc7f75f2007-09-17 12:30:59 -0700523 max_len = hw->nvm.word_size * 2;
524
525 first_word = eeprom->offset >> 1;
526 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
527 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
528 if (!eeprom_buff)
529 return -ENOMEM;
530
531 ptr = (void *)eeprom_buff;
532
533 if (eeprom->offset & 1) {
534 /* need read/modify/write of first changed EEPROM word */
535 /* only the second byte of the word is being modified */
536 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
537 ptr++;
538 }
Bruce Allan9e2d7652012-01-31 06:37:27 +0000539 if (((eeprom->offset + eeprom->len) & 1) && (!ret_val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700540 /* need read/modify/write of last changed EEPROM word */
541 /* only the first byte of the word is being modified */
542 ret_val = e1000_read_nvm(hw, last_word, 1,
543 &eeprom_buff[last_word - first_word]);
544
Bruce Allane2434552008-11-21 17:02:41 -0800545 if (ret_val)
546 goto out;
547
Auke Kokbc7f75f2007-09-17 12:30:59 -0700548 /* Device's eeprom is always little-endian, word addressable */
549 for (i = 0; i < last_word - first_word + 1; i++)
550 le16_to_cpus(&eeprom_buff[i]);
551
552 memcpy(ptr, bytes, eeprom->len);
553
554 for (i = 0; i < last_word - first_word + 1; i++)
Bruce Allane885d762012-01-31 06:37:32 +0000555 cpu_to_le16s(&eeprom_buff[i]);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700556
557 ret_val = e1000_write_nvm(hw, first_word,
558 last_word - first_word + 1, eeprom_buff);
559
Bruce Allane2434552008-11-21 17:02:41 -0800560 if (ret_val)
561 goto out;
562
Bruce Allanad680762008-03-28 09:15:03 -0700563 /*
564 * Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800565 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700566 */
Bruce Allane2434552008-11-21 17:02:41 -0800567 if ((first_word <= NVM_CHECKSUM_REG) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +0000568 (hw->mac.type == e1000_82583) ||
569 (hw->mac.type == e1000_82574) ||
570 (hw->mac.type == e1000_82573))
Bruce Allane2434552008-11-21 17:02:41 -0800571 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700572
Bruce Allane2434552008-11-21 17:02:41 -0800573out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700574 kfree(eeprom_buff);
575 return ret_val;
576}
577
578static void e1000_get_drvinfo(struct net_device *netdev,
579 struct ethtool_drvinfo *drvinfo)
580{
581 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700582
Rick Jones612a94d2011-11-14 08:13:25 +0000583 strlcpy(drvinfo->driver, e1000e_driver_name,
584 sizeof(drvinfo->driver));
Rick Jones33a5ba12011-11-15 14:59:53 +0000585 strlcpy(drvinfo->version, e1000e_driver_version,
Rick Jones612a94d2011-11-14 08:13:25 +0000586 sizeof(drvinfo->version));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700587
Bruce Allanad680762008-03-28 09:15:03 -0700588 /*
589 * EEPROM image version # is reported as firmware version # for
590 * PCI-E controllers
591 */
Rick Jones612a94d2011-11-14 08:13:25 +0000592 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
593 "%d.%d-%d",
Bruce Allan84527592008-11-21 17:00:22 -0800594 (adapter->eeprom_vers & 0xF000) >> 12,
595 (adapter->eeprom_vers & 0x0FF0) >> 4,
596 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700597
Rick Jones612a94d2011-11-14 08:13:25 +0000598 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
599 sizeof(drvinfo->bus_info));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700600 drvinfo->regdump_len = e1000_get_regs_len(netdev);
601 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
602}
603
604static void e1000_get_ringparam(struct net_device *netdev,
605 struct ethtool_ringparam *ring)
606{
607 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700608
609 ring->rx_max_pending = E1000_MAX_RXD;
610 ring->tx_max_pending = E1000_MAX_TXD;
Bruce Allan508da422011-12-16 00:45:51 +0000611 ring->rx_pending = adapter->rx_ring_count;
612 ring->tx_pending = adapter->tx_ring_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700613}
614
615static int e1000_set_ringparam(struct net_device *netdev,
616 struct ethtool_ringparam *ring)
617{
618 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan508da422011-12-16 00:45:51 +0000619 struct e1000_ring *temp_tx = NULL, *temp_rx = NULL;
620 int err = 0, size = sizeof(struct e1000_ring);
621 bool set_tx = false, set_rx = false;
622 u16 new_rx_count, new_tx_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700623
624 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
625 return -EINVAL;
626
Bruce Allan508da422011-12-16 00:45:51 +0000627 new_rx_count = clamp_t(u32, ring->rx_pending, E1000_MIN_RXD,
628 E1000_MAX_RXD);
629 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
630
631 new_tx_count = clamp_t(u32, ring->tx_pending, E1000_MIN_TXD,
632 E1000_MAX_TXD);
633 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
634
635 if ((new_tx_count == adapter->tx_ring_count) &&
636 (new_rx_count == adapter->rx_ring_count))
637 /* nothing to do */
638 return 0;
639
Auke Kokbc7f75f2007-09-17 12:30:59 -0700640 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000641 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700642
Bruce Allan508da422011-12-16 00:45:51 +0000643 if (!netif_running(adapter->netdev)) {
644 /* Set counts now and allocate resources during open() */
645 adapter->tx_ring->count = new_tx_count;
646 adapter->rx_ring->count = new_rx_count;
647 adapter->tx_ring_count = new_tx_count;
648 adapter->rx_ring_count = new_rx_count;
649 goto clear_reset;
650 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700651
Bruce Allan508da422011-12-16 00:45:51 +0000652 set_tx = (new_tx_count != adapter->tx_ring_count);
653 set_rx = (new_rx_count != adapter->rx_ring_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700654
Bruce Allan508da422011-12-16 00:45:51 +0000655 /* Allocate temporary storage for ring updates */
656 if (set_tx) {
657 temp_tx = vmalloc(size);
658 if (!temp_tx) {
659 err = -ENOMEM;
660 goto free_temp;
661 }
662 }
663 if (set_rx) {
664 temp_rx = vmalloc(size);
665 if (!temp_rx) {
666 err = -ENOMEM;
667 goto free_temp;
668 }
669 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700670
Bruce Allan508da422011-12-16 00:45:51 +0000671 e1000e_down(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700672
Bruce Allan508da422011-12-16 00:45:51 +0000673 /*
674 * We can't just free everything and then setup again, because the
675 * ISRs in MSI-X mode get passed pointers to the Tx and Rx ring
676 * structs. First, attempt to allocate new resources...
677 */
678 if (set_tx) {
679 memcpy(temp_tx, adapter->tx_ring, size);
680 temp_tx->count = new_tx_count;
681 err = e1000e_setup_tx_resources(temp_tx);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700682 if (err)
683 goto err_setup;
684 }
Bruce Allan508da422011-12-16 00:45:51 +0000685 if (set_rx) {
686 memcpy(temp_rx, adapter->rx_ring, size);
687 temp_rx->count = new_rx_count;
688 err = e1000e_setup_rx_resources(temp_rx);
689 if (err)
690 goto err_setup_rx;
691 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700692
Bruce Allan508da422011-12-16 00:45:51 +0000693 /* ...then free the old resources and copy back any new ring data */
694 if (set_tx) {
695 e1000e_free_tx_resources(adapter->tx_ring);
696 memcpy(adapter->tx_ring, temp_tx, size);
697 adapter->tx_ring_count = new_tx_count;
698 }
699 if (set_rx) {
700 e1000e_free_rx_resources(adapter->rx_ring);
701 memcpy(adapter->rx_ring, temp_rx, size);
702 adapter->rx_ring_count = new_rx_count;
703 }
704
Auke Kokbc7f75f2007-09-17 12:30:59 -0700705err_setup_rx:
Bruce Allan508da422011-12-16 00:45:51 +0000706 if (err && set_tx)
707 e1000e_free_tx_resources(temp_tx);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700708err_setup:
Bruce Allan508da422011-12-16 00:45:51 +0000709 e1000e_up(adapter);
710free_temp:
711 vfree(temp_tx);
712 vfree(temp_rx);
713clear_reset:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700714 clear_bit(__E1000_RESETTING, &adapter->state);
715 return err;
716}
717
Bruce Allancef8c792008-04-02 13:48:23 -0700718static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
719 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800720{
Bruce Allancef8c792008-04-02 13:48:23 -0700721 u32 pat, val;
Bruce Allan64806412010-12-11 05:53:42 +0000722 static const u32 test[] = {
723 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Bruce Allancef8c792008-04-02 13:48:23 -0700724 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800725 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700726 (test[pat] & write));
727 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
728 if (val != (test[pat] & write & mask)) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000729 e_err("pattern test reg %04X failed: got 0x%08X expected 0x%08X\n",
730 reg + offset, val, (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800731 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700732 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800733 }
734 }
Bruce Allancef8c792008-04-02 13:48:23 -0700735 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700736}
737
Joe Perches2a887192007-11-13 20:53:51 -0800738static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
739 int reg, u32 mask, u32 write)
740{
Bruce Allancef8c792008-04-02 13:48:23 -0700741 u32 val;
Joe Perches2a887192007-11-13 20:53:51 -0800742 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700743 val = __er32(&adapter->hw, reg);
744 if ((write & mask) != (val & mask)) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000745 e_err("set/check reg %04X test failed: got 0x%08X expected 0x%08X\n",
746 reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800747 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700748 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800749 }
Bruce Allancef8c792008-04-02 13:48:23 -0700750 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700751}
Bruce Allancef8c792008-04-02 13:48:23 -0700752#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
753 do { \
754 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
755 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800756 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700757#define REG_PATTERN_TEST(reg, mask, write) \
758 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800759
Bruce Allancef8c792008-04-02 13:48:23 -0700760#define REG_SET_AND_CHECK(reg, mask, write) \
761 do { \
762 if (reg_set_and_check(adapter, data, reg, mask, write)) \
763 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800764 } while (0)
765
Auke Kokbc7f75f2007-09-17 12:30:59 -0700766static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
767{
768 struct e1000_hw *hw = &adapter->hw;
769 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700770 u32 value;
771 u32 before;
772 u32 after;
773 u32 i;
774 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000775 u32 mask;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000776 u32 wlock_mac = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700777
Bruce Allanad680762008-03-28 09:15:03 -0700778 /*
779 * The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700780 * Some bits that get toggled are ignored.
781 */
782 switch (mac->type) {
783 /* there are several bits on newer hardware that are r/w */
784 case e1000_82571:
785 case e1000_82572:
786 case e1000_80003es2lan:
787 toggle = 0x7FFFF3FF;
788 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000789 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700790 toggle = 0x7FFFF033;
791 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700792 }
793
794 before = er32(STATUS);
795 value = (er32(STATUS) & toggle);
796 ew32(STATUS, toggle);
797 after = er32(STATUS) & toggle;
798 if (value != after) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000799 e_err("failed STATUS register test got: 0x%08X expected: 0x%08X\n",
800 after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700801 *data = 1;
802 return 1;
803 }
804 /* restore previous status */
805 ew32(STATUS, before);
806
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700807 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700808 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
809 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
810 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
811 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
812 }
813
814 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000815 REG_PATTERN_TEST(E1000_RDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
816 REG_PATTERN_TEST(E1000_RDLEN(0), 0x000FFF80, 0x000FFFFF);
817 REG_PATTERN_TEST(E1000_RDH(0), 0x0000FFFF, 0x0000FFFF);
818 REG_PATTERN_TEST(E1000_RDT(0), 0x0000FFFF, 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700819 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
820 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
821 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000822 REG_PATTERN_TEST(E1000_TDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
823 REG_PATTERN_TEST(E1000_TDLEN(0), 0x000FFF80, 0x000FFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700824
825 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
826
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700827 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700828 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
829 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
830
Auke Kok86582512007-10-04 15:00:08 -0700831 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000832 REG_PATTERN_TEST(E1000_RDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700833 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700834 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000835 REG_PATTERN_TEST(E1000_TDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
Auke Kok86582512007-10-04 15:00:08 -0700836 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000837 mask = 0x8003FFFF;
838 switch (mac->type) {
839 case e1000_ich10lan:
840 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000841 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000842 case e1000_pch_lpt:
Bruce Allana4f58f52009-06-02 11:29:18 +0000843 mask |= (1 << 18);
844 break;
845 default:
846 break;
847 }
Bruce Allan2fbe4522012-04-19 03:21:47 +0000848
849 if (mac->type == e1000_pch_lpt)
850 wlock_mac = (er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK) >>
851 E1000_FWSM_WLOCK_MAC_SHIFT;
852
853 for (i = 0; i < mac->rar_entry_count; i++) {
854 /* Cannot test write-protected SHRAL[n] registers */
855 if ((wlock_mac == 1) || (wlock_mac && (i > wlock_mac)))
856 continue;
857
Auke Kok86582512007-10-04 15:00:08 -0700858 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
Bruce Allan2fbe4522012-04-19 03:21:47 +0000859 mask, 0xFFFFFFFF);
860 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700861
862 for (i = 0; i < mac->mta_reg_count; i++)
863 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
864
865 *data = 0;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000866
Auke Kokbc7f75f2007-09-17 12:30:59 -0700867 return 0;
868}
869
870static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
871{
872 u16 temp;
873 u16 checksum = 0;
874 u16 i;
875
876 *data = 0;
877 /* Read and add up the contents of the EEPROM */
878 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
879 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
880 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800881 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700882 }
883 checksum += temp;
884 }
885
886 /* If Checksum is not Correct return error else test passed */
887 if ((checksum != (u16) NVM_SUM) && !(*data))
888 *data = 2;
889
890 return *data;
891}
892
893static irqreturn_t e1000_test_intr(int irq, void *data)
894{
895 struct net_device *netdev = (struct net_device *) data;
896 struct e1000_adapter *adapter = netdev_priv(netdev);
897 struct e1000_hw *hw = &adapter->hw;
898
899 adapter->test_icr |= er32(ICR);
900
901 return IRQ_HANDLED;
902}
903
904static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
905{
906 struct net_device *netdev = adapter->netdev;
907 struct e1000_hw *hw = &adapter->hw;
908 u32 mask;
909 u32 shared_int = 1;
910 u32 irq = adapter->pdev->irq;
911 int i;
Bruce Allan4662e822008-08-26 18:37:06 -0700912 int ret_val = 0;
913 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700914
915 *data = 0;
916
Bruce Allan4662e822008-08-26 18:37:06 -0700917 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
918 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
919 int_mode = adapter->int_mode;
920 e1000e_reset_interrupt_capability(adapter);
921 adapter->int_mode = E1000E_INT_MODE_LEGACY;
922 e1000e_set_interrupt_capability(adapter);
923 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700924 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800925 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700926 netdev)) {
927 shared_int = 0;
Joe Perchesa0607fd2009-11-18 23:29:17 -0800928 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700929 netdev->name, netdev)) {
930 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700931 ret_val = -1;
932 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700933 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700934 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700935
936 /* Disable all the interrupts */
937 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000938 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000939 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700940
941 /* Test each interrupt */
942 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700943 /* Interrupt to test */
944 mask = 1 << i;
945
Bruce Allanf4187b52008-08-26 18:36:50 -0700946 if (adapter->flags & FLAG_IS_ICH) {
947 switch (mask) {
948 case E1000_ICR_RXSEQ:
949 continue;
950 case 0x00000100:
951 if (adapter->hw.mac.type == e1000_ich8lan ||
952 adapter->hw.mac.type == e1000_ich9lan)
953 continue;
954 break;
955 default:
956 break;
957 }
958 }
959
Auke Kokbc7f75f2007-09-17 12:30:59 -0700960 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700961 /*
962 * Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700963 * the cause register and then force the same
964 * interrupt and see if one gets posted. If
965 * an interrupt was posted to the bus, the
966 * test failed.
967 */
968 adapter->test_icr = 0;
969 ew32(IMC, mask);
970 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000971 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000972 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700973
974 if (adapter->test_icr & mask) {
975 *data = 3;
976 break;
977 }
978 }
979
Bruce Allanad680762008-03-28 09:15:03 -0700980 /*
981 * Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700982 * the cause register and then force the same
983 * interrupt and see if one gets posted. If
984 * an interrupt was not posted to the bus, the
985 * test failed.
986 */
987 adapter->test_icr = 0;
988 ew32(IMS, mask);
989 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000990 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000991 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700992
993 if (!(adapter->test_icr & mask)) {
994 *data = 4;
995 break;
996 }
997
998 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700999 /*
1000 * Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001001 * the cause register and then force the other
1002 * interrupts and see if any get posted. If
1003 * an interrupt was posted to the bus, the
1004 * test failed.
1005 */
1006 adapter->test_icr = 0;
1007 ew32(IMC, ~mask & 0x00007FFF);
1008 ew32(ICS, ~mask & 0x00007FFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001009 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001010 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001011
1012 if (adapter->test_icr) {
1013 *data = 5;
1014 break;
1015 }
1016 }
1017 }
1018
1019 /* Disable all the interrupts */
1020 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001021 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001022 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001023
1024 /* Unhook test interrupt handler */
1025 free_irq(irq, netdev);
1026
Bruce Allan4662e822008-08-26 18:37:06 -07001027out:
1028 if (int_mode == E1000E_INT_MODE_MSIX) {
1029 e1000e_reset_interrupt_capability(adapter);
1030 adapter->int_mode = int_mode;
1031 e1000e_set_interrupt_capability(adapter);
1032 }
1033
1034 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001035}
1036
1037static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1038{
1039 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1040 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1041 struct pci_dev *pdev = adapter->pdev;
1042 int i;
1043
1044 if (tx_ring->desc && tx_ring->buffer_info) {
1045 for (i = 0; i < tx_ring->count; i++) {
1046 if (tx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001047 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001048 tx_ring->buffer_info[i].dma,
1049 tx_ring->buffer_info[i].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001050 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001051 if (tx_ring->buffer_info[i].skb)
1052 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1053 }
1054 }
1055
1056 if (rx_ring->desc && rx_ring->buffer_info) {
1057 for (i = 0; i < rx_ring->count; i++) {
1058 if (rx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001059 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001060 rx_ring->buffer_info[i].dma,
Nick Nunley0be3f552010-04-27 13:09:05 +00001061 2048, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001062 if (rx_ring->buffer_info[i].skb)
1063 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1064 }
1065 }
1066
1067 if (tx_ring->desc) {
1068 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1069 tx_ring->dma);
1070 tx_ring->desc = NULL;
1071 }
1072 if (rx_ring->desc) {
1073 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1074 rx_ring->dma);
1075 rx_ring->desc = NULL;
1076 }
1077
1078 kfree(tx_ring->buffer_info);
1079 tx_ring->buffer_info = NULL;
1080 kfree(rx_ring->buffer_info);
1081 rx_ring->buffer_info = NULL;
1082}
1083
1084static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1085{
1086 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1087 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1088 struct pci_dev *pdev = adapter->pdev;
1089 struct e1000_hw *hw = &adapter->hw;
1090 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001091 int i;
1092 int ret_val;
1093
1094 /* Setup Tx descriptor ring and Tx buffers */
1095
1096 if (!tx_ring->count)
1097 tx_ring->count = E1000_DEFAULT_TXD;
1098
Bruce Allancef8c792008-04-02 13:48:23 -07001099 tx_ring->buffer_info = kcalloc(tx_ring->count,
1100 sizeof(struct e1000_buffer),
1101 GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001102 if (!tx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001103 ret_val = 1;
1104 goto err_nomem;
1105 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001106
1107 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1108 tx_ring->size = ALIGN(tx_ring->size, 4096);
1109 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1110 &tx_ring->dma, GFP_KERNEL);
1111 if (!tx_ring->desc) {
1112 ret_val = 2;
1113 goto err_nomem;
1114 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001115 tx_ring->next_to_use = 0;
1116 tx_ring->next_to_clean = 0;
1117
Bruce Allan1e360522012-03-20 03:48:13 +00001118 ew32(TDBAL(0), ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
1119 ew32(TDBAH(0), ((u64) tx_ring->dma >> 32));
1120 ew32(TDLEN(0), tx_ring->count * sizeof(struct e1000_tx_desc));
1121 ew32(TDH(0), 0);
1122 ew32(TDT(0), 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001123 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1124 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1125 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001126
1127 for (i = 0; i < tx_ring->count; i++) {
1128 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1129 struct sk_buff *skb;
1130 unsigned int skb_size = 1024;
1131
1132 skb = alloc_skb(skb_size, GFP_KERNEL);
1133 if (!skb) {
1134 ret_val = 3;
1135 goto err_nomem;
1136 }
1137 skb_put(skb, skb_size);
1138 tx_ring->buffer_info[i].skb = skb;
1139 tx_ring->buffer_info[i].length = skb->len;
1140 tx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001141 dma_map_single(&pdev->dev, skb->data, skb->len,
1142 DMA_TO_DEVICE);
1143 if (dma_mapping_error(&pdev->dev,
1144 tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001145 ret_val = 4;
1146 goto err_nomem;
1147 }
Bruce Allancef8c792008-04-02 13:48:23 -07001148 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001149 tx_desc->lower.data = cpu_to_le32(skb->len);
1150 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1151 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001152 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001153 tx_desc->upper.data = 0;
1154 }
1155
1156 /* Setup Rx descriptor ring and Rx buffers */
1157
1158 if (!rx_ring->count)
1159 rx_ring->count = E1000_DEFAULT_RXD;
1160
Bruce Allancef8c792008-04-02 13:48:23 -07001161 rx_ring->buffer_info = kcalloc(rx_ring->count,
1162 sizeof(struct e1000_buffer),
1163 GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001164 if (!rx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001165 ret_val = 5;
1166 goto err_nomem;
1167 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001168
Bruce Allan5f450212011-07-22 06:21:46 +00001169 rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001170 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1171 &rx_ring->dma, GFP_KERNEL);
1172 if (!rx_ring->desc) {
1173 ret_val = 6;
1174 goto err_nomem;
1175 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001176 rx_ring->next_to_use = 0;
1177 rx_ring->next_to_clean = 0;
1178
1179 rctl = er32(RCTL);
Bruce Allan7f99ae62011-07-22 06:21:35 +00001180 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
1181 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan1e360522012-03-20 03:48:13 +00001182 ew32(RDBAL(0), ((u64) rx_ring->dma & 0xFFFFFFFF));
1183 ew32(RDBAH(0), ((u64) rx_ring->dma >> 32));
1184 ew32(RDLEN(0), rx_ring->size);
1185 ew32(RDH(0), 0);
1186 ew32(RDT(0), 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001187 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allancef8c792008-04-02 13:48:23 -07001188 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1189 E1000_RCTL_SBP | E1000_RCTL_SECRC |
Auke Kokbc7f75f2007-09-17 12:30:59 -07001190 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1191 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1192 ew32(RCTL, rctl);
1193
1194 for (i = 0; i < rx_ring->count; i++) {
Bruce Allan5f450212011-07-22 06:21:46 +00001195 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001196 struct sk_buff *skb;
1197
1198 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1199 if (!skb) {
1200 ret_val = 7;
1201 goto err_nomem;
1202 }
1203 skb_reserve(skb, NET_IP_ALIGN);
1204 rx_ring->buffer_info[i].skb = skb;
1205 rx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001206 dma_map_single(&pdev->dev, skb->data, 2048,
1207 DMA_FROM_DEVICE);
1208 if (dma_mapping_error(&pdev->dev,
1209 rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001210 ret_val = 8;
1211 goto err_nomem;
1212 }
Bruce Allan5f450212011-07-22 06:21:46 +00001213 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1214 rx_desc->read.buffer_addr =
1215 cpu_to_le64(rx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001216 memset(skb->data, 0x00, skb->len);
1217 }
1218
1219 return 0;
1220
1221err_nomem:
1222 e1000_free_desc_rings(adapter);
1223 return ret_val;
1224}
1225
1226static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1227{
1228 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1229 e1e_wphy(&adapter->hw, 29, 0x001F);
1230 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1231 e1e_wphy(&adapter->hw, 29, 0x001A);
1232 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1233}
1234
1235static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1236{
1237 struct e1000_hw *hw = &adapter->hw;
1238 u32 ctrl_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001239 u16 phy_reg = 0;
Bruce Allancbd006c2010-11-24 06:01:30 +00001240 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001241
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001242 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001243
Bruce Allan3af50482010-06-16 13:25:55 +00001244 if (hw->phy.type == e1000_phy_ife) {
1245 /* force 100, set loopback */
1246 e1e_wphy(hw, PHY_CONTROL, 0x6100);
Bruce Allanbb436b22009-11-20 23:24:11 +00001247
Bruce Allan3af50482010-06-16 13:25:55 +00001248 /* Now set up the MAC to the same speed/duplex as the PHY. */
1249 ctrl_reg = er32(CTRL);
1250 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1251 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1252 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1253 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1254 E1000_CTRL_FD); /* Force Duplex to FULL */
1255
1256 ew32(CTRL, ctrl_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001257 e1e_flush();
Bruce Allan3af50482010-06-16 13:25:55 +00001258 udelay(500);
1259
1260 return 0;
1261 }
1262
1263 /* Specific PHY configuration for loopback */
1264 switch (hw->phy.type) {
1265 case e1000_phy_m88:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001266 /* Auto-MDI/MDIX Off */
1267 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1268 /* reset to update Auto-MDI/MDIX */
1269 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1270 /* autoneg off */
1271 e1e_wphy(hw, PHY_CONTROL, 0x8140);
Bruce Allan3af50482010-06-16 13:25:55 +00001272 break;
1273 case e1000_phy_gg82563:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001274 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
Bruce Allancef8c792008-04-02 13:48:23 -07001275 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001276 case e1000_phy_bm:
1277 /* Set Default MAC Interface speed to 1GB */
1278 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1279 phy_reg &= ~0x0007;
1280 phy_reg |= 0x006;
1281 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1282 /* Assert SW reset for above settings to take effect */
1283 e1000e_commit_phy(hw);
1284 mdelay(1);
1285 /* Force Full Duplex */
1286 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1287 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1288 /* Set Link Up (in force link) */
1289 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1290 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1291 /* Force Link */
1292 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1293 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1294 /* Set Early Link Enable */
1295 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1296 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
Bruce Allan3af50482010-06-16 13:25:55 +00001297 break;
1298 case e1000_phy_82577:
1299 case e1000_phy_82578:
1300 /* Workaround: K1 must be disabled for stable 1Gbps operation */
Bruce Allancbd006c2010-11-24 06:01:30 +00001301 ret_val = hw->phy.ops.acquire(hw);
1302 if (ret_val) {
1303 e_err("Cannot setup 1Gbps loopback.\n");
1304 return ret_val;
1305 }
Bruce Allan3af50482010-06-16 13:25:55 +00001306 e1000_configure_k1_ich8lan(hw, false);
Bruce Allancbd006c2010-11-24 06:01:30 +00001307 hw->phy.ops.release(hw);
Bruce Allan3af50482010-06-16 13:25:55 +00001308 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001309 case e1000_phy_82579:
1310 /* Disable PHY energy detect power down */
1311 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1312 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
1313 /* Disable full chip energy detect */
1314 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1315 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1316 /* Enable loopback on the PHY */
1317#define I82577_PHY_LBK_CTRL 19
1318 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1319 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001320 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001321 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001322 }
1323
Bruce Allan3af50482010-06-16 13:25:55 +00001324 /* force 1000, set loopback */
1325 e1e_wphy(hw, PHY_CONTROL, 0x4140);
1326 mdelay(250);
1327
1328 /* Now set up the MAC to the same speed/duplex as the PHY. */
1329 ctrl_reg = er32(CTRL);
1330 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1331 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1332 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1333 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1334 E1000_CTRL_FD); /* Force Duplex to FULL */
1335
1336 if (adapter->flags & FLAG_IS_ICH)
1337 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1338
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001339 if (hw->phy.media_type == e1000_media_type_copper &&
1340 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001341 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1342 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001343 /*
1344 * Set the ILOS bit on the fiber Nic if half duplex link is
1345 * detected.
1346 */
Bruce Allan90da0662011-01-06 07:02:53 +00001347 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001348 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1349 }
1350
1351 ew32(CTRL, ctrl_reg);
1352
Bruce Allanad680762008-03-28 09:15:03 -07001353 /*
1354 * Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001355 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1356 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001357 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001358 e1000_phy_disable_receiver(adapter);
1359
1360 udelay(500);
1361
1362 return 0;
1363}
1364
1365static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1366{
1367 struct e1000_hw *hw = &adapter->hw;
1368 u32 ctrl = er32(CTRL);
1369 int link = 0;
1370
1371 /* special requirements for 82571/82572 fiber adapters */
1372
Bruce Allanad680762008-03-28 09:15:03 -07001373 /*
1374 * jump through hoops to make sure link is up because serdes
1375 * link is hardwired up
1376 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001377 ctrl |= E1000_CTRL_SLU;
1378 ew32(CTRL, ctrl);
1379
1380 /* disable autoneg */
1381 ctrl = er32(TXCW);
1382 ctrl &= ~(1 << 31);
1383 ew32(TXCW, ctrl);
1384
1385 link = (er32(STATUS) & E1000_STATUS_LU);
1386
1387 if (!link) {
1388 /* set invert loss of signal */
1389 ctrl = er32(CTRL);
1390 ctrl |= E1000_CTRL_ILOS;
1391 ew32(CTRL, ctrl);
1392 }
1393
Bruce Allanad680762008-03-28 09:15:03 -07001394 /*
1395 * special write to serdes control register to enable SerDes analog
1396 * loopback
1397 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001398#define E1000_SERDES_LB_ON 0x410
1399 ew32(SCTL, E1000_SERDES_LB_ON);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001400 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001401 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001402
1403 return 0;
1404}
1405
1406/* only call this for fiber/serdes connections to es2lan */
1407static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1408{
1409 struct e1000_hw *hw = &adapter->hw;
1410 u32 ctrlext = er32(CTRL_EXT);
1411 u32 ctrl = er32(CTRL);
1412
Bruce Allanad680762008-03-28 09:15:03 -07001413 /*
1414 * save CTRL_EXT to restore later, reuse an empty variable (unused
1415 * on mac_type 80003es2lan)
1416 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001417 adapter->tx_fifo_head = ctrlext;
1418
1419 /* clear the serdes mode bits, putting the device into mac loopback */
1420 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1421 ew32(CTRL_EXT, ctrlext);
1422
1423 /* force speed to 1000/FD, link up */
1424 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1425 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1426 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1427 ew32(CTRL, ctrl);
1428
1429 /* set mac loopback */
1430 ctrl = er32(RCTL);
1431 ctrl |= E1000_RCTL_LBM_MAC;
1432 ew32(RCTL, ctrl);
1433
1434 /* set testing mode parameters (no need to reset later) */
1435#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1436#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1437 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001438 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001439
1440 return 0;
1441}
1442
1443static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1444{
1445 struct e1000_hw *hw = &adapter->hw;
1446 u32 rctl;
1447
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001448 if (hw->phy.media_type == e1000_media_type_fiber ||
1449 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001450 switch (hw->mac.type) {
1451 case e1000_80003es2lan:
1452 return e1000_set_es2lan_mac_loopback(adapter);
1453 break;
1454 case e1000_82571:
1455 case e1000_82572:
1456 return e1000_set_82571_fiber_loopback(adapter);
1457 break;
1458 default:
1459 rctl = er32(RCTL);
1460 rctl |= E1000_RCTL_LBM_TCVR;
1461 ew32(RCTL, rctl);
1462 return 0;
1463 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001464 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001465 return e1000_integrated_phy_loopback(adapter);
1466 }
1467
1468 return 7;
1469}
1470
1471static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1472{
1473 struct e1000_hw *hw = &adapter->hw;
1474 u32 rctl;
1475 u16 phy_reg;
1476
1477 rctl = er32(RCTL);
1478 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1479 ew32(RCTL, rctl);
1480
1481 switch (hw->mac.type) {
1482 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001483 if (hw->phy.media_type == e1000_media_type_fiber ||
1484 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001485 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001486 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001487 adapter->tx_fifo_head = 0;
1488 }
1489 /* fall through */
1490 case e1000_82571:
1491 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001492 if (hw->phy.media_type == e1000_media_type_fiber ||
1493 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001494#define E1000_SERDES_LB_OFF 0x400
1495 ew32(SCTL, E1000_SERDES_LB_OFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001496 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001497 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001498 break;
1499 }
1500 /* Fall Through */
1501 default:
1502 hw->mac.autoneg = 1;
1503 if (hw->phy.type == e1000_phy_gg82563)
1504 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1505 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1506 if (phy_reg & MII_CR_LOOPBACK) {
1507 phy_reg &= ~MII_CR_LOOPBACK;
1508 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1509 e1000e_commit_phy(hw);
1510 }
1511 break;
1512 }
1513}
1514
1515static void e1000_create_lbtest_frame(struct sk_buff *skb,
1516 unsigned int frame_size)
1517{
1518 memset(skb->data, 0xFF, frame_size);
1519 frame_size &= ~1;
1520 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1521 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1522 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1523}
1524
1525static int e1000_check_lbtest_frame(struct sk_buff *skb,
1526 unsigned int frame_size)
1527{
1528 frame_size &= ~1;
1529 if (*(skb->data + 3) == 0xFF)
1530 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1531 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1532 return 0;
1533 return 13;
1534}
1535
1536static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1537{
1538 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1539 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1540 struct pci_dev *pdev = adapter->pdev;
1541 struct e1000_hw *hw = &adapter->hw;
1542 int i, j, k, l;
1543 int lc;
1544 int good_cnt;
1545 int ret_val = 0;
1546 unsigned long time;
1547
Bruce Allan1e360522012-03-20 03:48:13 +00001548 ew32(RDT(0), rx_ring->count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001549
Bruce Allanad680762008-03-28 09:15:03 -07001550 /*
1551 * Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001552 * The idea is to wrap the largest ring a number of times using 64
1553 * send/receive pairs during each loop
1554 */
1555
1556 if (rx_ring->count <= tx_ring->count)
1557 lc = ((tx_ring->count / 64) * 2) + 1;
1558 else
1559 lc = ((rx_ring->count / 64) * 2) + 1;
1560
1561 k = 0;
1562 l = 0;
1563 for (j = 0; j <= lc; j++) { /* loop count loop */
1564 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001565 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1566 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001567 dma_sync_single_for_device(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001568 tx_ring->buffer_info[k].dma,
1569 tx_ring->buffer_info[k].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001570 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001571 k++;
1572 if (k == tx_ring->count)
1573 k = 0;
1574 }
Bruce Allan1e360522012-03-20 03:48:13 +00001575 ew32(TDT(0), k);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001576 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001577 msleep(200);
1578 time = jiffies; /* set the start time for the receive */
1579 good_cnt = 0;
1580 do { /* receive the sent packets */
Nick Nunley0be3f552010-04-27 13:09:05 +00001581 dma_sync_single_for_cpu(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001582 rx_ring->buffer_info[l].dma, 2048,
Nick Nunley0be3f552010-04-27 13:09:05 +00001583 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001584
1585 ret_val = e1000_check_lbtest_frame(
1586 rx_ring->buffer_info[l].skb, 1024);
1587 if (!ret_val)
1588 good_cnt++;
1589 l++;
1590 if (l == rx_ring->count)
1591 l = 0;
Bruce Allanad680762008-03-28 09:15:03 -07001592 /*
1593 * time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001594 * enough time to complete the receives, if it's
1595 * exceeded, break and error off
1596 */
1597 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1598 if (good_cnt != 64) {
1599 ret_val = 13; /* ret_val is the same as mis-compare */
1600 break;
1601 }
Bruce Allancef8c792008-04-02 13:48:23 -07001602 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001603 ret_val = 14; /* error code for time out error */
1604 break;
1605 }
1606 } /* end loop count loop */
1607 return ret_val;
1608}
1609
1610static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1611{
Bruce Allan44abd5c2012-02-22 09:02:37 +00001612 struct e1000_hw *hw = &adapter->hw;
1613
Bruce Allanad680762008-03-28 09:15:03 -07001614 /*
1615 * PHY loopback cannot be performed if SoL/IDER
1616 * sessions are active
1617 */
Bruce Allan44abd5c2012-02-22 09:02:37 +00001618 if (hw->phy.ops.check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001619 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001620 *data = 0;
1621 goto out;
1622 }
1623
1624 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001625 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001626 goto out;
1627
1628 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001629 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001630 goto err_loopback;
1631
1632 *data = e1000_run_loopback_test(adapter);
1633 e1000_loopback_cleanup(adapter);
1634
1635err_loopback:
1636 e1000_free_desc_rings(adapter);
1637out:
1638 return *data;
1639}
1640
1641static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1642{
1643 struct e1000_hw *hw = &adapter->hw;
1644
1645 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001646 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001647 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001648 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001649
Bruce Allanad680762008-03-28 09:15:03 -07001650 /*
1651 * On some blade server designs, link establishment
1652 * could take as long as 2-3 minutes
1653 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001654 do {
1655 hw->mac.ops.check_for_link(hw);
1656 if (hw->mac.serdes_has_link)
1657 return *data;
1658 msleep(20);
1659 } while (i++ < 3750);
1660
1661 *data = 1;
1662 } else {
1663 hw->mac.ops.check_for_link(hw);
1664 if (hw->mac.autoneg)
Bruce Allan5661aeb2011-02-25 06:36:25 +00001665 /*
1666 * On some Phy/switch combinations, link establishment
1667 * can take a few seconds more than expected.
1668 */
1669 msleep(5000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001670
Bruce Allan5661aeb2011-02-25 06:36:25 +00001671 if (!(er32(STATUS) & E1000_STATUS_LU))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001672 *data = 1;
1673 }
1674 return *data;
1675}
1676
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001677static int e1000e_get_sset_count(struct net_device *netdev, int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001678{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001679 switch (sset) {
1680 case ETH_SS_TEST:
1681 return E1000_TEST_LEN;
1682 case ETH_SS_STATS:
1683 return E1000_STATS_LEN;
1684 default:
1685 return -EOPNOTSUPP;
1686 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001687}
1688
1689static void e1000_diag_test(struct net_device *netdev,
1690 struct ethtool_test *eth_test, u64 *data)
1691{
1692 struct e1000_adapter *adapter = netdev_priv(netdev);
1693 u16 autoneg_advertised;
1694 u8 forced_speed_duplex;
1695 u8 autoneg;
1696 bool if_running = netif_running(netdev);
1697
1698 set_bit(__E1000_TESTING, &adapter->state);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001699
1700 if (!if_running) {
1701 /* Get control of and reset hardware */
1702 if (adapter->flags & FLAG_HAS_AMT)
1703 e1000e_get_hw_control(adapter);
1704
1705 e1000e_power_up_phy(adapter);
1706
1707 adapter->hw.phy.autoneg_wait_to_complete = 1;
1708 e1000e_reset(adapter);
1709 adapter->hw.phy.autoneg_wait_to_complete = 0;
1710 }
1711
Auke Kokbc7f75f2007-09-17 12:30:59 -07001712 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1713 /* Offline tests */
1714
1715 /* save speed, duplex, autoneg settings */
1716 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1717 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1718 autoneg = adapter->hw.mac.autoneg;
1719
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001720 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001721
Auke Kokbc7f75f2007-09-17 12:30:59 -07001722 if (if_running)
1723 /* indicate we're in test mode */
1724 dev_close(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001725
1726 if (e1000_reg_test(adapter, &data[0]))
1727 eth_test->flags |= ETH_TEST_FL_FAILED;
1728
1729 e1000e_reset(adapter);
1730 if (e1000_eeprom_test(adapter, &data[1]))
1731 eth_test->flags |= ETH_TEST_FL_FAILED;
1732
1733 e1000e_reset(adapter);
1734 if (e1000_intr_test(adapter, &data[2]))
1735 eth_test->flags |= ETH_TEST_FL_FAILED;
1736
1737 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001738 if (e1000_loopback_test(adapter, &data[3]))
1739 eth_test->flags |= ETH_TEST_FL_FAILED;
1740
Auke Kokbc7f75f2007-09-17 12:30:59 -07001741 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001742 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001743 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001744 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001745
Carolyn Wybornyc6ce3852010-10-15 17:35:31 +00001746 if (e1000_link_test(adapter, &data[4]))
1747 eth_test->flags |= ETH_TEST_FL_FAILED;
1748
1749 /* restore speed, duplex, autoneg settings */
1750 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1751 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1752 adapter->hw.mac.autoneg = autoneg;
1753 e1000e_reset(adapter);
1754
Auke Kokbc7f75f2007-09-17 12:30:59 -07001755 clear_bit(__E1000_TESTING, &adapter->state);
1756 if (if_running)
1757 dev_open(netdev);
1758 } else {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001759 /* Online tests */
Bruce Allan11b08be2010-05-10 14:59:31 +00001760
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001761 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001762
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001763 /* register, eeprom, intr and loopback tests not run online */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001764 data[0] = 0;
1765 data[1] = 0;
1766 data[2] = 0;
1767 data[3] = 0;
1768
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001769 if (e1000_link_test(adapter, &data[4]))
1770 eth_test->flags |= ETH_TEST_FL_FAILED;
Bruce Allan11b08be2010-05-10 14:59:31 +00001771
Auke Kokbc7f75f2007-09-17 12:30:59 -07001772 clear_bit(__E1000_TESTING, &adapter->state);
1773 }
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001774
1775 if (!if_running) {
1776 e1000e_reset(adapter);
1777
1778 if (adapter->flags & FLAG_HAS_AMT)
1779 e1000e_release_hw_control(adapter);
1780 }
1781
Auke Kokbc7f75f2007-09-17 12:30:59 -07001782 msleep_interruptible(4 * 1000);
1783}
1784
1785static void e1000_get_wol(struct net_device *netdev,
1786 struct ethtool_wolinfo *wol)
1787{
1788 struct e1000_adapter *adapter = netdev_priv(netdev);
1789
1790 wol->supported = 0;
1791 wol->wolopts = 0;
1792
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001793 if (!(adapter->flags & FLAG_HAS_WOL) ||
1794 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001795 return;
1796
1797 wol->supported = WAKE_UCAST | WAKE_MCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001798 WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001799
1800 /* apply any specific unsupported masks here */
1801 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1802 wol->supported &= ~WAKE_UCAST;
1803
1804 if (adapter->wol & E1000_WUFC_EX)
Bruce Allan6ad65142012-04-12 05:47:09 +00001805 e_err("Interface does not support directed (unicast) frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001806 }
1807
1808 if (adapter->wol & E1000_WUFC_EX)
1809 wol->wolopts |= WAKE_UCAST;
1810 if (adapter->wol & E1000_WUFC_MC)
1811 wol->wolopts |= WAKE_MCAST;
1812 if (adapter->wol & E1000_WUFC_BC)
1813 wol->wolopts |= WAKE_BCAST;
1814 if (adapter->wol & E1000_WUFC_MAG)
1815 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001816 if (adapter->wol & E1000_WUFC_LNKC)
1817 wol->wolopts |= WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001818}
1819
Bruce Allan4a29e152011-03-04 09:07:01 +00001820static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001821{
1822 struct e1000_adapter *adapter = netdev_priv(netdev);
1823
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001824 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001825 !device_can_wakeup(&adapter->pdev->dev) ||
1826 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001827 WAKE_MAGIC | WAKE_PHY)))
Bruce Allan1fbfca32009-11-20 23:22:01 +00001828 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001829
1830 /* these settings will always override what we currently have */
1831 adapter->wol = 0;
1832
1833 if (wol->wolopts & WAKE_UCAST)
1834 adapter->wol |= E1000_WUFC_EX;
1835 if (wol->wolopts & WAKE_MCAST)
1836 adapter->wol |= E1000_WUFC_MC;
1837 if (wol->wolopts & WAKE_BCAST)
1838 adapter->wol |= E1000_WUFC_BC;
1839 if (wol->wolopts & WAKE_MAGIC)
1840 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001841 if (wol->wolopts & WAKE_PHY)
1842 adapter->wol |= E1000_WUFC_LNKC;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001843
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001844 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1845
Auke Kokbc7f75f2007-09-17 12:30:59 -07001846 return 0;
1847}
1848
Bruce Allandbf80dc2011-04-16 00:34:40 +00001849static int e1000_set_phys_id(struct net_device *netdev,
1850 enum ethtool_phys_id_state state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001851{
1852 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001853 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001854
Bruce Allandbf80dc2011-04-16 00:34:40 +00001855 switch (state) {
1856 case ETHTOOL_ID_ACTIVE:
1857 if (!hw->mac.ops.blink_led)
1858 return 2; /* cycle on/off twice per second */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001859
Bruce Allandbf80dc2011-04-16 00:34:40 +00001860 hw->mac.ops.blink_led(hw);
1861 break;
1862
1863 case ETHTOOL_ID_INACTIVE:
Bruce Allan4662e822008-08-26 18:37:06 -07001864 if (hw->phy.type == e1000_phy_ife)
1865 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001866 hw->mac.ops.led_off(hw);
1867 hw->mac.ops.cleanup_led(hw);
1868 break;
1869
1870 case ETHTOOL_ID_ON:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001871 hw->mac.ops.led_on(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001872 break;
1873
1874 case ETHTOOL_ID_OFF:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001875 hw->mac.ops.led_off(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001876 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001877 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001878 return 0;
1879}
1880
Auke Kokde5b3072008-04-23 11:09:08 -07001881static int e1000_get_coalesce(struct net_device *netdev,
1882 struct ethtool_coalesce *ec)
1883{
1884 struct e1000_adapter *adapter = netdev_priv(netdev);
1885
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001886 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07001887 ec->rx_coalesce_usecs = adapter->itr_setting;
1888 else
1889 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1890
1891 return 0;
1892}
1893
1894static int e1000_set_coalesce(struct net_device *netdev,
1895 struct ethtool_coalesce *ec)
1896{
1897 struct e1000_adapter *adapter = netdev_priv(netdev);
1898 struct e1000_hw *hw = &adapter->hw;
1899
1900 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001901 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07001902 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1903 (ec->rx_coalesce_usecs == 2))
1904 return -EINVAL;
1905
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001906 if (ec->rx_coalesce_usecs == 4) {
1907 adapter->itr = adapter->itr_setting = 4;
1908 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07001909 adapter->itr = 20000;
1910 adapter->itr_setting = ec->rx_coalesce_usecs;
1911 } else {
1912 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1913 adapter->itr_setting = adapter->itr & ~3;
1914 }
1915
1916 if (adapter->itr_setting != 0)
1917 ew32(ITR, 1000000000 / (adapter->itr * 256));
1918 else
1919 ew32(ITR, 0);
1920
1921 return 0;
1922}
1923
Auke Kokbc7f75f2007-09-17 12:30:59 -07001924static int e1000_nway_reset(struct net_device *netdev)
1925{
1926 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan5962bc22011-01-20 06:58:07 +00001927
1928 if (!netif_running(netdev))
1929 return -EAGAIN;
1930
1931 if (!adapter->hw.mac.autoneg)
1932 return -EINVAL;
1933
1934 e1000e_reinit_locked(adapter);
1935
Auke Kokbc7f75f2007-09-17 12:30:59 -07001936 return 0;
1937}
1938
Auke Kokbc7f75f2007-09-17 12:30:59 -07001939static void e1000_get_ethtool_stats(struct net_device *netdev,
1940 struct ethtool_stats *stats,
1941 u64 *data)
1942{
1943 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001944 struct rtnl_link_stats64 net_stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001945 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001946 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001947
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001948 e1000e_get_stats64(netdev, &net_stats);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001949 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001950 switch (e1000_gstrings_stats[i].type) {
1951 case NETDEV_STATS:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001952 p = (char *) &net_stats +
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001953 e1000_gstrings_stats[i].stat_offset;
1954 break;
1955 case E1000_STATS:
1956 p = (char *) adapter +
1957 e1000_gstrings_stats[i].stat_offset;
1958 break;
Bruce Allan61c75812010-12-09 23:04:25 +00001959 default:
1960 data[i] = 0;
1961 continue;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001962 }
1963
Auke Kokbc7f75f2007-09-17 12:30:59 -07001964 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1965 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1966 }
1967}
1968
1969static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1970 u8 *data)
1971{
1972 u8 *p = data;
1973 int i;
1974
1975 switch (stringset) {
1976 case ETH_SS_TEST:
Bruce Allan5c1bda02011-01-19 04:23:39 +00001977 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001978 break;
1979 case ETH_SS_STATS:
1980 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1981 memcpy(p, e1000_gstrings_stats[i].stat_string,
1982 ETH_GSTRING_LEN);
1983 p += ETH_GSTRING_LEN;
1984 }
1985 break;
1986 }
1987}
1988
Bruce Allan70495a52012-01-11 01:26:50 +00001989static int e1000_get_rxnfc(struct net_device *netdev,
1990 struct ethtool_rxnfc *info, u32 *rule_locs)
1991{
1992 info->data = 0;
1993
1994 switch (info->cmd) {
1995 case ETHTOOL_GRXFH: {
1996 struct e1000_adapter *adapter = netdev_priv(netdev);
1997 struct e1000_hw *hw = &adapter->hw;
1998 u32 mrqc = er32(MRQC);
1999
2000 if (!(mrqc & E1000_MRQC_RSS_FIELD_MASK))
2001 return 0;
2002
2003 switch (info->flow_type) {
2004 case TCP_V4_FLOW:
2005 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP)
2006 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2007 /* fall through */
2008 case UDP_V4_FLOW:
2009 case SCTP_V4_FLOW:
2010 case AH_ESP_V4_FLOW:
2011 case IPV4_FLOW:
2012 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4)
2013 info->data |= RXH_IP_SRC | RXH_IP_DST;
2014 break;
2015 case TCP_V6_FLOW:
2016 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP)
2017 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2018 /* fall through */
2019 case UDP_V6_FLOW:
2020 case SCTP_V6_FLOW:
2021 case AH_ESP_V6_FLOW:
2022 case IPV6_FLOW:
2023 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6)
2024 info->data |= RXH_IP_SRC | RXH_IP_DST;
2025 break;
2026 default:
2027 break;
2028 }
2029 return 0;
2030 }
2031 default:
2032 return -EOPNOTSUPP;
2033 }
2034}
2035
Auke Kokbc7f75f2007-09-17 12:30:59 -07002036static const struct ethtool_ops e1000_ethtool_ops = {
2037 .get_settings = e1000_get_settings,
2038 .set_settings = e1000_set_settings,
2039 .get_drvinfo = e1000_get_drvinfo,
2040 .get_regs_len = e1000_get_regs_len,
2041 .get_regs = e1000_get_regs,
2042 .get_wol = e1000_get_wol,
2043 .set_wol = e1000_set_wol,
2044 .get_msglevel = e1000_get_msglevel,
2045 .set_msglevel = e1000_set_msglevel,
2046 .nway_reset = e1000_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00002047 .get_link = ethtool_op_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002048 .get_eeprom_len = e1000_get_eeprom_len,
2049 .get_eeprom = e1000_get_eeprom,
2050 .set_eeprom = e1000_set_eeprom,
2051 .get_ringparam = e1000_get_ringparam,
2052 .set_ringparam = e1000_set_ringparam,
2053 .get_pauseparam = e1000_get_pauseparam,
2054 .set_pauseparam = e1000_set_pauseparam,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002055 .self_test = e1000_diag_test,
2056 .get_strings = e1000_get_strings,
Bruce Allandbf80dc2011-04-16 00:34:40 +00002057 .set_phys_id = e1000_set_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002058 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07002059 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07002060 .get_coalesce = e1000_get_coalesce,
2061 .set_coalesce = e1000_set_coalesce,
Bruce Allan70495a52012-01-11 01:26:50 +00002062 .get_rxnfc = e1000_get_rxnfc,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002063};
2064
2065void e1000e_set_ethtool_ops(struct net_device *netdev)
2066{
2067 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
2068}