blob: 58df18c2efc22cfc32b403e72452044eb41f013b [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanbf670442013-01-01 16:00:01 +00004 Copyright(c) 1999 - 2013 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>
Bruce Allan203e4152012-12-05 08:40:59 +000038#include <linux/mdio.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070039
40#include "e1000.h"
41
Ajit Khapardee0f36a92009-10-13 01:45:09 +000042enum {NETDEV_STATS, E1000_STATS};
43
Auke Kokbc7f75f2007-09-17 12:30:59 -070044struct e1000_stats {
45 char stat_string[ETH_GSTRING_LEN];
Ajit Khapardee0f36a92009-10-13 01:45:09 +000046 int type;
Auke Kokbc7f75f2007-09-17 12:30:59 -070047 int sizeof_stat;
48 int stat_offset;
49};
50
Bruce Allanf0f1a172010-12-11 05:53:32 +000051#define E1000_STAT(str, m) { \
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000052 .stat_string = str, \
53 .type = E1000_STATS, \
54 .sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
55 .stat_offset = offsetof(struct e1000_adapter, m) }
Bruce Allanf0f1a172010-12-11 05:53:32 +000056#define E1000_NETDEV_STAT(str, m) { \
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000057 .stat_string = str, \
58 .type = NETDEV_STATS, \
59 .sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \
60 .stat_offset = offsetof(struct rtnl_link_stats64, m) }
Ajit Khapardee0f36a92009-10-13 01:45:09 +000061
Auke Kokbc7f75f2007-09-17 12:30:59 -070062static const struct e1000_stats e1000_gstrings_stats[] = {
Bruce Allanf0f1a172010-12-11 05:53:32 +000063 E1000_STAT("rx_packets", stats.gprc),
64 E1000_STAT("tx_packets", stats.gptc),
65 E1000_STAT("rx_bytes", stats.gorc),
66 E1000_STAT("tx_bytes", stats.gotc),
67 E1000_STAT("rx_broadcast", stats.bprc),
68 E1000_STAT("tx_broadcast", stats.bptc),
69 E1000_STAT("rx_multicast", stats.mprc),
70 E1000_STAT("tx_multicast", stats.mptc),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000071 E1000_NETDEV_STAT("rx_errors", rx_errors),
72 E1000_NETDEV_STAT("tx_errors", tx_errors),
73 E1000_NETDEV_STAT("tx_dropped", tx_dropped),
Bruce Allanf0f1a172010-12-11 05:53:32 +000074 E1000_STAT("multicast", stats.mprc),
75 E1000_STAT("collisions", stats.colc),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000076 E1000_NETDEV_STAT("rx_length_errors", rx_length_errors),
77 E1000_NETDEV_STAT("rx_over_errors", rx_over_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000078 E1000_STAT("rx_crc_errors", stats.crcerrs),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000079 E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000080 E1000_STAT("rx_no_buffer_count", stats.rnbc),
81 E1000_STAT("rx_missed_errors", stats.mpc),
82 E1000_STAT("tx_aborted_errors", stats.ecol),
83 E1000_STAT("tx_carrier_errors", stats.tncrs),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000084 E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
85 E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000086 E1000_STAT("tx_window_errors", stats.latecol),
87 E1000_STAT("tx_abort_late_coll", stats.latecol),
88 E1000_STAT("tx_deferred_ok", stats.dc),
89 E1000_STAT("tx_single_coll_ok", stats.scc),
90 E1000_STAT("tx_multi_coll_ok", stats.mcc),
91 E1000_STAT("tx_timeout_count", tx_timeout_count),
92 E1000_STAT("tx_restart_queue", restart_queue),
93 E1000_STAT("rx_long_length_errors", stats.roc),
94 E1000_STAT("rx_short_length_errors", stats.ruc),
95 E1000_STAT("rx_align_errors", stats.algnerrc),
96 E1000_STAT("tx_tcp_seg_good", stats.tsctc),
97 E1000_STAT("tx_tcp_seg_failed", stats.tsctfc),
98 E1000_STAT("rx_flow_control_xon", stats.xonrxc),
99 E1000_STAT("rx_flow_control_xoff", stats.xoffrxc),
100 E1000_STAT("tx_flow_control_xon", stats.xontxc),
101 E1000_STAT("tx_flow_control_xoff", stats.xofftxc),
Bruce Allanf0f1a172010-12-11 05:53:32 +0000102 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),
Bruce Allanb67e1912012-12-27 08:32:33 +0000111 E1000_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Bruce Allan94fb8482013-01-23 09:00:03 +0000112 E1000_STAT("uncorr_ecc_errors", uncorr_errors),
113 E1000_STAT("corr_ecc_errors", corr_errors),
Auke Kokbc7f75f2007-09-17 12:30:59 -0700114};
115
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200116#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700117#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
118static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
119 "Register test (offline)", "Eeprom test (offline)",
120 "Interrupt test (offline)", "Loopback test (offline)",
121 "Link test (on/offline)"
122};
Bruce Allanad680762008-03-28 09:15:03 -0700123#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700124
125static int e1000_get_settings(struct net_device *netdev,
126 struct ethtool_cmd *ecmd)
127{
128 struct e1000_adapter *adapter = netdev_priv(netdev);
129 struct e1000_hw *hw = &adapter->hw;
David Decotigny70739492011-04-27 18:32:40 +0000130 u32 speed;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700131
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700132 if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700133
134 ecmd->supported = (SUPPORTED_10baseT_Half |
135 SUPPORTED_10baseT_Full |
136 SUPPORTED_100baseT_Half |
137 SUPPORTED_100baseT_Full |
138 SUPPORTED_1000baseT_Full |
139 SUPPORTED_Autoneg |
140 SUPPORTED_TP);
141 if (hw->phy.type == e1000_phy_ife)
142 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
143 ecmd->advertising = ADVERTISED_TP;
144
145 if (hw->mac.autoneg == 1) {
146 ecmd->advertising |= ADVERTISED_Autoneg;
147 /* the e1000 autoneg seems to match ethtool nicely */
148 ecmd->advertising |= hw->phy.autoneg_advertised;
149 }
150
151 ecmd->port = PORT_TP;
152 ecmd->phy_address = hw->phy.addr;
153 ecmd->transceiver = XCVR_INTERNAL;
154
155 } else {
156 ecmd->supported = (SUPPORTED_1000baseT_Full |
157 SUPPORTED_FIBRE |
158 SUPPORTED_Autoneg);
159
160 ecmd->advertising = (ADVERTISED_1000baseT_Full |
161 ADVERTISED_FIBRE |
162 ADVERTISED_Autoneg);
163
164 ecmd->port = PORT_FIBRE;
165 ecmd->transceiver = XCVR_EXTERNAL;
166 }
167
David Decotigny70739492011-04-27 18:32:40 +0000168 speed = -1;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000169 ecmd->duplex = -1;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700170
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000171 if (netif_running(netdev)) {
172 if (netif_carrier_ok(netdev)) {
David Decotigny70739492011-04-27 18:32:40 +0000173 speed = adapter->link_speed;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000174 ecmd->duplex = adapter->link_duplex - 1;
175 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700176 } else {
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000177 u32 status = er32(STATUS);
178 if (status & E1000_STATUS_LU) {
179 if (status & E1000_STATUS_SPEED_1000)
David Decotigny70739492011-04-27 18:32:40 +0000180 speed = SPEED_1000;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000181 else if (status & E1000_STATUS_SPEED_100)
David Decotigny70739492011-04-27 18:32:40 +0000182 speed = SPEED_100;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000183 else
David Decotigny70739492011-04-27 18:32:40 +0000184 speed = SPEED_10;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000185
186 if (status & E1000_STATUS_FD)
187 ecmd->duplex = DUPLEX_FULL;
188 else
189 ecmd->duplex = DUPLEX_HALF;
190 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700191 }
192
David Decotigny70739492011-04-27 18:32:40 +0000193 ethtool_cmd_speed_set(ecmd, speed);
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700194 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -0700195 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000196
197 /* MDI-X => 2; MDI =>1; Invalid =>0 */
198 if ((hw->phy.media_type == e1000_media_type_copper) &&
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000199 netif_carrier_ok(netdev))
Chaitanya Lala18760f12009-06-08 14:28:54 +0000200 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
201 ETH_TP_MDI;
202 else
203 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
204
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000205 if (hw->phy.mdix == AUTO_ALL_MODES)
206 ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
207 else
208 ecmd->eth_tp_mdix_ctrl = hw->phy.mdix;
209
Auke Kokbc7f75f2007-09-17 12:30:59 -0700210 return 0;
211}
212
David Decotigny14ad2512011-04-27 18:32:43 +0000213static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700214{
215 struct e1000_mac_info *mac = &adapter->hw.mac;
216
217 mac->autoneg = 0;
218
David Decotigny14ad2512011-04-27 18:32:43 +0000219 /* Make sure dplx is at most 1 bit and lsb of speed is not set
Bruce Allane921eb12012-11-28 09:28:37 +0000220 * for the switch() below to work
221 */
David Decotigny14ad2512011-04-27 18:32:43 +0000222 if ((spd & 1) || (dplx & ~1))
223 goto err_inval;
224
Auke Kokbc7f75f2007-09-17 12:30:59 -0700225 /* Fiber NICs only allow 1000 gbps Full duplex */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700226 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
David Decotigny14ad2512011-04-27 18:32:43 +0000227 spd != SPEED_1000 &&
228 dplx != DUPLEX_FULL) {
229 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700230 }
231
David Decotigny14ad2512011-04-27 18:32:43 +0000232 switch (spd + dplx) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700233 case SPEED_10 + DUPLEX_HALF:
234 mac->forced_speed_duplex = ADVERTISE_10_HALF;
235 break;
236 case SPEED_10 + DUPLEX_FULL:
237 mac->forced_speed_duplex = ADVERTISE_10_FULL;
238 break;
239 case SPEED_100 + DUPLEX_HALF:
240 mac->forced_speed_duplex = ADVERTISE_100_HALF;
241 break;
242 case SPEED_100 + DUPLEX_FULL:
243 mac->forced_speed_duplex = ADVERTISE_100_FULL;
244 break;
245 case SPEED_1000 + DUPLEX_FULL:
246 mac->autoneg = 1;
247 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
248 break;
249 case SPEED_1000 + DUPLEX_HALF: /* not supported */
250 default:
David Decotigny14ad2512011-04-27 18:32:43 +0000251 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700252 }
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000253
254 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
255 adapter->hw.phy.mdix = AUTO_ALL_MODES;
256
Auke Kokbc7f75f2007-09-17 12:30:59 -0700257 return 0;
David Decotigny14ad2512011-04-27 18:32:43 +0000258
259err_inval:
260 e_err("Unsupported Speed/Duplex configuration\n");
261 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700262}
263
264static int e1000_set_settings(struct net_device *netdev,
265 struct ethtool_cmd *ecmd)
266{
267 struct e1000_adapter *adapter = netdev_priv(netdev);
268 struct e1000_hw *hw = &adapter->hw;
269
Bruce Allane921eb12012-11-28 09:28:37 +0000270 /* When SoL/IDER sessions are active, autoneg/speed/duplex
Bruce Allanad680762008-03-28 09:15:03 -0700271 * cannot be changed
272 */
Bruce Allan470a5422012-05-26 06:08:48 +0000273 if (hw->phy.ops.check_reset_block &&
274 hw->phy.ops.check_reset_block(hw)) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000275 e_err("Cannot change link characteristics when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700276 return -EINVAL;
277 }
278
Bruce Allane921eb12012-11-28 09:28:37 +0000279 /* MDI setting is only allowed when autoneg enabled because
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000280 * some hardware doesn't allow MDI setting when speed or
281 * duplex is forced.
282 */
283 if (ecmd->eth_tp_mdix_ctrl) {
284 if (hw->phy.media_type != e1000_media_type_copper)
285 return -EOPNOTSUPP;
286
287 if ((ecmd->eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) &&
288 (ecmd->autoneg != AUTONEG_ENABLE)) {
289 e_err("forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
290 return -EINVAL;
291 }
292 }
293
Auke Kokbc7f75f2007-09-17 12:30:59 -0700294 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000295 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700296
297 if (ecmd->autoneg == AUTONEG_ENABLE) {
298 hw->mac.autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700299 if (hw->phy.media_type == e1000_media_type_fiber)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700300 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
301 ADVERTISED_FIBRE |
302 ADVERTISED_Autoneg;
303 else
304 hw->phy.autoneg_advertised = ecmd->advertising |
305 ADVERTISED_TP |
306 ADVERTISED_Autoneg;
307 ecmd->advertising = hw->phy.autoneg_advertised;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700308 if (adapter->fc_autoneg)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800309 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700310 } else {
David Decotigny25db0332011-04-27 18:32:39 +0000311 u32 speed = ethtool_cmd_speed(ecmd);
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000312 /* calling this overrides forced MDI setting */
David Decotigny14ad2512011-04-27 18:32:43 +0000313 if (e1000_set_spd_dplx(adapter, speed, ecmd->duplex)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700314 clear_bit(__E1000_RESETTING, &adapter->state);
315 return -EINVAL;
316 }
317 }
318
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000319 /* MDI-X => 2; MDI => 1; Auto => 3 */
320 if (ecmd->eth_tp_mdix_ctrl) {
Bruce Allane921eb12012-11-28 09:28:37 +0000321 /* fix up the value for auto (3 => 0) as zero is mapped
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000322 * internally to auto
323 */
324 if (ecmd->eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
325 hw->phy.mdix = AUTO_ALL_MODES;
326 else
327 hw->phy.mdix = ecmd->eth_tp_mdix_ctrl;
328 }
329
Auke Kokbc7f75f2007-09-17 12:30:59 -0700330 /* reset the link */
331
332 if (netif_running(adapter->netdev)) {
333 e1000e_down(adapter);
334 e1000e_up(adapter);
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000335 } else
Auke Kokbc7f75f2007-09-17 12:30:59 -0700336 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700337
338 clear_bit(__E1000_RESETTING, &adapter->state);
339 return 0;
340}
341
342static void e1000_get_pauseparam(struct net_device *netdev,
343 struct ethtool_pauseparam *pause)
344{
345 struct e1000_adapter *adapter = netdev_priv(netdev);
346 struct e1000_hw *hw = &adapter->hw;
347
348 pause->autoneg =
349 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
350
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800351 if (hw->fc.current_mode == e1000_fc_rx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700352 pause->rx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800353 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700354 pause->tx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800355 } else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700356 pause->rx_pause = 1;
357 pause->tx_pause = 1;
358 }
359}
360
361static int e1000_set_pauseparam(struct net_device *netdev,
362 struct ethtool_pauseparam *pause)
363{
364 struct e1000_adapter *adapter = netdev_priv(netdev);
365 struct e1000_hw *hw = &adapter->hw;
366 int retval = 0;
367
368 adapter->fc_autoneg = pause->autoneg;
369
370 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000371 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700372
Auke Kokbc7f75f2007-09-17 12:30:59 -0700373 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800374 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700375 if (netif_running(adapter->netdev)) {
376 e1000e_down(adapter);
377 e1000e_up(adapter);
378 } else {
379 e1000e_reset(adapter);
380 }
381 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800382 if (pause->rx_pause && pause->tx_pause)
383 hw->fc.requested_mode = e1000_fc_full;
384 else if (pause->rx_pause && !pause->tx_pause)
385 hw->fc.requested_mode = e1000_fc_rx_pause;
386 else if (!pause->rx_pause && pause->tx_pause)
387 hw->fc.requested_mode = e1000_fc_tx_pause;
388 else if (!pause->rx_pause && !pause->tx_pause)
389 hw->fc.requested_mode = e1000_fc_none;
390
391 hw->fc.current_mode = hw->fc.requested_mode;
392
Bruce Allan945eb312009-10-28 18:28:30 +0000393 if (hw->phy.media_type == e1000_media_type_fiber) {
394 retval = hw->mac.ops.setup_link(hw);
395 /* implicit goto out */
396 } else {
397 retval = e1000e_force_mac_fc(hw);
398 if (retval)
399 goto out;
400 e1000e_set_fc_watermarks(hw);
401 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700402 }
403
Bruce Allan945eb312009-10-28 18:28:30 +0000404out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700405 clear_bit(__E1000_RESETTING, &adapter->state);
406 return retval;
407}
408
Auke Kokbc7f75f2007-09-17 12:30:59 -0700409static u32 e1000_get_msglevel(struct net_device *netdev)
410{
411 struct e1000_adapter *adapter = netdev_priv(netdev);
412 return adapter->msg_enable;
413}
414
415static void e1000_set_msglevel(struct net_device *netdev, u32 data)
416{
417 struct e1000_adapter *adapter = netdev_priv(netdev);
418 adapter->msg_enable = data;
419}
420
421static int e1000_get_regs_len(struct net_device *netdev)
422{
423#define E1000_REGS_LEN 32 /* overestimate */
424 return E1000_REGS_LEN * sizeof(u32);
425}
426
427static void e1000_get_regs(struct net_device *netdev,
428 struct ethtool_regs *regs, void *p)
429{
430 struct e1000_adapter *adapter = netdev_priv(netdev);
431 struct e1000_hw *hw = &adapter->hw;
432 u32 *regs_buff = p;
433 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700434
435 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
436
Sergei Shtylyovff938e42011-02-28 11:57:33 -0800437 regs->version = (1 << 24) | (adapter->pdev->revision << 16) |
438 adapter->pdev->device;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700439
440 regs_buff[0] = er32(CTRL);
441 regs_buff[1] = er32(STATUS);
442
443 regs_buff[2] = er32(RCTL);
Bruce Allan1e360522012-03-20 03:48:13 +0000444 regs_buff[3] = er32(RDLEN(0));
445 regs_buff[4] = er32(RDH(0));
446 regs_buff[5] = er32(RDT(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700447 regs_buff[6] = er32(RDTR);
448
449 regs_buff[7] = er32(TCTL);
Bruce Allan1e360522012-03-20 03:48:13 +0000450 regs_buff[8] = er32(TDLEN(0));
451 regs_buff[9] = er32(TDH(0));
452 regs_buff[10] = er32(TDT(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700453 regs_buff[11] = er32(TIDV);
454
455 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700456
457 /* ethtool doesn't use anything past this point, so all this
Bruce Allane921eb12012-11-28 09:28:37 +0000458 * code is likely legacy junk for apps that may or may not exist
459 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700460 if (hw->phy.type == e1000_phy_m88) {
461 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
462 regs_buff[13] = (u32)phy_data; /* cable length */
463 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
464 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
465 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
466 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
467 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
468 regs_buff[18] = regs_buff[13]; /* cable polarity */
469 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
470 regs_buff[20] = regs_buff[17]; /* polarity correction */
471 /* phy receive errors */
472 regs_buff[22] = adapter->phy_stats.receive_errors;
473 regs_buff[23] = regs_buff[13]; /* mdix mode */
474 }
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700475 regs_buff[21] = 0; /* was idle_errors */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700476 e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
477 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
478 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
479}
480
481static int e1000_get_eeprom_len(struct net_device *netdev)
482{
483 struct e1000_adapter *adapter = netdev_priv(netdev);
484 return adapter->hw.nvm.word_size * 2;
485}
486
487static int e1000_get_eeprom(struct net_device *netdev,
488 struct ethtool_eeprom *eeprom, u8 *bytes)
489{
490 struct e1000_adapter *adapter = netdev_priv(netdev);
491 struct e1000_hw *hw = &adapter->hw;
492 u16 *eeprom_buff;
493 int first_word;
494 int last_word;
495 int ret_val = 0;
496 u16 i;
497
498 if (eeprom->len == 0)
499 return -EINVAL;
500
501 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
502
503 first_word = eeprom->offset >> 1;
504 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
505
506 eeprom_buff = kmalloc(sizeof(u16) *
507 (last_word - first_word + 1), GFP_KERNEL);
508 if (!eeprom_buff)
509 return -ENOMEM;
510
511 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
512 ret_val = e1000_read_nvm(hw, first_word,
513 last_word - first_word + 1,
514 eeprom_buff);
515 } else {
516 for (i = 0; i < last_word - first_word + 1; i++) {
517 ret_val = e1000_read_nvm(hw, first_word + i, 1,
518 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800519 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700520 break;
521 }
522 }
523
Bruce Allane2434552008-11-21 17:02:41 -0800524 if (ret_val) {
525 /* a read error occurred, throw away the result */
Roel Kluin8528b012009-12-01 15:54:24 +0000526 memset(eeprom_buff, 0xff, sizeof(u16) *
527 (last_word - first_word + 1));
Bruce Allane2434552008-11-21 17:02:41 -0800528 } else {
529 /* Device's eeprom is always little-endian, word addressable */
530 for (i = 0; i < last_word - first_word + 1; i++)
531 le16_to_cpus(&eeprom_buff[i]);
532 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700533
534 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
535 kfree(eeprom_buff);
536
537 return ret_val;
538}
539
540static int e1000_set_eeprom(struct net_device *netdev,
541 struct ethtool_eeprom *eeprom, u8 *bytes)
542{
543 struct e1000_adapter *adapter = netdev_priv(netdev);
544 struct e1000_hw *hw = &adapter->hw;
545 u16 *eeprom_buff;
546 void *ptr;
547 int max_len;
548 int first_word;
549 int last_word;
550 int ret_val = 0;
551 u16 i;
552
553 if (eeprom->len == 0)
554 return -EOPNOTSUPP;
555
556 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
557 return -EFAULT;
558
Bruce Allan4a770352008-10-01 17:18:35 -0700559 if (adapter->flags & FLAG_READ_ONLY_NVM)
560 return -EINVAL;
561
Auke Kokbc7f75f2007-09-17 12:30:59 -0700562 max_len = hw->nvm.word_size * 2;
563
564 first_word = eeprom->offset >> 1;
565 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
566 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
567 if (!eeprom_buff)
568 return -ENOMEM;
569
570 ptr = (void *)eeprom_buff;
571
572 if (eeprom->offset & 1) {
573 /* need read/modify/write of first changed EEPROM word */
574 /* only the second byte of the word is being modified */
575 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
576 ptr++;
577 }
Bruce Allan9e2d7652012-01-31 06:37:27 +0000578 if (((eeprom->offset + eeprom->len) & 1) && (!ret_val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700579 /* need read/modify/write of last changed EEPROM word */
580 /* only the first byte of the word is being modified */
581 ret_val = e1000_read_nvm(hw, last_word, 1,
582 &eeprom_buff[last_word - first_word]);
583
Bruce Allane2434552008-11-21 17:02:41 -0800584 if (ret_val)
585 goto out;
586
Auke Kokbc7f75f2007-09-17 12:30:59 -0700587 /* Device's eeprom is always little-endian, word addressable */
588 for (i = 0; i < last_word - first_word + 1; i++)
589 le16_to_cpus(&eeprom_buff[i]);
590
591 memcpy(ptr, bytes, eeprom->len);
592
593 for (i = 0; i < last_word - first_word + 1; i++)
Bruce Allane885d762012-01-31 06:37:32 +0000594 cpu_to_le16s(&eeprom_buff[i]);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700595
596 ret_val = e1000_write_nvm(hw, first_word,
597 last_word - first_word + 1, eeprom_buff);
598
Bruce Allane2434552008-11-21 17:02:41 -0800599 if (ret_val)
600 goto out;
601
Bruce Allane921eb12012-11-28 09:28:37 +0000602 /* Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800603 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700604 */
Bruce Allane2434552008-11-21 17:02:41 -0800605 if ((first_word <= NVM_CHECKSUM_REG) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +0000606 (hw->mac.type == e1000_82583) ||
607 (hw->mac.type == e1000_82574) ||
608 (hw->mac.type == e1000_82573))
Bruce Allane2434552008-11-21 17:02:41 -0800609 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700610
Bruce Allane2434552008-11-21 17:02:41 -0800611out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700612 kfree(eeprom_buff);
613 return ret_val;
614}
615
616static void e1000_get_drvinfo(struct net_device *netdev,
617 struct ethtool_drvinfo *drvinfo)
618{
619 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700620
Rick Jones612a94d2011-11-14 08:13:25 +0000621 strlcpy(drvinfo->driver, e1000e_driver_name,
622 sizeof(drvinfo->driver));
Rick Jones33a5ba12011-11-15 14:59:53 +0000623 strlcpy(drvinfo->version, e1000e_driver_version,
Rick Jones612a94d2011-11-14 08:13:25 +0000624 sizeof(drvinfo->version));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700625
Bruce Allane921eb12012-11-28 09:28:37 +0000626 /* EEPROM image version # is reported as firmware version # for
Bruce Allanad680762008-03-28 09:15:03 -0700627 * PCI-E controllers
628 */
Rick Jones612a94d2011-11-14 08:13:25 +0000629 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
630 "%d.%d-%d",
Bruce Allan84527592008-11-21 17:00:22 -0800631 (adapter->eeprom_vers & 0xF000) >> 12,
632 (adapter->eeprom_vers & 0x0FF0) >> 4,
633 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700634
Rick Jones612a94d2011-11-14 08:13:25 +0000635 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
636 sizeof(drvinfo->bus_info));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700637 drvinfo->regdump_len = e1000_get_regs_len(netdev);
638 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
639}
640
641static void e1000_get_ringparam(struct net_device *netdev,
642 struct ethtool_ringparam *ring)
643{
644 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700645
646 ring->rx_max_pending = E1000_MAX_RXD;
647 ring->tx_max_pending = E1000_MAX_TXD;
Bruce Allan508da422011-12-16 00:45:51 +0000648 ring->rx_pending = adapter->rx_ring_count;
649 ring->tx_pending = adapter->tx_ring_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700650}
651
652static int e1000_set_ringparam(struct net_device *netdev,
653 struct ethtool_ringparam *ring)
654{
655 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan508da422011-12-16 00:45:51 +0000656 struct e1000_ring *temp_tx = NULL, *temp_rx = NULL;
657 int err = 0, size = sizeof(struct e1000_ring);
658 bool set_tx = false, set_rx = false;
659 u16 new_rx_count, new_tx_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700660
661 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
662 return -EINVAL;
663
Bruce Allan508da422011-12-16 00:45:51 +0000664 new_rx_count = clamp_t(u32, ring->rx_pending, E1000_MIN_RXD,
665 E1000_MAX_RXD);
666 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
667
668 new_tx_count = clamp_t(u32, ring->tx_pending, E1000_MIN_TXD,
669 E1000_MAX_TXD);
670 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
671
672 if ((new_tx_count == adapter->tx_ring_count) &&
673 (new_rx_count == adapter->rx_ring_count))
674 /* nothing to do */
675 return 0;
676
Auke Kokbc7f75f2007-09-17 12:30:59 -0700677 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000678 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700679
Bruce Allan508da422011-12-16 00:45:51 +0000680 if (!netif_running(adapter->netdev)) {
681 /* Set counts now and allocate resources during open() */
682 adapter->tx_ring->count = new_tx_count;
683 adapter->rx_ring->count = new_rx_count;
684 adapter->tx_ring_count = new_tx_count;
685 adapter->rx_ring_count = new_rx_count;
686 goto clear_reset;
687 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700688
Bruce Allan508da422011-12-16 00:45:51 +0000689 set_tx = (new_tx_count != adapter->tx_ring_count);
690 set_rx = (new_rx_count != adapter->rx_ring_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700691
Bruce Allan508da422011-12-16 00:45:51 +0000692 /* Allocate temporary storage for ring updates */
693 if (set_tx) {
694 temp_tx = vmalloc(size);
695 if (!temp_tx) {
696 err = -ENOMEM;
697 goto free_temp;
698 }
699 }
700 if (set_rx) {
701 temp_rx = vmalloc(size);
702 if (!temp_rx) {
703 err = -ENOMEM;
704 goto free_temp;
705 }
706 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700707
Bruce Allan508da422011-12-16 00:45:51 +0000708 e1000e_down(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700709
Bruce Allane921eb12012-11-28 09:28:37 +0000710 /* We can't just free everything and then setup again, because the
Bruce Allan508da422011-12-16 00:45:51 +0000711 * ISRs in MSI-X mode get passed pointers to the Tx and Rx ring
712 * structs. First, attempt to allocate new resources...
713 */
714 if (set_tx) {
715 memcpy(temp_tx, adapter->tx_ring, size);
716 temp_tx->count = new_tx_count;
717 err = e1000e_setup_tx_resources(temp_tx);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700718 if (err)
719 goto err_setup;
720 }
Bruce Allan508da422011-12-16 00:45:51 +0000721 if (set_rx) {
722 memcpy(temp_rx, adapter->rx_ring, size);
723 temp_rx->count = new_rx_count;
724 err = e1000e_setup_rx_resources(temp_rx);
725 if (err)
726 goto err_setup_rx;
727 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700728
Bruce Allan508da422011-12-16 00:45:51 +0000729 /* ...then free the old resources and copy back any new ring data */
730 if (set_tx) {
731 e1000e_free_tx_resources(adapter->tx_ring);
732 memcpy(adapter->tx_ring, temp_tx, size);
733 adapter->tx_ring_count = new_tx_count;
734 }
735 if (set_rx) {
736 e1000e_free_rx_resources(adapter->rx_ring);
737 memcpy(adapter->rx_ring, temp_rx, size);
738 adapter->rx_ring_count = new_rx_count;
739 }
740
Auke Kokbc7f75f2007-09-17 12:30:59 -0700741err_setup_rx:
Bruce Allan508da422011-12-16 00:45:51 +0000742 if (err && set_tx)
743 e1000e_free_tx_resources(temp_tx);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700744err_setup:
Bruce Allan508da422011-12-16 00:45:51 +0000745 e1000e_up(adapter);
746free_temp:
747 vfree(temp_tx);
748 vfree(temp_rx);
749clear_reset:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700750 clear_bit(__E1000_RESETTING, &adapter->state);
751 return err;
752}
753
Bruce Allancef8c792008-04-02 13:48:23 -0700754static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
755 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800756{
Bruce Allancef8c792008-04-02 13:48:23 -0700757 u32 pat, val;
Bruce Allan64806412010-12-11 05:53:42 +0000758 static const u32 test[] = {
759 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Bruce Allancef8c792008-04-02 13:48:23 -0700760 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800761 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700762 (test[pat] & write));
763 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
764 if (val != (test[pat] & write & mask)) {
Bruce Allana8fc1892012-12-05 06:25:36 +0000765 e_err("pattern test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
766 reg + (offset << 2), val,
767 (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800768 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700769 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800770 }
771 }
Bruce Allancef8c792008-04-02 13:48:23 -0700772 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700773}
774
Joe Perches2a887192007-11-13 20:53:51 -0800775static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
776 int reg, u32 mask, u32 write)
777{
Bruce Allancef8c792008-04-02 13:48:23 -0700778 u32 val;
Joe Perches2a887192007-11-13 20:53:51 -0800779 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700780 val = __er32(&adapter->hw, reg);
781 if ((write & mask) != (val & mask)) {
Bruce Allana8fc1892012-12-05 06:25:36 +0000782 e_err("set/check test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
Bruce Allan6ad65142012-04-12 05:47:09 +0000783 reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800784 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700785 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800786 }
Bruce Allancef8c792008-04-02 13:48:23 -0700787 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700788}
Bruce Allancef8c792008-04-02 13:48:23 -0700789#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
790 do { \
791 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
792 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800793 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700794#define REG_PATTERN_TEST(reg, mask, write) \
795 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800796
Bruce Allancef8c792008-04-02 13:48:23 -0700797#define REG_SET_AND_CHECK(reg, mask, write) \
798 do { \
799 if (reg_set_and_check(adapter, data, reg, mask, write)) \
800 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800801 } while (0)
802
Auke Kokbc7f75f2007-09-17 12:30:59 -0700803static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
804{
805 struct e1000_hw *hw = &adapter->hw;
806 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700807 u32 value;
808 u32 before;
809 u32 after;
810 u32 i;
811 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000812 u32 mask;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000813 u32 wlock_mac = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700814
Bruce Allane921eb12012-11-28 09:28:37 +0000815 /* The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700816 * Some bits that get toggled are ignored.
817 */
818 switch (mac->type) {
819 /* there are several bits on newer hardware that are r/w */
820 case e1000_82571:
821 case e1000_82572:
822 case e1000_80003es2lan:
823 toggle = 0x7FFFF3FF;
824 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000825 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700826 toggle = 0x7FFFF033;
827 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700828 }
829
830 before = er32(STATUS);
831 value = (er32(STATUS) & toggle);
832 ew32(STATUS, toggle);
833 after = er32(STATUS) & toggle;
834 if (value != after) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000835 e_err("failed STATUS register test got: 0x%08X expected: 0x%08X\n",
836 after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700837 *data = 1;
838 return 1;
839 }
840 /* restore previous status */
841 ew32(STATUS, before);
842
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700843 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700844 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
845 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
846 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
847 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
848 }
849
850 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000851 REG_PATTERN_TEST(E1000_RDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
852 REG_PATTERN_TEST(E1000_RDLEN(0), 0x000FFF80, 0x000FFFFF);
853 REG_PATTERN_TEST(E1000_RDH(0), 0x0000FFFF, 0x0000FFFF);
854 REG_PATTERN_TEST(E1000_RDT(0), 0x0000FFFF, 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700855 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
856 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
857 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000858 REG_PATTERN_TEST(E1000_TDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
859 REG_PATTERN_TEST(E1000_TDLEN(0), 0x000FFF80, 0x000FFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700860
861 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
862
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700863 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700864 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
865 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
866
Auke Kok86582512007-10-04 15:00:08 -0700867 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000868 REG_PATTERN_TEST(E1000_RDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700869 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700870 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000871 REG_PATTERN_TEST(E1000_TDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
Auke Kok86582512007-10-04 15:00:08 -0700872 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000873 mask = 0x8003FFFF;
874 switch (mac->type) {
875 case e1000_ich10lan:
876 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000877 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000878 case e1000_pch_lpt:
Bruce Allana4f58f52009-06-02 11:29:18 +0000879 mask |= (1 << 18);
880 break;
881 default:
882 break;
883 }
Bruce Allan2fbe4522012-04-19 03:21:47 +0000884
885 if (mac->type == e1000_pch_lpt)
886 wlock_mac = (er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK) >>
887 E1000_FWSM_WLOCK_MAC_SHIFT;
888
889 for (i = 0; i < mac->rar_entry_count; i++) {
Bruce Allana8fc1892012-12-05 06:25:36 +0000890 if (mac->type == e1000_pch_lpt) {
891 /* Cannot test write-protected SHRAL[n] registers */
892 if ((wlock_mac == 1) || (wlock_mac && (i > wlock_mac)))
893 continue;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000894
Bruce Allana8fc1892012-12-05 06:25:36 +0000895 /* SHRAH[9] different than the others */
896 if (i == 10)
897 mask |= (1 << 30);
898 else
899 mask &= ~(1 << 30);
900 }
901
902 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1), mask,
903 0xFFFFFFFF);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000904 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700905
906 for (i = 0; i < mac->mta_reg_count; i++)
907 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
908
909 *data = 0;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000910
Auke Kokbc7f75f2007-09-17 12:30:59 -0700911 return 0;
912}
913
914static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
915{
916 u16 temp;
917 u16 checksum = 0;
918 u16 i;
919
920 *data = 0;
921 /* Read and add up the contents of the EEPROM */
922 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
923 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
924 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800925 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700926 }
927 checksum += temp;
928 }
929
930 /* If Checksum is not Correct return error else test passed */
931 if ((checksum != (u16) NVM_SUM) && !(*data))
932 *data = 2;
933
934 return *data;
935}
936
937static irqreturn_t e1000_test_intr(int irq, void *data)
938{
939 struct net_device *netdev = (struct net_device *) data;
940 struct e1000_adapter *adapter = netdev_priv(netdev);
941 struct e1000_hw *hw = &adapter->hw;
942
943 adapter->test_icr |= er32(ICR);
944
945 return IRQ_HANDLED;
946}
947
948static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
949{
950 struct net_device *netdev = adapter->netdev;
951 struct e1000_hw *hw = &adapter->hw;
952 u32 mask;
953 u32 shared_int = 1;
954 u32 irq = adapter->pdev->irq;
955 int i;
Bruce Allan4662e822008-08-26 18:37:06 -0700956 int ret_val = 0;
957 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700958
959 *data = 0;
960
Bruce Allan4662e822008-08-26 18:37:06 -0700961 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
962 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
963 int_mode = adapter->int_mode;
964 e1000e_reset_interrupt_capability(adapter);
965 adapter->int_mode = E1000E_INT_MODE_LEGACY;
966 e1000e_set_interrupt_capability(adapter);
967 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700968 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800969 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700970 netdev)) {
971 shared_int = 0;
Joe Perchesa0607fd2009-11-18 23:29:17 -0800972 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700973 netdev->name, netdev)) {
974 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700975 ret_val = -1;
976 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700977 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700978 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700979
980 /* Disable all the interrupts */
981 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000982 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000983 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700984
985 /* Test each interrupt */
986 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700987 /* Interrupt to test */
988 mask = 1 << i;
989
Bruce Allanf4187b52008-08-26 18:36:50 -0700990 if (adapter->flags & FLAG_IS_ICH) {
991 switch (mask) {
992 case E1000_ICR_RXSEQ:
993 continue;
994 case 0x00000100:
995 if (adapter->hw.mac.type == e1000_ich8lan ||
996 adapter->hw.mac.type == e1000_ich9lan)
997 continue;
998 break;
999 default:
1000 break;
1001 }
1002 }
1003
Auke Kokbc7f75f2007-09-17 12:30:59 -07001004 if (!shared_int) {
Bruce Allane921eb12012-11-28 09:28:37 +00001005 /* Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001006 * the cause register and then force the same
1007 * interrupt and see if one gets posted. If
1008 * an interrupt was posted to the bus, the
1009 * test failed.
1010 */
1011 adapter->test_icr = 0;
1012 ew32(IMC, mask);
1013 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001014 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001015 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001016
1017 if (adapter->test_icr & mask) {
1018 *data = 3;
1019 break;
1020 }
1021 }
1022
Bruce Allane921eb12012-11-28 09:28:37 +00001023 /* Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001024 * the cause register and then force the same
1025 * interrupt and see if one gets posted. If
1026 * an interrupt was not posted to the bus, the
1027 * test failed.
1028 */
1029 adapter->test_icr = 0;
1030 ew32(IMS, mask);
1031 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001032 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001033 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001034
1035 if (!(adapter->test_icr & mask)) {
1036 *data = 4;
1037 break;
1038 }
1039
1040 if (!shared_int) {
Bruce Allane921eb12012-11-28 09:28:37 +00001041 /* Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001042 * the cause register and then force the other
1043 * interrupts and see if any get posted. If
1044 * an interrupt was posted to the bus, the
1045 * test failed.
1046 */
1047 adapter->test_icr = 0;
1048 ew32(IMC, ~mask & 0x00007FFF);
1049 ew32(ICS, ~mask & 0x00007FFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001050 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001051 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001052
1053 if (adapter->test_icr) {
1054 *data = 5;
1055 break;
1056 }
1057 }
1058 }
1059
1060 /* Disable all the interrupts */
1061 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001062 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001063 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001064
1065 /* Unhook test interrupt handler */
1066 free_irq(irq, netdev);
1067
Bruce Allan4662e822008-08-26 18:37:06 -07001068out:
1069 if (int_mode == E1000E_INT_MODE_MSIX) {
1070 e1000e_reset_interrupt_capability(adapter);
1071 adapter->int_mode = int_mode;
1072 e1000e_set_interrupt_capability(adapter);
1073 }
1074
1075 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001076}
1077
1078static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1079{
1080 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1081 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1082 struct pci_dev *pdev = adapter->pdev;
1083 int i;
1084
1085 if (tx_ring->desc && tx_ring->buffer_info) {
1086 for (i = 0; i < tx_ring->count; i++) {
1087 if (tx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001088 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001089 tx_ring->buffer_info[i].dma,
1090 tx_ring->buffer_info[i].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001091 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001092 if (tx_ring->buffer_info[i].skb)
1093 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1094 }
1095 }
1096
1097 if (rx_ring->desc && rx_ring->buffer_info) {
1098 for (i = 0; i < rx_ring->count; i++) {
1099 if (rx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001100 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001101 rx_ring->buffer_info[i].dma,
Nick Nunley0be3f552010-04-27 13:09:05 +00001102 2048, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001103 if (rx_ring->buffer_info[i].skb)
1104 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1105 }
1106 }
1107
1108 if (tx_ring->desc) {
1109 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1110 tx_ring->dma);
1111 tx_ring->desc = NULL;
1112 }
1113 if (rx_ring->desc) {
1114 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1115 rx_ring->dma);
1116 rx_ring->desc = NULL;
1117 }
1118
1119 kfree(tx_ring->buffer_info);
1120 tx_ring->buffer_info = NULL;
1121 kfree(rx_ring->buffer_info);
1122 rx_ring->buffer_info = NULL;
1123}
1124
1125static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1126{
1127 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1128 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1129 struct pci_dev *pdev = adapter->pdev;
1130 struct e1000_hw *hw = &adapter->hw;
1131 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001132 int i;
1133 int ret_val;
1134
1135 /* Setup Tx descriptor ring and Tx buffers */
1136
1137 if (!tx_ring->count)
1138 tx_ring->count = E1000_DEFAULT_TXD;
1139
Bruce Allancef8c792008-04-02 13:48:23 -07001140 tx_ring->buffer_info = kcalloc(tx_ring->count,
1141 sizeof(struct e1000_buffer),
1142 GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001143 if (!tx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001144 ret_val = 1;
1145 goto err_nomem;
1146 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001147
1148 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1149 tx_ring->size = ALIGN(tx_ring->size, 4096);
1150 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1151 &tx_ring->dma, GFP_KERNEL);
1152 if (!tx_ring->desc) {
1153 ret_val = 2;
1154 goto err_nomem;
1155 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001156 tx_ring->next_to_use = 0;
1157 tx_ring->next_to_clean = 0;
1158
Bruce Allan1e360522012-03-20 03:48:13 +00001159 ew32(TDBAL(0), ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
1160 ew32(TDBAH(0), ((u64) tx_ring->dma >> 32));
1161 ew32(TDLEN(0), tx_ring->count * sizeof(struct e1000_tx_desc));
1162 ew32(TDH(0), 0);
1163 ew32(TDT(0), 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001164 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1165 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1166 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001167
1168 for (i = 0; i < tx_ring->count; i++) {
1169 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1170 struct sk_buff *skb;
1171 unsigned int skb_size = 1024;
1172
1173 skb = alloc_skb(skb_size, GFP_KERNEL);
1174 if (!skb) {
1175 ret_val = 3;
1176 goto err_nomem;
1177 }
1178 skb_put(skb, skb_size);
1179 tx_ring->buffer_info[i].skb = skb;
1180 tx_ring->buffer_info[i].length = skb->len;
1181 tx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001182 dma_map_single(&pdev->dev, skb->data, skb->len,
1183 DMA_TO_DEVICE);
1184 if (dma_mapping_error(&pdev->dev,
1185 tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001186 ret_val = 4;
1187 goto err_nomem;
1188 }
Bruce Allancef8c792008-04-02 13:48:23 -07001189 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001190 tx_desc->lower.data = cpu_to_le32(skb->len);
1191 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1192 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001193 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001194 tx_desc->upper.data = 0;
1195 }
1196
1197 /* Setup Rx descriptor ring and Rx buffers */
1198
1199 if (!rx_ring->count)
1200 rx_ring->count = E1000_DEFAULT_RXD;
1201
Bruce Allancef8c792008-04-02 13:48:23 -07001202 rx_ring->buffer_info = kcalloc(rx_ring->count,
1203 sizeof(struct e1000_buffer),
1204 GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001205 if (!rx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001206 ret_val = 5;
1207 goto err_nomem;
1208 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001209
Bruce Allan5f450212011-07-22 06:21:46 +00001210 rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001211 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1212 &rx_ring->dma, GFP_KERNEL);
1213 if (!rx_ring->desc) {
1214 ret_val = 6;
1215 goto err_nomem;
1216 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001217 rx_ring->next_to_use = 0;
1218 rx_ring->next_to_clean = 0;
1219
1220 rctl = er32(RCTL);
Bruce Allan7f99ae62011-07-22 06:21:35 +00001221 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
1222 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan1e360522012-03-20 03:48:13 +00001223 ew32(RDBAL(0), ((u64) rx_ring->dma & 0xFFFFFFFF));
1224 ew32(RDBAH(0), ((u64) rx_ring->dma >> 32));
1225 ew32(RDLEN(0), rx_ring->size);
1226 ew32(RDH(0), 0);
1227 ew32(RDT(0), 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001228 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allancef8c792008-04-02 13:48:23 -07001229 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1230 E1000_RCTL_SBP | E1000_RCTL_SECRC |
Auke Kokbc7f75f2007-09-17 12:30:59 -07001231 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1232 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1233 ew32(RCTL, rctl);
1234
1235 for (i = 0; i < rx_ring->count; i++) {
Bruce Allan5f450212011-07-22 06:21:46 +00001236 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001237 struct sk_buff *skb;
1238
1239 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1240 if (!skb) {
1241 ret_val = 7;
1242 goto err_nomem;
1243 }
1244 skb_reserve(skb, NET_IP_ALIGN);
1245 rx_ring->buffer_info[i].skb = skb;
1246 rx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001247 dma_map_single(&pdev->dev, skb->data, 2048,
1248 DMA_FROM_DEVICE);
1249 if (dma_mapping_error(&pdev->dev,
1250 rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001251 ret_val = 8;
1252 goto err_nomem;
1253 }
Bruce Allan5f450212011-07-22 06:21:46 +00001254 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1255 rx_desc->read.buffer_addr =
1256 cpu_to_le64(rx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001257 memset(skb->data, 0x00, skb->len);
1258 }
1259
1260 return 0;
1261
1262err_nomem:
1263 e1000_free_desc_rings(adapter);
1264 return ret_val;
1265}
1266
1267static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1268{
1269 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1270 e1e_wphy(&adapter->hw, 29, 0x001F);
1271 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1272 e1e_wphy(&adapter->hw, 29, 0x001A);
1273 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1274}
1275
1276static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1277{
1278 struct e1000_hw *hw = &adapter->hw;
1279 u32 ctrl_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001280 u16 phy_reg = 0;
Bruce Allancbd006c2010-11-24 06:01:30 +00001281 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001282
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001283 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001284
Bruce Allan3af50482010-06-16 13:25:55 +00001285 if (hw->phy.type == e1000_phy_ife) {
1286 /* force 100, set loopback */
1287 e1e_wphy(hw, PHY_CONTROL, 0x6100);
Bruce Allanbb436b22009-11-20 23:24:11 +00001288
Bruce Allan3af50482010-06-16 13:25:55 +00001289 /* Now set up the MAC to the same speed/duplex as the PHY. */
1290 ctrl_reg = er32(CTRL);
1291 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1292 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1293 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1294 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1295 E1000_CTRL_FD); /* Force Duplex to FULL */
1296
1297 ew32(CTRL, ctrl_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001298 e1e_flush();
Bruce Allan3af50482010-06-16 13:25:55 +00001299 udelay(500);
1300
1301 return 0;
1302 }
1303
1304 /* Specific PHY configuration for loopback */
1305 switch (hw->phy.type) {
1306 case e1000_phy_m88:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001307 /* Auto-MDI/MDIX Off */
1308 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1309 /* reset to update Auto-MDI/MDIX */
1310 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1311 /* autoneg off */
1312 e1e_wphy(hw, PHY_CONTROL, 0x8140);
Bruce Allan3af50482010-06-16 13:25:55 +00001313 break;
1314 case e1000_phy_gg82563:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001315 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
Bruce Allancef8c792008-04-02 13:48:23 -07001316 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001317 case e1000_phy_bm:
1318 /* Set Default MAC Interface speed to 1GB */
1319 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1320 phy_reg &= ~0x0007;
1321 phy_reg |= 0x006;
1322 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1323 /* Assert SW reset for above settings to take effect */
Bruce Allan6b598e12013-01-23 06:50:05 +00001324 hw->phy.ops.commit(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001325 mdelay(1);
1326 /* Force Full Duplex */
1327 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1328 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1329 /* Set Link Up (in force link) */
1330 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1331 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1332 /* Force Link */
1333 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1334 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1335 /* Set Early Link Enable */
1336 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1337 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
Bruce Allan3af50482010-06-16 13:25:55 +00001338 break;
1339 case e1000_phy_82577:
1340 case e1000_phy_82578:
1341 /* Workaround: K1 must be disabled for stable 1Gbps operation */
Bruce Allancbd006c2010-11-24 06:01:30 +00001342 ret_val = hw->phy.ops.acquire(hw);
1343 if (ret_val) {
1344 e_err("Cannot setup 1Gbps loopback.\n");
1345 return ret_val;
1346 }
Bruce Allan3af50482010-06-16 13:25:55 +00001347 e1000_configure_k1_ich8lan(hw, false);
Bruce Allancbd006c2010-11-24 06:01:30 +00001348 hw->phy.ops.release(hw);
Bruce Allan3af50482010-06-16 13:25:55 +00001349 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001350 case e1000_phy_82579:
1351 /* Disable PHY energy detect power down */
1352 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1353 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
1354 /* Disable full chip energy detect */
1355 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1356 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1357 /* Enable loopback on the PHY */
1358#define I82577_PHY_LBK_CTRL 19
1359 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1360 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001361 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001362 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001363 }
1364
Bruce Allan3af50482010-06-16 13:25:55 +00001365 /* force 1000, set loopback */
1366 e1e_wphy(hw, PHY_CONTROL, 0x4140);
1367 mdelay(250);
1368
1369 /* Now set up the MAC to the same speed/duplex as the PHY. */
1370 ctrl_reg = er32(CTRL);
1371 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1372 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1373 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1374 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1375 E1000_CTRL_FD); /* Force Duplex to FULL */
1376
1377 if (adapter->flags & FLAG_IS_ICH)
1378 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1379
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001380 if (hw->phy.media_type == e1000_media_type_copper &&
1381 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001382 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1383 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001384 /* Set the ILOS bit on the fiber Nic if half duplex link is
Bruce Allanad680762008-03-28 09:15:03 -07001385 * detected.
1386 */
Bruce Allan90da0662011-01-06 07:02:53 +00001387 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001388 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1389 }
1390
1391 ew32(CTRL, ctrl_reg);
1392
Bruce Allane921eb12012-11-28 09:28:37 +00001393 /* Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001394 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1395 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001396 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001397 e1000_phy_disable_receiver(adapter);
1398
1399 udelay(500);
1400
1401 return 0;
1402}
1403
1404static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1405{
1406 struct e1000_hw *hw = &adapter->hw;
1407 u32 ctrl = er32(CTRL);
Bruce Allan70806a72013-01-05 05:08:37 +00001408 int link;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001409
1410 /* special requirements for 82571/82572 fiber adapters */
1411
Bruce Allane921eb12012-11-28 09:28:37 +00001412 /* jump through hoops to make sure link is up because serdes
Bruce Allanad680762008-03-28 09:15:03 -07001413 * link is hardwired up
1414 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001415 ctrl |= E1000_CTRL_SLU;
1416 ew32(CTRL, ctrl);
1417
1418 /* disable autoneg */
1419 ctrl = er32(TXCW);
1420 ctrl &= ~(1 << 31);
1421 ew32(TXCW, ctrl);
1422
1423 link = (er32(STATUS) & E1000_STATUS_LU);
1424
1425 if (!link) {
1426 /* set invert loss of signal */
1427 ctrl = er32(CTRL);
1428 ctrl |= E1000_CTRL_ILOS;
1429 ew32(CTRL, ctrl);
1430 }
1431
Bruce Allane921eb12012-11-28 09:28:37 +00001432 /* special write to serdes control register to enable SerDes analog
Bruce Allanad680762008-03-28 09:15:03 -07001433 * loopback
1434 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001435#define E1000_SERDES_LB_ON 0x410
1436 ew32(SCTL, E1000_SERDES_LB_ON);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001437 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001438 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001439
1440 return 0;
1441}
1442
1443/* only call this for fiber/serdes connections to es2lan */
1444static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1445{
1446 struct e1000_hw *hw = &adapter->hw;
1447 u32 ctrlext = er32(CTRL_EXT);
1448 u32 ctrl = er32(CTRL);
1449
Bruce Allane921eb12012-11-28 09:28:37 +00001450 /* save CTRL_EXT to restore later, reuse an empty variable (unused
Bruce Allanad680762008-03-28 09:15:03 -07001451 * on mac_type 80003es2lan)
1452 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001453 adapter->tx_fifo_head = ctrlext;
1454
1455 /* clear the serdes mode bits, putting the device into mac loopback */
1456 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1457 ew32(CTRL_EXT, ctrlext);
1458
1459 /* force speed to 1000/FD, link up */
1460 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1461 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1462 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1463 ew32(CTRL, ctrl);
1464
1465 /* set mac loopback */
1466 ctrl = er32(RCTL);
1467 ctrl |= E1000_RCTL_LBM_MAC;
1468 ew32(RCTL, ctrl);
1469
1470 /* set testing mode parameters (no need to reset later) */
1471#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1472#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1473 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001474 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001475
1476 return 0;
1477}
1478
1479static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1480{
1481 struct e1000_hw *hw = &adapter->hw;
1482 u32 rctl;
1483
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001484 if (hw->phy.media_type == e1000_media_type_fiber ||
1485 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001486 switch (hw->mac.type) {
1487 case e1000_80003es2lan:
1488 return e1000_set_es2lan_mac_loopback(adapter);
1489 break;
1490 case e1000_82571:
1491 case e1000_82572:
1492 return e1000_set_82571_fiber_loopback(adapter);
1493 break;
1494 default:
1495 rctl = er32(RCTL);
1496 rctl |= E1000_RCTL_LBM_TCVR;
1497 ew32(RCTL, rctl);
1498 return 0;
1499 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001500 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001501 return e1000_integrated_phy_loopback(adapter);
1502 }
1503
1504 return 7;
1505}
1506
1507static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1508{
1509 struct e1000_hw *hw = &adapter->hw;
1510 u32 rctl;
1511 u16 phy_reg;
1512
1513 rctl = er32(RCTL);
1514 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1515 ew32(RCTL, rctl);
1516
1517 switch (hw->mac.type) {
1518 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001519 if (hw->phy.media_type == e1000_media_type_fiber ||
1520 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001521 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001522 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001523 adapter->tx_fifo_head = 0;
1524 }
1525 /* fall through */
1526 case e1000_82571:
1527 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001528 if (hw->phy.media_type == e1000_media_type_fiber ||
1529 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001530#define E1000_SERDES_LB_OFF 0x400
1531 ew32(SCTL, E1000_SERDES_LB_OFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001532 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001533 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001534 break;
1535 }
1536 /* Fall Through */
1537 default:
1538 hw->mac.autoneg = 1;
1539 if (hw->phy.type == e1000_phy_gg82563)
1540 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1541 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1542 if (phy_reg & MII_CR_LOOPBACK) {
1543 phy_reg &= ~MII_CR_LOOPBACK;
1544 e1e_wphy(hw, PHY_CONTROL, phy_reg);
Bruce Allan6b598e12013-01-23 06:50:05 +00001545 if (hw->phy.ops.commit)
1546 hw->phy.ops.commit(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001547 }
1548 break;
1549 }
1550}
1551
1552static void e1000_create_lbtest_frame(struct sk_buff *skb,
1553 unsigned int frame_size)
1554{
1555 memset(skb->data, 0xFF, frame_size);
1556 frame_size &= ~1;
1557 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1558 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1559 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1560}
1561
1562static int e1000_check_lbtest_frame(struct sk_buff *skb,
1563 unsigned int frame_size)
1564{
1565 frame_size &= ~1;
1566 if (*(skb->data + 3) == 0xFF)
1567 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1568 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1569 return 0;
1570 return 13;
1571}
1572
1573static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1574{
1575 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1576 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1577 struct pci_dev *pdev = adapter->pdev;
1578 struct e1000_hw *hw = &adapter->hw;
1579 int i, j, k, l;
1580 int lc;
1581 int good_cnt;
1582 int ret_val = 0;
1583 unsigned long time;
1584
Bruce Allan1e360522012-03-20 03:48:13 +00001585 ew32(RDT(0), rx_ring->count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001586
Bruce Allane921eb12012-11-28 09:28:37 +00001587 /* Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001588 * The idea is to wrap the largest ring a number of times using 64
1589 * send/receive pairs during each loop
1590 */
1591
1592 if (rx_ring->count <= tx_ring->count)
1593 lc = ((tx_ring->count / 64) * 2) + 1;
1594 else
1595 lc = ((rx_ring->count / 64) * 2) + 1;
1596
1597 k = 0;
1598 l = 0;
1599 for (j = 0; j <= lc; j++) { /* loop count loop */
1600 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001601 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1602 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001603 dma_sync_single_for_device(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001604 tx_ring->buffer_info[k].dma,
1605 tx_ring->buffer_info[k].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001606 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001607 k++;
1608 if (k == tx_ring->count)
1609 k = 0;
1610 }
Bruce Allan1e360522012-03-20 03:48:13 +00001611 ew32(TDT(0), k);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001612 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001613 msleep(200);
1614 time = jiffies; /* set the start time for the receive */
1615 good_cnt = 0;
1616 do { /* receive the sent packets */
Nick Nunley0be3f552010-04-27 13:09:05 +00001617 dma_sync_single_for_cpu(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001618 rx_ring->buffer_info[l].dma, 2048,
Nick Nunley0be3f552010-04-27 13:09:05 +00001619 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001620
1621 ret_val = e1000_check_lbtest_frame(
1622 rx_ring->buffer_info[l].skb, 1024);
1623 if (!ret_val)
1624 good_cnt++;
1625 l++;
1626 if (l == rx_ring->count)
1627 l = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00001628 /* time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001629 * enough time to complete the receives, if it's
1630 * exceeded, break and error off
1631 */
1632 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1633 if (good_cnt != 64) {
1634 ret_val = 13; /* ret_val is the same as mis-compare */
1635 break;
1636 }
Bruce Allancef8c792008-04-02 13:48:23 -07001637 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001638 ret_val = 14; /* error code for time out error */
1639 break;
1640 }
1641 } /* end loop count loop */
1642 return ret_val;
1643}
1644
1645static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1646{
Bruce Allan44abd5c2012-02-22 09:02:37 +00001647 struct e1000_hw *hw = &adapter->hw;
1648
Bruce Allane921eb12012-11-28 09:28:37 +00001649 /* PHY loopback cannot be performed if SoL/IDER sessions are active */
Bruce Allan470a5422012-05-26 06:08:48 +00001650 if (hw->phy.ops.check_reset_block &&
1651 hw->phy.ops.check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001652 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001653 *data = 0;
1654 goto out;
1655 }
1656
1657 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001658 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001659 goto out;
1660
1661 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001662 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001663 goto err_loopback;
1664
1665 *data = e1000_run_loopback_test(adapter);
1666 e1000_loopback_cleanup(adapter);
1667
1668err_loopback:
1669 e1000_free_desc_rings(adapter);
1670out:
1671 return *data;
1672}
1673
1674static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1675{
1676 struct e1000_hw *hw = &adapter->hw;
1677
1678 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001679 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001680 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001681 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001682
Bruce Allane921eb12012-11-28 09:28:37 +00001683 /* On some blade server designs, link establishment
Bruce Allanad680762008-03-28 09:15:03 -07001684 * could take as long as 2-3 minutes
1685 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001686 do {
1687 hw->mac.ops.check_for_link(hw);
1688 if (hw->mac.serdes_has_link)
1689 return *data;
1690 msleep(20);
1691 } while (i++ < 3750);
1692
1693 *data = 1;
1694 } else {
1695 hw->mac.ops.check_for_link(hw);
1696 if (hw->mac.autoneg)
Bruce Allane921eb12012-11-28 09:28:37 +00001697 /* On some Phy/switch combinations, link establishment
Bruce Allan5661aeb2011-02-25 06:36:25 +00001698 * can take a few seconds more than expected.
1699 */
1700 msleep(5000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001701
Bruce Allan5661aeb2011-02-25 06:36:25 +00001702 if (!(er32(STATUS) & E1000_STATUS_LU))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001703 *data = 1;
1704 }
1705 return *data;
1706}
1707
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001708static int e1000e_get_sset_count(struct net_device *netdev, int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001709{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001710 switch (sset) {
1711 case ETH_SS_TEST:
1712 return E1000_TEST_LEN;
1713 case ETH_SS_STATS:
1714 return E1000_STATS_LEN;
1715 default:
1716 return -EOPNOTSUPP;
1717 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001718}
1719
1720static void e1000_diag_test(struct net_device *netdev,
1721 struct ethtool_test *eth_test, u64 *data)
1722{
1723 struct e1000_adapter *adapter = netdev_priv(netdev);
1724 u16 autoneg_advertised;
1725 u8 forced_speed_duplex;
1726 u8 autoneg;
1727 bool if_running = netif_running(netdev);
1728
1729 set_bit(__E1000_TESTING, &adapter->state);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001730
1731 if (!if_running) {
1732 /* Get control of and reset hardware */
1733 if (adapter->flags & FLAG_HAS_AMT)
1734 e1000e_get_hw_control(adapter);
1735
1736 e1000e_power_up_phy(adapter);
1737
1738 adapter->hw.phy.autoneg_wait_to_complete = 1;
1739 e1000e_reset(adapter);
1740 adapter->hw.phy.autoneg_wait_to_complete = 0;
1741 }
1742
Auke Kokbc7f75f2007-09-17 12:30:59 -07001743 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1744 /* Offline tests */
1745
1746 /* save speed, duplex, autoneg settings */
1747 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1748 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1749 autoneg = adapter->hw.mac.autoneg;
1750
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001751 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001752
Auke Kokbc7f75f2007-09-17 12:30:59 -07001753 if (if_running)
1754 /* indicate we're in test mode */
1755 dev_close(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001756
1757 if (e1000_reg_test(adapter, &data[0]))
1758 eth_test->flags |= ETH_TEST_FL_FAILED;
1759
1760 e1000e_reset(adapter);
1761 if (e1000_eeprom_test(adapter, &data[1]))
1762 eth_test->flags |= ETH_TEST_FL_FAILED;
1763
1764 e1000e_reset(adapter);
1765 if (e1000_intr_test(adapter, &data[2]))
1766 eth_test->flags |= ETH_TEST_FL_FAILED;
1767
1768 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001769 if (e1000_loopback_test(adapter, &data[3]))
1770 eth_test->flags |= ETH_TEST_FL_FAILED;
1771
Auke Kokbc7f75f2007-09-17 12:30:59 -07001772 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001773 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001774 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001775 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001776
Carolyn Wybornyc6ce3852010-10-15 17:35:31 +00001777 if (e1000_link_test(adapter, &data[4]))
1778 eth_test->flags |= ETH_TEST_FL_FAILED;
1779
1780 /* restore speed, duplex, autoneg settings */
1781 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1782 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1783 adapter->hw.mac.autoneg = autoneg;
1784 e1000e_reset(adapter);
1785
Auke Kokbc7f75f2007-09-17 12:30:59 -07001786 clear_bit(__E1000_TESTING, &adapter->state);
1787 if (if_running)
1788 dev_open(netdev);
1789 } else {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001790 /* Online tests */
Bruce Allan11b08be2010-05-10 14:59:31 +00001791
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001792 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001793
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001794 /* register, eeprom, intr and loopback tests not run online */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001795 data[0] = 0;
1796 data[1] = 0;
1797 data[2] = 0;
1798 data[3] = 0;
1799
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001800 if (e1000_link_test(adapter, &data[4]))
1801 eth_test->flags |= ETH_TEST_FL_FAILED;
Bruce Allan11b08be2010-05-10 14:59:31 +00001802
Auke Kokbc7f75f2007-09-17 12:30:59 -07001803 clear_bit(__E1000_TESTING, &adapter->state);
1804 }
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001805
1806 if (!if_running) {
1807 e1000e_reset(adapter);
1808
1809 if (adapter->flags & FLAG_HAS_AMT)
1810 e1000e_release_hw_control(adapter);
1811 }
1812
Auke Kokbc7f75f2007-09-17 12:30:59 -07001813 msleep_interruptible(4 * 1000);
1814}
1815
1816static void e1000_get_wol(struct net_device *netdev,
1817 struct ethtool_wolinfo *wol)
1818{
1819 struct e1000_adapter *adapter = netdev_priv(netdev);
1820
1821 wol->supported = 0;
1822 wol->wolopts = 0;
1823
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001824 if (!(adapter->flags & FLAG_HAS_WOL) ||
1825 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001826 return;
1827
1828 wol->supported = WAKE_UCAST | WAKE_MCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001829 WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001830
1831 /* apply any specific unsupported masks here */
1832 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1833 wol->supported &= ~WAKE_UCAST;
1834
1835 if (adapter->wol & E1000_WUFC_EX)
Bruce Allan6ad65142012-04-12 05:47:09 +00001836 e_err("Interface does not support directed (unicast) frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001837 }
1838
1839 if (adapter->wol & E1000_WUFC_EX)
1840 wol->wolopts |= WAKE_UCAST;
1841 if (adapter->wol & E1000_WUFC_MC)
1842 wol->wolopts |= WAKE_MCAST;
1843 if (adapter->wol & E1000_WUFC_BC)
1844 wol->wolopts |= WAKE_BCAST;
1845 if (adapter->wol & E1000_WUFC_MAG)
1846 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001847 if (adapter->wol & E1000_WUFC_LNKC)
1848 wol->wolopts |= WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001849}
1850
Bruce Allan4a29e152011-03-04 09:07:01 +00001851static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001852{
1853 struct e1000_adapter *adapter = netdev_priv(netdev);
1854
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001855 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001856 !device_can_wakeup(&adapter->pdev->dev) ||
1857 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001858 WAKE_MAGIC | WAKE_PHY)))
Bruce Allan1fbfca32009-11-20 23:22:01 +00001859 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001860
1861 /* these settings will always override what we currently have */
1862 adapter->wol = 0;
1863
1864 if (wol->wolopts & WAKE_UCAST)
1865 adapter->wol |= E1000_WUFC_EX;
1866 if (wol->wolopts & WAKE_MCAST)
1867 adapter->wol |= E1000_WUFC_MC;
1868 if (wol->wolopts & WAKE_BCAST)
1869 adapter->wol |= E1000_WUFC_BC;
1870 if (wol->wolopts & WAKE_MAGIC)
1871 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001872 if (wol->wolopts & WAKE_PHY)
1873 adapter->wol |= E1000_WUFC_LNKC;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001874
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001875 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1876
Auke Kokbc7f75f2007-09-17 12:30:59 -07001877 return 0;
1878}
1879
Bruce Allandbf80dc2011-04-16 00:34:40 +00001880static int e1000_set_phys_id(struct net_device *netdev,
1881 enum ethtool_phys_id_state state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001882{
1883 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001884 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001885
Bruce Allandbf80dc2011-04-16 00:34:40 +00001886 switch (state) {
1887 case ETHTOOL_ID_ACTIVE:
1888 if (!hw->mac.ops.blink_led)
1889 return 2; /* cycle on/off twice per second */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001890
Bruce Allandbf80dc2011-04-16 00:34:40 +00001891 hw->mac.ops.blink_led(hw);
1892 break;
1893
1894 case ETHTOOL_ID_INACTIVE:
Bruce Allan4662e822008-08-26 18:37:06 -07001895 if (hw->phy.type == e1000_phy_ife)
1896 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001897 hw->mac.ops.led_off(hw);
1898 hw->mac.ops.cleanup_led(hw);
1899 break;
1900
1901 case ETHTOOL_ID_ON:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001902 hw->mac.ops.led_on(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001903 break;
1904
1905 case ETHTOOL_ID_OFF:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001906 hw->mac.ops.led_off(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001907 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001908 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001909 return 0;
1910}
1911
Auke Kokde5b3072008-04-23 11:09:08 -07001912static int e1000_get_coalesce(struct net_device *netdev,
1913 struct ethtool_coalesce *ec)
1914{
1915 struct e1000_adapter *adapter = netdev_priv(netdev);
1916
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001917 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07001918 ec->rx_coalesce_usecs = adapter->itr_setting;
1919 else
1920 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1921
1922 return 0;
1923}
1924
1925static int e1000_set_coalesce(struct net_device *netdev,
1926 struct ethtool_coalesce *ec)
1927{
1928 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokde5b3072008-04-23 11:09:08 -07001929
1930 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001931 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07001932 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1933 (ec->rx_coalesce_usecs == 2))
1934 return -EINVAL;
1935
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001936 if (ec->rx_coalesce_usecs == 4) {
Bruce Allan06a402e2012-08-17 06:17:57 +00001937 adapter->itr_setting = 4;
1938 adapter->itr = adapter->itr_setting;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001939 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07001940 adapter->itr = 20000;
1941 adapter->itr_setting = ec->rx_coalesce_usecs;
1942 } else {
1943 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1944 adapter->itr_setting = adapter->itr & ~3;
1945 }
1946
1947 if (adapter->itr_setting != 0)
Matthew Vick22a4cca2012-07-12 00:02:42 +00001948 e1000e_write_itr(adapter, adapter->itr);
Auke Kokde5b3072008-04-23 11:09:08 -07001949 else
Matthew Vick22a4cca2012-07-12 00:02:42 +00001950 e1000e_write_itr(adapter, 0);
Auke Kokde5b3072008-04-23 11:09:08 -07001951
1952 return 0;
1953}
1954
Auke Kokbc7f75f2007-09-17 12:30:59 -07001955static int e1000_nway_reset(struct net_device *netdev)
1956{
1957 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan5962bc22011-01-20 06:58:07 +00001958
1959 if (!netif_running(netdev))
1960 return -EAGAIN;
1961
1962 if (!adapter->hw.mac.autoneg)
1963 return -EINVAL;
1964
1965 e1000e_reinit_locked(adapter);
1966
Auke Kokbc7f75f2007-09-17 12:30:59 -07001967 return 0;
1968}
1969
Auke Kokbc7f75f2007-09-17 12:30:59 -07001970static void e1000_get_ethtool_stats(struct net_device *netdev,
1971 struct ethtool_stats *stats,
1972 u64 *data)
1973{
1974 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001975 struct rtnl_link_stats64 net_stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001976 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001977 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001978
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001979 e1000e_get_stats64(netdev, &net_stats);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001980 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001981 switch (e1000_gstrings_stats[i].type) {
1982 case NETDEV_STATS:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001983 p = (char *) &net_stats +
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001984 e1000_gstrings_stats[i].stat_offset;
1985 break;
1986 case E1000_STATS:
1987 p = (char *) adapter +
1988 e1000_gstrings_stats[i].stat_offset;
1989 break;
Bruce Allan61c75812010-12-09 23:04:25 +00001990 default:
1991 data[i] = 0;
1992 continue;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001993 }
1994
Auke Kokbc7f75f2007-09-17 12:30:59 -07001995 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1996 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1997 }
1998}
1999
2000static void e1000_get_strings(struct net_device *netdev, u32 stringset,
2001 u8 *data)
2002{
2003 u8 *p = data;
2004 int i;
2005
2006 switch (stringset) {
2007 case ETH_SS_TEST:
Bruce Allan5c1bda02011-01-19 04:23:39 +00002008 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002009 break;
2010 case ETH_SS_STATS:
2011 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
2012 memcpy(p, e1000_gstrings_stats[i].stat_string,
2013 ETH_GSTRING_LEN);
2014 p += ETH_GSTRING_LEN;
2015 }
2016 break;
2017 }
2018}
2019
Bruce Allan70495a52012-01-11 01:26:50 +00002020static int e1000_get_rxnfc(struct net_device *netdev,
2021 struct ethtool_rxnfc *info, u32 *rule_locs)
2022{
2023 info->data = 0;
2024
2025 switch (info->cmd) {
2026 case ETHTOOL_GRXFH: {
2027 struct e1000_adapter *adapter = netdev_priv(netdev);
2028 struct e1000_hw *hw = &adapter->hw;
2029 u32 mrqc = er32(MRQC);
2030
2031 if (!(mrqc & E1000_MRQC_RSS_FIELD_MASK))
2032 return 0;
2033
2034 switch (info->flow_type) {
2035 case TCP_V4_FLOW:
2036 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP)
2037 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2038 /* fall through */
2039 case UDP_V4_FLOW:
2040 case SCTP_V4_FLOW:
2041 case AH_ESP_V4_FLOW:
2042 case IPV4_FLOW:
2043 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4)
2044 info->data |= RXH_IP_SRC | RXH_IP_DST;
2045 break;
2046 case TCP_V6_FLOW:
2047 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP)
2048 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2049 /* fall through */
2050 case UDP_V6_FLOW:
2051 case SCTP_V6_FLOW:
2052 case AH_ESP_V6_FLOW:
2053 case IPV6_FLOW:
2054 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6)
2055 info->data |= RXH_IP_SRC | RXH_IP_DST;
2056 break;
2057 default:
2058 break;
2059 }
2060 return 0;
2061 }
2062 default:
2063 return -EOPNOTSUPP;
2064 }
2065}
2066
Bruce Allan203e4152012-12-05 08:40:59 +00002067static int e1000e_get_eee(struct net_device *netdev, struct ethtool_eee *edata)
2068{
2069 struct e1000_adapter *adapter = netdev_priv(netdev);
2070 struct e1000_hw *hw = &adapter->hw;
2071 u16 cap_addr, adv_addr, lpa_addr, pcs_stat_addr, phy_data, lpi_ctrl;
2072 u32 status, ret_val;
2073
2074 if (!(adapter->flags & FLAG_IS_ICH) ||
2075 !(adapter->flags2 & FLAG2_HAS_EEE))
2076 return -EOPNOTSUPP;
2077
2078 switch (hw->phy.type) {
2079 case e1000_phy_82579:
2080 cap_addr = I82579_EEE_CAPABILITY;
2081 adv_addr = I82579_EEE_ADVERTISEMENT;
2082 lpa_addr = I82579_EEE_LP_ABILITY;
2083 pcs_stat_addr = I82579_EEE_PCS_STATUS;
2084 break;
2085 case e1000_phy_i217:
2086 cap_addr = I217_EEE_CAPABILITY;
2087 adv_addr = I217_EEE_ADVERTISEMENT;
2088 lpa_addr = I217_EEE_LP_ABILITY;
2089 pcs_stat_addr = I217_EEE_PCS_STATUS;
2090 break;
2091 default:
2092 return -EOPNOTSUPP;
2093 }
2094
2095 ret_val = hw->phy.ops.acquire(hw);
2096 if (ret_val)
2097 return -EBUSY;
2098
2099 /* EEE Capability */
2100 ret_val = e1000_read_emi_reg_locked(hw, cap_addr, &phy_data);
2101 if (ret_val)
2102 goto release;
2103 edata->supported = mmd_eee_cap_to_ethtool_sup_t(phy_data);
2104
2105 /* EEE Advertised */
2106 ret_val = e1000_read_emi_reg_locked(hw, adv_addr, &phy_data);
2107 if (ret_val)
2108 goto release;
2109 edata->advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
2110
2111 /* EEE Link Partner Advertised */
2112 ret_val = e1000_read_emi_reg_locked(hw, lpa_addr, &phy_data);
2113 if (ret_val)
2114 goto release;
2115 edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
2116
2117 /* EEE PCS Status */
2118 ret_val = e1000_read_emi_reg_locked(hw, pcs_stat_addr, &phy_data);
2119 if (hw->phy.type == e1000_phy_82579)
2120 phy_data <<= 8;
2121
2122release:
2123 hw->phy.ops.release(hw);
2124 if (ret_val)
2125 return -ENODATA;
2126
2127 e1e_rphy(hw, I82579_LPI_CTRL, &lpi_ctrl);
2128 status = er32(STATUS);
2129
2130 /* Result of the EEE auto negotiation - there is no register that
2131 * has the status of the EEE negotiation so do a best-guess based
2132 * on whether both Tx and Rx LPI indications have been received or
2133 * base it on the link speed, the EEE advertised speeds on both ends
2134 * and the speeds on which EEE is enabled locally.
2135 */
2136 if (((phy_data & E1000_EEE_TX_LPI_RCVD) &&
2137 (phy_data & E1000_EEE_RX_LPI_RCVD)) ||
2138 ((status & E1000_STATUS_SPEED_100) &&
2139 (edata->advertised & ADVERTISED_100baseT_Full) &&
2140 (edata->lp_advertised & ADVERTISED_100baseT_Full) &&
2141 (lpi_ctrl & I82579_LPI_CTRL_100_ENABLE)) ||
2142 ((status & E1000_STATUS_SPEED_1000) &&
2143 (edata->advertised & ADVERTISED_1000baseT_Full) &&
2144 (edata->lp_advertised & ADVERTISED_1000baseT_Full) &&
2145 (lpi_ctrl & I82579_LPI_CTRL_1000_ENABLE)))
2146 edata->eee_active = true;
2147
2148 edata->eee_enabled = !hw->dev_spec.ich8lan.eee_disable;
2149 edata->tx_lpi_enabled = true;
2150 edata->tx_lpi_timer = er32(LPIC) >> E1000_LPIC_LPIET_SHIFT;
2151
2152 return 0;
2153}
2154
2155static int e1000e_set_eee(struct net_device *netdev, struct ethtool_eee *edata)
2156{
2157 struct e1000_adapter *adapter = netdev_priv(netdev);
2158 struct e1000_hw *hw = &adapter->hw;
2159 struct ethtool_eee eee_curr;
2160 s32 ret_val;
2161
2162 if (!(adapter->flags & FLAG_IS_ICH) ||
2163 !(adapter->flags2 & FLAG2_HAS_EEE))
2164 return -EOPNOTSUPP;
2165
2166 ret_val = e1000e_get_eee(netdev, &eee_curr);
2167 if (ret_val)
2168 return ret_val;
2169
2170 if (eee_curr.advertised != edata->advertised) {
2171 e_err("Setting EEE advertisement is not supported\n");
2172 return -EINVAL;
2173 }
2174
2175 if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
2176 e_err("Setting EEE tx-lpi is not supported\n");
2177 return -EINVAL;
2178 }
2179
2180 if (eee_curr.tx_lpi_timer != edata->tx_lpi_timer) {
2181 e_err("Setting EEE Tx LPI timer is not supported\n");
2182 return -EINVAL;
2183 }
2184
2185 if (hw->dev_spec.ich8lan.eee_disable != !edata->eee_enabled) {
2186 hw->dev_spec.ich8lan.eee_disable = !edata->eee_enabled;
2187
2188 /* reset the link */
2189 if (netif_running(netdev))
2190 e1000e_reinit_locked(adapter);
2191 else
2192 e1000e_reset(adapter);
2193 }
2194
2195 return 0;
2196}
2197
Bruce Allanb67e1912012-12-27 08:32:33 +00002198static int e1000e_get_ts_info(struct net_device *netdev,
2199 struct ethtool_ts_info *info)
2200{
2201 struct e1000_adapter *adapter = netdev_priv(netdev);
2202
2203 ethtool_op_get_ts_info(netdev, info);
2204
2205 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
2206 return 0;
2207
2208 info->so_timestamping |= (SOF_TIMESTAMPING_TX_HARDWARE |
2209 SOF_TIMESTAMPING_RX_HARDWARE |
2210 SOF_TIMESTAMPING_RAW_HARDWARE);
2211
2212 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
2213
2214 info->rx_filters = ((1 << HWTSTAMP_FILTER_NONE) |
Bruce Alland89777b2013-01-19 01:09:58 +00002215 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
2216 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
2217 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
2218 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
2219 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
2220 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
2221 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
2222 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
2223 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
Bruce Allanb67e1912012-12-27 08:32:33 +00002224 (1 << HWTSTAMP_FILTER_ALL));
2225
Bruce Alland89777b2013-01-19 01:09:58 +00002226 if (adapter->ptp_clock)
2227 info->phc_index = ptp_clock_index(adapter->ptp_clock);
2228
Bruce Allanb67e1912012-12-27 08:32:33 +00002229 return 0;
2230}
2231
Auke Kokbc7f75f2007-09-17 12:30:59 -07002232static const struct ethtool_ops e1000_ethtool_ops = {
2233 .get_settings = e1000_get_settings,
2234 .set_settings = e1000_set_settings,
2235 .get_drvinfo = e1000_get_drvinfo,
2236 .get_regs_len = e1000_get_regs_len,
2237 .get_regs = e1000_get_regs,
2238 .get_wol = e1000_get_wol,
2239 .set_wol = e1000_set_wol,
2240 .get_msglevel = e1000_get_msglevel,
2241 .set_msglevel = e1000_set_msglevel,
2242 .nway_reset = e1000_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00002243 .get_link = ethtool_op_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002244 .get_eeprom_len = e1000_get_eeprom_len,
2245 .get_eeprom = e1000_get_eeprom,
2246 .set_eeprom = e1000_set_eeprom,
2247 .get_ringparam = e1000_get_ringparam,
2248 .set_ringparam = e1000_set_ringparam,
2249 .get_pauseparam = e1000_get_pauseparam,
2250 .set_pauseparam = e1000_set_pauseparam,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002251 .self_test = e1000_diag_test,
2252 .get_strings = e1000_get_strings,
Bruce Allandbf80dc2011-04-16 00:34:40 +00002253 .set_phys_id = e1000_set_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002254 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07002255 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07002256 .get_coalesce = e1000_get_coalesce,
2257 .set_coalesce = e1000_set_coalesce,
Bruce Allan70495a52012-01-11 01:26:50 +00002258 .get_rxnfc = e1000_get_rxnfc,
Bruce Allanb67e1912012-12-27 08:32:33 +00002259 .get_ts_info = e1000e_get_ts_info,
Bruce Allan203e4152012-12-05 08:40:59 +00002260 .get_eee = e1000e_get_eee,
2261 .set_eee = e1000e_set_eee,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002262};
2263
2264void e1000e_set_ethtool_ops(struct net_device *netdev)
2265{
2266 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
2267}