blob: 6d8f0ed332143a85b62dc41e4095ba922f43cd93 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allan0d6057e2011-01-04 01:16:44 +00004 Copyright(c) 1999 - 2011 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29/* ethtool support for e1000 */
30
31#include <linux/netdevice.h>
Bruce Allan9fb7a5f2011-07-29 05:52:51 +000032#include <linux/interrupt.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070033#include <linux/ethtool.h>
34#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070036#include <linux/delay.h>
37
38#include "e1000.h"
39
Ajit Khapardee0f36a92009-10-13 01:45:09 +000040enum {NETDEV_STATS, E1000_STATS};
41
Auke Kokbc7f75f2007-09-17 12:30:59 -070042struct e1000_stats {
43 char stat_string[ETH_GSTRING_LEN];
Ajit Khapardee0f36a92009-10-13 01:45:09 +000044 int type;
Auke Kokbc7f75f2007-09-17 12:30:59 -070045 int sizeof_stat;
46 int stat_offset;
47};
48
Bruce Allanf0f1a172010-12-11 05:53:32 +000049#define E1000_STAT(str, m) { \
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000050 .stat_string = str, \
51 .type = E1000_STATS, \
52 .sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
53 .stat_offset = offsetof(struct e1000_adapter, m) }
Bruce Allanf0f1a172010-12-11 05:53:32 +000054#define E1000_NETDEV_STAT(str, m) { \
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000055 .stat_string = str, \
56 .type = NETDEV_STATS, \
57 .sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \
58 .stat_offset = offsetof(struct rtnl_link_stats64, m) }
Ajit Khapardee0f36a92009-10-13 01:45:09 +000059
Auke Kokbc7f75f2007-09-17 12:30:59 -070060static const struct e1000_stats e1000_gstrings_stats[] = {
Bruce Allanf0f1a172010-12-11 05:53:32 +000061 E1000_STAT("rx_packets", stats.gprc),
62 E1000_STAT("tx_packets", stats.gptc),
63 E1000_STAT("rx_bytes", stats.gorc),
64 E1000_STAT("tx_bytes", stats.gotc),
65 E1000_STAT("rx_broadcast", stats.bprc),
66 E1000_STAT("tx_broadcast", stats.bptc),
67 E1000_STAT("rx_multicast", stats.mprc),
68 E1000_STAT("tx_multicast", stats.mptc),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000069 E1000_NETDEV_STAT("rx_errors", rx_errors),
70 E1000_NETDEV_STAT("tx_errors", tx_errors),
71 E1000_NETDEV_STAT("tx_dropped", tx_dropped),
Bruce Allanf0f1a172010-12-11 05:53:32 +000072 E1000_STAT("multicast", stats.mprc),
73 E1000_STAT("collisions", stats.colc),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000074 E1000_NETDEV_STAT("rx_length_errors", rx_length_errors),
75 E1000_NETDEV_STAT("rx_over_errors", rx_over_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000076 E1000_STAT("rx_crc_errors", stats.crcerrs),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000077 E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000078 E1000_STAT("rx_no_buffer_count", stats.rnbc),
79 E1000_STAT("rx_missed_errors", stats.mpc),
80 E1000_STAT("tx_aborted_errors", stats.ecol),
81 E1000_STAT("tx_carrier_errors", stats.tncrs),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000082 E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
83 E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000084 E1000_STAT("tx_window_errors", stats.latecol),
85 E1000_STAT("tx_abort_late_coll", stats.latecol),
86 E1000_STAT("tx_deferred_ok", stats.dc),
87 E1000_STAT("tx_single_coll_ok", stats.scc),
88 E1000_STAT("tx_multi_coll_ok", stats.mcc),
89 E1000_STAT("tx_timeout_count", tx_timeout_count),
90 E1000_STAT("tx_restart_queue", restart_queue),
91 E1000_STAT("rx_long_length_errors", stats.roc),
92 E1000_STAT("rx_short_length_errors", stats.ruc),
93 E1000_STAT("rx_align_errors", stats.algnerrc),
94 E1000_STAT("tx_tcp_seg_good", stats.tsctc),
95 E1000_STAT("tx_tcp_seg_failed", stats.tsctfc),
96 E1000_STAT("rx_flow_control_xon", stats.xonrxc),
97 E1000_STAT("rx_flow_control_xoff", stats.xoffrxc),
98 E1000_STAT("tx_flow_control_xon", stats.xontxc),
99 E1000_STAT("tx_flow_control_xoff", stats.xofftxc),
100 E1000_STAT("rx_long_byte_count", stats.gorc),
101 E1000_STAT("rx_csum_offload_good", hw_csum_good),
102 E1000_STAT("rx_csum_offload_errors", hw_csum_err),
103 E1000_STAT("rx_header_split", rx_hdr_split),
104 E1000_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),
105 E1000_STAT("tx_smbus", stats.mgptc),
106 E1000_STAT("rx_smbus", stats.mgprc),
107 E1000_STAT("dropped_smbus", stats.mgpdc),
108 E1000_STAT("rx_dma_failed", rx_dma_failed),
109 E1000_STAT("tx_dma_failed", tx_dma_failed),
Auke Kokbc7f75f2007-09-17 12:30:59 -0700110};
111
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200112#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700113#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
114static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
115 "Register test (offline)", "Eeprom test (offline)",
116 "Interrupt test (offline)", "Loopback test (offline)",
117 "Link test (on/offline)"
118};
Bruce Allanad680762008-03-28 09:15:03 -0700119#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700120
121static int e1000_get_settings(struct net_device *netdev,
122 struct ethtool_cmd *ecmd)
123{
124 struct e1000_adapter *adapter = netdev_priv(netdev);
125 struct e1000_hw *hw = &adapter->hw;
David Decotigny70739492011-04-27 18:32:40 +0000126 u32 speed;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700127
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700128 if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700129
130 ecmd->supported = (SUPPORTED_10baseT_Half |
131 SUPPORTED_10baseT_Full |
132 SUPPORTED_100baseT_Half |
133 SUPPORTED_100baseT_Full |
134 SUPPORTED_1000baseT_Full |
135 SUPPORTED_Autoneg |
136 SUPPORTED_TP);
137 if (hw->phy.type == e1000_phy_ife)
138 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
139 ecmd->advertising = ADVERTISED_TP;
140
141 if (hw->mac.autoneg == 1) {
142 ecmd->advertising |= ADVERTISED_Autoneg;
143 /* the e1000 autoneg seems to match ethtool nicely */
144 ecmd->advertising |= hw->phy.autoneg_advertised;
145 }
146
147 ecmd->port = PORT_TP;
148 ecmd->phy_address = hw->phy.addr;
149 ecmd->transceiver = XCVR_INTERNAL;
150
151 } else {
152 ecmd->supported = (SUPPORTED_1000baseT_Full |
153 SUPPORTED_FIBRE |
154 SUPPORTED_Autoneg);
155
156 ecmd->advertising = (ADVERTISED_1000baseT_Full |
157 ADVERTISED_FIBRE |
158 ADVERTISED_Autoneg);
159
160 ecmd->port = PORT_FIBRE;
161 ecmd->transceiver = XCVR_EXTERNAL;
162 }
163
David Decotigny70739492011-04-27 18:32:40 +0000164 speed = -1;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000165 ecmd->duplex = -1;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700166
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000167 if (netif_running(netdev)) {
168 if (netif_carrier_ok(netdev)) {
David Decotigny70739492011-04-27 18:32:40 +0000169 speed = adapter->link_speed;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000170 ecmd->duplex = adapter->link_duplex - 1;
171 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700172 } else {
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000173 u32 status = er32(STATUS);
174 if (status & E1000_STATUS_LU) {
175 if (status & E1000_STATUS_SPEED_1000)
David Decotigny70739492011-04-27 18:32:40 +0000176 speed = SPEED_1000;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000177 else if (status & E1000_STATUS_SPEED_100)
David Decotigny70739492011-04-27 18:32:40 +0000178 speed = SPEED_100;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000179 else
David Decotigny70739492011-04-27 18:32:40 +0000180 speed = SPEED_10;
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000181
182 if (status & E1000_STATUS_FD)
183 ecmd->duplex = DUPLEX_FULL;
184 else
185 ecmd->duplex = DUPLEX_HALF;
186 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700187 }
188
David Decotigny70739492011-04-27 18:32:40 +0000189 ethtool_cmd_speed_set(ecmd, speed);
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700190 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -0700191 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000192
193 /* MDI-X => 2; MDI =>1; Invalid =>0 */
194 if ((hw->phy.media_type == e1000_media_type_copper) &&
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000195 netif_carrier_ok(netdev))
Chaitanya Lala18760f12009-06-08 14:28:54 +0000196 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
197 ETH_TP_MDI;
198 else
199 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
200
Auke Kokbc7f75f2007-09-17 12:30:59 -0700201 return 0;
202}
203
David Decotigny14ad2512011-04-27 18:32:43 +0000204static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700205{
206 struct e1000_mac_info *mac = &adapter->hw.mac;
207
208 mac->autoneg = 0;
209
David Decotigny14ad2512011-04-27 18:32:43 +0000210 /* Make sure dplx is at most 1 bit and lsb of speed is not set
211 * for the switch() below to work */
212 if ((spd & 1) || (dplx & ~1))
213 goto err_inval;
214
Auke Kokbc7f75f2007-09-17 12:30:59 -0700215 /* Fiber NICs only allow 1000 gbps Full duplex */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700216 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
David Decotigny14ad2512011-04-27 18:32:43 +0000217 spd != SPEED_1000 &&
218 dplx != DUPLEX_FULL) {
219 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700220 }
221
David Decotigny14ad2512011-04-27 18:32:43 +0000222 switch (spd + dplx) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700223 case SPEED_10 + DUPLEX_HALF:
224 mac->forced_speed_duplex = ADVERTISE_10_HALF;
225 break;
226 case SPEED_10 + DUPLEX_FULL:
227 mac->forced_speed_duplex = ADVERTISE_10_FULL;
228 break;
229 case SPEED_100 + DUPLEX_HALF:
230 mac->forced_speed_duplex = ADVERTISE_100_HALF;
231 break;
232 case SPEED_100 + DUPLEX_FULL:
233 mac->forced_speed_duplex = ADVERTISE_100_FULL;
234 break;
235 case SPEED_1000 + DUPLEX_FULL:
236 mac->autoneg = 1;
237 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
238 break;
239 case SPEED_1000 + DUPLEX_HALF: /* not supported */
240 default:
David Decotigny14ad2512011-04-27 18:32:43 +0000241 goto err_inval;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700242 }
243 return 0;
David Decotigny14ad2512011-04-27 18:32:43 +0000244
245err_inval:
246 e_err("Unsupported Speed/Duplex configuration\n");
247 return -EINVAL;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700248}
249
250static int e1000_set_settings(struct net_device *netdev,
251 struct ethtool_cmd *ecmd)
252{
253 struct e1000_adapter *adapter = netdev_priv(netdev);
254 struct e1000_hw *hw = &adapter->hw;
255
Bruce Allanad680762008-03-28 09:15:03 -0700256 /*
257 * When SoL/IDER sessions are active, autoneg/speed/duplex
258 * cannot be changed
259 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700260 if (e1000_check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700261 e_err("Cannot change link characteristics when SoL/IDER is "
262 "active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700263 return -EINVAL;
264 }
265
266 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000267 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700268
269 if (ecmd->autoneg == AUTONEG_ENABLE) {
270 hw->mac.autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700271 if (hw->phy.media_type == e1000_media_type_fiber)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700272 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
273 ADVERTISED_FIBRE |
274 ADVERTISED_Autoneg;
275 else
276 hw->phy.autoneg_advertised = ecmd->advertising |
277 ADVERTISED_TP |
278 ADVERTISED_Autoneg;
279 ecmd->advertising = hw->phy.autoneg_advertised;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700280 if (adapter->fc_autoneg)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800281 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700282 } else {
David Decotigny25db0332011-04-27 18:32:39 +0000283 u32 speed = ethtool_cmd_speed(ecmd);
David Decotigny14ad2512011-04-27 18:32:43 +0000284 if (e1000_set_spd_dplx(adapter, speed, ecmd->duplex)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700285 clear_bit(__E1000_RESETTING, &adapter->state);
286 return -EINVAL;
287 }
288 }
289
290 /* reset the link */
291
292 if (netif_running(adapter->netdev)) {
293 e1000e_down(adapter);
294 e1000e_up(adapter);
295 } else {
296 e1000e_reset(adapter);
297 }
298
299 clear_bit(__E1000_RESETTING, &adapter->state);
300 return 0;
301}
302
303static void e1000_get_pauseparam(struct net_device *netdev,
304 struct ethtool_pauseparam *pause)
305{
306 struct e1000_adapter *adapter = netdev_priv(netdev);
307 struct e1000_hw *hw = &adapter->hw;
308
309 pause->autoneg =
310 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
311
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800312 if (hw->fc.current_mode == e1000_fc_rx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700313 pause->rx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800314 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700315 pause->tx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800316 } else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700317 pause->rx_pause = 1;
318 pause->tx_pause = 1;
319 }
320}
321
322static int e1000_set_pauseparam(struct net_device *netdev,
323 struct ethtool_pauseparam *pause)
324{
325 struct e1000_adapter *adapter = netdev_priv(netdev);
326 struct e1000_hw *hw = &adapter->hw;
327 int retval = 0;
328
329 adapter->fc_autoneg = pause->autoneg;
330
331 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000332 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700333
Auke Kokbc7f75f2007-09-17 12:30:59 -0700334 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800335 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700336 if (netif_running(adapter->netdev)) {
337 e1000e_down(adapter);
338 e1000e_up(adapter);
339 } else {
340 e1000e_reset(adapter);
341 }
342 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800343 if (pause->rx_pause && pause->tx_pause)
344 hw->fc.requested_mode = e1000_fc_full;
345 else if (pause->rx_pause && !pause->tx_pause)
346 hw->fc.requested_mode = e1000_fc_rx_pause;
347 else if (!pause->rx_pause && pause->tx_pause)
348 hw->fc.requested_mode = e1000_fc_tx_pause;
349 else if (!pause->rx_pause && !pause->tx_pause)
350 hw->fc.requested_mode = e1000_fc_none;
351
352 hw->fc.current_mode = hw->fc.requested_mode;
353
Bruce Allan945eb312009-10-28 18:28:30 +0000354 if (hw->phy.media_type == e1000_media_type_fiber) {
355 retval = hw->mac.ops.setup_link(hw);
356 /* implicit goto out */
357 } else {
358 retval = e1000e_force_mac_fc(hw);
359 if (retval)
360 goto out;
361 e1000e_set_fc_watermarks(hw);
362 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700363 }
364
Bruce Allan945eb312009-10-28 18:28:30 +0000365out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700366 clear_bit(__E1000_RESETTING, &adapter->state);
367 return retval;
368}
369
Auke Kokbc7f75f2007-09-17 12:30:59 -0700370static u32 e1000_get_msglevel(struct net_device *netdev)
371{
372 struct e1000_adapter *adapter = netdev_priv(netdev);
373 return adapter->msg_enable;
374}
375
376static void e1000_set_msglevel(struct net_device *netdev, u32 data)
377{
378 struct e1000_adapter *adapter = netdev_priv(netdev);
379 adapter->msg_enable = data;
380}
381
382static int e1000_get_regs_len(struct net_device *netdev)
383{
384#define E1000_REGS_LEN 32 /* overestimate */
385 return E1000_REGS_LEN * sizeof(u32);
386}
387
388static void e1000_get_regs(struct net_device *netdev,
389 struct ethtool_regs *regs, void *p)
390{
391 struct e1000_adapter *adapter = netdev_priv(netdev);
392 struct e1000_hw *hw = &adapter->hw;
393 u32 *regs_buff = p;
394 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700395
396 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
397
Sergei Shtylyovff938e42011-02-28 11:57:33 -0800398 regs->version = (1 << 24) | (adapter->pdev->revision << 16) |
399 adapter->pdev->device;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700400
401 regs_buff[0] = er32(CTRL);
402 regs_buff[1] = er32(STATUS);
403
404 regs_buff[2] = er32(RCTL);
405 regs_buff[3] = er32(RDLEN);
406 regs_buff[4] = er32(RDH);
407 regs_buff[5] = er32(RDT);
408 regs_buff[6] = er32(RDTR);
409
410 regs_buff[7] = er32(TCTL);
411 regs_buff[8] = er32(TDLEN);
412 regs_buff[9] = er32(TDH);
413 regs_buff[10] = er32(TDT);
414 regs_buff[11] = er32(TIDV);
415
416 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700417
418 /* ethtool doesn't use anything past this point, so all this
419 * code is likely legacy junk for apps that may or may not
420 * exist */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700421 if (hw->phy.type == e1000_phy_m88) {
422 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
423 regs_buff[13] = (u32)phy_data; /* cable length */
424 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
425 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
426 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
427 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
428 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
429 regs_buff[18] = regs_buff[13]; /* cable polarity */
430 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
431 regs_buff[20] = regs_buff[17]; /* polarity correction */
432 /* phy receive errors */
433 regs_buff[22] = adapter->phy_stats.receive_errors;
434 regs_buff[23] = regs_buff[13]; /* mdix mode */
435 }
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700436 regs_buff[21] = 0; /* was idle_errors */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700437 e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
438 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
439 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
440}
441
442static int e1000_get_eeprom_len(struct net_device *netdev)
443{
444 struct e1000_adapter *adapter = netdev_priv(netdev);
445 return adapter->hw.nvm.word_size * 2;
446}
447
448static int e1000_get_eeprom(struct net_device *netdev,
449 struct ethtool_eeprom *eeprom, u8 *bytes)
450{
451 struct e1000_adapter *adapter = netdev_priv(netdev);
452 struct e1000_hw *hw = &adapter->hw;
453 u16 *eeprom_buff;
454 int first_word;
455 int last_word;
456 int ret_val = 0;
457 u16 i;
458
459 if (eeprom->len == 0)
460 return -EINVAL;
461
462 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
463
464 first_word = eeprom->offset >> 1;
465 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
466
467 eeprom_buff = kmalloc(sizeof(u16) *
468 (last_word - first_word + 1), GFP_KERNEL);
469 if (!eeprom_buff)
470 return -ENOMEM;
471
472 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
473 ret_val = e1000_read_nvm(hw, first_word,
474 last_word - first_word + 1,
475 eeprom_buff);
476 } else {
477 for (i = 0; i < last_word - first_word + 1; i++) {
478 ret_val = e1000_read_nvm(hw, first_word + i, 1,
479 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800480 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700481 break;
482 }
483 }
484
Bruce Allane2434552008-11-21 17:02:41 -0800485 if (ret_val) {
486 /* a read error occurred, throw away the result */
Roel Kluin8528b012009-12-01 15:54:24 +0000487 memset(eeprom_buff, 0xff, sizeof(u16) *
488 (last_word - first_word + 1));
Bruce Allane2434552008-11-21 17:02:41 -0800489 } else {
490 /* Device's eeprom is always little-endian, word addressable */
491 for (i = 0; i < last_word - first_word + 1; i++)
492 le16_to_cpus(&eeprom_buff[i]);
493 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700494
495 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
496 kfree(eeprom_buff);
497
498 return ret_val;
499}
500
501static int e1000_set_eeprom(struct net_device *netdev,
502 struct ethtool_eeprom *eeprom, u8 *bytes)
503{
504 struct e1000_adapter *adapter = netdev_priv(netdev);
505 struct e1000_hw *hw = &adapter->hw;
506 u16 *eeprom_buff;
507 void *ptr;
508 int max_len;
509 int first_word;
510 int last_word;
511 int ret_val = 0;
512 u16 i;
513
514 if (eeprom->len == 0)
515 return -EOPNOTSUPP;
516
517 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
518 return -EFAULT;
519
Bruce Allan4a770352008-10-01 17:18:35 -0700520 if (adapter->flags & FLAG_READ_ONLY_NVM)
521 return -EINVAL;
522
Auke Kokbc7f75f2007-09-17 12:30:59 -0700523 max_len = hw->nvm.word_size * 2;
524
525 first_word = eeprom->offset >> 1;
526 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
527 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
528 if (!eeprom_buff)
529 return -ENOMEM;
530
531 ptr = (void *)eeprom_buff;
532
533 if (eeprom->offset & 1) {
534 /* need read/modify/write of first changed EEPROM word */
535 /* only the second byte of the word is being modified */
536 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
537 ptr++;
538 }
539 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0))
540 /* need read/modify/write of last changed EEPROM word */
541 /* only the first byte of the word is being modified */
542 ret_val = e1000_read_nvm(hw, last_word, 1,
543 &eeprom_buff[last_word - first_word]);
544
Bruce Allane2434552008-11-21 17:02:41 -0800545 if (ret_val)
546 goto out;
547
Auke Kokbc7f75f2007-09-17 12:30:59 -0700548 /* Device's eeprom is always little-endian, word addressable */
549 for (i = 0; i < last_word - first_word + 1; i++)
550 le16_to_cpus(&eeprom_buff[i]);
551
552 memcpy(ptr, bytes, eeprom->len);
553
554 for (i = 0; i < last_word - first_word + 1; i++)
555 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
556
557 ret_val = e1000_write_nvm(hw, first_word,
558 last_word - first_word + 1, eeprom_buff);
559
Bruce Allane2434552008-11-21 17:02:41 -0800560 if (ret_val)
561 goto out;
562
Bruce Allanad680762008-03-28 09:15:03 -0700563 /*
564 * Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800565 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700566 */
Bruce Allane2434552008-11-21 17:02:41 -0800567 if ((first_word <= NVM_CHECKSUM_REG) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +0000568 (hw->mac.type == e1000_82583) ||
569 (hw->mac.type == e1000_82574) ||
570 (hw->mac.type == e1000_82573))
Bruce Allane2434552008-11-21 17:02:41 -0800571 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700572
Bruce Allane2434552008-11-21 17:02:41 -0800573out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700574 kfree(eeprom_buff);
575 return ret_val;
576}
577
578static void e1000_get_drvinfo(struct net_device *netdev,
579 struct ethtool_drvinfo *drvinfo)
580{
581 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700582
Rick Jones612a94d2011-11-14 08:13:25 +0000583 strlcpy(drvinfo->driver, e1000e_driver_name,
584 sizeof(drvinfo->driver));
Bruce Allane0dc4f12011-01-06 14:29:50 +0000585 strncpy(drvinfo->version, e1000e_driver_version,
Rick Jones612a94d2011-11-14 08:13:25 +0000586 sizeof(drvinfo->version));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700587
Bruce Allanad680762008-03-28 09:15:03 -0700588 /*
589 * EEPROM image version # is reported as firmware version # for
590 * PCI-E controllers
591 */
Rick Jones612a94d2011-11-14 08:13:25 +0000592 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
593 "%d.%d-%d",
Bruce Allan84527592008-11-21 17:00:22 -0800594 (adapter->eeprom_vers & 0xF000) >> 12,
595 (adapter->eeprom_vers & 0x0FF0) >> 4,
596 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700597
Rick Jones612a94d2011-11-14 08:13:25 +0000598 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
599 sizeof(drvinfo->bus_info));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700600 drvinfo->regdump_len = e1000_get_regs_len(netdev);
601 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
602}
603
604static void e1000_get_ringparam(struct net_device *netdev,
605 struct ethtool_ringparam *ring)
606{
607 struct e1000_adapter *adapter = netdev_priv(netdev);
608 struct e1000_ring *tx_ring = adapter->tx_ring;
609 struct e1000_ring *rx_ring = adapter->rx_ring;
610
611 ring->rx_max_pending = E1000_MAX_RXD;
612 ring->tx_max_pending = E1000_MAX_TXD;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700613 ring->rx_pending = rx_ring->count;
614 ring->tx_pending = tx_ring->count;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700615}
616
617static int e1000_set_ringparam(struct net_device *netdev,
618 struct ethtool_ringparam *ring)
619{
620 struct e1000_adapter *adapter = netdev_priv(netdev);
621 struct e1000_ring *tx_ring, *tx_old;
622 struct e1000_ring *rx_ring, *rx_old;
623 int err;
624
625 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
626 return -EINVAL;
627
628 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000629 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700630
631 if (netif_running(adapter->netdev))
632 e1000e_down(adapter);
633
634 tx_old = adapter->tx_ring;
635 rx_old = adapter->rx_ring;
636
637 err = -ENOMEM;
Bruce Allan05b93212011-01-05 07:10:38 +0000638 tx_ring = kmemdup(tx_old, sizeof(struct e1000_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700639 if (!tx_ring)
640 goto err_alloc_tx;
641
Bruce Allan05b93212011-01-05 07:10:38 +0000642 rx_ring = kmemdup(rx_old, sizeof(struct e1000_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700643 if (!rx_ring)
644 goto err_alloc_rx;
645
646 adapter->tx_ring = tx_ring;
647 adapter->rx_ring = rx_ring;
648
649 rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
650 rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD));
651 rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
652
653 tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
654 tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
655 tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
656
657 if (netif_running(adapter->netdev)) {
658 /* Try to get new resources before deleting old */
659 err = e1000e_setup_rx_resources(adapter);
660 if (err)
661 goto err_setup_rx;
662 err = e1000e_setup_tx_resources(adapter);
663 if (err)
664 goto err_setup_tx;
665
Bruce Allanad680762008-03-28 09:15:03 -0700666 /*
667 * restore the old in order to free it,
668 * then add in the new
669 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700670 adapter->rx_ring = rx_old;
671 adapter->tx_ring = tx_old;
672 e1000e_free_rx_resources(adapter);
673 e1000e_free_tx_resources(adapter);
674 kfree(tx_old);
675 kfree(rx_old);
676 adapter->rx_ring = rx_ring;
677 adapter->tx_ring = tx_ring;
678 err = e1000e_up(adapter);
679 if (err)
680 goto err_setup;
681 }
682
683 clear_bit(__E1000_RESETTING, &adapter->state);
684 return 0;
685err_setup_tx:
686 e1000e_free_rx_resources(adapter);
687err_setup_rx:
688 adapter->rx_ring = rx_old;
689 adapter->tx_ring = tx_old;
690 kfree(rx_ring);
691err_alloc_rx:
692 kfree(tx_ring);
693err_alloc_tx:
694 e1000e_up(adapter);
695err_setup:
696 clear_bit(__E1000_RESETTING, &adapter->state);
697 return err;
698}
699
Bruce Allancef8c792008-04-02 13:48:23 -0700700static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
701 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800702{
Bruce Allancef8c792008-04-02 13:48:23 -0700703 u32 pat, val;
Bruce Allan64806412010-12-11 05:53:42 +0000704 static const u32 test[] = {
705 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Bruce Allancef8c792008-04-02 13:48:23 -0700706 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800707 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700708 (test[pat] & write));
709 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
710 if (val != (test[pat] & write & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700711 e_err("pattern test reg %04X failed: got 0x%08X "
712 "expected 0x%08X\n", reg + offset, val,
713 (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800714 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700715 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800716 }
717 }
Bruce Allancef8c792008-04-02 13:48:23 -0700718 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700719}
720
Joe Perches2a887192007-11-13 20:53:51 -0800721static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
722 int reg, u32 mask, u32 write)
723{
Bruce Allancef8c792008-04-02 13:48:23 -0700724 u32 val;
Joe Perches2a887192007-11-13 20:53:51 -0800725 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700726 val = __er32(&adapter->hw, reg);
727 if ((write & mask) != (val & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700728 e_err("set/check reg %04X test failed: got 0x%08X "
729 "expected 0x%08X\n", reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800730 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700731 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800732 }
Bruce Allancef8c792008-04-02 13:48:23 -0700733 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700734}
Bruce Allancef8c792008-04-02 13:48:23 -0700735#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
736 do { \
737 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
738 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800739 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700740#define REG_PATTERN_TEST(reg, mask, write) \
741 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800742
Bruce Allancef8c792008-04-02 13:48:23 -0700743#define REG_SET_AND_CHECK(reg, mask, write) \
744 do { \
745 if (reg_set_and_check(adapter, data, reg, mask, write)) \
746 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800747 } while (0)
748
Auke Kokbc7f75f2007-09-17 12:30:59 -0700749static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
750{
751 struct e1000_hw *hw = &adapter->hw;
752 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700753 u32 value;
754 u32 before;
755 u32 after;
756 u32 i;
757 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000758 u32 mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700759
Bruce Allanad680762008-03-28 09:15:03 -0700760 /*
761 * The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700762 * Some bits that get toggled are ignored.
763 */
764 switch (mac->type) {
765 /* there are several bits on newer hardware that are r/w */
766 case e1000_82571:
767 case e1000_82572:
768 case e1000_80003es2lan:
769 toggle = 0x7FFFF3FF;
770 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000771 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700772 toggle = 0x7FFFF033;
773 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700774 }
775
776 before = er32(STATUS);
777 value = (er32(STATUS) & toggle);
778 ew32(STATUS, toggle);
779 after = er32(STATUS) & toggle;
780 if (value != after) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700781 e_err("failed STATUS register test got: 0x%08X expected: "
782 "0x%08X\n", after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700783 *data = 1;
784 return 1;
785 }
786 /* restore previous status */
787 ew32(STATUS, before);
788
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700789 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700790 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
791 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
792 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
793 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
794 }
795
796 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
797 REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
798 REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF);
799 REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF);
800 REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF);
801 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
802 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
803 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
804 REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
805 REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF);
806
807 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
808
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700809 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700810 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
811 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
812
Auke Kok86582512007-10-04 15:00:08 -0700813 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
814 REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700815 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700816 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
817 REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
818 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000819 mask = 0x8003FFFF;
820 switch (mac->type) {
821 case e1000_ich10lan:
822 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000823 case e1000_pch2lan:
Bruce Allana4f58f52009-06-02 11:29:18 +0000824 mask |= (1 << 18);
825 break;
826 default:
827 break;
828 }
Auke Kok86582512007-10-04 15:00:08 -0700829 for (i = 0; i < mac->rar_entry_count; i++)
830 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
Bruce Allana4f58f52009-06-02 11:29:18 +0000831 mask, 0xFFFFFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700832
833 for (i = 0; i < mac->mta_reg_count; i++)
834 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
835
836 *data = 0;
837 return 0;
838}
839
840static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
841{
842 u16 temp;
843 u16 checksum = 0;
844 u16 i;
845
846 *data = 0;
847 /* Read and add up the contents of the EEPROM */
848 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
849 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
850 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800851 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700852 }
853 checksum += temp;
854 }
855
856 /* If Checksum is not Correct return error else test passed */
857 if ((checksum != (u16) NVM_SUM) && !(*data))
858 *data = 2;
859
860 return *data;
861}
862
863static irqreturn_t e1000_test_intr(int irq, void *data)
864{
865 struct net_device *netdev = (struct net_device *) data;
866 struct e1000_adapter *adapter = netdev_priv(netdev);
867 struct e1000_hw *hw = &adapter->hw;
868
869 adapter->test_icr |= er32(ICR);
870
871 return IRQ_HANDLED;
872}
873
874static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
875{
876 struct net_device *netdev = adapter->netdev;
877 struct e1000_hw *hw = &adapter->hw;
878 u32 mask;
879 u32 shared_int = 1;
880 u32 irq = adapter->pdev->irq;
881 int i;
Bruce Allan4662e822008-08-26 18:37:06 -0700882 int ret_val = 0;
883 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700884
885 *data = 0;
886
Bruce Allan4662e822008-08-26 18:37:06 -0700887 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
888 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
889 int_mode = adapter->int_mode;
890 e1000e_reset_interrupt_capability(adapter);
891 adapter->int_mode = E1000E_INT_MODE_LEGACY;
892 e1000e_set_interrupt_capability(adapter);
893 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700894 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800895 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700896 netdev)) {
897 shared_int = 0;
Joe Perchesa0607fd2009-11-18 23:29:17 -0800898 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700899 netdev->name, netdev)) {
900 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700901 ret_val = -1;
902 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700903 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700904 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700905
906 /* Disable all the interrupts */
907 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000908 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000909 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700910
911 /* Test each interrupt */
912 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700913 /* Interrupt to test */
914 mask = 1 << i;
915
Bruce Allanf4187b52008-08-26 18:36:50 -0700916 if (adapter->flags & FLAG_IS_ICH) {
917 switch (mask) {
918 case E1000_ICR_RXSEQ:
919 continue;
920 case 0x00000100:
921 if (adapter->hw.mac.type == e1000_ich8lan ||
922 adapter->hw.mac.type == e1000_ich9lan)
923 continue;
924 break;
925 default:
926 break;
927 }
928 }
929
Auke Kokbc7f75f2007-09-17 12:30:59 -0700930 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700931 /*
932 * Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700933 * the cause register and then force the same
934 * interrupt and see if one gets posted. If
935 * an interrupt was posted to the bus, the
936 * test failed.
937 */
938 adapter->test_icr = 0;
939 ew32(IMC, mask);
940 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000941 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000942 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700943
944 if (adapter->test_icr & mask) {
945 *data = 3;
946 break;
947 }
948 }
949
Bruce Allanad680762008-03-28 09:15:03 -0700950 /*
951 * Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700952 * the cause register and then force the same
953 * interrupt and see if one gets posted. If
954 * an interrupt was not posted to the bus, the
955 * test failed.
956 */
957 adapter->test_icr = 0;
958 ew32(IMS, mask);
959 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000960 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000961 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700962
963 if (!(adapter->test_icr & mask)) {
964 *data = 4;
965 break;
966 }
967
968 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700969 /*
970 * Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700971 * the cause register and then force the other
972 * interrupts and see if any get posted. If
973 * an interrupt was posted to the bus, the
974 * test failed.
975 */
976 adapter->test_icr = 0;
977 ew32(IMC, ~mask & 0x00007FFF);
978 ew32(ICS, ~mask & 0x00007FFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000979 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000980 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700981
982 if (adapter->test_icr) {
983 *data = 5;
984 break;
985 }
986 }
987 }
988
989 /* Disable all the interrupts */
990 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000991 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000992 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700993
994 /* Unhook test interrupt handler */
995 free_irq(irq, netdev);
996
Bruce Allan4662e822008-08-26 18:37:06 -0700997out:
998 if (int_mode == E1000E_INT_MODE_MSIX) {
999 e1000e_reset_interrupt_capability(adapter);
1000 adapter->int_mode = int_mode;
1001 e1000e_set_interrupt_capability(adapter);
1002 }
1003
1004 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001005}
1006
1007static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1008{
1009 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1010 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1011 struct pci_dev *pdev = adapter->pdev;
1012 int i;
1013
1014 if (tx_ring->desc && tx_ring->buffer_info) {
1015 for (i = 0; i < tx_ring->count; i++) {
1016 if (tx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001017 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001018 tx_ring->buffer_info[i].dma,
1019 tx_ring->buffer_info[i].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001020 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001021 if (tx_ring->buffer_info[i].skb)
1022 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1023 }
1024 }
1025
1026 if (rx_ring->desc && rx_ring->buffer_info) {
1027 for (i = 0; i < rx_ring->count; i++) {
1028 if (rx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001029 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001030 rx_ring->buffer_info[i].dma,
Nick Nunley0be3f552010-04-27 13:09:05 +00001031 2048, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001032 if (rx_ring->buffer_info[i].skb)
1033 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1034 }
1035 }
1036
1037 if (tx_ring->desc) {
1038 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1039 tx_ring->dma);
1040 tx_ring->desc = NULL;
1041 }
1042 if (rx_ring->desc) {
1043 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1044 rx_ring->dma);
1045 rx_ring->desc = NULL;
1046 }
1047
1048 kfree(tx_ring->buffer_info);
1049 tx_ring->buffer_info = NULL;
1050 kfree(rx_ring->buffer_info);
1051 rx_ring->buffer_info = NULL;
1052}
1053
1054static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1055{
1056 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1057 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1058 struct pci_dev *pdev = adapter->pdev;
1059 struct e1000_hw *hw = &adapter->hw;
1060 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001061 int i;
1062 int ret_val;
1063
1064 /* Setup Tx descriptor ring and Tx buffers */
1065
1066 if (!tx_ring->count)
1067 tx_ring->count = E1000_DEFAULT_TXD;
1068
Bruce Allancef8c792008-04-02 13:48:23 -07001069 tx_ring->buffer_info = kcalloc(tx_ring->count,
1070 sizeof(struct e1000_buffer),
1071 GFP_KERNEL);
1072 if (!(tx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001073 ret_val = 1;
1074 goto err_nomem;
1075 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001076
1077 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1078 tx_ring->size = ALIGN(tx_ring->size, 4096);
1079 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1080 &tx_ring->dma, GFP_KERNEL);
1081 if (!tx_ring->desc) {
1082 ret_val = 2;
1083 goto err_nomem;
1084 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001085 tx_ring->next_to_use = 0;
1086 tx_ring->next_to_clean = 0;
1087
Bruce Allancef8c792008-04-02 13:48:23 -07001088 ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001089 ew32(TDBAH, ((u64) tx_ring->dma >> 32));
Bruce Allancef8c792008-04-02 13:48:23 -07001090 ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001091 ew32(TDH, 0);
1092 ew32(TDT, 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001093 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1094 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1095 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001096
1097 for (i = 0; i < tx_ring->count; i++) {
1098 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1099 struct sk_buff *skb;
1100 unsigned int skb_size = 1024;
1101
1102 skb = alloc_skb(skb_size, GFP_KERNEL);
1103 if (!skb) {
1104 ret_val = 3;
1105 goto err_nomem;
1106 }
1107 skb_put(skb, skb_size);
1108 tx_ring->buffer_info[i].skb = skb;
1109 tx_ring->buffer_info[i].length = skb->len;
1110 tx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001111 dma_map_single(&pdev->dev, skb->data, skb->len,
1112 DMA_TO_DEVICE);
1113 if (dma_mapping_error(&pdev->dev,
1114 tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001115 ret_val = 4;
1116 goto err_nomem;
1117 }
Bruce Allancef8c792008-04-02 13:48:23 -07001118 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001119 tx_desc->lower.data = cpu_to_le32(skb->len);
1120 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1121 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001122 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001123 tx_desc->upper.data = 0;
1124 }
1125
1126 /* Setup Rx descriptor ring and Rx buffers */
1127
1128 if (!rx_ring->count)
1129 rx_ring->count = E1000_DEFAULT_RXD;
1130
Bruce Allancef8c792008-04-02 13:48:23 -07001131 rx_ring->buffer_info = kcalloc(rx_ring->count,
1132 sizeof(struct e1000_buffer),
1133 GFP_KERNEL);
1134 if (!(rx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001135 ret_val = 5;
1136 goto err_nomem;
1137 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001138
Bruce Allan5f450212011-07-22 06:21:46 +00001139 rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001140 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1141 &rx_ring->dma, GFP_KERNEL);
1142 if (!rx_ring->desc) {
1143 ret_val = 6;
1144 goto err_nomem;
1145 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001146 rx_ring->next_to_use = 0;
1147 rx_ring->next_to_clean = 0;
1148
1149 rctl = er32(RCTL);
Bruce Allan7f99ae62011-07-22 06:21:35 +00001150 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
1151 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001152 ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
1153 ew32(RDBAH, ((u64) rx_ring->dma >> 32));
1154 ew32(RDLEN, rx_ring->size);
1155 ew32(RDH, 0);
1156 ew32(RDT, 0);
1157 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allancef8c792008-04-02 13:48:23 -07001158 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1159 E1000_RCTL_SBP | E1000_RCTL_SECRC |
Auke Kokbc7f75f2007-09-17 12:30:59 -07001160 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1161 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1162 ew32(RCTL, rctl);
1163
1164 for (i = 0; i < rx_ring->count; i++) {
Bruce Allan5f450212011-07-22 06:21:46 +00001165 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001166 struct sk_buff *skb;
1167
1168 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1169 if (!skb) {
1170 ret_val = 7;
1171 goto err_nomem;
1172 }
1173 skb_reserve(skb, NET_IP_ALIGN);
1174 rx_ring->buffer_info[i].skb = skb;
1175 rx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001176 dma_map_single(&pdev->dev, skb->data, 2048,
1177 DMA_FROM_DEVICE);
1178 if (dma_mapping_error(&pdev->dev,
1179 rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001180 ret_val = 8;
1181 goto err_nomem;
1182 }
Bruce Allan5f450212011-07-22 06:21:46 +00001183 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1184 rx_desc->read.buffer_addr =
1185 cpu_to_le64(rx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001186 memset(skb->data, 0x00, skb->len);
1187 }
1188
1189 return 0;
1190
1191err_nomem:
1192 e1000_free_desc_rings(adapter);
1193 return ret_val;
1194}
1195
1196static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1197{
1198 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1199 e1e_wphy(&adapter->hw, 29, 0x001F);
1200 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1201 e1e_wphy(&adapter->hw, 29, 0x001A);
1202 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1203}
1204
1205static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1206{
1207 struct e1000_hw *hw = &adapter->hw;
1208 u32 ctrl_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001209 u16 phy_reg = 0;
Bruce Allancbd006c2010-11-24 06:01:30 +00001210 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001211
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001212 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001213
Bruce Allan3af50482010-06-16 13:25:55 +00001214 if (hw->phy.type == e1000_phy_ife) {
1215 /* force 100, set loopback */
1216 e1e_wphy(hw, PHY_CONTROL, 0x6100);
Bruce Allanbb436b22009-11-20 23:24:11 +00001217
Bruce Allan3af50482010-06-16 13:25:55 +00001218 /* Now set up the MAC to the same speed/duplex as the PHY. */
1219 ctrl_reg = er32(CTRL);
1220 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1221 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1222 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1223 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1224 E1000_CTRL_FD); /* Force Duplex to FULL */
1225
1226 ew32(CTRL, ctrl_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001227 e1e_flush();
Bruce Allan3af50482010-06-16 13:25:55 +00001228 udelay(500);
1229
1230 return 0;
1231 }
1232
1233 /* Specific PHY configuration for loopback */
1234 switch (hw->phy.type) {
1235 case e1000_phy_m88:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001236 /* Auto-MDI/MDIX Off */
1237 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1238 /* reset to update Auto-MDI/MDIX */
1239 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1240 /* autoneg off */
1241 e1e_wphy(hw, PHY_CONTROL, 0x8140);
Bruce Allan3af50482010-06-16 13:25:55 +00001242 break;
1243 case e1000_phy_gg82563:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001244 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
Bruce Allancef8c792008-04-02 13:48:23 -07001245 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001246 case e1000_phy_bm:
1247 /* Set Default MAC Interface speed to 1GB */
1248 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1249 phy_reg &= ~0x0007;
1250 phy_reg |= 0x006;
1251 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1252 /* Assert SW reset for above settings to take effect */
1253 e1000e_commit_phy(hw);
1254 mdelay(1);
1255 /* Force Full Duplex */
1256 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1257 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1258 /* Set Link Up (in force link) */
1259 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1260 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1261 /* Force Link */
1262 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1263 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1264 /* Set Early Link Enable */
1265 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1266 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
Bruce Allan3af50482010-06-16 13:25:55 +00001267 break;
1268 case e1000_phy_82577:
1269 case e1000_phy_82578:
1270 /* Workaround: K1 must be disabled for stable 1Gbps operation */
Bruce Allancbd006c2010-11-24 06:01:30 +00001271 ret_val = hw->phy.ops.acquire(hw);
1272 if (ret_val) {
1273 e_err("Cannot setup 1Gbps loopback.\n");
1274 return ret_val;
1275 }
Bruce Allan3af50482010-06-16 13:25:55 +00001276 e1000_configure_k1_ich8lan(hw, false);
Bruce Allancbd006c2010-11-24 06:01:30 +00001277 hw->phy.ops.release(hw);
Bruce Allan3af50482010-06-16 13:25:55 +00001278 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001279 case e1000_phy_82579:
1280 /* Disable PHY energy detect power down */
1281 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1282 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
1283 /* Disable full chip energy detect */
1284 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1285 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1286 /* Enable loopback on the PHY */
1287#define I82577_PHY_LBK_CTRL 19
1288 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1289 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001290 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001291 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001292 }
1293
Bruce Allan3af50482010-06-16 13:25:55 +00001294 /* force 1000, set loopback */
1295 e1e_wphy(hw, PHY_CONTROL, 0x4140);
1296 mdelay(250);
1297
1298 /* Now set up the MAC to the same speed/duplex as the PHY. */
1299 ctrl_reg = er32(CTRL);
1300 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1301 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1302 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1303 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1304 E1000_CTRL_FD); /* Force Duplex to FULL */
1305
1306 if (adapter->flags & FLAG_IS_ICH)
1307 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1308
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001309 if (hw->phy.media_type == e1000_media_type_copper &&
1310 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001311 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1312 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001313 /*
1314 * Set the ILOS bit on the fiber Nic if half duplex link is
1315 * detected.
1316 */
Bruce Allan90da0662011-01-06 07:02:53 +00001317 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001318 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1319 }
1320
1321 ew32(CTRL, ctrl_reg);
1322
Bruce Allanad680762008-03-28 09:15:03 -07001323 /*
1324 * Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001325 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1326 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001327 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001328 e1000_phy_disable_receiver(adapter);
1329
1330 udelay(500);
1331
1332 return 0;
1333}
1334
1335static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1336{
1337 struct e1000_hw *hw = &adapter->hw;
1338 u32 ctrl = er32(CTRL);
1339 int link = 0;
1340
1341 /* special requirements for 82571/82572 fiber adapters */
1342
Bruce Allanad680762008-03-28 09:15:03 -07001343 /*
1344 * jump through hoops to make sure link is up because serdes
1345 * link is hardwired up
1346 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001347 ctrl |= E1000_CTRL_SLU;
1348 ew32(CTRL, ctrl);
1349
1350 /* disable autoneg */
1351 ctrl = er32(TXCW);
1352 ctrl &= ~(1 << 31);
1353 ew32(TXCW, ctrl);
1354
1355 link = (er32(STATUS) & E1000_STATUS_LU);
1356
1357 if (!link) {
1358 /* set invert loss of signal */
1359 ctrl = er32(CTRL);
1360 ctrl |= E1000_CTRL_ILOS;
1361 ew32(CTRL, ctrl);
1362 }
1363
Bruce Allanad680762008-03-28 09:15:03 -07001364 /*
1365 * special write to serdes control register to enable SerDes analog
1366 * loopback
1367 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001368#define E1000_SERDES_LB_ON 0x410
1369 ew32(SCTL, E1000_SERDES_LB_ON);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001370 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001371 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001372
1373 return 0;
1374}
1375
1376/* only call this for fiber/serdes connections to es2lan */
1377static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1378{
1379 struct e1000_hw *hw = &adapter->hw;
1380 u32 ctrlext = er32(CTRL_EXT);
1381 u32 ctrl = er32(CTRL);
1382
Bruce Allanad680762008-03-28 09:15:03 -07001383 /*
1384 * save CTRL_EXT to restore later, reuse an empty variable (unused
1385 * on mac_type 80003es2lan)
1386 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001387 adapter->tx_fifo_head = ctrlext;
1388
1389 /* clear the serdes mode bits, putting the device into mac loopback */
1390 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1391 ew32(CTRL_EXT, ctrlext);
1392
1393 /* force speed to 1000/FD, link up */
1394 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1395 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1396 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1397 ew32(CTRL, ctrl);
1398
1399 /* set mac loopback */
1400 ctrl = er32(RCTL);
1401 ctrl |= E1000_RCTL_LBM_MAC;
1402 ew32(RCTL, ctrl);
1403
1404 /* set testing mode parameters (no need to reset later) */
1405#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1406#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1407 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001408 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001409
1410 return 0;
1411}
1412
1413static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1414{
1415 struct e1000_hw *hw = &adapter->hw;
1416 u32 rctl;
1417
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001418 if (hw->phy.media_type == e1000_media_type_fiber ||
1419 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001420 switch (hw->mac.type) {
1421 case e1000_80003es2lan:
1422 return e1000_set_es2lan_mac_loopback(adapter);
1423 break;
1424 case e1000_82571:
1425 case e1000_82572:
1426 return e1000_set_82571_fiber_loopback(adapter);
1427 break;
1428 default:
1429 rctl = er32(RCTL);
1430 rctl |= E1000_RCTL_LBM_TCVR;
1431 ew32(RCTL, rctl);
1432 return 0;
1433 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001434 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001435 return e1000_integrated_phy_loopback(adapter);
1436 }
1437
1438 return 7;
1439}
1440
1441static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1442{
1443 struct e1000_hw *hw = &adapter->hw;
1444 u32 rctl;
1445 u16 phy_reg;
1446
1447 rctl = er32(RCTL);
1448 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1449 ew32(RCTL, rctl);
1450
1451 switch (hw->mac.type) {
1452 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001453 if (hw->phy.media_type == e1000_media_type_fiber ||
1454 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001455 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001456 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001457 adapter->tx_fifo_head = 0;
1458 }
1459 /* fall through */
1460 case e1000_82571:
1461 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001462 if (hw->phy.media_type == e1000_media_type_fiber ||
1463 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001464#define E1000_SERDES_LB_OFF 0x400
1465 ew32(SCTL, E1000_SERDES_LB_OFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001466 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001467 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001468 break;
1469 }
1470 /* Fall Through */
1471 default:
1472 hw->mac.autoneg = 1;
1473 if (hw->phy.type == e1000_phy_gg82563)
1474 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1475 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1476 if (phy_reg & MII_CR_LOOPBACK) {
1477 phy_reg &= ~MII_CR_LOOPBACK;
1478 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1479 e1000e_commit_phy(hw);
1480 }
1481 break;
1482 }
1483}
1484
1485static void e1000_create_lbtest_frame(struct sk_buff *skb,
1486 unsigned int frame_size)
1487{
1488 memset(skb->data, 0xFF, frame_size);
1489 frame_size &= ~1;
1490 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1491 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1492 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1493}
1494
1495static int e1000_check_lbtest_frame(struct sk_buff *skb,
1496 unsigned int frame_size)
1497{
1498 frame_size &= ~1;
1499 if (*(skb->data + 3) == 0xFF)
1500 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1501 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1502 return 0;
1503 return 13;
1504}
1505
1506static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1507{
1508 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1509 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1510 struct pci_dev *pdev = adapter->pdev;
1511 struct e1000_hw *hw = &adapter->hw;
1512 int i, j, k, l;
1513 int lc;
1514 int good_cnt;
1515 int ret_val = 0;
1516 unsigned long time;
1517
1518 ew32(RDT, rx_ring->count - 1);
1519
Bruce Allanad680762008-03-28 09:15:03 -07001520 /*
1521 * Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001522 * The idea is to wrap the largest ring a number of times using 64
1523 * send/receive pairs during each loop
1524 */
1525
1526 if (rx_ring->count <= tx_ring->count)
1527 lc = ((tx_ring->count / 64) * 2) + 1;
1528 else
1529 lc = ((rx_ring->count / 64) * 2) + 1;
1530
1531 k = 0;
1532 l = 0;
1533 for (j = 0; j <= lc; j++) { /* loop count loop */
1534 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001535 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1536 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001537 dma_sync_single_for_device(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001538 tx_ring->buffer_info[k].dma,
1539 tx_ring->buffer_info[k].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001540 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001541 k++;
1542 if (k == tx_ring->count)
1543 k = 0;
1544 }
1545 ew32(TDT, k);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001546 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001547 msleep(200);
1548 time = jiffies; /* set the start time for the receive */
1549 good_cnt = 0;
1550 do { /* receive the sent packets */
Nick Nunley0be3f552010-04-27 13:09:05 +00001551 dma_sync_single_for_cpu(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001552 rx_ring->buffer_info[l].dma, 2048,
Nick Nunley0be3f552010-04-27 13:09:05 +00001553 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001554
1555 ret_val = e1000_check_lbtest_frame(
1556 rx_ring->buffer_info[l].skb, 1024);
1557 if (!ret_val)
1558 good_cnt++;
1559 l++;
1560 if (l == rx_ring->count)
1561 l = 0;
Bruce Allanad680762008-03-28 09:15:03 -07001562 /*
1563 * time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001564 * enough time to complete the receives, if it's
1565 * exceeded, break and error off
1566 */
1567 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1568 if (good_cnt != 64) {
1569 ret_val = 13; /* ret_val is the same as mis-compare */
1570 break;
1571 }
Bruce Allancef8c792008-04-02 13:48:23 -07001572 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001573 ret_val = 14; /* error code for time out error */
1574 break;
1575 }
1576 } /* end loop count loop */
1577 return ret_val;
1578}
1579
1580static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1581{
Bruce Allanad680762008-03-28 09:15:03 -07001582 /*
1583 * PHY loopback cannot be performed if SoL/IDER
1584 * sessions are active
1585 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001586 if (e1000_check_reset_block(&adapter->hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001587 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001588 *data = 0;
1589 goto out;
1590 }
1591
1592 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001593 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001594 goto out;
1595
1596 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001597 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001598 goto err_loopback;
1599
1600 *data = e1000_run_loopback_test(adapter);
1601 e1000_loopback_cleanup(adapter);
1602
1603err_loopback:
1604 e1000_free_desc_rings(adapter);
1605out:
1606 return *data;
1607}
1608
1609static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1610{
1611 struct e1000_hw *hw = &adapter->hw;
1612
1613 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001614 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001615 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001616 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001617
Bruce Allanad680762008-03-28 09:15:03 -07001618 /*
1619 * On some blade server designs, link establishment
1620 * could take as long as 2-3 minutes
1621 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001622 do {
1623 hw->mac.ops.check_for_link(hw);
1624 if (hw->mac.serdes_has_link)
1625 return *data;
1626 msleep(20);
1627 } while (i++ < 3750);
1628
1629 *data = 1;
1630 } else {
1631 hw->mac.ops.check_for_link(hw);
1632 if (hw->mac.autoneg)
Bruce Allan5661aeb2011-02-25 06:36:25 +00001633 /*
1634 * On some Phy/switch combinations, link establishment
1635 * can take a few seconds more than expected.
1636 */
1637 msleep(5000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001638
Bruce Allan5661aeb2011-02-25 06:36:25 +00001639 if (!(er32(STATUS) & E1000_STATUS_LU))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001640 *data = 1;
1641 }
1642 return *data;
1643}
1644
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001645static int e1000e_get_sset_count(struct net_device *netdev, int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001646{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001647 switch (sset) {
1648 case ETH_SS_TEST:
1649 return E1000_TEST_LEN;
1650 case ETH_SS_STATS:
1651 return E1000_STATS_LEN;
1652 default:
1653 return -EOPNOTSUPP;
1654 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001655}
1656
1657static void e1000_diag_test(struct net_device *netdev,
1658 struct ethtool_test *eth_test, u64 *data)
1659{
1660 struct e1000_adapter *adapter = netdev_priv(netdev);
1661 u16 autoneg_advertised;
1662 u8 forced_speed_duplex;
1663 u8 autoneg;
1664 bool if_running = netif_running(netdev);
1665
1666 set_bit(__E1000_TESTING, &adapter->state);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001667
1668 if (!if_running) {
1669 /* Get control of and reset hardware */
1670 if (adapter->flags & FLAG_HAS_AMT)
1671 e1000e_get_hw_control(adapter);
1672
1673 e1000e_power_up_phy(adapter);
1674
1675 adapter->hw.phy.autoneg_wait_to_complete = 1;
1676 e1000e_reset(adapter);
1677 adapter->hw.phy.autoneg_wait_to_complete = 0;
1678 }
1679
Auke Kokbc7f75f2007-09-17 12:30:59 -07001680 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1681 /* Offline tests */
1682
1683 /* save speed, duplex, autoneg settings */
1684 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1685 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1686 autoneg = adapter->hw.mac.autoneg;
1687
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001688 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001689
Auke Kokbc7f75f2007-09-17 12:30:59 -07001690 if (if_running)
1691 /* indicate we're in test mode */
1692 dev_close(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001693
1694 if (e1000_reg_test(adapter, &data[0]))
1695 eth_test->flags |= ETH_TEST_FL_FAILED;
1696
1697 e1000e_reset(adapter);
1698 if (e1000_eeprom_test(adapter, &data[1]))
1699 eth_test->flags |= ETH_TEST_FL_FAILED;
1700
1701 e1000e_reset(adapter);
1702 if (e1000_intr_test(adapter, &data[2]))
1703 eth_test->flags |= ETH_TEST_FL_FAILED;
1704
1705 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001706 if (e1000_loopback_test(adapter, &data[3]))
1707 eth_test->flags |= ETH_TEST_FL_FAILED;
1708
Auke Kokbc7f75f2007-09-17 12:30:59 -07001709 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001710 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001711 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001712 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001713
Carolyn Wybornyc6ce3852010-10-15 17:35:31 +00001714 if (e1000_link_test(adapter, &data[4]))
1715 eth_test->flags |= ETH_TEST_FL_FAILED;
1716
1717 /* restore speed, duplex, autoneg settings */
1718 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1719 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1720 adapter->hw.mac.autoneg = autoneg;
1721 e1000e_reset(adapter);
1722
Auke Kokbc7f75f2007-09-17 12:30:59 -07001723 clear_bit(__E1000_TESTING, &adapter->state);
1724 if (if_running)
1725 dev_open(netdev);
1726 } else {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001727 /* Online tests */
Bruce Allan11b08be2010-05-10 14:59:31 +00001728
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001729 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001730
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001731 /* register, eeprom, intr and loopback tests not run online */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001732 data[0] = 0;
1733 data[1] = 0;
1734 data[2] = 0;
1735 data[3] = 0;
1736
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001737 if (e1000_link_test(adapter, &data[4]))
1738 eth_test->flags |= ETH_TEST_FL_FAILED;
Bruce Allan11b08be2010-05-10 14:59:31 +00001739
Auke Kokbc7f75f2007-09-17 12:30:59 -07001740 clear_bit(__E1000_TESTING, &adapter->state);
1741 }
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001742
1743 if (!if_running) {
1744 e1000e_reset(adapter);
1745
1746 if (adapter->flags & FLAG_HAS_AMT)
1747 e1000e_release_hw_control(adapter);
1748 }
1749
Auke Kokbc7f75f2007-09-17 12:30:59 -07001750 msleep_interruptible(4 * 1000);
1751}
1752
1753static void e1000_get_wol(struct net_device *netdev,
1754 struct ethtool_wolinfo *wol)
1755{
1756 struct e1000_adapter *adapter = netdev_priv(netdev);
1757
1758 wol->supported = 0;
1759 wol->wolopts = 0;
1760
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001761 if (!(adapter->flags & FLAG_HAS_WOL) ||
1762 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001763 return;
1764
1765 wol->supported = WAKE_UCAST | WAKE_MCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001766 WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001767
1768 /* apply any specific unsupported masks here */
1769 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1770 wol->supported &= ~WAKE_UCAST;
1771
1772 if (adapter->wol & E1000_WUFC_EX)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001773 e_err("Interface does not support directed (unicast) "
1774 "frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001775 }
1776
1777 if (adapter->wol & E1000_WUFC_EX)
1778 wol->wolopts |= WAKE_UCAST;
1779 if (adapter->wol & E1000_WUFC_MC)
1780 wol->wolopts |= WAKE_MCAST;
1781 if (adapter->wol & E1000_WUFC_BC)
1782 wol->wolopts |= WAKE_BCAST;
1783 if (adapter->wol & E1000_WUFC_MAG)
1784 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001785 if (adapter->wol & E1000_WUFC_LNKC)
1786 wol->wolopts |= WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001787}
1788
Bruce Allan4a29e152011-03-04 09:07:01 +00001789static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001790{
1791 struct e1000_adapter *adapter = netdev_priv(netdev);
1792
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001793 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001794 !device_can_wakeup(&adapter->pdev->dev) ||
1795 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001796 WAKE_MAGIC | WAKE_PHY)))
Bruce Allan1fbfca32009-11-20 23:22:01 +00001797 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001798
1799 /* these settings will always override what we currently have */
1800 adapter->wol = 0;
1801
1802 if (wol->wolopts & WAKE_UCAST)
1803 adapter->wol |= E1000_WUFC_EX;
1804 if (wol->wolopts & WAKE_MCAST)
1805 adapter->wol |= E1000_WUFC_MC;
1806 if (wol->wolopts & WAKE_BCAST)
1807 adapter->wol |= E1000_WUFC_BC;
1808 if (wol->wolopts & WAKE_MAGIC)
1809 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001810 if (wol->wolopts & WAKE_PHY)
1811 adapter->wol |= E1000_WUFC_LNKC;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001812
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001813 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1814
Auke Kokbc7f75f2007-09-17 12:30:59 -07001815 return 0;
1816}
1817
Bruce Allandbf80dc2011-04-16 00:34:40 +00001818static int e1000_set_phys_id(struct net_device *netdev,
1819 enum ethtool_phys_id_state state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001820{
1821 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001822 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001823
Bruce Allandbf80dc2011-04-16 00:34:40 +00001824 switch (state) {
1825 case ETHTOOL_ID_ACTIVE:
1826 if (!hw->mac.ops.blink_led)
1827 return 2; /* cycle on/off twice per second */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001828
Bruce Allandbf80dc2011-04-16 00:34:40 +00001829 hw->mac.ops.blink_led(hw);
1830 break;
1831
1832 case ETHTOOL_ID_INACTIVE:
Bruce Allan4662e822008-08-26 18:37:06 -07001833 if (hw->phy.type == e1000_phy_ife)
1834 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001835 hw->mac.ops.led_off(hw);
1836 hw->mac.ops.cleanup_led(hw);
1837 break;
1838
1839 case ETHTOOL_ID_ON:
1840 adapter->hw.mac.ops.led_on(&adapter->hw);
1841 break;
1842
1843 case ETHTOOL_ID_OFF:
1844 adapter->hw.mac.ops.led_off(&adapter->hw);
1845 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001846 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001847 return 0;
1848}
1849
Auke Kokde5b3072008-04-23 11:09:08 -07001850static int e1000_get_coalesce(struct net_device *netdev,
1851 struct ethtool_coalesce *ec)
1852{
1853 struct e1000_adapter *adapter = netdev_priv(netdev);
1854
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001855 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07001856 ec->rx_coalesce_usecs = adapter->itr_setting;
1857 else
1858 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1859
1860 return 0;
1861}
1862
1863static int e1000_set_coalesce(struct net_device *netdev,
1864 struct ethtool_coalesce *ec)
1865{
1866 struct e1000_adapter *adapter = netdev_priv(netdev);
1867 struct e1000_hw *hw = &adapter->hw;
1868
1869 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001870 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07001871 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1872 (ec->rx_coalesce_usecs == 2))
1873 return -EINVAL;
1874
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001875 if (ec->rx_coalesce_usecs == 4) {
1876 adapter->itr = adapter->itr_setting = 4;
1877 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07001878 adapter->itr = 20000;
1879 adapter->itr_setting = ec->rx_coalesce_usecs;
1880 } else {
1881 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1882 adapter->itr_setting = adapter->itr & ~3;
1883 }
1884
1885 if (adapter->itr_setting != 0)
1886 ew32(ITR, 1000000000 / (adapter->itr * 256));
1887 else
1888 ew32(ITR, 0);
1889
1890 return 0;
1891}
1892
Auke Kokbc7f75f2007-09-17 12:30:59 -07001893static int e1000_nway_reset(struct net_device *netdev)
1894{
1895 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan5962bc22011-01-20 06:58:07 +00001896
1897 if (!netif_running(netdev))
1898 return -EAGAIN;
1899
1900 if (!adapter->hw.mac.autoneg)
1901 return -EINVAL;
1902
1903 e1000e_reinit_locked(adapter);
1904
Auke Kokbc7f75f2007-09-17 12:30:59 -07001905 return 0;
1906}
1907
Auke Kokbc7f75f2007-09-17 12:30:59 -07001908static void e1000_get_ethtool_stats(struct net_device *netdev,
1909 struct ethtool_stats *stats,
1910 u64 *data)
1911{
1912 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001913 struct rtnl_link_stats64 net_stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001914 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001915 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001916
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001917 e1000e_get_stats64(netdev, &net_stats);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001918 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001919 switch (e1000_gstrings_stats[i].type) {
1920 case NETDEV_STATS:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001921 p = (char *) &net_stats +
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001922 e1000_gstrings_stats[i].stat_offset;
1923 break;
1924 case E1000_STATS:
1925 p = (char *) adapter +
1926 e1000_gstrings_stats[i].stat_offset;
1927 break;
Bruce Allan61c75812010-12-09 23:04:25 +00001928 default:
1929 data[i] = 0;
1930 continue;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001931 }
1932
Auke Kokbc7f75f2007-09-17 12:30:59 -07001933 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1934 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1935 }
1936}
1937
1938static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1939 u8 *data)
1940{
1941 u8 *p = data;
1942 int i;
1943
1944 switch (stringset) {
1945 case ETH_SS_TEST:
Bruce Allan5c1bda02011-01-19 04:23:39 +00001946 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001947 break;
1948 case ETH_SS_STATS:
1949 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1950 memcpy(p, e1000_gstrings_stats[i].stat_string,
1951 ETH_GSTRING_LEN);
1952 p += ETH_GSTRING_LEN;
1953 }
1954 break;
1955 }
1956}
1957
1958static const struct ethtool_ops e1000_ethtool_ops = {
1959 .get_settings = e1000_get_settings,
1960 .set_settings = e1000_set_settings,
1961 .get_drvinfo = e1000_get_drvinfo,
1962 .get_regs_len = e1000_get_regs_len,
1963 .get_regs = e1000_get_regs,
1964 .get_wol = e1000_get_wol,
1965 .set_wol = e1000_set_wol,
1966 .get_msglevel = e1000_get_msglevel,
1967 .set_msglevel = e1000_set_msglevel,
1968 .nway_reset = e1000_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00001969 .get_link = ethtool_op_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001970 .get_eeprom_len = e1000_get_eeprom_len,
1971 .get_eeprom = e1000_get_eeprom,
1972 .set_eeprom = e1000_set_eeprom,
1973 .get_ringparam = e1000_get_ringparam,
1974 .set_ringparam = e1000_set_ringparam,
1975 .get_pauseparam = e1000_get_pauseparam,
1976 .set_pauseparam = e1000_set_pauseparam,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001977 .self_test = e1000_diag_test,
1978 .get_strings = e1000_get_strings,
Bruce Allandbf80dc2011-04-16 00:34:40 +00001979 .set_phys_id = e1000_set_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001980 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001981 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07001982 .get_coalesce = e1000_get_coalesce,
1983 .set_coalesce = e1000_set_coalesce,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001984};
1985
1986void e1000e_set_ethtool_ops(struct net_device *netdev)
1987{
1988 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
1989}