blob: bbd4b1b3319d7a4dde7d5814977a5057e45a9e8e [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanbf670442013-01-01 16:00:01 +00004 Copyright(c) 1999 - 2013 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29/* ethtool support for e1000 */
30
31#include <linux/netdevice.h>
Bruce Allan9fb7a5f2011-07-29 05:52:51 +000032#include <linux/interrupt.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070033#include <linux/ethtool.h>
34#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070036#include <linux/delay.h>
David S. Millerc85c21a2012-01-26 16:25:55 -050037#include <linux/vmalloc.h>
Bruce Allan203e4152012-12-05 08:40:59 +000038#include <linux/mdio.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070039
40#include "e1000.h"
41
Bruce Allan362e20c2013-02-20 04:05:45 +000042enum { NETDEV_STATS, E1000_STATS };
Ajit Khapardee0f36a92009-10-13 01:45:09 +000043
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))
Bruce Allanf0ff4392013-02-20 04:05:39 +0000199 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X : ETH_TP_MDI;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000200 else
201 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
202
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000203 if (hw->phy.mdix == AUTO_ALL_MODES)
204 ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
205 else
206 ecmd->eth_tp_mdix_ctrl = hw->phy.mdix;
207
Auke Kokbc7f75f2007-09-17 12:30:59 -0700208 return 0;
209}
210
David Decotigny14ad2512011-04-27 18:32:43 +0000211static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700212{
213 struct e1000_mac_info *mac = &adapter->hw.mac;
214
215 mac->autoneg = 0;
216
David Decotigny14ad2512011-04-27 18:32:43 +0000217 /* Make sure dplx is at most 1 bit and lsb of speed is not set
Bruce Allane921eb12012-11-28 09:28:37 +0000218 * for the switch() below to work
219 */
David Decotigny14ad2512011-04-27 18:32:43 +0000220 if ((spd & 1) || (dplx & ~1))
221 goto err_inval;
222
Auke Kokbc7f75f2007-09-17 12:30:59 -0700223 /* Fiber NICs only allow 1000 gbps Full duplex */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700224 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
David Decotigny14ad2512011-04-27 18:32:43 +0000225 spd != SPEED_1000 &&
226 dplx != DUPLEX_FULL) {
227 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700228 }
229
David Decotigny14ad2512011-04-27 18:32:43 +0000230 switch (spd + dplx) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700231 case SPEED_10 + DUPLEX_HALF:
232 mac->forced_speed_duplex = ADVERTISE_10_HALF;
233 break;
234 case SPEED_10 + DUPLEX_FULL:
235 mac->forced_speed_duplex = ADVERTISE_10_FULL;
236 break;
237 case SPEED_100 + DUPLEX_HALF:
238 mac->forced_speed_duplex = ADVERTISE_100_HALF;
239 break;
240 case SPEED_100 + DUPLEX_FULL:
241 mac->forced_speed_duplex = ADVERTISE_100_FULL;
242 break;
243 case SPEED_1000 + DUPLEX_FULL:
244 mac->autoneg = 1;
245 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
246 break;
247 case SPEED_1000 + DUPLEX_HALF: /* not supported */
248 default:
David Decotigny14ad2512011-04-27 18:32:43 +0000249 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700250 }
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000251
252 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
253 adapter->hw.phy.mdix = AUTO_ALL_MODES;
254
Auke Kokbc7f75f2007-09-17 12:30:59 -0700255 return 0;
David Decotigny14ad2512011-04-27 18:32:43 +0000256
257err_inval:
258 e_err("Unsupported Speed/Duplex configuration\n");
259 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700260}
261
262static int e1000_set_settings(struct net_device *netdev,
263 struct ethtool_cmd *ecmd)
264{
265 struct e1000_adapter *adapter = netdev_priv(netdev);
266 struct e1000_hw *hw = &adapter->hw;
267
Bruce Allane921eb12012-11-28 09:28:37 +0000268 /* When SoL/IDER sessions are active, autoneg/speed/duplex
Bruce Allanad680762008-03-28 09:15:03 -0700269 * cannot be changed
270 */
Bruce Allan470a5422012-05-26 06:08:48 +0000271 if (hw->phy.ops.check_reset_block &&
272 hw->phy.ops.check_reset_block(hw)) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000273 e_err("Cannot change link characteristics when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700274 return -EINVAL;
275 }
276
Bruce Allane921eb12012-11-28 09:28:37 +0000277 /* MDI setting is only allowed when autoneg enabled because
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000278 * some hardware doesn't allow MDI setting when speed or
279 * duplex is forced.
280 */
281 if (ecmd->eth_tp_mdix_ctrl) {
282 if (hw->phy.media_type != e1000_media_type_copper)
283 return -EOPNOTSUPP;
284
285 if ((ecmd->eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) &&
286 (ecmd->autoneg != AUTONEG_ENABLE)) {
287 e_err("forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
288 return -EINVAL;
289 }
290 }
291
Auke Kokbc7f75f2007-09-17 12:30:59 -0700292 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000293 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700294
295 if (ecmd->autoneg == AUTONEG_ENABLE) {
296 hw->mac.autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700297 if (hw->phy.media_type == e1000_media_type_fiber)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700298 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
Bruce Allanf0ff4392013-02-20 04:05:39 +0000299 ADVERTISED_FIBRE | ADVERTISED_Autoneg;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700300 else
301 hw->phy.autoneg_advertised = ecmd->advertising |
Bruce Allanf0ff4392013-02-20 04:05:39 +0000302 ADVERTISED_TP | ADVERTISED_Autoneg;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700303 ecmd->advertising = hw->phy.autoneg_advertised;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700304 if (adapter->fc_autoneg)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800305 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700306 } else {
David Decotigny25db0332011-04-27 18:32:39 +0000307 u32 speed = ethtool_cmd_speed(ecmd);
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000308 /* calling this overrides forced MDI setting */
David Decotigny14ad2512011-04-27 18:32:43 +0000309 if (e1000_set_spd_dplx(adapter, speed, ecmd->duplex)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700310 clear_bit(__E1000_RESETTING, &adapter->state);
311 return -EINVAL;
312 }
313 }
314
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000315 /* MDI-X => 2; MDI => 1; Auto => 3 */
316 if (ecmd->eth_tp_mdix_ctrl) {
Bruce Allane921eb12012-11-28 09:28:37 +0000317 /* fix up the value for auto (3 => 0) as zero is mapped
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000318 * internally to auto
319 */
320 if (ecmd->eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
321 hw->phy.mdix = AUTO_ALL_MODES;
322 else
323 hw->phy.mdix = ecmd->eth_tp_mdix_ctrl;
324 }
325
Auke Kokbc7f75f2007-09-17 12:30:59 -0700326 /* reset the link */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700327 if (netif_running(adapter->netdev)) {
328 e1000e_down(adapter);
329 e1000e_up(adapter);
Bruce Allana7a1d9d2013-01-24 00:50:18 +0000330 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700331 e1000e_reset(adapter);
Bruce Allana7a1d9d2013-01-24 00:50:18 +0000332 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700333
334 clear_bit(__E1000_RESETTING, &adapter->state);
335 return 0;
336}
337
338static void e1000_get_pauseparam(struct net_device *netdev,
339 struct ethtool_pauseparam *pause)
340{
341 struct e1000_adapter *adapter = netdev_priv(netdev);
342 struct e1000_hw *hw = &adapter->hw;
343
344 pause->autoneg =
Bruce Allanf0ff4392013-02-20 04:05:39 +0000345 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700346
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800347 if (hw->fc.current_mode == e1000_fc_rx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700348 pause->rx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800349 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700350 pause->tx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800351 } else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700352 pause->rx_pause = 1;
353 pause->tx_pause = 1;
354 }
355}
356
357static int e1000_set_pauseparam(struct net_device *netdev,
358 struct ethtool_pauseparam *pause)
359{
360 struct e1000_adapter *adapter = netdev_priv(netdev);
361 struct e1000_hw *hw = &adapter->hw;
362 int retval = 0;
363
364 adapter->fc_autoneg = pause->autoneg;
365
366 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000367 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700368
Auke Kokbc7f75f2007-09-17 12:30:59 -0700369 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800370 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700371 if (netif_running(adapter->netdev)) {
372 e1000e_down(adapter);
373 e1000e_up(adapter);
374 } else {
375 e1000e_reset(adapter);
376 }
377 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800378 if (pause->rx_pause && pause->tx_pause)
379 hw->fc.requested_mode = e1000_fc_full;
380 else if (pause->rx_pause && !pause->tx_pause)
381 hw->fc.requested_mode = e1000_fc_rx_pause;
382 else if (!pause->rx_pause && pause->tx_pause)
383 hw->fc.requested_mode = e1000_fc_tx_pause;
384 else if (!pause->rx_pause && !pause->tx_pause)
385 hw->fc.requested_mode = e1000_fc_none;
386
387 hw->fc.current_mode = hw->fc.requested_mode;
388
Bruce Allan945eb312009-10-28 18:28:30 +0000389 if (hw->phy.media_type == e1000_media_type_fiber) {
390 retval = hw->mac.ops.setup_link(hw);
391 /* implicit goto out */
392 } else {
393 retval = e1000e_force_mac_fc(hw);
394 if (retval)
395 goto out;
396 e1000e_set_fc_watermarks(hw);
397 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700398 }
399
Bruce Allan945eb312009-10-28 18:28:30 +0000400out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700401 clear_bit(__E1000_RESETTING, &adapter->state);
402 return retval;
403}
404
Auke Kokbc7f75f2007-09-17 12:30:59 -0700405static u32 e1000_get_msglevel(struct net_device *netdev)
406{
407 struct e1000_adapter *adapter = netdev_priv(netdev);
408 return adapter->msg_enable;
409}
410
411static void e1000_set_msglevel(struct net_device *netdev, u32 data)
412{
413 struct e1000_adapter *adapter = netdev_priv(netdev);
414 adapter->msg_enable = data;
415}
416
Bruce Allan8bb62862013-01-16 08:46:49 +0000417static int e1000_get_regs_len(struct net_device __always_unused *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700418{
419#define E1000_REGS_LEN 32 /* overestimate */
420 return E1000_REGS_LEN * sizeof(u32);
421}
422
423static void e1000_get_regs(struct net_device *netdev,
424 struct ethtool_regs *regs, void *p)
425{
426 struct e1000_adapter *adapter = netdev_priv(netdev);
427 struct e1000_hw *hw = &adapter->hw;
428 u32 *regs_buff = p;
429 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700430
431 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
432
Sergei Shtylyovff938e42011-02-28 11:57:33 -0800433 regs->version = (1 << 24) | (adapter->pdev->revision << 16) |
Bruce Allanf0ff4392013-02-20 04:05:39 +0000434 adapter->pdev->device;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700435
436 regs_buff[0] = er32(CTRL);
437 regs_buff[1] = er32(STATUS);
438
439 regs_buff[2] = er32(RCTL);
Bruce Allan1e360522012-03-20 03:48:13 +0000440 regs_buff[3] = er32(RDLEN(0));
441 regs_buff[4] = er32(RDH(0));
442 regs_buff[5] = er32(RDT(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700443 regs_buff[6] = er32(RDTR);
444
445 regs_buff[7] = er32(TCTL);
Bruce Allan1e360522012-03-20 03:48:13 +0000446 regs_buff[8] = er32(TDLEN(0));
447 regs_buff[9] = er32(TDH(0));
448 regs_buff[10] = er32(TDT(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700449 regs_buff[11] = er32(TIDV);
450
451 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700452
453 /* ethtool doesn't use anything past this point, so all this
Bruce Allane921eb12012-11-28 09:28:37 +0000454 * code is likely legacy junk for apps that may or may not exist
455 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700456 if (hw->phy.type == e1000_phy_m88) {
457 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
458 regs_buff[13] = (u32)phy_data; /* cable length */
459 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
460 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
461 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
462 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
463 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
464 regs_buff[18] = regs_buff[13]; /* cable polarity */
465 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
466 regs_buff[20] = regs_buff[17]; /* polarity correction */
467 /* phy receive errors */
468 regs_buff[22] = adapter->phy_stats.receive_errors;
469 regs_buff[23] = regs_buff[13]; /* mdix mode */
470 }
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000471 regs_buff[21] = 0; /* was idle_errors */
472 e1e_rphy(hw, MII_STAT1000, &phy_data);
473 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
474 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700475}
476
477static int e1000_get_eeprom_len(struct net_device *netdev)
478{
479 struct e1000_adapter *adapter = netdev_priv(netdev);
480 return adapter->hw.nvm.word_size * 2;
481}
482
483static int e1000_get_eeprom(struct net_device *netdev,
484 struct ethtool_eeprom *eeprom, u8 *bytes)
485{
486 struct e1000_adapter *adapter = netdev_priv(netdev);
487 struct e1000_hw *hw = &adapter->hw;
488 u16 *eeprom_buff;
489 int first_word;
490 int last_word;
491 int ret_val = 0;
492 u16 i;
493
494 if (eeprom->len == 0)
495 return -EINVAL;
496
497 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
498
499 first_word = eeprom->offset >> 1;
500 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
501
502 eeprom_buff = kmalloc(sizeof(u16) *
503 (last_word - first_word + 1), GFP_KERNEL);
504 if (!eeprom_buff)
505 return -ENOMEM;
506
507 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
508 ret_val = e1000_read_nvm(hw, first_word,
509 last_word - first_word + 1,
510 eeprom_buff);
511 } else {
512 for (i = 0; i < last_word - first_word + 1; i++) {
513 ret_val = e1000_read_nvm(hw, first_word + i, 1,
514 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800515 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700516 break;
517 }
518 }
519
Bruce Allane2434552008-11-21 17:02:41 -0800520 if (ret_val) {
521 /* a read error occurred, throw away the result */
Roel Kluin8528b012009-12-01 15:54:24 +0000522 memset(eeprom_buff, 0xff, sizeof(u16) *
523 (last_word - first_word + 1));
Bruce Allane2434552008-11-21 17:02:41 -0800524 } else {
525 /* Device's eeprom is always little-endian, word addressable */
526 for (i = 0; i < last_word - first_word + 1; i++)
527 le16_to_cpus(&eeprom_buff[i]);
528 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700529
530 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
531 kfree(eeprom_buff);
532
533 return ret_val;
534}
535
536static int e1000_set_eeprom(struct net_device *netdev,
537 struct ethtool_eeprom *eeprom, u8 *bytes)
538{
539 struct e1000_adapter *adapter = netdev_priv(netdev);
540 struct e1000_hw *hw = &adapter->hw;
541 u16 *eeprom_buff;
542 void *ptr;
543 int max_len;
544 int first_word;
545 int last_word;
546 int ret_val = 0;
547 u16 i;
548
549 if (eeprom->len == 0)
550 return -EOPNOTSUPP;
551
552 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
553 return -EFAULT;
554
Bruce Allan4a770352008-10-01 17:18:35 -0700555 if (adapter->flags & FLAG_READ_ONLY_NVM)
556 return -EINVAL;
557
Auke Kokbc7f75f2007-09-17 12:30:59 -0700558 max_len = hw->nvm.word_size * 2;
559
560 first_word = eeprom->offset >> 1;
561 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
562 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
563 if (!eeprom_buff)
564 return -ENOMEM;
565
566 ptr = (void *)eeprom_buff;
567
568 if (eeprom->offset & 1) {
569 /* need read/modify/write of first changed EEPROM word */
570 /* only the second byte of the word is being modified */
571 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
572 ptr++;
573 }
Bruce Allan9e2d7652012-01-31 06:37:27 +0000574 if (((eeprom->offset + eeprom->len) & 1) && (!ret_val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700575 /* need read/modify/write of last changed EEPROM word */
576 /* only the first byte of the word is being modified */
577 ret_val = e1000_read_nvm(hw, last_word, 1,
578 &eeprom_buff[last_word - first_word]);
579
Bruce Allane2434552008-11-21 17:02:41 -0800580 if (ret_val)
581 goto out;
582
Auke Kokbc7f75f2007-09-17 12:30:59 -0700583 /* Device's eeprom is always little-endian, word addressable */
584 for (i = 0; i < last_word - first_word + 1; i++)
585 le16_to_cpus(&eeprom_buff[i]);
586
587 memcpy(ptr, bytes, eeprom->len);
588
589 for (i = 0; i < last_word - first_word + 1; i++)
Bruce Allane885d762012-01-31 06:37:32 +0000590 cpu_to_le16s(&eeprom_buff[i]);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700591
592 ret_val = e1000_write_nvm(hw, first_word,
593 last_word - first_word + 1, eeprom_buff);
594
Bruce Allane2434552008-11-21 17:02:41 -0800595 if (ret_val)
596 goto out;
597
Bruce Allane921eb12012-11-28 09:28:37 +0000598 /* Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800599 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700600 */
Bruce Allane2434552008-11-21 17:02:41 -0800601 if ((first_word <= NVM_CHECKSUM_REG) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +0000602 (hw->mac.type == e1000_82583) ||
603 (hw->mac.type == e1000_82574) ||
604 (hw->mac.type == e1000_82573))
Bruce Allane2434552008-11-21 17:02:41 -0800605 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700606
Bruce Allane2434552008-11-21 17:02:41 -0800607out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700608 kfree(eeprom_buff);
609 return ret_val;
610}
611
612static void e1000_get_drvinfo(struct net_device *netdev,
613 struct ethtool_drvinfo *drvinfo)
614{
615 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700616
Rick Jones612a94d2011-11-14 08:13:25 +0000617 strlcpy(drvinfo->driver, e1000e_driver_name,
618 sizeof(drvinfo->driver));
Rick Jones33a5ba12011-11-15 14:59:53 +0000619 strlcpy(drvinfo->version, e1000e_driver_version,
Rick Jones612a94d2011-11-14 08:13:25 +0000620 sizeof(drvinfo->version));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700621
Bruce Allane921eb12012-11-28 09:28:37 +0000622 /* EEPROM image version # is reported as firmware version # for
Bruce Allanad680762008-03-28 09:15:03 -0700623 * PCI-E controllers
624 */
Rick Jones612a94d2011-11-14 08:13:25 +0000625 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
626 "%d.%d-%d",
Bruce Allan84527592008-11-21 17:00:22 -0800627 (adapter->eeprom_vers & 0xF000) >> 12,
628 (adapter->eeprom_vers & 0x0FF0) >> 4,
629 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700630
Rick Jones612a94d2011-11-14 08:13:25 +0000631 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
632 sizeof(drvinfo->bus_info));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700633 drvinfo->regdump_len = e1000_get_regs_len(netdev);
634 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
635}
636
637static void e1000_get_ringparam(struct net_device *netdev,
638 struct ethtool_ringparam *ring)
639{
640 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700641
642 ring->rx_max_pending = E1000_MAX_RXD;
643 ring->tx_max_pending = E1000_MAX_TXD;
Bruce Allan508da422011-12-16 00:45:51 +0000644 ring->rx_pending = adapter->rx_ring_count;
645 ring->tx_pending = adapter->tx_ring_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700646}
647
648static int e1000_set_ringparam(struct net_device *netdev,
649 struct ethtool_ringparam *ring)
650{
651 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan508da422011-12-16 00:45:51 +0000652 struct e1000_ring *temp_tx = NULL, *temp_rx = NULL;
653 int err = 0, size = sizeof(struct e1000_ring);
654 bool set_tx = false, set_rx = false;
655 u16 new_rx_count, new_tx_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700656
657 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
658 return -EINVAL;
659
Bruce Allan508da422011-12-16 00:45:51 +0000660 new_rx_count = clamp_t(u32, ring->rx_pending, E1000_MIN_RXD,
661 E1000_MAX_RXD);
662 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
663
664 new_tx_count = clamp_t(u32, ring->tx_pending, E1000_MIN_TXD,
665 E1000_MAX_TXD);
666 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
667
668 if ((new_tx_count == adapter->tx_ring_count) &&
669 (new_rx_count == adapter->rx_ring_count))
670 /* nothing to do */
671 return 0;
672
Auke Kokbc7f75f2007-09-17 12:30:59 -0700673 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000674 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700675
Bruce Allan508da422011-12-16 00:45:51 +0000676 if (!netif_running(adapter->netdev)) {
677 /* Set counts now and allocate resources during open() */
678 adapter->tx_ring->count = new_tx_count;
679 adapter->rx_ring->count = new_rx_count;
680 adapter->tx_ring_count = new_tx_count;
681 adapter->rx_ring_count = new_rx_count;
682 goto clear_reset;
683 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700684
Bruce Allan508da422011-12-16 00:45:51 +0000685 set_tx = (new_tx_count != adapter->tx_ring_count);
686 set_rx = (new_rx_count != adapter->rx_ring_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700687
Bruce Allan508da422011-12-16 00:45:51 +0000688 /* Allocate temporary storage for ring updates */
689 if (set_tx) {
690 temp_tx = vmalloc(size);
691 if (!temp_tx) {
692 err = -ENOMEM;
693 goto free_temp;
694 }
695 }
696 if (set_rx) {
697 temp_rx = vmalloc(size);
698 if (!temp_rx) {
699 err = -ENOMEM;
700 goto free_temp;
701 }
702 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700703
Bruce Allan508da422011-12-16 00:45:51 +0000704 e1000e_down(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700705
Bruce Allane921eb12012-11-28 09:28:37 +0000706 /* We can't just free everything and then setup again, because the
Bruce Allan508da422011-12-16 00:45:51 +0000707 * ISRs in MSI-X mode get passed pointers to the Tx and Rx ring
708 * structs. First, attempt to allocate new resources...
709 */
710 if (set_tx) {
711 memcpy(temp_tx, adapter->tx_ring, size);
712 temp_tx->count = new_tx_count;
713 err = e1000e_setup_tx_resources(temp_tx);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700714 if (err)
715 goto err_setup;
716 }
Bruce Allan508da422011-12-16 00:45:51 +0000717 if (set_rx) {
718 memcpy(temp_rx, adapter->rx_ring, size);
719 temp_rx->count = new_rx_count;
720 err = e1000e_setup_rx_resources(temp_rx);
721 if (err)
722 goto err_setup_rx;
723 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700724
Bruce Allan508da422011-12-16 00:45:51 +0000725 /* ...then free the old resources and copy back any new ring data */
726 if (set_tx) {
727 e1000e_free_tx_resources(adapter->tx_ring);
728 memcpy(adapter->tx_ring, temp_tx, size);
729 adapter->tx_ring_count = new_tx_count;
730 }
731 if (set_rx) {
732 e1000e_free_rx_resources(adapter->rx_ring);
733 memcpy(adapter->rx_ring, temp_rx, size);
734 adapter->rx_ring_count = new_rx_count;
735 }
736
Auke Kokbc7f75f2007-09-17 12:30:59 -0700737err_setup_rx:
Bruce Allan508da422011-12-16 00:45:51 +0000738 if (err && set_tx)
739 e1000e_free_tx_resources(temp_tx);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700740err_setup:
Bruce Allan508da422011-12-16 00:45:51 +0000741 e1000e_up(adapter);
742free_temp:
743 vfree(temp_tx);
744 vfree(temp_rx);
745clear_reset:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700746 clear_bit(__E1000_RESETTING, &adapter->state);
747 return err;
748}
749
Bruce Allancef8c792008-04-02 13:48:23 -0700750static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
751 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800752{
Bruce Allancef8c792008-04-02 13:48:23 -0700753 u32 pat, val;
Bruce Allan64806412010-12-11 05:53:42 +0000754 static const u32 test[] = {
755 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Bruce Allancef8c792008-04-02 13:48:23 -0700756 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800757 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700758 (test[pat] & write));
759 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
760 if (val != (test[pat] & write & mask)) {
Bruce Allana8fc1892012-12-05 06:25:36 +0000761 e_err("pattern test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
762 reg + (offset << 2), val,
763 (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800764 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700765 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800766 }
767 }
Bruce Allancef8c792008-04-02 13:48:23 -0700768 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700769}
770
Joe Perches2a887192007-11-13 20:53:51 -0800771static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
772 int reg, u32 mask, u32 write)
773{
Bruce Allancef8c792008-04-02 13:48:23 -0700774 u32 val;
Joe Perches2a887192007-11-13 20:53:51 -0800775 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700776 val = __er32(&adapter->hw, reg);
777 if ((write & mask) != (val & mask)) {
Bruce Allana8fc1892012-12-05 06:25:36 +0000778 e_err("set/check test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
Bruce Allan6ad65142012-04-12 05:47:09 +0000779 reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800780 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700781 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800782 }
Bruce Allancef8c792008-04-02 13:48:23 -0700783 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700784}
Bruce Allancef8c792008-04-02 13:48:23 -0700785#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
786 do { \
787 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
788 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800789 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700790#define REG_PATTERN_TEST(reg, mask, write) \
791 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800792
Bruce Allancef8c792008-04-02 13:48:23 -0700793#define REG_SET_AND_CHECK(reg, mask, write) \
794 do { \
795 if (reg_set_and_check(adapter, data, reg, mask, write)) \
796 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800797 } while (0)
798
Auke Kokbc7f75f2007-09-17 12:30:59 -0700799static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
800{
801 struct e1000_hw *hw = &adapter->hw;
802 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700803 u32 value;
804 u32 before;
805 u32 after;
806 u32 i;
807 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000808 u32 mask;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000809 u32 wlock_mac = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700810
Bruce Allane921eb12012-11-28 09:28:37 +0000811 /* The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700812 * Some bits that get toggled are ignored.
813 */
814 switch (mac->type) {
815 /* there are several bits on newer hardware that are r/w */
816 case e1000_82571:
817 case e1000_82572:
818 case e1000_80003es2lan:
819 toggle = 0x7FFFF3FF;
820 break;
Bruce Allanf0ff4392013-02-20 04:05:39 +0000821 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700822 toggle = 0x7FFFF033;
823 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700824 }
825
826 before = er32(STATUS);
827 value = (er32(STATUS) & toggle);
828 ew32(STATUS, toggle);
829 after = er32(STATUS) & toggle;
830 if (value != after) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000831 e_err("failed STATUS register test got: 0x%08X expected: 0x%08X\n",
832 after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700833 *data = 1;
834 return 1;
835 }
836 /* restore previous status */
837 ew32(STATUS, before);
838
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700839 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700840 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
841 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
842 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
843 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
844 }
845
846 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000847 REG_PATTERN_TEST(E1000_RDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
848 REG_PATTERN_TEST(E1000_RDLEN(0), 0x000FFF80, 0x000FFFFF);
849 REG_PATTERN_TEST(E1000_RDH(0), 0x0000FFFF, 0x0000FFFF);
850 REG_PATTERN_TEST(E1000_RDT(0), 0x0000FFFF, 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700851 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
852 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
853 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000854 REG_PATTERN_TEST(E1000_TDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
855 REG_PATTERN_TEST(E1000_TDLEN(0), 0x000FFF80, 0x000FFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700856
857 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
858
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700859 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700860 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
861 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
862
Auke Kok86582512007-10-04 15:00:08 -0700863 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000864 REG_PATTERN_TEST(E1000_RDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700865 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700866 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000867 REG_PATTERN_TEST(E1000_TDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
Auke Kok86582512007-10-04 15:00:08 -0700868 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000869 mask = 0x8003FFFF;
870 switch (mac->type) {
871 case e1000_ich10lan:
872 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000873 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000874 case e1000_pch_lpt:
Bruce Allana4f58f52009-06-02 11:29:18 +0000875 mask |= (1 << 18);
876 break;
877 default:
878 break;
879 }
Bruce Allan2fbe4522012-04-19 03:21:47 +0000880
881 if (mac->type == e1000_pch_lpt)
882 wlock_mac = (er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK) >>
883 E1000_FWSM_WLOCK_MAC_SHIFT;
884
885 for (i = 0; i < mac->rar_entry_count; i++) {
Bruce Allana8fc1892012-12-05 06:25:36 +0000886 if (mac->type == e1000_pch_lpt) {
887 /* Cannot test write-protected SHRAL[n] registers */
888 if ((wlock_mac == 1) || (wlock_mac && (i > wlock_mac)))
889 continue;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000890
Bruce Allana8fc1892012-12-05 06:25:36 +0000891 /* SHRAH[9] different than the others */
892 if (i == 10)
893 mask |= (1 << 30);
894 else
895 mask &= ~(1 << 30);
896 }
897
898 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1), mask,
899 0xFFFFFFFF);
Bruce Allan2fbe4522012-04-19 03:21:47 +0000900 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700901
902 for (i = 0; i < mac->mta_reg_count; i++)
903 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
904
905 *data = 0;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000906
Auke Kokbc7f75f2007-09-17 12:30:59 -0700907 return 0;
908}
909
910static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
911{
912 u16 temp;
913 u16 checksum = 0;
914 u16 i;
915
916 *data = 0;
917 /* Read and add up the contents of the EEPROM */
918 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
919 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
920 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800921 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700922 }
923 checksum += temp;
924 }
925
926 /* If Checksum is not Correct return error else test passed */
927 if ((checksum != (u16) NVM_SUM) && !(*data))
928 *data = 2;
929
930 return *data;
931}
932
Bruce Allan8bb62862013-01-16 08:46:49 +0000933static irqreturn_t e1000_test_intr(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700934{
935 struct net_device *netdev = (struct net_device *) data;
936 struct e1000_adapter *adapter = netdev_priv(netdev);
937 struct e1000_hw *hw = &adapter->hw;
938
939 adapter->test_icr |= er32(ICR);
940
941 return IRQ_HANDLED;
942}
943
944static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
945{
946 struct net_device *netdev = adapter->netdev;
947 struct e1000_hw *hw = &adapter->hw;
948 u32 mask;
949 u32 shared_int = 1;
950 u32 irq = adapter->pdev->irq;
951 int i;
Bruce Allan4662e822008-08-26 18:37:06 -0700952 int ret_val = 0;
953 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700954
955 *data = 0;
956
Bruce Allan4662e822008-08-26 18:37:06 -0700957 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
958 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
959 int_mode = adapter->int_mode;
960 e1000e_reset_interrupt_capability(adapter);
961 adapter->int_mode = E1000E_INT_MODE_LEGACY;
962 e1000e_set_interrupt_capability(adapter);
963 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700964 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800965 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700966 netdev)) {
967 shared_int = 0;
Joe Perchesa0607fd2009-11-18 23:29:17 -0800968 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700969 netdev->name, netdev)) {
970 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700971 ret_val = -1;
972 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700973 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700974 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700975
976 /* Disable all the interrupts */
977 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000978 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000979 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700980
981 /* Test each interrupt */
982 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700983 /* Interrupt to test */
984 mask = 1 << i;
985
Bruce Allanf4187b52008-08-26 18:36:50 -0700986 if (adapter->flags & FLAG_IS_ICH) {
987 switch (mask) {
988 case E1000_ICR_RXSEQ:
989 continue;
990 case 0x00000100:
991 if (adapter->hw.mac.type == e1000_ich8lan ||
992 adapter->hw.mac.type == e1000_ich9lan)
993 continue;
994 break;
995 default:
996 break;
997 }
998 }
999
Auke Kokbc7f75f2007-09-17 12:30:59 -07001000 if (!shared_int) {
Bruce Allane921eb12012-11-28 09:28:37 +00001001 /* Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001002 * the cause register and then force the same
1003 * interrupt and see if one gets posted. If
1004 * an interrupt was posted to the bus, the
1005 * test failed.
1006 */
1007 adapter->test_icr = 0;
1008 ew32(IMC, mask);
1009 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001010 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001011 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001012
1013 if (adapter->test_icr & mask) {
1014 *data = 3;
1015 break;
1016 }
1017 }
1018
Bruce Allane921eb12012-11-28 09:28:37 +00001019 /* Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001020 * the cause register and then force the same
1021 * interrupt and see if one gets posted. If
1022 * an interrupt was not posted to the bus, the
1023 * test failed.
1024 */
1025 adapter->test_icr = 0;
1026 ew32(IMS, mask);
1027 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001028 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001029 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001030
1031 if (!(adapter->test_icr & mask)) {
1032 *data = 4;
1033 break;
1034 }
1035
1036 if (!shared_int) {
Bruce Allane921eb12012-11-28 09:28:37 +00001037 /* Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001038 * the cause register and then force the other
1039 * interrupts and see if any get posted. If
1040 * an interrupt was posted to the bus, the
1041 * test failed.
1042 */
1043 adapter->test_icr = 0;
1044 ew32(IMC, ~mask & 0x00007FFF);
1045 ew32(ICS, ~mask & 0x00007FFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001046 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001047 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001048
1049 if (adapter->test_icr) {
1050 *data = 5;
1051 break;
1052 }
1053 }
1054 }
1055
1056 /* Disable all the interrupts */
1057 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001058 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001059 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001060
1061 /* Unhook test interrupt handler */
1062 free_irq(irq, netdev);
1063
Bruce Allan4662e822008-08-26 18:37:06 -07001064out:
1065 if (int_mode == E1000E_INT_MODE_MSIX) {
1066 e1000e_reset_interrupt_capability(adapter);
1067 adapter->int_mode = int_mode;
1068 e1000e_set_interrupt_capability(adapter);
1069 }
1070
1071 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001072}
1073
1074static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1075{
1076 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1077 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1078 struct pci_dev *pdev = adapter->pdev;
1079 int i;
1080
1081 if (tx_ring->desc && tx_ring->buffer_info) {
1082 for (i = 0; i < tx_ring->count; i++) {
1083 if (tx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001084 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001085 tx_ring->buffer_info[i].dma,
1086 tx_ring->buffer_info[i].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001087 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001088 if (tx_ring->buffer_info[i].skb)
1089 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1090 }
1091 }
1092
1093 if (rx_ring->desc && rx_ring->buffer_info) {
1094 for (i = 0; i < rx_ring->count; i++) {
1095 if (rx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001096 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001097 rx_ring->buffer_info[i].dma,
Nick Nunley0be3f552010-04-27 13:09:05 +00001098 2048, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001099 if (rx_ring->buffer_info[i].skb)
1100 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1101 }
1102 }
1103
1104 if (tx_ring->desc) {
1105 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1106 tx_ring->dma);
1107 tx_ring->desc = NULL;
1108 }
1109 if (rx_ring->desc) {
1110 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1111 rx_ring->dma);
1112 rx_ring->desc = NULL;
1113 }
1114
1115 kfree(tx_ring->buffer_info);
1116 tx_ring->buffer_info = NULL;
1117 kfree(rx_ring->buffer_info);
1118 rx_ring->buffer_info = NULL;
1119}
1120
1121static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1122{
1123 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1124 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1125 struct pci_dev *pdev = adapter->pdev;
1126 struct e1000_hw *hw = &adapter->hw;
1127 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001128 int i;
1129 int ret_val;
1130
1131 /* Setup Tx descriptor ring and Tx buffers */
1132
1133 if (!tx_ring->count)
1134 tx_ring->count = E1000_DEFAULT_TXD;
1135
Bruce Allancef8c792008-04-02 13:48:23 -07001136 tx_ring->buffer_info = kcalloc(tx_ring->count,
1137 sizeof(struct e1000_buffer),
1138 GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001139 if (!tx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001140 ret_val = 1;
1141 goto err_nomem;
1142 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001143
1144 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1145 tx_ring->size = ALIGN(tx_ring->size, 4096);
1146 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1147 &tx_ring->dma, GFP_KERNEL);
1148 if (!tx_ring->desc) {
1149 ret_val = 2;
1150 goto err_nomem;
1151 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001152 tx_ring->next_to_use = 0;
1153 tx_ring->next_to_clean = 0;
1154
Bruce Allan1e360522012-03-20 03:48:13 +00001155 ew32(TDBAL(0), ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
1156 ew32(TDBAH(0), ((u64) tx_ring->dma >> 32));
1157 ew32(TDLEN(0), tx_ring->count * sizeof(struct e1000_tx_desc));
1158 ew32(TDH(0), 0);
1159 ew32(TDT(0), 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001160 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1161 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1162 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001163
1164 for (i = 0; i < tx_ring->count; i++) {
1165 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1166 struct sk_buff *skb;
1167 unsigned int skb_size = 1024;
1168
1169 skb = alloc_skb(skb_size, GFP_KERNEL);
1170 if (!skb) {
1171 ret_val = 3;
1172 goto err_nomem;
1173 }
1174 skb_put(skb, skb_size);
1175 tx_ring->buffer_info[i].skb = skb;
1176 tx_ring->buffer_info[i].length = skb->len;
1177 tx_ring->buffer_info[i].dma =
Bruce Allanf0ff4392013-02-20 04:05:39 +00001178 dma_map_single(&pdev->dev, skb->data, skb->len,
1179 DMA_TO_DEVICE);
Nick Nunley0be3f552010-04-27 13:09:05 +00001180 if (dma_mapping_error(&pdev->dev,
1181 tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001182 ret_val = 4;
1183 goto err_nomem;
1184 }
Bruce Allancef8c792008-04-02 13:48:23 -07001185 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001186 tx_desc->lower.data = cpu_to_le32(skb->len);
1187 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1188 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001189 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001190 tx_desc->upper.data = 0;
1191 }
1192
1193 /* Setup Rx descriptor ring and Rx buffers */
1194
1195 if (!rx_ring->count)
1196 rx_ring->count = E1000_DEFAULT_RXD;
1197
Bruce Allancef8c792008-04-02 13:48:23 -07001198 rx_ring->buffer_info = kcalloc(rx_ring->count,
1199 sizeof(struct e1000_buffer),
1200 GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001201 if (!rx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001202 ret_val = 5;
1203 goto err_nomem;
1204 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001205
Bruce Allan5f450212011-07-22 06:21:46 +00001206 rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001207 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1208 &rx_ring->dma, GFP_KERNEL);
1209 if (!rx_ring->desc) {
1210 ret_val = 6;
1211 goto err_nomem;
1212 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001213 rx_ring->next_to_use = 0;
1214 rx_ring->next_to_clean = 0;
1215
1216 rctl = er32(RCTL);
Bruce Allan7f99ae62011-07-22 06:21:35 +00001217 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
1218 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan1e360522012-03-20 03:48:13 +00001219 ew32(RDBAL(0), ((u64) rx_ring->dma & 0xFFFFFFFF));
1220 ew32(RDBAH(0), ((u64) rx_ring->dma >> 32));
1221 ew32(RDLEN(0), rx_ring->size);
1222 ew32(RDH(0), 0);
1223 ew32(RDT(0), 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001224 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allanf0ff4392013-02-20 04:05:39 +00001225 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1226 E1000_RCTL_SBP | E1000_RCTL_SECRC |
1227 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1228 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001229 ew32(RCTL, rctl);
1230
1231 for (i = 0; i < rx_ring->count; i++) {
Bruce Allan5f450212011-07-22 06:21:46 +00001232 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001233 struct sk_buff *skb;
1234
1235 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1236 if (!skb) {
1237 ret_val = 7;
1238 goto err_nomem;
1239 }
1240 skb_reserve(skb, NET_IP_ALIGN);
1241 rx_ring->buffer_info[i].skb = skb;
1242 rx_ring->buffer_info[i].dma =
Bruce Allanf0ff4392013-02-20 04:05:39 +00001243 dma_map_single(&pdev->dev, skb->data, 2048,
1244 DMA_FROM_DEVICE);
Nick Nunley0be3f552010-04-27 13:09:05 +00001245 if (dma_mapping_error(&pdev->dev,
1246 rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001247 ret_val = 8;
1248 goto err_nomem;
1249 }
Bruce Allan5f450212011-07-22 06:21:46 +00001250 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1251 rx_desc->read.buffer_addr =
1252 cpu_to_le64(rx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001253 memset(skb->data, 0x00, skb->len);
1254 }
1255
1256 return 0;
1257
1258err_nomem:
1259 e1000_free_desc_rings(adapter);
1260 return ret_val;
1261}
1262
1263static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1264{
1265 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1266 e1e_wphy(&adapter->hw, 29, 0x001F);
1267 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1268 e1e_wphy(&adapter->hw, 29, 0x001A);
1269 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1270}
1271
1272static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1273{
1274 struct e1000_hw *hw = &adapter->hw;
1275 u32 ctrl_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001276 u16 phy_reg = 0;
Bruce Allancbd006c2010-11-24 06:01:30 +00001277 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001278
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001279 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001280
Bruce Allan3af50482010-06-16 13:25:55 +00001281 if (hw->phy.type == e1000_phy_ife) {
1282 /* force 100, set loopback */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001283 e1e_wphy(hw, MII_BMCR, 0x6100);
Bruce Allanbb436b22009-11-20 23:24:11 +00001284
Bruce Allan3af50482010-06-16 13:25:55 +00001285 /* Now set up the MAC to the same speed/duplex as the PHY. */
1286 ctrl_reg = er32(CTRL);
1287 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1288 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1289 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1290 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1291 E1000_CTRL_FD); /* Force Duplex to FULL */
1292
1293 ew32(CTRL, ctrl_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001294 e1e_flush();
Bruce Allan3af50482010-06-16 13:25:55 +00001295 udelay(500);
1296
1297 return 0;
1298 }
1299
1300 /* Specific PHY configuration for loopback */
1301 switch (hw->phy.type) {
1302 case e1000_phy_m88:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001303 /* Auto-MDI/MDIX Off */
1304 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1305 /* reset to update Auto-MDI/MDIX */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001306 e1e_wphy(hw, MII_BMCR, 0x9140);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001307 /* autoneg off */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001308 e1e_wphy(hw, MII_BMCR, 0x8140);
Bruce Allan3af50482010-06-16 13:25:55 +00001309 break;
1310 case e1000_phy_gg82563:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001311 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
Bruce Allancef8c792008-04-02 13:48:23 -07001312 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001313 case e1000_phy_bm:
1314 /* Set Default MAC Interface speed to 1GB */
1315 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1316 phy_reg &= ~0x0007;
1317 phy_reg |= 0x006;
1318 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1319 /* Assert SW reset for above settings to take effect */
Bruce Allan6b598e12013-01-23 06:50:05 +00001320 hw->phy.ops.commit(hw);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001321 mdelay(1);
1322 /* Force Full Duplex */
1323 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1324 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1325 /* Set Link Up (in force link) */
1326 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1327 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1328 /* Force Link */
1329 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1330 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1331 /* Set Early Link Enable */
1332 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1333 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
Bruce Allan3af50482010-06-16 13:25:55 +00001334 break;
1335 case e1000_phy_82577:
1336 case e1000_phy_82578:
1337 /* Workaround: K1 must be disabled for stable 1Gbps operation */
Bruce Allancbd006c2010-11-24 06:01:30 +00001338 ret_val = hw->phy.ops.acquire(hw);
1339 if (ret_val) {
1340 e_err("Cannot setup 1Gbps loopback.\n");
1341 return ret_val;
1342 }
Bruce Allan3af50482010-06-16 13:25:55 +00001343 e1000_configure_k1_ich8lan(hw, false);
Bruce Allancbd006c2010-11-24 06:01:30 +00001344 hw->phy.ops.release(hw);
Bruce Allan3af50482010-06-16 13:25:55 +00001345 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001346 case e1000_phy_82579:
1347 /* Disable PHY energy detect power down */
1348 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1349 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
1350 /* Disable full chip energy detect */
1351 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1352 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1353 /* Enable loopback on the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00001354 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1355 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001356 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001357 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001358 }
1359
Bruce Allan3af50482010-06-16 13:25:55 +00001360 /* force 1000, set loopback */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001361 e1e_wphy(hw, MII_BMCR, 0x4140);
Bruce Allan3af50482010-06-16 13:25:55 +00001362 mdelay(250);
1363
1364 /* Now set up the MAC to the same speed/duplex as the PHY. */
1365 ctrl_reg = er32(CTRL);
1366 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1367 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1368 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1369 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1370 E1000_CTRL_FD); /* Force Duplex to FULL */
1371
1372 if (adapter->flags & FLAG_IS_ICH)
1373 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1374
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001375 if (hw->phy.media_type == e1000_media_type_copper &&
1376 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001377 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1378 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001379 /* Set the ILOS bit on the fiber Nic if half duplex link is
Bruce Allanad680762008-03-28 09:15:03 -07001380 * detected.
1381 */
Bruce Allan90da0662011-01-06 07:02:53 +00001382 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001383 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1384 }
1385
1386 ew32(CTRL, ctrl_reg);
1387
Bruce Allane921eb12012-11-28 09:28:37 +00001388 /* Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001389 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1390 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001391 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001392 e1000_phy_disable_receiver(adapter);
1393
1394 udelay(500);
1395
1396 return 0;
1397}
1398
1399static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1400{
1401 struct e1000_hw *hw = &adapter->hw;
1402 u32 ctrl = er32(CTRL);
Bruce Allan70806a72013-01-05 05:08:37 +00001403 int link;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001404
1405 /* special requirements for 82571/82572 fiber adapters */
1406
Bruce Allane921eb12012-11-28 09:28:37 +00001407 /* jump through hoops to make sure link is up because serdes
Bruce Allanad680762008-03-28 09:15:03 -07001408 * link is hardwired up
1409 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001410 ctrl |= E1000_CTRL_SLU;
1411 ew32(CTRL, ctrl);
1412
1413 /* disable autoneg */
1414 ctrl = er32(TXCW);
1415 ctrl &= ~(1 << 31);
1416 ew32(TXCW, ctrl);
1417
1418 link = (er32(STATUS) & E1000_STATUS_LU);
1419
1420 if (!link) {
1421 /* set invert loss of signal */
1422 ctrl = er32(CTRL);
1423 ctrl |= E1000_CTRL_ILOS;
1424 ew32(CTRL, ctrl);
1425 }
1426
Bruce Allane921eb12012-11-28 09:28:37 +00001427 /* special write to serdes control register to enable SerDes analog
Bruce Allanad680762008-03-28 09:15:03 -07001428 * loopback
1429 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001430#define E1000_SERDES_LB_ON 0x410
1431 ew32(SCTL, E1000_SERDES_LB_ON);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001432 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001433 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001434
1435 return 0;
1436}
1437
1438/* only call this for fiber/serdes connections to es2lan */
1439static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1440{
1441 struct e1000_hw *hw = &adapter->hw;
1442 u32 ctrlext = er32(CTRL_EXT);
1443 u32 ctrl = er32(CTRL);
1444
Bruce Allane921eb12012-11-28 09:28:37 +00001445 /* save CTRL_EXT to restore later, reuse an empty variable (unused
Bruce Allanad680762008-03-28 09:15:03 -07001446 * on mac_type 80003es2lan)
1447 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001448 adapter->tx_fifo_head = ctrlext;
1449
1450 /* clear the serdes mode bits, putting the device into mac loopback */
1451 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1452 ew32(CTRL_EXT, ctrlext);
1453
1454 /* force speed to 1000/FD, link up */
1455 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1456 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1457 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1458 ew32(CTRL, ctrl);
1459
1460 /* set mac loopback */
1461 ctrl = er32(RCTL);
1462 ctrl |= E1000_RCTL_LBM_MAC;
1463 ew32(RCTL, ctrl);
1464
1465 /* set testing mode parameters (no need to reset later) */
1466#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1467#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1468 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001469 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001470
1471 return 0;
1472}
1473
1474static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1475{
1476 struct e1000_hw *hw = &adapter->hw;
1477 u32 rctl;
1478
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001479 if (hw->phy.media_type == e1000_media_type_fiber ||
1480 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001481 switch (hw->mac.type) {
1482 case e1000_80003es2lan:
1483 return e1000_set_es2lan_mac_loopback(adapter);
1484 break;
1485 case e1000_82571:
1486 case e1000_82572:
1487 return e1000_set_82571_fiber_loopback(adapter);
1488 break;
1489 default:
1490 rctl = er32(RCTL);
1491 rctl |= E1000_RCTL_LBM_TCVR;
1492 ew32(RCTL, rctl);
1493 return 0;
1494 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001495 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001496 return e1000_integrated_phy_loopback(adapter);
1497 }
1498
1499 return 7;
1500}
1501
1502static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1503{
1504 struct e1000_hw *hw = &adapter->hw;
1505 u32 rctl;
1506 u16 phy_reg;
1507
1508 rctl = er32(RCTL);
1509 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1510 ew32(RCTL, rctl);
1511
1512 switch (hw->mac.type) {
1513 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001514 if (hw->phy.media_type == e1000_media_type_fiber ||
1515 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001516 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001517 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001518 adapter->tx_fifo_head = 0;
1519 }
1520 /* fall through */
1521 case e1000_82571:
1522 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001523 if (hw->phy.media_type == e1000_media_type_fiber ||
1524 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001525#define E1000_SERDES_LB_OFF 0x400
1526 ew32(SCTL, E1000_SERDES_LB_OFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001527 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001528 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001529 break;
1530 }
1531 /* Fall Through */
1532 default:
1533 hw->mac.autoneg = 1;
1534 if (hw->phy.type == e1000_phy_gg82563)
1535 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001536 e1e_rphy(hw, MII_BMCR, &phy_reg);
1537 if (phy_reg & BMCR_LOOPBACK) {
1538 phy_reg &= ~BMCR_LOOPBACK;
1539 e1e_wphy(hw, MII_BMCR, phy_reg);
Bruce Allan6b598e12013-01-23 06:50:05 +00001540 if (hw->phy.ops.commit)
1541 hw->phy.ops.commit(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001542 }
1543 break;
1544 }
1545}
1546
1547static void e1000_create_lbtest_frame(struct sk_buff *skb,
1548 unsigned int frame_size)
1549{
1550 memset(skb->data, 0xFF, frame_size);
1551 frame_size &= ~1;
1552 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1553 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1554 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1555}
1556
1557static int e1000_check_lbtest_frame(struct sk_buff *skb,
1558 unsigned int frame_size)
1559{
1560 frame_size &= ~1;
1561 if (*(skb->data + 3) == 0xFF)
1562 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1563 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1564 return 0;
1565 return 13;
1566}
1567
1568static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1569{
1570 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1571 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1572 struct pci_dev *pdev = adapter->pdev;
1573 struct e1000_hw *hw = &adapter->hw;
1574 int i, j, k, l;
1575 int lc;
1576 int good_cnt;
1577 int ret_val = 0;
1578 unsigned long time;
1579
Bruce Allan1e360522012-03-20 03:48:13 +00001580 ew32(RDT(0), rx_ring->count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001581
Bruce Allane921eb12012-11-28 09:28:37 +00001582 /* Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001583 * The idea is to wrap the largest ring a number of times using 64
1584 * send/receive pairs during each loop
1585 */
1586
1587 if (rx_ring->count <= tx_ring->count)
1588 lc = ((tx_ring->count / 64) * 2) + 1;
1589 else
1590 lc = ((rx_ring->count / 64) * 2) + 1;
1591
1592 k = 0;
1593 l = 0;
1594 for (j = 0; j <= lc; j++) { /* loop count loop */
1595 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001596 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1597 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001598 dma_sync_single_for_device(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001599 tx_ring->buffer_info[k].dma,
1600 tx_ring->buffer_info[k].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001601 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001602 k++;
1603 if (k == tx_ring->count)
1604 k = 0;
1605 }
Bruce Allan1e360522012-03-20 03:48:13 +00001606 ew32(TDT(0), k);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001607 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001608 msleep(200);
1609 time = jiffies; /* set the start time for the receive */
1610 good_cnt = 0;
1611 do { /* receive the sent packets */
Nick Nunley0be3f552010-04-27 13:09:05 +00001612 dma_sync_single_for_cpu(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001613 rx_ring->buffer_info[l].dma, 2048,
Nick Nunley0be3f552010-04-27 13:09:05 +00001614 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001615
1616 ret_val = e1000_check_lbtest_frame(
1617 rx_ring->buffer_info[l].skb, 1024);
1618 if (!ret_val)
1619 good_cnt++;
1620 l++;
1621 if (l == rx_ring->count)
1622 l = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00001623 /* time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001624 * enough time to complete the receives, if it's
1625 * exceeded, break and error off
1626 */
1627 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1628 if (good_cnt != 64) {
1629 ret_val = 13; /* ret_val is the same as mis-compare */
1630 break;
1631 }
Bruce Allancef8c792008-04-02 13:48:23 -07001632 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001633 ret_val = 14; /* error code for time out error */
1634 break;
1635 }
1636 } /* end loop count loop */
1637 return ret_val;
1638}
1639
1640static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1641{
Bruce Allan44abd5c2012-02-22 09:02:37 +00001642 struct e1000_hw *hw = &adapter->hw;
1643
Bruce Allane921eb12012-11-28 09:28:37 +00001644 /* PHY loopback cannot be performed if SoL/IDER sessions are active */
Bruce Allan470a5422012-05-26 06:08:48 +00001645 if (hw->phy.ops.check_reset_block &&
1646 hw->phy.ops.check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001647 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001648 *data = 0;
1649 goto out;
1650 }
1651
1652 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001653 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001654 goto out;
1655
1656 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001657 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001658 goto err_loopback;
1659
1660 *data = e1000_run_loopback_test(adapter);
1661 e1000_loopback_cleanup(adapter);
1662
1663err_loopback:
1664 e1000_free_desc_rings(adapter);
1665out:
1666 return *data;
1667}
1668
1669static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1670{
1671 struct e1000_hw *hw = &adapter->hw;
1672
1673 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001674 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001675 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001676 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001677
Bruce Allane921eb12012-11-28 09:28:37 +00001678 /* On some blade server designs, link establishment
Bruce Allanad680762008-03-28 09:15:03 -07001679 * could take as long as 2-3 minutes
1680 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001681 do {
1682 hw->mac.ops.check_for_link(hw);
1683 if (hw->mac.serdes_has_link)
1684 return *data;
1685 msleep(20);
1686 } while (i++ < 3750);
1687
1688 *data = 1;
1689 } else {
1690 hw->mac.ops.check_for_link(hw);
1691 if (hw->mac.autoneg)
Bruce Allane921eb12012-11-28 09:28:37 +00001692 /* On some Phy/switch combinations, link establishment
Bruce Allan5661aeb2011-02-25 06:36:25 +00001693 * can take a few seconds more than expected.
1694 */
1695 msleep(5000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001696
Bruce Allan5661aeb2011-02-25 06:36:25 +00001697 if (!(er32(STATUS) & E1000_STATUS_LU))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001698 *data = 1;
1699 }
1700 return *data;
1701}
1702
Bruce Allan8bb62862013-01-16 08:46:49 +00001703static int e1000e_get_sset_count(struct net_device __always_unused *netdev,
1704 int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001705{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001706 switch (sset) {
1707 case ETH_SS_TEST:
1708 return E1000_TEST_LEN;
1709 case ETH_SS_STATS:
1710 return E1000_STATS_LEN;
1711 default:
1712 return -EOPNOTSUPP;
1713 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001714}
1715
1716static void e1000_diag_test(struct net_device *netdev,
1717 struct ethtool_test *eth_test, u64 *data)
1718{
1719 struct e1000_adapter *adapter = netdev_priv(netdev);
1720 u16 autoneg_advertised;
1721 u8 forced_speed_duplex;
1722 u8 autoneg;
1723 bool if_running = netif_running(netdev);
1724
1725 set_bit(__E1000_TESTING, &adapter->state);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001726
1727 if (!if_running) {
1728 /* Get control of and reset hardware */
1729 if (adapter->flags & FLAG_HAS_AMT)
1730 e1000e_get_hw_control(adapter);
1731
1732 e1000e_power_up_phy(adapter);
1733
1734 adapter->hw.phy.autoneg_wait_to_complete = 1;
1735 e1000e_reset(adapter);
1736 adapter->hw.phy.autoneg_wait_to_complete = 0;
1737 }
1738
Auke Kokbc7f75f2007-09-17 12:30:59 -07001739 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1740 /* Offline tests */
1741
1742 /* save speed, duplex, autoneg settings */
1743 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1744 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1745 autoneg = adapter->hw.mac.autoneg;
1746
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001747 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001748
Auke Kokbc7f75f2007-09-17 12:30:59 -07001749 if (if_running)
1750 /* indicate we're in test mode */
1751 dev_close(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001752
1753 if (e1000_reg_test(adapter, &data[0]))
1754 eth_test->flags |= ETH_TEST_FL_FAILED;
1755
1756 e1000e_reset(adapter);
1757 if (e1000_eeprom_test(adapter, &data[1]))
1758 eth_test->flags |= ETH_TEST_FL_FAILED;
1759
1760 e1000e_reset(adapter);
1761 if (e1000_intr_test(adapter, &data[2]))
1762 eth_test->flags |= ETH_TEST_FL_FAILED;
1763
1764 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001765 if (e1000_loopback_test(adapter, &data[3]))
1766 eth_test->flags |= ETH_TEST_FL_FAILED;
1767
Auke Kokbc7f75f2007-09-17 12:30:59 -07001768 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001769 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001770 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001771 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001772
Carolyn Wybornyc6ce3852010-10-15 17:35:31 +00001773 if (e1000_link_test(adapter, &data[4]))
1774 eth_test->flags |= ETH_TEST_FL_FAILED;
1775
1776 /* restore speed, duplex, autoneg settings */
1777 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1778 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1779 adapter->hw.mac.autoneg = autoneg;
1780 e1000e_reset(adapter);
1781
Auke Kokbc7f75f2007-09-17 12:30:59 -07001782 clear_bit(__E1000_TESTING, &adapter->state);
1783 if (if_running)
1784 dev_open(netdev);
1785 } else {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001786 /* Online tests */
Bruce Allan11b08be2010-05-10 14:59:31 +00001787
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001788 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001789
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001790 /* register, eeprom, intr and loopback tests not run online */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001791 data[0] = 0;
1792 data[1] = 0;
1793 data[2] = 0;
1794 data[3] = 0;
1795
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001796 if (e1000_link_test(adapter, &data[4]))
1797 eth_test->flags |= ETH_TEST_FL_FAILED;
Bruce Allan11b08be2010-05-10 14:59:31 +00001798
Auke Kokbc7f75f2007-09-17 12:30:59 -07001799 clear_bit(__E1000_TESTING, &adapter->state);
1800 }
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001801
1802 if (!if_running) {
1803 e1000e_reset(adapter);
1804
1805 if (adapter->flags & FLAG_HAS_AMT)
1806 e1000e_release_hw_control(adapter);
1807 }
1808
Auke Kokbc7f75f2007-09-17 12:30:59 -07001809 msleep_interruptible(4 * 1000);
1810}
1811
1812static void e1000_get_wol(struct net_device *netdev,
1813 struct ethtool_wolinfo *wol)
1814{
1815 struct e1000_adapter *adapter = netdev_priv(netdev);
1816
1817 wol->supported = 0;
1818 wol->wolopts = 0;
1819
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001820 if (!(adapter->flags & FLAG_HAS_WOL) ||
1821 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001822 return;
1823
1824 wol->supported = WAKE_UCAST | WAKE_MCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001825 WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001826
1827 /* apply any specific unsupported masks here */
1828 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1829 wol->supported &= ~WAKE_UCAST;
1830
1831 if (adapter->wol & E1000_WUFC_EX)
Bruce Allan6ad65142012-04-12 05:47:09 +00001832 e_err("Interface does not support directed (unicast) frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001833 }
1834
1835 if (adapter->wol & E1000_WUFC_EX)
1836 wol->wolopts |= WAKE_UCAST;
1837 if (adapter->wol & E1000_WUFC_MC)
1838 wol->wolopts |= WAKE_MCAST;
1839 if (adapter->wol & E1000_WUFC_BC)
1840 wol->wolopts |= WAKE_BCAST;
1841 if (adapter->wol & E1000_WUFC_MAG)
1842 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001843 if (adapter->wol & E1000_WUFC_LNKC)
1844 wol->wolopts |= WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001845}
1846
Bruce Allan4a29e152011-03-04 09:07:01 +00001847static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001848{
1849 struct e1000_adapter *adapter = netdev_priv(netdev);
1850
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001851 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001852 !device_can_wakeup(&adapter->pdev->dev) ||
1853 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001854 WAKE_MAGIC | WAKE_PHY)))
Bruce Allan1fbfca32009-11-20 23:22:01 +00001855 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001856
1857 /* these settings will always override what we currently have */
1858 adapter->wol = 0;
1859
1860 if (wol->wolopts & WAKE_UCAST)
1861 adapter->wol |= E1000_WUFC_EX;
1862 if (wol->wolopts & WAKE_MCAST)
1863 adapter->wol |= E1000_WUFC_MC;
1864 if (wol->wolopts & WAKE_BCAST)
1865 adapter->wol |= E1000_WUFC_BC;
1866 if (wol->wolopts & WAKE_MAGIC)
1867 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001868 if (wol->wolopts & WAKE_PHY)
1869 adapter->wol |= E1000_WUFC_LNKC;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001870
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001871 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1872
Auke Kokbc7f75f2007-09-17 12:30:59 -07001873 return 0;
1874}
1875
Bruce Allandbf80dc2011-04-16 00:34:40 +00001876static int e1000_set_phys_id(struct net_device *netdev,
1877 enum ethtool_phys_id_state state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001878{
1879 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001880 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001881
Bruce Allandbf80dc2011-04-16 00:34:40 +00001882 switch (state) {
1883 case ETHTOOL_ID_ACTIVE:
1884 if (!hw->mac.ops.blink_led)
1885 return 2; /* cycle on/off twice per second */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001886
Bruce Allandbf80dc2011-04-16 00:34:40 +00001887 hw->mac.ops.blink_led(hw);
1888 break;
1889
1890 case ETHTOOL_ID_INACTIVE:
Bruce Allan4662e822008-08-26 18:37:06 -07001891 if (hw->phy.type == e1000_phy_ife)
1892 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001893 hw->mac.ops.led_off(hw);
1894 hw->mac.ops.cleanup_led(hw);
1895 break;
1896
1897 case ETHTOOL_ID_ON:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001898 hw->mac.ops.led_on(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001899 break;
1900
1901 case ETHTOOL_ID_OFF:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001902 hw->mac.ops.led_off(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001903 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001904 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001905 return 0;
1906}
1907
Auke Kokde5b3072008-04-23 11:09:08 -07001908static int e1000_get_coalesce(struct net_device *netdev,
1909 struct ethtool_coalesce *ec)
1910{
1911 struct e1000_adapter *adapter = netdev_priv(netdev);
1912
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001913 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07001914 ec->rx_coalesce_usecs = adapter->itr_setting;
1915 else
1916 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1917
1918 return 0;
1919}
1920
1921static int e1000_set_coalesce(struct net_device *netdev,
1922 struct ethtool_coalesce *ec)
1923{
1924 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokde5b3072008-04-23 11:09:08 -07001925
1926 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001927 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07001928 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1929 (ec->rx_coalesce_usecs == 2))
1930 return -EINVAL;
1931
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001932 if (ec->rx_coalesce_usecs == 4) {
Bruce Allan06a402e2012-08-17 06:17:57 +00001933 adapter->itr_setting = 4;
1934 adapter->itr = adapter->itr_setting;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001935 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07001936 adapter->itr = 20000;
1937 adapter->itr_setting = ec->rx_coalesce_usecs;
1938 } else {
1939 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1940 adapter->itr_setting = adapter->itr & ~3;
1941 }
1942
1943 if (adapter->itr_setting != 0)
Matthew Vick22a4cca2012-07-12 00:02:42 +00001944 e1000e_write_itr(adapter, adapter->itr);
Auke Kokde5b3072008-04-23 11:09:08 -07001945 else
Matthew Vick22a4cca2012-07-12 00:02:42 +00001946 e1000e_write_itr(adapter, 0);
Auke Kokde5b3072008-04-23 11:09:08 -07001947
1948 return 0;
1949}
1950
Auke Kokbc7f75f2007-09-17 12:30:59 -07001951static int e1000_nway_reset(struct net_device *netdev)
1952{
1953 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan5962bc22011-01-20 06:58:07 +00001954
1955 if (!netif_running(netdev))
1956 return -EAGAIN;
1957
1958 if (!adapter->hw.mac.autoneg)
1959 return -EINVAL;
1960
1961 e1000e_reinit_locked(adapter);
1962
Auke Kokbc7f75f2007-09-17 12:30:59 -07001963 return 0;
1964}
1965
Auke Kokbc7f75f2007-09-17 12:30:59 -07001966static void e1000_get_ethtool_stats(struct net_device *netdev,
Bruce Allan8bb62862013-01-16 08:46:49 +00001967 struct ethtool_stats __always_unused *stats,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001968 u64 *data)
1969{
1970 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001971 struct rtnl_link_stats64 net_stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001972 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001973 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001974
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001975 e1000e_get_stats64(netdev, &net_stats);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001976 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001977 switch (e1000_gstrings_stats[i].type) {
1978 case NETDEV_STATS:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001979 p = (char *) &net_stats +
Bruce Allanf0ff4392013-02-20 04:05:39 +00001980 e1000_gstrings_stats[i].stat_offset;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001981 break;
1982 case E1000_STATS:
1983 p = (char *) adapter +
Bruce Allanf0ff4392013-02-20 04:05:39 +00001984 e1000_gstrings_stats[i].stat_offset;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001985 break;
Bruce Allan61c75812010-12-09 23:04:25 +00001986 default:
1987 data[i] = 0;
1988 continue;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001989 }
1990
Auke Kokbc7f75f2007-09-17 12:30:59 -07001991 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
Bruce Allanf0ff4392013-02-20 04:05:39 +00001992 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001993 }
1994}
1995
Bruce Allan8bb62862013-01-16 08:46:49 +00001996static void e1000_get_strings(struct net_device __always_unused *netdev,
1997 u32 stringset, u8 *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001998{
1999 u8 *p = data;
2000 int i;
2001
2002 switch (stringset) {
2003 case ETH_SS_TEST:
Bruce Allan5c1bda02011-01-19 04:23:39 +00002004 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002005 break;
2006 case ETH_SS_STATS:
2007 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
2008 memcpy(p, e1000_gstrings_stats[i].stat_string,
2009 ETH_GSTRING_LEN);
2010 p += ETH_GSTRING_LEN;
2011 }
2012 break;
2013 }
2014}
2015
Bruce Allan70495a52012-01-11 01:26:50 +00002016static int e1000_get_rxnfc(struct net_device *netdev,
Bruce Allan8bb62862013-01-16 08:46:49 +00002017 struct ethtool_rxnfc *info,
2018 u32 __always_unused *rule_locs)
Bruce Allan70495a52012-01-11 01:26:50 +00002019{
2020 info->data = 0;
2021
2022 switch (info->cmd) {
2023 case ETHTOOL_GRXFH: {
2024 struct e1000_adapter *adapter = netdev_priv(netdev);
2025 struct e1000_hw *hw = &adapter->hw;
2026 u32 mrqc = er32(MRQC);
2027
2028 if (!(mrqc & E1000_MRQC_RSS_FIELD_MASK))
2029 return 0;
2030
2031 switch (info->flow_type) {
2032 case TCP_V4_FLOW:
2033 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP)
2034 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2035 /* fall through */
2036 case UDP_V4_FLOW:
2037 case SCTP_V4_FLOW:
2038 case AH_ESP_V4_FLOW:
2039 case IPV4_FLOW:
2040 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4)
2041 info->data |= RXH_IP_SRC | RXH_IP_DST;
2042 break;
2043 case TCP_V6_FLOW:
2044 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP)
2045 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2046 /* fall through */
2047 case UDP_V6_FLOW:
2048 case SCTP_V6_FLOW:
2049 case AH_ESP_V6_FLOW:
2050 case IPV6_FLOW:
2051 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6)
2052 info->data |= RXH_IP_SRC | RXH_IP_DST;
2053 break;
2054 default:
2055 break;
2056 }
2057 return 0;
2058 }
2059 default:
2060 return -EOPNOTSUPP;
2061 }
2062}
2063
Bruce Allan203e4152012-12-05 08:40:59 +00002064static int e1000e_get_eee(struct net_device *netdev, struct ethtool_eee *edata)
2065{
2066 struct e1000_adapter *adapter = netdev_priv(netdev);
2067 struct e1000_hw *hw = &adapter->hw;
2068 u16 cap_addr, adv_addr, lpa_addr, pcs_stat_addr, phy_data, lpi_ctrl;
2069 u32 status, ret_val;
2070
2071 if (!(adapter->flags & FLAG_IS_ICH) ||
2072 !(adapter->flags2 & FLAG2_HAS_EEE))
2073 return -EOPNOTSUPP;
2074
2075 switch (hw->phy.type) {
2076 case e1000_phy_82579:
2077 cap_addr = I82579_EEE_CAPABILITY;
2078 adv_addr = I82579_EEE_ADVERTISEMENT;
2079 lpa_addr = I82579_EEE_LP_ABILITY;
2080 pcs_stat_addr = I82579_EEE_PCS_STATUS;
2081 break;
2082 case e1000_phy_i217:
2083 cap_addr = I217_EEE_CAPABILITY;
2084 adv_addr = I217_EEE_ADVERTISEMENT;
2085 lpa_addr = I217_EEE_LP_ABILITY;
2086 pcs_stat_addr = I217_EEE_PCS_STATUS;
2087 break;
2088 default:
2089 return -EOPNOTSUPP;
2090 }
2091
2092 ret_val = hw->phy.ops.acquire(hw);
2093 if (ret_val)
2094 return -EBUSY;
2095
2096 /* EEE Capability */
2097 ret_val = e1000_read_emi_reg_locked(hw, cap_addr, &phy_data);
2098 if (ret_val)
2099 goto release;
2100 edata->supported = mmd_eee_cap_to_ethtool_sup_t(phy_data);
2101
2102 /* EEE Advertised */
2103 ret_val = e1000_read_emi_reg_locked(hw, adv_addr, &phy_data);
2104 if (ret_val)
2105 goto release;
2106 edata->advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
2107
2108 /* EEE Link Partner Advertised */
2109 ret_val = e1000_read_emi_reg_locked(hw, lpa_addr, &phy_data);
2110 if (ret_val)
2111 goto release;
2112 edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
2113
2114 /* EEE PCS Status */
2115 ret_val = e1000_read_emi_reg_locked(hw, pcs_stat_addr, &phy_data);
2116 if (hw->phy.type == e1000_phy_82579)
2117 phy_data <<= 8;
2118
2119release:
2120 hw->phy.ops.release(hw);
2121 if (ret_val)
2122 return -ENODATA;
2123
2124 e1e_rphy(hw, I82579_LPI_CTRL, &lpi_ctrl);
2125 status = er32(STATUS);
2126
2127 /* Result of the EEE auto negotiation - there is no register that
2128 * has the status of the EEE negotiation so do a best-guess based
2129 * on whether both Tx and Rx LPI indications have been received or
2130 * base it on the link speed, the EEE advertised speeds on both ends
2131 * and the speeds on which EEE is enabled locally.
2132 */
2133 if (((phy_data & E1000_EEE_TX_LPI_RCVD) &&
2134 (phy_data & E1000_EEE_RX_LPI_RCVD)) ||
2135 ((status & E1000_STATUS_SPEED_100) &&
2136 (edata->advertised & ADVERTISED_100baseT_Full) &&
2137 (edata->lp_advertised & ADVERTISED_100baseT_Full) &&
2138 (lpi_ctrl & I82579_LPI_CTRL_100_ENABLE)) ||
2139 ((status & E1000_STATUS_SPEED_1000) &&
2140 (edata->advertised & ADVERTISED_1000baseT_Full) &&
2141 (edata->lp_advertised & ADVERTISED_1000baseT_Full) &&
2142 (lpi_ctrl & I82579_LPI_CTRL_1000_ENABLE)))
2143 edata->eee_active = true;
2144
2145 edata->eee_enabled = !hw->dev_spec.ich8lan.eee_disable;
2146 edata->tx_lpi_enabled = true;
2147 edata->tx_lpi_timer = er32(LPIC) >> E1000_LPIC_LPIET_SHIFT;
2148
2149 return 0;
2150}
2151
2152static int e1000e_set_eee(struct net_device *netdev, struct ethtool_eee *edata)
2153{
2154 struct e1000_adapter *adapter = netdev_priv(netdev);
2155 struct e1000_hw *hw = &adapter->hw;
2156 struct ethtool_eee eee_curr;
2157 s32 ret_val;
2158
2159 if (!(adapter->flags & FLAG_IS_ICH) ||
2160 !(adapter->flags2 & FLAG2_HAS_EEE))
2161 return -EOPNOTSUPP;
2162
2163 ret_val = e1000e_get_eee(netdev, &eee_curr);
2164 if (ret_val)
2165 return ret_val;
2166
2167 if (eee_curr.advertised != edata->advertised) {
2168 e_err("Setting EEE advertisement is not supported\n");
2169 return -EINVAL;
2170 }
2171
2172 if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
2173 e_err("Setting EEE tx-lpi is not supported\n");
2174 return -EINVAL;
2175 }
2176
2177 if (eee_curr.tx_lpi_timer != edata->tx_lpi_timer) {
2178 e_err("Setting EEE Tx LPI timer is not supported\n");
2179 return -EINVAL;
2180 }
2181
2182 if (hw->dev_spec.ich8lan.eee_disable != !edata->eee_enabled) {
2183 hw->dev_spec.ich8lan.eee_disable = !edata->eee_enabled;
2184
2185 /* reset the link */
2186 if (netif_running(netdev))
2187 e1000e_reinit_locked(adapter);
2188 else
2189 e1000e_reset(adapter);
2190 }
2191
2192 return 0;
2193}
2194
Bruce Allanb67e1912012-12-27 08:32:33 +00002195static int e1000e_get_ts_info(struct net_device *netdev,
2196 struct ethtool_ts_info *info)
2197{
2198 struct e1000_adapter *adapter = netdev_priv(netdev);
2199
2200 ethtool_op_get_ts_info(netdev, info);
2201
2202 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
2203 return 0;
2204
2205 info->so_timestamping |= (SOF_TIMESTAMPING_TX_HARDWARE |
2206 SOF_TIMESTAMPING_RX_HARDWARE |
2207 SOF_TIMESTAMPING_RAW_HARDWARE);
2208
2209 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
2210
2211 info->rx_filters = ((1 << HWTSTAMP_FILTER_NONE) |
Bruce Alland89777b2013-01-19 01:09:58 +00002212 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
2213 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
2214 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
2215 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
2216 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
2217 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
2218 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
2219 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
2220 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
Bruce Allanb67e1912012-12-27 08:32:33 +00002221 (1 << HWTSTAMP_FILTER_ALL));
2222
Bruce Alland89777b2013-01-19 01:09:58 +00002223 if (adapter->ptp_clock)
2224 info->phc_index = ptp_clock_index(adapter->ptp_clock);
2225
Bruce Allanb67e1912012-12-27 08:32:33 +00002226 return 0;
2227}
2228
Auke Kokbc7f75f2007-09-17 12:30:59 -07002229static const struct ethtool_ops e1000_ethtool_ops = {
2230 .get_settings = e1000_get_settings,
2231 .set_settings = e1000_set_settings,
2232 .get_drvinfo = e1000_get_drvinfo,
2233 .get_regs_len = e1000_get_regs_len,
2234 .get_regs = e1000_get_regs,
2235 .get_wol = e1000_get_wol,
2236 .set_wol = e1000_set_wol,
2237 .get_msglevel = e1000_get_msglevel,
2238 .set_msglevel = e1000_set_msglevel,
2239 .nway_reset = e1000_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00002240 .get_link = ethtool_op_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002241 .get_eeprom_len = e1000_get_eeprom_len,
2242 .get_eeprom = e1000_get_eeprom,
2243 .set_eeprom = e1000_set_eeprom,
2244 .get_ringparam = e1000_get_ringparam,
2245 .set_ringparam = e1000_set_ringparam,
2246 .get_pauseparam = e1000_get_pauseparam,
2247 .set_pauseparam = e1000_set_pauseparam,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002248 .self_test = e1000_diag_test,
2249 .get_strings = e1000_get_strings,
Bruce Allandbf80dc2011-04-16 00:34:40 +00002250 .set_phys_id = e1000_set_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002251 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07002252 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07002253 .get_coalesce = e1000_get_coalesce,
2254 .set_coalesce = e1000_set_coalesce,
Bruce Allan70495a52012-01-11 01:26:50 +00002255 .get_rxnfc = e1000_get_rxnfc,
Bruce Allanb67e1912012-12-27 08:32:33 +00002256 .get_ts_info = e1000e_get_ts_info,
Bruce Allan203e4152012-12-05 08:40:59 +00002257 .get_eee = e1000e_get_eee,
2258 .set_eee = e1000e_set_eee,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002259};
2260
2261void e1000e_set_ethtool_ops(struct net_device *netdev)
2262{
2263 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
2264}