blob: 2c1813737f6d2562189065d945a5002750d8e10c [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 Allan203e41512012-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 ecmd->supported = (SUPPORTED_10baseT_Half |
134 SUPPORTED_10baseT_Full |
135 SUPPORTED_100baseT_Half |
136 SUPPORTED_100baseT_Full |
137 SUPPORTED_1000baseT_Full |
138 SUPPORTED_Autoneg |
139 SUPPORTED_TP);
140 if (hw->phy.type == e1000_phy_ife)
141 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
142 ecmd->advertising = ADVERTISED_TP;
143
144 if (hw->mac.autoneg == 1) {
145 ecmd->advertising |= ADVERTISED_Autoneg;
146 /* the e1000 autoneg seems to match ethtool nicely */
147 ecmd->advertising |= hw->phy.autoneg_advertised;
148 }
149
150 ecmd->port = PORT_TP;
151 ecmd->phy_address = hw->phy.addr;
152 ecmd->transceiver = XCVR_INTERNAL;
153
154 } else {
155 ecmd->supported = (SUPPORTED_1000baseT_Full |
156 SUPPORTED_FIBRE |
157 SUPPORTED_Autoneg);
158
159 ecmd->advertising = (ADVERTISED_1000baseT_Full |
160 ADVERTISED_FIBRE |
161 ADVERTISED_Autoneg);
162
163 ecmd->port = PORT_FIBRE;
164 ecmd->transceiver = XCVR_EXTERNAL;
165 }
166
David Decotigny70739492011-04-27 18:32:40 +0000167 speed = -1;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000168 ecmd->duplex = -1;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700169
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000170 if (netif_running(netdev)) {
171 if (netif_carrier_ok(netdev)) {
David Decotigny70739492011-04-27 18:32:40 +0000172 speed = adapter->link_speed;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000173 ecmd->duplex = adapter->link_duplex - 1;
174 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700175 } else {
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000176 u32 status = er32(STATUS);
177 if (status & E1000_STATUS_LU) {
178 if (status & E1000_STATUS_SPEED_1000)
David Decotigny70739492011-04-27 18:32:40 +0000179 speed = SPEED_1000;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000180 else if (status & E1000_STATUS_SPEED_100)
David Decotigny70739492011-04-27 18:32:40 +0000181 speed = SPEED_100;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000182 else
David Decotigny70739492011-04-27 18:32:40 +0000183 speed = SPEED_10;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000184
185 if (status & E1000_STATUS_FD)
186 ecmd->duplex = DUPLEX_FULL;
187 else
188 ecmd->duplex = DUPLEX_HALF;
189 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700190 }
191
David Decotigny70739492011-04-27 18:32:40 +0000192 ethtool_cmd_speed_set(ecmd, speed);
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700193 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -0700194 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000195
196 /* MDI-X => 2; MDI =>1; Invalid =>0 */
197 if ((hw->phy.media_type == e1000_media_type_copper) &&
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000198 netif_carrier_ok(netdev))
Chaitanya Lala18760f12009-06-08 14:28:54 +0000199 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
200 ETH_TP_MDI;
201 else
202 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
203
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000204 if (hw->phy.mdix == AUTO_ALL_MODES)
205 ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
206 else
207 ecmd->eth_tp_mdix_ctrl = hw->phy.mdix;
208
Auke Kokbc7f75f2007-09-17 12:30:59 -0700209 return 0;
210}
211
David Decotigny14ad2512011-04-27 18:32:43 +0000212static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700213{
214 struct e1000_mac_info *mac = &adapter->hw.mac;
215
216 mac->autoneg = 0;
217
David Decotigny14ad2512011-04-27 18:32:43 +0000218 /* Make sure dplx is at most 1 bit and lsb of speed is not set
Bruce Allane921eb12012-11-28 09:28:37 +0000219 * for the switch() below to work
220 */
David Decotigny14ad2512011-04-27 18:32:43 +0000221 if ((spd & 1) || (dplx & ~1))
222 goto err_inval;
223
Auke Kokbc7f75f2007-09-17 12:30:59 -0700224 /* Fiber NICs only allow 1000 gbps Full duplex */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700225 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
David Decotigny14ad2512011-04-27 18:32:43 +0000226 spd != SPEED_1000 &&
227 dplx != DUPLEX_FULL) {
228 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700229 }
230
David Decotigny14ad2512011-04-27 18:32:43 +0000231 switch (spd + dplx) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700232 case SPEED_10 + DUPLEX_HALF:
233 mac->forced_speed_duplex = ADVERTISE_10_HALF;
234 break;
235 case SPEED_10 + DUPLEX_FULL:
236 mac->forced_speed_duplex = ADVERTISE_10_FULL;
237 break;
238 case SPEED_100 + DUPLEX_HALF:
239 mac->forced_speed_duplex = ADVERTISE_100_HALF;
240 break;
241 case SPEED_100 + DUPLEX_FULL:
242 mac->forced_speed_duplex = ADVERTISE_100_FULL;
243 break;
244 case SPEED_1000 + DUPLEX_FULL:
245 mac->autoneg = 1;
246 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
247 break;
248 case SPEED_1000 + DUPLEX_HALF: /* not supported */
249 default:
David Decotigny14ad2512011-04-27 18:32:43 +0000250 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700251 }
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000252
253 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
254 adapter->hw.phy.mdix = AUTO_ALL_MODES;
255
Auke Kokbc7f75f2007-09-17 12:30:59 -0700256 return 0;
David Decotigny14ad2512011-04-27 18:32:43 +0000257
258err_inval:
259 e_err("Unsupported Speed/Duplex configuration\n");
260 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700261}
262
263static int e1000_set_settings(struct net_device *netdev,
264 struct ethtool_cmd *ecmd)
265{
266 struct e1000_adapter *adapter = netdev_priv(netdev);
267 struct e1000_hw *hw = &adapter->hw;
268
Bruce Allane921eb12012-11-28 09:28:37 +0000269 /* When SoL/IDER sessions are active, autoneg/speed/duplex
Bruce Allanad680762008-03-28 09:15:03 -0700270 * cannot be changed
271 */
Bruce Allan470a5422012-05-26 06:08:48 +0000272 if (hw->phy.ops.check_reset_block &&
273 hw->phy.ops.check_reset_block(hw)) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000274 e_err("Cannot change link characteristics when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700275 return -EINVAL;
276 }
277
Bruce Allane921eb12012-11-28 09:28:37 +0000278 /* MDI setting is only allowed when autoneg enabled because
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000279 * some hardware doesn't allow MDI setting when speed or
280 * duplex is forced.
281 */
282 if (ecmd->eth_tp_mdix_ctrl) {
283 if (hw->phy.media_type != e1000_media_type_copper)
284 return -EOPNOTSUPP;
285
286 if ((ecmd->eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) &&
287 (ecmd->autoneg != AUTONEG_ENABLE)) {
288 e_err("forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
289 return -EINVAL;
290 }
291 }
292
Auke Kokbc7f75f2007-09-17 12:30:59 -0700293 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000294 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700295
296 if (ecmd->autoneg == AUTONEG_ENABLE) {
297 hw->mac.autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700298 if (hw->phy.media_type == e1000_media_type_fiber)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700299 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
300 ADVERTISED_FIBRE |
301 ADVERTISED_Autoneg;
302 else
303 hw->phy.autoneg_advertised = ecmd->advertising |
304 ADVERTISED_TP |
305 ADVERTISED_Autoneg;
306 ecmd->advertising = hw->phy.autoneg_advertised;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700307 if (adapter->fc_autoneg)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800308 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700309 } else {
David Decotigny25db0332011-04-27 18:32:39 +0000310 u32 speed = ethtool_cmd_speed(ecmd);
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000311 /* calling this overrides forced MDI setting */
David Decotigny14ad2512011-04-27 18:32:43 +0000312 if (e1000_set_spd_dplx(adapter, speed, ecmd->duplex)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700313 clear_bit(__E1000_RESETTING, &adapter->state);
314 return -EINVAL;
315 }
316 }
317
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000318 /* MDI-X => 2; MDI => 1; Auto => 3 */
319 if (ecmd->eth_tp_mdix_ctrl) {
Bruce Allane921eb12012-11-28 09:28:37 +0000320 /* fix up the value for auto (3 => 0) as zero is mapped
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000321 * internally to auto
322 */
323 if (ecmd->eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
324 hw->phy.mdix = AUTO_ALL_MODES;
325 else
326 hw->phy.mdix = ecmd->eth_tp_mdix_ctrl;
327 }
328
Auke Kokbc7f75f2007-09-17 12:30:59 -0700329 /* reset the link */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700330 if (netif_running(adapter->netdev)) {
331 e1000e_down(adapter);
332 e1000e_up(adapter);
Bruce Allana7a1d9d2013-01-24 00:50:18 +0000333 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700334 e1000e_reset(adapter);
Bruce Allana7a1d9d2013-01-24 00:50:18 +0000335 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700336
337 clear_bit(__E1000_RESETTING, &adapter->state);
338 return 0;
339}
340
341static void e1000_get_pauseparam(struct net_device *netdev,
342 struct ethtool_pauseparam *pause)
343{
344 struct e1000_adapter *adapter = netdev_priv(netdev);
345 struct e1000_hw *hw = &adapter->hw;
346
347 pause->autoneg =
348 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
349
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800350 if (hw->fc.current_mode == e1000_fc_rx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700351 pause->rx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800352 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700353 pause->tx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800354 } else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700355 pause->rx_pause = 1;
356 pause->tx_pause = 1;
357 }
358}
359
360static int e1000_set_pauseparam(struct net_device *netdev,
361 struct ethtool_pauseparam *pause)
362{
363 struct e1000_adapter *adapter = netdev_priv(netdev);
364 struct e1000_hw *hw = &adapter->hw;
365 int retval = 0;
366
367 adapter->fc_autoneg = pause->autoneg;
368
369 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000370 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700371
Auke Kokbc7f75f2007-09-17 12:30:59 -0700372 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800373 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700374 if (netif_running(adapter->netdev)) {
375 e1000e_down(adapter);
376 e1000e_up(adapter);
377 } else {
378 e1000e_reset(adapter);
379 }
380 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800381 if (pause->rx_pause && pause->tx_pause)
382 hw->fc.requested_mode = e1000_fc_full;
383 else if (pause->rx_pause && !pause->tx_pause)
384 hw->fc.requested_mode = e1000_fc_rx_pause;
385 else if (!pause->rx_pause && pause->tx_pause)
386 hw->fc.requested_mode = e1000_fc_tx_pause;
387 else if (!pause->rx_pause && !pause->tx_pause)
388 hw->fc.requested_mode = e1000_fc_none;
389
390 hw->fc.current_mode = hw->fc.requested_mode;
391
Bruce Allan945eb312009-10-28 18:28:30 +0000392 if (hw->phy.media_type == e1000_media_type_fiber) {
393 retval = hw->mac.ops.setup_link(hw);
394 /* implicit goto out */
395 } else {
396 retval = e1000e_force_mac_fc(hw);
397 if (retval)
398 goto out;
399 e1000e_set_fc_watermarks(hw);
400 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700401 }
402
Bruce Allan945eb312009-10-28 18:28:30 +0000403out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700404 clear_bit(__E1000_RESETTING, &adapter->state);
405 return retval;
406}
407
Auke Kokbc7f75f2007-09-17 12:30:59 -0700408static u32 e1000_get_msglevel(struct net_device *netdev)
409{
410 struct e1000_adapter *adapter = netdev_priv(netdev);
411 return adapter->msg_enable;
412}
413
414static void e1000_set_msglevel(struct net_device *netdev, u32 data)
415{
416 struct e1000_adapter *adapter = netdev_priv(netdev);
417 adapter->msg_enable = data;
418}
419
Bruce Allan8bb62862013-01-16 08:46:49 +0000420static int e1000_get_regs_len(struct net_device __always_unused *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700421{
422#define E1000_REGS_LEN 32 /* overestimate */
423 return E1000_REGS_LEN * sizeof(u32);
424}
425
426static void e1000_get_regs(struct net_device *netdev,
427 struct ethtool_regs *regs, void *p)
428{
429 struct e1000_adapter *adapter = netdev_priv(netdev);
430 struct e1000_hw *hw = &adapter->hw;
431 u32 *regs_buff = p;
432 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700433
434 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
435
Sergei Shtylyovff938e42011-02-28 11:57:33 -0800436 regs->version = (1 << 24) | (adapter->pdev->revision << 16) |
437 adapter->pdev->device;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700438
439 regs_buff[0] = er32(CTRL);
440 regs_buff[1] = er32(STATUS);
441
442 regs_buff[2] = er32(RCTL);
Bruce Allan1e360522012-03-20 03:48:13 +0000443 regs_buff[3] = er32(RDLEN(0));
444 regs_buff[4] = er32(RDH(0));
445 regs_buff[5] = er32(RDT(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700446 regs_buff[6] = er32(RDTR);
447
448 regs_buff[7] = er32(TCTL);
Bruce Allan1e360522012-03-20 03:48:13 +0000449 regs_buff[8] = er32(TDLEN(0));
450 regs_buff[9] = er32(TDH(0));
451 regs_buff[10] = er32(TDT(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700452 regs_buff[11] = er32(TIDV);
453
454 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700455
456 /* ethtool doesn't use anything past this point, so all this
Bruce Allane921eb12012-11-28 09:28:37 +0000457 * code is likely legacy junk for apps that may or may not exist
458 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700459 if (hw->phy.type == e1000_phy_m88) {
460 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
461 regs_buff[13] = (u32)phy_data; /* cable length */
462 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
463 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
464 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
465 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
466 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
467 regs_buff[18] = regs_buff[13]; /* cable polarity */
468 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
469 regs_buff[20] = regs_buff[17]; /* polarity correction */
470 /* phy receive errors */
471 regs_buff[22] = adapter->phy_stats.receive_errors;
472 regs_buff[23] = regs_buff[13]; /* mdix mode */
473 }
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000474 regs_buff[21] = 0; /* was idle_errors */
475 e1e_rphy(hw, MII_STAT1000, &phy_data);
476 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
477 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700478}
479
480static int e1000_get_eeprom_len(struct net_device *netdev)
481{
482 struct e1000_adapter *adapter = netdev_priv(netdev);
483 return adapter->hw.nvm.word_size * 2;
484}
485
486static int e1000_get_eeprom(struct net_device *netdev,
487 struct ethtool_eeprom *eeprom, u8 *bytes)
488{
489 struct e1000_adapter *adapter = netdev_priv(netdev);
490 struct e1000_hw *hw = &adapter->hw;
491 u16 *eeprom_buff;
492 int first_word;
493 int last_word;
494 int ret_val = 0;
495 u16 i;
496
497 if (eeprom->len == 0)
498 return -EINVAL;
499
500 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
501
502 first_word = eeprom->offset >> 1;
503 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
504
505 eeprom_buff = kmalloc(sizeof(u16) *
506 (last_word - first_word + 1), GFP_KERNEL);
507 if (!eeprom_buff)
508 return -ENOMEM;
509
510 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
511 ret_val = e1000_read_nvm(hw, first_word,
512 last_word - first_word + 1,
513 eeprom_buff);
514 } else {
515 for (i = 0; i < last_word - first_word + 1; i++) {
516 ret_val = e1000_read_nvm(hw, first_word + i, 1,
517 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800518 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700519 break;
520 }
521 }
522
Bruce Allane2434552008-11-21 17:02:41 -0800523 if (ret_val) {
524 /* a read error occurred, throw away the result */
Roel Kluin8528b012009-12-01 15:54:24 +0000525 memset(eeprom_buff, 0xff, sizeof(u16) *
526 (last_word - first_word + 1));
Bruce Allane2434552008-11-21 17:02:41 -0800527 } else {
528 /* Device's eeprom is always little-endian, word addressable */
529 for (i = 0; i < last_word - first_word + 1; i++)
530 le16_to_cpus(&eeprom_buff[i]);
531 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700532
533 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
534 kfree(eeprom_buff);
535
536 return ret_val;
537}
538
539static int e1000_set_eeprom(struct net_device *netdev,
540 struct ethtool_eeprom *eeprom, u8 *bytes)
541{
542 struct e1000_adapter *adapter = netdev_priv(netdev);
543 struct e1000_hw *hw = &adapter->hw;
544 u16 *eeprom_buff;
545 void *ptr;
546 int max_len;
547 int first_word;
548 int last_word;
549 int ret_val = 0;
550 u16 i;
551
552 if (eeprom->len == 0)
553 return -EOPNOTSUPP;
554
555 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
556 return -EFAULT;
557
Bruce Allan4a770352008-10-01 17:18:35 -0700558 if (adapter->flags & FLAG_READ_ONLY_NVM)
559 return -EINVAL;
560
Auke Kokbc7f75f2007-09-17 12:30:59 -0700561 max_len = hw->nvm.word_size * 2;
562
563 first_word = eeprom->offset >> 1;
564 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
565 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
566 if (!eeprom_buff)
567 return -ENOMEM;
568
569 ptr = (void *)eeprom_buff;
570
571 if (eeprom->offset & 1) {
572 /* need read/modify/write of first changed EEPROM word */
573 /* only the second byte of the word is being modified */
574 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
575 ptr++;
576 }
Bruce Allan9e2d7652012-01-31 06:37:27 +0000577 if (((eeprom->offset + eeprom->len) & 1) && (!ret_val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700578 /* need read/modify/write of last changed EEPROM word */
579 /* only the first byte of the word is being modified */
580 ret_val = e1000_read_nvm(hw, last_word, 1,
581 &eeprom_buff[last_word - first_word]);
582
Bruce Allane2434552008-11-21 17:02:41 -0800583 if (ret_val)
584 goto out;
585
Auke Kokbc7f75f2007-09-17 12:30:59 -0700586 /* Device's eeprom is always little-endian, word addressable */
587 for (i = 0; i < last_word - first_word + 1; i++)
588 le16_to_cpus(&eeprom_buff[i]);
589
590 memcpy(ptr, bytes, eeprom->len);
591
592 for (i = 0; i < last_word - first_word + 1; i++)
Bruce Allane885d762012-01-31 06:37:32 +0000593 cpu_to_le16s(&eeprom_buff[i]);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700594
595 ret_val = e1000_write_nvm(hw, first_word,
596 last_word - first_word + 1, eeprom_buff);
597
Bruce Allane2434552008-11-21 17:02:41 -0800598 if (ret_val)
599 goto out;
600
Bruce Allane921eb12012-11-28 09:28:37 +0000601 /* Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800602 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700603 */
Bruce Allane2434552008-11-21 17:02:41 -0800604 if ((first_word <= NVM_CHECKSUM_REG) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +0000605 (hw->mac.type == e1000_82583) ||
606 (hw->mac.type == e1000_82574) ||
607 (hw->mac.type == e1000_82573))
Bruce Allane2434552008-11-21 17:02:41 -0800608 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700609
Bruce Allane2434552008-11-21 17:02:41 -0800610out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700611 kfree(eeprom_buff);
612 return ret_val;
613}
614
615static void e1000_get_drvinfo(struct net_device *netdev,
616 struct ethtool_drvinfo *drvinfo)
617{
618 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700619
Rick Jones612a94d2011-11-14 08:13:25 +0000620 strlcpy(drvinfo->driver, e1000e_driver_name,
621 sizeof(drvinfo->driver));
Rick Jones33a5ba12011-11-15 14:59:53 +0000622 strlcpy(drvinfo->version, e1000e_driver_version,
Rick Jones612a94d2011-11-14 08:13:25 +0000623 sizeof(drvinfo->version));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700624
Bruce Allane921eb12012-11-28 09:28:37 +0000625 /* EEPROM image version # is reported as firmware version # for
Bruce Allanad680762008-03-28 09:15:03 -0700626 * PCI-E controllers
627 */
Rick Jones612a94d2011-11-14 08:13:25 +0000628 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
629 "%d.%d-%d",
Bruce Allan84527592008-11-21 17:00:22 -0800630 (adapter->eeprom_vers & 0xF000) >> 12,
631 (adapter->eeprom_vers & 0x0FF0) >> 4,
632 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700633
Rick Jones612a94d2011-11-14 08:13:25 +0000634 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
635 sizeof(drvinfo->bus_info));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700636 drvinfo->regdump_len = e1000_get_regs_len(netdev);
637 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
638}
639
640static void e1000_get_ringparam(struct net_device *netdev,
641 struct ethtool_ringparam *ring)
642{
643 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700644
645 ring->rx_max_pending = E1000_MAX_RXD;
646 ring->tx_max_pending = E1000_MAX_TXD;
Bruce Allan508da422011-12-16 00:45:51 +0000647 ring->rx_pending = adapter->rx_ring_count;
648 ring->tx_pending = adapter->tx_ring_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700649}
650
651static int e1000_set_ringparam(struct net_device *netdev,
652 struct ethtool_ringparam *ring)
653{
654 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan508da422011-12-16 00:45:51 +0000655 struct e1000_ring *temp_tx = NULL, *temp_rx = NULL;
656 int err = 0, size = sizeof(struct e1000_ring);
657 bool set_tx = false, set_rx = false;
658 u16 new_rx_count, new_tx_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700659
660 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
661 return -EINVAL;
662
Bruce Allan508da422011-12-16 00:45:51 +0000663 new_rx_count = clamp_t(u32, ring->rx_pending, E1000_MIN_RXD,
664 E1000_MAX_RXD);
665 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
666
667 new_tx_count = clamp_t(u32, ring->tx_pending, E1000_MIN_TXD,
668 E1000_MAX_TXD);
669 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
670
671 if ((new_tx_count == adapter->tx_ring_count) &&
672 (new_rx_count == adapter->rx_ring_count))
673 /* nothing to do */
674 return 0;
675
Auke Kokbc7f75f2007-09-17 12:30:59 -0700676 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000677 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700678
Bruce Allan508da422011-12-16 00:45:51 +0000679 if (!netif_running(adapter->netdev)) {
680 /* Set counts now and allocate resources during open() */
681 adapter->tx_ring->count = new_tx_count;
682 adapter->rx_ring->count = new_rx_count;
683 adapter->tx_ring_count = new_tx_count;
684 adapter->rx_ring_count = new_rx_count;
685 goto clear_reset;
686 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700687
Bruce Allan508da422011-12-16 00:45:51 +0000688 set_tx = (new_tx_count != adapter->tx_ring_count);
689 set_rx = (new_rx_count != adapter->rx_ring_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700690
Bruce Allan508da422011-12-16 00:45:51 +0000691 /* Allocate temporary storage for ring updates */
692 if (set_tx) {
693 temp_tx = vmalloc(size);
694 if (!temp_tx) {
695 err = -ENOMEM;
696 goto free_temp;
697 }
698 }
699 if (set_rx) {
700 temp_rx = vmalloc(size);
701 if (!temp_rx) {
702 err = -ENOMEM;
703 goto free_temp;
704 }
705 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700706
Bruce Allan508da422011-12-16 00:45:51 +0000707 e1000e_down(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700708
Bruce Allane921eb12012-11-28 09:28:37 +0000709 /* We can't just free everything and then setup again, because the
Bruce Allan508da422011-12-16 00:45:51 +0000710 * ISRs in MSI-X mode get passed pointers to the Tx and Rx ring
711 * structs. First, attempt to allocate new resources...
712 */
713 if (set_tx) {
714 memcpy(temp_tx, adapter->tx_ring, size);
715 temp_tx->count = new_tx_count;
716 err = e1000e_setup_tx_resources(temp_tx);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700717 if (err)
718 goto err_setup;
719 }
Bruce Allan508da422011-12-16 00:45:51 +0000720 if (set_rx) {
721 memcpy(temp_rx, adapter->rx_ring, size);
722 temp_rx->count = new_rx_count;
723 err = e1000e_setup_rx_resources(temp_rx);
724 if (err)
725 goto err_setup_rx;
726 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700727
Bruce Allan508da422011-12-16 00:45:51 +0000728 /* ...then free the old resources and copy back any new ring data */
729 if (set_tx) {
730 e1000e_free_tx_resources(adapter->tx_ring);
731 memcpy(adapter->tx_ring, temp_tx, size);
732 adapter->tx_ring_count = new_tx_count;
733 }
734 if (set_rx) {
735 e1000e_free_rx_resources(adapter->rx_ring);
736 memcpy(adapter->rx_ring, temp_rx, size);
737 adapter->rx_ring_count = new_rx_count;
738 }
739
Auke Kokbc7f75f2007-09-17 12:30:59 -0700740err_setup_rx:
Bruce Allan508da422011-12-16 00:45:51 +0000741 if (err && set_tx)
742 e1000e_free_tx_resources(temp_tx);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700743err_setup:
Bruce Allan508da422011-12-16 00:45:51 +0000744 e1000e_up(adapter);
745free_temp:
746 vfree(temp_tx);
747 vfree(temp_rx);
748clear_reset:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700749 clear_bit(__E1000_RESETTING, &adapter->state);
750 return err;
751}
752
Bruce Allancef8c792008-04-02 13:48:23 -0700753static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
754 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800755{
Bruce Allancef8c792008-04-02 13:48:23 -0700756 u32 pat, val;
Bruce Allan64806412010-12-11 05:53:42 +0000757 static const u32 test[] = {
758 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Bruce Allancef8c792008-04-02 13:48:23 -0700759 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800760 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700761 (test[pat] & write));
762 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
763 if (val != (test[pat] & write & mask)) {
Bruce Allana8fc1892012-12-05 06:25:36 +0000764 e_err("pattern test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
765 reg + (offset << 2), val,
766 (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800767 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700768 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800769 }
770 }
Bruce Allancef8c792008-04-02 13:48:23 -0700771 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700772}
773
Joe Perches2a887192007-11-13 20:53:51 -0800774static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
775 int reg, u32 mask, u32 write)
776{
Bruce Allancef8c792008-04-02 13:48:23 -0700777 u32 val;
Joe Perches2a887192007-11-13 20:53:51 -0800778 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700779 val = __er32(&adapter->hw, reg);
780 if ((write & mask) != (val & mask)) {
Bruce Allana8fc1892012-12-05 06:25:36 +0000781 e_err("set/check test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
Bruce Allan6ad65142012-04-12 05:47:09 +0000782 reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800783 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700784 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800785 }
Bruce Allancef8c792008-04-02 13:48:23 -0700786 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700787}
Bruce Allancef8c792008-04-02 13:48:23 -0700788#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
789 do { \
790 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
791 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800792 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700793#define REG_PATTERN_TEST(reg, mask, write) \
794 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800795
Bruce Allancef8c792008-04-02 13:48:23 -0700796#define REG_SET_AND_CHECK(reg, mask, write) \
797 do { \
798 if (reg_set_and_check(adapter, data, reg, mask, write)) \
799 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800800 } while (0)
801
Auke Kokbc7f75f2007-09-17 12:30:59 -0700802static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
803{
804 struct e1000_hw *hw = &adapter->hw;
805 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700806 u32 value;
807 u32 before;
808 u32 after;
809 u32 i;
810 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000811 u32 mask;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000812 u32 wlock_mac = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700813
Bruce Allane921eb12012-11-28 09:28:37 +0000814 /* The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700815 * Some bits that get toggled are ignored.
816 */
817 switch (mac->type) {
818 /* there are several bits on newer hardware that are r/w */
819 case e1000_82571:
820 case e1000_82572:
821 case e1000_80003es2lan:
822 toggle = 0x7FFFF3FF;
823 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000824 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700825 toggle = 0x7FFFF033;
826 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700827 }
828
829 before = er32(STATUS);
830 value = (er32(STATUS) & toggle);
831 ew32(STATUS, toggle);
832 after = er32(STATUS) & toggle;
833 if (value != after) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000834 e_err("failed STATUS register test got: 0x%08X expected: 0x%08X\n",
835 after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700836 *data = 1;
837 return 1;
838 }
839 /* restore previous status */
840 ew32(STATUS, before);
841
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700842 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700843 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
844 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
845 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
846 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
847 }
848
849 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000850 REG_PATTERN_TEST(E1000_RDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
851 REG_PATTERN_TEST(E1000_RDLEN(0), 0x000FFF80, 0x000FFFFF);
852 REG_PATTERN_TEST(E1000_RDH(0), 0x0000FFFF, 0x0000FFFF);
853 REG_PATTERN_TEST(E1000_RDT(0), 0x0000FFFF, 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700854 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
855 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
856 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000857 REG_PATTERN_TEST(E1000_TDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
858 REG_PATTERN_TEST(E1000_TDLEN(0), 0x000FFF80, 0x000FFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700859
860 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
861
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700862 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700863 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
864 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
865
Auke Kok86582512007-10-04 15:00:08 -0700866 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000867 REG_PATTERN_TEST(E1000_RDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700868 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700869 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000870 REG_PATTERN_TEST(E1000_TDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
Auke Kok86582512007-10-04 15:00:08 -0700871 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000872 mask = 0x8003FFFF;
873 switch (mac->type) {
874 case e1000_ich10lan:
875 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000876 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000877 case e1000_pch_lpt:
Bruce Allana4f58f52009-06-02 11:29:18 +0000878 mask |= (1 << 18);
879 break;
880 default:
881 break;
882 }
Bruce Allan2fbe4522012-04-19 03:21:47 +0000883
884 if (mac->type == e1000_pch_lpt)
885 wlock_mac = (er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK) >>
886 E1000_FWSM_WLOCK_MAC_SHIFT;
887
888 for (i = 0; i < mac->rar_entry_count; i++) {
Bruce Allana8fc1892012-12-05 06:25:36 +0000889 if (mac->type == e1000_pch_lpt) {
890 /* Cannot test write-protected SHRAL[n] registers */
891 if ((wlock_mac == 1) || (wlock_mac && (i > wlock_mac)))
892 continue;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000893
Bruce Allana8fc1892012-12-05 06:25:36 +0000894 /* SHRAH[9] different than the others */
895 if (i == 10)
896 mask |= (1 << 30);
897 else
898 mask &= ~(1 << 30);
899 }
900
901 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1), mask,
902 0xFFFFFFFF);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000903 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700904
905 for (i = 0; i < mac->mta_reg_count; i++)
906 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
907
908 *data = 0;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000909
Auke Kokbc7f75f2007-09-17 12:30:59 -0700910 return 0;
911}
912
913static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
914{
915 u16 temp;
916 u16 checksum = 0;
917 u16 i;
918
919 *data = 0;
920 /* Read and add up the contents of the EEPROM */
921 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
922 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
923 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800924 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700925 }
926 checksum += temp;
927 }
928
929 /* If Checksum is not Correct return error else test passed */
930 if ((checksum != (u16) NVM_SUM) && !(*data))
931 *data = 2;
932
933 return *data;
934}
935
Bruce Allan8bb62862013-01-16 08:46:49 +0000936static irqreturn_t e1000_test_intr(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700937{
938 struct net_device *netdev = (struct net_device *) data;
939 struct e1000_adapter *adapter = netdev_priv(netdev);
940 struct e1000_hw *hw = &adapter->hw;
941
942 adapter->test_icr |= er32(ICR);
943
944 return IRQ_HANDLED;
945}
946
947static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
948{
949 struct net_device *netdev = adapter->netdev;
950 struct e1000_hw *hw = &adapter->hw;
951 u32 mask;
952 u32 shared_int = 1;
953 u32 irq = adapter->pdev->irq;
954 int i;
Bruce Allan4662e822008-08-26 18:37:06 -0700955 int ret_val = 0;
956 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700957
958 *data = 0;
959
Bruce Allan4662e822008-08-26 18:37:06 -0700960 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
961 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
962 int_mode = adapter->int_mode;
963 e1000e_reset_interrupt_capability(adapter);
964 adapter->int_mode = E1000E_INT_MODE_LEGACY;
965 e1000e_set_interrupt_capability(adapter);
966 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700967 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800968 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700969 netdev)) {
970 shared_int = 0;
Joe Perchesa0607fd2009-11-18 23:29:17 -0800971 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700972 netdev->name, netdev)) {
973 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700974 ret_val = -1;
975 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700976 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700977 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700978
979 /* Disable all the interrupts */
980 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000981 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000982 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700983
984 /* Test each interrupt */
985 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700986 /* Interrupt to test */
987 mask = 1 << i;
988
Bruce Allanf4187b52008-08-26 18:36:50 -0700989 if (adapter->flags & FLAG_IS_ICH) {
990 switch (mask) {
991 case E1000_ICR_RXSEQ:
992 continue;
993 case 0x00000100:
994 if (adapter->hw.mac.type == e1000_ich8lan ||
995 adapter->hw.mac.type == e1000_ich9lan)
996 continue;
997 break;
998 default:
999 break;
1000 }
1001 }
1002
Auke Kokbc7f75f2007-09-17 12:30:59 -07001003 if (!shared_int) {
Bruce Allane921eb12012-11-28 09:28:37 +00001004 /* Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001005 * the cause register and then force the same
1006 * interrupt and see if one gets posted. If
1007 * an interrupt was posted to the bus, the
1008 * test failed.
1009 */
1010 adapter->test_icr = 0;
1011 ew32(IMC, mask);
1012 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001013 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001014 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001015
1016 if (adapter->test_icr & mask) {
1017 *data = 3;
1018 break;
1019 }
1020 }
1021
Bruce Allane921eb12012-11-28 09:28:37 +00001022 /* Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001023 * the cause register and then force the same
1024 * interrupt and see if one gets posted. If
1025 * an interrupt was not posted to the bus, the
1026 * test failed.
1027 */
1028 adapter->test_icr = 0;
1029 ew32(IMS, mask);
1030 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001031 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001032 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001033
1034 if (!(adapter->test_icr & mask)) {
1035 *data = 4;
1036 break;
1037 }
1038
1039 if (!shared_int) {
Bruce Allane921eb12012-11-28 09:28:37 +00001040 /* Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001041 * the cause register and then force the other
1042 * interrupts and see if any get posted. If
1043 * an interrupt was posted to the bus, the
1044 * test failed.
1045 */
1046 adapter->test_icr = 0;
1047 ew32(IMC, ~mask & 0x00007FFF);
1048 ew32(ICS, ~mask & 0x00007FFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001049 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001050 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001051
1052 if (adapter->test_icr) {
1053 *data = 5;
1054 break;
1055 }
1056 }
1057 }
1058
1059 /* Disable all the interrupts */
1060 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001061 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001062 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001063
1064 /* Unhook test interrupt handler */
1065 free_irq(irq, netdev);
1066
Bruce Allan4662e822008-08-26 18:37:06 -07001067out:
1068 if (int_mode == E1000E_INT_MODE_MSIX) {
1069 e1000e_reset_interrupt_capability(adapter);
1070 adapter->int_mode = int_mode;
1071 e1000e_set_interrupt_capability(adapter);
1072 }
1073
1074 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001075}
1076
1077static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1078{
1079 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1080 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1081 struct pci_dev *pdev = adapter->pdev;
1082 int i;
1083
1084 if (tx_ring->desc && tx_ring->buffer_info) {
1085 for (i = 0; i < tx_ring->count; i++) {
1086 if (tx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001087 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001088 tx_ring->buffer_info[i].dma,
1089 tx_ring->buffer_info[i].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001090 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001091 if (tx_ring->buffer_info[i].skb)
1092 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1093 }
1094 }
1095
1096 if (rx_ring->desc && rx_ring->buffer_info) {
1097 for (i = 0; i < rx_ring->count; i++) {
1098 if (rx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001099 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001100 rx_ring->buffer_info[i].dma,
Nick Nunley0be3f552010-04-27 13:09:05 +00001101 2048, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001102 if (rx_ring->buffer_info[i].skb)
1103 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1104 }
1105 }
1106
1107 if (tx_ring->desc) {
1108 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1109 tx_ring->dma);
1110 tx_ring->desc = NULL;
1111 }
1112 if (rx_ring->desc) {
1113 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1114 rx_ring->dma);
1115 rx_ring->desc = NULL;
1116 }
1117
1118 kfree(tx_ring->buffer_info);
1119 tx_ring->buffer_info = NULL;
1120 kfree(rx_ring->buffer_info);
1121 rx_ring->buffer_info = NULL;
1122}
1123
1124static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1125{
1126 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1127 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1128 struct pci_dev *pdev = adapter->pdev;
1129 struct e1000_hw *hw = &adapter->hw;
1130 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001131 int i;
1132 int ret_val;
1133
1134 /* Setup Tx descriptor ring and Tx buffers */
1135
1136 if (!tx_ring->count)
1137 tx_ring->count = E1000_DEFAULT_TXD;
1138
Bruce Allancef8c792008-04-02 13:48:23 -07001139 tx_ring->buffer_info = kcalloc(tx_ring->count,
1140 sizeof(struct e1000_buffer),
1141 GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001142 if (!tx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001143 ret_val = 1;
1144 goto err_nomem;
1145 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001146
1147 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1148 tx_ring->size = ALIGN(tx_ring->size, 4096);
1149 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1150 &tx_ring->dma, GFP_KERNEL);
1151 if (!tx_ring->desc) {
1152 ret_val = 2;
1153 goto err_nomem;
1154 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001155 tx_ring->next_to_use = 0;
1156 tx_ring->next_to_clean = 0;
1157
Bruce Allan1e360522012-03-20 03:48:13 +00001158 ew32(TDBAL(0), ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
1159 ew32(TDBAH(0), ((u64) tx_ring->dma >> 32));
1160 ew32(TDLEN(0), tx_ring->count * sizeof(struct e1000_tx_desc));
1161 ew32(TDH(0), 0);
1162 ew32(TDT(0), 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001163 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1164 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1165 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001166
1167 for (i = 0; i < tx_ring->count; i++) {
1168 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1169 struct sk_buff *skb;
1170 unsigned int skb_size = 1024;
1171
1172 skb = alloc_skb(skb_size, GFP_KERNEL);
1173 if (!skb) {
1174 ret_val = 3;
1175 goto err_nomem;
1176 }
1177 skb_put(skb, skb_size);
1178 tx_ring->buffer_info[i].skb = skb;
1179 tx_ring->buffer_info[i].length = skb->len;
1180 tx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001181 dma_map_single(&pdev->dev, skb->data, skb->len,
1182 DMA_TO_DEVICE);
1183 if (dma_mapping_error(&pdev->dev,
1184 tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001185 ret_val = 4;
1186 goto err_nomem;
1187 }
Bruce Allancef8c792008-04-02 13:48:23 -07001188 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001189 tx_desc->lower.data = cpu_to_le32(skb->len);
1190 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1191 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001192 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001193 tx_desc->upper.data = 0;
1194 }
1195
1196 /* Setup Rx descriptor ring and Rx buffers */
1197
1198 if (!rx_ring->count)
1199 rx_ring->count = E1000_DEFAULT_RXD;
1200
Bruce Allancef8c792008-04-02 13:48:23 -07001201 rx_ring->buffer_info = kcalloc(rx_ring->count,
1202 sizeof(struct e1000_buffer),
1203 GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001204 if (!rx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001205 ret_val = 5;
1206 goto err_nomem;
1207 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001208
Bruce Allan5f450212011-07-22 06:21:46 +00001209 rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001210 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1211 &rx_ring->dma, GFP_KERNEL);
1212 if (!rx_ring->desc) {
1213 ret_val = 6;
1214 goto err_nomem;
1215 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001216 rx_ring->next_to_use = 0;
1217 rx_ring->next_to_clean = 0;
1218
1219 rctl = er32(RCTL);
Bruce Allan7f99ae62011-07-22 06:21:35 +00001220 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
1221 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan1e360522012-03-20 03:48:13 +00001222 ew32(RDBAL(0), ((u64) rx_ring->dma & 0xFFFFFFFF));
1223 ew32(RDBAH(0), ((u64) rx_ring->dma >> 32));
1224 ew32(RDLEN(0), rx_ring->size);
1225 ew32(RDH(0), 0);
1226 ew32(RDT(0), 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001227 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allancef8c792008-04-02 13:48:23 -07001228 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1229 E1000_RCTL_SBP | E1000_RCTL_SECRC |
Auke Kokbc7f75f2007-09-17 12:30:59 -07001230 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1231 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1232 ew32(RCTL, rctl);
1233
1234 for (i = 0; i < rx_ring->count; i++) {
Bruce Allan5f450212011-07-22 06:21:46 +00001235 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001236 struct sk_buff *skb;
1237
1238 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1239 if (!skb) {
1240 ret_val = 7;
1241 goto err_nomem;
1242 }
1243 skb_reserve(skb, NET_IP_ALIGN);
1244 rx_ring->buffer_info[i].skb = skb;
1245 rx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001246 dma_map_single(&pdev->dev, skb->data, 2048,
1247 DMA_FROM_DEVICE);
1248 if (dma_mapping_error(&pdev->dev,
1249 rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001250 ret_val = 8;
1251 goto err_nomem;
1252 }
Bruce Allan5f450212011-07-22 06:21:46 +00001253 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1254 rx_desc->read.buffer_addr =
1255 cpu_to_le64(rx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001256 memset(skb->data, 0x00, skb->len);
1257 }
1258
1259 return 0;
1260
1261err_nomem:
1262 e1000_free_desc_rings(adapter);
1263 return ret_val;
1264}
1265
1266static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1267{
1268 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1269 e1e_wphy(&adapter->hw, 29, 0x001F);
1270 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1271 e1e_wphy(&adapter->hw, 29, 0x001A);
1272 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1273}
1274
1275static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1276{
1277 struct e1000_hw *hw = &adapter->hw;
1278 u32 ctrl_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001279 u16 phy_reg = 0;
Bruce Allancbd006c2010-11-24 06:01:30 +00001280 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001281
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001282 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001283
Bruce Allan3af50482010-06-16 13:25:55 +00001284 if (hw->phy.type == e1000_phy_ife) {
1285 /* force 100, set loopback */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001286 e1e_wphy(hw, MII_BMCR, 0x6100);
Bruce Allanbb436b22009-11-20 23:24:11 +00001287
Bruce Allan3af50482010-06-16 13:25:55 +00001288 /* Now set up the MAC to the same speed/duplex as the PHY. */
1289 ctrl_reg = er32(CTRL);
1290 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1291 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1292 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1293 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1294 E1000_CTRL_FD); /* Force Duplex to FULL */
1295
1296 ew32(CTRL, ctrl_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001297 e1e_flush();
Bruce Allan3af50482010-06-16 13:25:55 +00001298 udelay(500);
1299
1300 return 0;
1301 }
1302
1303 /* Specific PHY configuration for loopback */
1304 switch (hw->phy.type) {
1305 case e1000_phy_m88:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001306 /* Auto-MDI/MDIX Off */
1307 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1308 /* reset to update Auto-MDI/MDIX */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001309 e1e_wphy(hw, MII_BMCR, 0x9140);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001310 /* autoneg off */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001311 e1e_wphy(hw, MII_BMCR, 0x8140);
Bruce Allan3af50482010-06-16 13:25:55 +00001312 break;
1313 case e1000_phy_gg82563:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001314 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
Bruce Allancef8c792008-04-02 13:48:23 -07001315 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001316 case e1000_phy_bm:
1317 /* Set Default MAC Interface speed to 1GB */
1318 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1319 phy_reg &= ~0x0007;
1320 phy_reg |= 0x006;
1321 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1322 /* Assert SW reset for above settings to take effect */
Bruce Allan6b598e12013-01-23 06:50:05 +00001323 hw->phy.ops.commit(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001324 mdelay(1);
1325 /* Force Full Duplex */
1326 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1327 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1328 /* Set Link Up (in force link) */
1329 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1330 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1331 /* Force Link */
1332 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1333 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1334 /* Set Early Link Enable */
1335 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1336 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
Bruce Allan3af50482010-06-16 13:25:55 +00001337 break;
1338 case e1000_phy_82577:
1339 case e1000_phy_82578:
1340 /* Workaround: K1 must be disabled for stable 1Gbps operation */
Bruce Allancbd006c2010-11-24 06:01:30 +00001341 ret_val = hw->phy.ops.acquire(hw);
1342 if (ret_val) {
1343 e_err("Cannot setup 1Gbps loopback.\n");
1344 return ret_val;
1345 }
Bruce Allan3af50482010-06-16 13:25:55 +00001346 e1000_configure_k1_ich8lan(hw, false);
Bruce Allancbd006c2010-11-24 06:01:30 +00001347 hw->phy.ops.release(hw);
Bruce Allan3af50482010-06-16 13:25:55 +00001348 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001349 case e1000_phy_82579:
1350 /* Disable PHY energy detect power down */
1351 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1352 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
1353 /* Disable full chip energy detect */
1354 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1355 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1356 /* Enable loopback on the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00001357 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1358 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001359 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001360 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001361 }
1362
Bruce Allan3af50482010-06-16 13:25:55 +00001363 /* force 1000, set loopback */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001364 e1e_wphy(hw, MII_BMCR, 0x4140);
Bruce Allan3af50482010-06-16 13:25:55 +00001365 mdelay(250);
1366
1367 /* Now set up the MAC to the same speed/duplex as the PHY. */
1368 ctrl_reg = er32(CTRL);
1369 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1370 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1371 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1372 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1373 E1000_CTRL_FD); /* Force Duplex to FULL */
1374
1375 if (adapter->flags & FLAG_IS_ICH)
1376 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1377
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001378 if (hw->phy.media_type == e1000_media_type_copper &&
1379 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001380 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1381 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001382 /* Set the ILOS bit on the fiber Nic if half duplex link is
Bruce Allanad680762008-03-28 09:15:03 -07001383 * detected.
1384 */
Bruce Allan90da0662011-01-06 07:02:53 +00001385 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001386 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1387 }
1388
1389 ew32(CTRL, ctrl_reg);
1390
Bruce Allane921eb12012-11-28 09:28:37 +00001391 /* Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001392 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1393 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001394 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001395 e1000_phy_disable_receiver(adapter);
1396
1397 udelay(500);
1398
1399 return 0;
1400}
1401
1402static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1403{
1404 struct e1000_hw *hw = &adapter->hw;
1405 u32 ctrl = er32(CTRL);
Bruce Allan70806a72013-01-05 05:08:37 +00001406 int link;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001407
1408 /* special requirements for 82571/82572 fiber adapters */
1409
Bruce Allane921eb12012-11-28 09:28:37 +00001410 /* jump through hoops to make sure link is up because serdes
Bruce Allanad680762008-03-28 09:15:03 -07001411 * link is hardwired up
1412 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001413 ctrl |= E1000_CTRL_SLU;
1414 ew32(CTRL, ctrl);
1415
1416 /* disable autoneg */
1417 ctrl = er32(TXCW);
1418 ctrl &= ~(1 << 31);
1419 ew32(TXCW, ctrl);
1420
1421 link = (er32(STATUS) & E1000_STATUS_LU);
1422
1423 if (!link) {
1424 /* set invert loss of signal */
1425 ctrl = er32(CTRL);
1426 ctrl |= E1000_CTRL_ILOS;
1427 ew32(CTRL, ctrl);
1428 }
1429
Bruce Allane921eb12012-11-28 09:28:37 +00001430 /* special write to serdes control register to enable SerDes analog
Bruce Allanad680762008-03-28 09:15:03 -07001431 * loopback
1432 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001433#define E1000_SERDES_LB_ON 0x410
1434 ew32(SCTL, E1000_SERDES_LB_ON);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001435 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001436 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001437
1438 return 0;
1439}
1440
1441/* only call this for fiber/serdes connections to es2lan */
1442static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1443{
1444 struct e1000_hw *hw = &adapter->hw;
1445 u32 ctrlext = er32(CTRL_EXT);
1446 u32 ctrl = er32(CTRL);
1447
Bruce Allane921eb12012-11-28 09:28:37 +00001448 /* save CTRL_EXT to restore later, reuse an empty variable (unused
Bruce Allanad680762008-03-28 09:15:03 -07001449 * on mac_type 80003es2lan)
1450 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001451 adapter->tx_fifo_head = ctrlext;
1452
1453 /* clear the serdes mode bits, putting the device into mac loopback */
1454 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1455 ew32(CTRL_EXT, ctrlext);
1456
1457 /* force speed to 1000/FD, link up */
1458 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1459 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1460 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1461 ew32(CTRL, ctrl);
1462
1463 /* set mac loopback */
1464 ctrl = er32(RCTL);
1465 ctrl |= E1000_RCTL_LBM_MAC;
1466 ew32(RCTL, ctrl);
1467
1468 /* set testing mode parameters (no need to reset later) */
1469#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1470#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1471 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001472 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001473
1474 return 0;
1475}
1476
1477static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1478{
1479 struct e1000_hw *hw = &adapter->hw;
1480 u32 rctl;
1481
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001482 if (hw->phy.media_type == e1000_media_type_fiber ||
1483 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001484 switch (hw->mac.type) {
1485 case e1000_80003es2lan:
1486 return e1000_set_es2lan_mac_loopback(adapter);
1487 break;
1488 case e1000_82571:
1489 case e1000_82572:
1490 return e1000_set_82571_fiber_loopback(adapter);
1491 break;
1492 default:
1493 rctl = er32(RCTL);
1494 rctl |= E1000_RCTL_LBM_TCVR;
1495 ew32(RCTL, rctl);
1496 return 0;
1497 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001498 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001499 return e1000_integrated_phy_loopback(adapter);
1500 }
1501
1502 return 7;
1503}
1504
1505static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1506{
1507 struct e1000_hw *hw = &adapter->hw;
1508 u32 rctl;
1509 u16 phy_reg;
1510
1511 rctl = er32(RCTL);
1512 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1513 ew32(RCTL, rctl);
1514
1515 switch (hw->mac.type) {
1516 case e1000_80003es2lan:
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 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001520 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001521 adapter->tx_fifo_head = 0;
1522 }
1523 /* fall through */
1524 case e1000_82571:
1525 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001526 if (hw->phy.media_type == e1000_media_type_fiber ||
1527 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001528#define E1000_SERDES_LB_OFF 0x400
1529 ew32(SCTL, E1000_SERDES_LB_OFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001530 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001531 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001532 break;
1533 }
1534 /* Fall Through */
1535 default:
1536 hw->mac.autoneg = 1;
1537 if (hw->phy.type == e1000_phy_gg82563)
1538 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001539 e1e_rphy(hw, MII_BMCR, &phy_reg);
1540 if (phy_reg & BMCR_LOOPBACK) {
1541 phy_reg &= ~BMCR_LOOPBACK;
1542 e1e_wphy(hw, MII_BMCR, phy_reg);
Bruce Allan6b598e12013-01-23 06:50:05 +00001543 if (hw->phy.ops.commit)
1544 hw->phy.ops.commit(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001545 }
1546 break;
1547 }
1548}
1549
1550static void e1000_create_lbtest_frame(struct sk_buff *skb,
1551 unsigned int frame_size)
1552{
1553 memset(skb->data, 0xFF, frame_size);
1554 frame_size &= ~1;
1555 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1556 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1557 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1558}
1559
1560static int e1000_check_lbtest_frame(struct sk_buff *skb,
1561 unsigned int frame_size)
1562{
1563 frame_size &= ~1;
1564 if (*(skb->data + 3) == 0xFF)
1565 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1566 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1567 return 0;
1568 return 13;
1569}
1570
1571static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1572{
1573 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1574 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1575 struct pci_dev *pdev = adapter->pdev;
1576 struct e1000_hw *hw = &adapter->hw;
1577 int i, j, k, l;
1578 int lc;
1579 int good_cnt;
1580 int ret_val = 0;
1581 unsigned long time;
1582
Bruce Allan1e360522012-03-20 03:48:13 +00001583 ew32(RDT(0), rx_ring->count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001584
Bruce Allane921eb12012-11-28 09:28:37 +00001585 /* Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001586 * The idea is to wrap the largest ring a number of times using 64
1587 * send/receive pairs during each loop
1588 */
1589
1590 if (rx_ring->count <= tx_ring->count)
1591 lc = ((tx_ring->count / 64) * 2) + 1;
1592 else
1593 lc = ((rx_ring->count / 64) * 2) + 1;
1594
1595 k = 0;
1596 l = 0;
1597 for (j = 0; j <= lc; j++) { /* loop count loop */
1598 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001599 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1600 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001601 dma_sync_single_for_device(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001602 tx_ring->buffer_info[k].dma,
1603 tx_ring->buffer_info[k].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001604 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001605 k++;
1606 if (k == tx_ring->count)
1607 k = 0;
1608 }
Bruce Allan1e360522012-03-20 03:48:13 +00001609 ew32(TDT(0), k);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001610 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001611 msleep(200);
1612 time = jiffies; /* set the start time for the receive */
1613 good_cnt = 0;
1614 do { /* receive the sent packets */
Nick Nunley0be3f552010-04-27 13:09:05 +00001615 dma_sync_single_for_cpu(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001616 rx_ring->buffer_info[l].dma, 2048,
Nick Nunley0be3f552010-04-27 13:09:05 +00001617 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001618
1619 ret_val = e1000_check_lbtest_frame(
1620 rx_ring->buffer_info[l].skb, 1024);
1621 if (!ret_val)
1622 good_cnt++;
1623 l++;
1624 if (l == rx_ring->count)
1625 l = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00001626 /* time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001627 * enough time to complete the receives, if it's
1628 * exceeded, break and error off
1629 */
1630 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1631 if (good_cnt != 64) {
1632 ret_val = 13; /* ret_val is the same as mis-compare */
1633 break;
1634 }
Bruce Allancef8c792008-04-02 13:48:23 -07001635 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001636 ret_val = 14; /* error code for time out error */
1637 break;
1638 }
1639 } /* end loop count loop */
1640 return ret_val;
1641}
1642
1643static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1644{
Bruce Allan44abd5c2012-02-22 09:02:37 +00001645 struct e1000_hw *hw = &adapter->hw;
1646
Bruce Allane921eb12012-11-28 09:28:37 +00001647 /* PHY loopback cannot be performed if SoL/IDER sessions are active */
Bruce Allan470a5422012-05-26 06:08:48 +00001648 if (hw->phy.ops.check_reset_block &&
1649 hw->phy.ops.check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001650 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001651 *data = 0;
1652 goto out;
1653 }
1654
1655 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001656 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001657 goto out;
1658
1659 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001660 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001661 goto err_loopback;
1662
1663 *data = e1000_run_loopback_test(adapter);
1664 e1000_loopback_cleanup(adapter);
1665
1666err_loopback:
1667 e1000_free_desc_rings(adapter);
1668out:
1669 return *data;
1670}
1671
1672static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1673{
1674 struct e1000_hw *hw = &adapter->hw;
1675
1676 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001677 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001678 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001679 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001680
Bruce Allane921eb12012-11-28 09:28:37 +00001681 /* On some blade server designs, link establishment
Bruce Allanad680762008-03-28 09:15:03 -07001682 * could take as long as 2-3 minutes
1683 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001684 do {
1685 hw->mac.ops.check_for_link(hw);
1686 if (hw->mac.serdes_has_link)
1687 return *data;
1688 msleep(20);
1689 } while (i++ < 3750);
1690
1691 *data = 1;
1692 } else {
1693 hw->mac.ops.check_for_link(hw);
1694 if (hw->mac.autoneg)
Bruce Allane921eb12012-11-28 09:28:37 +00001695 /* On some Phy/switch combinations, link establishment
Bruce Allan5661aeb2011-02-25 06:36:25 +00001696 * can take a few seconds more than expected.
1697 */
1698 msleep(5000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001699
Bruce Allan5661aeb2011-02-25 06:36:25 +00001700 if (!(er32(STATUS) & E1000_STATUS_LU))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001701 *data = 1;
1702 }
1703 return *data;
1704}
1705
Bruce Allan8bb62862013-01-16 08:46:49 +00001706static int e1000e_get_sset_count(struct net_device __always_unused *netdev,
1707 int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001708{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001709 switch (sset) {
1710 case ETH_SS_TEST:
1711 return E1000_TEST_LEN;
1712 case ETH_SS_STATS:
1713 return E1000_STATS_LEN;
1714 default:
1715 return -EOPNOTSUPP;
1716 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001717}
1718
1719static void e1000_diag_test(struct net_device *netdev,
1720 struct ethtool_test *eth_test, u64 *data)
1721{
1722 struct e1000_adapter *adapter = netdev_priv(netdev);
1723 u16 autoneg_advertised;
1724 u8 forced_speed_duplex;
1725 u8 autoneg;
1726 bool if_running = netif_running(netdev);
1727
1728 set_bit(__E1000_TESTING, &adapter->state);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001729
1730 if (!if_running) {
1731 /* Get control of and reset hardware */
1732 if (adapter->flags & FLAG_HAS_AMT)
1733 e1000e_get_hw_control(adapter);
1734
1735 e1000e_power_up_phy(adapter);
1736
1737 adapter->hw.phy.autoneg_wait_to_complete = 1;
1738 e1000e_reset(adapter);
1739 adapter->hw.phy.autoneg_wait_to_complete = 0;
1740 }
1741
Auke Kokbc7f75f2007-09-17 12:30:59 -07001742 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1743 /* Offline tests */
1744
1745 /* save speed, duplex, autoneg settings */
1746 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1747 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1748 autoneg = adapter->hw.mac.autoneg;
1749
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001750 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001751
Auke Kokbc7f75f2007-09-17 12:30:59 -07001752 if (if_running)
1753 /* indicate we're in test mode */
1754 dev_close(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001755
1756 if (e1000_reg_test(adapter, &data[0]))
1757 eth_test->flags |= ETH_TEST_FL_FAILED;
1758
1759 e1000e_reset(adapter);
1760 if (e1000_eeprom_test(adapter, &data[1]))
1761 eth_test->flags |= ETH_TEST_FL_FAILED;
1762
1763 e1000e_reset(adapter);
1764 if (e1000_intr_test(adapter, &data[2]))
1765 eth_test->flags |= ETH_TEST_FL_FAILED;
1766
1767 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001768 if (e1000_loopback_test(adapter, &data[3]))
1769 eth_test->flags |= ETH_TEST_FL_FAILED;
1770
Auke Kokbc7f75f2007-09-17 12:30:59 -07001771 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001772 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001773 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001774 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001775
Carolyn Wybornyc6ce3852010-10-15 17:35:31 +00001776 if (e1000_link_test(adapter, &data[4]))
1777 eth_test->flags |= ETH_TEST_FL_FAILED;
1778
1779 /* restore speed, duplex, autoneg settings */
1780 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1781 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1782 adapter->hw.mac.autoneg = autoneg;
1783 e1000e_reset(adapter);
1784
Auke Kokbc7f75f2007-09-17 12:30:59 -07001785 clear_bit(__E1000_TESTING, &adapter->state);
1786 if (if_running)
1787 dev_open(netdev);
1788 } else {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001789 /* Online tests */
Bruce Allan11b08be82010-05-10 14:59:31 +00001790
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001791 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001792
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001793 /* register, eeprom, intr and loopback tests not run online */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001794 data[0] = 0;
1795 data[1] = 0;
1796 data[2] = 0;
1797 data[3] = 0;
1798
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001799 if (e1000_link_test(adapter, &data[4]))
1800 eth_test->flags |= ETH_TEST_FL_FAILED;
Bruce Allan11b08be82010-05-10 14:59:31 +00001801
Auke Kokbc7f75f2007-09-17 12:30:59 -07001802 clear_bit(__E1000_TESTING, &adapter->state);
1803 }
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001804
1805 if (!if_running) {
1806 e1000e_reset(adapter);
1807
1808 if (adapter->flags & FLAG_HAS_AMT)
1809 e1000e_release_hw_control(adapter);
1810 }
1811
Auke Kokbc7f75f2007-09-17 12:30:59 -07001812 msleep_interruptible(4 * 1000);
1813}
1814
1815static void e1000_get_wol(struct net_device *netdev,
1816 struct ethtool_wolinfo *wol)
1817{
1818 struct e1000_adapter *adapter = netdev_priv(netdev);
1819
1820 wol->supported = 0;
1821 wol->wolopts = 0;
1822
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001823 if (!(adapter->flags & FLAG_HAS_WOL) ||
1824 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001825 return;
1826
1827 wol->supported = WAKE_UCAST | WAKE_MCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001828 WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001829
1830 /* apply any specific unsupported masks here */
1831 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1832 wol->supported &= ~WAKE_UCAST;
1833
1834 if (adapter->wol & E1000_WUFC_EX)
Bruce Allan6ad65142012-04-12 05:47:09 +00001835 e_err("Interface does not support directed (unicast) frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001836 }
1837
1838 if (adapter->wol & E1000_WUFC_EX)
1839 wol->wolopts |= WAKE_UCAST;
1840 if (adapter->wol & E1000_WUFC_MC)
1841 wol->wolopts |= WAKE_MCAST;
1842 if (adapter->wol & E1000_WUFC_BC)
1843 wol->wolopts |= WAKE_BCAST;
1844 if (adapter->wol & E1000_WUFC_MAG)
1845 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001846 if (adapter->wol & E1000_WUFC_LNKC)
1847 wol->wolopts |= WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001848}
1849
Bruce Allan4a29e152011-03-04 09:07:01 +00001850static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001851{
1852 struct e1000_adapter *adapter = netdev_priv(netdev);
1853
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001854 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001855 !device_can_wakeup(&adapter->pdev->dev) ||
1856 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001857 WAKE_MAGIC | WAKE_PHY)))
Bruce Allan1fbfca32009-11-20 23:22:01 +00001858 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001859
1860 /* these settings will always override what we currently have */
1861 adapter->wol = 0;
1862
1863 if (wol->wolopts & WAKE_UCAST)
1864 adapter->wol |= E1000_WUFC_EX;
1865 if (wol->wolopts & WAKE_MCAST)
1866 adapter->wol |= E1000_WUFC_MC;
1867 if (wol->wolopts & WAKE_BCAST)
1868 adapter->wol |= E1000_WUFC_BC;
1869 if (wol->wolopts & WAKE_MAGIC)
1870 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001871 if (wol->wolopts & WAKE_PHY)
1872 adapter->wol |= E1000_WUFC_LNKC;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001873
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001874 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1875
Auke Kokbc7f75f2007-09-17 12:30:59 -07001876 return 0;
1877}
1878
Bruce Allandbf80dc2011-04-16 00:34:40 +00001879static int e1000_set_phys_id(struct net_device *netdev,
1880 enum ethtool_phys_id_state state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001881{
1882 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001883 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001884
Bruce Allandbf80dc2011-04-16 00:34:40 +00001885 switch (state) {
1886 case ETHTOOL_ID_ACTIVE:
1887 if (!hw->mac.ops.blink_led)
1888 return 2; /* cycle on/off twice per second */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001889
Bruce Allandbf80dc2011-04-16 00:34:40 +00001890 hw->mac.ops.blink_led(hw);
1891 break;
1892
1893 case ETHTOOL_ID_INACTIVE:
Bruce Allan4662e822008-08-26 18:37:06 -07001894 if (hw->phy.type == e1000_phy_ife)
1895 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001896 hw->mac.ops.led_off(hw);
1897 hw->mac.ops.cleanup_led(hw);
1898 break;
1899
1900 case ETHTOOL_ID_ON:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001901 hw->mac.ops.led_on(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001902 break;
1903
1904 case ETHTOOL_ID_OFF:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001905 hw->mac.ops.led_off(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001906 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001907 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001908 return 0;
1909}
1910
Auke Kokde5b3072008-04-23 11:09:08 -07001911static int e1000_get_coalesce(struct net_device *netdev,
1912 struct ethtool_coalesce *ec)
1913{
1914 struct e1000_adapter *adapter = netdev_priv(netdev);
1915
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001916 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07001917 ec->rx_coalesce_usecs = adapter->itr_setting;
1918 else
1919 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1920
1921 return 0;
1922}
1923
1924static int e1000_set_coalesce(struct net_device *netdev,
1925 struct ethtool_coalesce *ec)
1926{
1927 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokde5b3072008-04-23 11:09:08 -07001928
1929 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001930 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07001931 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1932 (ec->rx_coalesce_usecs == 2))
1933 return -EINVAL;
1934
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001935 if (ec->rx_coalesce_usecs == 4) {
Bruce Allan06a402e2012-08-17 06:17:57 +00001936 adapter->itr_setting = 4;
1937 adapter->itr = adapter->itr_setting;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001938 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07001939 adapter->itr = 20000;
1940 adapter->itr_setting = ec->rx_coalesce_usecs;
1941 } else {
1942 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1943 adapter->itr_setting = adapter->itr & ~3;
1944 }
1945
1946 if (adapter->itr_setting != 0)
Matthew Vick22a4cca2012-07-12 00:02:42 +00001947 e1000e_write_itr(adapter, adapter->itr);
Auke Kokde5b3072008-04-23 11:09:08 -07001948 else
Matthew Vick22a4cca2012-07-12 00:02:42 +00001949 e1000e_write_itr(adapter, 0);
Auke Kokde5b3072008-04-23 11:09:08 -07001950
1951 return 0;
1952}
1953
Auke Kokbc7f75f2007-09-17 12:30:59 -07001954static int e1000_nway_reset(struct net_device *netdev)
1955{
1956 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan5962bc22011-01-20 06:58:07 +00001957
1958 if (!netif_running(netdev))
1959 return -EAGAIN;
1960
1961 if (!adapter->hw.mac.autoneg)
1962 return -EINVAL;
1963
1964 e1000e_reinit_locked(adapter);
1965
Auke Kokbc7f75f2007-09-17 12:30:59 -07001966 return 0;
1967}
1968
Auke Kokbc7f75f2007-09-17 12:30:59 -07001969static void e1000_get_ethtool_stats(struct net_device *netdev,
Bruce Allan8bb62862013-01-16 08:46:49 +00001970 struct ethtool_stats __always_unused *stats,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001971 u64 *data)
1972{
1973 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001974 struct rtnl_link_stats64 net_stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001975 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001976 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001977
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001978 e1000e_get_stats64(netdev, &net_stats);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001979 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001980 switch (e1000_gstrings_stats[i].type) {
1981 case NETDEV_STATS:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001982 p = (char *) &net_stats +
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001983 e1000_gstrings_stats[i].stat_offset;
1984 break;
1985 case E1000_STATS:
1986 p = (char *) adapter +
1987 e1000_gstrings_stats[i].stat_offset;
1988 break;
Bruce Allan61c75812010-12-09 23:04:25 +00001989 default:
1990 data[i] = 0;
1991 continue;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001992 }
1993
Auke Kokbc7f75f2007-09-17 12:30:59 -07001994 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1995 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1996 }
1997}
1998
Bruce Allan8bb62862013-01-16 08:46:49 +00001999static void e1000_get_strings(struct net_device __always_unused *netdev,
2000 u32 stringset, u8 *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002001{
2002 u8 *p = data;
2003 int i;
2004
2005 switch (stringset) {
2006 case ETH_SS_TEST:
Bruce Allan5c1bda02011-01-19 04:23:39 +00002007 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002008 break;
2009 case ETH_SS_STATS:
2010 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
2011 memcpy(p, e1000_gstrings_stats[i].stat_string,
2012 ETH_GSTRING_LEN);
2013 p += ETH_GSTRING_LEN;
2014 }
2015 break;
2016 }
2017}
2018
Bruce Allan70495a52012-01-11 01:26:50 +00002019static int e1000_get_rxnfc(struct net_device *netdev,
Bruce Allan8bb62862013-01-16 08:46:49 +00002020 struct ethtool_rxnfc *info,
2021 u32 __always_unused *rule_locs)
Bruce Allan70495a52012-01-11 01:26:50 +00002022{
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 Allan203e41512012-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 Allan203e41512012-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}