blob: f4dc0fa9d9b5288793c5e7eea37462c3fffa3ad7 [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 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700261 if (e1000_check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700262 e_err("Cannot change link characteristics when SoL/IDER is "
263 "active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700264 return -EINVAL;
265 }
266
267 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000268 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700269
270 if (ecmd->autoneg == AUTONEG_ENABLE) {
271 hw->mac.autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700272 if (hw->phy.media_type == e1000_media_type_fiber)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700273 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
274 ADVERTISED_FIBRE |
275 ADVERTISED_Autoneg;
276 else
277 hw->phy.autoneg_advertised = ecmd->advertising |
278 ADVERTISED_TP |
279 ADVERTISED_Autoneg;
280 ecmd->advertising = hw->phy.autoneg_advertised;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700281 if (adapter->fc_autoneg)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800282 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700283 } else {
David Decotigny25db0332011-04-27 18:32:39 +0000284 u32 speed = ethtool_cmd_speed(ecmd);
David Decotigny14ad2512011-04-27 18:32:43 +0000285 if (e1000_set_spd_dplx(adapter, speed, ecmd->duplex)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700286 clear_bit(__E1000_RESETTING, &adapter->state);
287 return -EINVAL;
288 }
289 }
290
291 /* reset the link */
292
293 if (netif_running(adapter->netdev)) {
294 e1000e_down(adapter);
295 e1000e_up(adapter);
296 } else {
297 e1000e_reset(adapter);
298 }
299
300 clear_bit(__E1000_RESETTING, &adapter->state);
301 return 0;
302}
303
304static void e1000_get_pauseparam(struct net_device *netdev,
305 struct ethtool_pauseparam *pause)
306{
307 struct e1000_adapter *adapter = netdev_priv(netdev);
308 struct e1000_hw *hw = &adapter->hw;
309
310 pause->autoneg =
311 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
312
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800313 if (hw->fc.current_mode == e1000_fc_rx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700314 pause->rx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800315 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700316 pause->tx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800317 } else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700318 pause->rx_pause = 1;
319 pause->tx_pause = 1;
320 }
321}
322
323static int e1000_set_pauseparam(struct net_device *netdev,
324 struct ethtool_pauseparam *pause)
325{
326 struct e1000_adapter *adapter = netdev_priv(netdev);
327 struct e1000_hw *hw = &adapter->hw;
328 int retval = 0;
329
330 adapter->fc_autoneg = pause->autoneg;
331
332 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000333 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700334
Auke Kokbc7f75f2007-09-17 12:30:59 -0700335 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800336 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700337 if (netif_running(adapter->netdev)) {
338 e1000e_down(adapter);
339 e1000e_up(adapter);
340 } else {
341 e1000e_reset(adapter);
342 }
343 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800344 if (pause->rx_pause && pause->tx_pause)
345 hw->fc.requested_mode = e1000_fc_full;
346 else if (pause->rx_pause && !pause->tx_pause)
347 hw->fc.requested_mode = e1000_fc_rx_pause;
348 else if (!pause->rx_pause && pause->tx_pause)
349 hw->fc.requested_mode = e1000_fc_tx_pause;
350 else if (!pause->rx_pause && !pause->tx_pause)
351 hw->fc.requested_mode = e1000_fc_none;
352
353 hw->fc.current_mode = hw->fc.requested_mode;
354
Bruce Allan945eb312009-10-28 18:28:30 +0000355 if (hw->phy.media_type == e1000_media_type_fiber) {
356 retval = hw->mac.ops.setup_link(hw);
357 /* implicit goto out */
358 } else {
359 retval = e1000e_force_mac_fc(hw);
360 if (retval)
361 goto out;
362 e1000e_set_fc_watermarks(hw);
363 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700364 }
365
Bruce Allan945eb312009-10-28 18:28:30 +0000366out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700367 clear_bit(__E1000_RESETTING, &adapter->state);
368 return retval;
369}
370
Auke Kokbc7f75f2007-09-17 12:30:59 -0700371static u32 e1000_get_msglevel(struct net_device *netdev)
372{
373 struct e1000_adapter *adapter = netdev_priv(netdev);
374 return adapter->msg_enable;
375}
376
377static void e1000_set_msglevel(struct net_device *netdev, u32 data)
378{
379 struct e1000_adapter *adapter = netdev_priv(netdev);
380 adapter->msg_enable = data;
381}
382
383static int e1000_get_regs_len(struct net_device *netdev)
384{
385#define E1000_REGS_LEN 32 /* overestimate */
386 return E1000_REGS_LEN * sizeof(u32);
387}
388
389static void e1000_get_regs(struct net_device *netdev,
390 struct ethtool_regs *regs, void *p)
391{
392 struct e1000_adapter *adapter = netdev_priv(netdev);
393 struct e1000_hw *hw = &adapter->hw;
394 u32 *regs_buff = p;
395 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700396
397 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
398
Sergei Shtylyovff938e42011-02-28 11:57:33 -0800399 regs->version = (1 << 24) | (adapter->pdev->revision << 16) |
400 adapter->pdev->device;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700401
402 regs_buff[0] = er32(CTRL);
403 regs_buff[1] = er32(STATUS);
404
405 regs_buff[2] = er32(RCTL);
406 regs_buff[3] = er32(RDLEN);
407 regs_buff[4] = er32(RDH);
408 regs_buff[5] = er32(RDT);
409 regs_buff[6] = er32(RDTR);
410
411 regs_buff[7] = er32(TCTL);
412 regs_buff[8] = er32(TDLEN);
413 regs_buff[9] = er32(TDH);
414 regs_buff[10] = er32(TDT);
415 regs_buff[11] = er32(TIDV);
416
417 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700418
419 /* ethtool doesn't use anything past this point, so all this
420 * code is likely legacy junk for apps that may or may not
421 * exist */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700422 if (hw->phy.type == e1000_phy_m88) {
423 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
424 regs_buff[13] = (u32)phy_data; /* cable length */
425 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
426 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
427 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
428 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
429 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
430 regs_buff[18] = regs_buff[13]; /* cable polarity */
431 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
432 regs_buff[20] = regs_buff[17]; /* polarity correction */
433 /* phy receive errors */
434 regs_buff[22] = adapter->phy_stats.receive_errors;
435 regs_buff[23] = regs_buff[13]; /* mdix mode */
436 }
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700437 regs_buff[21] = 0; /* was idle_errors */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700438 e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
439 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
440 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
441}
442
443static int e1000_get_eeprom_len(struct net_device *netdev)
444{
445 struct e1000_adapter *adapter = netdev_priv(netdev);
446 return adapter->hw.nvm.word_size * 2;
447}
448
449static int e1000_get_eeprom(struct net_device *netdev,
450 struct ethtool_eeprom *eeprom, u8 *bytes)
451{
452 struct e1000_adapter *adapter = netdev_priv(netdev);
453 struct e1000_hw *hw = &adapter->hw;
454 u16 *eeprom_buff;
455 int first_word;
456 int last_word;
457 int ret_val = 0;
458 u16 i;
459
460 if (eeprom->len == 0)
461 return -EINVAL;
462
463 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
464
465 first_word = eeprom->offset >> 1;
466 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
467
468 eeprom_buff = kmalloc(sizeof(u16) *
469 (last_word - first_word + 1), GFP_KERNEL);
470 if (!eeprom_buff)
471 return -ENOMEM;
472
473 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
474 ret_val = e1000_read_nvm(hw, first_word,
475 last_word - first_word + 1,
476 eeprom_buff);
477 } else {
478 for (i = 0; i < last_word - first_word + 1; i++) {
479 ret_val = e1000_read_nvm(hw, first_word + i, 1,
480 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800481 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700482 break;
483 }
484 }
485
Bruce Allane2434552008-11-21 17:02:41 -0800486 if (ret_val) {
487 /* a read error occurred, throw away the result */
Roel Kluin8528b012009-12-01 15:54:24 +0000488 memset(eeprom_buff, 0xff, sizeof(u16) *
489 (last_word - first_word + 1));
Bruce Allane2434552008-11-21 17:02:41 -0800490 } else {
491 /* Device's eeprom is always little-endian, word addressable */
492 for (i = 0; i < last_word - first_word + 1; i++)
493 le16_to_cpus(&eeprom_buff[i]);
494 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700495
496 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
497 kfree(eeprom_buff);
498
499 return ret_val;
500}
501
502static int e1000_set_eeprom(struct net_device *netdev,
503 struct ethtool_eeprom *eeprom, u8 *bytes)
504{
505 struct e1000_adapter *adapter = netdev_priv(netdev);
506 struct e1000_hw *hw = &adapter->hw;
507 u16 *eeprom_buff;
508 void *ptr;
509 int max_len;
510 int first_word;
511 int last_word;
512 int ret_val = 0;
513 u16 i;
514
515 if (eeprom->len == 0)
516 return -EOPNOTSUPP;
517
518 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
519 return -EFAULT;
520
Bruce Allan4a770352008-10-01 17:18:35 -0700521 if (adapter->flags & FLAG_READ_ONLY_NVM)
522 return -EINVAL;
523
Auke Kokbc7f75f2007-09-17 12:30:59 -0700524 max_len = hw->nvm.word_size * 2;
525
526 first_word = eeprom->offset >> 1;
527 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
528 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
529 if (!eeprom_buff)
530 return -ENOMEM;
531
532 ptr = (void *)eeprom_buff;
533
534 if (eeprom->offset & 1) {
535 /* need read/modify/write of first changed EEPROM word */
536 /* only the second byte of the word is being modified */
537 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
538 ptr++;
539 }
Bruce Allan9e2d7652012-01-31 06:37:27 +0000540 if (((eeprom->offset + eeprom->len) & 1) && (!ret_val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700541 /* need read/modify/write of last changed EEPROM word */
542 /* only the first byte of the word is being modified */
543 ret_val = e1000_read_nvm(hw, last_word, 1,
544 &eeprom_buff[last_word - first_word]);
545
Bruce Allane2434552008-11-21 17:02:41 -0800546 if (ret_val)
547 goto out;
548
Auke Kokbc7f75f2007-09-17 12:30:59 -0700549 /* Device's eeprom is always little-endian, word addressable */
550 for (i = 0; i < last_word - first_word + 1; i++)
551 le16_to_cpus(&eeprom_buff[i]);
552
553 memcpy(ptr, bytes, eeprom->len);
554
555 for (i = 0; i < last_word - first_word + 1; i++)
Bruce Allane885d762012-01-31 06:37:32 +0000556 cpu_to_le16s(&eeprom_buff[i]);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700557
558 ret_val = e1000_write_nvm(hw, first_word,
559 last_word - first_word + 1, eeprom_buff);
560
Bruce Allane2434552008-11-21 17:02:41 -0800561 if (ret_val)
562 goto out;
563
Bruce Allanad680762008-03-28 09:15:03 -0700564 /*
565 * Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800566 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700567 */
Bruce Allane2434552008-11-21 17:02:41 -0800568 if ((first_word <= NVM_CHECKSUM_REG) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +0000569 (hw->mac.type == e1000_82583) ||
570 (hw->mac.type == e1000_82574) ||
571 (hw->mac.type == e1000_82573))
Bruce Allane2434552008-11-21 17:02:41 -0800572 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700573
Bruce Allane2434552008-11-21 17:02:41 -0800574out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700575 kfree(eeprom_buff);
576 return ret_val;
577}
578
579static void e1000_get_drvinfo(struct net_device *netdev,
580 struct ethtool_drvinfo *drvinfo)
581{
582 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700583
Rick Jones612a94d2011-11-14 08:13:25 +0000584 strlcpy(drvinfo->driver, e1000e_driver_name,
585 sizeof(drvinfo->driver));
Rick Jones33a5ba12011-11-15 14:59:53 +0000586 strlcpy(drvinfo->version, e1000e_driver_version,
Rick Jones612a94d2011-11-14 08:13:25 +0000587 sizeof(drvinfo->version));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700588
Bruce Allanad680762008-03-28 09:15:03 -0700589 /*
590 * EEPROM image version # is reported as firmware version # for
591 * PCI-E controllers
592 */
Rick Jones612a94d2011-11-14 08:13:25 +0000593 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
594 "%d.%d-%d",
Bruce Allan84527592008-11-21 17:00:22 -0800595 (adapter->eeprom_vers & 0xF000) >> 12,
596 (adapter->eeprom_vers & 0x0FF0) >> 4,
597 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700598
Rick Jones612a94d2011-11-14 08:13:25 +0000599 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
600 sizeof(drvinfo->bus_info));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700601 drvinfo->regdump_len = e1000_get_regs_len(netdev);
602 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
603}
604
605static void e1000_get_ringparam(struct net_device *netdev,
606 struct ethtool_ringparam *ring)
607{
608 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700609
610 ring->rx_max_pending = E1000_MAX_RXD;
611 ring->tx_max_pending = E1000_MAX_TXD;
Bruce Allan508da422011-12-16 00:45:51 +0000612 ring->rx_pending = adapter->rx_ring_count;
613 ring->tx_pending = adapter->tx_ring_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700614}
615
616static int e1000_set_ringparam(struct net_device *netdev,
617 struct ethtool_ringparam *ring)
618{
619 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan508da422011-12-16 00:45:51 +0000620 struct e1000_ring *temp_tx = NULL, *temp_rx = NULL;
621 int err = 0, size = sizeof(struct e1000_ring);
622 bool set_tx = false, set_rx = false;
623 u16 new_rx_count, new_tx_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700624
625 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
626 return -EINVAL;
627
Bruce Allan508da422011-12-16 00:45:51 +0000628 new_rx_count = clamp_t(u32, ring->rx_pending, E1000_MIN_RXD,
629 E1000_MAX_RXD);
630 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
631
632 new_tx_count = clamp_t(u32, ring->tx_pending, E1000_MIN_TXD,
633 E1000_MAX_TXD);
634 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
635
636 if ((new_tx_count == adapter->tx_ring_count) &&
637 (new_rx_count == adapter->rx_ring_count))
638 /* nothing to do */
639 return 0;
640
Auke Kokbc7f75f2007-09-17 12:30:59 -0700641 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000642 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700643
Bruce Allan508da422011-12-16 00:45:51 +0000644 if (!netif_running(adapter->netdev)) {
645 /* Set counts now and allocate resources during open() */
646 adapter->tx_ring->count = new_tx_count;
647 adapter->rx_ring->count = new_rx_count;
648 adapter->tx_ring_count = new_tx_count;
649 adapter->rx_ring_count = new_rx_count;
650 goto clear_reset;
651 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700652
Bruce Allan508da422011-12-16 00:45:51 +0000653 set_tx = (new_tx_count != adapter->tx_ring_count);
654 set_rx = (new_rx_count != adapter->rx_ring_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700655
Bruce Allan508da422011-12-16 00:45:51 +0000656 /* Allocate temporary storage for ring updates */
657 if (set_tx) {
658 temp_tx = vmalloc(size);
659 if (!temp_tx) {
660 err = -ENOMEM;
661 goto free_temp;
662 }
663 }
664 if (set_rx) {
665 temp_rx = vmalloc(size);
666 if (!temp_rx) {
667 err = -ENOMEM;
668 goto free_temp;
669 }
670 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700671
Bruce Allan508da422011-12-16 00:45:51 +0000672 e1000e_down(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700673
Bruce Allan508da422011-12-16 00:45:51 +0000674 /*
675 * We can't just free everything and then setup again, because the
676 * ISRs in MSI-X mode get passed pointers to the Tx and Rx ring
677 * structs. First, attempt to allocate new resources...
678 */
679 if (set_tx) {
680 memcpy(temp_tx, adapter->tx_ring, size);
681 temp_tx->count = new_tx_count;
682 err = e1000e_setup_tx_resources(temp_tx);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700683 if (err)
684 goto err_setup;
685 }
Bruce Allan508da422011-12-16 00:45:51 +0000686 if (set_rx) {
687 memcpy(temp_rx, adapter->rx_ring, size);
688 temp_rx->count = new_rx_count;
689 err = e1000e_setup_rx_resources(temp_rx);
690 if (err)
691 goto err_setup_rx;
692 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700693
Bruce Allan508da422011-12-16 00:45:51 +0000694 /* ...then free the old resources and copy back any new ring data */
695 if (set_tx) {
696 e1000e_free_tx_resources(adapter->tx_ring);
697 memcpy(adapter->tx_ring, temp_tx, size);
698 adapter->tx_ring_count = new_tx_count;
699 }
700 if (set_rx) {
701 e1000e_free_rx_resources(adapter->rx_ring);
702 memcpy(adapter->rx_ring, temp_rx, size);
703 adapter->rx_ring_count = new_rx_count;
704 }
705
Auke Kokbc7f75f2007-09-17 12:30:59 -0700706err_setup_rx:
Bruce Allan508da422011-12-16 00:45:51 +0000707 if (err && set_tx)
708 e1000e_free_tx_resources(temp_tx);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700709err_setup:
Bruce Allan508da422011-12-16 00:45:51 +0000710 e1000e_up(adapter);
711free_temp:
712 vfree(temp_tx);
713 vfree(temp_rx);
714clear_reset:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700715 clear_bit(__E1000_RESETTING, &adapter->state);
716 return err;
717}
718
Bruce Allancef8c792008-04-02 13:48:23 -0700719static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
720 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800721{
Bruce Allancef8c792008-04-02 13:48:23 -0700722 u32 pat, val;
Bruce Allan64806412010-12-11 05:53:42 +0000723 static const u32 test[] = {
724 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Bruce Allancef8c792008-04-02 13:48:23 -0700725 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800726 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700727 (test[pat] & write));
728 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
729 if (val != (test[pat] & write & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700730 e_err("pattern test reg %04X failed: got 0x%08X "
731 "expected 0x%08X\n", reg + offset, val,
732 (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800733 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700734 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800735 }
736 }
Bruce Allancef8c792008-04-02 13:48:23 -0700737 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700738}
739
Joe Perches2a887192007-11-13 20:53:51 -0800740static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
741 int reg, u32 mask, u32 write)
742{
Bruce Allancef8c792008-04-02 13:48:23 -0700743 u32 val;
Joe Perches2a887192007-11-13 20:53:51 -0800744 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700745 val = __er32(&adapter->hw, reg);
746 if ((write & mask) != (val & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700747 e_err("set/check reg %04X test failed: got 0x%08X "
748 "expected 0x%08X\n", reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800749 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700750 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800751 }
Bruce Allancef8c792008-04-02 13:48:23 -0700752 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700753}
Bruce Allancef8c792008-04-02 13:48:23 -0700754#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
755 do { \
756 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
757 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800758 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700759#define REG_PATTERN_TEST(reg, mask, write) \
760 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800761
Bruce Allancef8c792008-04-02 13:48:23 -0700762#define REG_SET_AND_CHECK(reg, mask, write) \
763 do { \
764 if (reg_set_and_check(adapter, data, reg, mask, write)) \
765 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800766 } while (0)
767
Auke Kokbc7f75f2007-09-17 12:30:59 -0700768static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
769{
770 struct e1000_hw *hw = &adapter->hw;
771 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700772 u32 value;
773 u32 before;
774 u32 after;
775 u32 i;
776 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000777 u32 mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700778
Bruce Allanad680762008-03-28 09:15:03 -0700779 /*
780 * The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700781 * Some bits that get toggled are ignored.
782 */
783 switch (mac->type) {
784 /* there are several bits on newer hardware that are r/w */
785 case e1000_82571:
786 case e1000_82572:
787 case e1000_80003es2lan:
788 toggle = 0x7FFFF3FF;
789 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000790 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700791 toggle = 0x7FFFF033;
792 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700793 }
794
795 before = er32(STATUS);
796 value = (er32(STATUS) & toggle);
797 ew32(STATUS, toggle);
798 after = er32(STATUS) & toggle;
799 if (value != after) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700800 e_err("failed STATUS register test got: 0x%08X expected: "
801 "0x%08X\n", after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700802 *data = 1;
803 return 1;
804 }
805 /* restore previous status */
806 ew32(STATUS, before);
807
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700808 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700809 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
810 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
811 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
812 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
813 }
814
815 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
816 REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
817 REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF);
818 REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF);
819 REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF);
820 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
821 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
822 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
823 REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
824 REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF);
825
826 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
827
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700828 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700829 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
830 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
831
Auke Kok86582512007-10-04 15:00:08 -0700832 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
833 REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700834 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700835 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
836 REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
837 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000838 mask = 0x8003FFFF;
839 switch (mac->type) {
840 case e1000_ich10lan:
841 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000842 case e1000_pch2lan:
Bruce Allana4f58f52009-06-02 11:29:18 +0000843 mask |= (1 << 18);
844 break;
845 default:
846 break;
847 }
Auke Kok86582512007-10-04 15:00:08 -0700848 for (i = 0; i < mac->rar_entry_count; i++)
849 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
Bruce Allana4f58f52009-06-02 11:29:18 +0000850 mask, 0xFFFFFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700851
852 for (i = 0; i < mac->mta_reg_count; i++)
853 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
854
855 *data = 0;
856 return 0;
857}
858
859static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
860{
861 u16 temp;
862 u16 checksum = 0;
863 u16 i;
864
865 *data = 0;
866 /* Read and add up the contents of the EEPROM */
867 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
868 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
869 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800870 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700871 }
872 checksum += temp;
873 }
874
875 /* If Checksum is not Correct return error else test passed */
876 if ((checksum != (u16) NVM_SUM) && !(*data))
877 *data = 2;
878
879 return *data;
880}
881
882static irqreturn_t e1000_test_intr(int irq, void *data)
883{
884 struct net_device *netdev = (struct net_device *) data;
885 struct e1000_adapter *adapter = netdev_priv(netdev);
886 struct e1000_hw *hw = &adapter->hw;
887
888 adapter->test_icr |= er32(ICR);
889
890 return IRQ_HANDLED;
891}
892
893static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
894{
895 struct net_device *netdev = adapter->netdev;
896 struct e1000_hw *hw = &adapter->hw;
897 u32 mask;
898 u32 shared_int = 1;
899 u32 irq = adapter->pdev->irq;
900 int i;
Bruce Allan4662e822008-08-26 18:37:06 -0700901 int ret_val = 0;
902 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700903
904 *data = 0;
905
Bruce Allan4662e822008-08-26 18:37:06 -0700906 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
907 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
908 int_mode = adapter->int_mode;
909 e1000e_reset_interrupt_capability(adapter);
910 adapter->int_mode = E1000E_INT_MODE_LEGACY;
911 e1000e_set_interrupt_capability(adapter);
912 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700913 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800914 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700915 netdev)) {
916 shared_int = 0;
Joe Perchesa0607fd2009-11-18 23:29:17 -0800917 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700918 netdev->name, netdev)) {
919 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700920 ret_val = -1;
921 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700922 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700923 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700924
925 /* Disable all the interrupts */
926 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000927 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000928 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700929
930 /* Test each interrupt */
931 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700932 /* Interrupt to test */
933 mask = 1 << i;
934
Bruce Allanf4187b52008-08-26 18:36:50 -0700935 if (adapter->flags & FLAG_IS_ICH) {
936 switch (mask) {
937 case E1000_ICR_RXSEQ:
938 continue;
939 case 0x00000100:
940 if (adapter->hw.mac.type == e1000_ich8lan ||
941 adapter->hw.mac.type == e1000_ich9lan)
942 continue;
943 break;
944 default:
945 break;
946 }
947 }
948
Auke Kokbc7f75f2007-09-17 12:30:59 -0700949 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700950 /*
951 * Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700952 * the cause register and then force the same
953 * interrupt and see if one gets posted. If
954 * an interrupt was posted to the bus, the
955 * test failed.
956 */
957 adapter->test_icr = 0;
958 ew32(IMC, mask);
959 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000960 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000961 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700962
963 if (adapter->test_icr & mask) {
964 *data = 3;
965 break;
966 }
967 }
968
Bruce Allanad680762008-03-28 09:15:03 -0700969 /*
970 * Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700971 * the cause register and then force the same
972 * interrupt and see if one gets posted. If
973 * an interrupt was not posted to the bus, the
974 * test failed.
975 */
976 adapter->test_icr = 0;
977 ew32(IMS, mask);
978 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000979 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000980 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700981
982 if (!(adapter->test_icr & mask)) {
983 *data = 4;
984 break;
985 }
986
987 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700988 /*
989 * Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700990 * the cause register and then force the other
991 * interrupts and see if any get posted. If
992 * an interrupt was posted to the bus, the
993 * test failed.
994 */
995 adapter->test_icr = 0;
996 ew32(IMC, ~mask & 0x00007FFF);
997 ew32(ICS, ~mask & 0x00007FFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000998 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000999 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001000
1001 if (adapter->test_icr) {
1002 *data = 5;
1003 break;
1004 }
1005 }
1006 }
1007
1008 /* Disable all the interrupts */
1009 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001010 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001011 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001012
1013 /* Unhook test interrupt handler */
1014 free_irq(irq, netdev);
1015
Bruce Allan4662e822008-08-26 18:37:06 -07001016out:
1017 if (int_mode == E1000E_INT_MODE_MSIX) {
1018 e1000e_reset_interrupt_capability(adapter);
1019 adapter->int_mode = int_mode;
1020 e1000e_set_interrupt_capability(adapter);
1021 }
1022
1023 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001024}
1025
1026static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1027{
1028 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1029 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1030 struct pci_dev *pdev = adapter->pdev;
1031 int i;
1032
1033 if (tx_ring->desc && tx_ring->buffer_info) {
1034 for (i = 0; i < tx_ring->count; i++) {
1035 if (tx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001036 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001037 tx_ring->buffer_info[i].dma,
1038 tx_ring->buffer_info[i].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001039 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001040 if (tx_ring->buffer_info[i].skb)
1041 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1042 }
1043 }
1044
1045 if (rx_ring->desc && rx_ring->buffer_info) {
1046 for (i = 0; i < rx_ring->count; i++) {
1047 if (rx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001048 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001049 rx_ring->buffer_info[i].dma,
Nick Nunley0be3f552010-04-27 13:09:05 +00001050 2048, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001051 if (rx_ring->buffer_info[i].skb)
1052 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1053 }
1054 }
1055
1056 if (tx_ring->desc) {
1057 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1058 tx_ring->dma);
1059 tx_ring->desc = NULL;
1060 }
1061 if (rx_ring->desc) {
1062 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1063 rx_ring->dma);
1064 rx_ring->desc = NULL;
1065 }
1066
1067 kfree(tx_ring->buffer_info);
1068 tx_ring->buffer_info = NULL;
1069 kfree(rx_ring->buffer_info);
1070 rx_ring->buffer_info = NULL;
1071}
1072
1073static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1074{
1075 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1076 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1077 struct pci_dev *pdev = adapter->pdev;
1078 struct e1000_hw *hw = &adapter->hw;
1079 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001080 int i;
1081 int ret_val;
1082
1083 /* Setup Tx descriptor ring and Tx buffers */
1084
1085 if (!tx_ring->count)
1086 tx_ring->count = E1000_DEFAULT_TXD;
1087
Bruce Allancef8c792008-04-02 13:48:23 -07001088 tx_ring->buffer_info = kcalloc(tx_ring->count,
1089 sizeof(struct e1000_buffer),
1090 GFP_KERNEL);
1091 if (!(tx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001092 ret_val = 1;
1093 goto err_nomem;
1094 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001095
1096 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1097 tx_ring->size = ALIGN(tx_ring->size, 4096);
1098 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1099 &tx_ring->dma, GFP_KERNEL);
1100 if (!tx_ring->desc) {
1101 ret_val = 2;
1102 goto err_nomem;
1103 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001104 tx_ring->next_to_use = 0;
1105 tx_ring->next_to_clean = 0;
1106
Bruce Allancef8c792008-04-02 13:48:23 -07001107 ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001108 ew32(TDBAH, ((u64) tx_ring->dma >> 32));
Bruce Allancef8c792008-04-02 13:48:23 -07001109 ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001110 ew32(TDH, 0);
1111 ew32(TDT, 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001112 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1113 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1114 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001115
1116 for (i = 0; i < tx_ring->count; i++) {
1117 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1118 struct sk_buff *skb;
1119 unsigned int skb_size = 1024;
1120
1121 skb = alloc_skb(skb_size, GFP_KERNEL);
1122 if (!skb) {
1123 ret_val = 3;
1124 goto err_nomem;
1125 }
1126 skb_put(skb, skb_size);
1127 tx_ring->buffer_info[i].skb = skb;
1128 tx_ring->buffer_info[i].length = skb->len;
1129 tx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001130 dma_map_single(&pdev->dev, skb->data, skb->len,
1131 DMA_TO_DEVICE);
1132 if (dma_mapping_error(&pdev->dev,
1133 tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001134 ret_val = 4;
1135 goto err_nomem;
1136 }
Bruce Allancef8c792008-04-02 13:48:23 -07001137 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001138 tx_desc->lower.data = cpu_to_le32(skb->len);
1139 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1140 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001141 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001142 tx_desc->upper.data = 0;
1143 }
1144
1145 /* Setup Rx descriptor ring and Rx buffers */
1146
1147 if (!rx_ring->count)
1148 rx_ring->count = E1000_DEFAULT_RXD;
1149
Bruce Allancef8c792008-04-02 13:48:23 -07001150 rx_ring->buffer_info = kcalloc(rx_ring->count,
1151 sizeof(struct e1000_buffer),
1152 GFP_KERNEL);
1153 if (!(rx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001154 ret_val = 5;
1155 goto err_nomem;
1156 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001157
Bruce Allan5f450212011-07-22 06:21:46 +00001158 rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001159 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1160 &rx_ring->dma, GFP_KERNEL);
1161 if (!rx_ring->desc) {
1162 ret_val = 6;
1163 goto err_nomem;
1164 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001165 rx_ring->next_to_use = 0;
1166 rx_ring->next_to_clean = 0;
1167
1168 rctl = er32(RCTL);
Bruce Allan7f99ae62011-07-22 06:21:35 +00001169 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
1170 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001171 ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
1172 ew32(RDBAH, ((u64) rx_ring->dma >> 32));
1173 ew32(RDLEN, rx_ring->size);
1174 ew32(RDH, 0);
1175 ew32(RDT, 0);
1176 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allancef8c792008-04-02 13:48:23 -07001177 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1178 E1000_RCTL_SBP | E1000_RCTL_SECRC |
Auke Kokbc7f75f2007-09-17 12:30:59 -07001179 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1180 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1181 ew32(RCTL, rctl);
1182
1183 for (i = 0; i < rx_ring->count; i++) {
Bruce Allan5f450212011-07-22 06:21:46 +00001184 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001185 struct sk_buff *skb;
1186
1187 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1188 if (!skb) {
1189 ret_val = 7;
1190 goto err_nomem;
1191 }
1192 skb_reserve(skb, NET_IP_ALIGN);
1193 rx_ring->buffer_info[i].skb = skb;
1194 rx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001195 dma_map_single(&pdev->dev, skb->data, 2048,
1196 DMA_FROM_DEVICE);
1197 if (dma_mapping_error(&pdev->dev,
1198 rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001199 ret_val = 8;
1200 goto err_nomem;
1201 }
Bruce Allan5f450212011-07-22 06:21:46 +00001202 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1203 rx_desc->read.buffer_addr =
1204 cpu_to_le64(rx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001205 memset(skb->data, 0x00, skb->len);
1206 }
1207
1208 return 0;
1209
1210err_nomem:
1211 e1000_free_desc_rings(adapter);
1212 return ret_val;
1213}
1214
1215static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1216{
1217 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1218 e1e_wphy(&adapter->hw, 29, 0x001F);
1219 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1220 e1e_wphy(&adapter->hw, 29, 0x001A);
1221 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1222}
1223
1224static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1225{
1226 struct e1000_hw *hw = &adapter->hw;
1227 u32 ctrl_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001228 u16 phy_reg = 0;
Bruce Allancbd006c2010-11-24 06:01:30 +00001229 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001230
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001231 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001232
Bruce Allan3af50482010-06-16 13:25:55 +00001233 if (hw->phy.type == e1000_phy_ife) {
1234 /* force 100, set loopback */
1235 e1e_wphy(hw, PHY_CONTROL, 0x6100);
Bruce Allanbb436b22009-11-20 23:24:11 +00001236
Bruce Allan3af50482010-06-16 13:25:55 +00001237 /* Now set up the MAC to the same speed/duplex as the PHY. */
1238 ctrl_reg = er32(CTRL);
1239 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1240 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1241 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1242 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1243 E1000_CTRL_FD); /* Force Duplex to FULL */
1244
1245 ew32(CTRL, ctrl_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001246 e1e_flush();
Bruce Allan3af50482010-06-16 13:25:55 +00001247 udelay(500);
1248
1249 return 0;
1250 }
1251
1252 /* Specific PHY configuration for loopback */
1253 switch (hw->phy.type) {
1254 case e1000_phy_m88:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001255 /* Auto-MDI/MDIX Off */
1256 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1257 /* reset to update Auto-MDI/MDIX */
1258 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1259 /* autoneg off */
1260 e1e_wphy(hw, PHY_CONTROL, 0x8140);
Bruce Allan3af50482010-06-16 13:25:55 +00001261 break;
1262 case e1000_phy_gg82563:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001263 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
Bruce Allancef8c792008-04-02 13:48:23 -07001264 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001265 case e1000_phy_bm:
1266 /* Set Default MAC Interface speed to 1GB */
1267 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1268 phy_reg &= ~0x0007;
1269 phy_reg |= 0x006;
1270 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1271 /* Assert SW reset for above settings to take effect */
1272 e1000e_commit_phy(hw);
1273 mdelay(1);
1274 /* Force Full Duplex */
1275 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1276 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1277 /* Set Link Up (in force link) */
1278 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1279 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1280 /* Force Link */
1281 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1282 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1283 /* Set Early Link Enable */
1284 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1285 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
Bruce Allan3af50482010-06-16 13:25:55 +00001286 break;
1287 case e1000_phy_82577:
1288 case e1000_phy_82578:
1289 /* Workaround: K1 must be disabled for stable 1Gbps operation */
Bruce Allancbd006c2010-11-24 06:01:30 +00001290 ret_val = hw->phy.ops.acquire(hw);
1291 if (ret_val) {
1292 e_err("Cannot setup 1Gbps loopback.\n");
1293 return ret_val;
1294 }
Bruce Allan3af50482010-06-16 13:25:55 +00001295 e1000_configure_k1_ich8lan(hw, false);
Bruce Allancbd006c2010-11-24 06:01:30 +00001296 hw->phy.ops.release(hw);
Bruce Allan3af50482010-06-16 13:25:55 +00001297 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001298 case e1000_phy_82579:
1299 /* Disable PHY energy detect power down */
1300 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1301 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
1302 /* Disable full chip energy detect */
1303 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1304 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1305 /* Enable loopback on the PHY */
1306#define I82577_PHY_LBK_CTRL 19
1307 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1308 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001309 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001310 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001311 }
1312
Bruce Allan3af50482010-06-16 13:25:55 +00001313 /* force 1000, set loopback */
1314 e1e_wphy(hw, PHY_CONTROL, 0x4140);
1315 mdelay(250);
1316
1317 /* Now set up the MAC to the same speed/duplex as the PHY. */
1318 ctrl_reg = er32(CTRL);
1319 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1320 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1321 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1322 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1323 E1000_CTRL_FD); /* Force Duplex to FULL */
1324
1325 if (adapter->flags & FLAG_IS_ICH)
1326 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1327
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001328 if (hw->phy.media_type == e1000_media_type_copper &&
1329 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001330 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1331 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001332 /*
1333 * Set the ILOS bit on the fiber Nic if half duplex link is
1334 * detected.
1335 */
Bruce Allan90da0662011-01-06 07:02:53 +00001336 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001337 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1338 }
1339
1340 ew32(CTRL, ctrl_reg);
1341
Bruce Allanad680762008-03-28 09:15:03 -07001342 /*
1343 * Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001344 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1345 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001346 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001347 e1000_phy_disable_receiver(adapter);
1348
1349 udelay(500);
1350
1351 return 0;
1352}
1353
1354static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1355{
1356 struct e1000_hw *hw = &adapter->hw;
1357 u32 ctrl = er32(CTRL);
1358 int link = 0;
1359
1360 /* special requirements for 82571/82572 fiber adapters */
1361
Bruce Allanad680762008-03-28 09:15:03 -07001362 /*
1363 * jump through hoops to make sure link is up because serdes
1364 * link is hardwired up
1365 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001366 ctrl |= E1000_CTRL_SLU;
1367 ew32(CTRL, ctrl);
1368
1369 /* disable autoneg */
1370 ctrl = er32(TXCW);
1371 ctrl &= ~(1 << 31);
1372 ew32(TXCW, ctrl);
1373
1374 link = (er32(STATUS) & E1000_STATUS_LU);
1375
1376 if (!link) {
1377 /* set invert loss of signal */
1378 ctrl = er32(CTRL);
1379 ctrl |= E1000_CTRL_ILOS;
1380 ew32(CTRL, ctrl);
1381 }
1382
Bruce Allanad680762008-03-28 09:15:03 -07001383 /*
1384 * special write to serdes control register to enable SerDes analog
1385 * loopback
1386 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001387#define E1000_SERDES_LB_ON 0x410
1388 ew32(SCTL, E1000_SERDES_LB_ON);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001389 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001390 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001391
1392 return 0;
1393}
1394
1395/* only call this for fiber/serdes connections to es2lan */
1396static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1397{
1398 struct e1000_hw *hw = &adapter->hw;
1399 u32 ctrlext = er32(CTRL_EXT);
1400 u32 ctrl = er32(CTRL);
1401
Bruce Allanad680762008-03-28 09:15:03 -07001402 /*
1403 * save CTRL_EXT to restore later, reuse an empty variable (unused
1404 * on mac_type 80003es2lan)
1405 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001406 adapter->tx_fifo_head = ctrlext;
1407
1408 /* clear the serdes mode bits, putting the device into mac loopback */
1409 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1410 ew32(CTRL_EXT, ctrlext);
1411
1412 /* force speed to 1000/FD, link up */
1413 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1414 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1415 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1416 ew32(CTRL, ctrl);
1417
1418 /* set mac loopback */
1419 ctrl = er32(RCTL);
1420 ctrl |= E1000_RCTL_LBM_MAC;
1421 ew32(RCTL, ctrl);
1422
1423 /* set testing mode parameters (no need to reset later) */
1424#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1425#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1426 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001427 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001428
1429 return 0;
1430}
1431
1432static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1433{
1434 struct e1000_hw *hw = &adapter->hw;
1435 u32 rctl;
1436
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001437 if (hw->phy.media_type == e1000_media_type_fiber ||
1438 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001439 switch (hw->mac.type) {
1440 case e1000_80003es2lan:
1441 return e1000_set_es2lan_mac_loopback(adapter);
1442 break;
1443 case e1000_82571:
1444 case e1000_82572:
1445 return e1000_set_82571_fiber_loopback(adapter);
1446 break;
1447 default:
1448 rctl = er32(RCTL);
1449 rctl |= E1000_RCTL_LBM_TCVR;
1450 ew32(RCTL, rctl);
1451 return 0;
1452 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001453 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001454 return e1000_integrated_phy_loopback(adapter);
1455 }
1456
1457 return 7;
1458}
1459
1460static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1461{
1462 struct e1000_hw *hw = &adapter->hw;
1463 u32 rctl;
1464 u16 phy_reg;
1465
1466 rctl = er32(RCTL);
1467 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1468 ew32(RCTL, rctl);
1469
1470 switch (hw->mac.type) {
1471 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001472 if (hw->phy.media_type == e1000_media_type_fiber ||
1473 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001474 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001475 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001476 adapter->tx_fifo_head = 0;
1477 }
1478 /* fall through */
1479 case e1000_82571:
1480 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001481 if (hw->phy.media_type == e1000_media_type_fiber ||
1482 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001483#define E1000_SERDES_LB_OFF 0x400
1484 ew32(SCTL, E1000_SERDES_LB_OFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001485 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001486 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001487 break;
1488 }
1489 /* Fall Through */
1490 default:
1491 hw->mac.autoneg = 1;
1492 if (hw->phy.type == e1000_phy_gg82563)
1493 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1494 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1495 if (phy_reg & MII_CR_LOOPBACK) {
1496 phy_reg &= ~MII_CR_LOOPBACK;
1497 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1498 e1000e_commit_phy(hw);
1499 }
1500 break;
1501 }
1502}
1503
1504static void e1000_create_lbtest_frame(struct sk_buff *skb,
1505 unsigned int frame_size)
1506{
1507 memset(skb->data, 0xFF, frame_size);
1508 frame_size &= ~1;
1509 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1510 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1511 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1512}
1513
1514static int e1000_check_lbtest_frame(struct sk_buff *skb,
1515 unsigned int frame_size)
1516{
1517 frame_size &= ~1;
1518 if (*(skb->data + 3) == 0xFF)
1519 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1520 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1521 return 0;
1522 return 13;
1523}
1524
1525static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1526{
1527 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1528 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1529 struct pci_dev *pdev = adapter->pdev;
1530 struct e1000_hw *hw = &adapter->hw;
1531 int i, j, k, l;
1532 int lc;
1533 int good_cnt;
1534 int ret_val = 0;
1535 unsigned long time;
1536
1537 ew32(RDT, rx_ring->count - 1);
1538
Bruce Allanad680762008-03-28 09:15:03 -07001539 /*
1540 * Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001541 * The idea is to wrap the largest ring a number of times using 64
1542 * send/receive pairs during each loop
1543 */
1544
1545 if (rx_ring->count <= tx_ring->count)
1546 lc = ((tx_ring->count / 64) * 2) + 1;
1547 else
1548 lc = ((rx_ring->count / 64) * 2) + 1;
1549
1550 k = 0;
1551 l = 0;
1552 for (j = 0; j <= lc; j++) { /* loop count loop */
1553 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001554 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1555 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001556 dma_sync_single_for_device(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001557 tx_ring->buffer_info[k].dma,
1558 tx_ring->buffer_info[k].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001559 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001560 k++;
1561 if (k == tx_ring->count)
1562 k = 0;
1563 }
1564 ew32(TDT, k);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001565 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001566 msleep(200);
1567 time = jiffies; /* set the start time for the receive */
1568 good_cnt = 0;
1569 do { /* receive the sent packets */
Nick Nunley0be3f552010-04-27 13:09:05 +00001570 dma_sync_single_for_cpu(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001571 rx_ring->buffer_info[l].dma, 2048,
Nick Nunley0be3f552010-04-27 13:09:05 +00001572 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001573
1574 ret_val = e1000_check_lbtest_frame(
1575 rx_ring->buffer_info[l].skb, 1024);
1576 if (!ret_val)
1577 good_cnt++;
1578 l++;
1579 if (l == rx_ring->count)
1580 l = 0;
Bruce Allanad680762008-03-28 09:15:03 -07001581 /*
1582 * time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001583 * enough time to complete the receives, if it's
1584 * exceeded, break and error off
1585 */
1586 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1587 if (good_cnt != 64) {
1588 ret_val = 13; /* ret_val is the same as mis-compare */
1589 break;
1590 }
Bruce Allancef8c792008-04-02 13:48:23 -07001591 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001592 ret_val = 14; /* error code for time out error */
1593 break;
1594 }
1595 } /* end loop count loop */
1596 return ret_val;
1597}
1598
1599static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1600{
Bruce Allanad680762008-03-28 09:15:03 -07001601 /*
1602 * PHY loopback cannot be performed if SoL/IDER
1603 * sessions are active
1604 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001605 if (e1000_check_reset_block(&adapter->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)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001792 e_err("Interface does not support directed (unicast) "
1793 "frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001794 }
1795
1796 if (adapter->wol & E1000_WUFC_EX)
1797 wol->wolopts |= WAKE_UCAST;
1798 if (adapter->wol & E1000_WUFC_MC)
1799 wol->wolopts |= WAKE_MCAST;
1800 if (adapter->wol & E1000_WUFC_BC)
1801 wol->wolopts |= WAKE_BCAST;
1802 if (adapter->wol & E1000_WUFC_MAG)
1803 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001804 if (adapter->wol & E1000_WUFC_LNKC)
1805 wol->wolopts |= WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001806}
1807
Bruce Allan4a29e152011-03-04 09:07:01 +00001808static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001809{
1810 struct e1000_adapter *adapter = netdev_priv(netdev);
1811
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001812 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001813 !device_can_wakeup(&adapter->pdev->dev) ||
1814 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001815 WAKE_MAGIC | WAKE_PHY)))
Bruce Allan1fbfca32009-11-20 23:22:01 +00001816 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001817
1818 /* these settings will always override what we currently have */
1819 adapter->wol = 0;
1820
1821 if (wol->wolopts & WAKE_UCAST)
1822 adapter->wol |= E1000_WUFC_EX;
1823 if (wol->wolopts & WAKE_MCAST)
1824 adapter->wol |= E1000_WUFC_MC;
1825 if (wol->wolopts & WAKE_BCAST)
1826 adapter->wol |= E1000_WUFC_BC;
1827 if (wol->wolopts & WAKE_MAGIC)
1828 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001829 if (wol->wolopts & WAKE_PHY)
1830 adapter->wol |= E1000_WUFC_LNKC;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001831
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001832 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1833
Auke Kokbc7f75f2007-09-17 12:30:59 -07001834 return 0;
1835}
1836
Bruce Allandbf80dc2011-04-16 00:34:40 +00001837static int e1000_set_phys_id(struct net_device *netdev,
1838 enum ethtool_phys_id_state state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001839{
1840 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001841 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001842
Bruce Allandbf80dc2011-04-16 00:34:40 +00001843 switch (state) {
1844 case ETHTOOL_ID_ACTIVE:
1845 if (!hw->mac.ops.blink_led)
1846 return 2; /* cycle on/off twice per second */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001847
Bruce Allandbf80dc2011-04-16 00:34:40 +00001848 hw->mac.ops.blink_led(hw);
1849 break;
1850
1851 case ETHTOOL_ID_INACTIVE:
Bruce Allan4662e822008-08-26 18:37:06 -07001852 if (hw->phy.type == e1000_phy_ife)
1853 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001854 hw->mac.ops.led_off(hw);
1855 hw->mac.ops.cleanup_led(hw);
1856 break;
1857
1858 case ETHTOOL_ID_ON:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001859 hw->mac.ops.led_on(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001860 break;
1861
1862 case ETHTOOL_ID_OFF:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001863 hw->mac.ops.led_off(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001864 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001865 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001866 return 0;
1867}
1868
Auke Kokde5b3072008-04-23 11:09:08 -07001869static int e1000_get_coalesce(struct net_device *netdev,
1870 struct ethtool_coalesce *ec)
1871{
1872 struct e1000_adapter *adapter = netdev_priv(netdev);
1873
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001874 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07001875 ec->rx_coalesce_usecs = adapter->itr_setting;
1876 else
1877 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1878
1879 return 0;
1880}
1881
1882static int e1000_set_coalesce(struct net_device *netdev,
1883 struct ethtool_coalesce *ec)
1884{
1885 struct e1000_adapter *adapter = netdev_priv(netdev);
1886 struct e1000_hw *hw = &adapter->hw;
1887
1888 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001889 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07001890 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1891 (ec->rx_coalesce_usecs == 2))
1892 return -EINVAL;
1893
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001894 if (ec->rx_coalesce_usecs == 4) {
1895 adapter->itr = adapter->itr_setting = 4;
1896 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07001897 adapter->itr = 20000;
1898 adapter->itr_setting = ec->rx_coalesce_usecs;
1899 } else {
1900 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1901 adapter->itr_setting = adapter->itr & ~3;
1902 }
1903
1904 if (adapter->itr_setting != 0)
1905 ew32(ITR, 1000000000 / (adapter->itr * 256));
1906 else
1907 ew32(ITR, 0);
1908
1909 return 0;
1910}
1911
Auke Kokbc7f75f2007-09-17 12:30:59 -07001912static int e1000_nway_reset(struct net_device *netdev)
1913{
1914 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan5962bc22011-01-20 06:58:07 +00001915
1916 if (!netif_running(netdev))
1917 return -EAGAIN;
1918
1919 if (!adapter->hw.mac.autoneg)
1920 return -EINVAL;
1921
1922 e1000e_reinit_locked(adapter);
1923
Auke Kokbc7f75f2007-09-17 12:30:59 -07001924 return 0;
1925}
1926
Auke Kokbc7f75f2007-09-17 12:30:59 -07001927static void e1000_get_ethtool_stats(struct net_device *netdev,
1928 struct ethtool_stats *stats,
1929 u64 *data)
1930{
1931 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001932 struct rtnl_link_stats64 net_stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001933 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001934 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001935
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001936 e1000e_get_stats64(netdev, &net_stats);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001937 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001938 switch (e1000_gstrings_stats[i].type) {
1939 case NETDEV_STATS:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001940 p = (char *) &net_stats +
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001941 e1000_gstrings_stats[i].stat_offset;
1942 break;
1943 case E1000_STATS:
1944 p = (char *) adapter +
1945 e1000_gstrings_stats[i].stat_offset;
1946 break;
Bruce Allan61c75812010-12-09 23:04:25 +00001947 default:
1948 data[i] = 0;
1949 continue;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001950 }
1951
Auke Kokbc7f75f2007-09-17 12:30:59 -07001952 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1953 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1954 }
1955}
1956
1957static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1958 u8 *data)
1959{
1960 u8 *p = data;
1961 int i;
1962
1963 switch (stringset) {
1964 case ETH_SS_TEST:
Bruce Allan5c1bda02011-01-19 04:23:39 +00001965 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001966 break;
1967 case ETH_SS_STATS:
1968 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1969 memcpy(p, e1000_gstrings_stats[i].stat_string,
1970 ETH_GSTRING_LEN);
1971 p += ETH_GSTRING_LEN;
1972 }
1973 break;
1974 }
1975}
1976
Bruce Allan70495a52012-01-11 01:26:50 +00001977static int e1000_get_rxnfc(struct net_device *netdev,
1978 struct ethtool_rxnfc *info, u32 *rule_locs)
1979{
1980 info->data = 0;
1981
1982 switch (info->cmd) {
1983 case ETHTOOL_GRXFH: {
1984 struct e1000_adapter *adapter = netdev_priv(netdev);
1985 struct e1000_hw *hw = &adapter->hw;
1986 u32 mrqc = er32(MRQC);
1987
1988 if (!(mrqc & E1000_MRQC_RSS_FIELD_MASK))
1989 return 0;
1990
1991 switch (info->flow_type) {
1992 case TCP_V4_FLOW:
1993 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP)
1994 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1995 /* fall through */
1996 case UDP_V4_FLOW:
1997 case SCTP_V4_FLOW:
1998 case AH_ESP_V4_FLOW:
1999 case IPV4_FLOW:
2000 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4)
2001 info->data |= RXH_IP_SRC | RXH_IP_DST;
2002 break;
2003 case TCP_V6_FLOW:
2004 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP)
2005 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2006 /* fall through */
2007 case UDP_V6_FLOW:
2008 case SCTP_V6_FLOW:
2009 case AH_ESP_V6_FLOW:
2010 case IPV6_FLOW:
2011 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6)
2012 info->data |= RXH_IP_SRC | RXH_IP_DST;
2013 break;
2014 default:
2015 break;
2016 }
2017 return 0;
2018 }
2019 default:
2020 return -EOPNOTSUPP;
2021 }
2022}
2023
Auke Kokbc7f75f2007-09-17 12:30:59 -07002024static const struct ethtool_ops e1000_ethtool_ops = {
2025 .get_settings = e1000_get_settings,
2026 .set_settings = e1000_set_settings,
2027 .get_drvinfo = e1000_get_drvinfo,
2028 .get_regs_len = e1000_get_regs_len,
2029 .get_regs = e1000_get_regs,
2030 .get_wol = e1000_get_wol,
2031 .set_wol = e1000_set_wol,
2032 .get_msglevel = e1000_get_msglevel,
2033 .set_msglevel = e1000_set_msglevel,
2034 .nway_reset = e1000_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00002035 .get_link = ethtool_op_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002036 .get_eeprom_len = e1000_get_eeprom_len,
2037 .get_eeprom = e1000_get_eeprom,
2038 .set_eeprom = e1000_set_eeprom,
2039 .get_ringparam = e1000_get_ringparam,
2040 .set_ringparam = e1000_set_ringparam,
2041 .get_pauseparam = e1000_get_pauseparam,
2042 .set_pauseparam = e1000_set_pauseparam,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002043 .self_test = e1000_diag_test,
2044 .get_strings = e1000_get_strings,
Bruce Allandbf80dc2011-04-16 00:34:40 +00002045 .set_phys_id = e1000_set_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002046 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07002047 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07002048 .get_coalesce = e1000_get_coalesce,
2049 .set_coalesce = e1000_set_coalesce,
Bruce Allan70495a52012-01-11 01:26:50 +00002050 .get_rxnfc = e1000_get_rxnfc,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002051};
2052
2053void e1000e_set_ethtool_ops(struct net_device *netdev)
2054{
2055 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
2056}