blob: d96d0b0e08cf7b283ecb16eb15affaefc03a6402 [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);
582 char firmware_version[32];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700583
Bruce Allane0dc4f12011-01-06 14:29:50 +0000584 strncpy(drvinfo->driver, e1000e_driver_name,
585 sizeof(drvinfo->driver) - 1);
586 strncpy(drvinfo->version, e1000e_driver_version,
587 sizeof(drvinfo->version) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700588
Bruce Allanad680762008-03-28 09:15:03 -0700589 /*
590 * EEPROM image version # is reported as firmware version # for
591 * PCI-E controllers
592 */
Bruce Allane0dc4f12011-01-06 14:29:50 +0000593 snprintf(firmware_version, sizeof(firmware_version), "%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
Bruce Allane0dc4f12011-01-06 14:29:50 +0000598 strncpy(drvinfo->fw_version, firmware_version,
599 sizeof(drvinfo->fw_version) - 1);
600 strncpy(drvinfo->bus_info, pci_name(adapter->pdev),
601 sizeof(drvinfo->bus_info) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700602 drvinfo->regdump_len = e1000_get_regs_len(netdev);
603 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
604}
605
606static void e1000_get_ringparam(struct net_device *netdev,
607 struct ethtool_ringparam *ring)
608{
609 struct e1000_adapter *adapter = netdev_priv(netdev);
610 struct e1000_ring *tx_ring = adapter->tx_ring;
611 struct e1000_ring *rx_ring = adapter->rx_ring;
612
613 ring->rx_max_pending = E1000_MAX_RXD;
614 ring->tx_max_pending = E1000_MAX_TXD;
615 ring->rx_mini_max_pending = 0;
616 ring->rx_jumbo_max_pending = 0;
617 ring->rx_pending = rx_ring->count;
618 ring->tx_pending = tx_ring->count;
619 ring->rx_mini_pending = 0;
620 ring->rx_jumbo_pending = 0;
621}
622
623static int e1000_set_ringparam(struct net_device *netdev,
624 struct ethtool_ringparam *ring)
625{
626 struct e1000_adapter *adapter = netdev_priv(netdev);
627 struct e1000_ring *tx_ring, *tx_old;
628 struct e1000_ring *rx_ring, *rx_old;
629 int err;
630
631 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
632 return -EINVAL;
633
634 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000635 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700636
637 if (netif_running(adapter->netdev))
638 e1000e_down(adapter);
639
640 tx_old = adapter->tx_ring;
641 rx_old = adapter->rx_ring;
642
643 err = -ENOMEM;
Bruce Allan05b93212011-01-05 07:10:38 +0000644 tx_ring = kmemdup(tx_old, sizeof(struct e1000_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700645 if (!tx_ring)
646 goto err_alloc_tx;
647
Bruce Allan05b93212011-01-05 07:10:38 +0000648 rx_ring = kmemdup(rx_old, sizeof(struct e1000_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700649 if (!rx_ring)
650 goto err_alloc_rx;
651
652 adapter->tx_ring = tx_ring;
653 adapter->rx_ring = rx_ring;
654
655 rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
656 rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD));
657 rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
658
659 tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
660 tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
661 tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
662
663 if (netif_running(adapter->netdev)) {
664 /* Try to get new resources before deleting old */
665 err = e1000e_setup_rx_resources(adapter);
666 if (err)
667 goto err_setup_rx;
668 err = e1000e_setup_tx_resources(adapter);
669 if (err)
670 goto err_setup_tx;
671
Bruce Allanad680762008-03-28 09:15:03 -0700672 /*
673 * restore the old in order to free it,
674 * then add in the new
675 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700676 adapter->rx_ring = rx_old;
677 adapter->tx_ring = tx_old;
678 e1000e_free_rx_resources(adapter);
679 e1000e_free_tx_resources(adapter);
680 kfree(tx_old);
681 kfree(rx_old);
682 adapter->rx_ring = rx_ring;
683 adapter->tx_ring = tx_ring;
684 err = e1000e_up(adapter);
685 if (err)
686 goto err_setup;
687 }
688
689 clear_bit(__E1000_RESETTING, &adapter->state);
690 return 0;
691err_setup_tx:
692 e1000e_free_rx_resources(adapter);
693err_setup_rx:
694 adapter->rx_ring = rx_old;
695 adapter->tx_ring = tx_old;
696 kfree(rx_ring);
697err_alloc_rx:
698 kfree(tx_ring);
699err_alloc_tx:
700 e1000e_up(adapter);
701err_setup:
702 clear_bit(__E1000_RESETTING, &adapter->state);
703 return err;
704}
705
Bruce Allancef8c792008-04-02 13:48:23 -0700706static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
707 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800708{
Bruce Allancef8c792008-04-02 13:48:23 -0700709 u32 pat, val;
Bruce Allan64806412010-12-11 05:53:42 +0000710 static const u32 test[] = {
711 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Bruce Allancef8c792008-04-02 13:48:23 -0700712 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800713 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700714 (test[pat] & write));
715 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
716 if (val != (test[pat] & write & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700717 e_err("pattern test reg %04X failed: got 0x%08X "
718 "expected 0x%08X\n", reg + offset, val,
719 (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800720 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700721 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800722 }
723 }
Bruce Allancef8c792008-04-02 13:48:23 -0700724 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700725}
726
Joe Perches2a887192007-11-13 20:53:51 -0800727static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
728 int reg, u32 mask, u32 write)
729{
Bruce Allancef8c792008-04-02 13:48:23 -0700730 u32 val;
Joe Perches2a887192007-11-13 20:53:51 -0800731 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700732 val = __er32(&adapter->hw, reg);
733 if ((write & mask) != (val & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700734 e_err("set/check reg %04X test failed: got 0x%08X "
735 "expected 0x%08X\n", reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800736 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700737 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800738 }
Bruce Allancef8c792008-04-02 13:48:23 -0700739 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700740}
Bruce Allancef8c792008-04-02 13:48:23 -0700741#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
742 do { \
743 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
744 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800745 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700746#define REG_PATTERN_TEST(reg, mask, write) \
747 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800748
Bruce Allancef8c792008-04-02 13:48:23 -0700749#define REG_SET_AND_CHECK(reg, mask, write) \
750 do { \
751 if (reg_set_and_check(adapter, data, reg, mask, write)) \
752 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800753 } while (0)
754
Auke Kokbc7f75f2007-09-17 12:30:59 -0700755static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
756{
757 struct e1000_hw *hw = &adapter->hw;
758 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700759 u32 value;
760 u32 before;
761 u32 after;
762 u32 i;
763 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000764 u32 mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700765
Bruce Allanad680762008-03-28 09:15:03 -0700766 /*
767 * The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700768 * Some bits that get toggled are ignored.
769 */
770 switch (mac->type) {
771 /* there are several bits on newer hardware that are r/w */
772 case e1000_82571:
773 case e1000_82572:
774 case e1000_80003es2lan:
775 toggle = 0x7FFFF3FF;
776 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000777 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700778 toggle = 0x7FFFF033;
779 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700780 }
781
782 before = er32(STATUS);
783 value = (er32(STATUS) & toggle);
784 ew32(STATUS, toggle);
785 after = er32(STATUS) & toggle;
786 if (value != after) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700787 e_err("failed STATUS register test got: 0x%08X expected: "
788 "0x%08X\n", after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700789 *data = 1;
790 return 1;
791 }
792 /* restore previous status */
793 ew32(STATUS, before);
794
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700795 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700796 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
797 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
798 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
799 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
800 }
801
802 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
803 REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
804 REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF);
805 REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF);
806 REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF);
807 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
808 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
809 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
810 REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
811 REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF);
812
813 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
814
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700815 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700816 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
817 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
818
Auke Kok86582512007-10-04 15:00:08 -0700819 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
820 REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700821 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700822 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
823 REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
824 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000825 mask = 0x8003FFFF;
826 switch (mac->type) {
827 case e1000_ich10lan:
828 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000829 case e1000_pch2lan:
Bruce Allana4f58f52009-06-02 11:29:18 +0000830 mask |= (1 << 18);
831 break;
832 default:
833 break;
834 }
Auke Kok86582512007-10-04 15:00:08 -0700835 for (i = 0; i < mac->rar_entry_count; i++)
836 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
Bruce Allana4f58f52009-06-02 11:29:18 +0000837 mask, 0xFFFFFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700838
839 for (i = 0; i < mac->mta_reg_count; i++)
840 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
841
842 *data = 0;
843 return 0;
844}
845
846static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
847{
848 u16 temp;
849 u16 checksum = 0;
850 u16 i;
851
852 *data = 0;
853 /* Read and add up the contents of the EEPROM */
854 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
855 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
856 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800857 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700858 }
859 checksum += temp;
860 }
861
862 /* If Checksum is not Correct return error else test passed */
863 if ((checksum != (u16) NVM_SUM) && !(*data))
864 *data = 2;
865
866 return *data;
867}
868
869static irqreturn_t e1000_test_intr(int irq, void *data)
870{
871 struct net_device *netdev = (struct net_device *) data;
872 struct e1000_adapter *adapter = netdev_priv(netdev);
873 struct e1000_hw *hw = &adapter->hw;
874
875 adapter->test_icr |= er32(ICR);
876
877 return IRQ_HANDLED;
878}
879
880static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
881{
882 struct net_device *netdev = adapter->netdev;
883 struct e1000_hw *hw = &adapter->hw;
884 u32 mask;
885 u32 shared_int = 1;
886 u32 irq = adapter->pdev->irq;
887 int i;
Bruce Allan4662e822008-08-26 18:37:06 -0700888 int ret_val = 0;
889 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700890
891 *data = 0;
892
Bruce Allan4662e822008-08-26 18:37:06 -0700893 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
894 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
895 int_mode = adapter->int_mode;
896 e1000e_reset_interrupt_capability(adapter);
897 adapter->int_mode = E1000E_INT_MODE_LEGACY;
898 e1000e_set_interrupt_capability(adapter);
899 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700900 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800901 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700902 netdev)) {
903 shared_int = 0;
Joe Perchesa0607fd2009-11-18 23:29:17 -0800904 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700905 netdev->name, netdev)) {
906 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700907 ret_val = -1;
908 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700909 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700910 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700911
912 /* Disable all the interrupts */
913 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000914 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000915 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700916
917 /* Test each interrupt */
918 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700919 /* Interrupt to test */
920 mask = 1 << i;
921
Bruce Allanf4187b52008-08-26 18:36:50 -0700922 if (adapter->flags & FLAG_IS_ICH) {
923 switch (mask) {
924 case E1000_ICR_RXSEQ:
925 continue;
926 case 0x00000100:
927 if (adapter->hw.mac.type == e1000_ich8lan ||
928 adapter->hw.mac.type == e1000_ich9lan)
929 continue;
930 break;
931 default:
932 break;
933 }
934 }
935
Auke Kokbc7f75f2007-09-17 12:30:59 -0700936 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700937 /*
938 * Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700939 * the cause register and then force the same
940 * interrupt and see if one gets posted. If
941 * an interrupt was posted to the bus, the
942 * test failed.
943 */
944 adapter->test_icr = 0;
945 ew32(IMC, mask);
946 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000947 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000948 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700949
950 if (adapter->test_icr & mask) {
951 *data = 3;
952 break;
953 }
954 }
955
Bruce Allanad680762008-03-28 09:15:03 -0700956 /*
957 * Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700958 * the cause register and then force the same
959 * interrupt and see if one gets posted. If
960 * an interrupt was not posted to the bus, the
961 * test failed.
962 */
963 adapter->test_icr = 0;
964 ew32(IMS, mask);
965 ew32(ICS, mask);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000966 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000967 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700968
969 if (!(adapter->test_icr & mask)) {
970 *data = 4;
971 break;
972 }
973
974 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700975 /*
976 * Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700977 * the cause register and then force the other
978 * interrupts and see if any get posted. If
979 * an interrupt was posted to the bus, the
980 * test failed.
981 */
982 adapter->test_icr = 0;
983 ew32(IMC, ~mask & 0x00007FFF);
984 ew32(ICS, ~mask & 0x00007FFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000985 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000986 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700987
988 if (adapter->test_icr) {
989 *data = 5;
990 break;
991 }
992 }
993 }
994
995 /* Disable all the interrupts */
996 ew32(IMC, 0xFFFFFFFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000997 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000998 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700999
1000 /* Unhook test interrupt handler */
1001 free_irq(irq, netdev);
1002
Bruce Allan4662e822008-08-26 18:37:06 -07001003out:
1004 if (int_mode == E1000E_INT_MODE_MSIX) {
1005 e1000e_reset_interrupt_capability(adapter);
1006 adapter->int_mode = int_mode;
1007 e1000e_set_interrupt_capability(adapter);
1008 }
1009
1010 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001011}
1012
1013static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1014{
1015 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1016 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1017 struct pci_dev *pdev = adapter->pdev;
1018 int i;
1019
1020 if (tx_ring->desc && tx_ring->buffer_info) {
1021 for (i = 0; i < tx_ring->count; i++) {
1022 if (tx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001023 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001024 tx_ring->buffer_info[i].dma,
1025 tx_ring->buffer_info[i].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001026 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001027 if (tx_ring->buffer_info[i].skb)
1028 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1029 }
1030 }
1031
1032 if (rx_ring->desc && rx_ring->buffer_info) {
1033 for (i = 0; i < rx_ring->count; i++) {
1034 if (rx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001035 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001036 rx_ring->buffer_info[i].dma,
Nick Nunley0be3f552010-04-27 13:09:05 +00001037 2048, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001038 if (rx_ring->buffer_info[i].skb)
1039 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1040 }
1041 }
1042
1043 if (tx_ring->desc) {
1044 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1045 tx_ring->dma);
1046 tx_ring->desc = NULL;
1047 }
1048 if (rx_ring->desc) {
1049 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1050 rx_ring->dma);
1051 rx_ring->desc = NULL;
1052 }
1053
1054 kfree(tx_ring->buffer_info);
1055 tx_ring->buffer_info = NULL;
1056 kfree(rx_ring->buffer_info);
1057 rx_ring->buffer_info = NULL;
1058}
1059
1060static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1061{
1062 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1063 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1064 struct pci_dev *pdev = adapter->pdev;
1065 struct e1000_hw *hw = &adapter->hw;
1066 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001067 int i;
1068 int ret_val;
1069
1070 /* Setup Tx descriptor ring and Tx buffers */
1071
1072 if (!tx_ring->count)
1073 tx_ring->count = E1000_DEFAULT_TXD;
1074
Bruce Allancef8c792008-04-02 13:48:23 -07001075 tx_ring->buffer_info = kcalloc(tx_ring->count,
1076 sizeof(struct e1000_buffer),
1077 GFP_KERNEL);
1078 if (!(tx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001079 ret_val = 1;
1080 goto err_nomem;
1081 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001082
1083 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1084 tx_ring->size = ALIGN(tx_ring->size, 4096);
1085 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1086 &tx_ring->dma, GFP_KERNEL);
1087 if (!tx_ring->desc) {
1088 ret_val = 2;
1089 goto err_nomem;
1090 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001091 tx_ring->next_to_use = 0;
1092 tx_ring->next_to_clean = 0;
1093
Bruce Allancef8c792008-04-02 13:48:23 -07001094 ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001095 ew32(TDBAH, ((u64) tx_ring->dma >> 32));
Bruce Allancef8c792008-04-02 13:48:23 -07001096 ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001097 ew32(TDH, 0);
1098 ew32(TDT, 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001099 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1100 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1101 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001102
1103 for (i = 0; i < tx_ring->count; i++) {
1104 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1105 struct sk_buff *skb;
1106 unsigned int skb_size = 1024;
1107
1108 skb = alloc_skb(skb_size, GFP_KERNEL);
1109 if (!skb) {
1110 ret_val = 3;
1111 goto err_nomem;
1112 }
1113 skb_put(skb, skb_size);
1114 tx_ring->buffer_info[i].skb = skb;
1115 tx_ring->buffer_info[i].length = skb->len;
1116 tx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001117 dma_map_single(&pdev->dev, skb->data, skb->len,
1118 DMA_TO_DEVICE);
1119 if (dma_mapping_error(&pdev->dev,
1120 tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001121 ret_val = 4;
1122 goto err_nomem;
1123 }
Bruce Allancef8c792008-04-02 13:48:23 -07001124 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001125 tx_desc->lower.data = cpu_to_le32(skb->len);
1126 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1127 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001128 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001129 tx_desc->upper.data = 0;
1130 }
1131
1132 /* Setup Rx descriptor ring and Rx buffers */
1133
1134 if (!rx_ring->count)
1135 rx_ring->count = E1000_DEFAULT_RXD;
1136
Bruce Allancef8c792008-04-02 13:48:23 -07001137 rx_ring->buffer_info = kcalloc(rx_ring->count,
1138 sizeof(struct e1000_buffer),
1139 GFP_KERNEL);
1140 if (!(rx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001141 ret_val = 5;
1142 goto err_nomem;
1143 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001144
Bruce Allan5f450212011-07-22 06:21:46 +00001145 rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001146 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1147 &rx_ring->dma, GFP_KERNEL);
1148 if (!rx_ring->desc) {
1149 ret_val = 6;
1150 goto err_nomem;
1151 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001152 rx_ring->next_to_use = 0;
1153 rx_ring->next_to_clean = 0;
1154
1155 rctl = er32(RCTL);
Bruce Allan7f99ae62011-07-22 06:21:35 +00001156 if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
1157 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001158 ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
1159 ew32(RDBAH, ((u64) rx_ring->dma >> 32));
1160 ew32(RDLEN, rx_ring->size);
1161 ew32(RDH, 0);
1162 ew32(RDT, 0);
1163 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allancef8c792008-04-02 13:48:23 -07001164 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1165 E1000_RCTL_SBP | E1000_RCTL_SECRC |
Auke Kokbc7f75f2007-09-17 12:30:59 -07001166 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1167 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1168 ew32(RCTL, rctl);
1169
1170 for (i = 0; i < rx_ring->count; i++) {
Bruce Allan5f450212011-07-22 06:21:46 +00001171 union e1000_rx_desc_extended *rx_desc;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001172 struct sk_buff *skb;
1173
1174 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1175 if (!skb) {
1176 ret_val = 7;
1177 goto err_nomem;
1178 }
1179 skb_reserve(skb, NET_IP_ALIGN);
1180 rx_ring->buffer_info[i].skb = skb;
1181 rx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001182 dma_map_single(&pdev->dev, skb->data, 2048,
1183 DMA_FROM_DEVICE);
1184 if (dma_mapping_error(&pdev->dev,
1185 rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001186 ret_val = 8;
1187 goto err_nomem;
1188 }
Bruce Allan5f450212011-07-22 06:21:46 +00001189 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1190 rx_desc->read.buffer_addr =
1191 cpu_to_le64(rx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001192 memset(skb->data, 0x00, skb->len);
1193 }
1194
1195 return 0;
1196
1197err_nomem:
1198 e1000_free_desc_rings(adapter);
1199 return ret_val;
1200}
1201
1202static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1203{
1204 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1205 e1e_wphy(&adapter->hw, 29, 0x001F);
1206 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1207 e1e_wphy(&adapter->hw, 29, 0x001A);
1208 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1209}
1210
1211static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1212{
1213 struct e1000_hw *hw = &adapter->hw;
1214 u32 ctrl_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001215 u16 phy_reg = 0;
Bruce Allancbd006c2010-11-24 06:01:30 +00001216 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001217
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001218 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001219
Bruce Allan3af50482010-06-16 13:25:55 +00001220 if (hw->phy.type == e1000_phy_ife) {
1221 /* force 100, set loopback */
1222 e1e_wphy(hw, PHY_CONTROL, 0x6100);
Bruce Allanbb436b22009-11-20 23:24:11 +00001223
Bruce Allan3af50482010-06-16 13:25:55 +00001224 /* Now set up the MAC to the same speed/duplex as the PHY. */
1225 ctrl_reg = er32(CTRL);
1226 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1227 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1228 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1229 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1230 E1000_CTRL_FD); /* Force Duplex to FULL */
1231
1232 ew32(CTRL, ctrl_reg);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001233 e1e_flush();
Bruce Allan3af50482010-06-16 13:25:55 +00001234 udelay(500);
1235
1236 return 0;
1237 }
1238
1239 /* Specific PHY configuration for loopback */
1240 switch (hw->phy.type) {
1241 case e1000_phy_m88:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001242 /* Auto-MDI/MDIX Off */
1243 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1244 /* reset to update Auto-MDI/MDIX */
1245 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1246 /* autoneg off */
1247 e1e_wphy(hw, PHY_CONTROL, 0x8140);
Bruce Allan3af50482010-06-16 13:25:55 +00001248 break;
1249 case e1000_phy_gg82563:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001250 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
Bruce Allancef8c792008-04-02 13:48:23 -07001251 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001252 case e1000_phy_bm:
1253 /* Set Default MAC Interface speed to 1GB */
1254 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1255 phy_reg &= ~0x0007;
1256 phy_reg |= 0x006;
1257 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1258 /* Assert SW reset for above settings to take effect */
1259 e1000e_commit_phy(hw);
1260 mdelay(1);
1261 /* Force Full Duplex */
1262 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1263 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1264 /* Set Link Up (in force link) */
1265 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1266 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1267 /* Force Link */
1268 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1269 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1270 /* Set Early Link Enable */
1271 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1272 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
Bruce Allan3af50482010-06-16 13:25:55 +00001273 break;
1274 case e1000_phy_82577:
1275 case e1000_phy_82578:
1276 /* Workaround: K1 must be disabled for stable 1Gbps operation */
Bruce Allancbd006c2010-11-24 06:01:30 +00001277 ret_val = hw->phy.ops.acquire(hw);
1278 if (ret_val) {
1279 e_err("Cannot setup 1Gbps loopback.\n");
1280 return ret_val;
1281 }
Bruce Allan3af50482010-06-16 13:25:55 +00001282 e1000_configure_k1_ich8lan(hw, false);
Bruce Allancbd006c2010-11-24 06:01:30 +00001283 hw->phy.ops.release(hw);
Bruce Allan3af50482010-06-16 13:25:55 +00001284 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001285 case e1000_phy_82579:
1286 /* Disable PHY energy detect power down */
1287 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1288 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
1289 /* Disable full chip energy detect */
1290 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1291 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1292 /* Enable loopback on the PHY */
1293#define I82577_PHY_LBK_CTRL 19
1294 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1295 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001296 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001297 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001298 }
1299
Bruce Allan3af50482010-06-16 13:25:55 +00001300 /* force 1000, set loopback */
1301 e1e_wphy(hw, PHY_CONTROL, 0x4140);
1302 mdelay(250);
1303
1304 /* Now set up the MAC to the same speed/duplex as the PHY. */
1305 ctrl_reg = er32(CTRL);
1306 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1307 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1308 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1309 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1310 E1000_CTRL_FD); /* Force Duplex to FULL */
1311
1312 if (adapter->flags & FLAG_IS_ICH)
1313 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1314
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001315 if (hw->phy.media_type == e1000_media_type_copper &&
1316 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001317 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1318 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001319 /*
1320 * Set the ILOS bit on the fiber Nic if half duplex link is
1321 * detected.
1322 */
Bruce Allan90da0662011-01-06 07:02:53 +00001323 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001324 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1325 }
1326
1327 ew32(CTRL, ctrl_reg);
1328
Bruce Allanad680762008-03-28 09:15:03 -07001329 /*
1330 * Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001331 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1332 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001333 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001334 e1000_phy_disable_receiver(adapter);
1335
1336 udelay(500);
1337
1338 return 0;
1339}
1340
1341static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1342{
1343 struct e1000_hw *hw = &adapter->hw;
1344 u32 ctrl = er32(CTRL);
1345 int link = 0;
1346
1347 /* special requirements for 82571/82572 fiber adapters */
1348
Bruce Allanad680762008-03-28 09:15:03 -07001349 /*
1350 * jump through hoops to make sure link is up because serdes
1351 * link is hardwired up
1352 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001353 ctrl |= E1000_CTRL_SLU;
1354 ew32(CTRL, ctrl);
1355
1356 /* disable autoneg */
1357 ctrl = er32(TXCW);
1358 ctrl &= ~(1 << 31);
1359 ew32(TXCW, ctrl);
1360
1361 link = (er32(STATUS) & E1000_STATUS_LU);
1362
1363 if (!link) {
1364 /* set invert loss of signal */
1365 ctrl = er32(CTRL);
1366 ctrl |= E1000_CTRL_ILOS;
1367 ew32(CTRL, ctrl);
1368 }
1369
Bruce Allanad680762008-03-28 09:15:03 -07001370 /*
1371 * special write to serdes control register to enable SerDes analog
1372 * loopback
1373 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001374#define E1000_SERDES_LB_ON 0x410
1375 ew32(SCTL, E1000_SERDES_LB_ON);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001376 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001377 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001378
1379 return 0;
1380}
1381
1382/* only call this for fiber/serdes connections to es2lan */
1383static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1384{
1385 struct e1000_hw *hw = &adapter->hw;
1386 u32 ctrlext = er32(CTRL_EXT);
1387 u32 ctrl = er32(CTRL);
1388
Bruce Allanad680762008-03-28 09:15:03 -07001389 /*
1390 * save CTRL_EXT to restore later, reuse an empty variable (unused
1391 * on mac_type 80003es2lan)
1392 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001393 adapter->tx_fifo_head = ctrlext;
1394
1395 /* clear the serdes mode bits, putting the device into mac loopback */
1396 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1397 ew32(CTRL_EXT, ctrlext);
1398
1399 /* force speed to 1000/FD, link up */
1400 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1401 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1402 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1403 ew32(CTRL, ctrl);
1404
1405 /* set mac loopback */
1406 ctrl = er32(RCTL);
1407 ctrl |= E1000_RCTL_LBM_MAC;
1408 ew32(RCTL, ctrl);
1409
1410 /* set testing mode parameters (no need to reset later) */
1411#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1412#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1413 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001414 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001415
1416 return 0;
1417}
1418
1419static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1420{
1421 struct e1000_hw *hw = &adapter->hw;
1422 u32 rctl;
1423
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001424 if (hw->phy.media_type == e1000_media_type_fiber ||
1425 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001426 switch (hw->mac.type) {
1427 case e1000_80003es2lan:
1428 return e1000_set_es2lan_mac_loopback(adapter);
1429 break;
1430 case e1000_82571:
1431 case e1000_82572:
1432 return e1000_set_82571_fiber_loopback(adapter);
1433 break;
1434 default:
1435 rctl = er32(RCTL);
1436 rctl |= E1000_RCTL_LBM_TCVR;
1437 ew32(RCTL, rctl);
1438 return 0;
1439 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001440 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001441 return e1000_integrated_phy_loopback(adapter);
1442 }
1443
1444 return 7;
1445}
1446
1447static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1448{
1449 struct e1000_hw *hw = &adapter->hw;
1450 u32 rctl;
1451 u16 phy_reg;
1452
1453 rctl = er32(RCTL);
1454 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1455 ew32(RCTL, rctl);
1456
1457 switch (hw->mac.type) {
1458 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001459 if (hw->phy.media_type == e1000_media_type_fiber ||
1460 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001461 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001462 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001463 adapter->tx_fifo_head = 0;
1464 }
1465 /* fall through */
1466 case e1000_82571:
1467 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001468 if (hw->phy.media_type == e1000_media_type_fiber ||
1469 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001470#define E1000_SERDES_LB_OFF 0x400
1471 ew32(SCTL, E1000_SERDES_LB_OFF);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001472 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +00001473 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001474 break;
1475 }
1476 /* Fall Through */
1477 default:
1478 hw->mac.autoneg = 1;
1479 if (hw->phy.type == e1000_phy_gg82563)
1480 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1481 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1482 if (phy_reg & MII_CR_LOOPBACK) {
1483 phy_reg &= ~MII_CR_LOOPBACK;
1484 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1485 e1000e_commit_phy(hw);
1486 }
1487 break;
1488 }
1489}
1490
1491static void e1000_create_lbtest_frame(struct sk_buff *skb,
1492 unsigned int frame_size)
1493{
1494 memset(skb->data, 0xFF, frame_size);
1495 frame_size &= ~1;
1496 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1497 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1498 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1499}
1500
1501static int e1000_check_lbtest_frame(struct sk_buff *skb,
1502 unsigned int frame_size)
1503{
1504 frame_size &= ~1;
1505 if (*(skb->data + 3) == 0xFF)
1506 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1507 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1508 return 0;
1509 return 13;
1510}
1511
1512static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1513{
1514 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1515 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1516 struct pci_dev *pdev = adapter->pdev;
1517 struct e1000_hw *hw = &adapter->hw;
1518 int i, j, k, l;
1519 int lc;
1520 int good_cnt;
1521 int ret_val = 0;
1522 unsigned long time;
1523
1524 ew32(RDT, rx_ring->count - 1);
1525
Bruce Allanad680762008-03-28 09:15:03 -07001526 /*
1527 * Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001528 * The idea is to wrap the largest ring a number of times using 64
1529 * send/receive pairs during each loop
1530 */
1531
1532 if (rx_ring->count <= tx_ring->count)
1533 lc = ((tx_ring->count / 64) * 2) + 1;
1534 else
1535 lc = ((rx_ring->count / 64) * 2) + 1;
1536
1537 k = 0;
1538 l = 0;
1539 for (j = 0; j <= lc; j++) { /* loop count loop */
1540 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001541 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1542 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001543 dma_sync_single_for_device(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001544 tx_ring->buffer_info[k].dma,
1545 tx_ring->buffer_info[k].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001546 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001547 k++;
1548 if (k == tx_ring->count)
1549 k = 0;
1550 }
1551 ew32(TDT, k);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001552 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001553 msleep(200);
1554 time = jiffies; /* set the start time for the receive */
1555 good_cnt = 0;
1556 do { /* receive the sent packets */
Nick Nunley0be3f552010-04-27 13:09:05 +00001557 dma_sync_single_for_cpu(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001558 rx_ring->buffer_info[l].dma, 2048,
Nick Nunley0be3f552010-04-27 13:09:05 +00001559 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001560
1561 ret_val = e1000_check_lbtest_frame(
1562 rx_ring->buffer_info[l].skb, 1024);
1563 if (!ret_val)
1564 good_cnt++;
1565 l++;
1566 if (l == rx_ring->count)
1567 l = 0;
Bruce Allanad680762008-03-28 09:15:03 -07001568 /*
1569 * time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001570 * enough time to complete the receives, if it's
1571 * exceeded, break and error off
1572 */
1573 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1574 if (good_cnt != 64) {
1575 ret_val = 13; /* ret_val is the same as mis-compare */
1576 break;
1577 }
Bruce Allancef8c792008-04-02 13:48:23 -07001578 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001579 ret_val = 14; /* error code for time out error */
1580 break;
1581 }
1582 } /* end loop count loop */
1583 return ret_val;
1584}
1585
1586static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1587{
Bruce Allanad680762008-03-28 09:15:03 -07001588 /*
1589 * PHY loopback cannot be performed if SoL/IDER
1590 * sessions are active
1591 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001592 if (e1000_check_reset_block(&adapter->hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001593 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001594 *data = 0;
1595 goto out;
1596 }
1597
1598 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001599 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001600 goto out;
1601
1602 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001603 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001604 goto err_loopback;
1605
1606 *data = e1000_run_loopback_test(adapter);
1607 e1000_loopback_cleanup(adapter);
1608
1609err_loopback:
1610 e1000_free_desc_rings(adapter);
1611out:
1612 return *data;
1613}
1614
1615static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1616{
1617 struct e1000_hw *hw = &adapter->hw;
1618
1619 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001620 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001621 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001622 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001623
Bruce Allanad680762008-03-28 09:15:03 -07001624 /*
1625 * On some blade server designs, link establishment
1626 * could take as long as 2-3 minutes
1627 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001628 do {
1629 hw->mac.ops.check_for_link(hw);
1630 if (hw->mac.serdes_has_link)
1631 return *data;
1632 msleep(20);
1633 } while (i++ < 3750);
1634
1635 *data = 1;
1636 } else {
1637 hw->mac.ops.check_for_link(hw);
1638 if (hw->mac.autoneg)
Bruce Allan5661aeb2011-02-25 06:36:25 +00001639 /*
1640 * On some Phy/switch combinations, link establishment
1641 * can take a few seconds more than expected.
1642 */
1643 msleep(5000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001644
Bruce Allan5661aeb2011-02-25 06:36:25 +00001645 if (!(er32(STATUS) & E1000_STATUS_LU))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001646 *data = 1;
1647 }
1648 return *data;
1649}
1650
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001651static int e1000e_get_sset_count(struct net_device *netdev, int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001652{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001653 switch (sset) {
1654 case ETH_SS_TEST:
1655 return E1000_TEST_LEN;
1656 case ETH_SS_STATS:
1657 return E1000_STATS_LEN;
1658 default:
1659 return -EOPNOTSUPP;
1660 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001661}
1662
1663static void e1000_diag_test(struct net_device *netdev,
1664 struct ethtool_test *eth_test, u64 *data)
1665{
1666 struct e1000_adapter *adapter = netdev_priv(netdev);
1667 u16 autoneg_advertised;
1668 u8 forced_speed_duplex;
1669 u8 autoneg;
1670 bool if_running = netif_running(netdev);
1671
1672 set_bit(__E1000_TESTING, &adapter->state);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001673
1674 if (!if_running) {
1675 /* Get control of and reset hardware */
1676 if (adapter->flags & FLAG_HAS_AMT)
1677 e1000e_get_hw_control(adapter);
1678
1679 e1000e_power_up_phy(adapter);
1680
1681 adapter->hw.phy.autoneg_wait_to_complete = 1;
1682 e1000e_reset(adapter);
1683 adapter->hw.phy.autoneg_wait_to_complete = 0;
1684 }
1685
Auke Kokbc7f75f2007-09-17 12:30:59 -07001686 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1687 /* Offline tests */
1688
1689 /* save speed, duplex, autoneg settings */
1690 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1691 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1692 autoneg = adapter->hw.mac.autoneg;
1693
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001694 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001695
Auke Kokbc7f75f2007-09-17 12:30:59 -07001696 if (if_running)
1697 /* indicate we're in test mode */
1698 dev_close(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001699
1700 if (e1000_reg_test(adapter, &data[0]))
1701 eth_test->flags |= ETH_TEST_FL_FAILED;
1702
1703 e1000e_reset(adapter);
1704 if (e1000_eeprom_test(adapter, &data[1]))
1705 eth_test->flags |= ETH_TEST_FL_FAILED;
1706
1707 e1000e_reset(adapter);
1708 if (e1000_intr_test(adapter, &data[2]))
1709 eth_test->flags |= ETH_TEST_FL_FAILED;
1710
1711 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001712 if (e1000_loopback_test(adapter, &data[3]))
1713 eth_test->flags |= ETH_TEST_FL_FAILED;
1714
Auke Kokbc7f75f2007-09-17 12:30:59 -07001715 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001716 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001717 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001718 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001719
Carolyn Wybornyc6ce3852010-10-15 17:35:31 +00001720 if (e1000_link_test(adapter, &data[4]))
1721 eth_test->flags |= ETH_TEST_FL_FAILED;
1722
1723 /* restore speed, duplex, autoneg settings */
1724 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1725 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1726 adapter->hw.mac.autoneg = autoneg;
1727 e1000e_reset(adapter);
1728
Auke Kokbc7f75f2007-09-17 12:30:59 -07001729 clear_bit(__E1000_TESTING, &adapter->state);
1730 if (if_running)
1731 dev_open(netdev);
1732 } else {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001733 /* Online tests */
Bruce Allan11b08be2010-05-10 14:59:31 +00001734
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001735 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001736
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001737 /* register, eeprom, intr and loopback tests not run online */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001738 data[0] = 0;
1739 data[1] = 0;
1740 data[2] = 0;
1741 data[3] = 0;
1742
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001743 if (e1000_link_test(adapter, &data[4]))
1744 eth_test->flags |= ETH_TEST_FL_FAILED;
Bruce Allan11b08be2010-05-10 14:59:31 +00001745
Auke Kokbc7f75f2007-09-17 12:30:59 -07001746 clear_bit(__E1000_TESTING, &adapter->state);
1747 }
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001748
1749 if (!if_running) {
1750 e1000e_reset(adapter);
1751
1752 if (adapter->flags & FLAG_HAS_AMT)
1753 e1000e_release_hw_control(adapter);
1754 }
1755
Auke Kokbc7f75f2007-09-17 12:30:59 -07001756 msleep_interruptible(4 * 1000);
1757}
1758
1759static void e1000_get_wol(struct net_device *netdev,
1760 struct ethtool_wolinfo *wol)
1761{
1762 struct e1000_adapter *adapter = netdev_priv(netdev);
1763
1764 wol->supported = 0;
1765 wol->wolopts = 0;
1766
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001767 if (!(adapter->flags & FLAG_HAS_WOL) ||
1768 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001769 return;
1770
1771 wol->supported = WAKE_UCAST | WAKE_MCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001772 WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001773
1774 /* apply any specific unsupported masks here */
1775 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1776 wol->supported &= ~WAKE_UCAST;
1777
1778 if (adapter->wol & E1000_WUFC_EX)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001779 e_err("Interface does not support directed (unicast) "
1780 "frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001781 }
1782
1783 if (adapter->wol & E1000_WUFC_EX)
1784 wol->wolopts |= WAKE_UCAST;
1785 if (adapter->wol & E1000_WUFC_MC)
1786 wol->wolopts |= WAKE_MCAST;
1787 if (adapter->wol & E1000_WUFC_BC)
1788 wol->wolopts |= WAKE_BCAST;
1789 if (adapter->wol & E1000_WUFC_MAG)
1790 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001791 if (adapter->wol & E1000_WUFC_LNKC)
1792 wol->wolopts |= WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001793}
1794
Bruce Allan4a29e152011-03-04 09:07:01 +00001795static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001796{
1797 struct e1000_adapter *adapter = netdev_priv(netdev);
1798
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001799 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001800 !device_can_wakeup(&adapter->pdev->dev) ||
1801 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001802 WAKE_MAGIC | WAKE_PHY)))
Bruce Allan1fbfca32009-11-20 23:22:01 +00001803 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001804
1805 /* these settings will always override what we currently have */
1806 adapter->wol = 0;
1807
1808 if (wol->wolopts & WAKE_UCAST)
1809 adapter->wol |= E1000_WUFC_EX;
1810 if (wol->wolopts & WAKE_MCAST)
1811 adapter->wol |= E1000_WUFC_MC;
1812 if (wol->wolopts & WAKE_BCAST)
1813 adapter->wol |= E1000_WUFC_BC;
1814 if (wol->wolopts & WAKE_MAGIC)
1815 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001816 if (wol->wolopts & WAKE_PHY)
1817 adapter->wol |= E1000_WUFC_LNKC;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001818
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001819 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1820
Auke Kokbc7f75f2007-09-17 12:30:59 -07001821 return 0;
1822}
1823
Bruce Allandbf80dc2011-04-16 00:34:40 +00001824static int e1000_set_phys_id(struct net_device *netdev,
1825 enum ethtool_phys_id_state state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001826{
1827 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001828 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001829
Bruce Allandbf80dc2011-04-16 00:34:40 +00001830 switch (state) {
1831 case ETHTOOL_ID_ACTIVE:
1832 if (!hw->mac.ops.blink_led)
1833 return 2; /* cycle on/off twice per second */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001834
Bruce Allandbf80dc2011-04-16 00:34:40 +00001835 hw->mac.ops.blink_led(hw);
1836 break;
1837
1838 case ETHTOOL_ID_INACTIVE:
Bruce Allan4662e822008-08-26 18:37:06 -07001839 if (hw->phy.type == e1000_phy_ife)
1840 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001841 hw->mac.ops.led_off(hw);
1842 hw->mac.ops.cleanup_led(hw);
1843 break;
1844
1845 case ETHTOOL_ID_ON:
1846 adapter->hw.mac.ops.led_on(&adapter->hw);
1847 break;
1848
1849 case ETHTOOL_ID_OFF:
1850 adapter->hw.mac.ops.led_off(&adapter->hw);
1851 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001852 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001853 return 0;
1854}
1855
Auke Kokde5b3072008-04-23 11:09:08 -07001856static int e1000_get_coalesce(struct net_device *netdev,
1857 struct ethtool_coalesce *ec)
1858{
1859 struct e1000_adapter *adapter = netdev_priv(netdev);
1860
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001861 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07001862 ec->rx_coalesce_usecs = adapter->itr_setting;
1863 else
1864 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1865
1866 return 0;
1867}
1868
1869static int e1000_set_coalesce(struct net_device *netdev,
1870 struct ethtool_coalesce *ec)
1871{
1872 struct e1000_adapter *adapter = netdev_priv(netdev);
1873 struct e1000_hw *hw = &adapter->hw;
1874
1875 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001876 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07001877 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1878 (ec->rx_coalesce_usecs == 2))
1879 return -EINVAL;
1880
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001881 if (ec->rx_coalesce_usecs == 4) {
1882 adapter->itr = adapter->itr_setting = 4;
1883 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07001884 adapter->itr = 20000;
1885 adapter->itr_setting = ec->rx_coalesce_usecs;
1886 } else {
1887 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1888 adapter->itr_setting = adapter->itr & ~3;
1889 }
1890
1891 if (adapter->itr_setting != 0)
1892 ew32(ITR, 1000000000 / (adapter->itr * 256));
1893 else
1894 ew32(ITR, 0);
1895
1896 return 0;
1897}
1898
Auke Kokbc7f75f2007-09-17 12:30:59 -07001899static int e1000_nway_reset(struct net_device *netdev)
1900{
1901 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan5962bc22011-01-20 06:58:07 +00001902
1903 if (!netif_running(netdev))
1904 return -EAGAIN;
1905
1906 if (!adapter->hw.mac.autoneg)
1907 return -EINVAL;
1908
1909 e1000e_reinit_locked(adapter);
1910
Auke Kokbc7f75f2007-09-17 12:30:59 -07001911 return 0;
1912}
1913
Auke Kokbc7f75f2007-09-17 12:30:59 -07001914static void e1000_get_ethtool_stats(struct net_device *netdev,
1915 struct ethtool_stats *stats,
1916 u64 *data)
1917{
1918 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001919 struct rtnl_link_stats64 net_stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001920 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001921 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001922
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001923 e1000e_get_stats64(netdev, &net_stats);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001924 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001925 switch (e1000_gstrings_stats[i].type) {
1926 case NETDEV_STATS:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001927 p = (char *) &net_stats +
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001928 e1000_gstrings_stats[i].stat_offset;
1929 break;
1930 case E1000_STATS:
1931 p = (char *) adapter +
1932 e1000_gstrings_stats[i].stat_offset;
1933 break;
Bruce Allan61c75812010-12-09 23:04:25 +00001934 default:
1935 data[i] = 0;
1936 continue;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001937 }
1938
Auke Kokbc7f75f2007-09-17 12:30:59 -07001939 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1940 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1941 }
1942}
1943
1944static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1945 u8 *data)
1946{
1947 u8 *p = data;
1948 int i;
1949
1950 switch (stringset) {
1951 case ETH_SS_TEST:
Bruce Allan5c1bda02011-01-19 04:23:39 +00001952 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001953 break;
1954 case ETH_SS_STATS:
1955 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1956 memcpy(p, e1000_gstrings_stats[i].stat_string,
1957 ETH_GSTRING_LEN);
1958 p += ETH_GSTRING_LEN;
1959 }
1960 break;
1961 }
1962}
1963
1964static const struct ethtool_ops e1000_ethtool_ops = {
1965 .get_settings = e1000_get_settings,
1966 .set_settings = e1000_set_settings,
1967 .get_drvinfo = e1000_get_drvinfo,
1968 .get_regs_len = e1000_get_regs_len,
1969 .get_regs = e1000_get_regs,
1970 .get_wol = e1000_get_wol,
1971 .set_wol = e1000_set_wol,
1972 .get_msglevel = e1000_get_msglevel,
1973 .set_msglevel = e1000_set_msglevel,
1974 .nway_reset = e1000_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00001975 .get_link = ethtool_op_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001976 .get_eeprom_len = e1000_get_eeprom_len,
1977 .get_eeprom = e1000_get_eeprom,
1978 .set_eeprom = e1000_set_eeprom,
1979 .get_ringparam = e1000_get_ringparam,
1980 .set_ringparam = e1000_set_ringparam,
1981 .get_pauseparam = e1000_get_pauseparam,
1982 .set_pauseparam = e1000_set_pauseparam,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001983 .self_test = e1000_diag_test,
1984 .get_strings = e1000_get_strings,
Bruce Allandbf80dc2011-04-16 00:34:40 +00001985 .set_phys_id = e1000_set_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001986 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001987 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07001988 .get_coalesce = e1000_get_coalesce,
1989 .set_coalesce = e1000_set_coalesce,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001990};
1991
1992void e1000e_set_ethtool_ops(struct net_device *netdev)
1993{
1994 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
1995}