blob: 003cbd6057990050dd3bda971b9ad77ee6c5e17e [file] [log] [blame]
David Ertmane78b80b2014-02-04 01:56:06 +00001/* Intel PRO/1000 Linux driver
Yanir Lubetkin529498c2015-06-02 17:05:50 +03002 * Copyright(c) 1999 - 2015 Intel Corporation.
David Ertmane78b80b2014-02-04 01:56:06 +00003 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
15 *
16 * Contact Information:
17 * Linux NICS <linux.nics@intel.com>
18 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
19 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
20 */
Auke Kokbc7f75f2007-09-17 12:30:59 -070021
22/* ethtool support for e1000 */
23
24#include <linux/netdevice.h>
Bruce Allan9fb7a5f2011-07-29 05:52:51 +000025#include <linux/interrupt.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070026#include <linux/ethtool.h>
27#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090028#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070029#include <linux/delay.h>
David S. Millerc85c21a2012-01-26 16:25:55 -050030#include <linux/vmalloc.h>
Konstantin Khlebnikove60b22c2013-03-05 09:43:09 +000031#include <linux/pm_runtime.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070032
33#include "e1000.h"
34
Bruce Allan362e20c2013-02-20 04:05:45 +000035enum { NETDEV_STATS, E1000_STATS };
Ajit Khapardee0f36a92009-10-13 01:45:09 +000036
Auke Kokbc7f75f2007-09-17 12:30:59 -070037struct e1000_stats {
38 char stat_string[ETH_GSTRING_LEN];
Ajit Khapardee0f36a92009-10-13 01:45:09 +000039 int type;
Auke Kokbc7f75f2007-09-17 12:30:59 -070040 int sizeof_stat;
41 int stat_offset;
42};
43
Bruce Allanf0f1a172010-12-11 05:53:32 +000044#define E1000_STAT(str, m) { \
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000045 .stat_string = str, \
46 .type = E1000_STATS, \
47 .sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
48 .stat_offset = offsetof(struct e1000_adapter, m) }
Bruce Allanf0f1a172010-12-11 05:53:32 +000049#define E1000_NETDEV_STAT(str, m) { \
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000050 .stat_string = str, \
51 .type = NETDEV_STATS, \
52 .sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \
53 .stat_offset = offsetof(struct rtnl_link_stats64, m) }
Ajit Khapardee0f36a92009-10-13 01:45:09 +000054
Auke Kokbc7f75f2007-09-17 12:30:59 -070055static const struct e1000_stats e1000_gstrings_stats[] = {
Bruce Allanf0f1a172010-12-11 05:53:32 +000056 E1000_STAT("rx_packets", stats.gprc),
57 E1000_STAT("tx_packets", stats.gptc),
58 E1000_STAT("rx_bytes", stats.gorc),
59 E1000_STAT("tx_bytes", stats.gotc),
60 E1000_STAT("rx_broadcast", stats.bprc),
61 E1000_STAT("tx_broadcast", stats.bptc),
62 E1000_STAT("rx_multicast", stats.mprc),
63 E1000_STAT("tx_multicast", stats.mptc),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000064 E1000_NETDEV_STAT("rx_errors", rx_errors),
65 E1000_NETDEV_STAT("tx_errors", tx_errors),
66 E1000_NETDEV_STAT("tx_dropped", tx_dropped),
Bruce Allanf0f1a172010-12-11 05:53:32 +000067 E1000_STAT("multicast", stats.mprc),
68 E1000_STAT("collisions", stats.colc),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000069 E1000_NETDEV_STAT("rx_length_errors", rx_length_errors),
70 E1000_NETDEV_STAT("rx_over_errors", rx_over_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000071 E1000_STAT("rx_crc_errors", stats.crcerrs),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000072 E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000073 E1000_STAT("rx_no_buffer_count", stats.rnbc),
74 E1000_STAT("rx_missed_errors", stats.mpc),
75 E1000_STAT("tx_aborted_errors", stats.ecol),
76 E1000_STAT("tx_carrier_errors", stats.tncrs),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000077 E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
78 E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000079 E1000_STAT("tx_window_errors", stats.latecol),
80 E1000_STAT("tx_abort_late_coll", stats.latecol),
81 E1000_STAT("tx_deferred_ok", stats.dc),
82 E1000_STAT("tx_single_coll_ok", stats.scc),
83 E1000_STAT("tx_multi_coll_ok", stats.mcc),
84 E1000_STAT("tx_timeout_count", tx_timeout_count),
85 E1000_STAT("tx_restart_queue", restart_queue),
86 E1000_STAT("rx_long_length_errors", stats.roc),
87 E1000_STAT("rx_short_length_errors", stats.ruc),
88 E1000_STAT("rx_align_errors", stats.algnerrc),
89 E1000_STAT("tx_tcp_seg_good", stats.tsctc),
90 E1000_STAT("tx_tcp_seg_failed", stats.tsctfc),
91 E1000_STAT("rx_flow_control_xon", stats.xonrxc),
92 E1000_STAT("rx_flow_control_xoff", stats.xoffrxc),
93 E1000_STAT("tx_flow_control_xon", stats.xontxc),
94 E1000_STAT("tx_flow_control_xoff", stats.xofftxc),
Bruce Allanf0f1a172010-12-11 05:53:32 +000095 E1000_STAT("rx_csum_offload_good", hw_csum_good),
96 E1000_STAT("rx_csum_offload_errors", hw_csum_err),
97 E1000_STAT("rx_header_split", rx_hdr_split),
98 E1000_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),
99 E1000_STAT("tx_smbus", stats.mgptc),
100 E1000_STAT("rx_smbus", stats.mgprc),
101 E1000_STAT("dropped_smbus", stats.mgpdc),
102 E1000_STAT("rx_dma_failed", rx_dma_failed),
103 E1000_STAT("tx_dma_failed", tx_dma_failed),
Bruce Allanb67e1912012-12-27 08:32:33 +0000104 E1000_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Bruce Allan94fb8482013-01-23 09:00:03 +0000105 E1000_STAT("uncorr_ecc_errors", uncorr_errors),
106 E1000_STAT("corr_ecc_errors", corr_errors),
Jakub Kicinski59c871c2014-03-15 14:55:00 +0000107 E1000_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
Jacob Kellercff57142017-05-03 10:28:57 -0700108 E1000_STAT("tx_hwtstamp_skipped", tx_hwtstamp_skipped),
Auke Kokbc7f75f2007-09-17 12:30:59 -0700109};
110
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200111#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700112#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
113static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
114 "Register test (offline)", "Eeprom test (offline)",
115 "Interrupt test (offline)", "Loopback test (offline)",
116 "Link test (on/offline)"
117};
Bruce Allanfc830b72013-02-20 04:06:11 +0000118
Bruce Allanad680762008-03-28 09:15:03 -0700119#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700120
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100121static int e1000_get_link_ksettings(struct net_device *netdev,
122 struct ethtool_link_ksettings *cmd)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700123{
124 struct e1000_adapter *adapter = netdev_priv(netdev);
125 struct e1000_hw *hw = &adapter->hw;
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100126 u32 speed, supported, advertising;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700127
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700128 if (hw->phy.media_type == e1000_media_type_copper) {
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100129 supported = (SUPPORTED_10baseT_Half |
130 SUPPORTED_10baseT_Full |
131 SUPPORTED_100baseT_Half |
132 SUPPORTED_100baseT_Full |
133 SUPPORTED_1000baseT_Full |
134 SUPPORTED_Autoneg |
135 SUPPORTED_TP);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700136 if (hw->phy.type == e1000_phy_ife)
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100137 supported &= ~SUPPORTED_1000baseT_Full;
138 advertising = ADVERTISED_TP;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700139
140 if (hw->mac.autoneg == 1) {
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100141 advertising |= ADVERTISED_Autoneg;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700142 /* the e1000 autoneg seems to match ethtool nicely */
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100143 advertising |= hw->phy.autoneg_advertised;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700144 }
145
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100146 cmd->base.port = PORT_TP;
147 cmd->base.phy_address = hw->phy.addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700148 } else {
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100149 supported = (SUPPORTED_1000baseT_Full |
150 SUPPORTED_FIBRE |
151 SUPPORTED_Autoneg);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700152
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100153 advertising = (ADVERTISED_1000baseT_Full |
154 ADVERTISED_FIBRE |
155 ADVERTISED_Autoneg);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700156
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100157 cmd->base.port = PORT_FIBRE;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700158 }
159
Jiri Pirko537fae02014-06-06 14:17:00 +0200160 speed = SPEED_UNKNOWN;
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100161 cmd->base.duplex = DUPLEX_UNKNOWN;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700162
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000163 if (netif_running(netdev)) {
164 if (netif_carrier_ok(netdev)) {
David Decotigny70739492011-04-27 18:32:40 +0000165 speed = adapter->link_speed;
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100166 cmd->base.duplex = adapter->link_duplex - 1;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000167 }
Bruce Allan3ef672a2013-06-27 02:44:44 +0000168 } else if (!pm_runtime_suspended(netdev->dev.parent)) {
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000169 u32 status = er32(STATUS);
David Ertman6cf08d12014-04-05 06:07:00 +0000170
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000171 if (status & E1000_STATUS_LU) {
172 if (status & E1000_STATUS_SPEED_1000)
David Decotigny70739492011-04-27 18:32:40 +0000173 speed = SPEED_1000;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000174 else if (status & E1000_STATUS_SPEED_100)
David Decotigny70739492011-04-27 18:32:40 +0000175 speed = SPEED_100;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000176 else
David Decotigny70739492011-04-27 18:32:40 +0000177 speed = SPEED_10;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000178
179 if (status & E1000_STATUS_FD)
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100180 cmd->base.duplex = DUPLEX_FULL;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000181 else
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100182 cmd->base.duplex = DUPLEX_HALF;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000183 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700184 }
185
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100186 cmd->base.speed = speed;
187 cmd->base.autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -0700188 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000189
190 /* MDI-X => 2; MDI =>1; Invalid =>0 */
191 if ((hw->phy.media_type == e1000_media_type_copper) &&
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000192 netif_carrier_ok(netdev))
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100193 cmd->base.eth_tp_mdix = hw->phy.is_mdix ?
194 ETH_TP_MDI_X : ETH_TP_MDI;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000195 else
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100196 cmd->base.eth_tp_mdix = ETH_TP_MDI_INVALID;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000197
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000198 if (hw->phy.mdix == AUTO_ALL_MODES)
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100199 cmd->base.eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000200 else
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100201 cmd->base.eth_tp_mdix_ctrl = hw->phy.mdix;
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000202
Steve Shihe11f3032016-04-05 11:30:03 -0700203 if (hw->phy.media_type != e1000_media_type_copper)
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100204 cmd->base.eth_tp_mdix_ctrl = ETH_TP_MDI_INVALID;
205
206 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
207 supported);
208 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
209 advertising);
Steve Shihe11f3032016-04-05 11:30:03 -0700210
Auke Kokbc7f75f2007-09-17 12:30:59 -0700211 return 0;
212}
213
David Decotigny14ad2512011-04-27 18:32:43 +0000214static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700215{
216 struct e1000_mac_info *mac = &adapter->hw.mac;
217
218 mac->autoneg = 0;
219
David Decotigny14ad2512011-04-27 18:32:43 +0000220 /* Make sure dplx is at most 1 bit and lsb of speed is not set
Bruce Allane921eb12012-11-28 09:28:37 +0000221 * for the switch() below to work
222 */
David Decotigny14ad2512011-04-27 18:32:43 +0000223 if ((spd & 1) || (dplx & ~1))
224 goto err_inval;
225
Auke Kokbc7f75f2007-09-17 12:30:59 -0700226 /* Fiber NICs only allow 1000 gbps Full duplex */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700227 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
Bruce Allane5fe2542013-02-20 04:06:27 +0000228 (spd != SPEED_1000) && (dplx != DUPLEX_FULL)) {
David Decotigny14ad2512011-04-27 18:32:43 +0000229 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700230 }
231
David Decotigny14ad2512011-04-27 18:32:43 +0000232 switch (spd + dplx) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700233 case SPEED_10 + DUPLEX_HALF:
234 mac->forced_speed_duplex = ADVERTISE_10_HALF;
235 break;
236 case SPEED_10 + DUPLEX_FULL:
237 mac->forced_speed_duplex = ADVERTISE_10_FULL;
238 break;
239 case SPEED_100 + DUPLEX_HALF:
240 mac->forced_speed_duplex = ADVERTISE_100_HALF;
241 break;
242 case SPEED_100 + DUPLEX_FULL:
243 mac->forced_speed_duplex = ADVERTISE_100_FULL;
244 break;
245 case SPEED_1000 + DUPLEX_FULL:
Steve Shihe11f3032016-04-05 11:30:03 -0700246 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
247 mac->autoneg = 1;
248 adapter->hw.phy.autoneg_advertised =
249 ADVERTISE_1000_FULL;
250 } else {
251 mac->forced_speed_duplex = ADVERTISE_1000_FULL;
252 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700253 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +0000254 case SPEED_1000 + DUPLEX_HALF: /* not supported */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700255 default:
David Decotigny14ad2512011-04-27 18:32:43 +0000256 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700257 }
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000258
259 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
260 adapter->hw.phy.mdix = AUTO_ALL_MODES;
261
Auke Kokbc7f75f2007-09-17 12:30:59 -0700262 return 0;
David Decotigny14ad2512011-04-27 18:32:43 +0000263
264err_inval:
265 e_err("Unsupported Speed/Duplex configuration\n");
266 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700267}
268
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100269static int e1000_set_link_ksettings(struct net_device *netdev,
270 const struct ethtool_link_ksettings *cmd)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700271{
272 struct e1000_adapter *adapter = netdev_priv(netdev);
273 struct e1000_hw *hw = &adapter->hw;
Bruce Allan3ef672a2013-06-27 02:44:44 +0000274 int ret_val = 0;
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100275 u32 advertising;
276
277 ethtool_convert_link_mode_to_legacy_u32(&advertising,
278 cmd->link_modes.advertising);
Bruce Allan3ef672a2013-06-27 02:44:44 +0000279
280 pm_runtime_get_sync(netdev->dev.parent);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700281
Bruce Allane921eb12012-11-28 09:28:37 +0000282 /* When SoL/IDER sessions are active, autoneg/speed/duplex
Bruce Allanad680762008-03-28 09:15:03 -0700283 * cannot be changed
284 */
Bruce Allan470a5422012-05-26 06:08:48 +0000285 if (hw->phy.ops.check_reset_block &&
286 hw->phy.ops.check_reset_block(hw)) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000287 e_err("Cannot change link characteristics when SoL/IDER is active.\n");
Bruce Allan3ef672a2013-06-27 02:44:44 +0000288 ret_val = -EINVAL;
289 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700290 }
291
Bruce Allane921eb12012-11-28 09:28:37 +0000292 /* MDI setting is only allowed when autoneg enabled because
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000293 * some hardware doesn't allow MDI setting when speed or
294 * duplex is forced.
295 */
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100296 if (cmd->base.eth_tp_mdix_ctrl) {
Bruce Allan3ef672a2013-06-27 02:44:44 +0000297 if (hw->phy.media_type != e1000_media_type_copper) {
298 ret_val = -EOPNOTSUPP;
299 goto out;
300 }
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000301
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100302 if ((cmd->base.eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) &&
303 (cmd->base.autoneg != AUTONEG_ENABLE)) {
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000304 e_err("forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
Bruce Allan3ef672a2013-06-27 02:44:44 +0000305 ret_val = -EINVAL;
306 goto out;
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000307 }
308 }
309
Auke Kokbc7f75f2007-09-17 12:30:59 -0700310 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000311 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700312
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100313 if (cmd->base.autoneg == AUTONEG_ENABLE) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700314 hw->mac.autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700315 if (hw->phy.media_type == e1000_media_type_fiber)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700316 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
Bruce Allanf0ff4392013-02-20 04:05:39 +0000317 ADVERTISED_FIBRE | ADVERTISED_Autoneg;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700318 else
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100319 hw->phy.autoneg_advertised = advertising |
Bruce Allanf0ff4392013-02-20 04:05:39 +0000320 ADVERTISED_TP | ADVERTISED_Autoneg;
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100321 advertising = hw->phy.autoneg_advertised;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700322 if (adapter->fc_autoneg)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800323 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700324 } else {
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100325 u32 speed = cmd->base.speed;
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000326 /* calling this overrides forced MDI setting */
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100327 if (e1000_set_spd_dplx(adapter, speed, cmd->base.duplex)) {
Bruce Allan3ef672a2013-06-27 02:44:44 +0000328 ret_val = -EINVAL;
329 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700330 }
331 }
332
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000333 /* MDI-X => 2; MDI => 1; Auto => 3 */
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100334 if (cmd->base.eth_tp_mdix_ctrl) {
Bruce Allane921eb12012-11-28 09:28:37 +0000335 /* fix up the value for auto (3 => 0) as zero is mapped
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000336 * internally to auto
337 */
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100338 if (cmd->base.eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000339 hw->phy.mdix = AUTO_ALL_MODES;
340 else
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100341 hw->phy.mdix = cmd->base.eth_tp_mdix_ctrl;
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000342 }
343
Auke Kokbc7f75f2007-09-17 12:30:59 -0700344 /* reset the link */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700345 if (netif_running(adapter->netdev)) {
David Ertman28002092014-02-14 07:16:41 +0000346 e1000e_down(adapter, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700347 e1000e_up(adapter);
Bruce Allana7a1d9d2013-01-24 00:50:18 +0000348 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700349 e1000e_reset(adapter);
Bruce Allana7a1d9d2013-01-24 00:50:18 +0000350 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700351
Bruce Allan3ef672a2013-06-27 02:44:44 +0000352out:
353 pm_runtime_put_sync(netdev->dev.parent);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700354 clear_bit(__E1000_RESETTING, &adapter->state);
Bruce Allan3ef672a2013-06-27 02:44:44 +0000355 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700356}
357
358static void e1000_get_pauseparam(struct net_device *netdev,
359 struct ethtool_pauseparam *pause)
360{
361 struct e1000_adapter *adapter = netdev_priv(netdev);
362 struct e1000_hw *hw = &adapter->hw;
363
364 pause->autoneg =
Bruce Allanf0ff4392013-02-20 04:05:39 +0000365 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700366
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800367 if (hw->fc.current_mode == e1000_fc_rx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700368 pause->rx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800369 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700370 pause->tx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800371 } else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700372 pause->rx_pause = 1;
373 pause->tx_pause = 1;
374 }
375}
376
377static int e1000_set_pauseparam(struct net_device *netdev,
378 struct ethtool_pauseparam *pause)
379{
380 struct e1000_adapter *adapter = netdev_priv(netdev);
381 struct e1000_hw *hw = &adapter->hw;
382 int retval = 0;
383
384 adapter->fc_autoneg = pause->autoneg;
385
386 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000387 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700388
Bruce Allan3ef672a2013-06-27 02:44:44 +0000389 pm_runtime_get_sync(netdev->dev.parent);
390
Auke Kokbc7f75f2007-09-17 12:30:59 -0700391 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800392 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700393 if (netif_running(adapter->netdev)) {
David Ertman28002092014-02-14 07:16:41 +0000394 e1000e_down(adapter, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700395 e1000e_up(adapter);
396 } else {
397 e1000e_reset(adapter);
398 }
399 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800400 if (pause->rx_pause && pause->tx_pause)
401 hw->fc.requested_mode = e1000_fc_full;
402 else if (pause->rx_pause && !pause->tx_pause)
403 hw->fc.requested_mode = e1000_fc_rx_pause;
404 else if (!pause->rx_pause && pause->tx_pause)
405 hw->fc.requested_mode = e1000_fc_tx_pause;
406 else if (!pause->rx_pause && !pause->tx_pause)
407 hw->fc.requested_mode = e1000_fc_none;
408
409 hw->fc.current_mode = hw->fc.requested_mode;
410
Bruce Allan945eb312009-10-28 18:28:30 +0000411 if (hw->phy.media_type == e1000_media_type_fiber) {
412 retval = hw->mac.ops.setup_link(hw);
413 /* implicit goto out */
414 } else {
415 retval = e1000e_force_mac_fc(hw);
416 if (retval)
417 goto out;
418 e1000e_set_fc_watermarks(hw);
419 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700420 }
421
Bruce Allan945eb312009-10-28 18:28:30 +0000422out:
Bruce Allan3ef672a2013-06-27 02:44:44 +0000423 pm_runtime_put_sync(netdev->dev.parent);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700424 clear_bit(__E1000_RESETTING, &adapter->state);
425 return retval;
426}
427
Auke Kokbc7f75f2007-09-17 12:30:59 -0700428static u32 e1000_get_msglevel(struct net_device *netdev)
429{
430 struct e1000_adapter *adapter = netdev_priv(netdev);
431 return adapter->msg_enable;
432}
433
434static void e1000_set_msglevel(struct net_device *netdev, u32 data)
435{
436 struct e1000_adapter *adapter = netdev_priv(netdev);
437 adapter->msg_enable = data;
438}
439
Bruce Allan8bb62862013-01-16 08:46:49 +0000440static int e1000_get_regs_len(struct net_device __always_unused *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700441{
Bruce Allane80bd1d2013-05-01 01:19:46 +0000442#define E1000_REGS_LEN 32 /* overestimate */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700443 return E1000_REGS_LEN * sizeof(u32);
444}
445
446static void e1000_get_regs(struct net_device *netdev,
447 struct ethtool_regs *regs, void *p)
448{
449 struct e1000_adapter *adapter = netdev_priv(netdev);
450 struct e1000_hw *hw = &adapter->hw;
451 u32 *regs_buff = p;
452 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700453
Bruce Allan3ef672a2013-06-27 02:44:44 +0000454 pm_runtime_get_sync(netdev->dev.parent);
455
Auke Kokbc7f75f2007-09-17 12:30:59 -0700456 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
457
Jacob Keller18dd2392016-04-13 16:08:32 -0700458 regs->version = (1u << 24) |
459 (adapter->pdev->revision << 16) |
460 adapter->pdev->device;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700461
Bruce Allane80bd1d2013-05-01 01:19:46 +0000462 regs_buff[0] = er32(CTRL);
463 regs_buff[1] = er32(STATUS);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700464
Bruce Allane80bd1d2013-05-01 01:19:46 +0000465 regs_buff[2] = er32(RCTL);
466 regs_buff[3] = er32(RDLEN(0));
467 regs_buff[4] = er32(RDH(0));
468 regs_buff[5] = er32(RDT(0));
469 regs_buff[6] = er32(RDTR);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700470
Bruce Allane80bd1d2013-05-01 01:19:46 +0000471 regs_buff[7] = er32(TCTL);
472 regs_buff[8] = er32(TDLEN(0));
473 regs_buff[9] = er32(TDH(0));
Bruce Allan1e360522012-03-20 03:48:13 +0000474 regs_buff[10] = er32(TDT(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700475 regs_buff[11] = er32(TIDV);
476
Bruce Allane80bd1d2013-05-01 01:19:46 +0000477 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700478
479 /* ethtool doesn't use anything past this point, so all this
Bruce Allane921eb12012-11-28 09:28:37 +0000480 * code is likely legacy junk for apps that may or may not exist
481 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700482 if (hw->phy.type == e1000_phy_m88) {
483 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
484 regs_buff[13] = (u32)phy_data; /* cable length */
485 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
486 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
487 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
488 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
489 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
490 regs_buff[18] = regs_buff[13]; /* cable polarity */
491 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
492 regs_buff[20] = regs_buff[17]; /* polarity correction */
493 /* phy receive errors */
494 regs_buff[22] = adapter->phy_stats.receive_errors;
495 regs_buff[23] = regs_buff[13]; /* mdix mode */
496 }
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000497 regs_buff[21] = 0; /* was idle_errors */
498 e1e_rphy(hw, MII_STAT1000, &phy_data);
499 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
500 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
Bruce Allan3ef672a2013-06-27 02:44:44 +0000501
502 pm_runtime_put_sync(netdev->dev.parent);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700503}
504
505static int e1000_get_eeprom_len(struct net_device *netdev)
506{
507 struct e1000_adapter *adapter = netdev_priv(netdev);
508 return adapter->hw.nvm.word_size * 2;
509}
510
511static int e1000_get_eeprom(struct net_device *netdev,
512 struct ethtool_eeprom *eeprom, u8 *bytes)
513{
514 struct e1000_adapter *adapter = netdev_priv(netdev);
515 struct e1000_hw *hw = &adapter->hw;
516 u16 *eeprom_buff;
517 int first_word;
518 int last_word;
519 int ret_val = 0;
520 u16 i;
521
522 if (eeprom->len == 0)
523 return -EINVAL;
524
525 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
526
527 first_word = eeprom->offset >> 1;
528 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
529
Bruce Allan17e813e2013-02-20 04:06:01 +0000530 eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
531 GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700532 if (!eeprom_buff)
533 return -ENOMEM;
534
Bruce Allan3ef672a2013-06-27 02:44:44 +0000535 pm_runtime_get_sync(netdev->dev.parent);
536
Auke Kokbc7f75f2007-09-17 12:30:59 -0700537 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
538 ret_val = e1000_read_nvm(hw, first_word,
539 last_word - first_word + 1,
540 eeprom_buff);
541 } else {
542 for (i = 0; i < last_word - first_word + 1; i++) {
543 ret_val = e1000_read_nvm(hw, first_word + i, 1,
Bruce Allan17e813e2013-02-20 04:06:01 +0000544 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800545 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700546 break;
547 }
548 }
549
Bruce Allan3ef672a2013-06-27 02:44:44 +0000550 pm_runtime_put_sync(netdev->dev.parent);
551
Bruce Allane2434552008-11-21 17:02:41 -0800552 if (ret_val) {
553 /* a read error occurred, throw away the result */
Roel Kluin8528b012009-12-01 15:54:24 +0000554 memset(eeprom_buff, 0xff, sizeof(u16) *
555 (last_word - first_word + 1));
Bruce Allane2434552008-11-21 17:02:41 -0800556 } else {
557 /* Device's eeprom is always little-endian, word addressable */
558 for (i = 0; i < last_word - first_word + 1; i++)
559 le16_to_cpus(&eeprom_buff[i]);
560 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700561
562 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
563 kfree(eeprom_buff);
564
565 return ret_val;
566}
567
568static int e1000_set_eeprom(struct net_device *netdev,
569 struct ethtool_eeprom *eeprom, u8 *bytes)
570{
571 struct e1000_adapter *adapter = netdev_priv(netdev);
572 struct e1000_hw *hw = &adapter->hw;
573 u16 *eeprom_buff;
574 void *ptr;
575 int max_len;
576 int first_word;
577 int last_word;
578 int ret_val = 0;
579 u16 i;
580
581 if (eeprom->len == 0)
582 return -EOPNOTSUPP;
583
Bruce Allanc29c3ba2013-02-20 04:05:50 +0000584 if (eeprom->magic !=
585 (adapter->pdev->vendor | (adapter->pdev->device << 16)))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700586 return -EFAULT;
587
Bruce Allan4a770352008-10-01 17:18:35 -0700588 if (adapter->flags & FLAG_READ_ONLY_NVM)
589 return -EINVAL;
590
Auke Kokbc7f75f2007-09-17 12:30:59 -0700591 max_len = hw->nvm.word_size * 2;
592
593 first_word = eeprom->offset >> 1;
594 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
595 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
596 if (!eeprom_buff)
597 return -ENOMEM;
598
599 ptr = (void *)eeprom_buff;
600
Bruce Allan3ef672a2013-06-27 02:44:44 +0000601 pm_runtime_get_sync(netdev->dev.parent);
602
Auke Kokbc7f75f2007-09-17 12:30:59 -0700603 if (eeprom->offset & 1) {
604 /* need read/modify/write of first changed EEPROM word */
605 /* only the second byte of the word is being modified */
606 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
607 ptr++;
608 }
Bruce Allan9e2d7652012-01-31 06:37:27 +0000609 if (((eeprom->offset + eeprom->len) & 1) && (!ret_val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700610 /* need read/modify/write of last changed EEPROM word */
611 /* only the first byte of the word is being modified */
612 ret_val = e1000_read_nvm(hw, last_word, 1,
Bruce Allan17e813e2013-02-20 04:06:01 +0000613 &eeprom_buff[last_word - first_word]);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700614
Bruce Allane2434552008-11-21 17:02:41 -0800615 if (ret_val)
616 goto out;
617
Auke Kokbc7f75f2007-09-17 12:30:59 -0700618 /* Device's eeprom is always little-endian, word addressable */
619 for (i = 0; i < last_word - first_word + 1; i++)
620 le16_to_cpus(&eeprom_buff[i]);
621
622 memcpy(ptr, bytes, eeprom->len);
623
624 for (i = 0; i < last_word - first_word + 1; i++)
Bruce Allane885d762012-01-31 06:37:32 +0000625 cpu_to_le16s(&eeprom_buff[i]);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700626
627 ret_val = e1000_write_nvm(hw, first_word,
628 last_word - first_word + 1, eeprom_buff);
629
Bruce Allane2434552008-11-21 17:02:41 -0800630 if (ret_val)
631 goto out;
632
Bruce Allane921eb12012-11-28 09:28:37 +0000633 /* Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800634 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700635 */
Bruce Allane2434552008-11-21 17:02:41 -0800636 if ((first_word <= NVM_CHECKSUM_REG) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +0000637 (hw->mac.type == e1000_82583) ||
638 (hw->mac.type == e1000_82574) ||
639 (hw->mac.type == e1000_82573))
Bruce Allane2434552008-11-21 17:02:41 -0800640 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700641
Bruce Allane2434552008-11-21 17:02:41 -0800642out:
Bruce Allan3ef672a2013-06-27 02:44:44 +0000643 pm_runtime_put_sync(netdev->dev.parent);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700644 kfree(eeprom_buff);
645 return ret_val;
646}
647
648static void e1000_get_drvinfo(struct net_device *netdev,
649 struct ethtool_drvinfo *drvinfo)
650{
651 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700652
Bruce Allane5fe2542013-02-20 04:06:27 +0000653 strlcpy(drvinfo->driver, e1000e_driver_name, sizeof(drvinfo->driver));
Rick Jones33a5ba12011-11-15 14:59:53 +0000654 strlcpy(drvinfo->version, e1000e_driver_version,
Rick Jones612a94d2011-11-14 08:13:25 +0000655 sizeof(drvinfo->version));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700656
Bruce Allane921eb12012-11-28 09:28:37 +0000657 /* EEPROM image version # is reported as firmware version # for
Bruce Allanad680762008-03-28 09:15:03 -0700658 * PCI-E controllers
659 */
Rick Jones612a94d2011-11-14 08:13:25 +0000660 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
Bruce Allan17e813e2013-02-20 04:06:01 +0000661 "%d.%d-%d",
662 (adapter->eeprom_vers & 0xF000) >> 12,
663 (adapter->eeprom_vers & 0x0FF0) >> 4,
664 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700665
Rick Jones612a94d2011-11-14 08:13:25 +0000666 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
667 sizeof(drvinfo->bus_info));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700668}
669
670static void e1000_get_ringparam(struct net_device *netdev,
671 struct ethtool_ringparam *ring)
672{
673 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700674
675 ring->rx_max_pending = E1000_MAX_RXD;
676 ring->tx_max_pending = E1000_MAX_TXD;
Bruce Allan508da422011-12-16 00:45:51 +0000677 ring->rx_pending = adapter->rx_ring_count;
678 ring->tx_pending = adapter->tx_ring_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700679}
680
681static int e1000_set_ringparam(struct net_device *netdev,
682 struct ethtool_ringparam *ring)
683{
684 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan508da422011-12-16 00:45:51 +0000685 struct e1000_ring *temp_tx = NULL, *temp_rx = NULL;
686 int err = 0, size = sizeof(struct e1000_ring);
687 bool set_tx = false, set_rx = false;
688 u16 new_rx_count, new_tx_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700689
690 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
691 return -EINVAL;
692
Bruce Allan508da422011-12-16 00:45:51 +0000693 new_rx_count = clamp_t(u32, ring->rx_pending, E1000_MIN_RXD,
694 E1000_MAX_RXD);
695 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
696
697 new_tx_count = clamp_t(u32, ring->tx_pending, E1000_MIN_TXD,
698 E1000_MAX_TXD);
699 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
700
701 if ((new_tx_count == adapter->tx_ring_count) &&
702 (new_rx_count == adapter->rx_ring_count))
703 /* nothing to do */
704 return 0;
705
Auke Kokbc7f75f2007-09-17 12:30:59 -0700706 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000707 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700708
Bruce Allan508da422011-12-16 00:45:51 +0000709 if (!netif_running(adapter->netdev)) {
710 /* Set counts now and allocate resources during open() */
711 adapter->tx_ring->count = new_tx_count;
712 adapter->rx_ring->count = new_rx_count;
713 adapter->tx_ring_count = new_tx_count;
714 adapter->rx_ring_count = new_rx_count;
715 goto clear_reset;
716 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700717
Bruce Allan508da422011-12-16 00:45:51 +0000718 set_tx = (new_tx_count != adapter->tx_ring_count);
719 set_rx = (new_rx_count != adapter->rx_ring_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700720
Bruce Allan508da422011-12-16 00:45:51 +0000721 /* Allocate temporary storage for ring updates */
722 if (set_tx) {
723 temp_tx = vmalloc(size);
724 if (!temp_tx) {
725 err = -ENOMEM;
726 goto free_temp;
727 }
728 }
729 if (set_rx) {
730 temp_rx = vmalloc(size);
731 if (!temp_rx) {
732 err = -ENOMEM;
733 goto free_temp;
734 }
735 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700736
Bruce Allan3ef672a2013-06-27 02:44:44 +0000737 pm_runtime_get_sync(netdev->dev.parent);
738
David Ertman28002092014-02-14 07:16:41 +0000739 e1000e_down(adapter, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700740
Bruce Allane921eb12012-11-28 09:28:37 +0000741 /* We can't just free everything and then setup again, because the
Bruce Allan508da422011-12-16 00:45:51 +0000742 * ISRs in MSI-X mode get passed pointers to the Tx and Rx ring
743 * structs. First, attempt to allocate new resources...
744 */
745 if (set_tx) {
746 memcpy(temp_tx, adapter->tx_ring, size);
747 temp_tx->count = new_tx_count;
748 err = e1000e_setup_tx_resources(temp_tx);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700749 if (err)
750 goto err_setup;
751 }
Bruce Allan508da422011-12-16 00:45:51 +0000752 if (set_rx) {
753 memcpy(temp_rx, adapter->rx_ring, size);
754 temp_rx->count = new_rx_count;
755 err = e1000e_setup_rx_resources(temp_rx);
756 if (err)
757 goto err_setup_rx;
758 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700759
Bruce Allan508da422011-12-16 00:45:51 +0000760 /* ...then free the old resources and copy back any new ring data */
761 if (set_tx) {
762 e1000e_free_tx_resources(adapter->tx_ring);
763 memcpy(adapter->tx_ring, temp_tx, size);
764 adapter->tx_ring_count = new_tx_count;
765 }
766 if (set_rx) {
767 e1000e_free_rx_resources(adapter->rx_ring);
768 memcpy(adapter->rx_ring, temp_rx, size);
769 adapter->rx_ring_count = new_rx_count;
770 }
771
Auke Kokbc7f75f2007-09-17 12:30:59 -0700772err_setup_rx:
Bruce Allan508da422011-12-16 00:45:51 +0000773 if (err && set_tx)
774 e1000e_free_tx_resources(temp_tx);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700775err_setup:
Bruce Allan508da422011-12-16 00:45:51 +0000776 e1000e_up(adapter);
Bruce Allan3ef672a2013-06-27 02:44:44 +0000777 pm_runtime_put_sync(netdev->dev.parent);
Bruce Allan508da422011-12-16 00:45:51 +0000778free_temp:
779 vfree(temp_tx);
780 vfree(temp_rx);
781clear_reset:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700782 clear_bit(__E1000_RESETTING, &adapter->state);
783 return err;
784}
785
Bruce Allancef8c792008-04-02 13:48:23 -0700786static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
787 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800788{
Bruce Allancef8c792008-04-02 13:48:23 -0700789 u32 pat, val;
Bruce Allan64806412010-12-11 05:53:42 +0000790 static const u32 test[] = {
Bruce Allan04e115c2013-02-20 04:06:22 +0000791 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF
792 };
Bruce Allancef8c792008-04-02 13:48:23 -0700793 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800794 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700795 (test[pat] & write));
796 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
797 if (val != (test[pat] & write & mask)) {
Bruce Allana8fc1892012-12-05 06:25:36 +0000798 e_err("pattern test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
799 reg + (offset << 2), val,
800 (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800801 *data = reg;
David Ertman3992c8e2014-04-05 03:36:15 +0000802 return true;
Joe Perches2a887192007-11-13 20:53:51 -0800803 }
804 }
David Ertman3992c8e2014-04-05 03:36:15 +0000805 return false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700806}
807
Joe Perches2a887192007-11-13 20:53:51 -0800808static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
809 int reg, u32 mask, u32 write)
810{
Bruce Allancef8c792008-04-02 13:48:23 -0700811 u32 val;
David Ertman6cf08d12014-04-05 06:07:00 +0000812
Joe Perches2a887192007-11-13 20:53:51 -0800813 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700814 val = __er32(&adapter->hw, reg);
815 if ((write & mask) != (val & mask)) {
Bruce Allana8fc1892012-12-05 06:25:36 +0000816 e_err("set/check test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
Bruce Allan6ad65142012-04-12 05:47:09 +0000817 reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800818 *data = reg;
David Ertman3992c8e2014-04-05 03:36:15 +0000819 return true;
Joe Perches2a887192007-11-13 20:53:51 -0800820 }
David Ertman3992c8e2014-04-05 03:36:15 +0000821 return false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700822}
Bruce Allanfc830b72013-02-20 04:06:11 +0000823
Bruce Allancef8c792008-04-02 13:48:23 -0700824#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
825 do { \
826 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
827 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800828 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700829#define REG_PATTERN_TEST(reg, mask, write) \
830 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800831
Bruce Allancef8c792008-04-02 13:48:23 -0700832#define REG_SET_AND_CHECK(reg, mask, write) \
833 do { \
834 if (reg_set_and_check(adapter, data, reg, mask, write)) \
835 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800836 } while (0)
837
Auke Kokbc7f75f2007-09-17 12:30:59 -0700838static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
839{
840 struct e1000_hw *hw = &adapter->hw;
841 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700842 u32 value;
843 u32 before;
844 u32 after;
845 u32 i;
846 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000847 u32 mask;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000848 u32 wlock_mac = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700849
Bruce Allane921eb12012-11-28 09:28:37 +0000850 /* The status register is Read Only, so a write should fail.
Bruce Allan33550ce2013-02-20 04:06:16 +0000851 * Some bits that get toggled are ignored. There are several bits
852 * on newer hardware that are r/w.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700853 */
854 switch (mac->type) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700855 case e1000_82571:
856 case e1000_82572:
857 case e1000_80003es2lan:
858 toggle = 0x7FFFF3FF;
859 break;
Bruce Allanf0ff4392013-02-20 04:05:39 +0000860 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700861 toggle = 0x7FFFF033;
862 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700863 }
864
865 before = er32(STATUS);
866 value = (er32(STATUS) & toggle);
867 ew32(STATUS, toggle);
868 after = er32(STATUS) & toggle;
869 if (value != after) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000870 e_err("failed STATUS register test got: 0x%08X expected: 0x%08X\n",
871 after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700872 *data = 1;
873 return 1;
874 }
875 /* restore previous status */
876 ew32(STATUS, before);
877
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700878 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700879 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
880 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
881 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
882 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
883 }
884
885 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000886 REG_PATTERN_TEST(E1000_RDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
887 REG_PATTERN_TEST(E1000_RDLEN(0), 0x000FFF80, 0x000FFFFF);
888 REG_PATTERN_TEST(E1000_RDH(0), 0x0000FFFF, 0x0000FFFF);
889 REG_PATTERN_TEST(E1000_RDT(0), 0x0000FFFF, 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700890 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
891 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
892 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000893 REG_PATTERN_TEST(E1000_TDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
894 REG_PATTERN_TEST(E1000_TDLEN(0), 0x000FFF80, 0x000FFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700895
896 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
897
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700898 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700899 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
900 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
901
Auke Kok86582512007-10-04 15:00:08 -0700902 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000903 REG_PATTERN_TEST(E1000_RDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700904 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700905 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000906 REG_PATTERN_TEST(E1000_TDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
Auke Kok86582512007-10-04 15:00:08 -0700907 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000908 mask = 0x8003FFFF;
909 switch (mac->type) {
910 case e1000_ich10lan:
911 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000912 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000913 case e1000_pch_lpt:
David Ertman79849eb2015-02-10 09:10:43 +0000914 case e1000_pch_spt:
Sasha Neftinc8744f42017-04-06 10:26:47 +0300915 /* fall through */
916 case e1000_pch_cnp:
Jacob Keller18dd2392016-04-13 16:08:32 -0700917 mask |= BIT(18);
Bruce Allana4f58f52009-06-02 11:29:18 +0000918 break;
919 default:
920 break;
921 }
Bruce Allan2fbe4522012-04-19 03:21:47 +0000922
Sasha Neftinc8744f42017-04-06 10:26:47 +0300923 if (mac->type >= e1000_pch_lpt)
Bruce Allan2fbe4522012-04-19 03:21:47 +0000924 wlock_mac = (er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK) >>
925 E1000_FWSM_WLOCK_MAC_SHIFT;
926
927 for (i = 0; i < mac->rar_entry_count; i++) {
Sasha Neftinc8744f42017-04-06 10:26:47 +0300928 if (mac->type >= e1000_pch_lpt) {
Bruce Allana8fc1892012-12-05 06:25:36 +0000929 /* Cannot test write-protected SHRAL[n] registers */
930 if ((wlock_mac == 1) || (wlock_mac && (i > wlock_mac)))
931 continue;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000932
Bruce Allana8fc1892012-12-05 06:25:36 +0000933 /* SHRAH[9] different than the others */
934 if (i == 10)
Jacob Keller18dd2392016-04-13 16:08:32 -0700935 mask |= BIT(30);
Bruce Allana8fc1892012-12-05 06:25:36 +0000936 else
Jacob Keller18dd2392016-04-13 16:08:32 -0700937 mask &= ~BIT(30);
Bruce Allana8fc1892012-12-05 06:25:36 +0000938 }
David Ertmanc3a0dce2013-09-05 04:24:25 +0000939 if (mac->type == e1000_pch2lan) {
940 /* SHRAH[0,1,2] different than previous */
David Ertmanad400642014-03-05 07:54:19 +0000941 if (i == 1)
David Ertmanc3a0dce2013-09-05 04:24:25 +0000942 mask &= 0xFFF4FFFF;
943 /* SHRAH[3] different than SHRAH[0,1,2] */
David Ertmanad400642014-03-05 07:54:19 +0000944 if (i == 4)
Jacob Keller18dd2392016-04-13 16:08:32 -0700945 mask |= BIT(30);
David Ertmanad400642014-03-05 07:54:19 +0000946 /* RAR[1-6] owned by management engine - skipping */
947 if (i > 0)
948 i += 6;
David Ertmanc3a0dce2013-09-05 04:24:25 +0000949 }
Bruce Allana8fc1892012-12-05 06:25:36 +0000950
951 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1), mask,
952 0xFFFFFFFF);
David Ertmanad400642014-03-05 07:54:19 +0000953 /* reset index to actual value */
954 if ((mac->type == e1000_pch2lan) && (i > 6))
955 i -= 6;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000956 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700957
958 for (i = 0; i < mac->mta_reg_count; i++)
959 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
960
961 *data = 0;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000962
Auke Kokbc7f75f2007-09-17 12:30:59 -0700963 return 0;
964}
965
966static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
967{
968 u16 temp;
969 u16 checksum = 0;
970 u16 i;
971
972 *data = 0;
973 /* Read and add up the contents of the EEPROM */
974 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
975 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
976 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800977 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700978 }
979 checksum += temp;
980 }
981
982 /* If Checksum is not Correct return error else test passed */
Bruce Allan53aa82d2013-02-20 04:06:06 +0000983 if ((checksum != (u16)NVM_SUM) && !(*data))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700984 *data = 2;
985
986 return *data;
987}
988
Bruce Allan8bb62862013-01-16 08:46:49 +0000989static irqreturn_t e1000_test_intr(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700990{
Bruce Allan53aa82d2013-02-20 04:06:06 +0000991 struct net_device *netdev = (struct net_device *)data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700992 struct e1000_adapter *adapter = netdev_priv(netdev);
993 struct e1000_hw *hw = &adapter->hw;
994
995 adapter->test_icr |= er32(ICR);
996
997 return IRQ_HANDLED;
998}
999
1000static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
1001{
1002 struct net_device *netdev = adapter->netdev;
1003 struct e1000_hw *hw = &adapter->hw;
1004 u32 mask;
1005 u32 shared_int = 1;
1006 u32 irq = adapter->pdev->irq;
1007 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001008 int ret_val = 0;
1009 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001010
1011 *data = 0;
1012
Bruce Allan4662e822008-08-26 18:37:06 -07001013 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
1014 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
1015 int_mode = adapter->int_mode;
1016 e1000e_reset_interrupt_capability(adapter);
1017 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1018 e1000e_set_interrupt_capability(adapter);
1019 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001020 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -08001021 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001022 netdev)) {
1023 shared_int = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00001024 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED, netdev->name,
1025 netdev)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001026 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001027 ret_val = -1;
1028 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001029 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001030 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001031
1032 /* Disable all the interrupts */
1033 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001034 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001035 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001036
1037 /* Test each interrupt */
1038 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001039 /* Interrupt to test */
Jacob Keller18dd2392016-04-13 16:08:32 -07001040 mask = BIT(i);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001041
Bruce Allanf4187b52008-08-26 18:36:50 -07001042 if (adapter->flags & FLAG_IS_ICH) {
1043 switch (mask) {
1044 case E1000_ICR_RXSEQ:
1045 continue;
1046 case 0x00000100:
1047 if (adapter->hw.mac.type == e1000_ich8lan ||
1048 adapter->hw.mac.type == e1000_ich9lan)
1049 continue;
1050 break;
1051 default:
1052 break;
1053 }
1054 }
1055
Auke Kokbc7f75f2007-09-17 12:30:59 -07001056 if (!shared_int) {
Bruce Allane921eb12012-11-28 09:28:37 +00001057 /* Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001058 * the cause register and then force the same
1059 * interrupt and see if one gets posted. If
1060 * an interrupt was posted to the bus, the
1061 * test failed.
1062 */
1063 adapter->test_icr = 0;
1064 ew32(IMC, mask);
1065 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001066 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001067 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001068
1069 if (adapter->test_icr & mask) {
1070 *data = 3;
1071 break;
1072 }
1073 }
1074
Bruce Allane921eb12012-11-28 09:28:37 +00001075 /* Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001076 * the cause register and then force the same
1077 * interrupt and see if one gets posted. If
1078 * an interrupt was not posted to the bus, the
1079 * test failed.
1080 */
1081 adapter->test_icr = 0;
1082 ew32(IMS, mask);
1083 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001084 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001085 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001086
1087 if (!(adapter->test_icr & mask)) {
1088 *data = 4;
1089 break;
1090 }
1091
1092 if (!shared_int) {
Bruce Allane921eb12012-11-28 09:28:37 +00001093 /* Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001094 * the cause register and then force the other
1095 * interrupts and see if any get posted. If
1096 * an interrupt was posted to the bus, the
1097 * test failed.
1098 */
1099 adapter->test_icr = 0;
1100 ew32(IMC, ~mask & 0x00007FFF);
1101 ew32(ICS, ~mask & 0x00007FFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001102 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001103 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001104
1105 if (adapter->test_icr) {
1106 *data = 5;
1107 break;
1108 }
1109 }
1110 }
1111
1112 /* Disable all the interrupts */
1113 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001114 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001115 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001116
1117 /* Unhook test interrupt handler */
1118 free_irq(irq, netdev);
1119
Bruce Allan4662e822008-08-26 18:37:06 -07001120out:
1121 if (int_mode == E1000E_INT_MODE_MSIX) {
1122 e1000e_reset_interrupt_capability(adapter);
1123 adapter->int_mode = int_mode;
1124 e1000e_set_interrupt_capability(adapter);
1125 }
1126
1127 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001128}
1129
1130static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1131{
1132 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1133 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1134 struct pci_dev *pdev = adapter->pdev;
Bruce Allan17e813e2013-02-20 04:06:01 +00001135 struct e1000_buffer *buffer_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001136 int i;
1137
1138 if (tx_ring->desc && tx_ring->buffer_info) {
1139 for (i = 0; i < tx_ring->count; i++) {
Bruce Allan17e813e2013-02-20 04:06:01 +00001140 buffer_info = &tx_ring->buffer_info[i];
1141
1142 if (buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001143 dma_unmap_single(&pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00001144 buffer_info->dma,
1145 buffer_info->length,
1146 DMA_TO_DEVICE);
1147 if (buffer_info->skb)
1148 dev_kfree_skb(buffer_info->skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001149 }
1150 }
1151
1152 if (rx_ring->desc && rx_ring->buffer_info) {
1153 for (i = 0; i < rx_ring->count; i++) {
Bruce Allan17e813e2013-02-20 04:06:01 +00001154 buffer_info = &rx_ring->buffer_info[i];
1155
1156 if (buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001157 dma_unmap_single(&pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00001158 buffer_info->dma,
1159 2048, DMA_FROM_DEVICE);
1160 if (buffer_info->skb)
1161 dev_kfree_skb(buffer_info->skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001162 }
1163 }
1164
1165 if (tx_ring->desc) {
1166 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1167 tx_ring->dma);
1168 tx_ring->desc = NULL;
1169 }
1170 if (rx_ring->desc) {
1171 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1172 rx_ring->dma);
1173 rx_ring->desc = NULL;
1174 }
1175
1176 kfree(tx_ring->buffer_info);
1177 tx_ring->buffer_info = NULL;
1178 kfree(rx_ring->buffer_info);
1179 rx_ring->buffer_info = NULL;
1180}
1181
1182static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1183{
1184 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1185 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1186 struct pci_dev *pdev = adapter->pdev;
1187 struct e1000_hw *hw = &adapter->hw;
1188 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001189 int i;
1190 int ret_val;
1191
1192 /* Setup Tx descriptor ring and Tx buffers */
1193
1194 if (!tx_ring->count)
1195 tx_ring->count = E1000_DEFAULT_TXD;
1196
Bruce Allancef8c792008-04-02 13:48:23 -07001197 tx_ring->buffer_info = kcalloc(tx_ring->count,
Bruce Allane5fe2542013-02-20 04:06:27 +00001198 sizeof(struct e1000_buffer), GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001199 if (!tx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001200 ret_val = 1;
1201 goto err_nomem;
1202 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001203
1204 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1205 tx_ring->size = ALIGN(tx_ring->size, 4096);
1206 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1207 &tx_ring->dma, GFP_KERNEL);
1208 if (!tx_ring->desc) {
1209 ret_val = 2;
1210 goto err_nomem;
1211 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001212 tx_ring->next_to_use = 0;
1213 tx_ring->next_to_clean = 0;
1214
Bruce Allan53aa82d2013-02-20 04:06:06 +00001215 ew32(TDBAL(0), ((u64)tx_ring->dma & 0x00000000FFFFFFFF));
1216 ew32(TDBAH(0), ((u64)tx_ring->dma >> 32));
Bruce Allan1e360522012-03-20 03:48:13 +00001217 ew32(TDLEN(0), tx_ring->count * sizeof(struct e1000_tx_desc));
1218 ew32(TDH(0), 0);
1219 ew32(TDT(0), 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001220 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1221 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1222 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001223
1224 for (i = 0; i < tx_ring->count; i++) {
1225 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1226 struct sk_buff *skb;
1227 unsigned int skb_size = 1024;
1228
1229 skb = alloc_skb(skb_size, GFP_KERNEL);
1230 if (!skb) {
1231 ret_val = 3;
1232 goto err_nomem;
1233 }
1234 skb_put(skb, skb_size);
1235 tx_ring->buffer_info[i].skb = skb;
1236 tx_ring->buffer_info[i].length = skb->len;
1237 tx_ring->buffer_info[i].dma =
Bruce Allanf0ff4392013-02-20 04:05:39 +00001238 dma_map_single(&pdev->dev, skb->data, skb->len,
1239 DMA_TO_DEVICE);
Nick Nunley0be3f552010-04-27 13:09:05 +00001240 if (dma_mapping_error(&pdev->dev,
1241 tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001242 ret_val = 4;
1243 goto err_nomem;
1244 }
Bruce Allancef8c792008-04-02 13:48:23 -07001245 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001246 tx_desc->lower.data = cpu_to_le32(skb->len);
1247 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1248 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001249 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001250 tx_desc->upper.data = 0;
1251 }
1252
1253 /* Setup Rx descriptor ring and Rx buffers */
1254
1255 if (!rx_ring->count)
1256 rx_ring->count = E1000_DEFAULT_RXD;
1257
Bruce Allancef8c792008-04-02 13:48:23 -07001258 rx_ring->buffer_info = kcalloc(rx_ring->count,
Bruce Allane5fe2542013-02-20 04:06:27 +00001259 sizeof(struct e1000_buffer), GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001260 if (!rx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001261 ret_val = 5;
1262 goto err_nomem;
1263 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001264
Bruce Allan5f450212011-07-22 06:21:46 +00001265 rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001266 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1267 &rx_ring->dma, GFP_KERNEL);
1268 if (!rx_ring->desc) {
1269 ret_val = 6;
1270 goto err_nomem;
1271 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001272 rx_ring->next_to_use = 0;
1273 rx_ring->next_to_clean = 0;
1274
1275 rctl = er32(RCTL);
Bruce Allan7f99ae62011-07-22 06:21:35 +00001276 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
1277 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan53aa82d2013-02-20 04:06:06 +00001278 ew32(RDBAL(0), ((u64)rx_ring->dma & 0xFFFFFFFF));
1279 ew32(RDBAH(0), ((u64)rx_ring->dma >> 32));
Bruce Allan1e360522012-03-20 03:48:13 +00001280 ew32(RDLEN(0), rx_ring->size);
1281 ew32(RDH(0), 0);
1282 ew32(RDT(0), 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001283 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allanf0ff4392013-02-20 04:05:39 +00001284 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1285 E1000_RCTL_SBP | E1000_RCTL_SECRC |
1286 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1287 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001288 ew32(RCTL, rctl);
1289
1290 for (i = 0; i < rx_ring->count; i++) {
Bruce Allan5f450212011-07-22 06:21:46 +00001291 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001292 struct sk_buff *skb;
1293
1294 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1295 if (!skb) {
1296 ret_val = 7;
1297 goto err_nomem;
1298 }
1299 skb_reserve(skb, NET_IP_ALIGN);
1300 rx_ring->buffer_info[i].skb = skb;
1301 rx_ring->buffer_info[i].dma =
Bruce Allanf0ff4392013-02-20 04:05:39 +00001302 dma_map_single(&pdev->dev, skb->data, 2048,
1303 DMA_FROM_DEVICE);
Nick Nunley0be3f552010-04-27 13:09:05 +00001304 if (dma_mapping_error(&pdev->dev,
1305 rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001306 ret_val = 8;
1307 goto err_nomem;
1308 }
Bruce Allan5f450212011-07-22 06:21:46 +00001309 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1310 rx_desc->read.buffer_addr =
1311 cpu_to_le64(rx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001312 memset(skb->data, 0x00, skb->len);
1313 }
1314
1315 return 0;
1316
1317err_nomem:
1318 e1000_free_desc_rings(adapter);
1319 return ret_val;
1320}
1321
1322static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1323{
1324 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1325 e1e_wphy(&adapter->hw, 29, 0x001F);
1326 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1327 e1e_wphy(&adapter->hw, 29, 0x001A);
1328 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1329}
1330
1331static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1332{
1333 struct e1000_hw *hw = &adapter->hw;
1334 u32 ctrl_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001335 u16 phy_reg = 0;
Bruce Allancbd006c2010-11-24 06:01:30 +00001336 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001337
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001338 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001339
Bruce Allan3af50482010-06-16 13:25:55 +00001340 if (hw->phy.type == e1000_phy_ife) {
1341 /* force 100, set loopback */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001342 e1e_wphy(hw, MII_BMCR, 0x6100);
Bruce Allanbb436b22009-11-20 23:24:11 +00001343
Bruce Allan3af50482010-06-16 13:25:55 +00001344 /* Now set up the MAC to the same speed/duplex as the PHY. */
1345 ctrl_reg = er32(CTRL);
1346 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1347 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1348 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1349 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1350 E1000_CTRL_FD); /* Force Duplex to FULL */
1351
1352 ew32(CTRL, ctrl_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001353 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00001354 usleep_range(500, 1000);
Bruce Allan3af50482010-06-16 13:25:55 +00001355
1356 return 0;
1357 }
1358
1359 /* Specific PHY configuration for loopback */
1360 switch (hw->phy.type) {
1361 case e1000_phy_m88:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001362 /* Auto-MDI/MDIX Off */
1363 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1364 /* reset to update Auto-MDI/MDIX */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001365 e1e_wphy(hw, MII_BMCR, 0x9140);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001366 /* autoneg off */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001367 e1e_wphy(hw, MII_BMCR, 0x8140);
Bruce Allan3af50482010-06-16 13:25:55 +00001368 break;
1369 case e1000_phy_gg82563:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001370 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
Bruce Allancef8c792008-04-02 13:48:23 -07001371 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001372 case e1000_phy_bm:
1373 /* Set Default MAC Interface speed to 1GB */
1374 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1375 phy_reg &= ~0x0007;
1376 phy_reg |= 0x006;
1377 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1378 /* Assert SW reset for above settings to take effect */
Bruce Allan6b598e12013-01-23 06:50:05 +00001379 hw->phy.ops.commit(hw);
Bruce Allance43a212013-02-20 04:06:32 +00001380 usleep_range(1000, 2000);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001381 /* Force Full Duplex */
1382 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1383 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1384 /* Set Link Up (in force link) */
1385 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1386 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1387 /* Force Link */
1388 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1389 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1390 /* Set Early Link Enable */
1391 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1392 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
Bruce Allan3af50482010-06-16 13:25:55 +00001393 break;
1394 case e1000_phy_82577:
1395 case e1000_phy_82578:
1396 /* Workaround: K1 must be disabled for stable 1Gbps operation */
Bruce Allancbd006c2010-11-24 06:01:30 +00001397 ret_val = hw->phy.ops.acquire(hw);
1398 if (ret_val) {
1399 e_err("Cannot setup 1Gbps loopback.\n");
1400 return ret_val;
1401 }
Bruce Allan3af50482010-06-16 13:25:55 +00001402 e1000_configure_k1_ich8lan(hw, false);
Bruce Allancbd006c2010-11-24 06:01:30 +00001403 hw->phy.ops.release(hw);
Bruce Allan3af50482010-06-16 13:25:55 +00001404 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001405 case e1000_phy_82579:
1406 /* Disable PHY energy detect power down */
1407 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
Jacob Keller18dd2392016-04-13 16:08:32 -07001408 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~BIT(3));
Bruce Alland3738bb2010-06-16 13:27:28 +00001409 /* Disable full chip energy detect */
1410 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1411 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1412 /* Enable loopback on the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00001413 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1414 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001415 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001416 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001417 }
1418
Bruce Allan3af50482010-06-16 13:25:55 +00001419 /* force 1000, set loopback */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001420 e1e_wphy(hw, MII_BMCR, 0x4140);
Bruce Allance43a212013-02-20 04:06:32 +00001421 msleep(250);
Bruce Allan3af50482010-06-16 13:25:55 +00001422
1423 /* Now set up the MAC to the same speed/duplex as the PHY. */
1424 ctrl_reg = er32(CTRL);
1425 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1426 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1427 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1428 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1429 E1000_CTRL_FD); /* Force Duplex to FULL */
1430
1431 if (adapter->flags & FLAG_IS_ICH)
1432 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1433
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001434 if (hw->phy.media_type == e1000_media_type_copper &&
1435 hw->phy.type == e1000_phy_m88) {
Bruce Allane80bd1d2013-05-01 01:19:46 +00001436 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001437 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001438 /* Set the ILOS bit on the fiber Nic if half duplex link is
Bruce Allanad680762008-03-28 09:15:03 -07001439 * detected.
1440 */
Bruce Allan90da0662011-01-06 07:02:53 +00001441 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001442 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1443 }
1444
1445 ew32(CTRL, ctrl_reg);
1446
Bruce Allane921eb12012-11-28 09:28:37 +00001447 /* Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001448 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1449 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001450 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001451 e1000_phy_disable_receiver(adapter);
1452
Bruce Allance43a212013-02-20 04:06:32 +00001453 usleep_range(500, 1000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001454
1455 return 0;
1456}
1457
1458static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1459{
1460 struct e1000_hw *hw = &adapter->hw;
1461 u32 ctrl = er32(CTRL);
Bruce Allan70806a72013-01-05 05:08:37 +00001462 int link;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001463
1464 /* special requirements for 82571/82572 fiber adapters */
1465
Bruce Allane921eb12012-11-28 09:28:37 +00001466 /* jump through hoops to make sure link is up because serdes
Bruce Allanad680762008-03-28 09:15:03 -07001467 * link is hardwired up
1468 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001469 ctrl |= E1000_CTRL_SLU;
1470 ew32(CTRL, ctrl);
1471
1472 /* disable autoneg */
1473 ctrl = er32(TXCW);
Jacob Keller18dd2392016-04-13 16:08:32 -07001474 ctrl &= ~BIT(31);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001475 ew32(TXCW, ctrl);
1476
1477 link = (er32(STATUS) & E1000_STATUS_LU);
1478
1479 if (!link) {
1480 /* set invert loss of signal */
1481 ctrl = er32(CTRL);
1482 ctrl |= E1000_CTRL_ILOS;
1483 ew32(CTRL, ctrl);
1484 }
1485
Bruce Allane921eb12012-11-28 09:28:37 +00001486 /* special write to serdes control register to enable SerDes analog
Bruce Allanad680762008-03-28 09:15:03 -07001487 * loopback
1488 */
Bruce Allan3ffcf2c2013-02-20 04:06:43 +00001489 ew32(SCTL, E1000_SCTL_ENABLE_SERDES_LOOPBACK);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001490 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001491 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001492
1493 return 0;
1494}
1495
1496/* only call this for fiber/serdes connections to es2lan */
1497static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1498{
1499 struct e1000_hw *hw = &adapter->hw;
1500 u32 ctrlext = er32(CTRL_EXT);
1501 u32 ctrl = er32(CTRL);
1502
Bruce Allane921eb12012-11-28 09:28:37 +00001503 /* save CTRL_EXT to restore later, reuse an empty variable (unused
Bruce Allanad680762008-03-28 09:15:03 -07001504 * on mac_type 80003es2lan)
1505 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001506 adapter->tx_fifo_head = ctrlext;
1507
1508 /* clear the serdes mode bits, putting the device into mac loopback */
1509 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1510 ew32(CTRL_EXT, ctrlext);
1511
1512 /* force speed to 1000/FD, link up */
1513 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1514 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1515 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1516 ew32(CTRL, ctrl);
1517
1518 /* set mac loopback */
1519 ctrl = er32(RCTL);
1520 ctrl |= E1000_RCTL_LBM_MAC;
1521 ew32(RCTL, ctrl);
1522
1523 /* set testing mode parameters (no need to reset later) */
1524#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1525#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1526 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001527 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001528
1529 return 0;
1530}
1531
1532static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1533{
1534 struct e1000_hw *hw = &adapter->hw;
Yanir Lubetkin2ec7d292015-06-02 17:05:47 +03001535 u32 rctl, fext_nvm11, tarc0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001536
Sasha Neftinc8744f42017-04-06 10:26:47 +03001537 if (hw->mac.type >= e1000_pch_spt) {
Yanir Lubetkin2ec7d292015-06-02 17:05:47 +03001538 fext_nvm11 = er32(FEXTNVM11);
1539 fext_nvm11 |= E1000_FEXTNVM11_DISABLE_MULR_FIX;
1540 ew32(FEXTNVM11, fext_nvm11);
1541 tarc0 = er32(TARC(0));
1542 /* clear bits 28 & 29 (control of MULR concurrent requests) */
1543 tarc0 &= 0xcfffffff;
1544 /* set bit 29 (value of MULR requests is now 2) */
1545 tarc0 |= 0x20000000;
1546 ew32(TARC(0), tarc0);
1547 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001548 if (hw->phy.media_type == e1000_media_type_fiber ||
1549 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001550 switch (hw->mac.type) {
1551 case e1000_80003es2lan:
1552 return e1000_set_es2lan_mac_loopback(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001553 case e1000_82571:
1554 case e1000_82572:
1555 return e1000_set_82571_fiber_loopback(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001556 default:
1557 rctl = er32(RCTL);
1558 rctl |= E1000_RCTL_LBM_TCVR;
1559 ew32(RCTL, rctl);
1560 return 0;
1561 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001562 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001563 return e1000_integrated_phy_loopback(adapter);
1564 }
1565
1566 return 7;
1567}
1568
1569static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1570{
1571 struct e1000_hw *hw = &adapter->hw;
Yanir Lubetkin2ec7d292015-06-02 17:05:47 +03001572 u32 rctl, fext_nvm11, tarc0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001573 u16 phy_reg;
1574
1575 rctl = er32(RCTL);
1576 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1577 ew32(RCTL, rctl);
1578
1579 switch (hw->mac.type) {
Yanir Lubetkin2ec7d292015-06-02 17:05:47 +03001580 case e1000_pch_spt:
Sasha Neftinc8744f42017-04-06 10:26:47 +03001581 case e1000_pch_cnp:
Yanir Lubetkin2ec7d292015-06-02 17:05:47 +03001582 fext_nvm11 = er32(FEXTNVM11);
1583 fext_nvm11 &= ~E1000_FEXTNVM11_DISABLE_MULR_FIX;
1584 ew32(FEXTNVM11, fext_nvm11);
1585 tarc0 = er32(TARC(0));
1586 /* clear bits 28 & 29 (control of MULR concurrent requests) */
1587 /* set bit 29 (value of MULR requests is now 0) */
1588 tarc0 &= 0xcfffffff;
1589 ew32(TARC(0), tarc0);
1590 /* fall through */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001591 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001592 if (hw->phy.media_type == e1000_media_type_fiber ||
1593 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001594 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001595 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001596 adapter->tx_fifo_head = 0;
1597 }
1598 /* fall through */
1599 case e1000_82571:
1600 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001601 if (hw->phy.media_type == e1000_media_type_fiber ||
1602 hw->phy.media_type == e1000_media_type_internal_serdes) {
Bruce Allan3ffcf2c2013-02-20 04:06:43 +00001603 ew32(SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001604 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001605 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001606 break;
1607 }
1608 /* Fall Through */
1609 default:
1610 hw->mac.autoneg = 1;
1611 if (hw->phy.type == e1000_phy_gg82563)
1612 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001613 e1e_rphy(hw, MII_BMCR, &phy_reg);
1614 if (phy_reg & BMCR_LOOPBACK) {
1615 phy_reg &= ~BMCR_LOOPBACK;
1616 e1e_wphy(hw, MII_BMCR, phy_reg);
Bruce Allan6b598e12013-01-23 06:50:05 +00001617 if (hw->phy.ops.commit)
1618 hw->phy.ops.commit(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001619 }
1620 break;
1621 }
1622}
1623
1624static void e1000_create_lbtest_frame(struct sk_buff *skb,
1625 unsigned int frame_size)
1626{
1627 memset(skb->data, 0xFF, frame_size);
1628 frame_size &= ~1;
1629 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1630 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1631 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1632}
1633
1634static int e1000_check_lbtest_frame(struct sk_buff *skb,
1635 unsigned int frame_size)
1636{
1637 frame_size &= ~1;
1638 if (*(skb->data + 3) == 0xFF)
1639 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
Bruce Allan17e813e2013-02-20 04:06:01 +00001640 (*(skb->data + frame_size / 2 + 12) == 0xAF))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001641 return 0;
1642 return 13;
1643}
1644
1645static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1646{
1647 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1648 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1649 struct pci_dev *pdev = adapter->pdev;
1650 struct e1000_hw *hw = &adapter->hw;
Bruce Allan17e813e2013-02-20 04:06:01 +00001651 struct e1000_buffer *buffer_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001652 int i, j, k, l;
1653 int lc;
1654 int good_cnt;
1655 int ret_val = 0;
1656 unsigned long time;
1657
Bruce Allan1e360522012-03-20 03:48:13 +00001658 ew32(RDT(0), rx_ring->count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001659
Bruce Allane921eb12012-11-28 09:28:37 +00001660 /* Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001661 * The idea is to wrap the largest ring a number of times using 64
1662 * send/receive pairs during each loop
1663 */
1664
1665 if (rx_ring->count <= tx_ring->count)
1666 lc = ((tx_ring->count / 64) * 2) + 1;
1667 else
1668 lc = ((rx_ring->count / 64) * 2) + 1;
1669
1670 k = 0;
1671 l = 0;
Bruce Allan33550ce2013-02-20 04:06:16 +00001672 /* loop count loop */
1673 for (j = 0; j <= lc; j++) {
1674 /* send the packets */
1675 for (i = 0; i < 64; i++) {
Bruce Allan17e813e2013-02-20 04:06:01 +00001676 buffer_info = &tx_ring->buffer_info[k];
1677
1678 e1000_create_lbtest_frame(buffer_info->skb, 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001679 dma_sync_single_for_device(&pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00001680 buffer_info->dma,
1681 buffer_info->length,
1682 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001683 k++;
1684 if (k == tx_ring->count)
1685 k = 0;
1686 }
Bruce Allan1e360522012-03-20 03:48:13 +00001687 ew32(TDT(0), k);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001688 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001689 msleep(200);
Bruce Allane80bd1d2013-05-01 01:19:46 +00001690 time = jiffies; /* set the start time for the receive */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001691 good_cnt = 0;
Bruce Allan33550ce2013-02-20 04:06:16 +00001692 /* receive the sent packets */
1693 do {
Bruce Allan17e813e2013-02-20 04:06:01 +00001694 buffer_info = &rx_ring->buffer_info[l];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001695
Bruce Allan17e813e2013-02-20 04:06:01 +00001696 dma_sync_single_for_cpu(&pdev->dev,
1697 buffer_info->dma, 2048,
1698 DMA_FROM_DEVICE);
1699
1700 ret_val = e1000_check_lbtest_frame(buffer_info->skb,
1701 1024);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001702 if (!ret_val)
1703 good_cnt++;
1704 l++;
1705 if (l == rx_ring->count)
1706 l = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00001707 /* time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001708 * enough time to complete the receives, if it's
1709 * exceeded, break and error off
1710 */
1711 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1712 if (good_cnt != 64) {
Bruce Allane80bd1d2013-05-01 01:19:46 +00001713 ret_val = 13; /* ret_val is the same as mis-compare */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001714 break;
1715 }
Bruce Allan22f8aba2013-08-15 03:43:24 +00001716 if (time_after(jiffies, time + 20)) {
Bruce Allane80bd1d2013-05-01 01:19:46 +00001717 ret_val = 14; /* error code for time out error */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001718 break;
1719 }
Bruce Allan33550ce2013-02-20 04:06:16 +00001720 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001721 return ret_val;
1722}
1723
1724static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1725{
Bruce Allan44abd5c2012-02-22 09:02:37 +00001726 struct e1000_hw *hw = &adapter->hw;
1727
Bruce Allane921eb12012-11-28 09:28:37 +00001728 /* PHY loopback cannot be performed if SoL/IDER sessions are active */
Bruce Allan470a5422012-05-26 06:08:48 +00001729 if (hw->phy.ops.check_reset_block &&
1730 hw->phy.ops.check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001731 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001732 *data = 0;
1733 goto out;
1734 }
1735
1736 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001737 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001738 goto out;
1739
1740 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001741 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001742 goto err_loopback;
1743
1744 *data = e1000_run_loopback_test(adapter);
1745 e1000_loopback_cleanup(adapter);
1746
1747err_loopback:
1748 e1000_free_desc_rings(adapter);
1749out:
1750 return *data;
1751}
1752
1753static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1754{
1755 struct e1000_hw *hw = &adapter->hw;
1756
1757 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001758 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001759 int i = 0;
David Ertman6cf08d12014-04-05 06:07:00 +00001760
Alex Chiang612e2442009-02-05 23:55:45 -08001761 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001762
Bruce Allane921eb12012-11-28 09:28:37 +00001763 /* On some blade server designs, link establishment
Bruce Allanad680762008-03-28 09:15:03 -07001764 * could take as long as 2-3 minutes
1765 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001766 do {
1767 hw->mac.ops.check_for_link(hw);
1768 if (hw->mac.serdes_has_link)
1769 return *data;
1770 msleep(20);
1771 } while (i++ < 3750);
1772
1773 *data = 1;
1774 } else {
1775 hw->mac.ops.check_for_link(hw);
1776 if (hw->mac.autoneg)
Bruce Allane921eb12012-11-28 09:28:37 +00001777 /* On some Phy/switch combinations, link establishment
Bruce Allan5661aeb2011-02-25 06:36:25 +00001778 * can take a few seconds more than expected.
1779 */
Bruce Allance43a212013-02-20 04:06:32 +00001780 msleep_interruptible(5000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001781
Bruce Allan5661aeb2011-02-25 06:36:25 +00001782 if (!(er32(STATUS) & E1000_STATUS_LU))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001783 *data = 1;
1784 }
1785 return *data;
1786}
1787
Bruce Allan8bb62862013-01-16 08:46:49 +00001788static int e1000e_get_sset_count(struct net_device __always_unused *netdev,
1789 int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001790{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001791 switch (sset) {
1792 case ETH_SS_TEST:
1793 return E1000_TEST_LEN;
1794 case ETH_SS_STATS:
1795 return E1000_STATS_LEN;
1796 default:
1797 return -EOPNOTSUPP;
1798 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001799}
1800
1801static void e1000_diag_test(struct net_device *netdev,
1802 struct ethtool_test *eth_test, u64 *data)
1803{
1804 struct e1000_adapter *adapter = netdev_priv(netdev);
1805 u16 autoneg_advertised;
1806 u8 forced_speed_duplex;
1807 u8 autoneg;
1808 bool if_running = netif_running(netdev);
1809
Bruce Allan3ef672a2013-06-27 02:44:44 +00001810 pm_runtime_get_sync(netdev->dev.parent);
1811
Auke Kokbc7f75f2007-09-17 12:30:59 -07001812 set_bit(__E1000_TESTING, &adapter->state);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001813
1814 if (!if_running) {
1815 /* Get control of and reset hardware */
1816 if (adapter->flags & FLAG_HAS_AMT)
1817 e1000e_get_hw_control(adapter);
1818
1819 e1000e_power_up_phy(adapter);
1820
1821 adapter->hw.phy.autoneg_wait_to_complete = 1;
1822 e1000e_reset(adapter);
1823 adapter->hw.phy.autoneg_wait_to_complete = 0;
1824 }
1825
Auke Kokbc7f75f2007-09-17 12:30:59 -07001826 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1827 /* Offline tests */
1828
1829 /* save speed, duplex, autoneg settings */
1830 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1831 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1832 autoneg = adapter->hw.mac.autoneg;
1833
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001834 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001835
Auke Kokbc7f75f2007-09-17 12:30:59 -07001836 if (if_running)
1837 /* indicate we're in test mode */
Stefan Assmannd5ea45d2016-02-03 09:20:52 +01001838 e1000e_close(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001839
1840 if (e1000_reg_test(adapter, &data[0]))
1841 eth_test->flags |= ETH_TEST_FL_FAILED;
1842
1843 e1000e_reset(adapter);
1844 if (e1000_eeprom_test(adapter, &data[1]))
1845 eth_test->flags |= ETH_TEST_FL_FAILED;
1846
1847 e1000e_reset(adapter);
1848 if (e1000_intr_test(adapter, &data[2]))
1849 eth_test->flags |= ETH_TEST_FL_FAILED;
1850
1851 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001852 if (e1000_loopback_test(adapter, &data[3]))
1853 eth_test->flags |= ETH_TEST_FL_FAILED;
1854
Auke Kokbc7f75f2007-09-17 12:30:59 -07001855 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001856 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001857 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001858 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001859
Carolyn Wybornyc6ce3852010-10-15 17:35:31 +00001860 if (e1000_link_test(adapter, &data[4]))
1861 eth_test->flags |= ETH_TEST_FL_FAILED;
1862
1863 /* restore speed, duplex, autoneg settings */
1864 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1865 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1866 adapter->hw.mac.autoneg = autoneg;
1867 e1000e_reset(adapter);
1868
Auke Kokbc7f75f2007-09-17 12:30:59 -07001869 clear_bit(__E1000_TESTING, &adapter->state);
1870 if (if_running)
Stefan Assmannd5ea45d2016-02-03 09:20:52 +01001871 e1000e_open(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001872 } else {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001873 /* Online tests */
Bruce Allan11b08be2010-05-10 14:59:31 +00001874
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001875 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001876
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001877 /* register, eeprom, intr and loopback tests not run online */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001878 data[0] = 0;
1879 data[1] = 0;
1880 data[2] = 0;
1881 data[3] = 0;
1882
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001883 if (e1000_link_test(adapter, &data[4]))
1884 eth_test->flags |= ETH_TEST_FL_FAILED;
Bruce Allan11b08be2010-05-10 14:59:31 +00001885
Auke Kokbc7f75f2007-09-17 12:30:59 -07001886 clear_bit(__E1000_TESTING, &adapter->state);
1887 }
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001888
1889 if (!if_running) {
1890 e1000e_reset(adapter);
1891
1892 if (adapter->flags & FLAG_HAS_AMT)
1893 e1000e_release_hw_control(adapter);
1894 }
1895
Auke Kokbc7f75f2007-09-17 12:30:59 -07001896 msleep_interruptible(4 * 1000);
Bruce Allan3ef672a2013-06-27 02:44:44 +00001897
1898 pm_runtime_put_sync(netdev->dev.parent);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001899}
1900
1901static void e1000_get_wol(struct net_device *netdev,
1902 struct ethtool_wolinfo *wol)
1903{
1904 struct e1000_adapter *adapter = netdev_priv(netdev);
1905
1906 wol->supported = 0;
1907 wol->wolopts = 0;
1908
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001909 if (!(adapter->flags & FLAG_HAS_WOL) ||
1910 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001911 return;
1912
1913 wol->supported = WAKE_UCAST | WAKE_MCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001914 WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001915
1916 /* apply any specific unsupported masks here */
1917 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1918 wol->supported &= ~WAKE_UCAST;
1919
1920 if (adapter->wol & E1000_WUFC_EX)
Bruce Allan6ad65142012-04-12 05:47:09 +00001921 e_err("Interface does not support directed (unicast) frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001922 }
1923
1924 if (adapter->wol & E1000_WUFC_EX)
1925 wol->wolopts |= WAKE_UCAST;
1926 if (adapter->wol & E1000_WUFC_MC)
1927 wol->wolopts |= WAKE_MCAST;
1928 if (adapter->wol & E1000_WUFC_BC)
1929 wol->wolopts |= WAKE_BCAST;
1930 if (adapter->wol & E1000_WUFC_MAG)
1931 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001932 if (adapter->wol & E1000_WUFC_LNKC)
1933 wol->wolopts |= WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001934}
1935
Bruce Allan4a29e152011-03-04 09:07:01 +00001936static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001937{
1938 struct e1000_adapter *adapter = netdev_priv(netdev);
1939
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001940 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001941 !device_can_wakeup(&adapter->pdev->dev) ||
1942 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001943 WAKE_MAGIC | WAKE_PHY)))
Bruce Allan1fbfca32009-11-20 23:22:01 +00001944 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001945
1946 /* these settings will always override what we currently have */
1947 adapter->wol = 0;
1948
1949 if (wol->wolopts & WAKE_UCAST)
1950 adapter->wol |= E1000_WUFC_EX;
1951 if (wol->wolopts & WAKE_MCAST)
1952 adapter->wol |= E1000_WUFC_MC;
1953 if (wol->wolopts & WAKE_BCAST)
1954 adapter->wol |= E1000_WUFC_BC;
1955 if (wol->wolopts & WAKE_MAGIC)
1956 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001957 if (wol->wolopts & WAKE_PHY)
1958 adapter->wol |= E1000_WUFC_LNKC;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001959
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001960 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1961
Auke Kokbc7f75f2007-09-17 12:30:59 -07001962 return 0;
1963}
1964
Bruce Allandbf80dc2011-04-16 00:34:40 +00001965static int e1000_set_phys_id(struct net_device *netdev,
1966 enum ethtool_phys_id_state state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001967{
1968 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001969 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001970
Bruce Allandbf80dc2011-04-16 00:34:40 +00001971 switch (state) {
1972 case ETHTOOL_ID_ACTIVE:
Bruce Allan3ef672a2013-06-27 02:44:44 +00001973 pm_runtime_get_sync(netdev->dev.parent);
1974
Bruce Allandbf80dc2011-04-16 00:34:40 +00001975 if (!hw->mac.ops.blink_led)
1976 return 2; /* cycle on/off twice per second */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001977
Bruce Allandbf80dc2011-04-16 00:34:40 +00001978 hw->mac.ops.blink_led(hw);
1979 break;
1980
1981 case ETHTOOL_ID_INACTIVE:
Bruce Allan4662e822008-08-26 18:37:06 -07001982 if (hw->phy.type == e1000_phy_ife)
1983 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001984 hw->mac.ops.led_off(hw);
1985 hw->mac.ops.cleanup_led(hw);
Bruce Allan3ef672a2013-06-27 02:44:44 +00001986 pm_runtime_put_sync(netdev->dev.parent);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001987 break;
1988
1989 case ETHTOOL_ID_ON:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001990 hw->mac.ops.led_on(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001991 break;
1992
1993 case ETHTOOL_ID_OFF:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001994 hw->mac.ops.led_off(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001995 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001996 }
Bruce Allan3ef672a2013-06-27 02:44:44 +00001997
Auke Kokbc7f75f2007-09-17 12:30:59 -07001998 return 0;
1999}
2000
Auke Kokde5b3072008-04-23 11:09:08 -07002001static int e1000_get_coalesce(struct net_device *netdev,
2002 struct ethtool_coalesce *ec)
2003{
2004 struct e1000_adapter *adapter = netdev_priv(netdev);
2005
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00002006 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07002007 ec->rx_coalesce_usecs = adapter->itr_setting;
2008 else
2009 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
2010
2011 return 0;
2012}
2013
2014static int e1000_set_coalesce(struct net_device *netdev,
2015 struct ethtool_coalesce *ec)
2016{
2017 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokde5b3072008-04-23 11:09:08 -07002018
2019 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00002020 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07002021 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
2022 (ec->rx_coalesce_usecs == 2))
2023 return -EINVAL;
2024
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00002025 if (ec->rx_coalesce_usecs == 4) {
Bruce Allan06a402e2012-08-17 06:17:57 +00002026 adapter->itr_setting = 4;
2027 adapter->itr = adapter->itr_setting;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00002028 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07002029 adapter->itr = 20000;
2030 adapter->itr_setting = ec->rx_coalesce_usecs;
2031 } else {
2032 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
2033 adapter->itr_setting = adapter->itr & ~3;
2034 }
2035
Bruce Allan3ef672a2013-06-27 02:44:44 +00002036 pm_runtime_get_sync(netdev->dev.parent);
2037
Auke Kokde5b3072008-04-23 11:09:08 -07002038 if (adapter->itr_setting != 0)
Matthew Vick22a4cca2012-07-12 00:02:42 +00002039 e1000e_write_itr(adapter, adapter->itr);
Auke Kokde5b3072008-04-23 11:09:08 -07002040 else
Matthew Vick22a4cca2012-07-12 00:02:42 +00002041 e1000e_write_itr(adapter, 0);
Auke Kokde5b3072008-04-23 11:09:08 -07002042
Bruce Allan3ef672a2013-06-27 02:44:44 +00002043 pm_runtime_put_sync(netdev->dev.parent);
2044
Auke Kokde5b3072008-04-23 11:09:08 -07002045 return 0;
2046}
2047
Auke Kokbc7f75f2007-09-17 12:30:59 -07002048static int e1000_nway_reset(struct net_device *netdev)
2049{
2050 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan5962bc22011-01-20 06:58:07 +00002051
2052 if (!netif_running(netdev))
2053 return -EAGAIN;
2054
2055 if (!adapter->hw.mac.autoneg)
2056 return -EINVAL;
2057
Bruce Allan3ef672a2013-06-27 02:44:44 +00002058 pm_runtime_get_sync(netdev->dev.parent);
Bruce Allan5962bc22011-01-20 06:58:07 +00002059 e1000e_reinit_locked(adapter);
Bruce Allan3ef672a2013-06-27 02:44:44 +00002060 pm_runtime_put_sync(netdev->dev.parent);
Bruce Allan5962bc22011-01-20 06:58:07 +00002061
Auke Kokbc7f75f2007-09-17 12:30:59 -07002062 return 0;
2063}
2064
Auke Kokbc7f75f2007-09-17 12:30:59 -07002065static void e1000_get_ethtool_stats(struct net_device *netdev,
Bruce Allan8bb62862013-01-16 08:46:49 +00002066 struct ethtool_stats __always_unused *stats,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002067 u64 *data)
2068{
2069 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00002070 struct rtnl_link_stats64 net_stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002071 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00002072 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002073
Bruce Allan3ef672a2013-06-27 02:44:44 +00002074 pm_runtime_get_sync(netdev->dev.parent);
2075
Benjamin Poirier24ad2a92017-05-17 16:24:13 -04002076 dev_get_stats(netdev, &net_stats);
Bruce Allan3ef672a2013-06-27 02:44:44 +00002077
2078 pm_runtime_put_sync(netdev->dev.parent);
2079
Auke Kokbc7f75f2007-09-17 12:30:59 -07002080 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00002081 switch (e1000_gstrings_stats[i].type) {
2082 case NETDEV_STATS:
Bruce Allan53aa82d2013-02-20 04:06:06 +00002083 p = (char *)&net_stats +
Bruce Allanf0ff4392013-02-20 04:05:39 +00002084 e1000_gstrings_stats[i].stat_offset;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00002085 break;
2086 case E1000_STATS:
Bruce Allan53aa82d2013-02-20 04:06:06 +00002087 p = (char *)adapter +
Bruce Allanf0ff4392013-02-20 04:05:39 +00002088 e1000_gstrings_stats[i].stat_offset;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00002089 break;
Bruce Allan61c75812010-12-09 23:04:25 +00002090 default:
2091 data[i] = 0;
2092 continue;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00002093 }
2094
Auke Kokbc7f75f2007-09-17 12:30:59 -07002095 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
Bruce Allanf0ff4392013-02-20 04:05:39 +00002096 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002097 }
2098}
2099
Bruce Allan8bb62862013-01-16 08:46:49 +00002100static void e1000_get_strings(struct net_device __always_unused *netdev,
2101 u32 stringset, u8 *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002102{
2103 u8 *p = data;
2104 int i;
2105
2106 switch (stringset) {
2107 case ETH_SS_TEST:
Bruce Allan5c1bda02011-01-19 04:23:39 +00002108 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002109 break;
2110 case ETH_SS_STATS:
2111 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
2112 memcpy(p, e1000_gstrings_stats[i].stat_string,
2113 ETH_GSTRING_LEN);
2114 p += ETH_GSTRING_LEN;
2115 }
2116 break;
2117 }
2118}
2119
Bruce Allan70495a52012-01-11 01:26:50 +00002120static int e1000_get_rxnfc(struct net_device *netdev,
Bruce Allan8bb62862013-01-16 08:46:49 +00002121 struct ethtool_rxnfc *info,
2122 u32 __always_unused *rule_locs)
Bruce Allan70495a52012-01-11 01:26:50 +00002123{
2124 info->data = 0;
2125
2126 switch (info->cmd) {
2127 case ETHTOOL_GRXFH: {
2128 struct e1000_adapter *adapter = netdev_priv(netdev);
2129 struct e1000_hw *hw = &adapter->hw;
Bruce Allan3ef672a2013-06-27 02:44:44 +00002130 u32 mrqc;
2131
2132 pm_runtime_get_sync(netdev->dev.parent);
2133 mrqc = er32(MRQC);
2134 pm_runtime_put_sync(netdev->dev.parent);
Bruce Allan70495a52012-01-11 01:26:50 +00002135
2136 if (!(mrqc & E1000_MRQC_RSS_FIELD_MASK))
2137 return 0;
2138
2139 switch (info->flow_type) {
2140 case TCP_V4_FLOW:
2141 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP)
2142 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2143 /* fall through */
2144 case UDP_V4_FLOW:
2145 case SCTP_V4_FLOW:
2146 case AH_ESP_V4_FLOW:
2147 case IPV4_FLOW:
2148 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4)
2149 info->data |= RXH_IP_SRC | RXH_IP_DST;
2150 break;
2151 case TCP_V6_FLOW:
2152 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP)
2153 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2154 /* fall through */
2155 case UDP_V6_FLOW:
2156 case SCTP_V6_FLOW:
2157 case AH_ESP_V6_FLOW:
2158 case IPV6_FLOW:
2159 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6)
2160 info->data |= RXH_IP_SRC | RXH_IP_DST;
2161 break;
2162 default:
2163 break;
2164 }
2165 return 0;
2166 }
2167 default:
2168 return -EOPNOTSUPP;
2169 }
2170}
2171
Bruce Allan203e4152012-12-05 08:40:59 +00002172static int e1000e_get_eee(struct net_device *netdev, struct ethtool_eee *edata)
2173{
2174 struct e1000_adapter *adapter = netdev_priv(netdev);
2175 struct e1000_hw *hw = &adapter->hw;
Bruce Alland495bcb2013-03-20 07:23:11 +00002176 u16 cap_addr, lpa_addr, pcs_stat_addr, phy_data;
2177 u32 ret_val;
Bruce Allan203e4152012-12-05 08:40:59 +00002178
Bruce Alland495bcb2013-03-20 07:23:11 +00002179 if (!(adapter->flags2 & FLAG2_HAS_EEE))
Bruce Allan203e4152012-12-05 08:40:59 +00002180 return -EOPNOTSUPP;
2181
2182 switch (hw->phy.type) {
2183 case e1000_phy_82579:
2184 cap_addr = I82579_EEE_CAPABILITY;
Bruce Allan203e4152012-12-05 08:40:59 +00002185 lpa_addr = I82579_EEE_LP_ABILITY;
2186 pcs_stat_addr = I82579_EEE_PCS_STATUS;
2187 break;
2188 case e1000_phy_i217:
2189 cap_addr = I217_EEE_CAPABILITY;
Bruce Allan203e4152012-12-05 08:40:59 +00002190 lpa_addr = I217_EEE_LP_ABILITY;
2191 pcs_stat_addr = I217_EEE_PCS_STATUS;
2192 break;
2193 default:
2194 return -EOPNOTSUPP;
2195 }
2196
Bruce Allan3ef672a2013-06-27 02:44:44 +00002197 pm_runtime_get_sync(netdev->dev.parent);
2198
Bruce Allan203e4152012-12-05 08:40:59 +00002199 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan3ef672a2013-06-27 02:44:44 +00002200 if (ret_val) {
2201 pm_runtime_put_sync(netdev->dev.parent);
Bruce Allan203e4152012-12-05 08:40:59 +00002202 return -EBUSY;
Bruce Allan3ef672a2013-06-27 02:44:44 +00002203 }
Bruce Allan203e4152012-12-05 08:40:59 +00002204
2205 /* EEE Capability */
2206 ret_val = e1000_read_emi_reg_locked(hw, cap_addr, &phy_data);
2207 if (ret_val)
2208 goto release;
2209 edata->supported = mmd_eee_cap_to_ethtool_sup_t(phy_data);
2210
2211 /* EEE Advertised */
Bruce Alland495bcb2013-03-20 07:23:11 +00002212 edata->advertised = mmd_eee_adv_to_ethtool_adv_t(adapter->eee_advert);
Bruce Allan203e4152012-12-05 08:40:59 +00002213
2214 /* EEE Link Partner Advertised */
2215 ret_val = e1000_read_emi_reg_locked(hw, lpa_addr, &phy_data);
2216 if (ret_val)
2217 goto release;
2218 edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
2219
2220 /* EEE PCS Status */
2221 ret_val = e1000_read_emi_reg_locked(hw, pcs_stat_addr, &phy_data);
Bruce Allan3ef672a2013-06-27 02:44:44 +00002222 if (ret_val)
2223 goto release;
Bruce Allan203e4152012-12-05 08:40:59 +00002224 if (hw->phy.type == e1000_phy_82579)
2225 phy_data <<= 8;
2226
Bruce Allan203e4152012-12-05 08:40:59 +00002227 /* Result of the EEE auto negotiation - there is no register that
2228 * has the status of the EEE negotiation so do a best-guess based
Bruce Alland495bcb2013-03-20 07:23:11 +00002229 * on whether Tx or Rx LPI indications have been received.
Bruce Allan203e4152012-12-05 08:40:59 +00002230 */
Bruce Alland495bcb2013-03-20 07:23:11 +00002231 if (phy_data & (E1000_EEE_TX_LPI_RCVD | E1000_EEE_RX_LPI_RCVD))
Bruce Allan203e4152012-12-05 08:40:59 +00002232 edata->eee_active = true;
2233
2234 edata->eee_enabled = !hw->dev_spec.ich8lan.eee_disable;
2235 edata->tx_lpi_enabled = true;
2236 edata->tx_lpi_timer = er32(LPIC) >> E1000_LPIC_LPIET_SHIFT;
2237
Bruce Allan3ef672a2013-06-27 02:44:44 +00002238release:
2239 hw->phy.ops.release(hw);
2240 if (ret_val)
2241 ret_val = -ENODATA;
2242
2243 pm_runtime_put_sync(netdev->dev.parent);
2244
2245 return ret_val;
Bruce Allan203e4152012-12-05 08:40:59 +00002246}
2247
2248static int e1000e_set_eee(struct net_device *netdev, struct ethtool_eee *edata)
2249{
2250 struct e1000_adapter *adapter = netdev_priv(netdev);
2251 struct e1000_hw *hw = &adapter->hw;
2252 struct ethtool_eee eee_curr;
2253 s32 ret_val;
2254
Bruce Allan203e4152012-12-05 08:40:59 +00002255 ret_val = e1000e_get_eee(netdev, &eee_curr);
2256 if (ret_val)
2257 return ret_val;
2258
Bruce Allan203e4152012-12-05 08:40:59 +00002259 if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
2260 e_err("Setting EEE tx-lpi is not supported\n");
2261 return -EINVAL;
2262 }
2263
2264 if (eee_curr.tx_lpi_timer != edata->tx_lpi_timer) {
2265 e_err("Setting EEE Tx LPI timer is not supported\n");
2266 return -EINVAL;
2267 }
2268
Bruce Alland495bcb2013-03-20 07:23:11 +00002269 if (edata->advertised & ~(ADVERTISE_100_FULL | ADVERTISE_1000_FULL)) {
2270 e_err("EEE advertisement supports only 100TX and/or 1000T full-duplex\n");
2271 return -EINVAL;
Bruce Allan203e4152012-12-05 08:40:59 +00002272 }
2273
Bruce Alland495bcb2013-03-20 07:23:11 +00002274 adapter->eee_advert = ethtool_adv_to_mmd_eee_adv_t(edata->advertised);
2275
2276 hw->dev_spec.ich8lan.eee_disable = !edata->eee_enabled;
2277
Bruce Allan3ef672a2013-06-27 02:44:44 +00002278 pm_runtime_get_sync(netdev->dev.parent);
2279
Bruce Alland495bcb2013-03-20 07:23:11 +00002280 /* reset the link */
2281 if (netif_running(netdev))
2282 e1000e_reinit_locked(adapter);
2283 else
2284 e1000e_reset(adapter);
2285
Bruce Allan3ef672a2013-06-27 02:44:44 +00002286 pm_runtime_put_sync(netdev->dev.parent);
2287
Bruce Allan203e4152012-12-05 08:40:59 +00002288 return 0;
2289}
2290
Bruce Allanb67e1912012-12-27 08:32:33 +00002291static int e1000e_get_ts_info(struct net_device *netdev,
2292 struct ethtool_ts_info *info)
2293{
2294 struct e1000_adapter *adapter = netdev_priv(netdev);
2295
2296 ethtool_op_get_ts_info(netdev, info);
2297
2298 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
2299 return 0;
2300
2301 info->so_timestamping |= (SOF_TIMESTAMPING_TX_HARDWARE |
2302 SOF_TIMESTAMPING_RX_HARDWARE |
2303 SOF_TIMESTAMPING_RAW_HARDWARE);
2304
Jacob Keller18dd2392016-04-13 16:08:32 -07002305 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Bruce Allanb67e1912012-12-27 08:32:33 +00002306
Jacob Keller18dd2392016-04-13 16:08:32 -07002307 info->rx_filters = (BIT(HWTSTAMP_FILTER_NONE) |
2308 BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
2309 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
2310 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
2311 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
2312 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
2313 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
2314 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
2315 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
2316 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
2317 BIT(HWTSTAMP_FILTER_ALL));
Bruce Allanb67e1912012-12-27 08:32:33 +00002318
Bruce Alland89777b2013-01-19 01:09:58 +00002319 if (adapter->ptp_clock)
2320 info->phc_index = ptp_clock_index(adapter->ptp_clock);
2321
Bruce Allanb67e1912012-12-27 08:32:33 +00002322 return 0;
2323}
2324
Auke Kokbc7f75f2007-09-17 12:30:59 -07002325static const struct ethtool_ops e1000_ethtool_ops = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002326 .get_drvinfo = e1000_get_drvinfo,
2327 .get_regs_len = e1000_get_regs_len,
2328 .get_regs = e1000_get_regs,
2329 .get_wol = e1000_get_wol,
2330 .set_wol = e1000_set_wol,
2331 .get_msglevel = e1000_get_msglevel,
2332 .set_msglevel = e1000_set_msglevel,
2333 .nway_reset = e1000_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00002334 .get_link = ethtool_op_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002335 .get_eeprom_len = e1000_get_eeprom_len,
2336 .get_eeprom = e1000_get_eeprom,
2337 .set_eeprom = e1000_set_eeprom,
2338 .get_ringparam = e1000_get_ringparam,
2339 .set_ringparam = e1000_set_ringparam,
2340 .get_pauseparam = e1000_get_pauseparam,
2341 .set_pauseparam = e1000_set_pauseparam,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002342 .self_test = e1000_diag_test,
2343 .get_strings = e1000_get_strings,
Bruce Allandbf80dc2011-04-16 00:34:40 +00002344 .set_phys_id = e1000_set_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002345 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07002346 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07002347 .get_coalesce = e1000_get_coalesce,
2348 .set_coalesce = e1000_set_coalesce,
Bruce Allan70495a52012-01-11 01:26:50 +00002349 .get_rxnfc = e1000_get_rxnfc,
Bruce Allanb67e1912012-12-27 08:32:33 +00002350 .get_ts_info = e1000e_get_ts_info,
Bruce Allan203e4152012-12-05 08:40:59 +00002351 .get_eee = e1000e_get_eee,
2352 .set_eee = e1000e_set_eee,
Philippe Reynesfb052fd2017-01-26 22:19:53 +01002353 .get_link_ksettings = e1000_get_link_ksettings,
2354 .set_link_ksettings = e1000_set_link_ksettings,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002355};
2356
2357void e1000e_set_ethtool_ops(struct net_device *netdev)
2358{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002359 netdev->ethtool_ops = &e1000_ethtool_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002360}