blob: bc02c6b91f15e8e47e5a0daa0589f2e248b7a05e [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>
32#include <linux/ethtool.h>
33#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070035#include <linux/delay.h>
36
37#include "e1000.h"
38
Ajit Khapardee0f36a92009-10-13 01:45:09 +000039enum {NETDEV_STATS, E1000_STATS};
40
Auke Kokbc7f75f2007-09-17 12:30:59 -070041struct e1000_stats {
42 char stat_string[ETH_GSTRING_LEN];
Ajit Khapardee0f36a92009-10-13 01:45:09 +000043 int type;
Auke Kokbc7f75f2007-09-17 12:30:59 -070044 int sizeof_stat;
45 int stat_offset;
46};
47
Bruce Allanf0f1a172010-12-11 05:53:32 +000048#define E1000_STAT(str, m) { \
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000049 .stat_string = str, \
50 .type = E1000_STATS, \
51 .sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
52 .stat_offset = offsetof(struct e1000_adapter, m) }
Bruce Allanf0f1a172010-12-11 05:53:32 +000053#define E1000_NETDEV_STAT(str, m) { \
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000054 .stat_string = str, \
55 .type = NETDEV_STATS, \
56 .sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \
57 .stat_offset = offsetof(struct rtnl_link_stats64, m) }
Ajit Khapardee0f36a92009-10-13 01:45:09 +000058
Auke Kokbc7f75f2007-09-17 12:30:59 -070059static const struct e1000_stats e1000_gstrings_stats[] = {
Bruce Allanf0f1a172010-12-11 05:53:32 +000060 E1000_STAT("rx_packets", stats.gprc),
61 E1000_STAT("tx_packets", stats.gptc),
62 E1000_STAT("rx_bytes", stats.gorc),
63 E1000_STAT("tx_bytes", stats.gotc),
64 E1000_STAT("rx_broadcast", stats.bprc),
65 E1000_STAT("tx_broadcast", stats.bptc),
66 E1000_STAT("rx_multicast", stats.mprc),
67 E1000_STAT("tx_multicast", stats.mptc),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000068 E1000_NETDEV_STAT("rx_errors", rx_errors),
69 E1000_NETDEV_STAT("tx_errors", tx_errors),
70 E1000_NETDEV_STAT("tx_dropped", tx_dropped),
Bruce Allanf0f1a172010-12-11 05:53:32 +000071 E1000_STAT("multicast", stats.mprc),
72 E1000_STAT("collisions", stats.colc),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000073 E1000_NETDEV_STAT("rx_length_errors", rx_length_errors),
74 E1000_NETDEV_STAT("rx_over_errors", rx_over_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000075 E1000_STAT("rx_crc_errors", stats.crcerrs),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000076 E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000077 E1000_STAT("rx_no_buffer_count", stats.rnbc),
78 E1000_STAT("rx_missed_errors", stats.mpc),
79 E1000_STAT("tx_aborted_errors", stats.ecol),
80 E1000_STAT("tx_carrier_errors", stats.tncrs),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000081 E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
82 E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000083 E1000_STAT("tx_window_errors", stats.latecol),
84 E1000_STAT("tx_abort_late_coll", stats.latecol),
85 E1000_STAT("tx_deferred_ok", stats.dc),
86 E1000_STAT("tx_single_coll_ok", stats.scc),
87 E1000_STAT("tx_multi_coll_ok", stats.mcc),
88 E1000_STAT("tx_timeout_count", tx_timeout_count),
89 E1000_STAT("tx_restart_queue", restart_queue),
90 E1000_STAT("rx_long_length_errors", stats.roc),
91 E1000_STAT("rx_short_length_errors", stats.ruc),
92 E1000_STAT("rx_align_errors", stats.algnerrc),
93 E1000_STAT("tx_tcp_seg_good", stats.tsctc),
94 E1000_STAT("tx_tcp_seg_failed", stats.tsctfc),
95 E1000_STAT("rx_flow_control_xon", stats.xonrxc),
96 E1000_STAT("rx_flow_control_xoff", stats.xoffrxc),
97 E1000_STAT("tx_flow_control_xon", stats.xontxc),
98 E1000_STAT("tx_flow_control_xoff", stats.xofftxc),
99 E1000_STAT("rx_long_byte_count", stats.gorc),
100 E1000_STAT("rx_csum_offload_good", hw_csum_good),
101 E1000_STAT("rx_csum_offload_errors", hw_csum_err),
102 E1000_STAT("rx_header_split", rx_hdr_split),
103 E1000_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),
104 E1000_STAT("tx_smbus", stats.mgptc),
105 E1000_STAT("rx_smbus", stats.mgprc),
106 E1000_STAT("dropped_smbus", stats.mgpdc),
107 E1000_STAT("rx_dma_failed", rx_dma_failed),
108 E1000_STAT("tx_dma_failed", tx_dma_failed),
Auke Kokbc7f75f2007-09-17 12:30:59 -0700109};
110
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200111#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700112#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
113static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
114 "Register test (offline)", "Eeprom test (offline)",
115 "Interrupt test (offline)", "Loopback test (offline)",
116 "Link test (on/offline)"
117};
Bruce Allanad680762008-03-28 09:15:03 -0700118#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700119
120static int e1000_get_settings(struct net_device *netdev,
121 struct ethtool_cmd *ecmd)
122{
123 struct e1000_adapter *adapter = netdev_priv(netdev);
124 struct e1000_hw *hw = &adapter->hw;
125
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700126 if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700127
128 ecmd->supported = (SUPPORTED_10baseT_Half |
129 SUPPORTED_10baseT_Full |
130 SUPPORTED_100baseT_Half |
131 SUPPORTED_100baseT_Full |
132 SUPPORTED_1000baseT_Full |
133 SUPPORTED_Autoneg |
134 SUPPORTED_TP);
135 if (hw->phy.type == e1000_phy_ife)
136 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
137 ecmd->advertising = ADVERTISED_TP;
138
139 if (hw->mac.autoneg == 1) {
140 ecmd->advertising |= ADVERTISED_Autoneg;
141 /* the e1000 autoneg seems to match ethtool nicely */
142 ecmd->advertising |= hw->phy.autoneg_advertised;
143 }
144
145 ecmd->port = PORT_TP;
146 ecmd->phy_address = hw->phy.addr;
147 ecmd->transceiver = XCVR_INTERNAL;
148
149 } else {
150 ecmd->supported = (SUPPORTED_1000baseT_Full |
151 SUPPORTED_FIBRE |
152 SUPPORTED_Autoneg);
153
154 ecmd->advertising = (ADVERTISED_1000baseT_Full |
155 ADVERTISED_FIBRE |
156 ADVERTISED_Autoneg);
157
158 ecmd->port = PORT_FIBRE;
159 ecmd->transceiver = XCVR_EXTERNAL;
160 }
161
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000162 ecmd->speed = -1;
163 ecmd->duplex = -1;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700164
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000165 if (netif_running(netdev)) {
166 if (netif_carrier_ok(netdev)) {
167 ecmd->speed = adapter->link_speed;
168 ecmd->duplex = adapter->link_duplex - 1;
169 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700170 } else {
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000171 u32 status = er32(STATUS);
172 if (status & E1000_STATUS_LU) {
173 if (status & E1000_STATUS_SPEED_1000)
174 ecmd->speed = 1000;
175 else if (status & E1000_STATUS_SPEED_100)
176 ecmd->speed = 100;
177 else
178 ecmd->speed = 10;
179
180 if (status & E1000_STATUS_FD)
181 ecmd->duplex = DUPLEX_FULL;
182 else
183 ecmd->duplex = DUPLEX_HALF;
184 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700185 }
186
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700187 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -0700188 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000189
190 /* MDI-X => 2; MDI =>1; Invalid =>0 */
191 if ((hw->phy.media_type == e1000_media_type_copper) &&
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000192 netif_carrier_ok(netdev))
Chaitanya Lala18760f12009-06-08 14:28:54 +0000193 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
194 ETH_TP_MDI;
195 else
196 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
197
Auke Kokbc7f75f2007-09-17 12:30:59 -0700198 return 0;
199}
200
201static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
202{
203 struct e1000_mac_info *mac = &adapter->hw.mac;
204
205 mac->autoneg = 0;
206
207 /* Fiber NICs only allow 1000 gbps Full duplex */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700208 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -0700209 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700210 e_err("Unsupported Speed/Duplex configuration\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700211 return -EINVAL;
212 }
213
214 switch (spddplx) {
215 case SPEED_10 + DUPLEX_HALF:
216 mac->forced_speed_duplex = ADVERTISE_10_HALF;
217 break;
218 case SPEED_10 + DUPLEX_FULL:
219 mac->forced_speed_duplex = ADVERTISE_10_FULL;
220 break;
221 case SPEED_100 + DUPLEX_HALF:
222 mac->forced_speed_duplex = ADVERTISE_100_HALF;
223 break;
224 case SPEED_100 + DUPLEX_FULL:
225 mac->forced_speed_duplex = ADVERTISE_100_FULL;
226 break;
227 case SPEED_1000 + DUPLEX_FULL:
228 mac->autoneg = 1;
229 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
230 break;
231 case SPEED_1000 + DUPLEX_HALF: /* not supported */
232 default:
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700233 e_err("Unsupported Speed/Duplex configuration\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700234 return -EINVAL;
235 }
236 return 0;
237}
238
239static int e1000_set_settings(struct net_device *netdev,
240 struct ethtool_cmd *ecmd)
241{
242 struct e1000_adapter *adapter = netdev_priv(netdev);
243 struct e1000_hw *hw = &adapter->hw;
244
Bruce Allanad680762008-03-28 09:15:03 -0700245 /*
246 * When SoL/IDER sessions are active, autoneg/speed/duplex
247 * cannot be changed
248 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700249 if (e1000_check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700250 e_err("Cannot change link characteristics when SoL/IDER is "
251 "active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700252 return -EINVAL;
253 }
254
255 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000256 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700257
258 if (ecmd->autoneg == AUTONEG_ENABLE) {
259 hw->mac.autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700260 if (hw->phy.media_type == e1000_media_type_fiber)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700261 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
262 ADVERTISED_FIBRE |
263 ADVERTISED_Autoneg;
264 else
265 hw->phy.autoneg_advertised = ecmd->advertising |
266 ADVERTISED_TP |
267 ADVERTISED_Autoneg;
268 ecmd->advertising = hw->phy.autoneg_advertised;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700269 if (adapter->fc_autoneg)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800270 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700271 } else {
David Decotigny25db0332011-04-27 18:32:39 +0000272 u32 speed = ethtool_cmd_speed(ecmd);
273 if (e1000_set_spd_dplx(adapter, speed + ecmd->duplex)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700274 clear_bit(__E1000_RESETTING, &adapter->state);
275 return -EINVAL;
276 }
277 }
278
279 /* reset the link */
280
281 if (netif_running(adapter->netdev)) {
282 e1000e_down(adapter);
283 e1000e_up(adapter);
284 } else {
285 e1000e_reset(adapter);
286 }
287
288 clear_bit(__E1000_RESETTING, &adapter->state);
289 return 0;
290}
291
292static void e1000_get_pauseparam(struct net_device *netdev,
293 struct ethtool_pauseparam *pause)
294{
295 struct e1000_adapter *adapter = netdev_priv(netdev);
296 struct e1000_hw *hw = &adapter->hw;
297
298 pause->autoneg =
299 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
300
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800301 if (hw->fc.current_mode == e1000_fc_rx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700302 pause->rx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800303 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700304 pause->tx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800305 } else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700306 pause->rx_pause = 1;
307 pause->tx_pause = 1;
308 }
309}
310
311static int e1000_set_pauseparam(struct net_device *netdev,
312 struct ethtool_pauseparam *pause)
313{
314 struct e1000_adapter *adapter = netdev_priv(netdev);
315 struct e1000_hw *hw = &adapter->hw;
316 int retval = 0;
317
318 adapter->fc_autoneg = pause->autoneg;
319
320 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000321 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700322
Auke Kokbc7f75f2007-09-17 12:30:59 -0700323 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800324 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700325 if (netif_running(adapter->netdev)) {
326 e1000e_down(adapter);
327 e1000e_up(adapter);
328 } else {
329 e1000e_reset(adapter);
330 }
331 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800332 if (pause->rx_pause && pause->tx_pause)
333 hw->fc.requested_mode = e1000_fc_full;
334 else if (pause->rx_pause && !pause->tx_pause)
335 hw->fc.requested_mode = e1000_fc_rx_pause;
336 else if (!pause->rx_pause && pause->tx_pause)
337 hw->fc.requested_mode = e1000_fc_tx_pause;
338 else if (!pause->rx_pause && !pause->tx_pause)
339 hw->fc.requested_mode = e1000_fc_none;
340
341 hw->fc.current_mode = hw->fc.requested_mode;
342
Bruce Allan945eb312009-10-28 18:28:30 +0000343 if (hw->phy.media_type == e1000_media_type_fiber) {
344 retval = hw->mac.ops.setup_link(hw);
345 /* implicit goto out */
346 } else {
347 retval = e1000e_force_mac_fc(hw);
348 if (retval)
349 goto out;
350 e1000e_set_fc_watermarks(hw);
351 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700352 }
353
Bruce Allan945eb312009-10-28 18:28:30 +0000354out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700355 clear_bit(__E1000_RESETTING, &adapter->state);
356 return retval;
357}
358
359static u32 e1000_get_rx_csum(struct net_device *netdev)
360{
361 struct e1000_adapter *adapter = netdev_priv(netdev);
Eric Dumazet807540b2010-09-23 05:40:09 +0000362 return adapter->flags & FLAG_RX_CSUM_ENABLED;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700363}
364
365static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
366{
367 struct e1000_adapter *adapter = netdev_priv(netdev);
368
369 if (data)
370 adapter->flags |= FLAG_RX_CSUM_ENABLED;
371 else
372 adapter->flags &= ~FLAG_RX_CSUM_ENABLED;
373
374 if (netif_running(netdev))
375 e1000e_reinit_locked(adapter);
376 else
377 e1000e_reset(adapter);
378 return 0;
379}
380
381static u32 e1000_get_tx_csum(struct net_device *netdev)
382{
Eric Dumazet807540b2010-09-23 05:40:09 +0000383 return (netdev->features & NETIF_F_HW_CSUM) != 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700384}
385
386static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
387{
388 if (data)
389 netdev->features |= NETIF_F_HW_CSUM;
390 else
391 netdev->features &= ~NETIF_F_HW_CSUM;
392
393 return 0;
394}
395
396static int e1000_set_tso(struct net_device *netdev, u32 data)
397{
398 struct e1000_adapter *adapter = netdev_priv(netdev);
399
400 if (data) {
401 netdev->features |= NETIF_F_TSO;
402 netdev->features |= NETIF_F_TSO6;
403 } else {
404 netdev->features &= ~NETIF_F_TSO;
405 netdev->features &= ~NETIF_F_TSO6;
406 }
407
Auke Kokbc7f75f2007-09-17 12:30:59 -0700408 adapter->flags |= FLAG_TSO_FORCE;
409 return 0;
410}
411
412static u32 e1000_get_msglevel(struct net_device *netdev)
413{
414 struct e1000_adapter *adapter = netdev_priv(netdev);
415 return adapter->msg_enable;
416}
417
418static void e1000_set_msglevel(struct net_device *netdev, u32 data)
419{
420 struct e1000_adapter *adapter = netdev_priv(netdev);
421 adapter->msg_enable = data;
422}
423
424static int e1000_get_regs_len(struct net_device *netdev)
425{
426#define E1000_REGS_LEN 32 /* overestimate */
427 return E1000_REGS_LEN * sizeof(u32);
428}
429
430static void e1000_get_regs(struct net_device *netdev,
431 struct ethtool_regs *regs, void *p)
432{
433 struct e1000_adapter *adapter = netdev_priv(netdev);
434 struct e1000_hw *hw = &adapter->hw;
435 u32 *regs_buff = p;
436 u16 phy_data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700437
438 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
439
Sergei Shtylyovff938e42011-02-28 11:57:33 -0800440 regs->version = (1 << 24) | (adapter->pdev->revision << 16) |
441 adapter->pdev->device;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700442
443 regs_buff[0] = er32(CTRL);
444 regs_buff[1] = er32(STATUS);
445
446 regs_buff[2] = er32(RCTL);
447 regs_buff[3] = er32(RDLEN);
448 regs_buff[4] = er32(RDH);
449 regs_buff[5] = er32(RDT);
450 regs_buff[6] = er32(RDTR);
451
452 regs_buff[7] = er32(TCTL);
453 regs_buff[8] = er32(TDLEN);
454 regs_buff[9] = er32(TDH);
455 regs_buff[10] = er32(TDT);
456 regs_buff[11] = er32(TIDV);
457
458 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700459
460 /* ethtool doesn't use anything past this point, so all this
461 * code is likely legacy junk for apps that may or may not
462 * exist */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700463 if (hw->phy.type == e1000_phy_m88) {
464 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
465 regs_buff[13] = (u32)phy_data; /* cable length */
466 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
467 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
468 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
469 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
470 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
471 regs_buff[18] = regs_buff[13]; /* cable polarity */
472 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
473 regs_buff[20] = regs_buff[17]; /* polarity correction */
474 /* phy receive errors */
475 regs_buff[22] = adapter->phy_stats.receive_errors;
476 regs_buff[23] = regs_buff[13]; /* mdix mode */
477 }
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700478 regs_buff[21] = 0; /* was idle_errors */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700479 e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
480 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
481 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
482}
483
484static int e1000_get_eeprom_len(struct net_device *netdev)
485{
486 struct e1000_adapter *adapter = netdev_priv(netdev);
487 return adapter->hw.nvm.word_size * 2;
488}
489
490static int e1000_get_eeprom(struct net_device *netdev,
491 struct ethtool_eeprom *eeprom, u8 *bytes)
492{
493 struct e1000_adapter *adapter = netdev_priv(netdev);
494 struct e1000_hw *hw = &adapter->hw;
495 u16 *eeprom_buff;
496 int first_word;
497 int last_word;
498 int ret_val = 0;
499 u16 i;
500
501 if (eeprom->len == 0)
502 return -EINVAL;
503
504 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
505
506 first_word = eeprom->offset >> 1;
507 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
508
509 eeprom_buff = kmalloc(sizeof(u16) *
510 (last_word - first_word + 1), GFP_KERNEL);
511 if (!eeprom_buff)
512 return -ENOMEM;
513
514 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
515 ret_val = e1000_read_nvm(hw, first_word,
516 last_word - first_word + 1,
517 eeprom_buff);
518 } else {
519 for (i = 0; i < last_word - first_word + 1; i++) {
520 ret_val = e1000_read_nvm(hw, first_word + i, 1,
521 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800522 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700523 break;
524 }
525 }
526
Bruce Allane2434552008-11-21 17:02:41 -0800527 if (ret_val) {
528 /* a read error occurred, throw away the result */
Roel Kluin8528b012009-12-01 15:54:24 +0000529 memset(eeprom_buff, 0xff, sizeof(u16) *
530 (last_word - first_word + 1));
Bruce Allane2434552008-11-21 17:02:41 -0800531 } else {
532 /* Device's eeprom is always little-endian, word addressable */
533 for (i = 0; i < last_word - first_word + 1; i++)
534 le16_to_cpus(&eeprom_buff[i]);
535 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700536
537 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
538 kfree(eeprom_buff);
539
540 return ret_val;
541}
542
543static int e1000_set_eeprom(struct net_device *netdev,
544 struct ethtool_eeprom *eeprom, u8 *bytes)
545{
546 struct e1000_adapter *adapter = netdev_priv(netdev);
547 struct e1000_hw *hw = &adapter->hw;
548 u16 *eeprom_buff;
549 void *ptr;
550 int max_len;
551 int first_word;
552 int last_word;
553 int ret_val = 0;
554 u16 i;
555
556 if (eeprom->len == 0)
557 return -EOPNOTSUPP;
558
559 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
560 return -EFAULT;
561
Bruce Allan4a770352008-10-01 17:18:35 -0700562 if (adapter->flags & FLAG_READ_ONLY_NVM)
563 return -EINVAL;
564
Auke Kokbc7f75f2007-09-17 12:30:59 -0700565 max_len = hw->nvm.word_size * 2;
566
567 first_word = eeprom->offset >> 1;
568 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
569 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
570 if (!eeprom_buff)
571 return -ENOMEM;
572
573 ptr = (void *)eeprom_buff;
574
575 if (eeprom->offset & 1) {
576 /* need read/modify/write of first changed EEPROM word */
577 /* only the second byte of the word is being modified */
578 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
579 ptr++;
580 }
581 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0))
582 /* need read/modify/write of last changed EEPROM word */
583 /* only the first byte of the word is being modified */
584 ret_val = e1000_read_nvm(hw, last_word, 1,
585 &eeprom_buff[last_word - first_word]);
586
Bruce Allane2434552008-11-21 17:02:41 -0800587 if (ret_val)
588 goto out;
589
Auke Kokbc7f75f2007-09-17 12:30:59 -0700590 /* Device's eeprom is always little-endian, word addressable */
591 for (i = 0; i < last_word - first_word + 1; i++)
592 le16_to_cpus(&eeprom_buff[i]);
593
594 memcpy(ptr, bytes, eeprom->len);
595
596 for (i = 0; i < last_word - first_word + 1; i++)
597 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
598
599 ret_val = e1000_write_nvm(hw, first_word,
600 last_word - first_word + 1, eeprom_buff);
601
Bruce Allane2434552008-11-21 17:02:41 -0800602 if (ret_val)
603 goto out;
604
Bruce Allanad680762008-03-28 09:15:03 -0700605 /*
606 * Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800607 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700608 */
Bruce Allane2434552008-11-21 17:02:41 -0800609 if ((first_word <= NVM_CHECKSUM_REG) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +0000610 (hw->mac.type == e1000_82583) ||
611 (hw->mac.type == e1000_82574) ||
612 (hw->mac.type == e1000_82573))
Bruce Allane2434552008-11-21 17:02:41 -0800613 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700614
Bruce Allane2434552008-11-21 17:02:41 -0800615out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700616 kfree(eeprom_buff);
617 return ret_val;
618}
619
620static void e1000_get_drvinfo(struct net_device *netdev,
621 struct ethtool_drvinfo *drvinfo)
622{
623 struct e1000_adapter *adapter = netdev_priv(netdev);
624 char firmware_version[32];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700625
Bruce Allane0dc4f12011-01-06 14:29:50 +0000626 strncpy(drvinfo->driver, e1000e_driver_name,
627 sizeof(drvinfo->driver) - 1);
628 strncpy(drvinfo->version, e1000e_driver_version,
629 sizeof(drvinfo->version) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700630
Bruce Allanad680762008-03-28 09:15:03 -0700631 /*
632 * EEPROM image version # is reported as firmware version # for
633 * PCI-E controllers
634 */
Bruce Allane0dc4f12011-01-06 14:29:50 +0000635 snprintf(firmware_version, sizeof(firmware_version), "%d.%d-%d",
Bruce Allan84527592008-11-21 17:00:22 -0800636 (adapter->eeprom_vers & 0xF000) >> 12,
637 (adapter->eeprom_vers & 0x0FF0) >> 4,
638 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700639
Bruce Allane0dc4f12011-01-06 14:29:50 +0000640 strncpy(drvinfo->fw_version, firmware_version,
641 sizeof(drvinfo->fw_version) - 1);
642 strncpy(drvinfo->bus_info, pci_name(adapter->pdev),
643 sizeof(drvinfo->bus_info) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700644 drvinfo->regdump_len = e1000_get_regs_len(netdev);
645 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
646}
647
648static void e1000_get_ringparam(struct net_device *netdev,
649 struct ethtool_ringparam *ring)
650{
651 struct e1000_adapter *adapter = netdev_priv(netdev);
652 struct e1000_ring *tx_ring = adapter->tx_ring;
653 struct e1000_ring *rx_ring = adapter->rx_ring;
654
655 ring->rx_max_pending = E1000_MAX_RXD;
656 ring->tx_max_pending = E1000_MAX_TXD;
657 ring->rx_mini_max_pending = 0;
658 ring->rx_jumbo_max_pending = 0;
659 ring->rx_pending = rx_ring->count;
660 ring->tx_pending = tx_ring->count;
661 ring->rx_mini_pending = 0;
662 ring->rx_jumbo_pending = 0;
663}
664
665static int e1000_set_ringparam(struct net_device *netdev,
666 struct ethtool_ringparam *ring)
667{
668 struct e1000_adapter *adapter = netdev_priv(netdev);
669 struct e1000_ring *tx_ring, *tx_old;
670 struct e1000_ring *rx_ring, *rx_old;
671 int err;
672
673 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
674 return -EINVAL;
675
676 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
Bruce Allan1bba4382011-03-19 00:27:20 +0000677 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700678
679 if (netif_running(adapter->netdev))
680 e1000e_down(adapter);
681
682 tx_old = adapter->tx_ring;
683 rx_old = adapter->rx_ring;
684
685 err = -ENOMEM;
Bruce Allan05b93212011-01-05 07:10:38 +0000686 tx_ring = kmemdup(tx_old, sizeof(struct e1000_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700687 if (!tx_ring)
688 goto err_alloc_tx;
689
Bruce Allan05b93212011-01-05 07:10:38 +0000690 rx_ring = kmemdup(rx_old, sizeof(struct e1000_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700691 if (!rx_ring)
692 goto err_alloc_rx;
693
694 adapter->tx_ring = tx_ring;
695 adapter->rx_ring = rx_ring;
696
697 rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
698 rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD));
699 rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
700
701 tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
702 tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
703 tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
704
705 if (netif_running(adapter->netdev)) {
706 /* Try to get new resources before deleting old */
707 err = e1000e_setup_rx_resources(adapter);
708 if (err)
709 goto err_setup_rx;
710 err = e1000e_setup_tx_resources(adapter);
711 if (err)
712 goto err_setup_tx;
713
Bruce Allanad680762008-03-28 09:15:03 -0700714 /*
715 * restore the old in order to free it,
716 * then add in the new
717 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700718 adapter->rx_ring = rx_old;
719 adapter->tx_ring = tx_old;
720 e1000e_free_rx_resources(adapter);
721 e1000e_free_tx_resources(adapter);
722 kfree(tx_old);
723 kfree(rx_old);
724 adapter->rx_ring = rx_ring;
725 adapter->tx_ring = tx_ring;
726 err = e1000e_up(adapter);
727 if (err)
728 goto err_setup;
729 }
730
731 clear_bit(__E1000_RESETTING, &adapter->state);
732 return 0;
733err_setup_tx:
734 e1000e_free_rx_resources(adapter);
735err_setup_rx:
736 adapter->rx_ring = rx_old;
737 adapter->tx_ring = tx_old;
738 kfree(rx_ring);
739err_alloc_rx:
740 kfree(tx_ring);
741err_alloc_tx:
742 e1000e_up(adapter);
743err_setup:
744 clear_bit(__E1000_RESETTING, &adapter->state);
745 return err;
746}
747
Bruce Allancef8c792008-04-02 13:48:23 -0700748static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
749 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800750{
Bruce Allancef8c792008-04-02 13:48:23 -0700751 u32 pat, val;
Bruce Allan64806412010-12-11 05:53:42 +0000752 static const u32 test[] = {
753 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Bruce Allancef8c792008-04-02 13:48:23 -0700754 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800755 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700756 (test[pat] & write));
757 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
758 if (val != (test[pat] & write & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700759 e_err("pattern test reg %04X failed: got 0x%08X "
760 "expected 0x%08X\n", reg + offset, val,
761 (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800762 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700763 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800764 }
765 }
Bruce Allancef8c792008-04-02 13:48:23 -0700766 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700767}
768
Joe Perches2a887192007-11-13 20:53:51 -0800769static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
770 int reg, u32 mask, u32 write)
771{
Bruce Allancef8c792008-04-02 13:48:23 -0700772 u32 val;
Joe Perches2a887192007-11-13 20:53:51 -0800773 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700774 val = __er32(&adapter->hw, reg);
775 if ((write & mask) != (val & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700776 e_err("set/check reg %04X test failed: got 0x%08X "
777 "expected 0x%08X\n", reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800778 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700779 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800780 }
Bruce Allancef8c792008-04-02 13:48:23 -0700781 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700782}
Bruce Allancef8c792008-04-02 13:48:23 -0700783#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
784 do { \
785 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
786 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800787 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700788#define REG_PATTERN_TEST(reg, mask, write) \
789 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800790
Bruce Allancef8c792008-04-02 13:48:23 -0700791#define REG_SET_AND_CHECK(reg, mask, write) \
792 do { \
793 if (reg_set_and_check(adapter, data, reg, mask, write)) \
794 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800795 } while (0)
796
Auke Kokbc7f75f2007-09-17 12:30:59 -0700797static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
798{
799 struct e1000_hw *hw = &adapter->hw;
800 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700801 u32 value;
802 u32 before;
803 u32 after;
804 u32 i;
805 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000806 u32 mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700807
Bruce Allanad680762008-03-28 09:15:03 -0700808 /*
809 * The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700810 * Some bits that get toggled are ignored.
811 */
812 switch (mac->type) {
813 /* there are several bits on newer hardware that are r/w */
814 case e1000_82571:
815 case e1000_82572:
816 case e1000_80003es2lan:
817 toggle = 0x7FFFF3FF;
818 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000819 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700820 toggle = 0x7FFFF033;
821 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700822 }
823
824 before = er32(STATUS);
825 value = (er32(STATUS) & toggle);
826 ew32(STATUS, toggle);
827 after = er32(STATUS) & toggle;
828 if (value != after) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700829 e_err("failed STATUS register test got: 0x%08X expected: "
830 "0x%08X\n", after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700831 *data = 1;
832 return 1;
833 }
834 /* restore previous status */
835 ew32(STATUS, before);
836
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700837 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700838 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
839 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
840 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
841 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
842 }
843
844 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
845 REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
846 REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF);
847 REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF);
848 REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF);
849 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
850 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
851 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
852 REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
853 REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF);
854
855 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
856
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700857 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700858 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
859 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
860
Auke Kok86582512007-10-04 15:00:08 -0700861 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
862 REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700863 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700864 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
865 REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
866 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000867 mask = 0x8003FFFF;
868 switch (mac->type) {
869 case e1000_ich10lan:
870 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000871 case e1000_pch2lan:
Bruce Allana4f58f52009-06-02 11:29:18 +0000872 mask |= (1 << 18);
873 break;
874 default:
875 break;
876 }
Auke Kok86582512007-10-04 15:00:08 -0700877 for (i = 0; i < mac->rar_entry_count; i++)
878 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
Bruce Allana4f58f52009-06-02 11:29:18 +0000879 mask, 0xFFFFFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700880
881 for (i = 0; i < mac->mta_reg_count; i++)
882 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
883
884 *data = 0;
885 return 0;
886}
887
888static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
889{
890 u16 temp;
891 u16 checksum = 0;
892 u16 i;
893
894 *data = 0;
895 /* Read and add up the contents of the EEPROM */
896 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
897 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
898 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800899 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700900 }
901 checksum += temp;
902 }
903
904 /* If Checksum is not Correct return error else test passed */
905 if ((checksum != (u16) NVM_SUM) && !(*data))
906 *data = 2;
907
908 return *data;
909}
910
911static irqreturn_t e1000_test_intr(int irq, void *data)
912{
913 struct net_device *netdev = (struct net_device *) data;
914 struct e1000_adapter *adapter = netdev_priv(netdev);
915 struct e1000_hw *hw = &adapter->hw;
916
917 adapter->test_icr |= er32(ICR);
918
919 return IRQ_HANDLED;
920}
921
922static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
923{
924 struct net_device *netdev = adapter->netdev;
925 struct e1000_hw *hw = &adapter->hw;
926 u32 mask;
927 u32 shared_int = 1;
928 u32 irq = adapter->pdev->irq;
929 int i;
Bruce Allan4662e822008-08-26 18:37:06 -0700930 int ret_val = 0;
931 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700932
933 *data = 0;
934
Bruce Allan4662e822008-08-26 18:37:06 -0700935 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
936 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
937 int_mode = adapter->int_mode;
938 e1000e_reset_interrupt_capability(adapter);
939 adapter->int_mode = E1000E_INT_MODE_LEGACY;
940 e1000e_set_interrupt_capability(adapter);
941 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700942 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800943 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700944 netdev)) {
945 shared_int = 0;
Joe Perchesa0607fd2009-11-18 23:29:17 -0800946 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700947 netdev->name, netdev)) {
948 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700949 ret_val = -1;
950 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700951 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700952 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700953
954 /* Disable all the interrupts */
955 ew32(IMC, 0xFFFFFFFF);
Bruce Allan1bba4382011-03-19 00:27:20 +0000956 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700957
958 /* Test each interrupt */
959 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700960 /* Interrupt to test */
961 mask = 1 << i;
962
Bruce Allanf4187b52008-08-26 18:36:50 -0700963 if (adapter->flags & FLAG_IS_ICH) {
964 switch (mask) {
965 case E1000_ICR_RXSEQ:
966 continue;
967 case 0x00000100:
968 if (adapter->hw.mac.type == e1000_ich8lan ||
969 adapter->hw.mac.type == e1000_ich9lan)
970 continue;
971 break;
972 default:
973 break;
974 }
975 }
976
Auke Kokbc7f75f2007-09-17 12:30:59 -0700977 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700978 /*
979 * Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700980 * the cause register and then force the same
981 * interrupt and see if one gets posted. If
982 * an interrupt was posted to the bus, the
983 * test failed.
984 */
985 adapter->test_icr = 0;
986 ew32(IMC, mask);
987 ew32(ICS, mask);
Bruce Allan1bba4382011-03-19 00:27:20 +0000988 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700989
990 if (adapter->test_icr & mask) {
991 *data = 3;
992 break;
993 }
994 }
995
Bruce Allanad680762008-03-28 09:15:03 -0700996 /*
997 * Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700998 * the cause register and then force the same
999 * interrupt and see if one gets posted. If
1000 * an interrupt was not posted to the bus, the
1001 * test failed.
1002 */
1003 adapter->test_icr = 0;
1004 ew32(IMS, mask);
1005 ew32(ICS, mask);
Bruce Allan1bba4382011-03-19 00:27:20 +00001006 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001007
1008 if (!(adapter->test_icr & mask)) {
1009 *data = 4;
1010 break;
1011 }
1012
1013 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -07001014 /*
1015 * Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001016 * the cause register and then force the other
1017 * interrupts and see if any get posted. If
1018 * an interrupt was posted to the bus, the
1019 * test failed.
1020 */
1021 adapter->test_icr = 0;
1022 ew32(IMC, ~mask & 0x00007FFF);
1023 ew32(ICS, ~mask & 0x00007FFF);
Bruce Allan1bba4382011-03-19 00:27:20 +00001024 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001025
1026 if (adapter->test_icr) {
1027 *data = 5;
1028 break;
1029 }
1030 }
1031 }
1032
1033 /* Disable all the interrupts */
1034 ew32(IMC, 0xFFFFFFFF);
Bruce Allan1bba4382011-03-19 00:27:20 +00001035 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001036
1037 /* Unhook test interrupt handler */
1038 free_irq(irq, netdev);
1039
Bruce Allan4662e822008-08-26 18:37:06 -07001040out:
1041 if (int_mode == E1000E_INT_MODE_MSIX) {
1042 e1000e_reset_interrupt_capability(adapter);
1043 adapter->int_mode = int_mode;
1044 e1000e_set_interrupt_capability(adapter);
1045 }
1046
1047 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001048}
1049
1050static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1051{
1052 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1053 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1054 struct pci_dev *pdev = adapter->pdev;
1055 int i;
1056
1057 if (tx_ring->desc && tx_ring->buffer_info) {
1058 for (i = 0; i < tx_ring->count; i++) {
1059 if (tx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001060 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001061 tx_ring->buffer_info[i].dma,
1062 tx_ring->buffer_info[i].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001063 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001064 if (tx_ring->buffer_info[i].skb)
1065 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1066 }
1067 }
1068
1069 if (rx_ring->desc && rx_ring->buffer_info) {
1070 for (i = 0; i < rx_ring->count; i++) {
1071 if (rx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001072 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001073 rx_ring->buffer_info[i].dma,
Nick Nunley0be3f552010-04-27 13:09:05 +00001074 2048, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001075 if (rx_ring->buffer_info[i].skb)
1076 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1077 }
1078 }
1079
1080 if (tx_ring->desc) {
1081 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1082 tx_ring->dma);
1083 tx_ring->desc = NULL;
1084 }
1085 if (rx_ring->desc) {
1086 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1087 rx_ring->dma);
1088 rx_ring->desc = NULL;
1089 }
1090
1091 kfree(tx_ring->buffer_info);
1092 tx_ring->buffer_info = NULL;
1093 kfree(rx_ring->buffer_info);
1094 rx_ring->buffer_info = NULL;
1095}
1096
1097static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1098{
1099 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1100 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1101 struct pci_dev *pdev = adapter->pdev;
1102 struct e1000_hw *hw = &adapter->hw;
1103 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001104 int i;
1105 int ret_val;
1106
1107 /* Setup Tx descriptor ring and Tx buffers */
1108
1109 if (!tx_ring->count)
1110 tx_ring->count = E1000_DEFAULT_TXD;
1111
Bruce Allancef8c792008-04-02 13:48:23 -07001112 tx_ring->buffer_info = kcalloc(tx_ring->count,
1113 sizeof(struct e1000_buffer),
1114 GFP_KERNEL);
1115 if (!(tx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001116 ret_val = 1;
1117 goto err_nomem;
1118 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001119
1120 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1121 tx_ring->size = ALIGN(tx_ring->size, 4096);
1122 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1123 &tx_ring->dma, GFP_KERNEL);
1124 if (!tx_ring->desc) {
1125 ret_val = 2;
1126 goto err_nomem;
1127 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001128 tx_ring->next_to_use = 0;
1129 tx_ring->next_to_clean = 0;
1130
Bruce Allancef8c792008-04-02 13:48:23 -07001131 ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001132 ew32(TDBAH, ((u64) tx_ring->dma >> 32));
Bruce Allancef8c792008-04-02 13:48:23 -07001133 ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001134 ew32(TDH, 0);
1135 ew32(TDT, 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001136 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1137 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1138 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001139
1140 for (i = 0; i < tx_ring->count; i++) {
1141 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1142 struct sk_buff *skb;
1143 unsigned int skb_size = 1024;
1144
1145 skb = alloc_skb(skb_size, GFP_KERNEL);
1146 if (!skb) {
1147 ret_val = 3;
1148 goto err_nomem;
1149 }
1150 skb_put(skb, skb_size);
1151 tx_ring->buffer_info[i].skb = skb;
1152 tx_ring->buffer_info[i].length = skb->len;
1153 tx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001154 dma_map_single(&pdev->dev, skb->data, skb->len,
1155 DMA_TO_DEVICE);
1156 if (dma_mapping_error(&pdev->dev,
1157 tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001158 ret_val = 4;
1159 goto err_nomem;
1160 }
Bruce Allancef8c792008-04-02 13:48:23 -07001161 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001162 tx_desc->lower.data = cpu_to_le32(skb->len);
1163 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1164 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001165 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001166 tx_desc->upper.data = 0;
1167 }
1168
1169 /* Setup Rx descriptor ring and Rx buffers */
1170
1171 if (!rx_ring->count)
1172 rx_ring->count = E1000_DEFAULT_RXD;
1173
Bruce Allancef8c792008-04-02 13:48:23 -07001174 rx_ring->buffer_info = kcalloc(rx_ring->count,
1175 sizeof(struct e1000_buffer),
1176 GFP_KERNEL);
1177 if (!(rx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001178 ret_val = 5;
1179 goto err_nomem;
1180 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001181
1182 rx_ring->size = rx_ring->count * sizeof(struct e1000_rx_desc);
1183 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1184 &rx_ring->dma, GFP_KERNEL);
1185 if (!rx_ring->desc) {
1186 ret_val = 6;
1187 goto err_nomem;
1188 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001189 rx_ring->next_to_use = 0;
1190 rx_ring->next_to_clean = 0;
1191
1192 rctl = er32(RCTL);
1193 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1194 ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
1195 ew32(RDBAH, ((u64) rx_ring->dma >> 32));
1196 ew32(RDLEN, rx_ring->size);
1197 ew32(RDH, 0);
1198 ew32(RDT, 0);
1199 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allancef8c792008-04-02 13:48:23 -07001200 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1201 E1000_RCTL_SBP | E1000_RCTL_SECRC |
Auke Kokbc7f75f2007-09-17 12:30:59 -07001202 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1203 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1204 ew32(RCTL, rctl);
1205
1206 for (i = 0; i < rx_ring->count; i++) {
1207 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
1208 struct sk_buff *skb;
1209
1210 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1211 if (!skb) {
1212 ret_val = 7;
1213 goto err_nomem;
1214 }
1215 skb_reserve(skb, NET_IP_ALIGN);
1216 rx_ring->buffer_info[i].skb = skb;
1217 rx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001218 dma_map_single(&pdev->dev, skb->data, 2048,
1219 DMA_FROM_DEVICE);
1220 if (dma_mapping_error(&pdev->dev,
1221 rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001222 ret_val = 8;
1223 goto err_nomem;
1224 }
1225 rx_desc->buffer_addr =
1226 cpu_to_le64(rx_ring->buffer_info[i].dma);
1227 memset(skb->data, 0x00, skb->len);
1228 }
1229
1230 return 0;
1231
1232err_nomem:
1233 e1000_free_desc_rings(adapter);
1234 return ret_val;
1235}
1236
1237static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1238{
1239 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1240 e1e_wphy(&adapter->hw, 29, 0x001F);
1241 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1242 e1e_wphy(&adapter->hw, 29, 0x001A);
1243 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1244}
1245
1246static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1247{
1248 struct e1000_hw *hw = &adapter->hw;
1249 u32 ctrl_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001250 u16 phy_reg = 0;
Bruce Allancbd006c2010-11-24 06:01:30 +00001251 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001252
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001253 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001254
Bruce Allan3af50482010-06-16 13:25:55 +00001255 if (hw->phy.type == e1000_phy_ife) {
1256 /* force 100, set loopback */
1257 e1e_wphy(hw, PHY_CONTROL, 0x6100);
Bruce Allanbb436b22009-11-20 23:24:11 +00001258
Bruce Allan3af50482010-06-16 13:25:55 +00001259 /* Now set up the MAC to the same speed/duplex as the PHY. */
1260 ctrl_reg = er32(CTRL);
1261 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1262 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1263 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1264 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1265 E1000_CTRL_FD); /* Force Duplex to FULL */
1266
1267 ew32(CTRL, ctrl_reg);
1268 udelay(500);
1269
1270 return 0;
1271 }
1272
1273 /* Specific PHY configuration for loopback */
1274 switch (hw->phy.type) {
1275 case e1000_phy_m88:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001276 /* Auto-MDI/MDIX Off */
1277 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1278 /* reset to update Auto-MDI/MDIX */
1279 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1280 /* autoneg off */
1281 e1e_wphy(hw, PHY_CONTROL, 0x8140);
Bruce Allan3af50482010-06-16 13:25:55 +00001282 break;
1283 case e1000_phy_gg82563:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001284 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
Bruce Allancef8c792008-04-02 13:48:23 -07001285 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001286 case e1000_phy_bm:
1287 /* Set Default MAC Interface speed to 1GB */
1288 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1289 phy_reg &= ~0x0007;
1290 phy_reg |= 0x006;
1291 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1292 /* Assert SW reset for above settings to take effect */
1293 e1000e_commit_phy(hw);
1294 mdelay(1);
1295 /* Force Full Duplex */
1296 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1297 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1298 /* Set Link Up (in force link) */
1299 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1300 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1301 /* Force Link */
1302 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1303 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1304 /* Set Early Link Enable */
1305 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1306 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
Bruce Allan3af50482010-06-16 13:25:55 +00001307 break;
1308 case e1000_phy_82577:
1309 case e1000_phy_82578:
1310 /* Workaround: K1 must be disabled for stable 1Gbps operation */
Bruce Allancbd006c2010-11-24 06:01:30 +00001311 ret_val = hw->phy.ops.acquire(hw);
1312 if (ret_val) {
1313 e_err("Cannot setup 1Gbps loopback.\n");
1314 return ret_val;
1315 }
Bruce Allan3af50482010-06-16 13:25:55 +00001316 e1000_configure_k1_ich8lan(hw, false);
Bruce Allancbd006c2010-11-24 06:01:30 +00001317 hw->phy.ops.release(hw);
Bruce Allan3af50482010-06-16 13:25:55 +00001318 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001319 case e1000_phy_82579:
1320 /* Disable PHY energy detect power down */
1321 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1322 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
1323 /* Disable full chip energy detect */
1324 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1325 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1326 /* Enable loopback on the PHY */
1327#define I82577_PHY_LBK_CTRL 19
1328 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1329 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001330 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001331 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001332 }
1333
Bruce Allan3af50482010-06-16 13:25:55 +00001334 /* force 1000, set loopback */
1335 e1e_wphy(hw, PHY_CONTROL, 0x4140);
1336 mdelay(250);
1337
1338 /* Now set up the MAC to the same speed/duplex as the PHY. */
1339 ctrl_reg = er32(CTRL);
1340 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1341 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1342 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1343 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1344 E1000_CTRL_FD); /* Force Duplex to FULL */
1345
1346 if (adapter->flags & FLAG_IS_ICH)
1347 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1348
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001349 if (hw->phy.media_type == e1000_media_type_copper &&
1350 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001351 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1352 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001353 /*
1354 * Set the ILOS bit on the fiber Nic if half duplex link is
1355 * detected.
1356 */
Bruce Allan90da0662011-01-06 07:02:53 +00001357 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001358 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1359 }
1360
1361 ew32(CTRL, ctrl_reg);
1362
Bruce Allanad680762008-03-28 09:15:03 -07001363 /*
1364 * Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001365 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1366 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001367 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001368 e1000_phy_disable_receiver(adapter);
1369
1370 udelay(500);
1371
1372 return 0;
1373}
1374
1375static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1376{
1377 struct e1000_hw *hw = &adapter->hw;
1378 u32 ctrl = er32(CTRL);
1379 int link = 0;
1380
1381 /* special requirements for 82571/82572 fiber adapters */
1382
Bruce Allanad680762008-03-28 09:15:03 -07001383 /*
1384 * jump through hoops to make sure link is up because serdes
1385 * link is hardwired up
1386 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001387 ctrl |= E1000_CTRL_SLU;
1388 ew32(CTRL, ctrl);
1389
1390 /* disable autoneg */
1391 ctrl = er32(TXCW);
1392 ctrl &= ~(1 << 31);
1393 ew32(TXCW, ctrl);
1394
1395 link = (er32(STATUS) & E1000_STATUS_LU);
1396
1397 if (!link) {
1398 /* set invert loss of signal */
1399 ctrl = er32(CTRL);
1400 ctrl |= E1000_CTRL_ILOS;
1401 ew32(CTRL, ctrl);
1402 }
1403
Bruce Allanad680762008-03-28 09:15:03 -07001404 /*
1405 * special write to serdes control register to enable SerDes analog
1406 * loopback
1407 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001408#define E1000_SERDES_LB_ON 0x410
1409 ew32(SCTL, E1000_SERDES_LB_ON);
Bruce Allan1bba4382011-03-19 00:27:20 +00001410 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001411
1412 return 0;
1413}
1414
1415/* only call this for fiber/serdes connections to es2lan */
1416static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1417{
1418 struct e1000_hw *hw = &adapter->hw;
1419 u32 ctrlext = er32(CTRL_EXT);
1420 u32 ctrl = er32(CTRL);
1421
Bruce Allanad680762008-03-28 09:15:03 -07001422 /*
1423 * save CTRL_EXT to restore later, reuse an empty variable (unused
1424 * on mac_type 80003es2lan)
1425 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001426 adapter->tx_fifo_head = ctrlext;
1427
1428 /* clear the serdes mode bits, putting the device into mac loopback */
1429 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1430 ew32(CTRL_EXT, ctrlext);
1431
1432 /* force speed to 1000/FD, link up */
1433 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1434 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1435 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1436 ew32(CTRL, ctrl);
1437
1438 /* set mac loopback */
1439 ctrl = er32(RCTL);
1440 ctrl |= E1000_RCTL_LBM_MAC;
1441 ew32(RCTL, ctrl);
1442
1443 /* set testing mode parameters (no need to reset later) */
1444#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1445#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1446 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001447 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001448
1449 return 0;
1450}
1451
1452static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1453{
1454 struct e1000_hw *hw = &adapter->hw;
1455 u32 rctl;
1456
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001457 if (hw->phy.media_type == e1000_media_type_fiber ||
1458 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001459 switch (hw->mac.type) {
1460 case e1000_80003es2lan:
1461 return e1000_set_es2lan_mac_loopback(adapter);
1462 break;
1463 case e1000_82571:
1464 case e1000_82572:
1465 return e1000_set_82571_fiber_loopback(adapter);
1466 break;
1467 default:
1468 rctl = er32(RCTL);
1469 rctl |= E1000_RCTL_LBM_TCVR;
1470 ew32(RCTL, rctl);
1471 return 0;
1472 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001473 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001474 return e1000_integrated_phy_loopback(adapter);
1475 }
1476
1477 return 7;
1478}
1479
1480static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1481{
1482 struct e1000_hw *hw = &adapter->hw;
1483 u32 rctl;
1484 u16 phy_reg;
1485
1486 rctl = er32(RCTL);
1487 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1488 ew32(RCTL, rctl);
1489
1490 switch (hw->mac.type) {
1491 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001492 if (hw->phy.media_type == e1000_media_type_fiber ||
1493 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001494 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001495 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001496 adapter->tx_fifo_head = 0;
1497 }
1498 /* fall through */
1499 case e1000_82571:
1500 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001501 if (hw->phy.media_type == e1000_media_type_fiber ||
1502 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001503#define E1000_SERDES_LB_OFF 0x400
1504 ew32(SCTL, E1000_SERDES_LB_OFF);
Bruce Allan1bba4382011-03-19 00:27:20 +00001505 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001506 break;
1507 }
1508 /* Fall Through */
1509 default:
1510 hw->mac.autoneg = 1;
1511 if (hw->phy.type == e1000_phy_gg82563)
1512 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1513 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1514 if (phy_reg & MII_CR_LOOPBACK) {
1515 phy_reg &= ~MII_CR_LOOPBACK;
1516 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1517 e1000e_commit_phy(hw);
1518 }
1519 break;
1520 }
1521}
1522
1523static void e1000_create_lbtest_frame(struct sk_buff *skb,
1524 unsigned int frame_size)
1525{
1526 memset(skb->data, 0xFF, frame_size);
1527 frame_size &= ~1;
1528 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1529 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1530 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1531}
1532
1533static int e1000_check_lbtest_frame(struct sk_buff *skb,
1534 unsigned int frame_size)
1535{
1536 frame_size &= ~1;
1537 if (*(skb->data + 3) == 0xFF)
1538 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1539 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1540 return 0;
1541 return 13;
1542}
1543
1544static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1545{
1546 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1547 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1548 struct pci_dev *pdev = adapter->pdev;
1549 struct e1000_hw *hw = &adapter->hw;
1550 int i, j, k, l;
1551 int lc;
1552 int good_cnt;
1553 int ret_val = 0;
1554 unsigned long time;
1555
1556 ew32(RDT, rx_ring->count - 1);
1557
Bruce Allanad680762008-03-28 09:15:03 -07001558 /*
1559 * Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001560 * The idea is to wrap the largest ring a number of times using 64
1561 * send/receive pairs during each loop
1562 */
1563
1564 if (rx_ring->count <= tx_ring->count)
1565 lc = ((tx_ring->count / 64) * 2) + 1;
1566 else
1567 lc = ((rx_ring->count / 64) * 2) + 1;
1568
1569 k = 0;
1570 l = 0;
1571 for (j = 0; j <= lc; j++) { /* loop count loop */
1572 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001573 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1574 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001575 dma_sync_single_for_device(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001576 tx_ring->buffer_info[k].dma,
1577 tx_ring->buffer_info[k].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001578 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001579 k++;
1580 if (k == tx_ring->count)
1581 k = 0;
1582 }
1583 ew32(TDT, k);
1584 msleep(200);
1585 time = jiffies; /* set the start time for the receive */
1586 good_cnt = 0;
1587 do { /* receive the sent packets */
Nick Nunley0be3f552010-04-27 13:09:05 +00001588 dma_sync_single_for_cpu(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001589 rx_ring->buffer_info[l].dma, 2048,
Nick Nunley0be3f552010-04-27 13:09:05 +00001590 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001591
1592 ret_val = e1000_check_lbtest_frame(
1593 rx_ring->buffer_info[l].skb, 1024);
1594 if (!ret_val)
1595 good_cnt++;
1596 l++;
1597 if (l == rx_ring->count)
1598 l = 0;
Bruce Allanad680762008-03-28 09:15:03 -07001599 /*
1600 * time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001601 * enough time to complete the receives, if it's
1602 * exceeded, break and error off
1603 */
1604 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1605 if (good_cnt != 64) {
1606 ret_val = 13; /* ret_val is the same as mis-compare */
1607 break;
1608 }
Bruce Allancef8c792008-04-02 13:48:23 -07001609 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001610 ret_val = 14; /* error code for time out error */
1611 break;
1612 }
1613 } /* end loop count loop */
1614 return ret_val;
1615}
1616
1617static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1618{
Bruce Allanad680762008-03-28 09:15:03 -07001619 /*
1620 * PHY loopback cannot be performed if SoL/IDER
1621 * sessions are active
1622 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001623 if (e1000_check_reset_block(&adapter->hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001624 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001625 *data = 0;
1626 goto out;
1627 }
1628
1629 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001630 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001631 goto out;
1632
1633 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001634 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001635 goto err_loopback;
1636
1637 *data = e1000_run_loopback_test(adapter);
1638 e1000_loopback_cleanup(adapter);
1639
1640err_loopback:
1641 e1000_free_desc_rings(adapter);
1642out:
1643 return *data;
1644}
1645
1646static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1647{
1648 struct e1000_hw *hw = &adapter->hw;
1649
1650 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001651 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001652 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001653 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001654
Bruce Allanad680762008-03-28 09:15:03 -07001655 /*
1656 * On some blade server designs, link establishment
1657 * could take as long as 2-3 minutes
1658 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001659 do {
1660 hw->mac.ops.check_for_link(hw);
1661 if (hw->mac.serdes_has_link)
1662 return *data;
1663 msleep(20);
1664 } while (i++ < 3750);
1665
1666 *data = 1;
1667 } else {
1668 hw->mac.ops.check_for_link(hw);
1669 if (hw->mac.autoneg)
Bruce Allan5661aeb2011-02-25 06:36:25 +00001670 /*
1671 * On some Phy/switch combinations, link establishment
1672 * can take a few seconds more than expected.
1673 */
1674 msleep(5000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001675
Bruce Allan5661aeb2011-02-25 06:36:25 +00001676 if (!(er32(STATUS) & E1000_STATUS_LU))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001677 *data = 1;
1678 }
1679 return *data;
1680}
1681
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001682static int e1000e_get_sset_count(struct net_device *netdev, int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001683{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001684 switch (sset) {
1685 case ETH_SS_TEST:
1686 return E1000_TEST_LEN;
1687 case ETH_SS_STATS:
1688 return E1000_STATS_LEN;
1689 default:
1690 return -EOPNOTSUPP;
1691 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001692}
1693
1694static void e1000_diag_test(struct net_device *netdev,
1695 struct ethtool_test *eth_test, u64 *data)
1696{
1697 struct e1000_adapter *adapter = netdev_priv(netdev);
1698 u16 autoneg_advertised;
1699 u8 forced_speed_duplex;
1700 u8 autoneg;
1701 bool if_running = netif_running(netdev);
1702
1703 set_bit(__E1000_TESTING, &adapter->state);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001704
1705 if (!if_running) {
1706 /* Get control of and reset hardware */
1707 if (adapter->flags & FLAG_HAS_AMT)
1708 e1000e_get_hw_control(adapter);
1709
1710 e1000e_power_up_phy(adapter);
1711
1712 adapter->hw.phy.autoneg_wait_to_complete = 1;
1713 e1000e_reset(adapter);
1714 adapter->hw.phy.autoneg_wait_to_complete = 0;
1715 }
1716
Auke Kokbc7f75f2007-09-17 12:30:59 -07001717 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1718 /* Offline tests */
1719
1720 /* save speed, duplex, autoneg settings */
1721 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1722 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1723 autoneg = adapter->hw.mac.autoneg;
1724
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001725 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001726
Auke Kokbc7f75f2007-09-17 12:30:59 -07001727 if (if_running)
1728 /* indicate we're in test mode */
1729 dev_close(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001730
1731 if (e1000_reg_test(adapter, &data[0]))
1732 eth_test->flags |= ETH_TEST_FL_FAILED;
1733
1734 e1000e_reset(adapter);
1735 if (e1000_eeprom_test(adapter, &data[1]))
1736 eth_test->flags |= ETH_TEST_FL_FAILED;
1737
1738 e1000e_reset(adapter);
1739 if (e1000_intr_test(adapter, &data[2]))
1740 eth_test->flags |= ETH_TEST_FL_FAILED;
1741
1742 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001743 if (e1000_loopback_test(adapter, &data[3]))
1744 eth_test->flags |= ETH_TEST_FL_FAILED;
1745
Auke Kokbc7f75f2007-09-17 12:30:59 -07001746 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001747 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001748 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001749 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001750
Carolyn Wybornyc6ce3852010-10-15 17:35:31 +00001751 if (e1000_link_test(adapter, &data[4]))
1752 eth_test->flags |= ETH_TEST_FL_FAILED;
1753
1754 /* restore speed, duplex, autoneg settings */
1755 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1756 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1757 adapter->hw.mac.autoneg = autoneg;
1758 e1000e_reset(adapter);
1759
Auke Kokbc7f75f2007-09-17 12:30:59 -07001760 clear_bit(__E1000_TESTING, &adapter->state);
1761 if (if_running)
1762 dev_open(netdev);
1763 } else {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001764 /* Online tests */
Bruce Allan11b08be2010-05-10 14:59:31 +00001765
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001766 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001767
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001768 /* register, eeprom, intr and loopback tests not run online */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001769 data[0] = 0;
1770 data[1] = 0;
1771 data[2] = 0;
1772 data[3] = 0;
1773
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001774 if (e1000_link_test(adapter, &data[4]))
1775 eth_test->flags |= ETH_TEST_FL_FAILED;
Bruce Allan11b08be2010-05-10 14:59:31 +00001776
Auke Kokbc7f75f2007-09-17 12:30:59 -07001777 clear_bit(__E1000_TESTING, &adapter->state);
1778 }
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001779
1780 if (!if_running) {
1781 e1000e_reset(adapter);
1782
1783 if (adapter->flags & FLAG_HAS_AMT)
1784 e1000e_release_hw_control(adapter);
1785 }
1786
Auke Kokbc7f75f2007-09-17 12:30:59 -07001787 msleep_interruptible(4 * 1000);
1788}
1789
1790static void e1000_get_wol(struct net_device *netdev,
1791 struct ethtool_wolinfo *wol)
1792{
1793 struct e1000_adapter *adapter = netdev_priv(netdev);
1794
1795 wol->supported = 0;
1796 wol->wolopts = 0;
1797
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001798 if (!(adapter->flags & FLAG_HAS_WOL) ||
1799 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001800 return;
1801
1802 wol->supported = WAKE_UCAST | WAKE_MCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001803 WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001804
1805 /* apply any specific unsupported masks here */
1806 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1807 wol->supported &= ~WAKE_UCAST;
1808
1809 if (adapter->wol & E1000_WUFC_EX)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001810 e_err("Interface does not support directed (unicast) "
1811 "frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001812 }
1813
1814 if (adapter->wol & E1000_WUFC_EX)
1815 wol->wolopts |= WAKE_UCAST;
1816 if (adapter->wol & E1000_WUFC_MC)
1817 wol->wolopts |= WAKE_MCAST;
1818 if (adapter->wol & E1000_WUFC_BC)
1819 wol->wolopts |= WAKE_BCAST;
1820 if (adapter->wol & E1000_WUFC_MAG)
1821 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001822 if (adapter->wol & E1000_WUFC_LNKC)
1823 wol->wolopts |= WAKE_PHY;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001824}
1825
Bruce Allan4a29e152011-03-04 09:07:01 +00001826static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001827{
1828 struct e1000_adapter *adapter = netdev_priv(netdev);
1829
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001830 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001831 !device_can_wakeup(&adapter->pdev->dev) ||
1832 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
Bruce Allan4a29e152011-03-04 09:07:01 +00001833 WAKE_MAGIC | WAKE_PHY)))
Bruce Allan1fbfca32009-11-20 23:22:01 +00001834 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001835
1836 /* these settings will always override what we currently have */
1837 adapter->wol = 0;
1838
1839 if (wol->wolopts & WAKE_UCAST)
1840 adapter->wol |= E1000_WUFC_EX;
1841 if (wol->wolopts & WAKE_MCAST)
1842 adapter->wol |= E1000_WUFC_MC;
1843 if (wol->wolopts & WAKE_BCAST)
1844 adapter->wol |= E1000_WUFC_BC;
1845 if (wol->wolopts & WAKE_MAGIC)
1846 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001847 if (wol->wolopts & WAKE_PHY)
1848 adapter->wol |= E1000_WUFC_LNKC;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001849
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001850 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1851
Auke Kokbc7f75f2007-09-17 12:30:59 -07001852 return 0;
1853}
1854
Bruce Allandbf80dc2011-04-16 00:34:40 +00001855static int e1000_set_phys_id(struct net_device *netdev,
1856 enum ethtool_phys_id_state state)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001857{
1858 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001859 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001860
Bruce Allandbf80dc2011-04-16 00:34:40 +00001861 switch (state) {
1862 case ETHTOOL_ID_ACTIVE:
1863 if (!hw->mac.ops.blink_led)
1864 return 2; /* cycle on/off twice per second */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001865
Bruce Allandbf80dc2011-04-16 00:34:40 +00001866 hw->mac.ops.blink_led(hw);
1867 break;
1868
1869 case ETHTOOL_ID_INACTIVE:
Bruce Allan4662e822008-08-26 18:37:06 -07001870 if (hw->phy.type == e1000_phy_ife)
1871 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Bruce Allandbf80dc2011-04-16 00:34:40 +00001872 hw->mac.ops.led_off(hw);
1873 hw->mac.ops.cleanup_led(hw);
1874 break;
1875
1876 case ETHTOOL_ID_ON:
1877 adapter->hw.mac.ops.led_on(&adapter->hw);
1878 break;
1879
1880 case ETHTOOL_ID_OFF:
1881 adapter->hw.mac.ops.led_off(&adapter->hw);
1882 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001883 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001884 return 0;
1885}
1886
Auke Kokde5b3072008-04-23 11:09:08 -07001887static int e1000_get_coalesce(struct net_device *netdev,
1888 struct ethtool_coalesce *ec)
1889{
1890 struct e1000_adapter *adapter = netdev_priv(netdev);
1891
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001892 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07001893 ec->rx_coalesce_usecs = adapter->itr_setting;
1894 else
1895 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1896
1897 return 0;
1898}
1899
1900static int e1000_set_coalesce(struct net_device *netdev,
1901 struct ethtool_coalesce *ec)
1902{
1903 struct e1000_adapter *adapter = netdev_priv(netdev);
1904 struct e1000_hw *hw = &adapter->hw;
1905
1906 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001907 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07001908 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1909 (ec->rx_coalesce_usecs == 2))
1910 return -EINVAL;
1911
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001912 if (ec->rx_coalesce_usecs == 4) {
1913 adapter->itr = adapter->itr_setting = 4;
1914 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07001915 adapter->itr = 20000;
1916 adapter->itr_setting = ec->rx_coalesce_usecs;
1917 } else {
1918 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1919 adapter->itr_setting = adapter->itr & ~3;
1920 }
1921
1922 if (adapter->itr_setting != 0)
1923 ew32(ITR, 1000000000 / (adapter->itr * 256));
1924 else
1925 ew32(ITR, 0);
1926
1927 return 0;
1928}
1929
Auke Kokbc7f75f2007-09-17 12:30:59 -07001930static int e1000_nway_reset(struct net_device *netdev)
1931{
1932 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan5962bc22011-01-20 06:58:07 +00001933
1934 if (!netif_running(netdev))
1935 return -EAGAIN;
1936
1937 if (!adapter->hw.mac.autoneg)
1938 return -EINVAL;
1939
1940 e1000e_reinit_locked(adapter);
1941
Auke Kokbc7f75f2007-09-17 12:30:59 -07001942 return 0;
1943}
1944
Auke Kokbc7f75f2007-09-17 12:30:59 -07001945static void e1000_get_ethtool_stats(struct net_device *netdev,
1946 struct ethtool_stats *stats,
1947 u64 *data)
1948{
1949 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001950 struct rtnl_link_stats64 net_stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001951 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001952 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001953
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001954 e1000e_get_stats64(netdev, &net_stats);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001955 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001956 switch (e1000_gstrings_stats[i].type) {
1957 case NETDEV_STATS:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001958 p = (char *) &net_stats +
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001959 e1000_gstrings_stats[i].stat_offset;
1960 break;
1961 case E1000_STATS:
1962 p = (char *) adapter +
1963 e1000_gstrings_stats[i].stat_offset;
1964 break;
Bruce Allan61c75812010-12-09 23:04:25 +00001965 default:
1966 data[i] = 0;
1967 continue;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001968 }
1969
Auke Kokbc7f75f2007-09-17 12:30:59 -07001970 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1971 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1972 }
1973}
1974
1975static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1976 u8 *data)
1977{
1978 u8 *p = data;
1979 int i;
1980
1981 switch (stringset) {
1982 case ETH_SS_TEST:
Bruce Allan5c1bda02011-01-19 04:23:39 +00001983 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001984 break;
1985 case ETH_SS_STATS:
1986 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1987 memcpy(p, e1000_gstrings_stats[i].stat_string,
1988 ETH_GSTRING_LEN);
1989 p += ETH_GSTRING_LEN;
1990 }
1991 break;
1992 }
1993}
1994
Jeff Kirsher86d70e52011-03-25 16:01:01 +00001995static int e1000e_set_flags(struct net_device *netdev, u32 data)
1996{
1997 struct e1000_adapter *adapter = netdev_priv(netdev);
1998 bool need_reset = false;
1999 int rc;
2000
2001 need_reset = (data & ETH_FLAG_RXVLAN) !=
2002 (netdev->features & NETIF_F_HW_VLAN_RX);
2003
2004 rc = ethtool_op_set_flags(netdev, data, ETH_FLAG_RXVLAN |
2005 ETH_FLAG_TXVLAN);
2006
2007 if (rc)
2008 return rc;
2009
2010 if (need_reset) {
2011 if (netif_running(netdev))
2012 e1000e_reinit_locked(adapter);
2013 else
2014 e1000e_reset(adapter);
2015 }
2016
2017 return 0;
2018}
2019
Auke Kokbc7f75f2007-09-17 12:30:59 -07002020static const struct ethtool_ops e1000_ethtool_ops = {
2021 .get_settings = e1000_get_settings,
2022 .set_settings = e1000_set_settings,
2023 .get_drvinfo = e1000_get_drvinfo,
2024 .get_regs_len = e1000_get_regs_len,
2025 .get_regs = e1000_get_regs,
2026 .get_wol = e1000_get_wol,
2027 .set_wol = e1000_set_wol,
2028 .get_msglevel = e1000_get_msglevel,
2029 .set_msglevel = e1000_set_msglevel,
2030 .nway_reset = e1000_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00002031 .get_link = ethtool_op_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002032 .get_eeprom_len = e1000_get_eeprom_len,
2033 .get_eeprom = e1000_get_eeprom,
2034 .set_eeprom = e1000_set_eeprom,
2035 .get_ringparam = e1000_get_ringparam,
2036 .set_ringparam = e1000_set_ringparam,
2037 .get_pauseparam = e1000_get_pauseparam,
2038 .set_pauseparam = e1000_set_pauseparam,
2039 .get_rx_csum = e1000_get_rx_csum,
2040 .set_rx_csum = e1000_set_rx_csum,
2041 .get_tx_csum = e1000_get_tx_csum,
2042 .set_tx_csum = e1000_set_tx_csum,
2043 .get_sg = ethtool_op_get_sg,
2044 .set_sg = ethtool_op_set_sg,
2045 .get_tso = ethtool_op_get_tso,
2046 .set_tso = e1000_set_tso,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002047 .self_test = e1000_diag_test,
2048 .get_strings = e1000_get_strings,
Bruce Allandbf80dc2011-04-16 00:34:40 +00002049 .set_phys_id = e1000_set_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002050 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07002051 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07002052 .get_coalesce = e1000_get_coalesce,
2053 .set_coalesce = e1000_set_coalesce,
Bruce Allane7d906f2009-11-20 23:22:57 +00002054 .get_flags = ethtool_op_get_flags,
Jeff Kirsher86d70e52011-03-25 16:01:01 +00002055 .set_flags = e1000e_set_flags,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002056};
2057
2058void e1000e_set_ethtool_ops(struct net_device *netdev)
2059{
2060 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
2061}