blob: 4f1edd9c22f158b2a3427bb719085c87df9f68bb [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;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700776
Bruce Allanad680762008-03-28 09:15:03 -0700777 /*
778 * The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700779 * Some bits that get toggled are ignored.
780 */
781 switch (mac->type) {
782 /* there are several bits on newer hardware that are r/w */
783 case e1000_82571:
784 case e1000_82572:
785 case e1000_80003es2lan:
786 toggle = 0x7FFFF3FF;
787 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000788 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700789 toggle = 0x7FFFF033;
790 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700791 }
792
793 before = er32(STATUS);
794 value = (er32(STATUS) & toggle);
795 ew32(STATUS, toggle);
796 after = er32(STATUS) & toggle;
797 if (value != after) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000798 e_err("failed STATUS register test got: 0x%08X expected: 0x%08X\n",
799 after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700800 *data = 1;
801 return 1;
802 }
803 /* restore previous status */
804 ew32(STATUS, before);
805
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700806 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700807 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
808 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
809 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
810 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
811 }
812
813 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000814 REG_PATTERN_TEST(E1000_RDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
815 REG_PATTERN_TEST(E1000_RDLEN(0), 0x000FFF80, 0x000FFFFF);
816 REG_PATTERN_TEST(E1000_RDH(0), 0x0000FFFF, 0x0000FFFF);
817 REG_PATTERN_TEST(E1000_RDT(0), 0x0000FFFF, 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700818 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
819 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
820 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000821 REG_PATTERN_TEST(E1000_TDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
822 REG_PATTERN_TEST(E1000_TDLEN(0), 0x000FFF80, 0x000FFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700823
824 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
825
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700826 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700827 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
828 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
829
Auke Kok86582512007-10-04 15:00:08 -0700830 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000831 REG_PATTERN_TEST(E1000_RDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700832 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700833 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000834 REG_PATTERN_TEST(E1000_TDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
Auke Kok86582512007-10-04 15:00:08 -0700835 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000836 mask = 0x8003FFFF;
837 switch (mac->type) {
838 case e1000_ich10lan:
839 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000840 case e1000_pch2lan:
Bruce Allana4f58f52009-06-02 11:29:18 +0000841 mask |= (1 << 18);
842 break;
843 default:
844 break;
845 }
Auke Kok86582512007-10-04 15:00:08 -0700846 for (i = 0; i < mac->rar_entry_count; i++)
847 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
Bruce Allana4f58f52009-06-02 11:29:18 +0000848 mask, 0xFFFFFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700849
850 for (i = 0; i < mac->mta_reg_count; i++)
851 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
852
853 *data = 0;
854 return 0;
855}
856
857static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
858{
859 u16 temp;
860 u16 checksum = 0;
861 u16 i;
862
863 *data = 0;
864 /* Read and add up the contents of the EEPROM */
865 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
866 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
867 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800868 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700869 }
870 checksum += temp;
871 }
872
873 /* If Checksum is not Correct return error else test passed */
874 if ((checksum != (u16) NVM_SUM) && !(*data))
875 *data = 2;
876
877 return *data;
878}
879
880static irqreturn_t e1000_test_intr(int irq, void *data)
881{
882 struct net_device *netdev = (struct net_device *) data;
883 struct e1000_adapter *adapter = netdev_priv(netdev);
884 struct e1000_hw *hw = &adapter->hw;
885
886 adapter->test_icr |= er32(ICR);
887
888 return IRQ_HANDLED;
889}
890
891static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
892{
893 struct net_device *netdev = adapter->netdev;
894 struct e1000_hw *hw = &adapter->hw;
895 u32 mask;
896 u32 shared_int = 1;
897 u32 irq = adapter->pdev->irq;
898 int i;
Bruce Allan4662e822008-08-26 18:37:06 -0700899 int ret_val = 0;
900 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700901
902 *data = 0;
903
Bruce Allan4662e822008-08-26 18:37:06 -0700904 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
905 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
906 int_mode = adapter->int_mode;
907 e1000e_reset_interrupt_capability(adapter);
908 adapter->int_mode = E1000E_INT_MODE_LEGACY;
909 e1000e_set_interrupt_capability(adapter);
910 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700911 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800912 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700913 netdev)) {
914 shared_int = 0;
Joe Perchesa0607fd2009-11-18 23:29:17 -0800915 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700916 netdev->name, netdev)) {
917 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700918 ret_val = -1;
919 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700920 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700921 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700922
923 /* Disable all the interrupts */
924 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000925 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000926 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700927
928 /* Test each interrupt */
929 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700930 /* Interrupt to test */
931 mask = 1 << i;
932
Bruce Allanf4187b52008-08-26 18:36:50 -0700933 if (adapter->flags & FLAG_IS_ICH) {
934 switch (mask) {
935 case E1000_ICR_RXSEQ:
936 continue;
937 case 0x00000100:
938 if (adapter->hw.mac.type == e1000_ich8lan ||
939 adapter->hw.mac.type == e1000_ich9lan)
940 continue;
941 break;
942 default:
943 break;
944 }
945 }
946
Auke Kokbc7f75f2007-09-17 12:30:59 -0700947 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700948 /*
949 * Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700950 * the cause register and then force the same
951 * interrupt and see if one gets posted. If
952 * an interrupt was posted to the bus, the
953 * test failed.
954 */
955 adapter->test_icr = 0;
956 ew32(IMC, mask);
957 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000958 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000959 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700960
961 if (adapter->test_icr & mask) {
962 *data = 3;
963 break;
964 }
965 }
966
Bruce Allanad680762008-03-28 09:15:03 -0700967 /*
968 * Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700969 * the cause register and then force the same
970 * interrupt and see if one gets posted. If
971 * an interrupt was not posted to the bus, the
972 * test failed.
973 */
974 adapter->test_icr = 0;
975 ew32(IMS, mask);
976 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000977 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000978 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700979
980 if (!(adapter->test_icr & mask)) {
981 *data = 4;
982 break;
983 }
984
985 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700986 /*
987 * Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700988 * the cause register and then force the other
989 * interrupts and see if any get posted. If
990 * an interrupt was posted to the bus, the
991 * test failed.
992 */
993 adapter->test_icr = 0;
994 ew32(IMC, ~mask & 0x00007FFF);
995 ew32(ICS, ~mask & 0x00007FFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000996 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000997 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700998
999 if (adapter->test_icr) {
1000 *data = 5;
1001 break;
1002 }
1003 }
1004 }
1005
1006 /* Disable all the interrupts */
1007 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001008 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001009 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001010
1011 /* Unhook test interrupt handler */
1012 free_irq(irq, netdev);
1013
Bruce Allan4662e822008-08-26 18:37:06 -07001014out:
1015 if (int_mode == E1000E_INT_MODE_MSIX) {
1016 e1000e_reset_interrupt_capability(adapter);
1017 adapter->int_mode = int_mode;
1018 e1000e_set_interrupt_capability(adapter);
1019 }
1020
1021 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001022}
1023
1024static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1025{
1026 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1027 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1028 struct pci_dev *pdev = adapter->pdev;
1029 int i;
1030
1031 if (tx_ring->desc && tx_ring->buffer_info) {
1032 for (i = 0; i < tx_ring->count; i++) {
1033 if (tx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001034 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001035 tx_ring->buffer_info[i].dma,
1036 tx_ring->buffer_info[i].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001037 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001038 if (tx_ring->buffer_info[i].skb)
1039 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1040 }
1041 }
1042
1043 if (rx_ring->desc && rx_ring->buffer_info) {
1044 for (i = 0; i < rx_ring->count; i++) {
1045 if (rx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001046 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001047 rx_ring->buffer_info[i].dma,
Nick Nunley0be3f552010-04-27 13:09:05 +00001048 2048, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001049 if (rx_ring->buffer_info[i].skb)
1050 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1051 }
1052 }
1053
1054 if (tx_ring->desc) {
1055 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1056 tx_ring->dma);
1057 tx_ring->desc = NULL;
1058 }
1059 if (rx_ring->desc) {
1060 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1061 rx_ring->dma);
1062 rx_ring->desc = NULL;
1063 }
1064
1065 kfree(tx_ring->buffer_info);
1066 tx_ring->buffer_info = NULL;
1067 kfree(rx_ring->buffer_info);
1068 rx_ring->buffer_info = NULL;
1069}
1070
1071static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1072{
1073 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1074 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1075 struct pci_dev *pdev = adapter->pdev;
1076 struct e1000_hw *hw = &adapter->hw;
1077 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001078 int i;
1079 int ret_val;
1080
1081 /* Setup Tx descriptor ring and Tx buffers */
1082
1083 if (!tx_ring->count)
1084 tx_ring->count = E1000_DEFAULT_TXD;
1085
Bruce Allancef8c792008-04-02 13:48:23 -07001086 tx_ring->buffer_info = kcalloc(tx_ring->count,
1087 sizeof(struct e1000_buffer),
1088 GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001089 if (!tx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001090 ret_val = 1;
1091 goto err_nomem;
1092 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001093
1094 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1095 tx_ring->size = ALIGN(tx_ring->size, 4096);
1096 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1097 &tx_ring->dma, GFP_KERNEL);
1098 if (!tx_ring->desc) {
1099 ret_val = 2;
1100 goto err_nomem;
1101 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001102 tx_ring->next_to_use = 0;
1103 tx_ring->next_to_clean = 0;
1104
Bruce Allan1e360522012-03-20 03:48:13 +00001105 ew32(TDBAL(0), ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
1106 ew32(TDBAH(0), ((u64) tx_ring->dma >> 32));
1107 ew32(TDLEN(0), tx_ring->count * sizeof(struct e1000_tx_desc));
1108 ew32(TDH(0), 0);
1109 ew32(TDT(0), 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001110 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1111 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1112 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001113
1114 for (i = 0; i < tx_ring->count; i++) {
1115 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1116 struct sk_buff *skb;
1117 unsigned int skb_size = 1024;
1118
1119 skb = alloc_skb(skb_size, GFP_KERNEL);
1120 if (!skb) {
1121 ret_val = 3;
1122 goto err_nomem;
1123 }
1124 skb_put(skb, skb_size);
1125 tx_ring->buffer_info[i].skb = skb;
1126 tx_ring->buffer_info[i].length = skb->len;
1127 tx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001128 dma_map_single(&pdev->dev, skb->data, skb->len,
1129 DMA_TO_DEVICE);
1130 if (dma_mapping_error(&pdev->dev,
1131 tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001132 ret_val = 4;
1133 goto err_nomem;
1134 }
Bruce Allancef8c792008-04-02 13:48:23 -07001135 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001136 tx_desc->lower.data = cpu_to_le32(skb->len);
1137 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1138 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001139 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001140 tx_desc->upper.data = 0;
1141 }
1142
1143 /* Setup Rx descriptor ring and Rx buffers */
1144
1145 if (!rx_ring->count)
1146 rx_ring->count = E1000_DEFAULT_RXD;
1147
Bruce Allancef8c792008-04-02 13:48:23 -07001148 rx_ring->buffer_info = kcalloc(rx_ring->count,
1149 sizeof(struct e1000_buffer),
1150 GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001151 if (!rx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001152 ret_val = 5;
1153 goto err_nomem;
1154 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001155
Bruce Allan5f450212011-07-22 06:21:46 +00001156 rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001157 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1158 &rx_ring->dma, GFP_KERNEL);
1159 if (!rx_ring->desc) {
1160 ret_val = 6;
1161 goto err_nomem;
1162 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001163 rx_ring->next_to_use = 0;
1164 rx_ring->next_to_clean = 0;
1165
1166 rctl = er32(RCTL);
Bruce Allan7f99ae62011-07-22 06:21:35 +00001167 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
1168 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan1e360522012-03-20 03:48:13 +00001169 ew32(RDBAL(0), ((u64) rx_ring->dma & 0xFFFFFFFF));
1170 ew32(RDBAH(0), ((u64) rx_ring->dma >> 32));
1171 ew32(RDLEN(0), rx_ring->size);
1172 ew32(RDH(0), 0);
1173 ew32(RDT(0), 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001174 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allancef8c792008-04-02 13:48:23 -07001175 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1176 E1000_RCTL_SBP | E1000_RCTL_SECRC |
Auke Kokbc7f75f2007-09-17 12:30:59 -07001177 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1178 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1179 ew32(RCTL, rctl);
1180
1181 for (i = 0; i < rx_ring->count; i++) {
Bruce Allan5f450212011-07-22 06:21:46 +00001182 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001183 struct sk_buff *skb;
1184
1185 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1186 if (!skb) {
1187 ret_val = 7;
1188 goto err_nomem;
1189 }
1190 skb_reserve(skb, NET_IP_ALIGN);
1191 rx_ring->buffer_info[i].skb = skb;
1192 rx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001193 dma_map_single(&pdev->dev, skb->data, 2048,
1194 DMA_FROM_DEVICE);
1195 if (dma_mapping_error(&pdev->dev,
1196 rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001197 ret_val = 8;
1198 goto err_nomem;
1199 }
Bruce Allan5f450212011-07-22 06:21:46 +00001200 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1201 rx_desc->read.buffer_addr =
1202 cpu_to_le64(rx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001203 memset(skb->data, 0x00, skb->len);
1204 }
1205
1206 return 0;
1207
1208err_nomem:
1209 e1000_free_desc_rings(adapter);
1210 return ret_val;
1211}
1212
1213static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1214{
1215 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1216 e1e_wphy(&adapter->hw, 29, 0x001F);
1217 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1218 e1e_wphy(&adapter->hw, 29, 0x001A);
1219 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1220}
1221
1222static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1223{
1224 struct e1000_hw *hw = &adapter->hw;
1225 u32 ctrl_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001226 u16 phy_reg = 0;
Bruce Allancbd006c2010-11-24 06:01:30 +00001227 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001228
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001229 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001230
Bruce Allan3af50482010-06-16 13:25:55 +00001231 if (hw->phy.type == e1000_phy_ife) {
1232 /* force 100, set loopback */
1233 e1e_wphy(hw, PHY_CONTROL, 0x6100);
Bruce Allanbb436b22009-11-20 23:24:11 +00001234
Bruce Allan3af50482010-06-16 13:25:55 +00001235 /* Now set up the MAC to the same speed/duplex as the PHY. */
1236 ctrl_reg = er32(CTRL);
1237 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1238 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1239 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1240 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1241 E1000_CTRL_FD); /* Force Duplex to FULL */
1242
1243 ew32(CTRL, ctrl_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001244 e1e_flush();
Bruce Allan3af50482010-06-16 13:25:55 +00001245 udelay(500);
1246
1247 return 0;
1248 }
1249
1250 /* Specific PHY configuration for loopback */
1251 switch (hw->phy.type) {
1252 case e1000_phy_m88:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001253 /* Auto-MDI/MDIX Off */
1254 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1255 /* reset to update Auto-MDI/MDIX */
1256 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1257 /* autoneg off */
1258 e1e_wphy(hw, PHY_CONTROL, 0x8140);
Bruce Allan3af50482010-06-16 13:25:55 +00001259 break;
1260 case e1000_phy_gg82563:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001261 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
Bruce Allancef8c792008-04-02 13:48:23 -07001262 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001263 case e1000_phy_bm:
1264 /* Set Default MAC Interface speed to 1GB */
1265 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1266 phy_reg &= ~0x0007;
1267 phy_reg |= 0x006;
1268 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1269 /* Assert SW reset for above settings to take effect */
1270 e1000e_commit_phy(hw);
1271 mdelay(1);
1272 /* Force Full Duplex */
1273 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1274 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1275 /* Set Link Up (in force link) */
1276 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1277 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1278 /* Force Link */
1279 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1280 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1281 /* Set Early Link Enable */
1282 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1283 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
Bruce Allan3af50482010-06-16 13:25:55 +00001284 break;
1285 case e1000_phy_82577:
1286 case e1000_phy_82578:
1287 /* Workaround: K1 must be disabled for stable 1Gbps operation */
Bruce Allancbd006c2010-11-24 06:01:30 +00001288 ret_val = hw->phy.ops.acquire(hw);
1289 if (ret_val) {
1290 e_err("Cannot setup 1Gbps loopback.\n");
1291 return ret_val;
1292 }
Bruce Allan3af50482010-06-16 13:25:55 +00001293 e1000_configure_k1_ich8lan(hw, false);
Bruce Allancbd006c2010-11-24 06:01:30 +00001294 hw->phy.ops.release(hw);
Bruce Allan3af50482010-06-16 13:25:55 +00001295 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001296 case e1000_phy_82579:
1297 /* Disable PHY energy detect power down */
1298 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1299 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
1300 /* Disable full chip energy detect */
1301 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1302 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1303 /* Enable loopback on the PHY */
1304#define I82577_PHY_LBK_CTRL 19
1305 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1306 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001307 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001308 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001309 }
1310
Bruce Allan3af50482010-06-16 13:25:55 +00001311 /* force 1000, set loopback */
1312 e1e_wphy(hw, PHY_CONTROL, 0x4140);
1313 mdelay(250);
1314
1315 /* Now set up the MAC to the same speed/duplex as the PHY. */
1316 ctrl_reg = er32(CTRL);
1317 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1318 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1319 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1320 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1321 E1000_CTRL_FD); /* Force Duplex to FULL */
1322
1323 if (adapter->flags & FLAG_IS_ICH)
1324 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1325
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001326 if (hw->phy.media_type == e1000_media_type_copper &&
1327 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001328 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1329 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001330 /*
1331 * Set the ILOS bit on the fiber Nic if half duplex link is
1332 * detected.
1333 */
Bruce Allan90da0662011-01-06 07:02:53 +00001334 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001335 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1336 }
1337
1338 ew32(CTRL, ctrl_reg);
1339
Bruce Allanad680762008-03-28 09:15:03 -07001340 /*
1341 * Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001342 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1343 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001344 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001345 e1000_phy_disable_receiver(adapter);
1346
1347 udelay(500);
1348
1349 return 0;
1350}
1351
1352static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1353{
1354 struct e1000_hw *hw = &adapter->hw;
1355 u32 ctrl = er32(CTRL);
1356 int link = 0;
1357
1358 /* special requirements for 82571/82572 fiber adapters */
1359
Bruce Allanad680762008-03-28 09:15:03 -07001360 /*
1361 * jump through hoops to make sure link is up because serdes
1362 * link is hardwired up
1363 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001364 ctrl |= E1000_CTRL_SLU;
1365 ew32(CTRL, ctrl);
1366
1367 /* disable autoneg */
1368 ctrl = er32(TXCW);
1369 ctrl &= ~(1 << 31);
1370 ew32(TXCW, ctrl);
1371
1372 link = (er32(STATUS) & E1000_STATUS_LU);
1373
1374 if (!link) {
1375 /* set invert loss of signal */
1376 ctrl = er32(CTRL);
1377 ctrl |= E1000_CTRL_ILOS;
1378 ew32(CTRL, ctrl);
1379 }
1380
Bruce Allanad680762008-03-28 09:15:03 -07001381 /*
1382 * special write to serdes control register to enable SerDes analog
1383 * loopback
1384 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001385#define E1000_SERDES_LB_ON 0x410
1386 ew32(SCTL, E1000_SERDES_LB_ON);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001387 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001388 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001389
1390 return 0;
1391}
1392
1393/* only call this for fiber/serdes connections to es2lan */
1394static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1395{
1396 struct e1000_hw *hw = &adapter->hw;
1397 u32 ctrlext = er32(CTRL_EXT);
1398 u32 ctrl = er32(CTRL);
1399
Bruce Allanad680762008-03-28 09:15:03 -07001400 /*
1401 * save CTRL_EXT to restore later, reuse an empty variable (unused
1402 * on mac_type 80003es2lan)
1403 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001404 adapter->tx_fifo_head = ctrlext;
1405
1406 /* clear the serdes mode bits, putting the device into mac loopback */
1407 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1408 ew32(CTRL_EXT, ctrlext);
1409
1410 /* force speed to 1000/FD, link up */
1411 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1412 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1413 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1414 ew32(CTRL, ctrl);
1415
1416 /* set mac loopback */
1417 ctrl = er32(RCTL);
1418 ctrl |= E1000_RCTL_LBM_MAC;
1419 ew32(RCTL, ctrl);
1420
1421 /* set testing mode parameters (no need to reset later) */
1422#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1423#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1424 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001425 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001426
1427 return 0;
1428}
1429
1430static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1431{
1432 struct e1000_hw *hw = &adapter->hw;
1433 u32 rctl;
1434
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001435 if (hw->phy.media_type == e1000_media_type_fiber ||
1436 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001437 switch (hw->mac.type) {
1438 case e1000_80003es2lan:
1439 return e1000_set_es2lan_mac_loopback(adapter);
1440 break;
1441 case e1000_82571:
1442 case e1000_82572:
1443 return e1000_set_82571_fiber_loopback(adapter);
1444 break;
1445 default:
1446 rctl = er32(RCTL);
1447 rctl |= E1000_RCTL_LBM_TCVR;
1448 ew32(RCTL, rctl);
1449 return 0;
1450 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001451 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001452 return e1000_integrated_phy_loopback(adapter);
1453 }
1454
1455 return 7;
1456}
1457
1458static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1459{
1460 struct e1000_hw *hw = &adapter->hw;
1461 u32 rctl;
1462 u16 phy_reg;
1463
1464 rctl = er32(RCTL);
1465 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1466 ew32(RCTL, rctl);
1467
1468 switch (hw->mac.type) {
1469 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001470 if (hw->phy.media_type == e1000_media_type_fiber ||
1471 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001472 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001473 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001474 adapter->tx_fifo_head = 0;
1475 }
1476 /* fall through */
1477 case e1000_82571:
1478 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001479 if (hw->phy.media_type == e1000_media_type_fiber ||
1480 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001481#define E1000_SERDES_LB_OFF 0x400
1482 ew32(SCTL, E1000_SERDES_LB_OFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001483 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001484 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001485 break;
1486 }
1487 /* Fall Through */
1488 default:
1489 hw->mac.autoneg = 1;
1490 if (hw->phy.type == e1000_phy_gg82563)
1491 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1492 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1493 if (phy_reg & MII_CR_LOOPBACK) {
1494 phy_reg &= ~MII_CR_LOOPBACK;
1495 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1496 e1000e_commit_phy(hw);
1497 }
1498 break;
1499 }
1500}
1501
1502static void e1000_create_lbtest_frame(struct sk_buff *skb,
1503 unsigned int frame_size)
1504{
1505 memset(skb->data, 0xFF, frame_size);
1506 frame_size &= ~1;
1507 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1508 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1509 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1510}
1511
1512static int e1000_check_lbtest_frame(struct sk_buff *skb,
1513 unsigned int frame_size)
1514{
1515 frame_size &= ~1;
1516 if (*(skb->data + 3) == 0xFF)
1517 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1518 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1519 return 0;
1520 return 13;
1521}
1522
1523static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1524{
1525 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1526 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1527 struct pci_dev *pdev = adapter->pdev;
1528 struct e1000_hw *hw = &adapter->hw;
1529 int i, j, k, l;
1530 int lc;
1531 int good_cnt;
1532 int ret_val = 0;
1533 unsigned long time;
1534
Bruce Allan1e360522012-03-20 03:48:13 +00001535 ew32(RDT(0), rx_ring->count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001536
Bruce Allanad680762008-03-28 09:15:03 -07001537 /*
1538 * Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001539 * The idea is to wrap the largest ring a number of times using 64
1540 * send/receive pairs during each loop
1541 */
1542
1543 if (rx_ring->count <= tx_ring->count)
1544 lc = ((tx_ring->count / 64) * 2) + 1;
1545 else
1546 lc = ((rx_ring->count / 64) * 2) + 1;
1547
1548 k = 0;
1549 l = 0;
1550 for (j = 0; j <= lc; j++) { /* loop count loop */
1551 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001552 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1553 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001554 dma_sync_single_for_device(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001555 tx_ring->buffer_info[k].dma,
1556 tx_ring->buffer_info[k].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001557 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001558 k++;
1559 if (k == tx_ring->count)
1560 k = 0;
1561 }
Bruce Allan1e360522012-03-20 03:48:13 +00001562 ew32(TDT(0), k);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001563 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001564 msleep(200);
1565 time = jiffies; /* set the start time for the receive */
1566 good_cnt = 0;
1567 do { /* receive the sent packets */
Nick Nunley0be3f552010-04-27 13:09:05 +00001568 dma_sync_single_for_cpu(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001569 rx_ring->buffer_info[l].dma, 2048,
Nick Nunley0be3f552010-04-27 13:09:05 +00001570 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001571
1572 ret_val = e1000_check_lbtest_frame(
1573 rx_ring->buffer_info[l].skb, 1024);
1574 if (!ret_val)
1575 good_cnt++;
1576 l++;
1577 if (l == rx_ring->count)
1578 l = 0;
Bruce Allanad680762008-03-28 09:15:03 -07001579 /*
1580 * time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001581 * enough time to complete the receives, if it's
1582 * exceeded, break and error off
1583 */
1584 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1585 if (good_cnt != 64) {
1586 ret_val = 13; /* ret_val is the same as mis-compare */
1587 break;
1588 }
Bruce Allancef8c792008-04-02 13:48:23 -07001589 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001590 ret_val = 14; /* error code for time out error */
1591 break;
1592 }
1593 } /* end loop count loop */
1594 return ret_val;
1595}
1596
1597static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1598{
Bruce Allan44abd5c2012-02-22 09:02:37 +00001599 struct e1000_hw *hw = &adapter->hw;
1600
Bruce Allanad680762008-03-28 09:15:03 -07001601 /*
1602 * PHY loopback cannot be performed if SoL/IDER
1603 * sessions are active
1604 */
Bruce Allan44abd5c2012-02-22 09:02:37 +00001605 if (hw->phy.ops.check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001606 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001607 *data = 0;
1608 goto out;
1609 }
1610
1611 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001612 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001613 goto out;
1614
1615 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001616 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001617 goto err_loopback;
1618
1619 *data = e1000_run_loopback_test(adapter);
1620 e1000_loopback_cleanup(adapter);
1621
1622err_loopback:
1623 e1000_free_desc_rings(adapter);
1624out:
1625 return *data;
1626}
1627
1628static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1629{
1630 struct e1000_hw *hw = &adapter->hw;
1631
1632 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001633 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001634 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001635 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001636
Bruce Allanad680762008-03-28 09:15:03 -07001637 /*
1638 * On some blade server designs, link establishment
1639 * could take as long as 2-3 minutes
1640 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001641 do {
1642 hw->mac.ops.check_for_link(hw);
1643 if (hw->mac.serdes_has_link)
1644 return *data;
1645 msleep(20);
1646 } while (i++ < 3750);
1647
1648 *data = 1;
1649 } else {
1650 hw->mac.ops.check_for_link(hw);
1651 if (hw->mac.autoneg)
Bruce Allan5661aeb2011-02-25 06:36:25 +00001652 /*
1653 * On some Phy/switch combinations, link establishment
1654 * can take a few seconds more than expected.
1655 */
1656 msleep(5000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001657
Bruce Allan5661aeb2011-02-25 06:36:25 +00001658 if (!(er32(STATUS) & E1000_STATUS_LU))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001659 *data = 1;
1660 }
1661 return *data;
1662}
1663
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001664static int e1000e_get_sset_count(struct net_device *netdev, int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001665{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001666 switch (sset) {
1667 case ETH_SS_TEST:
1668 return E1000_TEST_LEN;
1669 case ETH_SS_STATS:
1670 return E1000_STATS_LEN;
1671 default:
1672 return -EOPNOTSUPP;
1673 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001674}
1675
1676static void e1000_diag_test(struct net_device *netdev,
1677 struct ethtool_test *eth_test, u64 *data)
1678{
1679 struct e1000_adapter *adapter = netdev_priv(netdev);
1680 u16 autoneg_advertised;
1681 u8 forced_speed_duplex;
1682 u8 autoneg;
1683 bool if_running = netif_running(netdev);
1684
1685 set_bit(__E1000_TESTING, &adapter->state);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001686
1687 if (!if_running) {
1688 /* Get control of and reset hardware */
1689 if (adapter->flags & FLAG_HAS_AMT)
1690 e1000e_get_hw_control(adapter);
1691
1692 e1000e_power_up_phy(adapter);
1693
1694 adapter->hw.phy.autoneg_wait_to_complete = 1;
1695 e1000e_reset(adapter);
1696 adapter->hw.phy.autoneg_wait_to_complete = 0;
1697 }
1698
Auke Kokbc7f75f2007-09-17 12:30:59 -07001699 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1700 /* Offline tests */
1701
1702 /* save speed, duplex, autoneg settings */
1703 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1704 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1705 autoneg = adapter->hw.mac.autoneg;
1706
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001707 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001708
Auke Kokbc7f75f2007-09-17 12:30:59 -07001709 if (if_running)
1710 /* indicate we're in test mode */
1711 dev_close(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001712
1713 if (e1000_reg_test(adapter, &data[0]))
1714 eth_test->flags |= ETH_TEST_FL_FAILED;
1715
1716 e1000e_reset(adapter);
1717 if (e1000_eeprom_test(adapter, &data[1]))
1718 eth_test->flags |= ETH_TEST_FL_FAILED;
1719
1720 e1000e_reset(adapter);
1721 if (e1000_intr_test(adapter, &data[2]))
1722 eth_test->flags |= ETH_TEST_FL_FAILED;
1723
1724 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001725 if (e1000_loopback_test(adapter, &data[3]))
1726 eth_test->flags |= ETH_TEST_FL_FAILED;
1727
Auke Kokbc7f75f2007-09-17 12:30:59 -07001728 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001729 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001730 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001731 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001732
Carolyn Wybornyc6ce3852010-10-15 17:35:31 +00001733 if (e1000_link_test(adapter, &data[4]))
1734 eth_test->flags |= ETH_TEST_FL_FAILED;
1735
1736 /* restore speed, duplex, autoneg settings */
1737 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1738 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1739 adapter->hw.mac.autoneg = autoneg;
1740 e1000e_reset(adapter);
1741
Auke Kokbc7f75f2007-09-17 12:30:59 -07001742 clear_bit(__E1000_TESTING, &adapter->state);
1743 if (if_running)
1744 dev_open(netdev);
1745 } else {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001746 /* Online tests */
Bruce Allan11b08be2010-05-10 14:59:31 +00001747
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001748 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001749
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001750 /* register, eeprom, intr and loopback tests not run online */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001751 data[0] = 0;
1752 data[1] = 0;
1753 data[2] = 0;
1754 data[3] = 0;
1755
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001756 if (e1000_link_test(adapter, &data[4]))
1757 eth_test->flags |= ETH_TEST_FL_FAILED;
Bruce Allan11b08be2010-05-10 14:59:31 +00001758
Auke Kokbc7f75f2007-09-17 12:30:59 -07001759 clear_bit(__E1000_TESTING, &adapter->state);
1760 }
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001761
1762 if (!if_running) {
1763 e1000e_reset(adapter);
1764
1765 if (adapter->flags & FLAG_HAS_AMT)
1766 e1000e_release_hw_control(adapter);
1767 }
1768
Auke Kokbc7f75f2007-09-17 12:30:59 -07001769 msleep_interruptible(4 * 1000);
1770}
1771
1772static void e1000_get_wol(struct net_device *netdev,
1773 struct ethtool_wolinfo *wol)
1774{
1775 struct e1000_adapter *adapter = netdev_priv(netdev);
1776
1777 wol->supported = 0;
1778 wol->wolopts = 0;
1779
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001780 if (!(adapter->flags & FLAG_HAS_WOL) ||
1781 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001782 return;
1783
1784 wol->supported = WAKE_UCAST | WAKE_MCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001785 WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001786
1787 /* apply any specific unsupported masks here */
1788 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1789 wol->supported &= ~WAKE_UCAST;
1790
1791 if (adapter->wol & E1000_WUFC_EX)
Bruce Allan6ad65142012-04-12 05:47:09 +00001792 e_err("Interface does not support directed (unicast) frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001793 }
1794
1795 if (adapter->wol & E1000_WUFC_EX)
1796 wol->wolopts |= WAKE_UCAST;
1797 if (adapter->wol & E1000_WUFC_MC)
1798 wol->wolopts |= WAKE_MCAST;
1799 if (adapter->wol & E1000_WUFC_BC)
1800 wol->wolopts |= WAKE_BCAST;
1801 if (adapter->wol & E1000_WUFC_MAG)
1802 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001803 if (adapter->wol & E1000_WUFC_LNKC)
1804 wol->wolopts |= WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001805}
1806
Bruce Allan4a29e152011-03-04 09:07:01 +00001807static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001808{
1809 struct e1000_adapter *adapter = netdev_priv(netdev);
1810
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001811 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001812 !device_can_wakeup(&adapter->pdev->dev) ||
1813 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001814 WAKE_MAGIC | WAKE_PHY)))
Bruce Allan1fbfca32009-11-20 23:22:01 +00001815 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001816
1817 /* these settings will always override what we currently have */
1818 adapter->wol = 0;
1819
1820 if (wol->wolopts & WAKE_UCAST)
1821 adapter->wol |= E1000_WUFC_EX;
1822 if (wol->wolopts & WAKE_MCAST)
1823 adapter->wol |= E1000_WUFC_MC;
1824 if (wol->wolopts & WAKE_BCAST)
1825 adapter->wol |= E1000_WUFC_BC;
1826 if (wol->wolopts & WAKE_MAGIC)
1827 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001828 if (wol->wolopts & WAKE_PHY)
1829 adapter->wol |= E1000_WUFC_LNKC;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001830
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001831 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1832
Auke Kokbc7f75f2007-09-17 12:30:59 -07001833 return 0;
1834}
1835
Bruce Allandbf80dc2011-04-16 00:34:40 +00001836static int e1000_set_phys_id(struct net_device *netdev,
1837 enum ethtool_phys_id_state state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001838{
1839 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001840 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001841
Bruce Allandbf80dc2011-04-16 00:34:40 +00001842 switch (state) {
1843 case ETHTOOL_ID_ACTIVE:
1844 if (!hw->mac.ops.blink_led)
1845 return 2; /* cycle on/off twice per second */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001846
Bruce Allandbf80dc2011-04-16 00:34:40 +00001847 hw->mac.ops.blink_led(hw);
1848 break;
1849
1850 case ETHTOOL_ID_INACTIVE:
Bruce Allan4662e822008-08-26 18:37:06 -07001851 if (hw->phy.type == e1000_phy_ife)
1852 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001853 hw->mac.ops.led_off(hw);
1854 hw->mac.ops.cleanup_led(hw);
1855 break;
1856
1857 case ETHTOOL_ID_ON:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001858 hw->mac.ops.led_on(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001859 break;
1860
1861 case ETHTOOL_ID_OFF:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001862 hw->mac.ops.led_off(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001863 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001864 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001865 return 0;
1866}
1867
Auke Kokde5b3072008-04-23 11:09:08 -07001868static int e1000_get_coalesce(struct net_device *netdev,
1869 struct ethtool_coalesce *ec)
1870{
1871 struct e1000_adapter *adapter = netdev_priv(netdev);
1872
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001873 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07001874 ec->rx_coalesce_usecs = adapter->itr_setting;
1875 else
1876 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1877
1878 return 0;
1879}
1880
1881static int e1000_set_coalesce(struct net_device *netdev,
1882 struct ethtool_coalesce *ec)
1883{
1884 struct e1000_adapter *adapter = netdev_priv(netdev);
1885 struct e1000_hw *hw = &adapter->hw;
1886
1887 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001888 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07001889 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1890 (ec->rx_coalesce_usecs == 2))
1891 return -EINVAL;
1892
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001893 if (ec->rx_coalesce_usecs == 4) {
1894 adapter->itr = adapter->itr_setting = 4;
1895 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07001896 adapter->itr = 20000;
1897 adapter->itr_setting = ec->rx_coalesce_usecs;
1898 } else {
1899 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1900 adapter->itr_setting = adapter->itr & ~3;
1901 }
1902
1903 if (adapter->itr_setting != 0)
1904 ew32(ITR, 1000000000 / (adapter->itr * 256));
1905 else
1906 ew32(ITR, 0);
1907
1908 return 0;
1909}
1910
Auke Kokbc7f75f2007-09-17 12:30:59 -07001911static int e1000_nway_reset(struct net_device *netdev)
1912{
1913 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan5962bc22011-01-20 06:58:07 +00001914
1915 if (!netif_running(netdev))
1916 return -EAGAIN;
1917
1918 if (!adapter->hw.mac.autoneg)
1919 return -EINVAL;
1920
1921 e1000e_reinit_locked(adapter);
1922
Auke Kokbc7f75f2007-09-17 12:30:59 -07001923 return 0;
1924}
1925
Auke Kokbc7f75f2007-09-17 12:30:59 -07001926static void e1000_get_ethtool_stats(struct net_device *netdev,
1927 struct ethtool_stats *stats,
1928 u64 *data)
1929{
1930 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001931 struct rtnl_link_stats64 net_stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001932 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001933 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001934
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001935 e1000e_get_stats64(netdev, &net_stats);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001936 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001937 switch (e1000_gstrings_stats[i].type) {
1938 case NETDEV_STATS:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001939 p = (char *) &net_stats +
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001940 e1000_gstrings_stats[i].stat_offset;
1941 break;
1942 case E1000_STATS:
1943 p = (char *) adapter +
1944 e1000_gstrings_stats[i].stat_offset;
1945 break;
Bruce Allan61c75812010-12-09 23:04:25 +00001946 default:
1947 data[i] = 0;
1948 continue;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001949 }
1950
Auke Kokbc7f75f2007-09-17 12:30:59 -07001951 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1952 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1953 }
1954}
1955
1956static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1957 u8 *data)
1958{
1959 u8 *p = data;
1960 int i;
1961
1962 switch (stringset) {
1963 case ETH_SS_TEST:
Bruce Allan5c1bda02011-01-19 04:23:39 +00001964 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001965 break;
1966 case ETH_SS_STATS:
1967 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1968 memcpy(p, e1000_gstrings_stats[i].stat_string,
1969 ETH_GSTRING_LEN);
1970 p += ETH_GSTRING_LEN;
1971 }
1972 break;
1973 }
1974}
1975
Bruce Allan70495a52012-01-11 01:26:50 +00001976static int e1000_get_rxnfc(struct net_device *netdev,
1977 struct ethtool_rxnfc *info, u32 *rule_locs)
1978{
1979 info->data = 0;
1980
1981 switch (info->cmd) {
1982 case ETHTOOL_GRXFH: {
1983 struct e1000_adapter *adapter = netdev_priv(netdev);
1984 struct e1000_hw *hw = &adapter->hw;
1985 u32 mrqc = er32(MRQC);
1986
1987 if (!(mrqc & E1000_MRQC_RSS_FIELD_MASK))
1988 return 0;
1989
1990 switch (info->flow_type) {
1991 case TCP_V4_FLOW:
1992 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP)
1993 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1994 /* fall through */
1995 case UDP_V4_FLOW:
1996 case SCTP_V4_FLOW:
1997 case AH_ESP_V4_FLOW:
1998 case IPV4_FLOW:
1999 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4)
2000 info->data |= RXH_IP_SRC | RXH_IP_DST;
2001 break;
2002 case TCP_V6_FLOW:
2003 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP)
2004 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2005 /* fall through */
2006 case UDP_V6_FLOW:
2007 case SCTP_V6_FLOW:
2008 case AH_ESP_V6_FLOW:
2009 case IPV6_FLOW:
2010 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6)
2011 info->data |= RXH_IP_SRC | RXH_IP_DST;
2012 break;
2013 default:
2014 break;
2015 }
2016 return 0;
2017 }
2018 default:
2019 return -EOPNOTSUPP;
2020 }
2021}
2022
Auke Kokbc7f75f2007-09-17 12:30:59 -07002023static const struct ethtool_ops e1000_ethtool_ops = {
2024 .get_settings = e1000_get_settings,
2025 .set_settings = e1000_set_settings,
2026 .get_drvinfo = e1000_get_drvinfo,
2027 .get_regs_len = e1000_get_regs_len,
2028 .get_regs = e1000_get_regs,
2029 .get_wol = e1000_get_wol,
2030 .set_wol = e1000_set_wol,
2031 .get_msglevel = e1000_get_msglevel,
2032 .set_msglevel = e1000_set_msglevel,
2033 .nway_reset = e1000_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00002034 .get_link = ethtool_op_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002035 .get_eeprom_len = e1000_get_eeprom_len,
2036 .get_eeprom = e1000_get_eeprom,
2037 .set_eeprom = e1000_set_eeprom,
2038 .get_ringparam = e1000_get_ringparam,
2039 .set_ringparam = e1000_set_ringparam,
2040 .get_pauseparam = e1000_get_pauseparam,
2041 .set_pauseparam = e1000_set_pauseparam,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002042 .self_test = e1000_diag_test,
2043 .get_strings = e1000_get_strings,
Bruce Allandbf80dc2011-04-16 00:34:40 +00002044 .set_phys_id = e1000_set_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002045 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07002046 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07002047 .get_coalesce = e1000_get_coalesce,
2048 .set_coalesce = e1000_set_coalesce,
Bruce Allan70495a52012-01-11 01:26:50 +00002049 .get_rxnfc = e1000_get_rxnfc,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002050};
2051
2052void e1000e_set_ethtool_ops(struct net_device *netdev)
2053{
2054 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
2055}