blob: e70b1ebff60df2d0a20a876c04613938b89432cc [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:
Jacob Keller18dd2392016-04-13 16:08:32 -0700914 mask |= BIT(18);
Bruce Allana4f58f52009-06-02 11:29:18 +0000915 break;
916 default:
917 break;
918 }
Bruce Allan2fbe4522012-04-19 03:21:47 +0000919
David Ertman79849eb2015-02-10 09:10:43 +0000920 if ((mac->type == e1000_pch_lpt) || (mac->type == e1000_pch_spt))
Bruce Allan2fbe4522012-04-19 03:21:47 +0000921 wlock_mac = (er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK) >>
922 E1000_FWSM_WLOCK_MAC_SHIFT;
923
924 for (i = 0; i < mac->rar_entry_count; i++) {
David Ertman79849eb2015-02-10 09:10:43 +0000925 if ((mac->type == e1000_pch_lpt) ||
926 (mac->type == e1000_pch_spt)) {
Bruce Allana8fc1892012-12-05 06:25:36 +0000927 /* Cannot test write-protected SHRAL[n] registers */
928 if ((wlock_mac == 1) || (wlock_mac && (i > wlock_mac)))
929 continue;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000930
Bruce Allana8fc1892012-12-05 06:25:36 +0000931 /* SHRAH[9] different than the others */
932 if (i == 10)
Jacob Keller18dd2392016-04-13 16:08:32 -0700933 mask |= BIT(30);
Bruce Allana8fc1892012-12-05 06:25:36 +0000934 else
Jacob Keller18dd2392016-04-13 16:08:32 -0700935 mask &= ~BIT(30);
Bruce Allana8fc1892012-12-05 06:25:36 +0000936 }
David Ertmanc3a0dce2013-09-05 04:24:25 +0000937 if (mac->type == e1000_pch2lan) {
938 /* SHRAH[0,1,2] different than previous */
David Ertmanad400642014-03-05 07:54:19 +0000939 if (i == 1)
David Ertmanc3a0dce2013-09-05 04:24:25 +0000940 mask &= 0xFFF4FFFF;
941 /* SHRAH[3] different than SHRAH[0,1,2] */
David Ertmanad400642014-03-05 07:54:19 +0000942 if (i == 4)
Jacob Keller18dd2392016-04-13 16:08:32 -0700943 mask |= BIT(30);
David Ertmanad400642014-03-05 07:54:19 +0000944 /* RAR[1-6] owned by management engine - skipping */
945 if (i > 0)
946 i += 6;
David Ertmanc3a0dce2013-09-05 04:24:25 +0000947 }
Bruce Allana8fc1892012-12-05 06:25:36 +0000948
949 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1), mask,
950 0xFFFFFFFF);
David Ertmanad400642014-03-05 07:54:19 +0000951 /* reset index to actual value */
952 if ((mac->type == e1000_pch2lan) && (i > 6))
953 i -= 6;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000954 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700955
956 for (i = 0; i < mac->mta_reg_count; i++)
957 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
958
959 *data = 0;
Bruce Allan2fbe4522012-04-19 03:21:47 +0000960
Auke Kokbc7f75f2007-09-17 12:30:59 -0700961 return 0;
962}
963
964static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
965{
966 u16 temp;
967 u16 checksum = 0;
968 u16 i;
969
970 *data = 0;
971 /* Read and add up the contents of the EEPROM */
972 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
973 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
974 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800975 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700976 }
977 checksum += temp;
978 }
979
980 /* If Checksum is not Correct return error else test passed */
Bruce Allan53aa82d2013-02-20 04:06:06 +0000981 if ((checksum != (u16)NVM_SUM) && !(*data))
Auke Kokbc7f75f2007-09-17 12:30:59 -0700982 *data = 2;
983
984 return *data;
985}
986
Bruce Allan8bb62862013-01-16 08:46:49 +0000987static irqreturn_t e1000_test_intr(int __always_unused irq, void *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700988{
Bruce Allan53aa82d2013-02-20 04:06:06 +0000989 struct net_device *netdev = (struct net_device *)data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700990 struct e1000_adapter *adapter = netdev_priv(netdev);
991 struct e1000_hw *hw = &adapter->hw;
992
993 adapter->test_icr |= er32(ICR);
994
995 return IRQ_HANDLED;
996}
997
998static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
999{
1000 struct net_device *netdev = adapter->netdev;
1001 struct e1000_hw *hw = &adapter->hw;
1002 u32 mask;
1003 u32 shared_int = 1;
1004 u32 irq = adapter->pdev->irq;
1005 int i;
Bruce Allan4662e822008-08-26 18:37:06 -07001006 int ret_val = 0;
1007 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001008
1009 *data = 0;
1010
Bruce Allan4662e822008-08-26 18:37:06 -07001011 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
1012 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
1013 int_mode = adapter->int_mode;
1014 e1000e_reset_interrupt_capability(adapter);
1015 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1016 e1000e_set_interrupt_capability(adapter);
1017 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001018 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -08001019 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001020 netdev)) {
1021 shared_int = 0;
Bruce Allan17e813e2013-02-20 04:06:01 +00001022 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED, netdev->name,
1023 netdev)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001024 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -07001025 ret_val = -1;
1026 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001027 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001028 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001029
1030 /* Disable all the interrupts */
1031 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001032 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001033 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001034
1035 /* Test each interrupt */
1036 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001037 /* Interrupt to test */
Jacob Keller18dd2392016-04-13 16:08:32 -07001038 mask = BIT(i);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001039
Bruce Allanf4187b52008-08-26 18:36:50 -07001040 if (adapter->flags & FLAG_IS_ICH) {
1041 switch (mask) {
1042 case E1000_ICR_RXSEQ:
1043 continue;
1044 case 0x00000100:
1045 if (adapter->hw.mac.type == e1000_ich8lan ||
1046 adapter->hw.mac.type == e1000_ich9lan)
1047 continue;
1048 break;
1049 default:
1050 break;
1051 }
1052 }
1053
Auke Kokbc7f75f2007-09-17 12:30:59 -07001054 if (!shared_int) {
Bruce Allane921eb12012-11-28 09:28:37 +00001055 /* Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001056 * the cause register and then force the same
1057 * interrupt and see if one gets posted. If
1058 * an interrupt was posted to the bus, the
1059 * test failed.
1060 */
1061 adapter->test_icr = 0;
1062 ew32(IMC, mask);
1063 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001064 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001065 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001066
1067 if (adapter->test_icr & mask) {
1068 *data = 3;
1069 break;
1070 }
1071 }
1072
Bruce Allane921eb12012-11-28 09:28:37 +00001073 /* Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001074 * the cause register and then force the same
1075 * interrupt and see if one gets posted. If
1076 * an interrupt was not posted to the bus, the
1077 * test failed.
1078 */
1079 adapter->test_icr = 0;
1080 ew32(IMS, mask);
1081 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001082 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001083 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001084
1085 if (!(adapter->test_icr & mask)) {
1086 *data = 4;
1087 break;
1088 }
1089
1090 if (!shared_int) {
Bruce Allane921eb12012-11-28 09:28:37 +00001091 /* Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001092 * the cause register and then force the other
1093 * interrupts and see if any get posted. If
1094 * an interrupt was posted to the bus, the
1095 * test failed.
1096 */
1097 adapter->test_icr = 0;
1098 ew32(IMC, ~mask & 0x00007FFF);
1099 ew32(ICS, ~mask & 0x00007FFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001100 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001101 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001102
1103 if (adapter->test_icr) {
1104 *data = 5;
1105 break;
1106 }
1107 }
1108 }
1109
1110 /* Disable all the interrupts */
1111 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001112 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001113 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001114
1115 /* Unhook test interrupt handler */
1116 free_irq(irq, netdev);
1117
Bruce Allan4662e822008-08-26 18:37:06 -07001118out:
1119 if (int_mode == E1000E_INT_MODE_MSIX) {
1120 e1000e_reset_interrupt_capability(adapter);
1121 adapter->int_mode = int_mode;
1122 e1000e_set_interrupt_capability(adapter);
1123 }
1124
1125 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001126}
1127
1128static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1129{
1130 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1131 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1132 struct pci_dev *pdev = adapter->pdev;
Bruce Allan17e813e2013-02-20 04:06:01 +00001133 struct e1000_buffer *buffer_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001134 int i;
1135
1136 if (tx_ring->desc && tx_ring->buffer_info) {
1137 for (i = 0; i < tx_ring->count; i++) {
Bruce Allan17e813e2013-02-20 04:06:01 +00001138 buffer_info = &tx_ring->buffer_info[i];
1139
1140 if (buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001141 dma_unmap_single(&pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00001142 buffer_info->dma,
1143 buffer_info->length,
1144 DMA_TO_DEVICE);
1145 if (buffer_info->skb)
1146 dev_kfree_skb(buffer_info->skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001147 }
1148 }
1149
1150 if (rx_ring->desc && rx_ring->buffer_info) {
1151 for (i = 0; i < rx_ring->count; i++) {
Bruce Allan17e813e2013-02-20 04:06:01 +00001152 buffer_info = &rx_ring->buffer_info[i];
1153
1154 if (buffer_info->dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001155 dma_unmap_single(&pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00001156 buffer_info->dma,
1157 2048, DMA_FROM_DEVICE);
1158 if (buffer_info->skb)
1159 dev_kfree_skb(buffer_info->skb);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001160 }
1161 }
1162
1163 if (tx_ring->desc) {
1164 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1165 tx_ring->dma);
1166 tx_ring->desc = NULL;
1167 }
1168 if (rx_ring->desc) {
1169 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1170 rx_ring->dma);
1171 rx_ring->desc = NULL;
1172 }
1173
1174 kfree(tx_ring->buffer_info);
1175 tx_ring->buffer_info = NULL;
1176 kfree(rx_ring->buffer_info);
1177 rx_ring->buffer_info = NULL;
1178}
1179
1180static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1181{
1182 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1183 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1184 struct pci_dev *pdev = adapter->pdev;
1185 struct e1000_hw *hw = &adapter->hw;
1186 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001187 int i;
1188 int ret_val;
1189
1190 /* Setup Tx descriptor ring and Tx buffers */
1191
1192 if (!tx_ring->count)
1193 tx_ring->count = E1000_DEFAULT_TXD;
1194
Bruce Allancef8c792008-04-02 13:48:23 -07001195 tx_ring->buffer_info = kcalloc(tx_ring->count,
Bruce Allane5fe2542013-02-20 04:06:27 +00001196 sizeof(struct e1000_buffer), GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001197 if (!tx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001198 ret_val = 1;
1199 goto err_nomem;
1200 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001201
1202 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1203 tx_ring->size = ALIGN(tx_ring->size, 4096);
1204 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1205 &tx_ring->dma, GFP_KERNEL);
1206 if (!tx_ring->desc) {
1207 ret_val = 2;
1208 goto err_nomem;
1209 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001210 tx_ring->next_to_use = 0;
1211 tx_ring->next_to_clean = 0;
1212
Bruce Allan53aa82d2013-02-20 04:06:06 +00001213 ew32(TDBAL(0), ((u64)tx_ring->dma & 0x00000000FFFFFFFF));
1214 ew32(TDBAH(0), ((u64)tx_ring->dma >> 32));
Bruce Allan1e360522012-03-20 03:48:13 +00001215 ew32(TDLEN(0), tx_ring->count * sizeof(struct e1000_tx_desc));
1216 ew32(TDH(0), 0);
1217 ew32(TDT(0), 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001218 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1219 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1220 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001221
1222 for (i = 0; i < tx_ring->count; i++) {
1223 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1224 struct sk_buff *skb;
1225 unsigned int skb_size = 1024;
1226
1227 skb = alloc_skb(skb_size, GFP_KERNEL);
1228 if (!skb) {
1229 ret_val = 3;
1230 goto err_nomem;
1231 }
1232 skb_put(skb, skb_size);
1233 tx_ring->buffer_info[i].skb = skb;
1234 tx_ring->buffer_info[i].length = skb->len;
1235 tx_ring->buffer_info[i].dma =
Bruce Allanf0ff4392013-02-20 04:05:39 +00001236 dma_map_single(&pdev->dev, skb->data, skb->len,
1237 DMA_TO_DEVICE);
Nick Nunley0be3f552010-04-27 13:09:05 +00001238 if (dma_mapping_error(&pdev->dev,
1239 tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001240 ret_val = 4;
1241 goto err_nomem;
1242 }
Bruce Allancef8c792008-04-02 13:48:23 -07001243 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001244 tx_desc->lower.data = cpu_to_le32(skb->len);
1245 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1246 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001247 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001248 tx_desc->upper.data = 0;
1249 }
1250
1251 /* Setup Rx descriptor ring and Rx buffers */
1252
1253 if (!rx_ring->count)
1254 rx_ring->count = E1000_DEFAULT_RXD;
1255
Bruce Allancef8c792008-04-02 13:48:23 -07001256 rx_ring->buffer_info = kcalloc(rx_ring->count,
Bruce Allane5fe2542013-02-20 04:06:27 +00001257 sizeof(struct e1000_buffer), GFP_KERNEL);
Bruce Allan668018d2012-01-31 07:02:56 +00001258 if (!rx_ring->buffer_info) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001259 ret_val = 5;
1260 goto err_nomem;
1261 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001262
Bruce Allan5f450212011-07-22 06:21:46 +00001263 rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001264 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1265 &rx_ring->dma, GFP_KERNEL);
1266 if (!rx_ring->desc) {
1267 ret_val = 6;
1268 goto err_nomem;
1269 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001270 rx_ring->next_to_use = 0;
1271 rx_ring->next_to_clean = 0;
1272
1273 rctl = er32(RCTL);
Bruce Allan7f99ae62011-07-22 06:21:35 +00001274 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
1275 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Bruce Allan53aa82d2013-02-20 04:06:06 +00001276 ew32(RDBAL(0), ((u64)rx_ring->dma & 0xFFFFFFFF));
1277 ew32(RDBAH(0), ((u64)rx_ring->dma >> 32));
Bruce Allan1e360522012-03-20 03:48:13 +00001278 ew32(RDLEN(0), rx_ring->size);
1279 ew32(RDH(0), 0);
1280 ew32(RDT(0), 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001281 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allanf0ff4392013-02-20 04:05:39 +00001282 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1283 E1000_RCTL_SBP | E1000_RCTL_SECRC |
1284 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1285 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001286 ew32(RCTL, rctl);
1287
1288 for (i = 0; i < rx_ring->count; i++) {
Bruce Allan5f450212011-07-22 06:21:46 +00001289 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001290 struct sk_buff *skb;
1291
1292 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1293 if (!skb) {
1294 ret_val = 7;
1295 goto err_nomem;
1296 }
1297 skb_reserve(skb, NET_IP_ALIGN);
1298 rx_ring->buffer_info[i].skb = skb;
1299 rx_ring->buffer_info[i].dma =
Bruce Allanf0ff4392013-02-20 04:05:39 +00001300 dma_map_single(&pdev->dev, skb->data, 2048,
1301 DMA_FROM_DEVICE);
Nick Nunley0be3f552010-04-27 13:09:05 +00001302 if (dma_mapping_error(&pdev->dev,
1303 rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001304 ret_val = 8;
1305 goto err_nomem;
1306 }
Bruce Allan5f450212011-07-22 06:21:46 +00001307 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1308 rx_desc->read.buffer_addr =
1309 cpu_to_le64(rx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001310 memset(skb->data, 0x00, skb->len);
1311 }
1312
1313 return 0;
1314
1315err_nomem:
1316 e1000_free_desc_rings(adapter);
1317 return ret_val;
1318}
1319
1320static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1321{
1322 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1323 e1e_wphy(&adapter->hw, 29, 0x001F);
1324 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1325 e1e_wphy(&adapter->hw, 29, 0x001A);
1326 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1327}
1328
1329static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1330{
1331 struct e1000_hw *hw = &adapter->hw;
1332 u32 ctrl_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001333 u16 phy_reg = 0;
Bruce Allancbd006c2010-11-24 06:01:30 +00001334 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001335
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001336 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001337
Bruce Allan3af50482010-06-16 13:25:55 +00001338 if (hw->phy.type == e1000_phy_ife) {
1339 /* force 100, set loopback */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001340 e1e_wphy(hw, MII_BMCR, 0x6100);
Bruce Allanbb436b22009-11-20 23:24:11 +00001341
Bruce Allan3af50482010-06-16 13:25:55 +00001342 /* Now set up the MAC to the same speed/duplex as the PHY. */
1343 ctrl_reg = er32(CTRL);
1344 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1345 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1346 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1347 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1348 E1000_CTRL_FD); /* Force Duplex to FULL */
1349
1350 ew32(CTRL, ctrl_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001351 e1e_flush();
Bruce Allance43a212013-02-20 04:06:32 +00001352 usleep_range(500, 1000);
Bruce Allan3af50482010-06-16 13:25:55 +00001353
1354 return 0;
1355 }
1356
1357 /* Specific PHY configuration for loopback */
1358 switch (hw->phy.type) {
1359 case e1000_phy_m88:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001360 /* Auto-MDI/MDIX Off */
1361 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1362 /* reset to update Auto-MDI/MDIX */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001363 e1e_wphy(hw, MII_BMCR, 0x9140);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001364 /* autoneg off */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001365 e1e_wphy(hw, MII_BMCR, 0x8140);
Bruce Allan3af50482010-06-16 13:25:55 +00001366 break;
1367 case e1000_phy_gg82563:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001368 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
Bruce Allancef8c792008-04-02 13:48:23 -07001369 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001370 case e1000_phy_bm:
1371 /* Set Default MAC Interface speed to 1GB */
1372 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1373 phy_reg &= ~0x0007;
1374 phy_reg |= 0x006;
1375 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1376 /* Assert SW reset for above settings to take effect */
Bruce Allan6b598e12013-01-23 06:50:05 +00001377 hw->phy.ops.commit(hw);
Bruce Allance43a212013-02-20 04:06:32 +00001378 usleep_range(1000, 2000);
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001379 /* Force Full Duplex */
1380 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1381 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1382 /* Set Link Up (in force link) */
1383 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1384 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1385 /* Force Link */
1386 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1387 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1388 /* Set Early Link Enable */
1389 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1390 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
Bruce Allan3af50482010-06-16 13:25:55 +00001391 break;
1392 case e1000_phy_82577:
1393 case e1000_phy_82578:
1394 /* Workaround: K1 must be disabled for stable 1Gbps operation */
Bruce Allancbd006c2010-11-24 06:01:30 +00001395 ret_val = hw->phy.ops.acquire(hw);
1396 if (ret_val) {
1397 e_err("Cannot setup 1Gbps loopback.\n");
1398 return ret_val;
1399 }
Bruce Allan3af50482010-06-16 13:25:55 +00001400 e1000_configure_k1_ich8lan(hw, false);
Bruce Allancbd006c2010-11-24 06:01:30 +00001401 hw->phy.ops.release(hw);
Bruce Allan3af50482010-06-16 13:25:55 +00001402 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001403 case e1000_phy_82579:
1404 /* Disable PHY energy detect power down */
1405 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
Jacob Keller18dd2392016-04-13 16:08:32 -07001406 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~BIT(3));
Bruce Alland3738bb2010-06-16 13:27:28 +00001407 /* Disable full chip energy detect */
1408 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1409 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1410 /* Enable loopback on the PHY */
Bruce Alland3738bb2010-06-16 13:27:28 +00001411 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1412 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001413 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001414 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001415 }
1416
Bruce Allan3af50482010-06-16 13:25:55 +00001417 /* force 1000, set loopback */
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001418 e1e_wphy(hw, MII_BMCR, 0x4140);
Bruce Allance43a212013-02-20 04:06:32 +00001419 msleep(250);
Bruce Allan3af50482010-06-16 13:25:55 +00001420
1421 /* Now set up the MAC to the same speed/duplex as the PHY. */
1422 ctrl_reg = er32(CTRL);
1423 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1424 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1425 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1426 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1427 E1000_CTRL_FD); /* Force Duplex to FULL */
1428
1429 if (adapter->flags & FLAG_IS_ICH)
1430 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1431
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001432 if (hw->phy.media_type == e1000_media_type_copper &&
1433 hw->phy.type == e1000_phy_m88) {
Bruce Allane80bd1d2013-05-01 01:19:46 +00001434 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001435 } else {
Bruce Allane921eb12012-11-28 09:28:37 +00001436 /* Set the ILOS bit on the fiber Nic if half duplex link is
Bruce Allanad680762008-03-28 09:15:03 -07001437 * detected.
1438 */
Bruce Allan90da0662011-01-06 07:02:53 +00001439 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001440 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1441 }
1442
1443 ew32(CTRL, ctrl_reg);
1444
Bruce Allane921eb12012-11-28 09:28:37 +00001445 /* Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001446 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1447 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001448 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001449 e1000_phy_disable_receiver(adapter);
1450
Bruce Allance43a212013-02-20 04:06:32 +00001451 usleep_range(500, 1000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001452
1453 return 0;
1454}
1455
1456static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1457{
1458 struct e1000_hw *hw = &adapter->hw;
1459 u32 ctrl = er32(CTRL);
Bruce Allan70806a72013-01-05 05:08:37 +00001460 int link;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001461
1462 /* special requirements for 82571/82572 fiber adapters */
1463
Bruce Allane921eb12012-11-28 09:28:37 +00001464 /* jump through hoops to make sure link is up because serdes
Bruce Allanad680762008-03-28 09:15:03 -07001465 * link is hardwired up
1466 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001467 ctrl |= E1000_CTRL_SLU;
1468 ew32(CTRL, ctrl);
1469
1470 /* disable autoneg */
1471 ctrl = er32(TXCW);
Jacob Keller18dd2392016-04-13 16:08:32 -07001472 ctrl &= ~BIT(31);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001473 ew32(TXCW, ctrl);
1474
1475 link = (er32(STATUS) & E1000_STATUS_LU);
1476
1477 if (!link) {
1478 /* set invert loss of signal */
1479 ctrl = er32(CTRL);
1480 ctrl |= E1000_CTRL_ILOS;
1481 ew32(CTRL, ctrl);
1482 }
1483
Bruce Allane921eb12012-11-28 09:28:37 +00001484 /* special write to serdes control register to enable SerDes analog
Bruce Allanad680762008-03-28 09:15:03 -07001485 * loopback
1486 */
Bruce Allan3ffcf2c2013-02-20 04:06:43 +00001487 ew32(SCTL, E1000_SCTL_ENABLE_SERDES_LOOPBACK);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001488 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001489 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001490
1491 return 0;
1492}
1493
1494/* only call this for fiber/serdes connections to es2lan */
1495static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1496{
1497 struct e1000_hw *hw = &adapter->hw;
1498 u32 ctrlext = er32(CTRL_EXT);
1499 u32 ctrl = er32(CTRL);
1500
Bruce Allane921eb12012-11-28 09:28:37 +00001501 /* save CTRL_EXT to restore later, reuse an empty variable (unused
Bruce Allanad680762008-03-28 09:15:03 -07001502 * on mac_type 80003es2lan)
1503 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001504 adapter->tx_fifo_head = ctrlext;
1505
1506 /* clear the serdes mode bits, putting the device into mac loopback */
1507 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1508 ew32(CTRL_EXT, ctrlext);
1509
1510 /* force speed to 1000/FD, link up */
1511 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1512 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1513 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1514 ew32(CTRL, ctrl);
1515
1516 /* set mac loopback */
1517 ctrl = er32(RCTL);
1518 ctrl |= E1000_RCTL_LBM_MAC;
1519 ew32(RCTL, ctrl);
1520
1521 /* set testing mode parameters (no need to reset later) */
1522#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1523#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1524 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001525 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001526
1527 return 0;
1528}
1529
1530static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1531{
1532 struct e1000_hw *hw = &adapter->hw;
Yanir Lubetkin2ec7d292015-06-02 17:05:47 +03001533 u32 rctl, fext_nvm11, tarc0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001534
Yanir Lubetkin2ec7d292015-06-02 17:05:47 +03001535 if (hw->mac.type == e1000_pch_spt) {
1536 fext_nvm11 = er32(FEXTNVM11);
1537 fext_nvm11 |= E1000_FEXTNVM11_DISABLE_MULR_FIX;
1538 ew32(FEXTNVM11, fext_nvm11);
1539 tarc0 = er32(TARC(0));
1540 /* clear bits 28 & 29 (control of MULR concurrent requests) */
1541 tarc0 &= 0xcfffffff;
1542 /* set bit 29 (value of MULR requests is now 2) */
1543 tarc0 |= 0x20000000;
1544 ew32(TARC(0), tarc0);
1545 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001546 if (hw->phy.media_type == e1000_media_type_fiber ||
1547 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001548 switch (hw->mac.type) {
1549 case e1000_80003es2lan:
1550 return e1000_set_es2lan_mac_loopback(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001551 case e1000_82571:
1552 case e1000_82572:
1553 return e1000_set_82571_fiber_loopback(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001554 default:
1555 rctl = er32(RCTL);
1556 rctl |= E1000_RCTL_LBM_TCVR;
1557 ew32(RCTL, rctl);
1558 return 0;
1559 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001560 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001561 return e1000_integrated_phy_loopback(adapter);
1562 }
1563
1564 return 7;
1565}
1566
1567static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1568{
1569 struct e1000_hw *hw = &adapter->hw;
Yanir Lubetkin2ec7d292015-06-02 17:05:47 +03001570 u32 rctl, fext_nvm11, tarc0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001571 u16 phy_reg;
1572
1573 rctl = er32(RCTL);
1574 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1575 ew32(RCTL, rctl);
1576
1577 switch (hw->mac.type) {
Yanir Lubetkin2ec7d292015-06-02 17:05:47 +03001578 case e1000_pch_spt:
1579 fext_nvm11 = er32(FEXTNVM11);
1580 fext_nvm11 &= ~E1000_FEXTNVM11_DISABLE_MULR_FIX;
1581 ew32(FEXTNVM11, fext_nvm11);
1582 tarc0 = er32(TARC(0));
1583 /* clear bits 28 & 29 (control of MULR concurrent requests) */
1584 /* set bit 29 (value of MULR requests is now 0) */
1585 tarc0 &= 0xcfffffff;
1586 ew32(TARC(0), tarc0);
1587 /* fall through */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001588 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001589 if (hw->phy.media_type == e1000_media_type_fiber ||
1590 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001591 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001592 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001593 adapter->tx_fifo_head = 0;
1594 }
1595 /* fall through */
1596 case e1000_82571:
1597 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001598 if (hw->phy.media_type == e1000_media_type_fiber ||
1599 hw->phy.media_type == e1000_media_type_internal_serdes) {
Bruce Allan3ffcf2c2013-02-20 04:06:43 +00001600 ew32(SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001601 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001602 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001603 break;
1604 }
1605 /* Fall Through */
1606 default:
1607 hw->mac.autoneg = 1;
1608 if (hw->phy.type == e1000_phy_gg82563)
1609 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
Bruce Allanc2ade1a2013-01-16 08:54:35 +00001610 e1e_rphy(hw, MII_BMCR, &phy_reg);
1611 if (phy_reg & BMCR_LOOPBACK) {
1612 phy_reg &= ~BMCR_LOOPBACK;
1613 e1e_wphy(hw, MII_BMCR, phy_reg);
Bruce Allan6b598e12013-01-23 06:50:05 +00001614 if (hw->phy.ops.commit)
1615 hw->phy.ops.commit(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001616 }
1617 break;
1618 }
1619}
1620
1621static void e1000_create_lbtest_frame(struct sk_buff *skb,
1622 unsigned int frame_size)
1623{
1624 memset(skb->data, 0xFF, frame_size);
1625 frame_size &= ~1;
1626 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1627 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1628 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1629}
1630
1631static int e1000_check_lbtest_frame(struct sk_buff *skb,
1632 unsigned int frame_size)
1633{
1634 frame_size &= ~1;
1635 if (*(skb->data + 3) == 0xFF)
1636 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
Bruce Allan17e813e2013-02-20 04:06:01 +00001637 (*(skb->data + frame_size / 2 + 12) == 0xAF))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001638 return 0;
1639 return 13;
1640}
1641
1642static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1643{
1644 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1645 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1646 struct pci_dev *pdev = adapter->pdev;
1647 struct e1000_hw *hw = &adapter->hw;
Bruce Allan17e813e2013-02-20 04:06:01 +00001648 struct e1000_buffer *buffer_info;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001649 int i, j, k, l;
1650 int lc;
1651 int good_cnt;
1652 int ret_val = 0;
1653 unsigned long time;
1654
Bruce Allan1e360522012-03-20 03:48:13 +00001655 ew32(RDT(0), rx_ring->count - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001656
Bruce Allane921eb12012-11-28 09:28:37 +00001657 /* Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001658 * The idea is to wrap the largest ring a number of times using 64
1659 * send/receive pairs during each loop
1660 */
1661
1662 if (rx_ring->count <= tx_ring->count)
1663 lc = ((tx_ring->count / 64) * 2) + 1;
1664 else
1665 lc = ((rx_ring->count / 64) * 2) + 1;
1666
1667 k = 0;
1668 l = 0;
Bruce Allan33550ce2013-02-20 04:06:16 +00001669 /* loop count loop */
1670 for (j = 0; j <= lc; j++) {
1671 /* send the packets */
1672 for (i = 0; i < 64; i++) {
Bruce Allan17e813e2013-02-20 04:06:01 +00001673 buffer_info = &tx_ring->buffer_info[k];
1674
1675 e1000_create_lbtest_frame(buffer_info->skb, 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001676 dma_sync_single_for_device(&pdev->dev,
Bruce Allan17e813e2013-02-20 04:06:01 +00001677 buffer_info->dma,
1678 buffer_info->length,
1679 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001680 k++;
1681 if (k == tx_ring->count)
1682 k = 0;
1683 }
Bruce Allan1e360522012-03-20 03:48:13 +00001684 ew32(TDT(0), k);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001685 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001686 msleep(200);
Bruce Allane80bd1d2013-05-01 01:19:46 +00001687 time = jiffies; /* set the start time for the receive */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001688 good_cnt = 0;
Bruce Allan33550ce2013-02-20 04:06:16 +00001689 /* receive the sent packets */
1690 do {
Bruce Allan17e813e2013-02-20 04:06:01 +00001691 buffer_info = &rx_ring->buffer_info[l];
Auke Kokbc7f75f2007-09-17 12:30:59 -07001692
Bruce Allan17e813e2013-02-20 04:06:01 +00001693 dma_sync_single_for_cpu(&pdev->dev,
1694 buffer_info->dma, 2048,
1695 DMA_FROM_DEVICE);
1696
1697 ret_val = e1000_check_lbtest_frame(buffer_info->skb,
1698 1024);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001699 if (!ret_val)
1700 good_cnt++;
1701 l++;
1702 if (l == rx_ring->count)
1703 l = 0;
Bruce Allane921eb12012-11-28 09:28:37 +00001704 /* time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001705 * enough time to complete the receives, if it's
1706 * exceeded, break and error off
1707 */
1708 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1709 if (good_cnt != 64) {
Bruce Allane80bd1d2013-05-01 01:19:46 +00001710 ret_val = 13; /* ret_val is the same as mis-compare */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001711 break;
1712 }
Bruce Allan22f8aba2013-08-15 03:43:24 +00001713 if (time_after(jiffies, time + 20)) {
Bruce Allane80bd1d2013-05-01 01:19:46 +00001714 ret_val = 14; /* error code for time out error */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001715 break;
1716 }
Bruce Allan33550ce2013-02-20 04:06:16 +00001717 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001718 return ret_val;
1719}
1720
1721static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1722{
Bruce Allan44abd5c2012-02-22 09:02:37 +00001723 struct e1000_hw *hw = &adapter->hw;
1724
Bruce Allane921eb12012-11-28 09:28:37 +00001725 /* PHY loopback cannot be performed if SoL/IDER sessions are active */
Bruce Allan470a5422012-05-26 06:08:48 +00001726 if (hw->phy.ops.check_reset_block &&
1727 hw->phy.ops.check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001728 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001729 *data = 0;
1730 goto out;
1731 }
1732
1733 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001734 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001735 goto out;
1736
1737 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001738 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001739 goto err_loopback;
1740
1741 *data = e1000_run_loopback_test(adapter);
1742 e1000_loopback_cleanup(adapter);
1743
1744err_loopback:
1745 e1000_free_desc_rings(adapter);
1746out:
1747 return *data;
1748}
1749
1750static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1751{
1752 struct e1000_hw *hw = &adapter->hw;
1753
1754 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001755 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001756 int i = 0;
David Ertman6cf08d12014-04-05 06:07:00 +00001757
Alex Chiang612e2442009-02-05 23:55:45 -08001758 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001759
Bruce Allane921eb12012-11-28 09:28:37 +00001760 /* On some blade server designs, link establishment
Bruce Allanad680762008-03-28 09:15:03 -07001761 * could take as long as 2-3 minutes
1762 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001763 do {
1764 hw->mac.ops.check_for_link(hw);
1765 if (hw->mac.serdes_has_link)
1766 return *data;
1767 msleep(20);
1768 } while (i++ < 3750);
1769
1770 *data = 1;
1771 } else {
1772 hw->mac.ops.check_for_link(hw);
1773 if (hw->mac.autoneg)
Bruce Allane921eb12012-11-28 09:28:37 +00001774 /* On some Phy/switch combinations, link establishment
Bruce Allan5661aeb2011-02-25 06:36:25 +00001775 * can take a few seconds more than expected.
1776 */
Bruce Allance43a212013-02-20 04:06:32 +00001777 msleep_interruptible(5000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001778
Bruce Allan5661aeb2011-02-25 06:36:25 +00001779 if (!(er32(STATUS) & E1000_STATUS_LU))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001780 *data = 1;
1781 }
1782 return *data;
1783}
1784
Bruce Allan8bb62862013-01-16 08:46:49 +00001785static int e1000e_get_sset_count(struct net_device __always_unused *netdev,
1786 int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001787{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001788 switch (sset) {
1789 case ETH_SS_TEST:
1790 return E1000_TEST_LEN;
1791 case ETH_SS_STATS:
1792 return E1000_STATS_LEN;
1793 default:
1794 return -EOPNOTSUPP;
1795 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001796}
1797
1798static void e1000_diag_test(struct net_device *netdev,
1799 struct ethtool_test *eth_test, u64 *data)
1800{
1801 struct e1000_adapter *adapter = netdev_priv(netdev);
1802 u16 autoneg_advertised;
1803 u8 forced_speed_duplex;
1804 u8 autoneg;
1805 bool if_running = netif_running(netdev);
1806
Bruce Allan3ef672a2013-06-27 02:44:44 +00001807 pm_runtime_get_sync(netdev->dev.parent);
1808
Auke Kokbc7f75f2007-09-17 12:30:59 -07001809 set_bit(__E1000_TESTING, &adapter->state);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001810
1811 if (!if_running) {
1812 /* Get control of and reset hardware */
1813 if (adapter->flags & FLAG_HAS_AMT)
1814 e1000e_get_hw_control(adapter);
1815
1816 e1000e_power_up_phy(adapter);
1817
1818 adapter->hw.phy.autoneg_wait_to_complete = 1;
1819 e1000e_reset(adapter);
1820 adapter->hw.phy.autoneg_wait_to_complete = 0;
1821 }
1822
Auke Kokbc7f75f2007-09-17 12:30:59 -07001823 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1824 /* Offline tests */
1825
1826 /* save speed, duplex, autoneg settings */
1827 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1828 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1829 autoneg = adapter->hw.mac.autoneg;
1830
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001831 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001832
Auke Kokbc7f75f2007-09-17 12:30:59 -07001833 if (if_running)
1834 /* indicate we're in test mode */
Stefan Assmannd5ea45d2016-02-03 09:20:52 +01001835 e1000e_close(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001836
1837 if (e1000_reg_test(adapter, &data[0]))
1838 eth_test->flags |= ETH_TEST_FL_FAILED;
1839
1840 e1000e_reset(adapter);
1841 if (e1000_eeprom_test(adapter, &data[1]))
1842 eth_test->flags |= ETH_TEST_FL_FAILED;
1843
1844 e1000e_reset(adapter);
1845 if (e1000_intr_test(adapter, &data[2]))
1846 eth_test->flags |= ETH_TEST_FL_FAILED;
1847
1848 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001849 if (e1000_loopback_test(adapter, &data[3]))
1850 eth_test->flags |= ETH_TEST_FL_FAILED;
1851
Auke Kokbc7f75f2007-09-17 12:30:59 -07001852 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001853 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001854 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001855 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001856
Carolyn Wybornyc6ce3852010-10-15 17:35:31 +00001857 if (e1000_link_test(adapter, &data[4]))
1858 eth_test->flags |= ETH_TEST_FL_FAILED;
1859
1860 /* restore speed, duplex, autoneg settings */
1861 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1862 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1863 adapter->hw.mac.autoneg = autoneg;
1864 e1000e_reset(adapter);
1865
Auke Kokbc7f75f2007-09-17 12:30:59 -07001866 clear_bit(__E1000_TESTING, &adapter->state);
1867 if (if_running)
Stefan Assmannd5ea45d2016-02-03 09:20:52 +01001868 e1000e_open(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001869 } else {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001870 /* Online tests */
Bruce Allan11b08be2010-05-10 14:59:31 +00001871
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001872 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001873
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001874 /* register, eeprom, intr and loopback tests not run online */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001875 data[0] = 0;
1876 data[1] = 0;
1877 data[2] = 0;
1878 data[3] = 0;
1879
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001880 if (e1000_link_test(adapter, &data[4]))
1881 eth_test->flags |= ETH_TEST_FL_FAILED;
Bruce Allan11b08be2010-05-10 14:59:31 +00001882
Auke Kokbc7f75f2007-09-17 12:30:59 -07001883 clear_bit(__E1000_TESTING, &adapter->state);
1884 }
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001885
1886 if (!if_running) {
1887 e1000e_reset(adapter);
1888
1889 if (adapter->flags & FLAG_HAS_AMT)
1890 e1000e_release_hw_control(adapter);
1891 }
1892
Auke Kokbc7f75f2007-09-17 12:30:59 -07001893 msleep_interruptible(4 * 1000);
Bruce Allan3ef672a2013-06-27 02:44:44 +00001894
1895 pm_runtime_put_sync(netdev->dev.parent);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001896}
1897
1898static void e1000_get_wol(struct net_device *netdev,
1899 struct ethtool_wolinfo *wol)
1900{
1901 struct e1000_adapter *adapter = netdev_priv(netdev);
1902
1903 wol->supported = 0;
1904 wol->wolopts = 0;
1905
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001906 if (!(adapter->flags & FLAG_HAS_WOL) ||
1907 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001908 return;
1909
1910 wol->supported = WAKE_UCAST | WAKE_MCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001911 WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001912
1913 /* apply any specific unsupported masks here */
1914 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1915 wol->supported &= ~WAKE_UCAST;
1916
1917 if (adapter->wol & E1000_WUFC_EX)
Bruce Allan6ad65142012-04-12 05:47:09 +00001918 e_err("Interface does not support directed (unicast) frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001919 }
1920
1921 if (adapter->wol & E1000_WUFC_EX)
1922 wol->wolopts |= WAKE_UCAST;
1923 if (adapter->wol & E1000_WUFC_MC)
1924 wol->wolopts |= WAKE_MCAST;
1925 if (adapter->wol & E1000_WUFC_BC)
1926 wol->wolopts |= WAKE_BCAST;
1927 if (adapter->wol & E1000_WUFC_MAG)
1928 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001929 if (adapter->wol & E1000_WUFC_LNKC)
1930 wol->wolopts |= WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001931}
1932
Bruce Allan4a29e152011-03-04 09:07:01 +00001933static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001934{
1935 struct e1000_adapter *adapter = netdev_priv(netdev);
1936
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001937 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001938 !device_can_wakeup(&adapter->pdev->dev) ||
1939 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001940 WAKE_MAGIC | WAKE_PHY)))
Bruce Allan1fbfca32009-11-20 23:22:01 +00001941 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001942
1943 /* these settings will always override what we currently have */
1944 adapter->wol = 0;
1945
1946 if (wol->wolopts & WAKE_UCAST)
1947 adapter->wol |= E1000_WUFC_EX;
1948 if (wol->wolopts & WAKE_MCAST)
1949 adapter->wol |= E1000_WUFC_MC;
1950 if (wol->wolopts & WAKE_BCAST)
1951 adapter->wol |= E1000_WUFC_BC;
1952 if (wol->wolopts & WAKE_MAGIC)
1953 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001954 if (wol->wolopts & WAKE_PHY)
1955 adapter->wol |= E1000_WUFC_LNKC;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001956
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001957 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1958
Auke Kokbc7f75f2007-09-17 12:30:59 -07001959 return 0;
1960}
1961
Bruce Allandbf80dc2011-04-16 00:34:40 +00001962static int e1000_set_phys_id(struct net_device *netdev,
1963 enum ethtool_phys_id_state state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001964{
1965 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001966 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001967
Bruce Allandbf80dc2011-04-16 00:34:40 +00001968 switch (state) {
1969 case ETHTOOL_ID_ACTIVE:
Bruce Allan3ef672a2013-06-27 02:44:44 +00001970 pm_runtime_get_sync(netdev->dev.parent);
1971
Bruce Allandbf80dc2011-04-16 00:34:40 +00001972 if (!hw->mac.ops.blink_led)
1973 return 2; /* cycle on/off twice per second */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001974
Bruce Allandbf80dc2011-04-16 00:34:40 +00001975 hw->mac.ops.blink_led(hw);
1976 break;
1977
1978 case ETHTOOL_ID_INACTIVE:
Bruce Allan4662e822008-08-26 18:37:06 -07001979 if (hw->phy.type == e1000_phy_ife)
1980 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001981 hw->mac.ops.led_off(hw);
1982 hw->mac.ops.cleanup_led(hw);
Bruce Allan3ef672a2013-06-27 02:44:44 +00001983 pm_runtime_put_sync(netdev->dev.parent);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001984 break;
1985
1986 case ETHTOOL_ID_ON:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001987 hw->mac.ops.led_on(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001988 break;
1989
1990 case ETHTOOL_ID_OFF:
Bruce Allanf23efdf2012-01-31 06:37:38 +00001991 hw->mac.ops.led_off(hw);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001992 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001993 }
Bruce Allan3ef672a2013-06-27 02:44:44 +00001994
Auke Kokbc7f75f2007-09-17 12:30:59 -07001995 return 0;
1996}
1997
Auke Kokde5b3072008-04-23 11:09:08 -07001998static int e1000_get_coalesce(struct net_device *netdev,
1999 struct ethtool_coalesce *ec)
2000{
2001 struct e1000_adapter *adapter = netdev_priv(netdev);
2002
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00002003 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07002004 ec->rx_coalesce_usecs = adapter->itr_setting;
2005 else
2006 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
2007
2008 return 0;
2009}
2010
2011static int e1000_set_coalesce(struct net_device *netdev,
2012 struct ethtool_coalesce *ec)
2013{
2014 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokde5b3072008-04-23 11:09:08 -07002015
2016 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00002017 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07002018 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
2019 (ec->rx_coalesce_usecs == 2))
2020 return -EINVAL;
2021
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00002022 if (ec->rx_coalesce_usecs == 4) {
Bruce Allan06a402e2012-08-17 06:17:57 +00002023 adapter->itr_setting = 4;
2024 adapter->itr = adapter->itr_setting;
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00002025 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07002026 adapter->itr = 20000;
2027 adapter->itr_setting = ec->rx_coalesce_usecs;
2028 } else {
2029 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
2030 adapter->itr_setting = adapter->itr & ~3;
2031 }
2032
Bruce Allan3ef672a2013-06-27 02:44:44 +00002033 pm_runtime_get_sync(netdev->dev.parent);
2034
Auke Kokde5b3072008-04-23 11:09:08 -07002035 if (adapter->itr_setting != 0)
Matthew Vick22a4cca2012-07-12 00:02:42 +00002036 e1000e_write_itr(adapter, adapter->itr);
Auke Kokde5b3072008-04-23 11:09:08 -07002037 else
Matthew Vick22a4cca2012-07-12 00:02:42 +00002038 e1000e_write_itr(adapter, 0);
Auke Kokde5b3072008-04-23 11:09:08 -07002039
Bruce Allan3ef672a2013-06-27 02:44:44 +00002040 pm_runtime_put_sync(netdev->dev.parent);
2041
Auke Kokde5b3072008-04-23 11:09:08 -07002042 return 0;
2043}
2044
Auke Kokbc7f75f2007-09-17 12:30:59 -07002045static int e1000_nway_reset(struct net_device *netdev)
2046{
2047 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan5962bc22011-01-20 06:58:07 +00002048
2049 if (!netif_running(netdev))
2050 return -EAGAIN;
2051
2052 if (!adapter->hw.mac.autoneg)
2053 return -EINVAL;
2054
Bruce Allan3ef672a2013-06-27 02:44:44 +00002055 pm_runtime_get_sync(netdev->dev.parent);
Bruce Allan5962bc22011-01-20 06:58:07 +00002056 e1000e_reinit_locked(adapter);
Bruce Allan3ef672a2013-06-27 02:44:44 +00002057 pm_runtime_put_sync(netdev->dev.parent);
Bruce Allan5962bc22011-01-20 06:58:07 +00002058
Auke Kokbc7f75f2007-09-17 12:30:59 -07002059 return 0;
2060}
2061
Auke Kokbc7f75f2007-09-17 12:30:59 -07002062static void e1000_get_ethtool_stats(struct net_device *netdev,
Bruce Allan8bb62862013-01-16 08:46:49 +00002063 struct ethtool_stats __always_unused *stats,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002064 u64 *data)
2065{
2066 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00002067 struct rtnl_link_stats64 net_stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002068 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00002069 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002070
Bruce Allan3ef672a2013-06-27 02:44:44 +00002071 pm_runtime_get_sync(netdev->dev.parent);
2072
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00002073 e1000e_get_stats64(netdev, &net_stats);
Bruce Allan3ef672a2013-06-27 02:44:44 +00002074
2075 pm_runtime_put_sync(netdev->dev.parent);
2076
Auke Kokbc7f75f2007-09-17 12:30:59 -07002077 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00002078 switch (e1000_gstrings_stats[i].type) {
2079 case NETDEV_STATS:
Bruce Allan53aa82d2013-02-20 04:06:06 +00002080 p = (char *)&net_stats +
Bruce Allanf0ff4392013-02-20 04:05:39 +00002081 e1000_gstrings_stats[i].stat_offset;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00002082 break;
2083 case E1000_STATS:
Bruce Allan53aa82d2013-02-20 04:06:06 +00002084 p = (char *)adapter +
Bruce Allanf0ff4392013-02-20 04:05:39 +00002085 e1000_gstrings_stats[i].stat_offset;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00002086 break;
Bruce Allan61c75812010-12-09 23:04:25 +00002087 default:
2088 data[i] = 0;
2089 continue;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00002090 }
2091
Auke Kokbc7f75f2007-09-17 12:30:59 -07002092 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
Bruce Allanf0ff4392013-02-20 04:05:39 +00002093 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002094 }
2095}
2096
Bruce Allan8bb62862013-01-16 08:46:49 +00002097static void e1000_get_strings(struct net_device __always_unused *netdev,
2098 u32 stringset, u8 *data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002099{
2100 u8 *p = data;
2101 int i;
2102
2103 switch (stringset) {
2104 case ETH_SS_TEST:
Bruce Allan5c1bda02011-01-19 04:23:39 +00002105 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002106 break;
2107 case ETH_SS_STATS:
2108 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
2109 memcpy(p, e1000_gstrings_stats[i].stat_string,
2110 ETH_GSTRING_LEN);
2111 p += ETH_GSTRING_LEN;
2112 }
2113 break;
2114 }
2115}
2116
Bruce Allan70495a52012-01-11 01:26:50 +00002117static int e1000_get_rxnfc(struct net_device *netdev,
Bruce Allan8bb62862013-01-16 08:46:49 +00002118 struct ethtool_rxnfc *info,
2119 u32 __always_unused *rule_locs)
Bruce Allan70495a52012-01-11 01:26:50 +00002120{
2121 info->data = 0;
2122
2123 switch (info->cmd) {
2124 case ETHTOOL_GRXFH: {
2125 struct e1000_adapter *adapter = netdev_priv(netdev);
2126 struct e1000_hw *hw = &adapter->hw;
Bruce Allan3ef672a2013-06-27 02:44:44 +00002127 u32 mrqc;
2128
2129 pm_runtime_get_sync(netdev->dev.parent);
2130 mrqc = er32(MRQC);
2131 pm_runtime_put_sync(netdev->dev.parent);
Bruce Allan70495a52012-01-11 01:26:50 +00002132
2133 if (!(mrqc & E1000_MRQC_RSS_FIELD_MASK))
2134 return 0;
2135
2136 switch (info->flow_type) {
2137 case TCP_V4_FLOW:
2138 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP)
2139 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2140 /* fall through */
2141 case UDP_V4_FLOW:
2142 case SCTP_V4_FLOW:
2143 case AH_ESP_V4_FLOW:
2144 case IPV4_FLOW:
2145 if (mrqc & E1000_MRQC_RSS_FIELD_IPV4)
2146 info->data |= RXH_IP_SRC | RXH_IP_DST;
2147 break;
2148 case TCP_V6_FLOW:
2149 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP)
2150 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2151 /* fall through */
2152 case UDP_V6_FLOW:
2153 case SCTP_V6_FLOW:
2154 case AH_ESP_V6_FLOW:
2155 case IPV6_FLOW:
2156 if (mrqc & E1000_MRQC_RSS_FIELD_IPV6)
2157 info->data |= RXH_IP_SRC | RXH_IP_DST;
2158 break;
2159 default:
2160 break;
2161 }
2162 return 0;
2163 }
2164 default:
2165 return -EOPNOTSUPP;
2166 }
2167}
2168
Bruce Allan203e4152012-12-05 08:40:59 +00002169static int e1000e_get_eee(struct net_device *netdev, struct ethtool_eee *edata)
2170{
2171 struct e1000_adapter *adapter = netdev_priv(netdev);
2172 struct e1000_hw *hw = &adapter->hw;
Bruce Alland495bcb2013-03-20 07:23:11 +00002173 u16 cap_addr, lpa_addr, pcs_stat_addr, phy_data;
2174 u32 ret_val;
Bruce Allan203e4152012-12-05 08:40:59 +00002175
Bruce Alland495bcb2013-03-20 07:23:11 +00002176 if (!(adapter->flags2 & FLAG2_HAS_EEE))
Bruce Allan203e4152012-12-05 08:40:59 +00002177 return -EOPNOTSUPP;
2178
2179 switch (hw->phy.type) {
2180 case e1000_phy_82579:
2181 cap_addr = I82579_EEE_CAPABILITY;
Bruce Allan203e4152012-12-05 08:40:59 +00002182 lpa_addr = I82579_EEE_LP_ABILITY;
2183 pcs_stat_addr = I82579_EEE_PCS_STATUS;
2184 break;
2185 case e1000_phy_i217:
2186 cap_addr = I217_EEE_CAPABILITY;
Bruce Allan203e4152012-12-05 08:40:59 +00002187 lpa_addr = I217_EEE_LP_ABILITY;
2188 pcs_stat_addr = I217_EEE_PCS_STATUS;
2189 break;
2190 default:
2191 return -EOPNOTSUPP;
2192 }
2193
Bruce Allan3ef672a2013-06-27 02:44:44 +00002194 pm_runtime_get_sync(netdev->dev.parent);
2195
Bruce Allan203e4152012-12-05 08:40:59 +00002196 ret_val = hw->phy.ops.acquire(hw);
Bruce Allan3ef672a2013-06-27 02:44:44 +00002197 if (ret_val) {
2198 pm_runtime_put_sync(netdev->dev.parent);
Bruce Allan203e4152012-12-05 08:40:59 +00002199 return -EBUSY;
Bruce Allan3ef672a2013-06-27 02:44:44 +00002200 }
Bruce Allan203e4152012-12-05 08:40:59 +00002201
2202 /* EEE Capability */
2203 ret_val = e1000_read_emi_reg_locked(hw, cap_addr, &phy_data);
2204 if (ret_val)
2205 goto release;
2206 edata->supported = mmd_eee_cap_to_ethtool_sup_t(phy_data);
2207
2208 /* EEE Advertised */
Bruce Alland495bcb2013-03-20 07:23:11 +00002209 edata->advertised = mmd_eee_adv_to_ethtool_adv_t(adapter->eee_advert);
Bruce Allan203e4152012-12-05 08:40:59 +00002210
2211 /* EEE Link Partner Advertised */
2212 ret_val = e1000_read_emi_reg_locked(hw, lpa_addr, &phy_data);
2213 if (ret_val)
2214 goto release;
2215 edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
2216
2217 /* EEE PCS Status */
2218 ret_val = e1000_read_emi_reg_locked(hw, pcs_stat_addr, &phy_data);
Bruce Allan3ef672a2013-06-27 02:44:44 +00002219 if (ret_val)
2220 goto release;
Bruce Allan203e4152012-12-05 08:40:59 +00002221 if (hw->phy.type == e1000_phy_82579)
2222 phy_data <<= 8;
2223
Bruce Allan203e4152012-12-05 08:40:59 +00002224 /* Result of the EEE auto negotiation - there is no register that
2225 * has the status of the EEE negotiation so do a best-guess based
Bruce Alland495bcb2013-03-20 07:23:11 +00002226 * on whether Tx or Rx LPI indications have been received.
Bruce Allan203e4152012-12-05 08:40:59 +00002227 */
Bruce Alland495bcb2013-03-20 07:23:11 +00002228 if (phy_data & (E1000_EEE_TX_LPI_RCVD | E1000_EEE_RX_LPI_RCVD))
Bruce Allan203e4152012-12-05 08:40:59 +00002229 edata->eee_active = true;
2230
2231 edata->eee_enabled = !hw->dev_spec.ich8lan.eee_disable;
2232 edata->tx_lpi_enabled = true;
2233 edata->tx_lpi_timer = er32(LPIC) >> E1000_LPIC_LPIET_SHIFT;
2234
Bruce Allan3ef672a2013-06-27 02:44:44 +00002235release:
2236 hw->phy.ops.release(hw);
2237 if (ret_val)
2238 ret_val = -ENODATA;
2239
2240 pm_runtime_put_sync(netdev->dev.parent);
2241
2242 return ret_val;
Bruce Allan203e4152012-12-05 08:40:59 +00002243}
2244
2245static int e1000e_set_eee(struct net_device *netdev, struct ethtool_eee *edata)
2246{
2247 struct e1000_adapter *adapter = netdev_priv(netdev);
2248 struct e1000_hw *hw = &adapter->hw;
2249 struct ethtool_eee eee_curr;
2250 s32 ret_val;
2251
Bruce Allan203e4152012-12-05 08:40:59 +00002252 ret_val = e1000e_get_eee(netdev, &eee_curr);
2253 if (ret_val)
2254 return ret_val;
2255
Bruce Allan203e4152012-12-05 08:40:59 +00002256 if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
2257 e_err("Setting EEE tx-lpi is not supported\n");
2258 return -EINVAL;
2259 }
2260
2261 if (eee_curr.tx_lpi_timer != edata->tx_lpi_timer) {
2262 e_err("Setting EEE Tx LPI timer is not supported\n");
2263 return -EINVAL;
2264 }
2265
Bruce Alland495bcb2013-03-20 07:23:11 +00002266 if (edata->advertised & ~(ADVERTISE_100_FULL | ADVERTISE_1000_FULL)) {
2267 e_err("EEE advertisement supports only 100TX and/or 1000T full-duplex\n");
2268 return -EINVAL;
Bruce Allan203e4152012-12-05 08:40:59 +00002269 }
2270
Bruce Alland495bcb2013-03-20 07:23:11 +00002271 adapter->eee_advert = ethtool_adv_to_mmd_eee_adv_t(edata->advertised);
2272
2273 hw->dev_spec.ich8lan.eee_disable = !edata->eee_enabled;
2274
Bruce Allan3ef672a2013-06-27 02:44:44 +00002275 pm_runtime_get_sync(netdev->dev.parent);
2276
Bruce Alland495bcb2013-03-20 07:23:11 +00002277 /* reset the link */
2278 if (netif_running(netdev))
2279 e1000e_reinit_locked(adapter);
2280 else
2281 e1000e_reset(adapter);
2282
Bruce Allan3ef672a2013-06-27 02:44:44 +00002283 pm_runtime_put_sync(netdev->dev.parent);
2284
Bruce Allan203e4152012-12-05 08:40:59 +00002285 return 0;
2286}
2287
Bruce Allanb67e1912012-12-27 08:32:33 +00002288static int e1000e_get_ts_info(struct net_device *netdev,
2289 struct ethtool_ts_info *info)
2290{
2291 struct e1000_adapter *adapter = netdev_priv(netdev);
2292
2293 ethtool_op_get_ts_info(netdev, info);
2294
2295 if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
2296 return 0;
2297
2298 info->so_timestamping |= (SOF_TIMESTAMPING_TX_HARDWARE |
2299 SOF_TIMESTAMPING_RX_HARDWARE |
2300 SOF_TIMESTAMPING_RAW_HARDWARE);
2301
Jacob Keller18dd2392016-04-13 16:08:32 -07002302 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Bruce Allanb67e1912012-12-27 08:32:33 +00002303
Jacob Keller18dd2392016-04-13 16:08:32 -07002304 info->rx_filters = (BIT(HWTSTAMP_FILTER_NONE) |
2305 BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
2306 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
2307 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
2308 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
2309 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
2310 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
2311 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
2312 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
2313 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
2314 BIT(HWTSTAMP_FILTER_ALL));
Bruce Allanb67e1912012-12-27 08:32:33 +00002315
Bruce Alland89777b2013-01-19 01:09:58 +00002316 if (adapter->ptp_clock)
2317 info->phc_index = ptp_clock_index(adapter->ptp_clock);
2318
Bruce Allanb67e1912012-12-27 08:32:33 +00002319 return 0;
2320}
2321
Auke Kokbc7f75f2007-09-17 12:30:59 -07002322static const struct ethtool_ops e1000_ethtool_ops = {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002323 .get_drvinfo = e1000_get_drvinfo,
2324 .get_regs_len = e1000_get_regs_len,
2325 .get_regs = e1000_get_regs,
2326 .get_wol = e1000_get_wol,
2327 .set_wol = e1000_set_wol,
2328 .get_msglevel = e1000_get_msglevel,
2329 .set_msglevel = e1000_set_msglevel,
2330 .nway_reset = e1000_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00002331 .get_link = ethtool_op_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002332 .get_eeprom_len = e1000_get_eeprom_len,
2333 .get_eeprom = e1000_get_eeprom,
2334 .set_eeprom = e1000_set_eeprom,
2335 .get_ringparam = e1000_get_ringparam,
2336 .set_ringparam = e1000_set_ringparam,
2337 .get_pauseparam = e1000_get_pauseparam,
2338 .set_pauseparam = e1000_set_pauseparam,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002339 .self_test = e1000_diag_test,
2340 .get_strings = e1000_get_strings,
Bruce Allandbf80dc2011-04-16 00:34:40 +00002341 .set_phys_id = e1000_set_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002342 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07002343 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07002344 .get_coalesce = e1000_get_coalesce,
2345 .set_coalesce = e1000_set_coalesce,
Bruce Allan70495a52012-01-11 01:26:50 +00002346 .get_rxnfc = e1000_get_rxnfc,
Bruce Allanb67e1912012-12-27 08:32:33 +00002347 .get_ts_info = e1000e_get_ts_info,
Bruce Allan203e4152012-12-05 08:40:59 +00002348 .get_eee = e1000e_get_eee,
2349 .set_eee = e1000e_set_eee,
Philippe Reynesfb052fd2017-01-26 22:19:53 +01002350 .get_link_ksettings = e1000_get_link_ksettings,
2351 .set_link_ksettings = e1000_set_link_ksettings,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002352};
2353
2354void e1000e_set_ethtool_ops(struct net_device *netdev)
2355{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002356 netdev->ethtool_ops = &e1000_ethtool_ops;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002357}