blob: e23dbd9190d6b4ff47cd71bd30849676b2689acc [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),
Auke Kokbc7f75f2007-09-17 12:30:59 -0700108};
109
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200110#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700111#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
112static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
113 "Register test (offline)", "Eeprom test (offline)",
114 "Interrupt test (offline)", "Loopback test (offline)",
115 "Link test (on/offline)"
116};
Bruce Allanfc830b72013-02-20 04:06:11 +0000117
Bruce Allanad680762008-03-28 09:15:03 -0700118#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700119
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100120static int e1000_get_link_ksettings(struct net_device *netdev,
121 struct ethtool_link_ksettings *cmd)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700122{
123 struct e1000_adapter *adapter = netdev_priv(netdev);
124 struct e1000_hw *hw = &adapter->hw;
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100125 u32 speed, supported, advertising;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700126
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700127 if (hw->phy.media_type == e1000_media_type_copper) {
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100128 supported = (SUPPORTED_10baseT_Half |
129 SUPPORTED_10baseT_Full |
130 SUPPORTED_100baseT_Half |
131 SUPPORTED_100baseT_Full |
132 SUPPORTED_1000baseT_Full |
133 SUPPORTED_Autoneg |
134 SUPPORTED_TP);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700135 if (hw->phy.type == e1000_phy_ife)
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100136 supported &= ~SUPPORTED_1000baseT_Full;
137 advertising = ADVERTISED_TP;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700138
139 if (hw->mac.autoneg == 1) {
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100140 advertising |= ADVERTISED_Autoneg;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700141 /* the e1000 autoneg seems to match ethtool nicely */
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100142 advertising |= hw->phy.autoneg_advertised;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700143 }
144
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100145 cmd->base.port = PORT_TP;
146 cmd->base.phy_address = hw->phy.addr;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700147 } else {
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100148 supported = (SUPPORTED_1000baseT_Full |
149 SUPPORTED_FIBRE |
150 SUPPORTED_Autoneg);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700151
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100152 advertising = (ADVERTISED_1000baseT_Full |
153 ADVERTISED_FIBRE |
154 ADVERTISED_Autoneg);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700155
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100156 cmd->base.port = PORT_FIBRE;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700157 }
158
Jiri Pirko537fae02014-06-06 14:17:00 +0200159 speed = SPEED_UNKNOWN;
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100160 cmd->base.duplex = DUPLEX_UNKNOWN;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700161
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000162 if (netif_running(netdev)) {
163 if (netif_carrier_ok(netdev)) {
David Decotigny70739492011-04-27 18:32:40 +0000164 speed = adapter->link_speed;
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100165 cmd->base.duplex = adapter->link_duplex - 1;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000166 }
Bruce Allan3ef672a2013-06-27 02:44:44 +0000167 } else if (!pm_runtime_suspended(netdev->dev.parent)) {
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000168 u32 status = er32(STATUS);
David Ertman6cf08d12014-04-05 06:07:00 +0000169
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000170 if (status & E1000_STATUS_LU) {
171 if (status & E1000_STATUS_SPEED_1000)
David Decotigny70739492011-04-27 18:32:40 +0000172 speed = SPEED_1000;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000173 else if (status & E1000_STATUS_SPEED_100)
David Decotigny70739492011-04-27 18:32:40 +0000174 speed = SPEED_100;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000175 else
David Decotigny70739492011-04-27 18:32:40 +0000176 speed = SPEED_10;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000177
178 if (status & E1000_STATUS_FD)
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100179 cmd->base.duplex = DUPLEX_FULL;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000180 else
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100181 cmd->base.duplex = DUPLEX_HALF;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000182 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700183 }
184
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100185 cmd->base.speed = speed;
186 cmd->base.autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -0700187 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000188
189 /* MDI-X => 2; MDI =>1; Invalid =>0 */
190 if ((hw->phy.media_type == e1000_media_type_copper) &&
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000191 netif_carrier_ok(netdev))
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100192 cmd->base.eth_tp_mdix = hw->phy.is_mdix ?
193 ETH_TP_MDI_X : ETH_TP_MDI;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000194 else
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100195 cmd->base.eth_tp_mdix = ETH_TP_MDI_INVALID;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000196
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000197 if (hw->phy.mdix == AUTO_ALL_MODES)
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100198 cmd->base.eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000199 else
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100200 cmd->base.eth_tp_mdix_ctrl = hw->phy.mdix;
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000201
Steve Shihe11f3032016-04-05 11:30:03 -0700202 if (hw->phy.media_type != e1000_media_type_copper)
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100203 cmd->base.eth_tp_mdix_ctrl = ETH_TP_MDI_INVALID;
204
205 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
206 supported);
207 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
208 advertising);
Steve Shihe11f3032016-04-05 11:30:03 -0700209
Auke Kokbc7f75f2007-09-17 12:30:59 -0700210 return 0;
211}
212
David Decotigny14ad2512011-04-27 18:32:43 +0000213static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700214{
215 struct e1000_mac_info *mac = &adapter->hw.mac;
216
217 mac->autoneg = 0;
218
David Decotigny14ad2512011-04-27 18:32:43 +0000219 /* Make sure dplx is at most 1 bit and lsb of speed is not set
Bruce Allane921eb12012-11-28 09:28:37 +0000220 * for the switch() below to work
221 */
David Decotigny14ad2512011-04-27 18:32:43 +0000222 if ((spd & 1) || (dplx & ~1))
223 goto err_inval;
224
Auke Kokbc7f75f2007-09-17 12:30:59 -0700225 /* Fiber NICs only allow 1000 gbps Full duplex */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700226 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
Bruce Allane5fe2542013-02-20 04:06:27 +0000227 (spd != SPEED_1000) && (dplx != DUPLEX_FULL)) {
David Decotigny14ad2512011-04-27 18:32:43 +0000228 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700229 }
230
David Decotigny14ad2512011-04-27 18:32:43 +0000231 switch (spd + dplx) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700232 case SPEED_10 + DUPLEX_HALF:
233 mac->forced_speed_duplex = ADVERTISE_10_HALF;
234 break;
235 case SPEED_10 + DUPLEX_FULL:
236 mac->forced_speed_duplex = ADVERTISE_10_FULL;
237 break;
238 case SPEED_100 + DUPLEX_HALF:
239 mac->forced_speed_duplex = ADVERTISE_100_HALF;
240 break;
241 case SPEED_100 + DUPLEX_FULL:
242 mac->forced_speed_duplex = ADVERTISE_100_FULL;
243 break;
244 case SPEED_1000 + DUPLEX_FULL:
Steve Shihe11f3032016-04-05 11:30:03 -0700245 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
246 mac->autoneg = 1;
247 adapter->hw.phy.autoneg_advertised =
248 ADVERTISE_1000_FULL;
249 } else {
250 mac->forced_speed_duplex = ADVERTISE_1000_FULL;
251 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700252 break;
Bruce Allane80bd1d2013-05-01 01:19:46 +0000253 case SPEED_1000 + DUPLEX_HALF: /* not supported */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700254 default:
David Decotigny14ad2512011-04-27 18:32:43 +0000255 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700256 }
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000257
258 /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
259 adapter->hw.phy.mdix = AUTO_ALL_MODES;
260
Auke Kokbc7f75f2007-09-17 12:30:59 -0700261 return 0;
David Decotigny14ad2512011-04-27 18:32:43 +0000262
263err_inval:
264 e_err("Unsupported Speed/Duplex configuration\n");
265 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700266}
267
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100268static int e1000_set_link_ksettings(struct net_device *netdev,
269 const struct ethtool_link_ksettings *cmd)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700270{
271 struct e1000_adapter *adapter = netdev_priv(netdev);
272 struct e1000_hw *hw = &adapter->hw;
Bruce Allan3ef672a2013-06-27 02:44:44 +0000273 int ret_val = 0;
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100274 u32 advertising;
275
276 ethtool_convert_link_mode_to_legacy_u32(&advertising,
277 cmd->link_modes.advertising);
Bruce Allan3ef672a2013-06-27 02:44:44 +0000278
279 pm_runtime_get_sync(netdev->dev.parent);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700280
Bruce Allane921eb12012-11-28 09:28:37 +0000281 /* When SoL/IDER sessions are active, autoneg/speed/duplex
Bruce Allanad680762008-03-28 09:15:03 -0700282 * cannot be changed
283 */
Bruce Allan470a5422012-05-26 06:08:48 +0000284 if (hw->phy.ops.check_reset_block &&
285 hw->phy.ops.check_reset_block(hw)) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000286 e_err("Cannot change link characteristics when SoL/IDER is active.\n");
Bruce Allan3ef672a2013-06-27 02:44:44 +0000287 ret_val = -EINVAL;
288 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700289 }
290
Bruce Allane921eb12012-11-28 09:28:37 +0000291 /* MDI setting is only allowed when autoneg enabled because
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000292 * some hardware doesn't allow MDI setting when speed or
293 * duplex is forced.
294 */
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100295 if (cmd->base.eth_tp_mdix_ctrl) {
Bruce Allan3ef672a2013-06-27 02:44:44 +0000296 if (hw->phy.media_type != e1000_media_type_copper) {
297 ret_val = -EOPNOTSUPP;
298 goto out;
299 }
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000300
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100301 if ((cmd->base.eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) &&
302 (cmd->base.autoneg != AUTONEG_ENABLE)) {
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000303 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 +0000304 ret_val = -EINVAL;
305 goto out;
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000306 }
307 }
308
Auke Kokbc7f75f2007-09-17 12:30:59 -0700309 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000310 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700311
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100312 if (cmd->base.autoneg == AUTONEG_ENABLE) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700313 hw->mac.autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700314 if (hw->phy.media_type == e1000_media_type_fiber)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700315 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
Bruce Allanf0ff4392013-02-20 04:05:39 +0000316 ADVERTISED_FIBRE | ADVERTISED_Autoneg;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700317 else
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100318 hw->phy.autoneg_advertised = advertising |
Bruce Allanf0ff4392013-02-20 04:05:39 +0000319 ADVERTISED_TP | ADVERTISED_Autoneg;
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100320 advertising = hw->phy.autoneg_advertised;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700321 if (adapter->fc_autoneg)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800322 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700323 } else {
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100324 u32 speed = cmd->base.speed;
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000325 /* calling this overrides forced MDI setting */
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100326 if (e1000_set_spd_dplx(adapter, speed, cmd->base.duplex)) {
Bruce Allan3ef672a2013-06-27 02:44:44 +0000327 ret_val = -EINVAL;
328 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700329 }
330 }
331
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000332 /* MDI-X => 2; MDI => 1; Auto => 3 */
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100333 if (cmd->base.eth_tp_mdix_ctrl) {
Bruce Allane921eb12012-11-28 09:28:37 +0000334 /* fix up the value for auto (3 => 0) as zero is mapped
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000335 * internally to auto
336 */
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100337 if (cmd->base.eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000338 hw->phy.mdix = AUTO_ALL_MODES;
339 else
Philippe Reynesfb052fd2017-01-26 22:19:53 +0100340 hw->phy.mdix = cmd->base.eth_tp_mdix_ctrl;
Jesse Brandeburg4e8186b2012-07-26 02:31:14 +0000341 }
342
Auke Kokbc7f75f2007-09-17 12:30:59 -0700343 /* reset the link */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700344 if (netif_running(adapter->netdev)) {
David Ertman28002092014-02-14 07:16:41 +0000345 e1000e_down(adapter, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700346 e1000e_up(adapter);
Bruce Allana7a1d9d2013-01-24 00:50:18 +0000347 } else {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700348 e1000e_reset(adapter);
Bruce Allana7a1d9d2013-01-24 00:50:18 +0000349 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700350
Bruce Allan3ef672a2013-06-27 02:44:44 +0000351out:
352 pm_runtime_put_sync(netdev->dev.parent);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700353 clear_bit(__E1000_RESETTING, &adapter->state);
Bruce Allan3ef672a2013-06-27 02:44:44 +0000354 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700355}
356
357static void e1000_get_pauseparam(struct net_device *netdev,
358 struct ethtool_pauseparam *pause)
359{
360 struct e1000_adapter *adapter = netdev_priv(netdev);
361 struct e1000_hw *hw = &adapter->hw;
362
363 pause->autoneg =
Bruce Allanf0ff4392013-02-20 04:05:39 +0000364 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700365
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800366 if (hw->fc.current_mode == e1000_fc_rx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700367 pause->rx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800368 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700369 pause->tx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800370 } else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700371 pause->rx_pause = 1;
372 pause->tx_pause = 1;
373 }
374}
375
376static int e1000_set_pauseparam(struct net_device *netdev,
377 struct ethtool_pauseparam *pause)
378{
379 struct e1000_adapter *adapter = netdev_priv(netdev);
380 struct e1000_hw *hw = &adapter->hw;
381 int retval = 0;
382
383 adapter->fc_autoneg = pause->autoneg;
384
385 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000386 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700387
Bruce Allan3ef672a2013-06-27 02:44:44 +0000388 pm_runtime_get_sync(netdev->dev.parent);
389
Auke Kokbc7f75f2007-09-17 12:30:59 -0700390 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800391 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700392 if (netif_running(adapter->netdev)) {
David Ertman28002092014-02-14 07:16:41 +0000393 e1000e_down(adapter, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700394 e1000e_up(adapter);
395 } else {
396 e1000e_reset(adapter);
397 }
398 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800399 if (pause->rx_pause && pause->tx_pause)
400 hw->fc.requested_mode = e1000_fc_full;
401 else if (pause->rx_pause && !pause->tx_pause)
402 hw->fc.requested_mode = e1000_fc_rx_pause;
403 else if (!pause->rx_pause && pause->tx_pause)
404 hw->fc.requested_mode = e1000_fc_tx_pause;
405 else if (!pause->rx_pause && !pause->tx_pause)
406 hw->fc.requested_mode = e1000_fc_none;
407
408 hw->fc.current_mode = hw->fc.requested_mode;
409
Bruce Allan945eb312009-10-28 18:28:30 +0000410 if (hw->phy.media_type == e1000_media_type_fiber) {
411 retval = hw->mac.ops.setup_link(hw);
412 /* implicit goto out */
413 } else {
414 retval = e1000e_force_mac_fc(hw);
415 if (retval)
416 goto out;
417 e1000e_set_fc_watermarks(hw);
418 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700419 }
420
Bruce Allan945eb312009-10-28 18:28:30 +0000421out:
Bruce Allan3ef672a2013-06-27 02:44:44 +0000422 pm_runtime_put_sync(netdev->dev.parent);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700423 clear_bit(__E1000_RESETTING, &adapter->state);
424 return retval;
425}
426
Auke Kokbc7f75f2007-09-17 12:30:59 -0700427static u32 e1000_get_msglevel(struct net_device *netdev)
428{
429 struct e1000_adapter *adapter = netdev_priv(netdev);
430 return adapter->msg_enable;
431}
432
433static void e1000_set_msglevel(struct net_device *netdev, u32 data)
434{
435 struct e1000_adapter *adapter = netdev_priv(netdev);
436 adapter->msg_enable = data;
437}
438
Bruce Allan8bb62862013-01-16 08:46:49 +0000439static int e1000_get_regs_len(struct net_device __always_unused *netdev)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700440{
Bruce Allane80bd1d2013-05-01 01:19:46 +0000441#define E1000_REGS_LEN 32 /* overestimate */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700442 return E1000_REGS_LEN * sizeof(u32);
443}
444
445static void e1000_get_regs(struct net_device *netdev,
446 struct ethtool_regs *regs, void *p)
447{
448 struct e1000_adapter *adapter = netdev_priv(netdev);
449 struct e1000_hw *hw = &adapter->hw;
450 u32 *regs_buff = p;
451 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700452
Bruce Allan3ef672a2013-06-27 02:44:44 +0000453 pm_runtime_get_sync(netdev->dev.parent);
454
Auke Kokbc7f75f2007-09-17 12:30:59 -0700455 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
456
Jacob Keller18dd2392016-04-13 16:08:32 -0700457 regs->version = (1u << 24) |
458 (adapter->pdev->revision << 16) |
459 adapter->pdev->device;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700460
Bruce Allane80bd1d2013-05-01 01:19:46 +0000461 regs_buff[0] = er32(CTRL);
462 regs_buff[1] = er32(STATUS);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700463
Bruce Allane80bd1d2013-05-01 01:19:46 +0000464 regs_buff[2] = er32(RCTL);
465 regs_buff[3] = er32(RDLEN(0));
466 regs_buff[4] = er32(RDH(0));
467 regs_buff[5] = er32(RDT(0));
468 regs_buff[6] = er32(RDTR);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700469
Bruce Allane80bd1d2013-05-01 01:19:46 +0000470 regs_buff[7] = er32(TCTL);
471 regs_buff[8] = er32(TDLEN(0));
472 regs_buff[9] = er32(TDH(0));
Bruce Allan1e360522012-03-20 03:48:13 +0000473 regs_buff[10] = er32(TDT(0));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700474 regs_buff[11] = er32(TIDV);
475
Bruce Allane80bd1d2013-05-01 01:19:46 +0000476 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700477
478 /* ethtool doesn't use anything past this point, so all this
Bruce Allane921eb12012-11-28 09:28:37 +0000479 * code is likely legacy junk for apps that may or may not exist
480 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700481 if (hw->phy.type == e1000_phy_m88) {
482 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
483 regs_buff[13] = (u32)phy_data; /* cable length */
484 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
485 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
486 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
487 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
488 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
489 regs_buff[18] = regs_buff[13]; /* cable polarity */
490 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
491 regs_buff[20] = regs_buff[17]; /* polarity correction */
492 /* phy receive errors */
493 regs_buff[22] = adapter->phy_stats.receive_errors;
494 regs_buff[23] = regs_buff[13]; /* mdix mode */
495 }
Bruce Allanc2ade1a2013-01-16 08:54:35 +0000496 regs_buff[21] = 0; /* was idle_errors */
497 e1e_rphy(hw, MII_STAT1000, &phy_data);
498 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
499 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
Bruce Allan3ef672a2013-06-27 02:44:44 +0000500
501 pm_runtime_put_sync(netdev->dev.parent);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700502}
503
504static int e1000_get_eeprom_len(struct net_device *netdev)
505{
506 struct e1000_adapter *adapter = netdev_priv(netdev);
507 return adapter->hw.nvm.word_size * 2;
508}
509
510static int e1000_get_eeprom(struct net_device *netdev,
511 struct ethtool_eeprom *eeprom, u8 *bytes)
512{
513 struct e1000_adapter *adapter = netdev_priv(netdev);
514 struct e1000_hw *hw = &adapter->hw;
515 u16 *eeprom_buff;
516 int first_word;
517 int last_word;
518 int ret_val = 0;
519 u16 i;
520
521 if (eeprom->len == 0)
522 return -EINVAL;
523
524 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
525
526 first_word = eeprom->offset >> 1;
527 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
528
Bruce Allan17e813e2013-02-20 04:06:01 +0000529 eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
530 GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700531 if (!eeprom_buff)
532 return -ENOMEM;
533
Bruce Allan3ef672a2013-06-27 02:44:44 +0000534 pm_runtime_get_sync(netdev->dev.parent);
535
Auke Kokbc7f75f2007-09-17 12:30:59 -0700536 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
537 ret_val = e1000_read_nvm(hw, first_word,
538 last_word - first_word + 1,
539 eeprom_buff);
540 } else {
541 for (i = 0; i < last_word - first_word + 1; i++) {
542 ret_val = e1000_read_nvm(hw, first_word + i, 1,
Bruce Allan17e813e2013-02-20 04:06:01 +0000543 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800544 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700545 break;
546 }
547 }
548
Bruce Allan3ef672a2013-06-27 02:44:44 +0000549 pm_runtime_put_sync(netdev->dev.parent);
550
Bruce Allane2434552008-11-21 17:02:41 -0800551 if (ret_val) {
552 /* a read error occurred, throw away the result */
Roel Kluin8528b012009-12-01 15:54:24 +0000553 memset(eeprom_buff, 0xff, sizeof(u16) *
554 (last_word - first_word + 1));
Bruce Allane2434552008-11-21 17:02:41 -0800555 } else {
556 /* Device's eeprom is always little-endian, word addressable */
557 for (i = 0; i < last_word - first_word + 1; i++)
558 le16_to_cpus(&eeprom_buff[i]);
559 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700560
561 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
562 kfree(eeprom_buff);
563
564 return ret_val;
565}
566
567static int e1000_set_eeprom(struct net_device *netdev,
568 struct ethtool_eeprom *eeprom, u8 *bytes)
569{
570 struct e1000_adapter *adapter = netdev_priv(netdev);
571 struct e1000_hw *hw = &adapter->hw;
572 u16 *eeprom_buff;
573 void *ptr;
574 int max_len;
575 int first_word;
576 int last_word;
577 int ret_val = 0;
578 u16 i;
579
580 if (eeprom->len == 0)
581 return -EOPNOTSUPP;
582
Bruce Allanc29c3ba2013-02-20 04:05:50 +0000583 if (eeprom->magic !=
584 (adapter->pdev->vendor | (adapter->pdev->device << 16)))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700585 return -EFAULT;
586
Bruce Allan4a770352008-10-01 17:18:35 -0700587 if (adapter->flags & FLAG_READ_ONLY_NVM)
588 return -EINVAL;
589
Auke Kokbc7f75f2007-09-17 12:30:59 -0700590 max_len = hw->nvm.word_size * 2;
591
592 first_word = eeprom->offset >> 1;
593 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
594 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
595 if (!eeprom_buff)
596 return -ENOMEM;
597
598 ptr = (void *)eeprom_buff;
599
Bruce Allan3ef672a2013-06-27 02:44:44 +0000600 pm_runtime_get_sync(netdev->dev.parent);
601
Auke Kokbc7f75f2007-09-17 12:30:59 -0700602 if (eeprom->offset & 1) {
603 /* need read/modify/write of first changed EEPROM word */
604 /* only the second byte of the word is being modified */
605 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
606 ptr++;
607 }
Bruce Allan9e2d7652012-01-31 06:37:27 +0000608 if (((eeprom->offset + eeprom->len) & 1) && (!ret_val))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700609 /* need read/modify/write of last changed EEPROM word */
610 /* only the first byte of the word is being modified */
611 ret_val = e1000_read_nvm(hw, last_word, 1,
Bruce Allan17e813e2013-02-20 04:06:01 +0000612 &eeprom_buff[last_word - first_word]);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700613
Bruce Allane2434552008-11-21 17:02:41 -0800614 if (ret_val)
615 goto out;
616
Auke Kokbc7f75f2007-09-17 12:30:59 -0700617 /* Device's eeprom is always little-endian, word addressable */
618 for (i = 0; i < last_word - first_word + 1; i++)
619 le16_to_cpus(&eeprom_buff[i]);
620
621 memcpy(ptr, bytes, eeprom->len);
622
623 for (i = 0; i < last_word - first_word + 1; i++)
Bruce Allane885d762012-01-31 06:37:32 +0000624 cpu_to_le16s(&eeprom_buff[i]);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700625
626 ret_val = e1000_write_nvm(hw, first_word,
627 last_word - first_word + 1, eeprom_buff);
628
Bruce Allane2434552008-11-21 17:02:41 -0800629 if (ret_val)
630 goto out;
631
Bruce Allane921eb12012-11-28 09:28:37 +0000632 /* Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800633 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700634 */
Bruce Allane2434552008-11-21 17:02:41 -0800635 if ((first_word <= NVM_CHECKSUM_REG) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +0000636 (hw->mac.type == e1000_82583) ||
637 (hw->mac.type == e1000_82574) ||
638 (hw->mac.type == e1000_82573))
Bruce Allane2434552008-11-21 17:02:41 -0800639 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700640
Bruce Allane2434552008-11-21 17:02:41 -0800641out:
Bruce Allan3ef672a2013-06-27 02:44:44 +0000642 pm_runtime_put_sync(netdev->dev.parent);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700643 kfree(eeprom_buff);
644 return ret_val;
645}
646
647static void e1000_get_drvinfo(struct net_device *netdev,
648 struct ethtool_drvinfo *drvinfo)
649{
650 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700651
Bruce Allane5fe2542013-02-20 04:06:27 +0000652 strlcpy(drvinfo->driver, e1000e_driver_name, sizeof(drvinfo->driver));
Rick Jones33a5ba12011-11-15 14:59:53 +0000653 strlcpy(drvinfo->version, e1000e_driver_version,
Rick Jones612a94d2011-11-14 08:13:25 +0000654 sizeof(drvinfo->version));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700655
Bruce Allane921eb12012-11-28 09:28:37 +0000656 /* EEPROM image version # is reported as firmware version # for
Bruce Allanad680762008-03-28 09:15:03 -0700657 * PCI-E controllers
658 */
Rick Jones612a94d2011-11-14 08:13:25 +0000659 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
Bruce Allan17e813e2013-02-20 04:06:01 +0000660 "%d.%d-%d",
661 (adapter->eeprom_vers & 0xF000) >> 12,
662 (adapter->eeprom_vers & 0x0FF0) >> 4,
663 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700664
Rick Jones612a94d2011-11-14 08:13:25 +0000665 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
666 sizeof(drvinfo->bus_info));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700667}
668
669static void e1000_get_ringparam(struct net_device *netdev,
670 struct ethtool_ringparam *ring)
671{
672 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700673
674 ring->rx_max_pending = E1000_MAX_RXD;
675 ring->tx_max_pending = E1000_MAX_TXD;
Bruce Allan508da422011-12-16 00:45:51 +0000676 ring->rx_pending = adapter->rx_ring_count;
677 ring->tx_pending = adapter->tx_ring_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700678}
679
680static int e1000_set_ringparam(struct net_device *netdev,
681 struct ethtool_ringparam *ring)
682{
683 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan508da422011-12-16 00:45:51 +0000684 struct e1000_ring *temp_tx = NULL, *temp_rx = NULL;
685 int err = 0, size = sizeof(struct e1000_ring);
686 bool set_tx = false, set_rx = false;
687 u16 new_rx_count, new_tx_count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700688
689 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
690 return -EINVAL;
691
Bruce Allan508da422011-12-16 00:45:51 +0000692 new_rx_count = clamp_t(u32, ring->rx_pending, E1000_MIN_RXD,
693 E1000_MAX_RXD);
694 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
695
696 new_tx_count = clamp_t(u32, ring->tx_pending, E1000_MIN_TXD,
697 E1000_MAX_TXD);
698 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
699
700 if ((new_tx_count == adapter->tx_ring_count) &&
701 (new_rx_count == adapter->rx_ring_count))
702 /* nothing to do */
703 return 0;
704
Auke Kokbc7f75f2007-09-17 12:30:59 -0700705 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000706 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700707
Bruce Allan508da422011-12-16 00:45:51 +0000708 if (!netif_running(adapter->netdev)) {
709 /* Set counts now and allocate resources during open() */
710 adapter->tx_ring->count = new_tx_count;
711 adapter->rx_ring->count = new_rx_count;
712 adapter->tx_ring_count = new_tx_count;
713 adapter->rx_ring_count = new_rx_count;
714 goto clear_reset;
715 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700716
Bruce Allan508da422011-12-16 00:45:51 +0000717 set_tx = (new_tx_count != adapter->tx_ring_count);
718 set_rx = (new_rx_count != adapter->rx_ring_count);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700719
Bruce Allan508da422011-12-16 00:45:51 +0000720 /* Allocate temporary storage for ring updates */
721 if (set_tx) {
722 temp_tx = vmalloc(size);
723 if (!temp_tx) {
724 err = -ENOMEM;
725 goto free_temp;
726 }
727 }
728 if (set_rx) {
729 temp_rx = vmalloc(size);
730 if (!temp_rx) {
731 err = -ENOMEM;
732 goto free_temp;
733 }
734 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700735
Bruce Allan3ef672a2013-06-27 02:44:44 +0000736 pm_runtime_get_sync(netdev->dev.parent);
737
David Ertman28002092014-02-14 07:16:41 +0000738 e1000e_down(adapter, true);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700739
Bruce Allane921eb12012-11-28 09:28:37 +0000740 /* We can't just free everything and then setup again, because the
Bruce Allan508da422011-12-16 00:45:51 +0000741 * ISRs in MSI-X mode get passed pointers to the Tx and Rx ring
742 * structs. First, attempt to allocate new resources...
743 */
744 if (set_tx) {
745 memcpy(temp_tx, adapter->tx_ring, size);
746 temp_tx->count = new_tx_count;
747 err = e1000e_setup_tx_resources(temp_tx);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700748 if (err)
749 goto err_setup;
750 }
Bruce Allan508da422011-12-16 00:45:51 +0000751 if (set_rx) {
752 memcpy(temp_rx, adapter->rx_ring, size);
753 temp_rx->count = new_rx_count;
754 err = e1000e_setup_rx_resources(temp_rx);
755 if (err)
756 goto err_setup_rx;
757 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700758
Bruce Allan508da422011-12-16 00:45:51 +0000759 /* ...then free the old resources and copy back any new ring data */
760 if (set_tx) {
761 e1000e_free_tx_resources(adapter->tx_ring);
762 memcpy(adapter->tx_ring, temp_tx, size);
763 adapter->tx_ring_count = new_tx_count;
764 }
765 if (set_rx) {
766 e1000e_free_rx_resources(adapter->rx_ring);
767 memcpy(adapter->rx_ring, temp_rx, size);
768 adapter->rx_ring_count = new_rx_count;
769 }
770
Auke Kokbc7f75f2007-09-17 12:30:59 -0700771err_setup_rx:
Bruce Allan508da422011-12-16 00:45:51 +0000772 if (err && set_tx)
773 e1000e_free_tx_resources(temp_tx);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700774err_setup:
Bruce Allan508da422011-12-16 00:45:51 +0000775 e1000e_up(adapter);
Bruce Allan3ef672a2013-06-27 02:44:44 +0000776 pm_runtime_put_sync(netdev->dev.parent);
Bruce Allan508da422011-12-16 00:45:51 +0000777free_temp:
778 vfree(temp_tx);
779 vfree(temp_rx);
780clear_reset:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700781 clear_bit(__E1000_RESETTING, &adapter->state);
782 return err;
783}
784
Bruce Allancef8c792008-04-02 13:48:23 -0700785static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
786 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800787{
Bruce Allancef8c792008-04-02 13:48:23 -0700788 u32 pat, val;
Bruce Allan64806412010-12-11 05:53:42 +0000789 static const u32 test[] = {
Bruce Allan04e115c2013-02-20 04:06:22 +0000790 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF
791 };
Bruce Allancef8c792008-04-02 13:48:23 -0700792 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800793 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700794 (test[pat] & write));
795 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
796 if (val != (test[pat] & write & mask)) {
Bruce Allana8fc1892012-12-05 06:25:36 +0000797 e_err("pattern test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
798 reg + (offset << 2), val,
799 (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800800 *data = reg;
David Ertman3992c8e2014-04-05 03:36:15 +0000801 return true;
Joe Perches2a887192007-11-13 20:53:51 -0800802 }
803 }
David Ertman3992c8e2014-04-05 03:36:15 +0000804 return false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700805}
806
Joe Perches2a887192007-11-13 20:53:51 -0800807static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
808 int reg, u32 mask, u32 write)
809{
Bruce Allancef8c792008-04-02 13:48:23 -0700810 u32 val;
David Ertman6cf08d12014-04-05 06:07:00 +0000811
Joe Perches2a887192007-11-13 20:53:51 -0800812 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700813 val = __er32(&adapter->hw, reg);
814 if ((write & mask) != (val & mask)) {
Bruce Allana8fc1892012-12-05 06:25:36 +0000815 e_err("set/check test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
Bruce Allan6ad65142012-04-12 05:47:09 +0000816 reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800817 *data = reg;
David Ertman3992c8e2014-04-05 03:36:15 +0000818 return true;
Joe Perches2a887192007-11-13 20:53:51 -0800819 }
David Ertman3992c8e2014-04-05 03:36:15 +0000820 return false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700821}
Bruce Allanfc830b72013-02-20 04:06:11 +0000822
Bruce Allancef8c792008-04-02 13:48:23 -0700823#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
824 do { \
825 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
826 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800827 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700828#define REG_PATTERN_TEST(reg, mask, write) \
829 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800830
Bruce Allancef8c792008-04-02 13:48:23 -0700831#define REG_SET_AND_CHECK(reg, mask, write) \
832 do { \
833 if (reg_set_and_check(adapter, data, reg, mask, write)) \
834 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800835 } while (0)
836
Auke Kokbc7f75f2007-09-17 12:30:59 -0700837static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
838{
839 struct e1000_hw *hw = &adapter->hw;
840 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700841 u32 value;
842 u32 before;
843 u32 after;
844 u32 i;
845 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000846 u32 mask;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000847 u32 wlock_mac = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700848
Bruce Allane921eb12012-11-28 09:28:37 +0000849 /* The status register is Read Only, so a write should fail.
Bruce Allan33550ce2013-02-20 04:06:16 +0000850 * Some bits that get toggled are ignored. There are several bits
851 * on newer hardware that are r/w.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700852 */
853 switch (mac->type) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700854 case e1000_82571:
855 case e1000_82572:
856 case e1000_80003es2lan:
857 toggle = 0x7FFFF3FF;
858 break;
Bruce Allanf0ff4392013-02-20 04:05:39 +0000859 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700860 toggle = 0x7FFFF033;
861 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700862 }
863
864 before = er32(STATUS);
865 value = (er32(STATUS) & toggle);
866 ew32(STATUS, toggle);
867 after = er32(STATUS) & toggle;
868 if (value != after) {
Bruce Allan6ad65142012-04-12 05:47:09 +0000869 e_err("failed STATUS register test got: 0x%08X expected: 0x%08X\n",
870 after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700871 *data = 1;
872 return 1;
873 }
874 /* restore previous status */
875 ew32(STATUS, before);
876
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700877 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700878 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
879 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
880 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
881 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
882 }
883
884 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000885 REG_PATTERN_TEST(E1000_RDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
886 REG_PATTERN_TEST(E1000_RDLEN(0), 0x000FFF80, 0x000FFFFF);
887 REG_PATTERN_TEST(E1000_RDH(0), 0x0000FFFF, 0x0000FFFF);
888 REG_PATTERN_TEST(E1000_RDT(0), 0x0000FFFF, 0x0000FFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700889 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
890 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
891 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000892 REG_PATTERN_TEST(E1000_TDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
893 REG_PATTERN_TEST(E1000_TDLEN(0), 0x000FFF80, 0x000FFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700894
895 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
896
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700897 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700898 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
899 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
900
Auke Kok86582512007-10-04 15:00:08 -0700901 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000902 REG_PATTERN_TEST(E1000_RDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700903 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700904 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
Bruce Allan1e360522012-03-20 03:48:13 +0000905 REG_PATTERN_TEST(E1000_TDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
Auke Kok86582512007-10-04 15:00:08 -0700906 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000907 mask = 0x8003FFFF;
908 switch (mac->type) {
909 case e1000_ich10lan:
910 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000911 case e1000_pch2lan:
Bruce Allan2fbe4522012-04-19 03:21:47 +0000912 case e1000_pch_lpt:
David Ertman79849eb2015-02-10 09:10:43 +0000913 case e1000_pch_spt:
Sasha Neftinc8744f42017-04-06 10:26:47 +0300914 /* fall through */
915 case e1000_pch_cnp:
Jacob Keller18dd2392016-04-13 16:08:32 -0700916 mask |= BIT(18);
Bruce Allana4f58f52009-06-02 11:29:18 +0000917 break;
918 default:
919 break;
920 }
Bruce Allan2fbe4522012-04-19 03:21:47 +0000921
Sasha Neftinc8744f42017-04-06 10:26:47 +0300922 if (mac->type >= e1000_pch_lpt)
Bruce Allan2fbe4522012-04-19 03:21:47 +0000923 wlock_mac = (er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK) >>
924 E1000_FWSM_WLOCK_MAC_SHIFT;
925
926 for (i = 0; i < mac->rar_entry_count; i++) {
Sasha Neftinc8744f42017-04-06 10:26:47 +0300927 if (mac->type >= e1000_pch_lpt) {
Bruce Allana8fc1892012-12-05 06:25:36 +0000928 /* Cannot test write-protected SHRAL[n] registers */
929 if ((wlock_mac == 1) || (wlock_mac && (i > wlock_mac)))
930 continue;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000931
Bruce Allana8fc1892012-12-05 06:25:36 +0000932 /* SHRAH[9] different than the others */
933 if (i == 10)
Jacob Keller18dd2392016-04-13 16:08:32 -0700934 mask |= BIT(30);
Bruce Allana8fc1892012-12-05 06:25:36 +0000935 else
Jacob Keller18dd2392016-04-13 16:08:32 -0700936 mask &= ~BIT(30);
Bruce Allana8fc1892012-12-05 06:25:36 +0000937 }
David Ertmanc3a0dce2013-09-05 04:24:25 +0000938 if (mac->type == e1000_pch2lan) {
939 /* SHRAH[0,1,2] different than previous */
David Ertmanad400642014-03-05 07:54:19 +0000940 if (i == 1)
David Ertmanc3a0dce2013-09-05 04:24:25 +0000941 mask &= 0xFFF4FFFF;
942 /* SHRAH[3] different than SHRAH[0,1,2] */
David Ertmanad400642014-03-05 07:54:19 +0000943 if (i == 4)
Jacob Keller18dd2392016-04-13 16:08:32 -0700944 mask |= BIT(30);
David Ertmanad400642014-03-05 07:54:19 +0000945 /* RAR[1-6] owned by management engine - skipping */
946 if (i > 0)
947 i += 6;
David Ertmanc3a0dce2013-09-05 04:24:25 +0000948 }
Bruce Allana8fc1892012-12-05 06:25:36 +0000949
950 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1), mask,
951 0xFFFFFFFF);
David Ertmanad400642014-03-05 07:54:19 +0000952 /* reset index to actual value */
953 if ((mac->type == e1000_pch2lan) && (i > 6))
954 i -= 6;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000955 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700956
957 for (i = 0; i < mac->mta_reg_count; i++)
958 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
959
960 *data = 0;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000961
Auke Kokbc7f75f2007-09-17 12:30:59 -0700962 return 0;
963}
964
965static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
966{
967 u16 temp;
968 u16 checksum = 0;
969 u16 i;
970
971 *data = 0;
972 /* Read and add up the contents of the EEPROM */
973 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
974 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
975 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800976 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700977 }
978 checksum += temp;
979 }
980
981 /* If Checksum is not Correct return error else test passed */
Bruce Allan53aa82d2013-02-20 04:06:06 +0000982 if ((checksum != (u16)NVM_SUM) && !(*data))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700983 *data = 2;
984
985 return *data;
986}
987
Bruce Allan8bb62862013-01-16 08:46:49 +0000988static irqreturn_t e1000_test_intr(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700989{
Bruce Allan53aa82d2013-02-20 04:06:06 +0000990 struct net_device *netdev = (struct net_device *)data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700991 struct e1000_adapter *adapter = netdev_priv(netdev);
992 struct e1000_hw *hw = &adapter->hw;
993
994 adapter->test_icr |= er32(ICR);
995
996 return IRQ_HANDLED;
997}
998
999static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
1000{
1001 struct net_device *netdev = adapter->netdev;
1002 struct e1000_hw *hw = &adapter->hw;
1003 u32 mask;
1004 u32 shared_int = 1;
1005 u32 irq = adapter->pdev->irq;
1006 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001007 int ret_val = 0;
1008 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001009
1010 *data = 0;
1011
Bruce Allan4662e822008-08-26 18:37:06 -07001012 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
1013 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
1014 int_mode = adapter->int_mode;
1015 e1000e_reset_interrupt_capability(adapter);
1016 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1017 e1000e_set_interrupt_capability(adapter);
1018 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001019 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -08001020 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001021 netdev)) {
1022 shared_int = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00001023 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED, netdev->name,
1024 netdev)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001025 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001026 ret_val = -1;
1027 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001028 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001029 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001030
1031 /* Disable all the interrupts */
1032 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001033 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001034 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001035
1036 /* Test each interrupt */
1037 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001038 /* Interrupt to test */
Jacob Keller18dd2392016-04-13 16:08:32 -07001039 mask = BIT(i);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001040
Bruce Allanf4187b52008-08-26 18:36:50 -07001041 if (adapter->flags & FLAG_IS_ICH) {
1042 switch (mask) {
1043 case E1000_ICR_RXSEQ:
1044 continue;
1045 case 0x00000100:
1046 if (adapter->hw.mac.type == e1000_ich8lan ||
1047 adapter->hw.mac.type == e1000_ich9lan)
1048 continue;
1049 break;
1050 default:
1051 break;
1052 }
1053 }
1054
Auke Kokbc7f75f2007-09-17 12:30:59 -07001055 if (!shared_int) {
Bruce Allane921eb12012-11-28 09:28:37 +00001056 /* Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001057 * the cause register and then force the same
1058 * interrupt and see if one gets posted. If
1059 * an interrupt was posted to the bus, the
1060 * test failed.
1061 */
1062 adapter->test_icr = 0;
1063 ew32(IMC, mask);
1064 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001065 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001066 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001067
1068 if (adapter->test_icr & mask) {
1069 *data = 3;
1070 break;
1071 }
1072 }
1073
Bruce Allane921eb12012-11-28 09:28:37 +00001074 /* Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001075 * the cause register and then force the same
1076 * interrupt and see if one gets posted. If
1077 * an interrupt was not posted to the bus, the
1078 * test failed.
1079 */
1080 adapter->test_icr = 0;
1081 ew32(IMS, mask);
1082 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001083 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001084 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001085
1086 if (!(adapter->test_icr & mask)) {
1087 *data = 4;
1088 break;
1089 }
1090
1091 if (!shared_int) {
Bruce Allane921eb12012-11-28 09:28:37 +00001092 /* Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001093 * the cause register and then force the other
1094 * interrupts and see if any get posted. If
1095 * an interrupt was posted to the bus, the
1096 * test failed.
1097 */
1098 adapter->test_icr = 0;
1099 ew32(IMC, ~mask & 0x00007FFF);
1100 ew32(ICS, ~mask & 0x00007FFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001101 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001102 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001103
1104 if (adapter->test_icr) {
1105 *data = 5;
1106 break;
1107 }
1108 }
1109 }
1110
1111 /* Disable all the interrupts */
1112 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001113 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001114 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001115
1116 /* Unhook test interrupt handler */
1117 free_irq(irq, netdev);
1118
Bruce Allan4662e822008-08-26 18:37:06 -07001119out:
1120 if (int_mode == E1000E_INT_MODE_MSIX) {
1121 e1000e_reset_interrupt_capability(adapter);
1122 adapter->int_mode = int_mode;
1123 e1000e_set_interrupt_capability(adapter);
1124 }
1125
1126 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001127}
1128
1129static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1130{
1131 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1132 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1133 struct pci_dev *pdev = adapter->pdev;
Bruce Allan17e813e2013-02-20 04:06:01 +00001134 struct e1000_buffer *buffer_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001135 int i;
1136
1137 if (tx_ring->desc && tx_ring->buffer_info) {
1138 for (i = 0; i < tx_ring->count; i++) {
Bruce Allan17e813e2013-02-20 04:06:01 +00001139 buffer_info = &tx_ring->buffer_info[i];
1140
1141 if (buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001142 dma_unmap_single(&pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00001143 buffer_info->dma,
1144 buffer_info->length,
1145 DMA_TO_DEVICE);
1146 if (buffer_info->skb)
1147 dev_kfree_skb(buffer_info->skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001148 }
1149 }
1150
1151 if (rx_ring->desc && rx_ring->buffer_info) {
1152 for (i = 0; i < rx_ring->count; i++) {
Bruce Allan17e813e2013-02-20 04:06:01 +00001153 buffer_info = &rx_ring->buffer_info[i];
1154
1155 if (buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001156 dma_unmap_single(&pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00001157 buffer_info->dma,
1158 2048, DMA_FROM_DEVICE);
1159 if (buffer_info->skb)
1160 dev_kfree_skb(buffer_info->skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001161 }
1162 }
1163
1164 if (tx_ring->desc) {
1165 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1166 tx_ring->dma);
1167 tx_ring->desc = NULL;
1168 }
1169 if (rx_ring->desc) {
1170 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1171 rx_ring->dma);
1172 rx_ring->desc = NULL;
1173 }
1174
1175 kfree(tx_ring->buffer_info);
1176 tx_ring->buffer_info = NULL;
1177 kfree(rx_ring->buffer_info);
1178 rx_ring->buffer_info = NULL;
1179}
1180
1181static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1182{
1183 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1184 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1185 struct pci_dev *pdev = adapter->pdev;
1186 struct e1000_hw *hw = &adapter->hw;
1187 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001188 int i;
1189 int ret_val;
1190
1191 /* Setup Tx descriptor ring and Tx buffers */
1192
1193 if (!tx_ring->count)
1194 tx_ring->count = E1000_DEFAULT_TXD;
1195
Bruce Allancef8c792008-04-02 13:48:23 -07001196 tx_ring->buffer_info = kcalloc(tx_ring->count,
Bruce Allane5fe2542013-02-20 04:06:27 +00001197 sizeof(struct e1000_buffer), GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001198 if (!tx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001199 ret_val = 1;
1200 goto err_nomem;
1201 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001202
1203 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1204 tx_ring->size = ALIGN(tx_ring->size, 4096);
1205 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1206 &tx_ring->dma, GFP_KERNEL);
1207 if (!tx_ring->desc) {
1208 ret_val = 2;
1209 goto err_nomem;
1210 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001211 tx_ring->next_to_use = 0;
1212 tx_ring->next_to_clean = 0;
1213
Bruce Allan53aa82d2013-02-20 04:06:06 +00001214 ew32(TDBAL(0), ((u64)tx_ring->dma & 0x00000000FFFFFFFF));
1215 ew32(TDBAH(0), ((u64)tx_ring->dma >> 32));
Bruce Allan1e360522012-03-20 03:48:13 +00001216 ew32(TDLEN(0), tx_ring->count * sizeof(struct e1000_tx_desc));
1217 ew32(TDH(0), 0);
1218 ew32(TDT(0), 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001219 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1220 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1221 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001222
1223 for (i = 0; i < tx_ring->count; i++) {
1224 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1225 struct sk_buff *skb;
1226 unsigned int skb_size = 1024;
1227
1228 skb = alloc_skb(skb_size, GFP_KERNEL);
1229 if (!skb) {
1230 ret_val = 3;
1231 goto err_nomem;
1232 }
1233 skb_put(skb, skb_size);
1234 tx_ring->buffer_info[i].skb = skb;
1235 tx_ring->buffer_info[i].length = skb->len;
1236 tx_ring->buffer_info[i].dma =
Bruce Allanf0ff4392013-02-20 04:05:39 +00001237 dma_map_single(&pdev->dev, skb->data, skb->len,
1238 DMA_TO_DEVICE);
Nick Nunley0be3f552010-04-27 13:09:05 +00001239 if (dma_mapping_error(&pdev->dev,
1240 tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001241 ret_val = 4;
1242 goto err_nomem;
1243 }
Bruce Allancef8c792008-04-02 13:48:23 -07001244 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001245 tx_desc->lower.data = cpu_to_le32(skb->len);
1246 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1247 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001248 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001249 tx_desc->upper.data = 0;
1250 }
1251
1252 /* Setup Rx descriptor ring and Rx buffers */
1253
1254 if (!rx_ring->count)
1255 rx_ring->count = E1000_DEFAULT_RXD;
1256
Bruce Allancef8c792008-04-02 13:48:23 -07001257 rx_ring->buffer_info = kcalloc(rx_ring->count,
Bruce Allane5fe2542013-02-20 04:06:27 +00001258 sizeof(struct e1000_buffer), GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001259 if (!rx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001260 ret_val = 5;
1261 goto err_nomem;
1262 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001263
Bruce Allan5f450212011-07-22 06:21:46 +00001264 rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001265 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1266 &rx_ring->dma, GFP_KERNEL);
1267 if (!rx_ring->desc) {
1268 ret_val = 6;
1269 goto err_nomem;
1270 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001271 rx_ring->next_to_use = 0;
1272 rx_ring->next_to_clean = 0;
1273
1274 rctl = er32(RCTL);
Bruce Allan7f99ae62011-07-22 06:21:35 +00001275 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
1276 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan53aa82d2013-02-20 04:06:06 +00001277 ew32(RDBAL(0), ((u64)rx_ring->dma & 0xFFFFFFFF));
1278 ew32(RDBAH(0), ((u64)rx_ring->dma >> 32));
Bruce Allan1e360522012-03-20 03:48:13 +00001279 ew32(RDLEN(0), rx_ring->size);
1280 ew32(RDH(0), 0);
1281 ew32(RDT(0), 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001282 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allanf0ff4392013-02-20 04:05:39 +00001283 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1284 E1000_RCTL_SBP | E1000_RCTL_SECRC |
1285 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1286 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001287 ew32(RCTL, rctl);
1288
1289 for (i = 0; i < rx_ring->count; i++) {
Bruce Allan5f450212011-07-22 06:21:46 +00001290 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001291 struct sk_buff *skb;
1292
1293 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1294 if (!skb) {
1295 ret_val = 7;
1296 goto err_nomem;
1297 }
1298 skb_reserve(skb, NET_IP_ALIGN);
1299 rx_ring->buffer_info[i].skb = skb;
1300 rx_ring->buffer_info[i].dma =
Bruce Allanf0ff4392013-02-20 04:05:39 +00001301 dma_map_single(&pdev->dev, skb->data, 2048,
1302 DMA_FROM_DEVICE);
Nick Nunley0be3f552010-04-27 13:09:05 +00001303 if (dma_mapping_error(&pdev->dev,
1304 rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001305 ret_val = 8;
1306 goto err_nomem;
1307 }
Bruce Allan5f450212011-07-22 06:21:46 +00001308 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1309 rx_desc->read.buffer_addr =
1310 cpu_to_le64(rx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001311 memset(skb->data, 0x00, skb->len);
1312 }
1313
1314 return 0;
1315
1316err_nomem:
1317 e1000_free_desc_rings(adapter);
1318 return ret_val;
1319}
1320
1321static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1322{
1323 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1324 e1e_wphy(&adapter->hw, 29, 0x001F);
1325 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1326 e1e_wphy(&adapter->hw, 29, 0x001A);
1327 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1328}
1329
1330static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1331{
1332 struct e1000_hw *hw = &adapter->hw;
1333 u32 ctrl_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001334 u16 phy_reg = 0;
Bruce Allancbd006c2010-11-24 06:01:30 +00001335 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001336
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001337 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001338
Bruce Allan3af50482010-06-16 13:25:55 +00001339 if (hw->phy.type == e1000_phy_ife) {
1340 /* force 100, set loopback */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001341 e1e_wphy(hw, MII_BMCR, 0x6100);
Bruce Allanbb436b22009-11-20 23:24:11 +00001342
Bruce Allan3af50482010-06-16 13:25:55 +00001343 /* Now set up the MAC to the same speed/duplex as the PHY. */
1344 ctrl_reg = er32(CTRL);
1345 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1346 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1347 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1348 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1349 E1000_CTRL_FD); /* Force Duplex to FULL */
1350
1351 ew32(CTRL, ctrl_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001352 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00001353 usleep_range(500, 1000);
Bruce Allan3af50482010-06-16 13:25:55 +00001354
1355 return 0;
1356 }
1357
1358 /* Specific PHY configuration for loopback */
1359 switch (hw->phy.type) {
1360 case e1000_phy_m88:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001361 /* Auto-MDI/MDIX Off */
1362 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1363 /* reset to update Auto-MDI/MDIX */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001364 e1e_wphy(hw, MII_BMCR, 0x9140);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001365 /* autoneg off */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001366 e1e_wphy(hw, MII_BMCR, 0x8140);
Bruce Allan3af50482010-06-16 13:25:55 +00001367 break;
1368 case e1000_phy_gg82563:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001369 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
Bruce Allancef8c792008-04-02 13:48:23 -07001370 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001371 case e1000_phy_bm:
1372 /* Set Default MAC Interface speed to 1GB */
1373 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1374 phy_reg &= ~0x0007;
1375 phy_reg |= 0x006;
1376 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1377 /* Assert SW reset for above settings to take effect */
Bruce Allan6b598e12013-01-23 06:50:05 +00001378 hw->phy.ops.commit(hw);
Bruce Allance43a212013-02-20 04:06:32 +00001379 usleep_range(1000, 2000);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001380 /* Force Full Duplex */
1381 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1382 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1383 /* Set Link Up (in force link) */
1384 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1385 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1386 /* Force Link */
1387 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1388 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1389 /* Set Early Link Enable */
1390 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1391 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
Bruce Allan3af50482010-06-16 13:25:55 +00001392 break;
1393 case e1000_phy_82577:
1394 case e1000_phy_82578:
1395 /* Workaround: K1 must be disabled for stable 1Gbps operation */
Bruce Allancbd006c2010-11-24 06:01:30 +00001396 ret_val = hw->phy.ops.acquire(hw);
1397 if (ret_val) {
1398 e_err("Cannot setup 1Gbps loopback.\n");
1399 return ret_val;
1400 }
Bruce Allan3af50482010-06-16 13:25:55 +00001401 e1000_configure_k1_ich8lan(hw, false);
Bruce Allancbd006c2010-11-24 06:01:30 +00001402 hw->phy.ops.release(hw);
Bruce Allan3af50482010-06-16 13:25:55 +00001403 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001404 case e1000_phy_82579:
1405 /* Disable PHY energy detect power down */
1406 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
Jacob Keller18dd2392016-04-13 16:08:32 -07001407 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~BIT(3));
Bruce Alland3738bb2010-06-16 13:27:28 +00001408 /* Disable full chip energy detect */
1409 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1410 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1411 /* Enable loopback on the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00001412 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1413 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001414 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001415 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001416 }
1417
Bruce Allan3af50482010-06-16 13:25:55 +00001418 /* force 1000, set loopback */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001419 e1e_wphy(hw, MII_BMCR, 0x4140);
Bruce Allance43a212013-02-20 04:06:32 +00001420 msleep(250);
Bruce Allan3af50482010-06-16 13:25:55 +00001421
1422 /* Now set up the MAC to the same speed/duplex as the PHY. */
1423 ctrl_reg = er32(CTRL);
1424 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1425 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1426 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1427 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1428 E1000_CTRL_FD); /* Force Duplex to FULL */
1429
1430 if (adapter->flags & FLAG_IS_ICH)
1431 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1432
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001433 if (hw->phy.media_type == e1000_media_type_copper &&
1434 hw->phy.type == e1000_phy_m88) {
Bruce Allane80bd1d2013-05-01 01:19:46 +00001435 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001436 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001437 /* Set the ILOS bit on the fiber Nic if half duplex link is
Bruce Allanad680762008-03-28 09:15:03 -07001438 * detected.
1439 */
Bruce Allan90da0662011-01-06 07:02:53 +00001440 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001441 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1442 }
1443
1444 ew32(CTRL, ctrl_reg);
1445
Bruce Allane921eb12012-11-28 09:28:37 +00001446 /* Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001447 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1448 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001449 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001450 e1000_phy_disable_receiver(adapter);
1451
Bruce Allance43a212013-02-20 04:06:32 +00001452 usleep_range(500, 1000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001453
1454 return 0;
1455}
1456
1457static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1458{
1459 struct e1000_hw *hw = &adapter->hw;
1460 u32 ctrl = er32(CTRL);
Bruce Allan70806a72013-01-05 05:08:37 +00001461 int link;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001462
1463 /* special requirements for 82571/82572 fiber adapters */
1464
Bruce Allane921eb12012-11-28 09:28:37 +00001465 /* jump through hoops to make sure link is up because serdes
Bruce Allanad680762008-03-28 09:15:03 -07001466 * link is hardwired up
1467 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001468 ctrl |= E1000_CTRL_SLU;
1469 ew32(CTRL, ctrl);
1470
1471 /* disable autoneg */
1472 ctrl = er32(TXCW);
Jacob Keller18dd2392016-04-13 16:08:32 -07001473 ctrl &= ~BIT(31);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001474 ew32(TXCW, ctrl);
1475
1476 link = (er32(STATUS) & E1000_STATUS_LU);
1477
1478 if (!link) {
1479 /* set invert loss of signal */
1480 ctrl = er32(CTRL);
1481 ctrl |= E1000_CTRL_ILOS;
1482 ew32(CTRL, ctrl);
1483 }
1484
Bruce Allane921eb12012-11-28 09:28:37 +00001485 /* special write to serdes control register to enable SerDes analog
Bruce Allanad680762008-03-28 09:15:03 -07001486 * loopback
1487 */
Bruce Allan3ffcf2c2013-02-20 04:06:43 +00001488 ew32(SCTL, E1000_SCTL_ENABLE_SERDES_LOOPBACK);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001489 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001490 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001491
1492 return 0;
1493}
1494
1495/* only call this for fiber/serdes connections to es2lan */
1496static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1497{
1498 struct e1000_hw *hw = &adapter->hw;
1499 u32 ctrlext = er32(CTRL_EXT);
1500 u32 ctrl = er32(CTRL);
1501
Bruce Allane921eb12012-11-28 09:28:37 +00001502 /* save CTRL_EXT to restore later, reuse an empty variable (unused
Bruce Allanad680762008-03-28 09:15:03 -07001503 * on mac_type 80003es2lan)
1504 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001505 adapter->tx_fifo_head = ctrlext;
1506
1507 /* clear the serdes mode bits, putting the device into mac loopback */
1508 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1509 ew32(CTRL_EXT, ctrlext);
1510
1511 /* force speed to 1000/FD, link up */
1512 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1513 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1514 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1515 ew32(CTRL, ctrl);
1516
1517 /* set mac loopback */
1518 ctrl = er32(RCTL);
1519 ctrl |= E1000_RCTL_LBM_MAC;
1520 ew32(RCTL, ctrl);
1521
1522 /* set testing mode parameters (no need to reset later) */
1523#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1524#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1525 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001526 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001527
1528 return 0;
1529}
1530
1531static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1532{
1533 struct e1000_hw *hw = &adapter->hw;
Yanir Lubetkin2ec7d292015-06-02 17:05:47 +03001534 u32 rctl, fext_nvm11, tarc0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001535
Sasha Neftinc8744f42017-04-06 10:26:47 +03001536 if (hw->mac.type >= e1000_pch_spt) {
Yanir Lubetkin2ec7d292015-06-02 17:05:47 +03001537 fext_nvm11 = er32(FEXTNVM11);
1538 fext_nvm11 |= E1000_FEXTNVM11_DISABLE_MULR_FIX;
1539 ew32(FEXTNVM11, fext_nvm11);
1540 tarc0 = er32(TARC(0));
1541 /* clear bits 28 & 29 (control of MULR concurrent requests) */
1542 tarc0 &= 0xcfffffff;
1543 /* set bit 29 (value of MULR requests is now 2) */
1544 tarc0 |= 0x20000000;
1545 ew32(TARC(0), tarc0);
1546 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001547 if (hw->phy.media_type == e1000_media_type_fiber ||
1548 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001549 switch (hw->mac.type) {
1550 case e1000_80003es2lan:
1551 return e1000_set_es2lan_mac_loopback(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001552 case e1000_82571:
1553 case e1000_82572:
1554 return e1000_set_82571_fiber_loopback(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001555 default:
1556 rctl = er32(RCTL);
1557 rctl |= E1000_RCTL_LBM_TCVR;
1558 ew32(RCTL, rctl);
1559 return 0;
1560 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001561 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001562 return e1000_integrated_phy_loopback(adapter);
1563 }
1564
1565 return 7;
1566}
1567
1568static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1569{
1570 struct e1000_hw *hw = &adapter->hw;
Yanir Lubetkin2ec7d292015-06-02 17:05:47 +03001571 u32 rctl, fext_nvm11, tarc0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001572 u16 phy_reg;
1573
1574 rctl = er32(RCTL);
1575 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1576 ew32(RCTL, rctl);
1577
1578 switch (hw->mac.type) {
Yanir Lubetkin2ec7d292015-06-02 17:05:47 +03001579 case e1000_pch_spt:
Sasha Neftinc8744f42017-04-06 10:26:47 +03001580 case e1000_pch_cnp:
Yanir Lubetkin2ec7d292015-06-02 17:05:47 +03001581 fext_nvm11 = er32(FEXTNVM11);
1582 fext_nvm11 &= ~E1000_FEXTNVM11_DISABLE_MULR_FIX;
1583 ew32(FEXTNVM11, fext_nvm11);
1584 tarc0 = er32(TARC(0));
1585 /* clear bits 28 & 29 (control of MULR concurrent requests) */
1586 /* set bit 29 (value of MULR requests is now 0) */
1587 tarc0 &= 0xcfffffff;
1588 ew32(TARC(0), tarc0);
1589 /* fall through */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001590 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001591 if (hw->phy.media_type == e1000_media_type_fiber ||
1592 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001593 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001594 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001595 adapter->tx_fifo_head = 0;
1596 }
1597 /* fall through */
1598 case e1000_82571:
1599 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001600 if (hw->phy.media_type == e1000_media_type_fiber ||
1601 hw->phy.media_type == e1000_media_type_internal_serdes) {
Bruce Allan3ffcf2c2013-02-20 04:06:43 +00001602 ew32(SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001603 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001604 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001605 break;
1606 }
1607 /* Fall Through */
1608 default:
1609 hw->mac.autoneg = 1;
1610 if (hw->phy.type == e1000_phy_gg82563)
1611 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001612 e1e_rphy(hw, MII_BMCR, &phy_reg);
1613 if (phy_reg & BMCR_LOOPBACK) {
1614 phy_reg &= ~BMCR_LOOPBACK;
1615 e1e_wphy(hw, MII_BMCR, phy_reg);
Bruce Allan6b598e12013-01-23 06:50:05 +00001616 if (hw->phy.ops.commit)
1617 hw->phy.ops.commit(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001618 }
1619 break;
1620 }
1621}
1622
1623static void e1000_create_lbtest_frame(struct sk_buff *skb,
1624 unsigned int frame_size)
1625{
1626 memset(skb->data, 0xFF, frame_size);
1627 frame_size &= ~1;
1628 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1629 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1630 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1631}
1632
1633static int e1000_check_lbtest_frame(struct sk_buff *skb,
1634 unsigned int frame_size)
1635{
1636 frame_size &= ~1;
1637 if (*(skb->data + 3) == 0xFF)
1638 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
Bruce Allan17e813e2013-02-20 04:06:01 +00001639 (*(skb->data + frame_size / 2 + 12) == 0xAF))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001640 return 0;
1641 return 13;
1642}
1643
1644static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1645{
1646 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1647 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1648 struct pci_dev *pdev = adapter->pdev;
1649 struct e1000_hw *hw = &adapter->hw;
Bruce Allan17e813e2013-02-20 04:06:01 +00001650 struct e1000_buffer *buffer_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001651 int i, j, k, l;
1652 int lc;
1653 int good_cnt;
1654 int ret_val = 0;
1655 unsigned long time;
1656
Bruce Allan1e360522012-03-20 03:48:13 +00001657 ew32(RDT(0), rx_ring->count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001658
Bruce Allane921eb12012-11-28 09:28:37 +00001659 /* Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001660 * The idea is to wrap the largest ring a number of times using 64
1661 * send/receive pairs during each loop
1662 */
1663
1664 if (rx_ring->count <= tx_ring->count)
1665 lc = ((tx_ring->count / 64) * 2) + 1;
1666 else
1667 lc = ((rx_ring->count / 64) * 2) + 1;
1668
1669 k = 0;
1670 l = 0;
Bruce Allan33550ce2013-02-20 04:06:16 +00001671 /* loop count loop */
1672 for (j = 0; j <= lc; j++) {
1673 /* send the packets */
1674 for (i = 0; i < 64; i++) {
Bruce Allan17e813e2013-02-20 04:06:01 +00001675 buffer_info = &tx_ring->buffer_info[k];
1676
1677 e1000_create_lbtest_frame(buffer_info->skb, 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001678 dma_sync_single_for_device(&pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00001679 buffer_info->dma,
1680 buffer_info->length,
1681 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001682 k++;
1683 if (k == tx_ring->count)
1684 k = 0;
1685 }
Bruce Allan1e360522012-03-20 03:48:13 +00001686 ew32(TDT(0), k);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001687 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001688 msleep(200);
Bruce Allane80bd1d2013-05-01 01:19:46 +00001689 time = jiffies; /* set the start time for the receive */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001690 good_cnt = 0;
Bruce Allan33550ce2013-02-20 04:06:16 +00001691 /* receive the sent packets */
1692 do {
Bruce Allan17e813e2013-02-20 04:06:01 +00001693 buffer_info = &rx_ring->buffer_info[l];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001694
Bruce Allan17e813e2013-02-20 04:06:01 +00001695 dma_sync_single_for_cpu(&pdev->dev,
1696 buffer_info->dma, 2048,
1697 DMA_FROM_DEVICE);
1698
1699 ret_val = e1000_check_lbtest_frame(buffer_info->skb,
1700 1024);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001701 if (!ret_val)
1702 good_cnt++;
1703 l++;
1704 if (l == rx_ring->count)
1705 l = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00001706 /* time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001707 * enough time to complete the receives, if it's
1708 * exceeded, break and error off
1709 */
1710 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1711 if (good_cnt != 64) {
Bruce Allane80bd1d2013-05-01 01:19:46 +00001712 ret_val = 13; /* ret_val is the same as mis-compare */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001713 break;
1714 }
Bruce Allan22f8aba2013-08-15 03:43:24 +00001715 if (time_after(jiffies, time + 20)) {
Bruce Allane80bd1d2013-05-01 01:19:46 +00001716 ret_val = 14; /* error code for time out error */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001717 break;
1718 }
Bruce Allan33550ce2013-02-20 04:06:16 +00001719 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001720 return ret_val;
1721}
1722
1723static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1724{
Bruce Allan44abd5c2012-02-22 09:02:37 +00001725 struct e1000_hw *hw = &adapter->hw;
1726
Bruce Allane921eb12012-11-28 09:28:37 +00001727 /* PHY loopback cannot be performed if SoL/IDER sessions are active */
Bruce Allan470a5422012-05-26 06:08:48 +00001728 if (hw->phy.ops.check_reset_block &&
1729 hw->phy.ops.check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001730 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001731 *data = 0;
1732 goto out;
1733 }
1734
1735 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001736 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001737 goto out;
1738
1739 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001740 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001741 goto err_loopback;
1742
1743 *data = e1000_run_loopback_test(adapter);
1744 e1000_loopback_cleanup(adapter);
1745
1746err_loopback:
1747 e1000_free_desc_rings(adapter);
1748out:
1749 return *data;
1750}
1751
1752static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1753{
1754 struct e1000_hw *hw = &adapter->hw;
1755
1756 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001757 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001758 int i = 0;
David Ertman6cf08d12014-04-05 06:07:00 +00001759
Alex Chiang612e2442009-02-05 23:55:45 -08001760 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001761
Bruce Allane921eb12012-11-28 09:28:37 +00001762 /* On some blade server designs, link establishment
Bruce Allanad680762008-03-28 09:15:03 -07001763 * could take as long as 2-3 minutes
1764 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001765 do {
1766 hw->mac.ops.check_for_link(hw);
1767 if (hw->mac.serdes_has_link)
1768 return *data;
1769 msleep(20);
1770 } while (i++ < 3750);
1771
1772 *data = 1;
1773 } else {
1774 hw->mac.ops.check_for_link(hw);
1775 if (hw->mac.autoneg)
Bruce Allane921eb12012-11-28 09:28:37 +00001776 /* On some Phy/switch combinations, link establishment
Bruce Allan5661aeb2011-02-25 06:36:25 +00001777 * can take a few seconds more than expected.
1778 */
Bruce Allance43a212013-02-20 04:06:32 +00001779 msleep_interruptible(5000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001780
Bruce Allan5661aeb2011-02-25 06:36:25 +00001781 if (!(er32(STATUS) & E1000_STATUS_LU))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001782 *data = 1;
1783 }
1784 return *data;
1785}
1786
Bruce Allan8bb62862013-01-16 08:46:49 +00001787static int e1000e_get_sset_count(struct net_device __always_unused *netdev,
1788 int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001789{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001790 switch (sset) {
1791 case ETH_SS_TEST:
1792 return E1000_TEST_LEN;
1793 case ETH_SS_STATS:
1794 return E1000_STATS_LEN;
1795 default:
1796 return -EOPNOTSUPP;
1797 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001798}
1799
1800static void e1000_diag_test(struct net_device *netdev,
1801 struct ethtool_test *eth_test, u64 *data)
1802{
1803 struct e1000_adapter *adapter = netdev_priv(netdev);
1804 u16 autoneg_advertised;
1805 u8 forced_speed_duplex;
1806 u8 autoneg;
1807 bool if_running = netif_running(netdev);
1808
Bruce Allan3ef672a2013-06-27 02:44:44 +00001809 pm_runtime_get_sync(netdev->dev.parent);
1810
Auke Kokbc7f75f2007-09-17 12:30:59 -07001811 set_bit(__E1000_TESTING, &adapter->state);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001812
1813 if (!if_running) {
1814 /* Get control of and reset hardware */
1815 if (adapter->flags & FLAG_HAS_AMT)
1816 e1000e_get_hw_control(adapter);
1817
1818 e1000e_power_up_phy(adapter);
1819
1820 adapter->hw.phy.autoneg_wait_to_complete = 1;
1821 e1000e_reset(adapter);
1822 adapter->hw.phy.autoneg_wait_to_complete = 0;
1823 }
1824
Auke Kokbc7f75f2007-09-17 12:30:59 -07001825 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1826 /* Offline tests */
1827
1828 /* save speed, duplex, autoneg settings */
1829 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1830 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1831 autoneg = adapter->hw.mac.autoneg;
1832
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001833 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001834
Auke Kokbc7f75f2007-09-17 12:30:59 -07001835 if (if_running)
1836 /* indicate we're in test mode */
Stefan Assmannd5ea45d2016-02-03 09:20:52 +01001837 e1000e_close(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001838
1839 if (e1000_reg_test(adapter, &data[0]))
1840 eth_test->flags |= ETH_TEST_FL_FAILED;
1841
1842 e1000e_reset(adapter);
1843 if (e1000_eeprom_test(adapter, &data[1]))
1844 eth_test->flags |= ETH_TEST_FL_FAILED;
1845
1846 e1000e_reset(adapter);
1847 if (e1000_intr_test(adapter, &data[2]))
1848 eth_test->flags |= ETH_TEST_FL_FAILED;
1849
1850 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001851 if (e1000_loopback_test(adapter, &data[3]))
1852 eth_test->flags |= ETH_TEST_FL_FAILED;
1853
Auke Kokbc7f75f2007-09-17 12:30:59 -07001854 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001855 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001856 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001857 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001858
Carolyn Wybornyc6ce3852010-10-15 17:35:31 +00001859 if (e1000_link_test(adapter, &data[4]))
1860 eth_test->flags |= ETH_TEST_FL_FAILED;
1861
1862 /* restore speed, duplex, autoneg settings */
1863 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1864 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1865 adapter->hw.mac.autoneg = autoneg;
1866 e1000e_reset(adapter);
1867
Auke Kokbc7f75f2007-09-17 12:30:59 -07001868 clear_bit(__E1000_TESTING, &adapter->state);
1869 if (if_running)
Stefan Assmannd5ea45d2016-02-03 09:20:52 +01001870 e1000e_open(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001871 } else {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001872 /* Online tests */
Bruce Allan11b08be2010-05-10 14:59:31 +00001873
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001874 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001875
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001876 /* register, eeprom, intr and loopback tests not run online */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001877 data[0] = 0;
1878 data[1] = 0;
1879 data[2] = 0;
1880 data[3] = 0;
1881
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001882 if (e1000_link_test(adapter, &data[4]))
1883 eth_test->flags |= ETH_TEST_FL_FAILED;
Bruce Allan11b08be2010-05-10 14:59:31 +00001884
Auke Kokbc7f75f2007-09-17 12:30:59 -07001885 clear_bit(__E1000_TESTING, &adapter->state);
1886 }
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001887
1888 if (!if_running) {
1889 e1000e_reset(adapter);
1890
1891 if (adapter->flags & FLAG_HAS_AMT)
1892 e1000e_release_hw_control(adapter);
1893 }
1894
Auke Kokbc7f75f2007-09-17 12:30:59 -07001895 msleep_interruptible(4 * 1000);
Bruce Allan3ef672a2013-06-27 02:44:44 +00001896
1897 pm_runtime_put_sync(netdev->dev.parent);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001898}
1899
1900static void e1000_get_wol(struct net_device *netdev,
1901 struct ethtool_wolinfo *wol)
1902{
1903 struct e1000_adapter *adapter = netdev_priv(netdev);
1904
1905 wol->supported = 0;
1906 wol->wolopts = 0;
1907
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001908 if (!(adapter->flags & FLAG_HAS_WOL) ||
1909 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001910 return;
1911
1912 wol->supported = WAKE_UCAST | WAKE_MCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001913 WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001914
1915 /* apply any specific unsupported masks here */
1916 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1917 wol->supported &= ~WAKE_UCAST;
1918
1919 if (adapter->wol & E1000_WUFC_EX)
Bruce Allan6ad65142012-04-12 05:47:09 +00001920 e_err("Interface does not support directed (unicast) frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001921 }
1922
1923 if (adapter->wol & E1000_WUFC_EX)
1924 wol->wolopts |= WAKE_UCAST;
1925 if (adapter->wol & E1000_WUFC_MC)
1926 wol->wolopts |= WAKE_MCAST;
1927 if (adapter->wol & E1000_WUFC_BC)
1928 wol->wolopts |= WAKE_BCAST;
1929 if (adapter->wol & E1000_WUFC_MAG)
1930 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001931 if (adapter->wol & E1000_WUFC_LNKC)
1932 wol->wolopts |= WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001933}
1934
Bruce Allan4a29e152011-03-04 09:07:01 +00001935static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001936{
1937 struct e1000_adapter *adapter = netdev_priv(netdev);
1938
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001939 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001940 !device_can_wakeup(&adapter->pdev->dev) ||
1941 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001942 WAKE_MAGIC | WAKE_PHY)))
Bruce Allan1fbfca32009-11-20 23:22:01 +00001943 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001944
1945 /* these settings will always override what we currently have */
1946 adapter->wol = 0;
1947
1948 if (wol->wolopts & WAKE_UCAST)
1949 adapter->wol |= E1000_WUFC_EX;
1950 if (wol->wolopts & WAKE_MCAST)
1951 adapter->wol |= E1000_WUFC_MC;
1952 if (wol->wolopts & WAKE_BCAST)
1953 adapter->wol |= E1000_WUFC_BC;
1954 if (wol->wolopts & WAKE_MAGIC)
1955 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001956 if (wol->wolopts & WAKE_PHY)
1957 adapter->wol |= E1000_WUFC_LNKC;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001958
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001959 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1960
Auke Kokbc7f75f2007-09-17 12:30:59 -07001961 return 0;
1962}
1963
Bruce Allandbf80dc2011-04-16 00:34:40 +00001964static int e1000_set_phys_id(struct net_device *netdev,
1965 enum ethtool_phys_id_state state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001966{
1967 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001968 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001969
Bruce Allandbf80dc2011-04-16 00:34:40 +00001970 switch (state) {
1971 case ETHTOOL_ID_ACTIVE:
Bruce Allan3ef672a2013-06-27 02:44:44 +00001972 pm_runtime_get_sync(netdev->dev.parent);
1973
Bruce Allandbf80dc2011-04-16 00:34:40 +00001974 if (!hw->mac.ops.blink_led)
1975 return 2; /* cycle on/off twice per second */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001976
Bruce Allandbf80dc2011-04-16 00:34:40 +00001977 hw->mac.ops.blink_led(hw);
1978 break;
1979
1980 case ETHTOOL_ID_INACTIVE:
Bruce Allan4662e822008-08-26 18:37:06 -07001981 if (hw->phy.type == e1000_phy_ife)
1982 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001983 hw->mac.ops.led_off(hw);
1984 hw->mac.ops.cleanup_led(hw);
Bruce Allan3ef672a2013-06-27 02:44:44 +00001985 pm_runtime_put_sync(netdev->dev.parent);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001986 break;
1987
1988 case ETHTOOL_ID_ON:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001989 hw->mac.ops.led_on(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001990 break;
1991
1992 case ETHTOOL_ID_OFF:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001993 hw->mac.ops.led_off(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001994 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001995 }
Bruce Allan3ef672a2013-06-27 02:44:44 +00001996
Auke Kokbc7f75f2007-09-17 12:30:59 -07001997 return 0;
1998}
1999
Auke Kokde5b3072008-04-23 11:09:08 -07002000static int e1000_get_coalesce(struct net_device *netdev,
2001 struct ethtool_coalesce *ec)
2002{
2003 struct e1000_adapter *adapter = netdev_priv(netdev);
2004
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00002005 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07002006 ec->rx_coalesce_usecs = adapter->itr_setting;
2007 else
2008 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
2009
2010 return 0;
2011}
2012
2013static int e1000_set_coalesce(struct net_device *netdev,
2014 struct ethtool_coalesce *ec)
2015{
2016 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokde5b3072008-04-23 11:09:08 -07002017
2018 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00002019 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07002020 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
2021 (ec->rx_coalesce_usecs == 2))
2022 return -EINVAL;
2023
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00002024 if (ec->rx_coalesce_usecs == 4) {
Bruce Allan06a402e2012-08-17 06:17:57 +00002025 adapter->itr_setting = 4;
2026 adapter->itr = adapter->itr_setting;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00002027 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07002028 adapter->itr = 20000;
2029 adapter->itr_setting = ec->rx_coalesce_usecs;
2030 } else {
2031 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
2032 adapter->itr_setting = adapter->itr & ~3;
2033 }
2034
Bruce Allan3ef672a2013-06-27 02:44:44 +00002035 pm_runtime_get_sync(netdev->dev.parent);
2036
Auke Kokde5b3072008-04-23 11:09:08 -07002037 if (adapter->itr_setting != 0)
Matthew Vick22a4cca2012-07-12 00:02:42 +00002038 e1000e_write_itr(adapter, adapter->itr);
Auke Kokde5b3072008-04-23 11:09:08 -07002039 else
Matthew Vick22a4cca2012-07-12 00:02:42 +00002040 e1000e_write_itr(adapter, 0);
Auke Kokde5b3072008-04-23 11:09:08 -07002041
Bruce Allan3ef672a2013-06-27 02:44:44 +00002042 pm_runtime_put_sync(netdev->dev.parent);
2043
Auke Kokde5b3072008-04-23 11:09:08 -07002044 return 0;
2045}
2046
Auke Kokbc7f75f2007-09-17 12:30:59 -07002047static int e1000_nway_reset(struct net_device *netdev)
2048{
2049 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan5962bc22011-01-20 06:58:07 +00002050
2051 if (!netif_running(netdev))
2052 return -EAGAIN;
2053
2054 if (!adapter->hw.mac.autoneg)
2055 return -EINVAL;
2056
Bruce Allan3ef672a2013-06-27 02:44:44 +00002057 pm_runtime_get_sync(netdev->dev.parent);
Bruce Allan5962bc22011-01-20 06:58:07 +00002058 e1000e_reinit_locked(adapter);
Bruce Allan3ef672a2013-06-27 02:44:44 +00002059 pm_runtime_put_sync(netdev->dev.parent);
Bruce Allan5962bc22011-01-20 06:58:07 +00002060
Auke Kokbc7f75f2007-09-17 12:30:59 -07002061 return 0;
2062}
2063
Auke Kokbc7f75f2007-09-17 12:30:59 -07002064static void e1000_get_ethtool_stats(struct net_device *netdev,
Bruce Allan8bb62862013-01-16 08:46:49 +00002065 struct ethtool_stats __always_unused *stats,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002066 u64 *data)
2067{
2068 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00002069 struct rtnl_link_stats64 net_stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002070 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00002071 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002072
Bruce Allan3ef672a2013-06-27 02:44:44 +00002073 pm_runtime_get_sync(netdev->dev.parent);
2074
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00002075 e1000e_get_stats64(netdev, &net_stats);
Bruce Allan3ef672a2013-06-27 02:44:44 +00002076
2077 pm_runtime_put_sync(netdev->dev.parent);
2078
Auke Kokbc7f75f2007-09-17 12:30:59 -07002079 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00002080 switch (e1000_gstrings_stats[i].type) {
2081 case NETDEV_STATS:
Bruce Allan53aa82d2013-02-20 04:06:06 +00002082 p = (char *)&net_stats +
Bruce Allanf0ff4392013-02-20 04:05:39 +00002083 e1000_gstrings_stats[i].stat_offset;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00002084 break;
2085 case E1000_STATS:
Bruce Allan53aa82d2013-02-20 04:06:06 +00002086 p = (char *)adapter +
Bruce Allanf0ff4392013-02-20 04:05:39 +00002087 e1000_gstrings_stats[i].stat_offset;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00002088 break;
Bruce Allan61c75812010-12-09 23:04:25 +00002089 default:
2090 data[i] = 0;
2091 continue;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00002092 }
2093
Auke Kokbc7f75f2007-09-17 12:30:59 -07002094 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
Bruce Allanf0ff4392013-02-20 04:05:39 +00002095 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002096 }
2097}
2098
Bruce Allan8bb62862013-01-16 08:46:49 +00002099static void e1000_get_strings(struct net_device __always_unused *netdev,
2100 u32 stringset, u8 *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002101{
2102 u8 *p = data;
2103 int i;
2104
2105 switch (stringset) {
2106 case ETH_SS_TEST:
Bruce Allan5c1bda02011-01-19 04:23:39 +00002107 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002108 break;
2109 case ETH_SS_STATS:
2110 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
2111 memcpy(p, e1000_gstrings_stats[i].stat_string,
2112 ETH_GSTRING_LEN);
2113 p += ETH_GSTRING_LEN;
2114 }
2115 break;
2116 }
2117}
2118
Bruce Allan70495a52012-01-11 01:26:50 +00002119static int e1000_get_rxnfc(struct net_device *netdev,
Bruce Allan8bb62862013-01-16 08:46:49 +00002120 struct ethtool_rxnfc *info,
2121 u32 __always_unused *rule_locs)
Bruce Allan70495a52012-01-11 01:26:50 +00002122{
2123 info->data = 0;
2124
2125 switch (info->cmd) {
2126 case ETHTOOL_GRXFH: {
2127 struct e1000_adapter *adapter = netdev_priv(netdev);
2128 struct e1000_hw *hw = &adapter->hw;
Bruce Allan3ef672a2013-06-27 02:44:44 +00002129 u32 mrqc;
2130
2131 pm_runtime_get_sync(netdev->dev.parent);
2132 mrqc = er32(MRQC);
2133 pm_runtime_put_sync(netdev->dev.parent);
Bruce Allan70495a52012-01-11 01:26:50 +00002134
2135 if (!(mrqc & E1000_MRQC_RSS_FIELD_MASK))
2136 return 0;
2137
2138 switch (info->flow_type) {
2139 case TCP_V4_FLOW:
2140 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP)
2141 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2142 /* fall through */
2143 case UDP_V4_FLOW:
2144 case SCTP_V4_FLOW:
2145 case AH_ESP_V4_FLOW:
2146 case IPV4_FLOW:
2147 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4)
2148 info->data |= RXH_IP_SRC | RXH_IP_DST;
2149 break;
2150 case TCP_V6_FLOW:
2151 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP)
2152 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2153 /* fall through */
2154 case UDP_V6_FLOW:
2155 case SCTP_V6_FLOW:
2156 case AH_ESP_V6_FLOW:
2157 case IPV6_FLOW:
2158 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6)
2159 info->data |= RXH_IP_SRC | RXH_IP_DST;
2160 break;
2161 default:
2162 break;
2163 }
2164 return 0;
2165 }
2166 default:
2167 return -EOPNOTSUPP;
2168 }
2169}
2170
Bruce Allan203e4152012-12-05 08:40:59 +00002171static int e1000e_get_eee(struct net_device *netdev, struct ethtool_eee *edata)
2172{
2173 struct e1000_adapter *adapter = netdev_priv(netdev);
2174 struct e1000_hw *hw = &adapter->hw;
Bruce Alland495bcb2013-03-20 07:23:11 +00002175 u16 cap_addr, lpa_addr, pcs_stat_addr, phy_data;
2176 u32 ret_val;
Bruce Allan203e4152012-12-05 08:40:59 +00002177
Bruce Alland495bcb2013-03-20 07:23:11 +00002178 if (!(adapter->flags2 & FLAG2_HAS_EEE))
Bruce Allan203e4152012-12-05 08:40:59 +00002179 return -EOPNOTSUPP;
2180
2181 switch (hw->phy.type) {
2182 case e1000_phy_82579:
2183 cap_addr = I82579_EEE_CAPABILITY;
Bruce Allan203e4152012-12-05 08:40:59 +00002184 lpa_addr = I82579_EEE_LP_ABILITY;
2185 pcs_stat_addr = I82579_EEE_PCS_STATUS;
2186 break;
2187 case e1000_phy_i217:
2188 cap_addr = I217_EEE_CAPABILITY;
Bruce Allan203e4152012-12-05 08:40:59 +00002189 lpa_addr = I217_EEE_LP_ABILITY;
2190 pcs_stat_addr = I217_EEE_PCS_STATUS;
2191 break;
2192 default:
2193 return -EOPNOTSUPP;
2194 }
2195
Bruce Allan3ef672a2013-06-27 02:44:44 +00002196 pm_runtime_get_sync(netdev->dev.parent);
2197
Bruce Allan203e4152012-12-05 08:40:59 +00002198 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan3ef672a2013-06-27 02:44:44 +00002199 if (ret_val) {
2200 pm_runtime_put_sync(netdev->dev.parent);
Bruce Allan203e4152012-12-05 08:40:59 +00002201 return -EBUSY;
Bruce Allan3ef672a2013-06-27 02:44:44 +00002202 }
Bruce Allan203e4152012-12-05 08:40:59 +00002203
2204 /* EEE Capability */
2205 ret_val = e1000_read_emi_reg_locked(hw, cap_addr, &phy_data);
2206 if (ret_val)
2207 goto release;
2208 edata->supported = mmd_eee_cap_to_ethtool_sup_t(phy_data);
2209
2210 /* EEE Advertised */
Bruce Alland495bcb2013-03-20 07:23:11 +00002211 edata->advertised = mmd_eee_adv_to_ethtool_adv_t(adapter->eee_advert);
Bruce Allan203e4152012-12-05 08:40:59 +00002212
2213 /* EEE Link Partner Advertised */
2214 ret_val = e1000_read_emi_reg_locked(hw, lpa_addr, &phy_data);
2215 if (ret_val)
2216 goto release;
2217 edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
2218
2219 /* EEE PCS Status */
2220 ret_val = e1000_read_emi_reg_locked(hw, pcs_stat_addr, &phy_data);
Bruce Allan3ef672a2013-06-27 02:44:44 +00002221 if (ret_val)
2222 goto release;
Bruce Allan203e4152012-12-05 08:40:59 +00002223 if (hw->phy.type == e1000_phy_82579)
2224 phy_data <<= 8;
2225
Bruce Allan203e4152012-12-05 08:40:59 +00002226 /* Result of the EEE auto negotiation - there is no register that
2227 * has the status of the EEE negotiation so do a best-guess based
Bruce Alland495bcb2013-03-20 07:23:11 +00002228 * on whether Tx or Rx LPI indications have been received.
Bruce Allan203e4152012-12-05 08:40:59 +00002229 */
Bruce Alland495bcb2013-03-20 07:23:11 +00002230 if (phy_data & (E1000_EEE_TX_LPI_RCVD | E1000_EEE_RX_LPI_RCVD))
Bruce Allan203e4152012-12-05 08:40:59 +00002231 edata->eee_active = true;
2232
2233 edata->eee_enabled = !hw->dev_spec.ich8lan.eee_disable;
2234 edata->tx_lpi_enabled = true;
2235 edata->tx_lpi_timer = er32(LPIC) >> E1000_LPIC_LPIET_SHIFT;
2236
Bruce Allan3ef672a2013-06-27 02:44:44 +00002237release:
2238 hw->phy.ops.release(hw);
2239 if (ret_val)
2240 ret_val = -ENODATA;
2241
2242 pm_runtime_put_sync(netdev->dev.parent);
2243
2244 return ret_val;
Bruce Allan203e4152012-12-05 08:40:59 +00002245}
2246
2247static int e1000e_set_eee(struct net_device *netdev, struct ethtool_eee *edata)
2248{
2249 struct e1000_adapter *adapter = netdev_priv(netdev);
2250 struct e1000_hw *hw = &adapter->hw;
2251 struct ethtool_eee eee_curr;
2252 s32 ret_val;
2253
Bruce Allan203e4152012-12-05 08:40:59 +00002254 ret_val = e1000e_get_eee(netdev, &eee_curr);
2255 if (ret_val)
2256 return ret_val;
2257
Bruce Allan203e4152012-12-05 08:40:59 +00002258 if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
2259 e_err("Setting EEE tx-lpi is not supported\n");
2260 return -EINVAL;
2261 }
2262
2263 if (eee_curr.tx_lpi_timer != edata->tx_lpi_timer) {
2264 e_err("Setting EEE Tx LPI timer is not supported\n");
2265 return -EINVAL;
2266 }
2267
Bruce Alland495bcb2013-03-20 07:23:11 +00002268 if (edata->advertised & ~(ADVERTISE_100_FULL | ADVERTISE_1000_FULL)) {
2269 e_err("EEE advertisement supports only 100TX and/or 1000T full-duplex\n");
2270 return -EINVAL;
Bruce Allan203e4152012-12-05 08:40:59 +00002271 }
2272
Bruce Alland495bcb2013-03-20 07:23:11 +00002273 adapter->eee_advert = ethtool_adv_to_mmd_eee_adv_t(edata->advertised);
2274
2275 hw->dev_spec.ich8lan.eee_disable = !edata->eee_enabled;
2276
Bruce Allan3ef672a2013-06-27 02:44:44 +00002277 pm_runtime_get_sync(netdev->dev.parent);
2278
Bruce Alland495bcb2013-03-20 07:23:11 +00002279 /* reset the link */
2280 if (netif_running(netdev))
2281 e1000e_reinit_locked(adapter);
2282 else
2283 e1000e_reset(adapter);
2284
Bruce Allan3ef672a2013-06-27 02:44:44 +00002285 pm_runtime_put_sync(netdev->dev.parent);
2286
Bruce Allan203e4152012-12-05 08:40:59 +00002287 return 0;
2288}
2289
Bruce Allanb67e1912012-12-27 08:32:33 +00002290static int e1000e_get_ts_info(struct net_device *netdev,
2291 struct ethtool_ts_info *info)
2292{
2293 struct e1000_adapter *adapter = netdev_priv(netdev);
2294
2295 ethtool_op_get_ts_info(netdev, info);
2296
2297 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
2298 return 0;
2299
2300 info->so_timestamping |= (SOF_TIMESTAMPING_TX_HARDWARE |
2301 SOF_TIMESTAMPING_RX_HARDWARE |
2302 SOF_TIMESTAMPING_RAW_HARDWARE);
2303
Jacob Keller18dd2392016-04-13 16:08:32 -07002304 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Bruce Allanb67e1912012-12-27 08:32:33 +00002305
Jacob Keller18dd2392016-04-13 16:08:32 -07002306 info->rx_filters = (BIT(HWTSTAMP_FILTER_NONE) |
2307 BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
2308 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
2309 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
2310 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
2311 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
2312 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
2313 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
2314 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
2315 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
2316 BIT(HWTSTAMP_FILTER_ALL));
Bruce Allanb67e1912012-12-27 08:32:33 +00002317
Bruce Alland89777b2013-01-19 01:09:58 +00002318 if (adapter->ptp_clock)
2319 info->phc_index = ptp_clock_index(adapter->ptp_clock);
2320
Bruce Allanb67e1912012-12-27 08:32:33 +00002321 return 0;
2322}
2323
Auke Kokbc7f75f2007-09-17 12:30:59 -07002324static const struct ethtool_ops e1000_ethtool_ops = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002325 .get_drvinfo = e1000_get_drvinfo,
2326 .get_regs_len = e1000_get_regs_len,
2327 .get_regs = e1000_get_regs,
2328 .get_wol = e1000_get_wol,
2329 .set_wol = e1000_set_wol,
2330 .get_msglevel = e1000_get_msglevel,
2331 .set_msglevel = e1000_set_msglevel,
2332 .nway_reset = e1000_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00002333 .get_link = ethtool_op_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002334 .get_eeprom_len = e1000_get_eeprom_len,
2335 .get_eeprom = e1000_get_eeprom,
2336 .set_eeprom = e1000_set_eeprom,
2337 .get_ringparam = e1000_get_ringparam,
2338 .set_ringparam = e1000_set_ringparam,
2339 .get_pauseparam = e1000_get_pauseparam,
2340 .set_pauseparam = e1000_set_pauseparam,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002341 .self_test = e1000_diag_test,
2342 .get_strings = e1000_get_strings,
Bruce Allandbf80dc2011-04-16 00:34:40 +00002343 .set_phys_id = e1000_set_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002344 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07002345 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07002346 .get_coalesce = e1000_get_coalesce,
2347 .set_coalesce = e1000_set_coalesce,
Bruce Allan70495a52012-01-11 01:26:50 +00002348 .get_rxnfc = e1000_get_rxnfc,
Bruce Allanb67e1912012-12-27 08:32:33 +00002349 .get_ts_info = e1000e_get_ts_info,
Bruce Allan203e4152012-12-05 08:40:59 +00002350 .get_eee = e1000e_get_eee,
2351 .set_eee = e1000e_set_eee,
Philippe Reynesfb052fd2017-01-26 22:19:53 +01002352 .get_link_ksettings = e1000_get_link_ksettings,
2353 .set_link_ksettings = e1000_set_link_ksettings,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002354};
2355
2356void e1000e_set_ethtool_ops(struct net_device *netdev)
2357{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002358 netdev->ethtool_ops = &e1000_ethtool_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002359}