blob: f268cbcb751d93a3e55b6ea1296d6cb053073567 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanf5e261e2012-01-01 16:00:03 +00004 Copyright(c) 1999 - 2012 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29/* ethtool support for e1000 */
30
31#include <linux/netdevice.h>
Bruce Allan9fb7a5f2011-07-29 05:52:51 +000032#include <linux/interrupt.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070033#include <linux/ethtool.h>
34#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070036#include <linux/delay.h>
David S. Millerc85c21a2012-01-26 16:25:55 -050037#include <linux/vmalloc.h>
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),
Auke Kokbc7f75f2007-09-17 12:30:59 -0700112};
113
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200114#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700115#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
116static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
117 "Register test (offline)", "Eeprom test (offline)",
118 "Interrupt test (offline)", "Loopback test (offline)",
119 "Link test (on/offline)"
120};
Bruce Allanad680762008-03-28 09:15:03 -0700121#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700122
123static int e1000_get_settings(struct net_device *netdev,
124 struct ethtool_cmd *ecmd)
125{
126 struct e1000_adapter *adapter = netdev_priv(netdev);
127 struct e1000_hw *hw = &adapter->hw;
David Decotigny70739492011-04-27 18:32:40 +0000128 u32 speed;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700129
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700130 if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700131
132 ecmd->supported = (SUPPORTED_10baseT_Half |
133 SUPPORTED_10baseT_Full |
134 SUPPORTED_100baseT_Half |
135 SUPPORTED_100baseT_Full |
136 SUPPORTED_1000baseT_Full |
137 SUPPORTED_Autoneg |
138 SUPPORTED_TP);
139 if (hw->phy.type == e1000_phy_ife)
140 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
141 ecmd->advertising = ADVERTISED_TP;
142
143 if (hw->mac.autoneg == 1) {
144 ecmd->advertising |= ADVERTISED_Autoneg;
145 /* the e1000 autoneg seems to match ethtool nicely */
146 ecmd->advertising |= hw->phy.autoneg_advertised;
147 }
148
149 ecmd->port = PORT_TP;
150 ecmd->phy_address = hw->phy.addr;
151 ecmd->transceiver = XCVR_INTERNAL;
152
153 } else {
154 ecmd->supported = (SUPPORTED_1000baseT_Full |
155 SUPPORTED_FIBRE |
156 SUPPORTED_Autoneg);
157
158 ecmd->advertising = (ADVERTISED_1000baseT_Full |
159 ADVERTISED_FIBRE |
160 ADVERTISED_Autoneg);
161
162 ecmd->port = PORT_FIBRE;
163 ecmd->transceiver = XCVR_EXTERNAL;
164 }
165
David Decotigny70739492011-04-27 18:32:40 +0000166 speed = -1;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000167 ecmd->duplex = -1;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700168
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000169 if (netif_running(netdev)) {
170 if (netif_carrier_ok(netdev)) {
David Decotigny70739492011-04-27 18:32:40 +0000171 speed = adapter->link_speed;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000172 ecmd->duplex = adapter->link_duplex - 1;
173 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700174 } else {
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000175 u32 status = er32(STATUS);
176 if (status & E1000_STATUS_LU) {
177 if (status & E1000_STATUS_SPEED_1000)
David Decotigny70739492011-04-27 18:32:40 +0000178 speed = SPEED_1000;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000179 else if (status & E1000_STATUS_SPEED_100)
David Decotigny70739492011-04-27 18:32:40 +0000180 speed = SPEED_100;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000181 else
David Decotigny70739492011-04-27 18:32:40 +0000182 speed = SPEED_10;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000183
184 if (status & E1000_STATUS_FD)
185 ecmd->duplex = DUPLEX_FULL;
186 else
187 ecmd->duplex = DUPLEX_HALF;
188 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700189 }
190
David Decotigny70739492011-04-27 18:32:40 +0000191 ethtool_cmd_speed_set(ecmd, speed);
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700192 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -0700193 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000194
195 /* MDI-X => 2; MDI =>1; Invalid =>0 */
196 if ((hw->phy.media_type == e1000_media_type_copper) &&
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000197 netif_carrier_ok(netdev))
Chaitanya Lala18760f12009-06-08 14:28:54 +0000198 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
199 ETH_TP_MDI;
200 else
201 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
202
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000203 if (hw->phy.mdix == AUTO_ALL_MODES)
204 ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
205 else
206 ecmd->eth_tp_mdix_ctrl = hw->phy.mdix;
207
Auke Kokbc7f75f2007-09-17 12:30:59 -0700208 return 0;
209}
210
David Decotigny14ad2512011-04-27 18:32:43 +0000211static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700212{
213 struct e1000_mac_info *mac = &adapter->hw.mac;
214
215 mac->autoneg = 0;
216
David Decotigny14ad2512011-04-27 18:32:43 +0000217 /* Make sure dplx is at most 1 bit and lsb of speed is not set
Bruce Allane921eb12012-11-28 09:28:37 +0000218 * for the switch() below to work
219 */
David Decotigny14ad2512011-04-27 18:32:43 +0000220 if ((spd & 1) || (dplx & ~1))
221 goto err_inval;
222
Auke Kokbc7f75f2007-09-17 12:30:59 -0700223 /* Fiber NICs only allow 1000 gbps Full duplex */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700224 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
David Decotigny14ad2512011-04-27 18:32:43 +0000225 spd != SPEED_1000 &&
226 dplx != DUPLEX_FULL) {
227 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700228 }
229
David Decotigny14ad2512011-04-27 18:32:43 +0000230 switch (spd + dplx) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700231 case SPEED_10 + DUPLEX_HALF:
232 mac->forced_speed_duplex = ADVERTISE_10_HALF;
233 break;
234 case SPEED_10 + DUPLEX_FULL:
235 mac->forced_speed_duplex = ADVERTISE_10_FULL;
236 break;
237 case SPEED_100 + DUPLEX_HALF:
238 mac->forced_speed_duplex = ADVERTISE_100_HALF;
239 break;
240 case SPEED_100 + DUPLEX_FULL:
241 mac->forced_speed_duplex = ADVERTISE_100_FULL;
242 break;
243 case SPEED_1000 + DUPLEX_FULL:
244 mac->autoneg = 1;
245 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
246 break;
247 case SPEED_1000 + DUPLEX_HALF: /* not supported */
248 default:
David Decotigny14ad2512011-04-27 18:32:43 +0000249 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700250 }
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000251
252 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
253 adapter->hw.phy.mdix = AUTO_ALL_MODES;
254
Auke Kokbc7f75f2007-09-17 12:30:59 -0700255 return 0;
David Decotigny14ad2512011-04-27 18:32:43 +0000256
257err_inval:
258 e_err("Unsupported Speed/Duplex configuration\n");
259 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700260}
261
262static int e1000_set_settings(struct net_device *netdev,
263 struct ethtool_cmd *ecmd)
264{
265 struct e1000_adapter *adapter = netdev_priv(netdev);
266 struct e1000_hw *hw = &adapter->hw;
267
Bruce Allane921eb12012-11-28 09:28:37 +0000268 /* When SoL/IDER sessions are active, autoneg/speed/duplex
Bruce Allanad680762008-03-28 09:15:03 -0700269 * cannot be changed
270 */
Bruce Allan470a5422012-05-26 06:08:48 +0000271 if (hw->phy.ops.check_reset_block &&
272 hw->phy.ops.check_reset_block(hw)) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000273 e_err("Cannot change link characteristics when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700274 return -EINVAL;
275 }
276
Bruce Allane921eb12012-11-28 09:28:37 +0000277 /* MDI setting is only allowed when autoneg enabled because
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000278 * some hardware doesn't allow MDI setting when speed or
279 * duplex is forced.
280 */
281 if (ecmd->eth_tp_mdix_ctrl) {
282 if (hw->phy.media_type != e1000_media_type_copper)
283 return -EOPNOTSUPP;
284
285 if ((ecmd->eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) &&
286 (ecmd->autoneg != AUTONEG_ENABLE)) {
287 e_err("forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
288 return -EINVAL;
289 }
290 }
291
Auke Kokbc7f75f2007-09-17 12:30:59 -0700292 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000293 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700294
295 if (ecmd->autoneg == AUTONEG_ENABLE) {
296 hw->mac.autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700297 if (hw->phy.media_type == e1000_media_type_fiber)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700298 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
299 ADVERTISED_FIBRE |
300 ADVERTISED_Autoneg;
301 else
302 hw->phy.autoneg_advertised = ecmd->advertising |
303 ADVERTISED_TP |
304 ADVERTISED_Autoneg;
305 ecmd->advertising = hw->phy.autoneg_advertised;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700306 if (adapter->fc_autoneg)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800307 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700308 } else {
David Decotigny25db0332011-04-27 18:32:39 +0000309 u32 speed = ethtool_cmd_speed(ecmd);
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000310 /* calling this overrides forced MDI setting */
David Decotigny14ad2512011-04-27 18:32:43 +0000311 if (e1000_set_spd_dplx(adapter, speed, ecmd->duplex)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700312 clear_bit(__E1000_RESETTING, &adapter->state);
313 return -EINVAL;
314 }
315 }
316
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000317 /* MDI-X => 2; MDI => 1; Auto => 3 */
318 if (ecmd->eth_tp_mdix_ctrl) {
Bruce Allane921eb12012-11-28 09:28:37 +0000319 /* fix up the value for auto (3 => 0) as zero is mapped
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000320 * internally to auto
321 */
322 if (ecmd->eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
323 hw->phy.mdix = AUTO_ALL_MODES;
324 else
325 hw->phy.mdix = ecmd->eth_tp_mdix_ctrl;
326 }
327
Auke Kokbc7f75f2007-09-17 12:30:59 -0700328 /* reset the link */
329
330 if (netif_running(adapter->netdev)) {
331 e1000e_down(adapter);
332 e1000e_up(adapter);
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000333 } else
Auke Kokbc7f75f2007-09-17 12:30:59 -0700334 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700335
336 clear_bit(__E1000_RESETTING, &adapter->state);
337 return 0;
338}
339
340static void e1000_get_pauseparam(struct net_device *netdev,
341 struct ethtool_pauseparam *pause)
342{
343 struct e1000_adapter *adapter = netdev_priv(netdev);
344 struct e1000_hw *hw = &adapter->hw;
345
346 pause->autoneg =
347 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
348
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800349 if (hw->fc.current_mode == e1000_fc_rx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700350 pause->rx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800351 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700352 pause->tx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800353 } else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700354 pause->rx_pause = 1;
355 pause->tx_pause = 1;
356 }
357}
358
359static int e1000_set_pauseparam(struct net_device *netdev,
360 struct ethtool_pauseparam *pause)
361{
362 struct e1000_adapter *adapter = netdev_priv(netdev);
363 struct e1000_hw *hw = &adapter->hw;
364 int retval = 0;
365
366 adapter->fc_autoneg = pause->autoneg;
367
368 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000369 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700370
Auke Kokbc7f75f2007-09-17 12:30:59 -0700371 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800372 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700373 if (netif_running(adapter->netdev)) {
374 e1000e_down(adapter);
375 e1000e_up(adapter);
376 } else {
377 e1000e_reset(adapter);
378 }
379 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800380 if (pause->rx_pause && pause->tx_pause)
381 hw->fc.requested_mode = e1000_fc_full;
382 else if (pause->rx_pause && !pause->tx_pause)
383 hw->fc.requested_mode = e1000_fc_rx_pause;
384 else if (!pause->rx_pause && pause->tx_pause)
385 hw->fc.requested_mode = e1000_fc_tx_pause;
386 else if (!pause->rx_pause && !pause->tx_pause)
387 hw->fc.requested_mode = e1000_fc_none;
388
389 hw->fc.current_mode = hw->fc.requested_mode;
390
Bruce Allan945eb312009-10-28 18:28:30 +0000391 if (hw->phy.media_type == e1000_media_type_fiber) {
392 retval = hw->mac.ops.setup_link(hw);
393 /* implicit goto out */
394 } else {
395 retval = e1000e_force_mac_fc(hw);
396 if (retval)
397 goto out;
398 e1000e_set_fc_watermarks(hw);
399 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700400 }
401
Bruce Allan945eb312009-10-28 18:28:30 +0000402out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700403 clear_bit(__E1000_RESETTING, &adapter->state);
404 return retval;
405}
406
Auke Kokbc7f75f2007-09-17 12:30:59 -0700407static u32 e1000_get_msglevel(struct net_device *netdev)
408{
409 struct e1000_adapter *adapter = netdev_priv(netdev);
410 return adapter->msg_enable;
411}
412
413static void e1000_set_msglevel(struct net_device *netdev, u32 data)
414{
415 struct e1000_adapter *adapter = netdev_priv(netdev);
416 adapter->msg_enable = data;
417}
418
419static int e1000_get_regs_len(struct net_device *netdev)
420{
421#define E1000_REGS_LEN 32 /* overestimate */
422 return E1000_REGS_LEN * sizeof(u32);
423}
424
425static void e1000_get_regs(struct net_device *netdev,
426 struct ethtool_regs *regs, void *p)
427{
428 struct e1000_adapter *adapter = netdev_priv(netdev);
429 struct e1000_hw *hw = &adapter->hw;
430 u32 *regs_buff = p;
431 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700432
433 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
434
Sergei Shtylyovff938e42011-02-28 11:57:33 -0800435 regs->version = (1 << 24) | (adapter->pdev->revision << 16) |
436 adapter->pdev->device;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700437
438 regs_buff[0] = er32(CTRL);
439 regs_buff[1] = er32(STATUS);
440
441 regs_buff[2] = er32(RCTL);
Bruce Allan1e360522012-03-20 03:48:13 +0000442 regs_buff[3] = er32(RDLEN(0));
443 regs_buff[4] = er32(RDH(0));
444 regs_buff[5] = er32(RDT(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700445 regs_buff[6] = er32(RDTR);
446
447 regs_buff[7] = er32(TCTL);
Bruce Allan1e360522012-03-20 03:48:13 +0000448 regs_buff[8] = er32(TDLEN(0));
449 regs_buff[9] = er32(TDH(0));
450 regs_buff[10] = er32(TDT(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700451 regs_buff[11] = er32(TIDV);
452
453 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700454
455 /* ethtool doesn't use anything past this point, so all this
Bruce Allane921eb12012-11-28 09:28:37 +0000456 * code is likely legacy junk for apps that may or may not exist
457 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700458 if (hw->phy.type == e1000_phy_m88) {
459 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
460 regs_buff[13] = (u32)phy_data; /* cable length */
461 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
462 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
463 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
464 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
465 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
466 regs_buff[18] = regs_buff[13]; /* cable polarity */
467 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
468 regs_buff[20] = regs_buff[17]; /* polarity correction */
469 /* phy receive errors */
470 regs_buff[22] = adapter->phy_stats.receive_errors;
471 regs_buff[23] = regs_buff[13]; /* mdix mode */
472 }
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700473 regs_buff[21] = 0; /* was idle_errors */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700474 e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
475 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
476 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
477}
478
479static int e1000_get_eeprom_len(struct net_device *netdev)
480{
481 struct e1000_adapter *adapter = netdev_priv(netdev);
482 return adapter->hw.nvm.word_size * 2;
483}
484
485static int e1000_get_eeprom(struct net_device *netdev,
486 struct ethtool_eeprom *eeprom, u8 *bytes)
487{
488 struct e1000_adapter *adapter = netdev_priv(netdev);
489 struct e1000_hw *hw = &adapter->hw;
490 u16 *eeprom_buff;
491 int first_word;
492 int last_word;
493 int ret_val = 0;
494 u16 i;
495
496 if (eeprom->len == 0)
497 return -EINVAL;
498
499 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
500
501 first_word = eeprom->offset >> 1;
502 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
503
504 eeprom_buff = kmalloc(sizeof(u16) *
505 (last_word - first_word + 1), GFP_KERNEL);
506 if (!eeprom_buff)
507 return -ENOMEM;
508
509 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
510 ret_val = e1000_read_nvm(hw, first_word,
511 last_word - first_word + 1,
512 eeprom_buff);
513 } else {
514 for (i = 0; i < last_word - first_word + 1; i++) {
515 ret_val = e1000_read_nvm(hw, first_word + i, 1,
516 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800517 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700518 break;
519 }
520 }
521
Bruce Allane2434552008-11-21 17:02:41 -0800522 if (ret_val) {
523 /* a read error occurred, throw away the result */
Roel Kluin8528b012009-12-01 15:54:24 +0000524 memset(eeprom_buff, 0xff, sizeof(u16) *
525 (last_word - first_word + 1));
Bruce Allane2434552008-11-21 17:02:41 -0800526 } else {
527 /* Device's eeprom is always little-endian, word addressable */
528 for (i = 0; i < last_word - first_word + 1; i++)
529 le16_to_cpus(&eeprom_buff[i]);
530 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700531
532 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
533 kfree(eeprom_buff);
534
535 return ret_val;
536}
537
538static int e1000_set_eeprom(struct net_device *netdev,
539 struct ethtool_eeprom *eeprom, u8 *bytes)
540{
541 struct e1000_adapter *adapter = netdev_priv(netdev);
542 struct e1000_hw *hw = &adapter->hw;
543 u16 *eeprom_buff;
544 void *ptr;
545 int max_len;
546 int first_word;
547 int last_word;
548 int ret_val = 0;
549 u16 i;
550
551 if (eeprom->len == 0)
552 return -EOPNOTSUPP;
553
554 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
555 return -EFAULT;
556
Bruce Allan4a770352008-10-01 17:18:35 -0700557 if (adapter->flags & FLAG_READ_ONLY_NVM)
558 return -EINVAL;
559
Auke Kokbc7f75f2007-09-17 12:30:59 -0700560 max_len = hw->nvm.word_size * 2;
561
562 first_word = eeprom->offset >> 1;
563 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
564 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
565 if (!eeprom_buff)
566 return -ENOMEM;
567
568 ptr = (void *)eeprom_buff;
569
570 if (eeprom->offset & 1) {
571 /* need read/modify/write of first changed EEPROM word */
572 /* only the second byte of the word is being modified */
573 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
574 ptr++;
575 }
Bruce Allan9e2d7652012-01-31 06:37:27 +0000576 if (((eeprom->offset + eeprom->len) & 1) && (!ret_val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700577 /* need read/modify/write of last changed EEPROM word */
578 /* only the first byte of the word is being modified */
579 ret_val = e1000_read_nvm(hw, last_word, 1,
580 &eeprom_buff[last_word - first_word]);
581
Bruce Allane2434552008-11-21 17:02:41 -0800582 if (ret_val)
583 goto out;
584
Auke Kokbc7f75f2007-09-17 12:30:59 -0700585 /* Device's eeprom is always little-endian, word addressable */
586 for (i = 0; i < last_word - first_word + 1; i++)
587 le16_to_cpus(&eeprom_buff[i]);
588
589 memcpy(ptr, bytes, eeprom->len);
590
591 for (i = 0; i < last_word - first_word + 1; i++)
Bruce Allane885d762012-01-31 06:37:32 +0000592 cpu_to_le16s(&eeprom_buff[i]);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700593
594 ret_val = e1000_write_nvm(hw, first_word,
595 last_word - first_word + 1, eeprom_buff);
596
Bruce Allane2434552008-11-21 17:02:41 -0800597 if (ret_val)
598 goto out;
599
Bruce Allane921eb12012-11-28 09:28:37 +0000600 /* Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800601 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700602 */
Bruce Allane2434552008-11-21 17:02:41 -0800603 if ((first_word <= NVM_CHECKSUM_REG) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +0000604 (hw->mac.type == e1000_82583) ||
605 (hw->mac.type == e1000_82574) ||
606 (hw->mac.type == e1000_82573))
Bruce Allane2434552008-11-21 17:02:41 -0800607 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700608
Bruce Allane2434552008-11-21 17:02:41 -0800609out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700610 kfree(eeprom_buff);
611 return ret_val;
612}
613
614static void e1000_get_drvinfo(struct net_device *netdev,
615 struct ethtool_drvinfo *drvinfo)
616{
617 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700618
Rick Jones612a94d2011-11-14 08:13:25 +0000619 strlcpy(drvinfo->driver, e1000e_driver_name,
620 sizeof(drvinfo->driver));
Rick Jones33a5ba12011-11-15 14:59:53 +0000621 strlcpy(drvinfo->version, e1000e_driver_version,
Rick Jones612a94d2011-11-14 08:13:25 +0000622 sizeof(drvinfo->version));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700623
Bruce Allane921eb12012-11-28 09:28:37 +0000624 /* EEPROM image version # is reported as firmware version # for
Bruce Allanad680762008-03-28 09:15:03 -0700625 * PCI-E controllers
626 */
Rick Jones612a94d2011-11-14 08:13:25 +0000627 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
628 "%d.%d-%d",
Bruce Allan84527592008-11-21 17:00:22 -0800629 (adapter->eeprom_vers & 0xF000) >> 12,
630 (adapter->eeprom_vers & 0x0FF0) >> 4,
631 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700632
Rick Jones612a94d2011-11-14 08:13:25 +0000633 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
634 sizeof(drvinfo->bus_info));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700635 drvinfo->regdump_len = e1000_get_regs_len(netdev);
636 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
637}
638
639static void e1000_get_ringparam(struct net_device *netdev,
640 struct ethtool_ringparam *ring)
641{
642 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700643
644 ring->rx_max_pending = E1000_MAX_RXD;
645 ring->tx_max_pending = E1000_MAX_TXD;
Bruce Allan508da422011-12-16 00:45:51 +0000646 ring->rx_pending = adapter->rx_ring_count;
647 ring->tx_pending = adapter->tx_ring_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700648}
649
650static int e1000_set_ringparam(struct net_device *netdev,
651 struct ethtool_ringparam *ring)
652{
653 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan508da422011-12-16 00:45:51 +0000654 struct e1000_ring *temp_tx = NULL, *temp_rx = NULL;
655 int err = 0, size = sizeof(struct e1000_ring);
656 bool set_tx = false, set_rx = false;
657 u16 new_rx_count, new_tx_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700658
659 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
660 return -EINVAL;
661
Bruce Allan508da422011-12-16 00:45:51 +0000662 new_rx_count = clamp_t(u32, ring->rx_pending, E1000_MIN_RXD,
663 E1000_MAX_RXD);
664 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
665
666 new_tx_count = clamp_t(u32, ring->tx_pending, E1000_MIN_TXD,
667 E1000_MAX_TXD);
668 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
669
670 if ((new_tx_count == adapter->tx_ring_count) &&
671 (new_rx_count == adapter->rx_ring_count))
672 /* nothing to do */
673 return 0;
674
Auke Kokbc7f75f2007-09-17 12:30:59 -0700675 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000676 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700677
Bruce Allan508da422011-12-16 00:45:51 +0000678 if (!netif_running(adapter->netdev)) {
679 /* Set counts now and allocate resources during open() */
680 adapter->tx_ring->count = new_tx_count;
681 adapter->rx_ring->count = new_rx_count;
682 adapter->tx_ring_count = new_tx_count;
683 adapter->rx_ring_count = new_rx_count;
684 goto clear_reset;
685 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700686
Bruce Allan508da422011-12-16 00:45:51 +0000687 set_tx = (new_tx_count != adapter->tx_ring_count);
688 set_rx = (new_rx_count != adapter->rx_ring_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700689
Bruce Allan508da422011-12-16 00:45:51 +0000690 /* Allocate temporary storage for ring updates */
691 if (set_tx) {
692 temp_tx = vmalloc(size);
693 if (!temp_tx) {
694 err = -ENOMEM;
695 goto free_temp;
696 }
697 }
698 if (set_rx) {
699 temp_rx = vmalloc(size);
700 if (!temp_rx) {
701 err = -ENOMEM;
702 goto free_temp;
703 }
704 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700705
Bruce Allan508da422011-12-16 00:45:51 +0000706 e1000e_down(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700707
Bruce Allane921eb12012-11-28 09:28:37 +0000708 /* We can't just free everything and then setup again, because the
Bruce Allan508da422011-12-16 00:45:51 +0000709 * ISRs in MSI-X mode get passed pointers to the Tx and Rx ring
710 * structs. First, attempt to allocate new resources...
711 */
712 if (set_tx) {
713 memcpy(temp_tx, adapter->tx_ring, size);
714 temp_tx->count = new_tx_count;
715 err = e1000e_setup_tx_resources(temp_tx);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700716 if (err)
717 goto err_setup;
718 }
Bruce Allan508da422011-12-16 00:45:51 +0000719 if (set_rx) {
720 memcpy(temp_rx, adapter->rx_ring, size);
721 temp_rx->count = new_rx_count;
722 err = e1000e_setup_rx_resources(temp_rx);
723 if (err)
724 goto err_setup_rx;
725 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700726
Bruce Allan508da422011-12-16 00:45:51 +0000727 /* ...then free the old resources and copy back any new ring data */
728 if (set_tx) {
729 e1000e_free_tx_resources(adapter->tx_ring);
730 memcpy(adapter->tx_ring, temp_tx, size);
731 adapter->tx_ring_count = new_tx_count;
732 }
733 if (set_rx) {
734 e1000e_free_rx_resources(adapter->rx_ring);
735 memcpy(adapter->rx_ring, temp_rx, size);
736 adapter->rx_ring_count = new_rx_count;
737 }
738
Auke Kokbc7f75f2007-09-17 12:30:59 -0700739err_setup_rx:
Bruce Allan508da422011-12-16 00:45:51 +0000740 if (err && set_tx)
741 e1000e_free_tx_resources(temp_tx);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700742err_setup:
Bruce Allan508da422011-12-16 00:45:51 +0000743 e1000e_up(adapter);
744free_temp:
745 vfree(temp_tx);
746 vfree(temp_rx);
747clear_reset:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700748 clear_bit(__E1000_RESETTING, &adapter->state);
749 return err;
750}
751
Bruce Allancef8c792008-04-02 13:48:23 -0700752static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
753 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800754{
Bruce Allancef8c792008-04-02 13:48:23 -0700755 u32 pat, val;
Bruce Allan64806412010-12-11 05:53:42 +0000756 static const u32 test[] = {
757 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Bruce Allancef8c792008-04-02 13:48:23 -0700758 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800759 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700760 (test[pat] & write));
761 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
762 if (val != (test[pat] & write & mask)) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000763 e_err("pattern test reg %04X failed: got 0x%08X expected 0x%08X\n",
764 reg + offset, val, (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800765 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700766 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800767 }
768 }
Bruce Allancef8c792008-04-02 13:48:23 -0700769 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700770}
771
Joe Perches2a887192007-11-13 20:53:51 -0800772static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
773 int reg, u32 mask, u32 write)
774{
Bruce Allancef8c792008-04-02 13:48:23 -0700775 u32 val;
Joe Perches2a887192007-11-13 20:53:51 -0800776 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700777 val = __er32(&adapter->hw, reg);
778 if ((write & mask) != (val & mask)) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000779 e_err("set/check reg %04X test failed: got 0x%08X expected 0x%08X\n",
780 reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800781 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700782 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800783 }
Bruce Allancef8c792008-04-02 13:48:23 -0700784 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700785}
Bruce Allancef8c792008-04-02 13:48:23 -0700786#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
787 do { \
788 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
789 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800790 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700791#define REG_PATTERN_TEST(reg, mask, write) \
792 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800793
Bruce Allancef8c792008-04-02 13:48:23 -0700794#define REG_SET_AND_CHECK(reg, mask, write) \
795 do { \
796 if (reg_set_and_check(adapter, data, reg, mask, write)) \
797 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800798 } while (0)
799
Auke Kokbc7f75f2007-09-17 12:30:59 -0700800static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
801{
802 struct e1000_hw *hw = &adapter->hw;
803 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700804 u32 value;
805 u32 before;
806 u32 after;
807 u32 i;
808 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000809 u32 mask;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000810 u32 wlock_mac = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700811
Bruce Allane921eb12012-11-28 09:28:37 +0000812 /* The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700813 * Some bits that get toggled are ignored.
814 */
815 switch (mac->type) {
816 /* there are several bits on newer hardware that are r/w */
817 case e1000_82571:
818 case e1000_82572:
819 case e1000_80003es2lan:
820 toggle = 0x7FFFF3FF;
821 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000822 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700823 toggle = 0x7FFFF033;
824 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700825 }
826
827 before = er32(STATUS);
828 value = (er32(STATUS) & toggle);
829 ew32(STATUS, toggle);
830 after = er32(STATUS) & toggle;
831 if (value != after) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000832 e_err("failed STATUS register test got: 0x%08X expected: 0x%08X\n",
833 after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700834 *data = 1;
835 return 1;
836 }
837 /* restore previous status */
838 ew32(STATUS, before);
839
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700840 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700841 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
842 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
843 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
844 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
845 }
846
847 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000848 REG_PATTERN_TEST(E1000_RDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
849 REG_PATTERN_TEST(E1000_RDLEN(0), 0x000FFF80, 0x000FFFFF);
850 REG_PATTERN_TEST(E1000_RDH(0), 0x0000FFFF, 0x0000FFFF);
851 REG_PATTERN_TEST(E1000_RDT(0), 0x0000FFFF, 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700852 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
853 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
854 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000855 REG_PATTERN_TEST(E1000_TDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
856 REG_PATTERN_TEST(E1000_TDLEN(0), 0x000FFF80, 0x000FFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700857
858 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
859
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700860 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700861 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
862 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
863
Auke Kok86582512007-10-04 15:00:08 -0700864 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000865 REG_PATTERN_TEST(E1000_RDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700866 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700867 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000868 REG_PATTERN_TEST(E1000_TDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
Auke Kok86582512007-10-04 15:00:08 -0700869 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000870 mask = 0x8003FFFF;
871 switch (mac->type) {
872 case e1000_ich10lan:
873 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000874 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000875 case e1000_pch_lpt:
Bruce Allana4f58f52009-06-02 11:29:18 +0000876 mask |= (1 << 18);
877 break;
878 default:
879 break;
880 }
Bruce Allan2fbe4522012-04-19 03:21:47 +0000881
882 if (mac->type == e1000_pch_lpt)
883 wlock_mac = (er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK) >>
884 E1000_FWSM_WLOCK_MAC_SHIFT;
885
886 for (i = 0; i < mac->rar_entry_count; i++) {
887 /* Cannot test write-protected SHRAL[n] registers */
888 if ((wlock_mac == 1) || (wlock_mac && (i > wlock_mac)))
889 continue;
890
Auke Kok86582512007-10-04 15:00:08 -0700891 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
Bruce Allan2fbe4522012-04-19 03:21:47 +0000892 mask, 0xFFFFFFFF);
893 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700894
895 for (i = 0; i < mac->mta_reg_count; i++)
896 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
897
898 *data = 0;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000899
Auke Kokbc7f75f2007-09-17 12:30:59 -0700900 return 0;
901}
902
903static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
904{
905 u16 temp;
906 u16 checksum = 0;
907 u16 i;
908
909 *data = 0;
910 /* Read and add up the contents of the EEPROM */
911 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
912 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
913 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800914 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700915 }
916 checksum += temp;
917 }
918
919 /* If Checksum is not Correct return error else test passed */
920 if ((checksum != (u16) NVM_SUM) && !(*data))
921 *data = 2;
922
923 return *data;
924}
925
926static irqreturn_t e1000_test_intr(int irq, void *data)
927{
928 struct net_device *netdev = (struct net_device *) data;
929 struct e1000_adapter *adapter = netdev_priv(netdev);
930 struct e1000_hw *hw = &adapter->hw;
931
932 adapter->test_icr |= er32(ICR);
933
934 return IRQ_HANDLED;
935}
936
937static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
938{
939 struct net_device *netdev = adapter->netdev;
940 struct e1000_hw *hw = &adapter->hw;
941 u32 mask;
942 u32 shared_int = 1;
943 u32 irq = adapter->pdev->irq;
944 int i;
Bruce Allan4662e822008-08-26 18:37:06 -0700945 int ret_val = 0;
946 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700947
948 *data = 0;
949
Bruce Allan4662e822008-08-26 18:37:06 -0700950 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
951 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
952 int_mode = adapter->int_mode;
953 e1000e_reset_interrupt_capability(adapter);
954 adapter->int_mode = E1000E_INT_MODE_LEGACY;
955 e1000e_set_interrupt_capability(adapter);
956 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700957 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800958 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700959 netdev)) {
960 shared_int = 0;
Joe Perchesa0607fd2009-11-18 23:29:17 -0800961 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700962 netdev->name, netdev)) {
963 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700964 ret_val = -1;
965 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700966 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700967 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700968
969 /* Disable all the interrupts */
970 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000971 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000972 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700973
974 /* Test each interrupt */
975 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700976 /* Interrupt to test */
977 mask = 1 << i;
978
Bruce Allanf4187b52008-08-26 18:36:50 -0700979 if (adapter->flags & FLAG_IS_ICH) {
980 switch (mask) {
981 case E1000_ICR_RXSEQ:
982 continue;
983 case 0x00000100:
984 if (adapter->hw.mac.type == e1000_ich8lan ||
985 adapter->hw.mac.type == e1000_ich9lan)
986 continue;
987 break;
988 default:
989 break;
990 }
991 }
992
Auke Kokbc7f75f2007-09-17 12:30:59 -0700993 if (!shared_int) {
Bruce Allane921eb12012-11-28 09:28:37 +0000994 /* Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700995 * the cause register and then force the same
996 * interrupt and see if one gets posted. If
997 * an interrupt was posted to the bus, the
998 * test failed.
999 */
1000 adapter->test_icr = 0;
1001 ew32(IMC, mask);
1002 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001003 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001004 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001005
1006 if (adapter->test_icr & mask) {
1007 *data = 3;
1008 break;
1009 }
1010 }
1011
Bruce Allane921eb12012-11-28 09:28:37 +00001012 /* Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001013 * the cause register and then force the same
1014 * interrupt and see if one gets posted. If
1015 * an interrupt was not posted to the bus, the
1016 * test failed.
1017 */
1018 adapter->test_icr = 0;
1019 ew32(IMS, mask);
1020 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001021 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001022 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001023
1024 if (!(adapter->test_icr & mask)) {
1025 *data = 4;
1026 break;
1027 }
1028
1029 if (!shared_int) {
Bruce Allane921eb12012-11-28 09:28:37 +00001030 /* Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001031 * the cause register and then force the other
1032 * interrupts and see if any get posted. If
1033 * an interrupt was posted to the bus, the
1034 * test failed.
1035 */
1036 adapter->test_icr = 0;
1037 ew32(IMC, ~mask & 0x00007FFF);
1038 ew32(ICS, ~mask & 0x00007FFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001039 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001040 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001041
1042 if (adapter->test_icr) {
1043 *data = 5;
1044 break;
1045 }
1046 }
1047 }
1048
1049 /* Disable all the interrupts */
1050 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001051 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001052 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001053
1054 /* Unhook test interrupt handler */
1055 free_irq(irq, netdev);
1056
Bruce Allan4662e822008-08-26 18:37:06 -07001057out:
1058 if (int_mode == E1000E_INT_MODE_MSIX) {
1059 e1000e_reset_interrupt_capability(adapter);
1060 adapter->int_mode = int_mode;
1061 e1000e_set_interrupt_capability(adapter);
1062 }
1063
1064 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001065}
1066
1067static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1068{
1069 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1070 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1071 struct pci_dev *pdev = adapter->pdev;
1072 int i;
1073
1074 if (tx_ring->desc && tx_ring->buffer_info) {
1075 for (i = 0; i < tx_ring->count; i++) {
1076 if (tx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001077 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001078 tx_ring->buffer_info[i].dma,
1079 tx_ring->buffer_info[i].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001080 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001081 if (tx_ring->buffer_info[i].skb)
1082 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1083 }
1084 }
1085
1086 if (rx_ring->desc && rx_ring->buffer_info) {
1087 for (i = 0; i < rx_ring->count; i++) {
1088 if (rx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001089 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001090 rx_ring->buffer_info[i].dma,
Nick Nunley0be3f552010-04-27 13:09:05 +00001091 2048, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001092 if (rx_ring->buffer_info[i].skb)
1093 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1094 }
1095 }
1096
1097 if (tx_ring->desc) {
1098 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1099 tx_ring->dma);
1100 tx_ring->desc = NULL;
1101 }
1102 if (rx_ring->desc) {
1103 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1104 rx_ring->dma);
1105 rx_ring->desc = NULL;
1106 }
1107
1108 kfree(tx_ring->buffer_info);
1109 tx_ring->buffer_info = NULL;
1110 kfree(rx_ring->buffer_info);
1111 rx_ring->buffer_info = NULL;
1112}
1113
1114static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1115{
1116 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1117 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1118 struct pci_dev *pdev = adapter->pdev;
1119 struct e1000_hw *hw = &adapter->hw;
1120 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001121 int i;
1122 int ret_val;
1123
1124 /* Setup Tx descriptor ring and Tx buffers */
1125
1126 if (!tx_ring->count)
1127 tx_ring->count = E1000_DEFAULT_TXD;
1128
Bruce Allancef8c792008-04-02 13:48:23 -07001129 tx_ring->buffer_info = kcalloc(tx_ring->count,
1130 sizeof(struct e1000_buffer),
1131 GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001132 if (!tx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001133 ret_val = 1;
1134 goto err_nomem;
1135 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001136
1137 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1138 tx_ring->size = ALIGN(tx_ring->size, 4096);
1139 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1140 &tx_ring->dma, GFP_KERNEL);
1141 if (!tx_ring->desc) {
1142 ret_val = 2;
1143 goto err_nomem;
1144 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001145 tx_ring->next_to_use = 0;
1146 tx_ring->next_to_clean = 0;
1147
Bruce Allan1e360522012-03-20 03:48:13 +00001148 ew32(TDBAL(0), ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
1149 ew32(TDBAH(0), ((u64) tx_ring->dma >> 32));
1150 ew32(TDLEN(0), tx_ring->count * sizeof(struct e1000_tx_desc));
1151 ew32(TDH(0), 0);
1152 ew32(TDT(0), 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001153 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1154 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1155 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001156
1157 for (i = 0; i < tx_ring->count; i++) {
1158 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1159 struct sk_buff *skb;
1160 unsigned int skb_size = 1024;
1161
1162 skb = alloc_skb(skb_size, GFP_KERNEL);
1163 if (!skb) {
1164 ret_val = 3;
1165 goto err_nomem;
1166 }
1167 skb_put(skb, skb_size);
1168 tx_ring->buffer_info[i].skb = skb;
1169 tx_ring->buffer_info[i].length = skb->len;
1170 tx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001171 dma_map_single(&pdev->dev, skb->data, skb->len,
1172 DMA_TO_DEVICE);
1173 if (dma_mapping_error(&pdev->dev,
1174 tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001175 ret_val = 4;
1176 goto err_nomem;
1177 }
Bruce Allancef8c792008-04-02 13:48:23 -07001178 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001179 tx_desc->lower.data = cpu_to_le32(skb->len);
1180 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1181 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001182 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001183 tx_desc->upper.data = 0;
1184 }
1185
1186 /* Setup Rx descriptor ring and Rx buffers */
1187
1188 if (!rx_ring->count)
1189 rx_ring->count = E1000_DEFAULT_RXD;
1190
Bruce Allancef8c792008-04-02 13:48:23 -07001191 rx_ring->buffer_info = kcalloc(rx_ring->count,
1192 sizeof(struct e1000_buffer),
1193 GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001194 if (!rx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001195 ret_val = 5;
1196 goto err_nomem;
1197 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001198
Bruce Allan5f450212011-07-22 06:21:46 +00001199 rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001200 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1201 &rx_ring->dma, GFP_KERNEL);
1202 if (!rx_ring->desc) {
1203 ret_val = 6;
1204 goto err_nomem;
1205 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001206 rx_ring->next_to_use = 0;
1207 rx_ring->next_to_clean = 0;
1208
1209 rctl = er32(RCTL);
Bruce Allan7f99ae62011-07-22 06:21:35 +00001210 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
1211 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan1e360522012-03-20 03:48:13 +00001212 ew32(RDBAL(0), ((u64) rx_ring->dma & 0xFFFFFFFF));
1213 ew32(RDBAH(0), ((u64) rx_ring->dma >> 32));
1214 ew32(RDLEN(0), rx_ring->size);
1215 ew32(RDH(0), 0);
1216 ew32(RDT(0), 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001217 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allancef8c792008-04-02 13:48:23 -07001218 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1219 E1000_RCTL_SBP | E1000_RCTL_SECRC |
Auke Kokbc7f75f2007-09-17 12:30:59 -07001220 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1221 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1222 ew32(RCTL, rctl);
1223
1224 for (i = 0; i < rx_ring->count; i++) {
Bruce Allan5f450212011-07-22 06:21:46 +00001225 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001226 struct sk_buff *skb;
1227
1228 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1229 if (!skb) {
1230 ret_val = 7;
1231 goto err_nomem;
1232 }
1233 skb_reserve(skb, NET_IP_ALIGN);
1234 rx_ring->buffer_info[i].skb = skb;
1235 rx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001236 dma_map_single(&pdev->dev, skb->data, 2048,
1237 DMA_FROM_DEVICE);
1238 if (dma_mapping_error(&pdev->dev,
1239 rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001240 ret_val = 8;
1241 goto err_nomem;
1242 }
Bruce Allan5f450212011-07-22 06:21:46 +00001243 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1244 rx_desc->read.buffer_addr =
1245 cpu_to_le64(rx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001246 memset(skb->data, 0x00, skb->len);
1247 }
1248
1249 return 0;
1250
1251err_nomem:
1252 e1000_free_desc_rings(adapter);
1253 return ret_val;
1254}
1255
1256static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1257{
1258 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1259 e1e_wphy(&adapter->hw, 29, 0x001F);
1260 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1261 e1e_wphy(&adapter->hw, 29, 0x001A);
1262 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1263}
1264
1265static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1266{
1267 struct e1000_hw *hw = &adapter->hw;
1268 u32 ctrl_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001269 u16 phy_reg = 0;
Bruce Allancbd006c2010-11-24 06:01:30 +00001270 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001271
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001272 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001273
Bruce Allan3af50482010-06-16 13:25:55 +00001274 if (hw->phy.type == e1000_phy_ife) {
1275 /* force 100, set loopback */
1276 e1e_wphy(hw, PHY_CONTROL, 0x6100);
Bruce Allanbb436b22009-11-20 23:24:11 +00001277
Bruce Allan3af50482010-06-16 13:25:55 +00001278 /* Now set up the MAC to the same speed/duplex as the PHY. */
1279 ctrl_reg = er32(CTRL);
1280 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1281 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1282 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1283 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1284 E1000_CTRL_FD); /* Force Duplex to FULL */
1285
1286 ew32(CTRL, ctrl_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001287 e1e_flush();
Bruce Allan3af50482010-06-16 13:25:55 +00001288 udelay(500);
1289
1290 return 0;
1291 }
1292
1293 /* Specific PHY configuration for loopback */
1294 switch (hw->phy.type) {
1295 case e1000_phy_m88:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001296 /* Auto-MDI/MDIX Off */
1297 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1298 /* reset to update Auto-MDI/MDIX */
1299 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1300 /* autoneg off */
1301 e1e_wphy(hw, PHY_CONTROL, 0x8140);
Bruce Allan3af50482010-06-16 13:25:55 +00001302 break;
1303 case e1000_phy_gg82563:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001304 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
Bruce Allancef8c792008-04-02 13:48:23 -07001305 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001306 case e1000_phy_bm:
1307 /* Set Default MAC Interface speed to 1GB */
1308 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1309 phy_reg &= ~0x0007;
1310 phy_reg |= 0x006;
1311 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1312 /* Assert SW reset for above settings to take effect */
1313 e1000e_commit_phy(hw);
1314 mdelay(1);
1315 /* Force Full Duplex */
1316 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1317 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1318 /* Set Link Up (in force link) */
1319 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1320 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1321 /* Force Link */
1322 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1323 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1324 /* Set Early Link Enable */
1325 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1326 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
Bruce Allan3af50482010-06-16 13:25:55 +00001327 break;
1328 case e1000_phy_82577:
1329 case e1000_phy_82578:
1330 /* Workaround: K1 must be disabled for stable 1Gbps operation */
Bruce Allancbd006c2010-11-24 06:01:30 +00001331 ret_val = hw->phy.ops.acquire(hw);
1332 if (ret_val) {
1333 e_err("Cannot setup 1Gbps loopback.\n");
1334 return ret_val;
1335 }
Bruce Allan3af50482010-06-16 13:25:55 +00001336 e1000_configure_k1_ich8lan(hw, false);
Bruce Allancbd006c2010-11-24 06:01:30 +00001337 hw->phy.ops.release(hw);
Bruce Allan3af50482010-06-16 13:25:55 +00001338 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001339 case e1000_phy_82579:
1340 /* Disable PHY energy detect power down */
1341 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1342 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
1343 /* Disable full chip energy detect */
1344 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1345 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1346 /* Enable loopback on the PHY */
1347#define I82577_PHY_LBK_CTRL 19
1348 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1349 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001350 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001351 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001352 }
1353
Bruce Allan3af50482010-06-16 13:25:55 +00001354 /* force 1000, set loopback */
1355 e1e_wphy(hw, PHY_CONTROL, 0x4140);
1356 mdelay(250);
1357
1358 /* Now set up the MAC to the same speed/duplex as the PHY. */
1359 ctrl_reg = er32(CTRL);
1360 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1361 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1362 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1363 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1364 E1000_CTRL_FD); /* Force Duplex to FULL */
1365
1366 if (adapter->flags & FLAG_IS_ICH)
1367 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1368
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001369 if (hw->phy.media_type == e1000_media_type_copper &&
1370 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001371 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1372 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001373 /* Set the ILOS bit on the fiber Nic if half duplex link is
Bruce Allanad680762008-03-28 09:15:03 -07001374 * detected.
1375 */
Bruce Allan90da0662011-01-06 07:02:53 +00001376 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001377 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1378 }
1379
1380 ew32(CTRL, ctrl_reg);
1381
Bruce Allane921eb12012-11-28 09:28:37 +00001382 /* Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001383 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1384 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001385 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001386 e1000_phy_disable_receiver(adapter);
1387
1388 udelay(500);
1389
1390 return 0;
1391}
1392
1393static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1394{
1395 struct e1000_hw *hw = &adapter->hw;
1396 u32 ctrl = er32(CTRL);
1397 int link = 0;
1398
1399 /* special requirements for 82571/82572 fiber adapters */
1400
Bruce Allane921eb12012-11-28 09:28:37 +00001401 /* jump through hoops to make sure link is up because serdes
Bruce Allanad680762008-03-28 09:15:03 -07001402 * link is hardwired up
1403 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001404 ctrl |= E1000_CTRL_SLU;
1405 ew32(CTRL, ctrl);
1406
1407 /* disable autoneg */
1408 ctrl = er32(TXCW);
1409 ctrl &= ~(1 << 31);
1410 ew32(TXCW, ctrl);
1411
1412 link = (er32(STATUS) & E1000_STATUS_LU);
1413
1414 if (!link) {
1415 /* set invert loss of signal */
1416 ctrl = er32(CTRL);
1417 ctrl |= E1000_CTRL_ILOS;
1418 ew32(CTRL, ctrl);
1419 }
1420
Bruce Allane921eb12012-11-28 09:28:37 +00001421 /* special write to serdes control register to enable SerDes analog
Bruce Allanad680762008-03-28 09:15:03 -07001422 * loopback
1423 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001424#define E1000_SERDES_LB_ON 0x410
1425 ew32(SCTL, E1000_SERDES_LB_ON);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001426 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001427 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001428
1429 return 0;
1430}
1431
1432/* only call this for fiber/serdes connections to es2lan */
1433static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1434{
1435 struct e1000_hw *hw = &adapter->hw;
1436 u32 ctrlext = er32(CTRL_EXT);
1437 u32 ctrl = er32(CTRL);
1438
Bruce Allane921eb12012-11-28 09:28:37 +00001439 /* save CTRL_EXT to restore later, reuse an empty variable (unused
Bruce Allanad680762008-03-28 09:15:03 -07001440 * on mac_type 80003es2lan)
1441 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001442 adapter->tx_fifo_head = ctrlext;
1443
1444 /* clear the serdes mode bits, putting the device into mac loopback */
1445 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1446 ew32(CTRL_EXT, ctrlext);
1447
1448 /* force speed to 1000/FD, link up */
1449 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1450 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1451 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1452 ew32(CTRL, ctrl);
1453
1454 /* set mac loopback */
1455 ctrl = er32(RCTL);
1456 ctrl |= E1000_RCTL_LBM_MAC;
1457 ew32(RCTL, ctrl);
1458
1459 /* set testing mode parameters (no need to reset later) */
1460#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1461#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1462 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001463 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001464
1465 return 0;
1466}
1467
1468static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1469{
1470 struct e1000_hw *hw = &adapter->hw;
1471 u32 rctl;
1472
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001473 if (hw->phy.media_type == e1000_media_type_fiber ||
1474 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001475 switch (hw->mac.type) {
1476 case e1000_80003es2lan:
1477 return e1000_set_es2lan_mac_loopback(adapter);
1478 break;
1479 case e1000_82571:
1480 case e1000_82572:
1481 return e1000_set_82571_fiber_loopback(adapter);
1482 break;
1483 default:
1484 rctl = er32(RCTL);
1485 rctl |= E1000_RCTL_LBM_TCVR;
1486 ew32(RCTL, rctl);
1487 return 0;
1488 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001489 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001490 return e1000_integrated_phy_loopback(adapter);
1491 }
1492
1493 return 7;
1494}
1495
1496static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1497{
1498 struct e1000_hw *hw = &adapter->hw;
1499 u32 rctl;
1500 u16 phy_reg;
1501
1502 rctl = er32(RCTL);
1503 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1504 ew32(RCTL, rctl);
1505
1506 switch (hw->mac.type) {
1507 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001508 if (hw->phy.media_type == e1000_media_type_fiber ||
1509 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001510 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001511 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001512 adapter->tx_fifo_head = 0;
1513 }
1514 /* fall through */
1515 case e1000_82571:
1516 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001517 if (hw->phy.media_type == e1000_media_type_fiber ||
1518 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001519#define E1000_SERDES_LB_OFF 0x400
1520 ew32(SCTL, E1000_SERDES_LB_OFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001521 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001522 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001523 break;
1524 }
1525 /* Fall Through */
1526 default:
1527 hw->mac.autoneg = 1;
1528 if (hw->phy.type == e1000_phy_gg82563)
1529 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1530 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1531 if (phy_reg & MII_CR_LOOPBACK) {
1532 phy_reg &= ~MII_CR_LOOPBACK;
1533 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1534 e1000e_commit_phy(hw);
1535 }
1536 break;
1537 }
1538}
1539
1540static void e1000_create_lbtest_frame(struct sk_buff *skb,
1541 unsigned int frame_size)
1542{
1543 memset(skb->data, 0xFF, frame_size);
1544 frame_size &= ~1;
1545 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1546 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1547 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1548}
1549
1550static int e1000_check_lbtest_frame(struct sk_buff *skb,
1551 unsigned int frame_size)
1552{
1553 frame_size &= ~1;
1554 if (*(skb->data + 3) == 0xFF)
1555 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1556 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1557 return 0;
1558 return 13;
1559}
1560
1561static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1562{
1563 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1564 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1565 struct pci_dev *pdev = adapter->pdev;
1566 struct e1000_hw *hw = &adapter->hw;
1567 int i, j, k, l;
1568 int lc;
1569 int good_cnt;
1570 int ret_val = 0;
1571 unsigned long time;
1572
Bruce Allan1e360522012-03-20 03:48:13 +00001573 ew32(RDT(0), rx_ring->count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001574
Bruce Allane921eb12012-11-28 09:28:37 +00001575 /* Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001576 * The idea is to wrap the largest ring a number of times using 64
1577 * send/receive pairs during each loop
1578 */
1579
1580 if (rx_ring->count <= tx_ring->count)
1581 lc = ((tx_ring->count / 64) * 2) + 1;
1582 else
1583 lc = ((rx_ring->count / 64) * 2) + 1;
1584
1585 k = 0;
1586 l = 0;
1587 for (j = 0; j <= lc; j++) { /* loop count loop */
1588 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001589 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1590 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001591 dma_sync_single_for_device(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001592 tx_ring->buffer_info[k].dma,
1593 tx_ring->buffer_info[k].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001594 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001595 k++;
1596 if (k == tx_ring->count)
1597 k = 0;
1598 }
Bruce Allan1e360522012-03-20 03:48:13 +00001599 ew32(TDT(0), k);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001600 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001601 msleep(200);
1602 time = jiffies; /* set the start time for the receive */
1603 good_cnt = 0;
1604 do { /* receive the sent packets */
Nick Nunley0be3f552010-04-27 13:09:05 +00001605 dma_sync_single_for_cpu(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001606 rx_ring->buffer_info[l].dma, 2048,
Nick Nunley0be3f552010-04-27 13:09:05 +00001607 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001608
1609 ret_val = e1000_check_lbtest_frame(
1610 rx_ring->buffer_info[l].skb, 1024);
1611 if (!ret_val)
1612 good_cnt++;
1613 l++;
1614 if (l == rx_ring->count)
1615 l = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00001616 /* time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001617 * enough time to complete the receives, if it's
1618 * exceeded, break and error off
1619 */
1620 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1621 if (good_cnt != 64) {
1622 ret_val = 13; /* ret_val is the same as mis-compare */
1623 break;
1624 }
Bruce Allancef8c792008-04-02 13:48:23 -07001625 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001626 ret_val = 14; /* error code for time out error */
1627 break;
1628 }
1629 } /* end loop count loop */
1630 return ret_val;
1631}
1632
1633static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1634{
Bruce Allan44abd5c2012-02-22 09:02:37 +00001635 struct e1000_hw *hw = &adapter->hw;
1636
Bruce Allane921eb12012-11-28 09:28:37 +00001637 /* PHY loopback cannot be performed if SoL/IDER sessions are active */
Bruce Allan470a5422012-05-26 06:08:48 +00001638 if (hw->phy.ops.check_reset_block &&
1639 hw->phy.ops.check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001640 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001641 *data = 0;
1642 goto out;
1643 }
1644
1645 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001646 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001647 goto out;
1648
1649 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001650 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001651 goto err_loopback;
1652
1653 *data = e1000_run_loopback_test(adapter);
1654 e1000_loopback_cleanup(adapter);
1655
1656err_loopback:
1657 e1000_free_desc_rings(adapter);
1658out:
1659 return *data;
1660}
1661
1662static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1663{
1664 struct e1000_hw *hw = &adapter->hw;
1665
1666 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001667 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001668 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001669 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001670
Bruce Allane921eb12012-11-28 09:28:37 +00001671 /* On some blade server designs, link establishment
Bruce Allanad680762008-03-28 09:15:03 -07001672 * could take as long as 2-3 minutes
1673 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001674 do {
1675 hw->mac.ops.check_for_link(hw);
1676 if (hw->mac.serdes_has_link)
1677 return *data;
1678 msleep(20);
1679 } while (i++ < 3750);
1680
1681 *data = 1;
1682 } else {
1683 hw->mac.ops.check_for_link(hw);
1684 if (hw->mac.autoneg)
Bruce Allane921eb12012-11-28 09:28:37 +00001685 /* On some Phy/switch combinations, link establishment
Bruce Allan5661aeb2011-02-25 06:36:25 +00001686 * can take a few seconds more than expected.
1687 */
1688 msleep(5000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001689
Bruce Allan5661aeb2011-02-25 06:36:25 +00001690 if (!(er32(STATUS) & E1000_STATUS_LU))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001691 *data = 1;
1692 }
1693 return *data;
1694}
1695
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001696static int e1000e_get_sset_count(struct net_device *netdev, int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001697{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001698 switch (sset) {
1699 case ETH_SS_TEST:
1700 return E1000_TEST_LEN;
1701 case ETH_SS_STATS:
1702 return E1000_STATS_LEN;
1703 default:
1704 return -EOPNOTSUPP;
1705 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001706}
1707
1708static void e1000_diag_test(struct net_device *netdev,
1709 struct ethtool_test *eth_test, u64 *data)
1710{
1711 struct e1000_adapter *adapter = netdev_priv(netdev);
1712 u16 autoneg_advertised;
1713 u8 forced_speed_duplex;
1714 u8 autoneg;
1715 bool if_running = netif_running(netdev);
1716
1717 set_bit(__E1000_TESTING, &adapter->state);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001718
1719 if (!if_running) {
1720 /* Get control of and reset hardware */
1721 if (adapter->flags & FLAG_HAS_AMT)
1722 e1000e_get_hw_control(adapter);
1723
1724 e1000e_power_up_phy(adapter);
1725
1726 adapter->hw.phy.autoneg_wait_to_complete = 1;
1727 e1000e_reset(adapter);
1728 adapter->hw.phy.autoneg_wait_to_complete = 0;
1729 }
1730
Auke Kokbc7f75f2007-09-17 12:30:59 -07001731 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1732 /* Offline tests */
1733
1734 /* save speed, duplex, autoneg settings */
1735 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1736 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1737 autoneg = adapter->hw.mac.autoneg;
1738
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001739 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001740
Auke Kokbc7f75f2007-09-17 12:30:59 -07001741 if (if_running)
1742 /* indicate we're in test mode */
1743 dev_close(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001744
1745 if (e1000_reg_test(adapter, &data[0]))
1746 eth_test->flags |= ETH_TEST_FL_FAILED;
1747
1748 e1000e_reset(adapter);
1749 if (e1000_eeprom_test(adapter, &data[1]))
1750 eth_test->flags |= ETH_TEST_FL_FAILED;
1751
1752 e1000e_reset(adapter);
1753 if (e1000_intr_test(adapter, &data[2]))
1754 eth_test->flags |= ETH_TEST_FL_FAILED;
1755
1756 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001757 if (e1000_loopback_test(adapter, &data[3]))
1758 eth_test->flags |= ETH_TEST_FL_FAILED;
1759
Auke Kokbc7f75f2007-09-17 12:30:59 -07001760 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001761 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001762 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001763 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001764
Carolyn Wybornyc6ce3852010-10-15 17:35:31 +00001765 if (e1000_link_test(adapter, &data[4]))
1766 eth_test->flags |= ETH_TEST_FL_FAILED;
1767
1768 /* restore speed, duplex, autoneg settings */
1769 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1770 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1771 adapter->hw.mac.autoneg = autoneg;
1772 e1000e_reset(adapter);
1773
Auke Kokbc7f75f2007-09-17 12:30:59 -07001774 clear_bit(__E1000_TESTING, &adapter->state);
1775 if (if_running)
1776 dev_open(netdev);
1777 } else {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001778 /* Online tests */
Bruce Allan11b08be2010-05-10 14:59:31 +00001779
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001780 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001781
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001782 /* register, eeprom, intr and loopback tests not run online */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001783 data[0] = 0;
1784 data[1] = 0;
1785 data[2] = 0;
1786 data[3] = 0;
1787
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001788 if (e1000_link_test(adapter, &data[4]))
1789 eth_test->flags |= ETH_TEST_FL_FAILED;
Bruce Allan11b08be2010-05-10 14:59:31 +00001790
Auke Kokbc7f75f2007-09-17 12:30:59 -07001791 clear_bit(__E1000_TESTING, &adapter->state);
1792 }
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001793
1794 if (!if_running) {
1795 e1000e_reset(adapter);
1796
1797 if (adapter->flags & FLAG_HAS_AMT)
1798 e1000e_release_hw_control(adapter);
1799 }
1800
Auke Kokbc7f75f2007-09-17 12:30:59 -07001801 msleep_interruptible(4 * 1000);
1802}
1803
1804static void e1000_get_wol(struct net_device *netdev,
1805 struct ethtool_wolinfo *wol)
1806{
1807 struct e1000_adapter *adapter = netdev_priv(netdev);
1808
1809 wol->supported = 0;
1810 wol->wolopts = 0;
1811
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001812 if (!(adapter->flags & FLAG_HAS_WOL) ||
1813 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001814 return;
1815
1816 wol->supported = WAKE_UCAST | WAKE_MCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001817 WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001818
1819 /* apply any specific unsupported masks here */
1820 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1821 wol->supported &= ~WAKE_UCAST;
1822
1823 if (adapter->wol & E1000_WUFC_EX)
Bruce Allan6ad65142012-04-12 05:47:09 +00001824 e_err("Interface does not support directed (unicast) frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001825 }
1826
1827 if (adapter->wol & E1000_WUFC_EX)
1828 wol->wolopts |= WAKE_UCAST;
1829 if (adapter->wol & E1000_WUFC_MC)
1830 wol->wolopts |= WAKE_MCAST;
1831 if (adapter->wol & E1000_WUFC_BC)
1832 wol->wolopts |= WAKE_BCAST;
1833 if (adapter->wol & E1000_WUFC_MAG)
1834 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001835 if (adapter->wol & E1000_WUFC_LNKC)
1836 wol->wolopts |= WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001837}
1838
Bruce Allan4a29e152011-03-04 09:07:01 +00001839static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001840{
1841 struct e1000_adapter *adapter = netdev_priv(netdev);
1842
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001843 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001844 !device_can_wakeup(&adapter->pdev->dev) ||
1845 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001846 WAKE_MAGIC | WAKE_PHY)))
Bruce Allan1fbfca32009-11-20 23:22:01 +00001847 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001848
1849 /* these settings will always override what we currently have */
1850 adapter->wol = 0;
1851
1852 if (wol->wolopts & WAKE_UCAST)
1853 adapter->wol |= E1000_WUFC_EX;
1854 if (wol->wolopts & WAKE_MCAST)
1855 adapter->wol |= E1000_WUFC_MC;
1856 if (wol->wolopts & WAKE_BCAST)
1857 adapter->wol |= E1000_WUFC_BC;
1858 if (wol->wolopts & WAKE_MAGIC)
1859 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001860 if (wol->wolopts & WAKE_PHY)
1861 adapter->wol |= E1000_WUFC_LNKC;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001862
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001863 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1864
Auke Kokbc7f75f2007-09-17 12:30:59 -07001865 return 0;
1866}
1867
Bruce Allandbf80dc2011-04-16 00:34:40 +00001868static int e1000_set_phys_id(struct net_device *netdev,
1869 enum ethtool_phys_id_state state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001870{
1871 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001872 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001873
Bruce Allandbf80dc2011-04-16 00:34:40 +00001874 switch (state) {
1875 case ETHTOOL_ID_ACTIVE:
1876 if (!hw->mac.ops.blink_led)
1877 return 2; /* cycle on/off twice per second */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001878
Bruce Allandbf80dc2011-04-16 00:34:40 +00001879 hw->mac.ops.blink_led(hw);
1880 break;
1881
1882 case ETHTOOL_ID_INACTIVE:
Bruce Allan4662e822008-08-26 18:37:06 -07001883 if (hw->phy.type == e1000_phy_ife)
1884 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001885 hw->mac.ops.led_off(hw);
1886 hw->mac.ops.cleanup_led(hw);
1887 break;
1888
1889 case ETHTOOL_ID_ON:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001890 hw->mac.ops.led_on(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001891 break;
1892
1893 case ETHTOOL_ID_OFF:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001894 hw->mac.ops.led_off(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001895 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001896 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001897 return 0;
1898}
1899
Auke Kokde5b3072008-04-23 11:09:08 -07001900static int e1000_get_coalesce(struct net_device *netdev,
1901 struct ethtool_coalesce *ec)
1902{
1903 struct e1000_adapter *adapter = netdev_priv(netdev);
1904
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001905 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07001906 ec->rx_coalesce_usecs = adapter->itr_setting;
1907 else
1908 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1909
1910 return 0;
1911}
1912
1913static int e1000_set_coalesce(struct net_device *netdev,
1914 struct ethtool_coalesce *ec)
1915{
1916 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokde5b3072008-04-23 11:09:08 -07001917
1918 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001919 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07001920 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1921 (ec->rx_coalesce_usecs == 2))
1922 return -EINVAL;
1923
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001924 if (ec->rx_coalesce_usecs == 4) {
Bruce Allan06a402e2012-08-17 06:17:57 +00001925 adapter->itr_setting = 4;
1926 adapter->itr = adapter->itr_setting;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001927 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07001928 adapter->itr = 20000;
1929 adapter->itr_setting = ec->rx_coalesce_usecs;
1930 } else {
1931 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1932 adapter->itr_setting = adapter->itr & ~3;
1933 }
1934
1935 if (adapter->itr_setting != 0)
Matthew Vick22a4cca2012-07-12 00:02:42 +00001936 e1000e_write_itr(adapter, adapter->itr);
Auke Kokde5b3072008-04-23 11:09:08 -07001937 else
Matthew Vick22a4cca2012-07-12 00:02:42 +00001938 e1000e_write_itr(adapter, 0);
Auke Kokde5b3072008-04-23 11:09:08 -07001939
1940 return 0;
1941}
1942
Auke Kokbc7f75f2007-09-17 12:30:59 -07001943static int e1000_nway_reset(struct net_device *netdev)
1944{
1945 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan5962bc22011-01-20 06:58:07 +00001946
1947 if (!netif_running(netdev))
1948 return -EAGAIN;
1949
1950 if (!adapter->hw.mac.autoneg)
1951 return -EINVAL;
1952
1953 e1000e_reinit_locked(adapter);
1954
Auke Kokbc7f75f2007-09-17 12:30:59 -07001955 return 0;
1956}
1957
Auke Kokbc7f75f2007-09-17 12:30:59 -07001958static void e1000_get_ethtool_stats(struct net_device *netdev,
1959 struct ethtool_stats *stats,
1960 u64 *data)
1961{
1962 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001963 struct rtnl_link_stats64 net_stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001964 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001965 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001966
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001967 e1000e_get_stats64(netdev, &net_stats);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001968 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001969 switch (e1000_gstrings_stats[i].type) {
1970 case NETDEV_STATS:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001971 p = (char *) &net_stats +
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001972 e1000_gstrings_stats[i].stat_offset;
1973 break;
1974 case E1000_STATS:
1975 p = (char *) adapter +
1976 e1000_gstrings_stats[i].stat_offset;
1977 break;
Bruce Allan61c75812010-12-09 23:04:25 +00001978 default:
1979 data[i] = 0;
1980 continue;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001981 }
1982
Auke Kokbc7f75f2007-09-17 12:30:59 -07001983 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1984 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1985 }
1986}
1987
1988static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1989 u8 *data)
1990{
1991 u8 *p = data;
1992 int i;
1993
1994 switch (stringset) {
1995 case ETH_SS_TEST:
Bruce Allan5c1bda02011-01-19 04:23:39 +00001996 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001997 break;
1998 case ETH_SS_STATS:
1999 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
2000 memcpy(p, e1000_gstrings_stats[i].stat_string,
2001 ETH_GSTRING_LEN);
2002 p += ETH_GSTRING_LEN;
2003 }
2004 break;
2005 }
2006}
2007
Bruce Allan70495a52012-01-11 01:26:50 +00002008static int e1000_get_rxnfc(struct net_device *netdev,
2009 struct ethtool_rxnfc *info, u32 *rule_locs)
2010{
2011 info->data = 0;
2012
2013 switch (info->cmd) {
2014 case ETHTOOL_GRXFH: {
2015 struct e1000_adapter *adapter = netdev_priv(netdev);
2016 struct e1000_hw *hw = &adapter->hw;
2017 u32 mrqc = er32(MRQC);
2018
2019 if (!(mrqc & E1000_MRQC_RSS_FIELD_MASK))
2020 return 0;
2021
2022 switch (info->flow_type) {
2023 case TCP_V4_FLOW:
2024 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP)
2025 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2026 /* fall through */
2027 case UDP_V4_FLOW:
2028 case SCTP_V4_FLOW:
2029 case AH_ESP_V4_FLOW:
2030 case IPV4_FLOW:
2031 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4)
2032 info->data |= RXH_IP_SRC | RXH_IP_DST;
2033 break;
2034 case TCP_V6_FLOW:
2035 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP)
2036 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2037 /* fall through */
2038 case UDP_V6_FLOW:
2039 case SCTP_V6_FLOW:
2040 case AH_ESP_V6_FLOW:
2041 case IPV6_FLOW:
2042 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6)
2043 info->data |= RXH_IP_SRC | RXH_IP_DST;
2044 break;
2045 default:
2046 break;
2047 }
2048 return 0;
2049 }
2050 default:
2051 return -EOPNOTSUPP;
2052 }
2053}
2054
Bruce Allan203e4152012-12-05 08:40:59 +00002055static int e1000e_get_eee(struct net_device *netdev, struct ethtool_eee *edata)
2056{
2057 struct e1000_adapter *adapter = netdev_priv(netdev);
2058 struct e1000_hw *hw = &adapter->hw;
2059 u16 cap_addr, adv_addr, lpa_addr, pcs_stat_addr, phy_data, lpi_ctrl;
2060 u32 status, ret_val;
2061
2062 if (!(adapter->flags & FLAG_IS_ICH) ||
2063 !(adapter->flags2 & FLAG2_HAS_EEE))
2064 return -EOPNOTSUPP;
2065
2066 switch (hw->phy.type) {
2067 case e1000_phy_82579:
2068 cap_addr = I82579_EEE_CAPABILITY;
2069 adv_addr = I82579_EEE_ADVERTISEMENT;
2070 lpa_addr = I82579_EEE_LP_ABILITY;
2071 pcs_stat_addr = I82579_EEE_PCS_STATUS;
2072 break;
2073 case e1000_phy_i217:
2074 cap_addr = I217_EEE_CAPABILITY;
2075 adv_addr = I217_EEE_ADVERTISEMENT;
2076 lpa_addr = I217_EEE_LP_ABILITY;
2077 pcs_stat_addr = I217_EEE_PCS_STATUS;
2078 break;
2079 default:
2080 return -EOPNOTSUPP;
2081 }
2082
2083 ret_val = hw->phy.ops.acquire(hw);
2084 if (ret_val)
2085 return -EBUSY;
2086
2087 /* EEE Capability */
2088 ret_val = e1000_read_emi_reg_locked(hw, cap_addr, &phy_data);
2089 if (ret_val)
2090 goto release;
2091 edata->supported = mmd_eee_cap_to_ethtool_sup_t(phy_data);
2092
2093 /* EEE Advertised */
2094 ret_val = e1000_read_emi_reg_locked(hw, adv_addr, &phy_data);
2095 if (ret_val)
2096 goto release;
2097 edata->advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
2098
2099 /* EEE Link Partner Advertised */
2100 ret_val = e1000_read_emi_reg_locked(hw, lpa_addr, &phy_data);
2101 if (ret_val)
2102 goto release;
2103 edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
2104
2105 /* EEE PCS Status */
2106 ret_val = e1000_read_emi_reg_locked(hw, pcs_stat_addr, &phy_data);
2107 if (hw->phy.type == e1000_phy_82579)
2108 phy_data <<= 8;
2109
2110release:
2111 hw->phy.ops.release(hw);
2112 if (ret_val)
2113 return -ENODATA;
2114
2115 e1e_rphy(hw, I82579_LPI_CTRL, &lpi_ctrl);
2116 status = er32(STATUS);
2117
2118 /* Result of the EEE auto negotiation - there is no register that
2119 * has the status of the EEE negotiation so do a best-guess based
2120 * on whether both Tx and Rx LPI indications have been received or
2121 * base it on the link speed, the EEE advertised speeds on both ends
2122 * and the speeds on which EEE is enabled locally.
2123 */
2124 if (((phy_data & E1000_EEE_TX_LPI_RCVD) &&
2125 (phy_data & E1000_EEE_RX_LPI_RCVD)) ||
2126 ((status & E1000_STATUS_SPEED_100) &&
2127 (edata->advertised & ADVERTISED_100baseT_Full) &&
2128 (edata->lp_advertised & ADVERTISED_100baseT_Full) &&
2129 (lpi_ctrl & I82579_LPI_CTRL_100_ENABLE)) ||
2130 ((status & E1000_STATUS_SPEED_1000) &&
2131 (edata->advertised & ADVERTISED_1000baseT_Full) &&
2132 (edata->lp_advertised & ADVERTISED_1000baseT_Full) &&
2133 (lpi_ctrl & I82579_LPI_CTRL_1000_ENABLE)))
2134 edata->eee_active = true;
2135
2136 edata->eee_enabled = !hw->dev_spec.ich8lan.eee_disable;
2137 edata->tx_lpi_enabled = true;
2138 edata->tx_lpi_timer = er32(LPIC) >> E1000_LPIC_LPIET_SHIFT;
2139
2140 return 0;
2141}
2142
2143static int e1000e_set_eee(struct net_device *netdev, struct ethtool_eee *edata)
2144{
2145 struct e1000_adapter *adapter = netdev_priv(netdev);
2146 struct e1000_hw *hw = &adapter->hw;
2147 struct ethtool_eee eee_curr;
2148 s32 ret_val;
2149
2150 if (!(adapter->flags & FLAG_IS_ICH) ||
2151 !(adapter->flags2 & FLAG2_HAS_EEE))
2152 return -EOPNOTSUPP;
2153
2154 ret_val = e1000e_get_eee(netdev, &eee_curr);
2155 if (ret_val)
2156 return ret_val;
2157
2158 if (eee_curr.advertised != edata->advertised) {
2159 e_err("Setting EEE advertisement is not supported\n");
2160 return -EINVAL;
2161 }
2162
2163 if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
2164 e_err("Setting EEE tx-lpi is not supported\n");
2165 return -EINVAL;
2166 }
2167
2168 if (eee_curr.tx_lpi_timer != edata->tx_lpi_timer) {
2169 e_err("Setting EEE Tx LPI timer is not supported\n");
2170 return -EINVAL;
2171 }
2172
2173 if (hw->dev_spec.ich8lan.eee_disable != !edata->eee_enabled) {
2174 hw->dev_spec.ich8lan.eee_disable = !edata->eee_enabled;
2175
2176 /* reset the link */
2177 if (netif_running(netdev))
2178 e1000e_reinit_locked(adapter);
2179 else
2180 e1000e_reset(adapter);
2181 }
2182
2183 return 0;
2184}
2185
Bruce Allanb67e1912012-12-27 08:32:33 +00002186static int e1000e_get_ts_info(struct net_device *netdev,
2187 struct ethtool_ts_info *info)
2188{
2189 struct e1000_adapter *adapter = netdev_priv(netdev);
2190
2191 ethtool_op_get_ts_info(netdev, info);
2192
2193 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
2194 return 0;
2195
2196 info->so_timestamping |= (SOF_TIMESTAMPING_TX_HARDWARE |
2197 SOF_TIMESTAMPING_RX_HARDWARE |
2198 SOF_TIMESTAMPING_RAW_HARDWARE);
2199
2200 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
2201
2202 info->rx_filters = ((1 << HWTSTAMP_FILTER_NONE) |
2203 (1 << HWTSTAMP_FILTER_ALL));
2204
2205 return 0;
2206}
2207
Auke Kokbc7f75f2007-09-17 12:30:59 -07002208static const struct ethtool_ops e1000_ethtool_ops = {
2209 .get_settings = e1000_get_settings,
2210 .set_settings = e1000_set_settings,
2211 .get_drvinfo = e1000_get_drvinfo,
2212 .get_regs_len = e1000_get_regs_len,
2213 .get_regs = e1000_get_regs,
2214 .get_wol = e1000_get_wol,
2215 .set_wol = e1000_set_wol,
2216 .get_msglevel = e1000_get_msglevel,
2217 .set_msglevel = e1000_set_msglevel,
2218 .nway_reset = e1000_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00002219 .get_link = ethtool_op_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002220 .get_eeprom_len = e1000_get_eeprom_len,
2221 .get_eeprom = e1000_get_eeprom,
2222 .set_eeprom = e1000_set_eeprom,
2223 .get_ringparam = e1000_get_ringparam,
2224 .set_ringparam = e1000_set_ringparam,
2225 .get_pauseparam = e1000_get_pauseparam,
2226 .set_pauseparam = e1000_set_pauseparam,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002227 .self_test = e1000_diag_test,
2228 .get_strings = e1000_get_strings,
Bruce Allandbf80dc2011-04-16 00:34:40 +00002229 .set_phys_id = e1000_set_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002230 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07002231 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07002232 .get_coalesce = e1000_get_coalesce,
2233 .set_coalesce = e1000_set_coalesce,
Bruce Allan70495a52012-01-11 01:26:50 +00002234 .get_rxnfc = e1000_get_rxnfc,
Bruce Allanb67e1912012-12-27 08:32:33 +00002235 .get_ts_info = e1000e_get_ts_info,
Bruce Allan203e4152012-12-05 08:40:59 +00002236 .get_eee = e1000e_get_eee,
2237 .set_eee = e1000e_set_eee,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002238};
2239
2240void e1000e_set_ethtool_ops(struct net_device *netdev)
2241{
2242 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
2243}