blob: 3612900b3bfe4ff091952bf7c861862c04d3dd9a [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allan451152d2010-06-16 13:28:11 +00004 Copyright(c) 1999 - 2010 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
Ajit Khapardee0f36a92009-10-13 01:45:09 +000048#define E1000_STAT(m) E1000_STATS, \
49 sizeof(((struct e1000_adapter *)0)->m), \
50 offsetof(struct e1000_adapter, m)
51#define E1000_NETDEV_STAT(m) NETDEV_STATS, \
52 sizeof(((struct net_device *)0)->m), \
53 offsetof(struct net_device, m)
54
Auke Kokbc7f75f2007-09-17 12:30:59 -070055static const struct e1000_stats e1000_gstrings_stats[] = {
56 { "rx_packets", E1000_STAT(stats.gprc) },
57 { "tx_packets", E1000_STAT(stats.gptc) },
Bruce Allan7c257692008-04-23 11:09:00 -070058 { "rx_bytes", E1000_STAT(stats.gorc) },
59 { "tx_bytes", E1000_STAT(stats.gotc) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070060 { "rx_broadcast", E1000_STAT(stats.bprc) },
61 { "tx_broadcast", E1000_STAT(stats.bptc) },
62 { "rx_multicast", E1000_STAT(stats.mprc) },
63 { "tx_multicast", E1000_STAT(stats.mptc) },
Ajit Khaparde7274c202009-10-07 02:44:26 +000064 { "rx_errors", E1000_NETDEV_STAT(stats.rx_errors) },
65 { "tx_errors", E1000_NETDEV_STAT(stats.tx_errors) },
66 { "tx_dropped", E1000_NETDEV_STAT(stats.tx_dropped) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070067 { "multicast", E1000_STAT(stats.mprc) },
68 { "collisions", E1000_STAT(stats.colc) },
Ajit Khaparde7274c202009-10-07 02:44:26 +000069 { "rx_length_errors", E1000_NETDEV_STAT(stats.rx_length_errors) },
70 { "rx_over_errors", E1000_NETDEV_STAT(stats.rx_over_errors) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070071 { "rx_crc_errors", E1000_STAT(stats.crcerrs) },
Ajit Khaparde7274c202009-10-07 02:44:26 +000072 { "rx_frame_errors", E1000_NETDEV_STAT(stats.rx_frame_errors) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070073 { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
74 { "rx_missed_errors", E1000_STAT(stats.mpc) },
75 { "tx_aborted_errors", E1000_STAT(stats.ecol) },
76 { "tx_carrier_errors", E1000_STAT(stats.tncrs) },
Ajit Khaparde7274c202009-10-07 02:44:26 +000077 { "tx_fifo_errors", E1000_NETDEV_STAT(stats.tx_fifo_errors) },
78 { "tx_heartbeat_errors", E1000_NETDEV_STAT(stats.tx_heartbeat_errors) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070079 { "tx_window_errors", E1000_STAT(stats.latecol) },
80 { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
81 { "tx_deferred_ok", E1000_STAT(stats.dc) },
82 { "tx_single_coll_ok", E1000_STAT(stats.scc) },
83 { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
84 { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
85 { "tx_restart_queue", E1000_STAT(restart_queue) },
86 { "rx_long_length_errors", E1000_STAT(stats.roc) },
87 { "rx_short_length_errors", E1000_STAT(stats.ruc) },
88 { "rx_align_errors", E1000_STAT(stats.algnerrc) },
89 { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
90 { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
91 { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
92 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
93 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
94 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
Bruce Allan7c257692008-04-23 11:09:00 -070095 { "rx_long_byte_count", E1000_STAT(stats.gorc) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070096 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
97 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
98 { "rx_header_split", E1000_STAT(rx_hdr_split) },
99 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
100 { "tx_smbus", E1000_STAT(stats.mgptc) },
101 { "rx_smbus", E1000_STAT(stats.mgprc) },
102 { "dropped_smbus", E1000_STAT(stats.mgpdc) },
103 { "rx_dma_failed", E1000_STAT(rx_dma_failed) },
104 { "tx_dma_failed", E1000_STAT(tx_dma_failed) },
105};
106
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200107#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700108#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
109static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
110 "Register test (offline)", "Eeprom test (offline)",
111 "Interrupt test (offline)", "Loopback test (offline)",
112 "Link test (on/offline)"
113};
Bruce Allanad680762008-03-28 09:15:03 -0700114#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700115
116static int e1000_get_settings(struct net_device *netdev,
117 struct ethtool_cmd *ecmd)
118{
119 struct e1000_adapter *adapter = netdev_priv(netdev);
120 struct e1000_hw *hw = &adapter->hw;
121
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700122 if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700123
124 ecmd->supported = (SUPPORTED_10baseT_Half |
125 SUPPORTED_10baseT_Full |
126 SUPPORTED_100baseT_Half |
127 SUPPORTED_100baseT_Full |
128 SUPPORTED_1000baseT_Full |
129 SUPPORTED_Autoneg |
130 SUPPORTED_TP);
131 if (hw->phy.type == e1000_phy_ife)
132 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
133 ecmd->advertising = ADVERTISED_TP;
134
135 if (hw->mac.autoneg == 1) {
136 ecmd->advertising |= ADVERTISED_Autoneg;
137 /* the e1000 autoneg seems to match ethtool nicely */
138 ecmd->advertising |= hw->phy.autoneg_advertised;
139 }
140
141 ecmd->port = PORT_TP;
142 ecmd->phy_address = hw->phy.addr;
143 ecmd->transceiver = XCVR_INTERNAL;
144
145 } else {
146 ecmd->supported = (SUPPORTED_1000baseT_Full |
147 SUPPORTED_FIBRE |
148 SUPPORTED_Autoneg);
149
150 ecmd->advertising = (ADVERTISED_1000baseT_Full |
151 ADVERTISED_FIBRE |
152 ADVERTISED_Autoneg);
153
154 ecmd->port = PORT_FIBRE;
155 ecmd->transceiver = XCVR_EXTERNAL;
156 }
157
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000158 ecmd->speed = -1;
159 ecmd->duplex = -1;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700160
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000161 if (netif_running(netdev)) {
162 if (netif_carrier_ok(netdev)) {
163 ecmd->speed = adapter->link_speed;
164 ecmd->duplex = adapter->link_duplex - 1;
165 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700166 } else {
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000167 u32 status = er32(STATUS);
168 if (status & E1000_STATUS_LU) {
169 if (status & E1000_STATUS_SPEED_1000)
170 ecmd->speed = 1000;
171 else if (status & E1000_STATUS_SPEED_100)
172 ecmd->speed = 100;
173 else
174 ecmd->speed = 10;
175
176 if (status & E1000_STATUS_FD)
177 ecmd->duplex = DUPLEX_FULL;
178 else
179 ecmd->duplex = DUPLEX_HALF;
180 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700181 }
182
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700183 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -0700184 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000185
186 /* MDI-X => 2; MDI =>1; Invalid =>0 */
187 if ((hw->phy.media_type == e1000_media_type_copper) &&
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000188 netif_carrier_ok(netdev))
Chaitanya Lala18760f12009-06-08 14:28:54 +0000189 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
190 ETH_TP_MDI;
191 else
192 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
193
Auke Kokbc7f75f2007-09-17 12:30:59 -0700194 return 0;
195}
196
197static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
198{
199 struct e1000_mac_info *mac = &adapter->hw.mac;
200
201 mac->autoneg = 0;
202
203 /* Fiber NICs only allow 1000 gbps Full duplex */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700204 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -0700205 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700206 e_err("Unsupported Speed/Duplex configuration\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700207 return -EINVAL;
208 }
209
210 switch (spddplx) {
211 case SPEED_10 + DUPLEX_HALF:
212 mac->forced_speed_duplex = ADVERTISE_10_HALF;
213 break;
214 case SPEED_10 + DUPLEX_FULL:
215 mac->forced_speed_duplex = ADVERTISE_10_FULL;
216 break;
217 case SPEED_100 + DUPLEX_HALF:
218 mac->forced_speed_duplex = ADVERTISE_100_HALF;
219 break;
220 case SPEED_100 + DUPLEX_FULL:
221 mac->forced_speed_duplex = ADVERTISE_100_FULL;
222 break;
223 case SPEED_1000 + DUPLEX_FULL:
224 mac->autoneg = 1;
225 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
226 break;
227 case SPEED_1000 + DUPLEX_HALF: /* not supported */
228 default:
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700229 e_err("Unsupported Speed/Duplex configuration\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700230 return -EINVAL;
231 }
232 return 0;
233}
234
235static int e1000_set_settings(struct net_device *netdev,
236 struct ethtool_cmd *ecmd)
237{
238 struct e1000_adapter *adapter = netdev_priv(netdev);
239 struct e1000_hw *hw = &adapter->hw;
240
Bruce Allanad680762008-03-28 09:15:03 -0700241 /*
242 * When SoL/IDER sessions are active, autoneg/speed/duplex
243 * cannot be changed
244 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700245 if (e1000_check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700246 e_err("Cannot change link characteristics when SoL/IDER is "
247 "active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700248 return -EINVAL;
249 }
250
251 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
252 msleep(1);
253
254 if (ecmd->autoneg == AUTONEG_ENABLE) {
255 hw->mac.autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700256 if (hw->phy.media_type == e1000_media_type_fiber)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700257 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
258 ADVERTISED_FIBRE |
259 ADVERTISED_Autoneg;
260 else
261 hw->phy.autoneg_advertised = ecmd->advertising |
262 ADVERTISED_TP |
263 ADVERTISED_Autoneg;
264 ecmd->advertising = hw->phy.autoneg_advertised;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700265 if (adapter->fc_autoneg)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800266 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700267 } else {
268 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
269 clear_bit(__E1000_RESETTING, &adapter->state);
270 return -EINVAL;
271 }
272 }
273
274 /* reset the link */
275
276 if (netif_running(adapter->netdev)) {
277 e1000e_down(adapter);
278 e1000e_up(adapter);
279 } else {
280 e1000e_reset(adapter);
281 }
282
283 clear_bit(__E1000_RESETTING, &adapter->state);
284 return 0;
285}
286
287static void e1000_get_pauseparam(struct net_device *netdev,
288 struct ethtool_pauseparam *pause)
289{
290 struct e1000_adapter *adapter = netdev_priv(netdev);
291 struct e1000_hw *hw = &adapter->hw;
292
293 pause->autoneg =
294 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
295
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800296 if (hw->fc.current_mode == e1000_fc_rx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700297 pause->rx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800298 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700299 pause->tx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800300 } else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700301 pause->rx_pause = 1;
302 pause->tx_pause = 1;
303 }
304}
305
306static int e1000_set_pauseparam(struct net_device *netdev,
307 struct ethtool_pauseparam *pause)
308{
309 struct e1000_adapter *adapter = netdev_priv(netdev);
310 struct e1000_hw *hw = &adapter->hw;
311 int retval = 0;
312
313 adapter->fc_autoneg = pause->autoneg;
314
315 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
316 msleep(1);
317
Auke Kokbc7f75f2007-09-17 12:30:59 -0700318 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800319 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700320 if (netif_running(adapter->netdev)) {
321 e1000e_down(adapter);
322 e1000e_up(adapter);
323 } else {
324 e1000e_reset(adapter);
325 }
326 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800327 if (pause->rx_pause && pause->tx_pause)
328 hw->fc.requested_mode = e1000_fc_full;
329 else if (pause->rx_pause && !pause->tx_pause)
330 hw->fc.requested_mode = e1000_fc_rx_pause;
331 else if (!pause->rx_pause && pause->tx_pause)
332 hw->fc.requested_mode = e1000_fc_tx_pause;
333 else if (!pause->rx_pause && !pause->tx_pause)
334 hw->fc.requested_mode = e1000_fc_none;
335
336 hw->fc.current_mode = hw->fc.requested_mode;
337
Bruce Allan945eb312009-10-28 18:28:30 +0000338 if (hw->phy.media_type == e1000_media_type_fiber) {
339 retval = hw->mac.ops.setup_link(hw);
340 /* implicit goto out */
341 } else {
342 retval = e1000e_force_mac_fc(hw);
343 if (retval)
344 goto out;
345 e1000e_set_fc_watermarks(hw);
346 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700347 }
348
Bruce Allan945eb312009-10-28 18:28:30 +0000349out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700350 clear_bit(__E1000_RESETTING, &adapter->state);
351 return retval;
352}
353
354static u32 e1000_get_rx_csum(struct net_device *netdev)
355{
356 struct e1000_adapter *adapter = netdev_priv(netdev);
Eric Dumazet807540b2010-09-23 05:40:09 +0000357 return adapter->flags & FLAG_RX_CSUM_ENABLED;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700358}
359
360static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
361{
362 struct e1000_adapter *adapter = netdev_priv(netdev);
363
364 if (data)
365 adapter->flags |= FLAG_RX_CSUM_ENABLED;
366 else
367 adapter->flags &= ~FLAG_RX_CSUM_ENABLED;
368
369 if (netif_running(netdev))
370 e1000e_reinit_locked(adapter);
371 else
372 e1000e_reset(adapter);
373 return 0;
374}
375
376static u32 e1000_get_tx_csum(struct net_device *netdev)
377{
Eric Dumazet807540b2010-09-23 05:40:09 +0000378 return (netdev->features & NETIF_F_HW_CSUM) != 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700379}
380
381static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
382{
383 if (data)
384 netdev->features |= NETIF_F_HW_CSUM;
385 else
386 netdev->features &= ~NETIF_F_HW_CSUM;
387
388 return 0;
389}
390
391static int e1000_set_tso(struct net_device *netdev, u32 data)
392{
393 struct e1000_adapter *adapter = netdev_priv(netdev);
394
395 if (data) {
396 netdev->features |= NETIF_F_TSO;
397 netdev->features |= NETIF_F_TSO6;
398 } else {
399 netdev->features &= ~NETIF_F_TSO;
400 netdev->features &= ~NETIF_F_TSO6;
401 }
402
Auke Kokbc7f75f2007-09-17 12:30:59 -0700403 adapter->flags |= FLAG_TSO_FORCE;
404 return 0;
405}
406
407static u32 e1000_get_msglevel(struct net_device *netdev)
408{
409 struct e1000_adapter *adapter = netdev_priv(netdev);
410 return adapter->msg_enable;
411}
412
413static void e1000_set_msglevel(struct net_device *netdev, u32 data)
414{
415 struct e1000_adapter *adapter = netdev_priv(netdev);
416 adapter->msg_enable = data;
417}
418
419static int e1000_get_regs_len(struct net_device *netdev)
420{
421#define E1000_REGS_LEN 32 /* overestimate */
422 return E1000_REGS_LEN * sizeof(u32);
423}
424
425static void e1000_get_regs(struct net_device *netdev,
426 struct ethtool_regs *regs, void *p)
427{
428 struct e1000_adapter *adapter = netdev_priv(netdev);
429 struct e1000_hw *hw = &adapter->hw;
430 u32 *regs_buff = p;
431 u16 phy_data;
432 u8 revision_id;
433
434 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
435
436 pci_read_config_byte(adapter->pdev, PCI_REVISION_ID, &revision_id);
437
438 regs->version = (1 << 24) | (revision_id << 16) | adapter->pdev->device;
439
440 regs_buff[0] = er32(CTRL);
441 regs_buff[1] = er32(STATUS);
442
443 regs_buff[2] = er32(RCTL);
444 regs_buff[3] = er32(RDLEN);
445 regs_buff[4] = er32(RDH);
446 regs_buff[5] = er32(RDT);
447 regs_buff[6] = er32(RDTR);
448
449 regs_buff[7] = er32(TCTL);
450 regs_buff[8] = er32(TDLEN);
451 regs_buff[9] = er32(TDH);
452 regs_buff[10] = er32(TDT);
453 regs_buff[11] = er32(TIDV);
454
455 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700456
457 /* ethtool doesn't use anything past this point, so all this
458 * code is likely legacy junk for apps that may or may not
459 * exist */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700460 if (hw->phy.type == e1000_phy_m88) {
461 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
462 regs_buff[13] = (u32)phy_data; /* cable length */
463 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
464 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
465 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
466 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
467 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
468 regs_buff[18] = regs_buff[13]; /* cable polarity */
469 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
470 regs_buff[20] = regs_buff[17]; /* polarity correction */
471 /* phy receive errors */
472 regs_buff[22] = adapter->phy_stats.receive_errors;
473 regs_buff[23] = regs_buff[13]; /* mdix mode */
474 }
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700475 regs_buff[21] = 0; /* was idle_errors */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700476 e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
477 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
478 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
479}
480
481static int e1000_get_eeprom_len(struct net_device *netdev)
482{
483 struct e1000_adapter *adapter = netdev_priv(netdev);
484 return adapter->hw.nvm.word_size * 2;
485}
486
487static int e1000_get_eeprom(struct net_device *netdev,
488 struct ethtool_eeprom *eeprom, u8 *bytes)
489{
490 struct e1000_adapter *adapter = netdev_priv(netdev);
491 struct e1000_hw *hw = &adapter->hw;
492 u16 *eeprom_buff;
493 int first_word;
494 int last_word;
495 int ret_val = 0;
496 u16 i;
497
498 if (eeprom->len == 0)
499 return -EINVAL;
500
501 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
502
503 first_word = eeprom->offset >> 1;
504 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
505
506 eeprom_buff = kmalloc(sizeof(u16) *
507 (last_word - first_word + 1), GFP_KERNEL);
508 if (!eeprom_buff)
509 return -ENOMEM;
510
511 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
512 ret_val = e1000_read_nvm(hw, first_word,
513 last_word - first_word + 1,
514 eeprom_buff);
515 } else {
516 for (i = 0; i < last_word - first_word + 1; i++) {
517 ret_val = e1000_read_nvm(hw, first_word + i, 1,
518 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800519 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700520 break;
521 }
522 }
523
Bruce Allane2434552008-11-21 17:02:41 -0800524 if (ret_val) {
525 /* a read error occurred, throw away the result */
Roel Kluin8528b012009-12-01 15:54:24 +0000526 memset(eeprom_buff, 0xff, sizeof(u16) *
527 (last_word - first_word + 1));
Bruce Allane2434552008-11-21 17:02:41 -0800528 } else {
529 /* Device's eeprom is always little-endian, word addressable */
530 for (i = 0; i < last_word - first_word + 1; i++)
531 le16_to_cpus(&eeprom_buff[i]);
532 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700533
534 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
535 kfree(eeprom_buff);
536
537 return ret_val;
538}
539
540static int e1000_set_eeprom(struct net_device *netdev,
541 struct ethtool_eeprom *eeprom, u8 *bytes)
542{
543 struct e1000_adapter *adapter = netdev_priv(netdev);
544 struct e1000_hw *hw = &adapter->hw;
545 u16 *eeprom_buff;
546 void *ptr;
547 int max_len;
548 int first_word;
549 int last_word;
550 int ret_val = 0;
551 u16 i;
552
553 if (eeprom->len == 0)
554 return -EOPNOTSUPP;
555
556 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
557 return -EFAULT;
558
Bruce Allan4a770352008-10-01 17:18:35 -0700559 if (adapter->flags & FLAG_READ_ONLY_NVM)
560 return -EINVAL;
561
Auke Kokbc7f75f2007-09-17 12:30:59 -0700562 max_len = hw->nvm.word_size * 2;
563
564 first_word = eeprom->offset >> 1;
565 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
566 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
567 if (!eeprom_buff)
568 return -ENOMEM;
569
570 ptr = (void *)eeprom_buff;
571
572 if (eeprom->offset & 1) {
573 /* need read/modify/write of first changed EEPROM word */
574 /* only the second byte of the word is being modified */
575 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
576 ptr++;
577 }
578 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0))
579 /* need read/modify/write of last changed EEPROM word */
580 /* only the first byte of the word is being modified */
581 ret_val = e1000_read_nvm(hw, last_word, 1,
582 &eeprom_buff[last_word - first_word]);
583
Bruce Allane2434552008-11-21 17:02:41 -0800584 if (ret_val)
585 goto out;
586
Auke Kokbc7f75f2007-09-17 12:30:59 -0700587 /* Device's eeprom is always little-endian, word addressable */
588 for (i = 0; i < last_word - first_word + 1; i++)
589 le16_to_cpus(&eeprom_buff[i]);
590
591 memcpy(ptr, bytes, eeprom->len);
592
593 for (i = 0; i < last_word - first_word + 1; i++)
594 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
595
596 ret_val = e1000_write_nvm(hw, first_word,
597 last_word - first_word + 1, eeprom_buff);
598
Bruce Allane2434552008-11-21 17:02:41 -0800599 if (ret_val)
600 goto out;
601
Bruce Allanad680762008-03-28 09:15:03 -0700602 /*
603 * Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800604 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700605 */
Bruce Allane2434552008-11-21 17:02:41 -0800606 if ((first_word <= NVM_CHECKSUM_REG) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +0000607 (hw->mac.type == e1000_82583) ||
608 (hw->mac.type == e1000_82574) ||
609 (hw->mac.type == e1000_82573))
Bruce Allane2434552008-11-21 17:02:41 -0800610 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700611
Bruce Allane2434552008-11-21 17:02:41 -0800612out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700613 kfree(eeprom_buff);
614 return ret_val;
615}
616
617static void e1000_get_drvinfo(struct net_device *netdev,
618 struct ethtool_drvinfo *drvinfo)
619{
620 struct e1000_adapter *adapter = netdev_priv(netdev);
621 char firmware_version[32];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700622
623 strncpy(drvinfo->driver, e1000e_driver_name, 32);
624 strncpy(drvinfo->version, e1000e_driver_version, 32);
625
Bruce Allanad680762008-03-28 09:15:03 -0700626 /*
627 * EEPROM image version # is reported as firmware version # for
628 * PCI-E controllers
629 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700630 sprintf(firmware_version, "%d.%d-%d",
Bruce Allan84527592008-11-21 17:00:22 -0800631 (adapter->eeprom_vers & 0xF000) >> 12,
632 (adapter->eeprom_vers & 0x0FF0) >> 4,
633 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700634
635 strncpy(drvinfo->fw_version, firmware_version, 32);
636 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700637 drvinfo->regdump_len = e1000_get_regs_len(netdev);
638 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
639}
640
641static void e1000_get_ringparam(struct net_device *netdev,
642 struct ethtool_ringparam *ring)
643{
644 struct e1000_adapter *adapter = netdev_priv(netdev);
645 struct e1000_ring *tx_ring = adapter->tx_ring;
646 struct e1000_ring *rx_ring = adapter->rx_ring;
647
648 ring->rx_max_pending = E1000_MAX_RXD;
649 ring->tx_max_pending = E1000_MAX_TXD;
650 ring->rx_mini_max_pending = 0;
651 ring->rx_jumbo_max_pending = 0;
652 ring->rx_pending = rx_ring->count;
653 ring->tx_pending = tx_ring->count;
654 ring->rx_mini_pending = 0;
655 ring->rx_jumbo_pending = 0;
656}
657
658static int e1000_set_ringparam(struct net_device *netdev,
659 struct ethtool_ringparam *ring)
660{
661 struct e1000_adapter *adapter = netdev_priv(netdev);
662 struct e1000_ring *tx_ring, *tx_old;
663 struct e1000_ring *rx_ring, *rx_old;
664 int err;
665
666 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
667 return -EINVAL;
668
669 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
670 msleep(1);
671
672 if (netif_running(adapter->netdev))
673 e1000e_down(adapter);
674
675 tx_old = adapter->tx_ring;
676 rx_old = adapter->rx_ring;
677
678 err = -ENOMEM;
679 tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
680 if (!tx_ring)
681 goto err_alloc_tx;
Bruce Allancef8c792008-04-02 13:48:23 -0700682 /*
683 * use a memcpy to save any previously configured
684 * items like napi structs from having to be
685 * reinitialized
686 */
687 memcpy(tx_ring, tx_old, sizeof(struct e1000_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700688
689 rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
690 if (!rx_ring)
691 goto err_alloc_rx;
Bruce Allancef8c792008-04-02 13:48:23 -0700692 memcpy(rx_ring, rx_old, sizeof(struct e1000_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700693
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;
Joe Perches2a887192007-11-13 20:53:51 -0800752 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);
956 msleep(10);
957
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);
988 msleep(10);
989
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);
1006 msleep(10);
1007
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);
1024 msleep(10);
1025
1026 if (adapter->test_icr) {
1027 *data = 5;
1028 break;
1029 }
1030 }
1031 }
1032
1033 /* Disable all the interrupts */
1034 ew32(IMC, 0xFFFFFFFF);
1035 msleep(10);
1036
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;
1250 u32 stat_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001251 u16 phy_reg = 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 */
1311 e1000_configure_k1_ich8lan(hw, false);
1312 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001313 case e1000_phy_82579:
1314 /* Disable PHY energy detect power down */
1315 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1316 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
1317 /* Disable full chip energy detect */
1318 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1319 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1320 /* Enable loopback on the PHY */
1321#define I82577_PHY_LBK_CTRL 19
1322 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1323 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001324 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001325 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001326 }
1327
Bruce Allan3af50482010-06-16 13:25:55 +00001328 /* force 1000, set loopback */
1329 e1e_wphy(hw, PHY_CONTROL, 0x4140);
1330 mdelay(250);
1331
1332 /* Now set up the MAC to the same speed/duplex as the PHY. */
1333 ctrl_reg = er32(CTRL);
1334 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1335 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1336 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1337 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1338 E1000_CTRL_FD); /* Force Duplex to FULL */
1339
1340 if (adapter->flags & FLAG_IS_ICH)
1341 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1342
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001343 if (hw->phy.media_type == e1000_media_type_copper &&
1344 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001345 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1346 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001347 /*
1348 * Set the ILOS bit on the fiber Nic if half duplex link is
1349 * detected.
1350 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001351 stat_reg = er32(STATUS);
1352 if ((stat_reg & E1000_STATUS_FD) == 0)
1353 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1354 }
1355
1356 ew32(CTRL, ctrl_reg);
1357
Bruce Allanad680762008-03-28 09:15:03 -07001358 /*
1359 * Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001360 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1361 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001362 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001363 e1000_phy_disable_receiver(adapter);
1364
1365 udelay(500);
1366
1367 return 0;
1368}
1369
1370static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1371{
1372 struct e1000_hw *hw = &adapter->hw;
1373 u32 ctrl = er32(CTRL);
1374 int link = 0;
1375
1376 /* special requirements for 82571/82572 fiber adapters */
1377
Bruce Allanad680762008-03-28 09:15:03 -07001378 /*
1379 * jump through hoops to make sure link is up because serdes
1380 * link is hardwired up
1381 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001382 ctrl |= E1000_CTRL_SLU;
1383 ew32(CTRL, ctrl);
1384
1385 /* disable autoneg */
1386 ctrl = er32(TXCW);
1387 ctrl &= ~(1 << 31);
1388 ew32(TXCW, ctrl);
1389
1390 link = (er32(STATUS) & E1000_STATUS_LU);
1391
1392 if (!link) {
1393 /* set invert loss of signal */
1394 ctrl = er32(CTRL);
1395 ctrl |= E1000_CTRL_ILOS;
1396 ew32(CTRL, ctrl);
1397 }
1398
Bruce Allanad680762008-03-28 09:15:03 -07001399 /*
1400 * special write to serdes control register to enable SerDes analog
1401 * loopback
1402 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001403#define E1000_SERDES_LB_ON 0x410
1404 ew32(SCTL, E1000_SERDES_LB_ON);
1405 msleep(10);
1406
1407 return 0;
1408}
1409
1410/* only call this for fiber/serdes connections to es2lan */
1411static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1412{
1413 struct e1000_hw *hw = &adapter->hw;
1414 u32 ctrlext = er32(CTRL_EXT);
1415 u32 ctrl = er32(CTRL);
1416
Bruce Allanad680762008-03-28 09:15:03 -07001417 /*
1418 * save CTRL_EXT to restore later, reuse an empty variable (unused
1419 * on mac_type 80003es2lan)
1420 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001421 adapter->tx_fifo_head = ctrlext;
1422
1423 /* clear the serdes mode bits, putting the device into mac loopback */
1424 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1425 ew32(CTRL_EXT, ctrlext);
1426
1427 /* force speed to 1000/FD, link up */
1428 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1429 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1430 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1431 ew32(CTRL, ctrl);
1432
1433 /* set mac loopback */
1434 ctrl = er32(RCTL);
1435 ctrl |= E1000_RCTL_LBM_MAC;
1436 ew32(RCTL, ctrl);
1437
1438 /* set testing mode parameters (no need to reset later) */
1439#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1440#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1441 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001442 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001443
1444 return 0;
1445}
1446
1447static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1448{
1449 struct e1000_hw *hw = &adapter->hw;
1450 u32 rctl;
1451
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001452 if (hw->phy.media_type == e1000_media_type_fiber ||
1453 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001454 switch (hw->mac.type) {
1455 case e1000_80003es2lan:
1456 return e1000_set_es2lan_mac_loopback(adapter);
1457 break;
1458 case e1000_82571:
1459 case e1000_82572:
1460 return e1000_set_82571_fiber_loopback(adapter);
1461 break;
1462 default:
1463 rctl = er32(RCTL);
1464 rctl |= E1000_RCTL_LBM_TCVR;
1465 ew32(RCTL, rctl);
1466 return 0;
1467 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001468 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001469 return e1000_integrated_phy_loopback(adapter);
1470 }
1471
1472 return 7;
1473}
1474
1475static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1476{
1477 struct e1000_hw *hw = &adapter->hw;
1478 u32 rctl;
1479 u16 phy_reg;
1480
1481 rctl = er32(RCTL);
1482 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1483 ew32(RCTL, rctl);
1484
1485 switch (hw->mac.type) {
1486 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001487 if (hw->phy.media_type == e1000_media_type_fiber ||
1488 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001489 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001490 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001491 adapter->tx_fifo_head = 0;
1492 }
1493 /* fall through */
1494 case e1000_82571:
1495 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001496 if (hw->phy.media_type == e1000_media_type_fiber ||
1497 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001498#define E1000_SERDES_LB_OFF 0x400
1499 ew32(SCTL, E1000_SERDES_LB_OFF);
1500 msleep(10);
1501 break;
1502 }
1503 /* Fall Through */
1504 default:
1505 hw->mac.autoneg = 1;
1506 if (hw->phy.type == e1000_phy_gg82563)
1507 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1508 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1509 if (phy_reg & MII_CR_LOOPBACK) {
1510 phy_reg &= ~MII_CR_LOOPBACK;
1511 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1512 e1000e_commit_phy(hw);
1513 }
1514 break;
1515 }
1516}
1517
1518static void e1000_create_lbtest_frame(struct sk_buff *skb,
1519 unsigned int frame_size)
1520{
1521 memset(skb->data, 0xFF, frame_size);
1522 frame_size &= ~1;
1523 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1524 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1525 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1526}
1527
1528static int e1000_check_lbtest_frame(struct sk_buff *skb,
1529 unsigned int frame_size)
1530{
1531 frame_size &= ~1;
1532 if (*(skb->data + 3) == 0xFF)
1533 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1534 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1535 return 0;
1536 return 13;
1537}
1538
1539static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1540{
1541 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1542 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1543 struct pci_dev *pdev = adapter->pdev;
1544 struct e1000_hw *hw = &adapter->hw;
1545 int i, j, k, l;
1546 int lc;
1547 int good_cnt;
1548 int ret_val = 0;
1549 unsigned long time;
1550
1551 ew32(RDT, rx_ring->count - 1);
1552
Bruce Allanad680762008-03-28 09:15:03 -07001553 /*
1554 * Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001555 * The idea is to wrap the largest ring a number of times using 64
1556 * send/receive pairs during each loop
1557 */
1558
1559 if (rx_ring->count <= tx_ring->count)
1560 lc = ((tx_ring->count / 64) * 2) + 1;
1561 else
1562 lc = ((rx_ring->count / 64) * 2) + 1;
1563
1564 k = 0;
1565 l = 0;
1566 for (j = 0; j <= lc; j++) { /* loop count loop */
1567 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001568 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1569 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001570 dma_sync_single_for_device(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001571 tx_ring->buffer_info[k].dma,
1572 tx_ring->buffer_info[k].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001573 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001574 k++;
1575 if (k == tx_ring->count)
1576 k = 0;
1577 }
1578 ew32(TDT, k);
1579 msleep(200);
1580 time = jiffies; /* set the start time for the receive */
1581 good_cnt = 0;
1582 do { /* receive the sent packets */
Nick Nunley0be3f552010-04-27 13:09:05 +00001583 dma_sync_single_for_cpu(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001584 rx_ring->buffer_info[l].dma, 2048,
Nick Nunley0be3f552010-04-27 13:09:05 +00001585 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001586
1587 ret_val = e1000_check_lbtest_frame(
1588 rx_ring->buffer_info[l].skb, 1024);
1589 if (!ret_val)
1590 good_cnt++;
1591 l++;
1592 if (l == rx_ring->count)
1593 l = 0;
Bruce Allanad680762008-03-28 09:15:03 -07001594 /*
1595 * time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001596 * enough time to complete the receives, if it's
1597 * exceeded, break and error off
1598 */
1599 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1600 if (good_cnt != 64) {
1601 ret_val = 13; /* ret_val is the same as mis-compare */
1602 break;
1603 }
Bruce Allancef8c792008-04-02 13:48:23 -07001604 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001605 ret_val = 14; /* error code for time out error */
1606 break;
1607 }
1608 } /* end loop count loop */
1609 return ret_val;
1610}
1611
1612static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1613{
Bruce Allanad680762008-03-28 09:15:03 -07001614 /*
1615 * PHY loopback cannot be performed if SoL/IDER
1616 * sessions are active
1617 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001618 if (e1000_check_reset_block(&adapter->hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001619 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001620 *data = 0;
1621 goto out;
1622 }
1623
1624 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001625 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001626 goto out;
1627
1628 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001629 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001630 goto err_loopback;
1631
1632 *data = e1000_run_loopback_test(adapter);
1633 e1000_loopback_cleanup(adapter);
1634
1635err_loopback:
1636 e1000_free_desc_rings(adapter);
1637out:
1638 return *data;
1639}
1640
1641static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1642{
1643 struct e1000_hw *hw = &adapter->hw;
1644
1645 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001646 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001647 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001648 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001649
Bruce Allanad680762008-03-28 09:15:03 -07001650 /*
1651 * On some blade server designs, link establishment
1652 * could take as long as 2-3 minutes
1653 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001654 do {
1655 hw->mac.ops.check_for_link(hw);
1656 if (hw->mac.serdes_has_link)
1657 return *data;
1658 msleep(20);
1659 } while (i++ < 3750);
1660
1661 *data = 1;
1662 } else {
1663 hw->mac.ops.check_for_link(hw);
1664 if (hw->mac.autoneg)
1665 msleep(4000);
1666
1667 if (!(er32(STATUS) &
1668 E1000_STATUS_LU))
1669 *data = 1;
1670 }
1671 return *data;
1672}
1673
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001674static int e1000e_get_sset_count(struct net_device *netdev, int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001675{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001676 switch (sset) {
1677 case ETH_SS_TEST:
1678 return E1000_TEST_LEN;
1679 case ETH_SS_STATS:
1680 return E1000_STATS_LEN;
1681 default:
1682 return -EOPNOTSUPP;
1683 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001684}
1685
1686static void e1000_diag_test(struct net_device *netdev,
1687 struct ethtool_test *eth_test, u64 *data)
1688{
1689 struct e1000_adapter *adapter = netdev_priv(netdev);
1690 u16 autoneg_advertised;
1691 u8 forced_speed_duplex;
1692 u8 autoneg;
1693 bool if_running = netif_running(netdev);
1694
1695 set_bit(__E1000_TESTING, &adapter->state);
1696 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1697 /* Offline tests */
1698
1699 /* save speed, duplex, autoneg settings */
1700 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1701 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1702 autoneg = adapter->hw.mac.autoneg;
1703
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001704 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001705
Auke Kokbc7f75f2007-09-17 12:30:59 -07001706 if (if_running)
1707 /* indicate we're in test mode */
1708 dev_close(netdev);
1709 else
1710 e1000e_reset(adapter);
1711
1712 if (e1000_reg_test(adapter, &data[0]))
1713 eth_test->flags |= ETH_TEST_FL_FAILED;
1714
1715 e1000e_reset(adapter);
1716 if (e1000_eeprom_test(adapter, &data[1]))
1717 eth_test->flags |= ETH_TEST_FL_FAILED;
1718
1719 e1000e_reset(adapter);
1720 if (e1000_intr_test(adapter, &data[2]))
1721 eth_test->flags |= ETH_TEST_FL_FAILED;
1722
1723 e1000e_reset(adapter);
1724 /* make sure the phy is powered up */
1725 e1000e_power_up_phy(adapter);
1726 if (e1000_loopback_test(adapter, &data[3]))
1727 eth_test->flags |= ETH_TEST_FL_FAILED;
1728
Auke Kokbc7f75f2007-09-17 12:30:59 -07001729 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001730 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001731 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001732 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001733
Carolyn Wybornyc6ce3852010-10-15 17:35:31 +00001734 if (e1000_link_test(adapter, &data[4]))
1735 eth_test->flags |= ETH_TEST_FL_FAILED;
1736
1737 /* restore speed, duplex, autoneg settings */
1738 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1739 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1740 adapter->hw.mac.autoneg = autoneg;
1741 e1000e_reset(adapter);
1742
Auke Kokbc7f75f2007-09-17 12:30:59 -07001743 clear_bit(__E1000_TESTING, &adapter->state);
1744 if (if_running)
1745 dev_open(netdev);
1746 } else {
Bruce Allan11b08be2010-05-10 14:59:31 +00001747 if (!if_running && (adapter->flags & FLAG_HAS_AMT)) {
1748 clear_bit(__E1000_TESTING, &adapter->state);
1749 dev_open(netdev);
1750 set_bit(__E1000_TESTING, &adapter->state);
1751 }
1752
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001753 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001754 /* Online tests */
1755 if (e1000_link_test(adapter, &data[4]))
1756 eth_test->flags |= ETH_TEST_FL_FAILED;
1757
1758 /* Online tests aren't run; pass by default */
1759 data[0] = 0;
1760 data[1] = 0;
1761 data[2] = 0;
1762 data[3] = 0;
1763
Bruce Allan11b08be2010-05-10 14:59:31 +00001764 if (!if_running && (adapter->flags & FLAG_HAS_AMT))
1765 dev_close(netdev);
1766
Auke Kokbc7f75f2007-09-17 12:30:59 -07001767 clear_bit(__E1000_TESTING, &adapter->state);
1768 }
1769 msleep_interruptible(4 * 1000);
1770}
1771
1772static void e1000_get_wol(struct net_device *netdev,
1773 struct ethtool_wolinfo *wol)
1774{
1775 struct e1000_adapter *adapter = netdev_priv(netdev);
1776
1777 wol->supported = 0;
1778 wol->wolopts = 0;
1779
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001780 if (!(adapter->flags & FLAG_HAS_WOL) ||
1781 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001782 return;
1783
1784 wol->supported = WAKE_UCAST | WAKE_MCAST |
Mitch Williamsefb90e42008-01-29 12:43:02 -08001785 WAKE_BCAST | WAKE_MAGIC |
1786 WAKE_PHY | WAKE_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001787
1788 /* apply any specific unsupported masks here */
1789 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1790 wol->supported &= ~WAKE_UCAST;
1791
1792 if (adapter->wol & E1000_WUFC_EX)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001793 e_err("Interface does not support directed (unicast) "
1794 "frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001795 }
1796
1797 if (adapter->wol & E1000_WUFC_EX)
1798 wol->wolopts |= WAKE_UCAST;
1799 if (adapter->wol & E1000_WUFC_MC)
1800 wol->wolopts |= WAKE_MCAST;
1801 if (adapter->wol & E1000_WUFC_BC)
1802 wol->wolopts |= WAKE_BCAST;
1803 if (adapter->wol & E1000_WUFC_MAG)
1804 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001805 if (adapter->wol & E1000_WUFC_LNKC)
1806 wol->wolopts |= WAKE_PHY;
1807 if (adapter->wol & E1000_WUFC_ARP)
1808 wol->wolopts |= WAKE_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001809}
1810
1811static int e1000_set_wol(struct net_device *netdev,
1812 struct ethtool_wolinfo *wol)
1813{
1814 struct e1000_adapter *adapter = netdev_priv(netdev);
1815
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001816 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001817 !device_can_wakeup(&adapter->pdev->dev) ||
1818 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
1819 WAKE_MAGIC | WAKE_PHY | WAKE_ARP)))
1820 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001821
1822 /* these settings will always override what we currently have */
1823 adapter->wol = 0;
1824
1825 if (wol->wolopts & WAKE_UCAST)
1826 adapter->wol |= E1000_WUFC_EX;
1827 if (wol->wolopts & WAKE_MCAST)
1828 adapter->wol |= E1000_WUFC_MC;
1829 if (wol->wolopts & WAKE_BCAST)
1830 adapter->wol |= E1000_WUFC_BC;
1831 if (wol->wolopts & WAKE_MAGIC)
1832 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001833 if (wol->wolopts & WAKE_PHY)
1834 adapter->wol |= E1000_WUFC_LNKC;
1835 if (wol->wolopts & WAKE_ARP)
1836 adapter->wol |= E1000_WUFC_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001837
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001838 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1839
Auke Kokbc7f75f2007-09-17 12:30:59 -07001840 return 0;
1841}
1842
1843/* toggle LED 4 times per second = 2 "blinks" per second */
1844#define E1000_ID_INTERVAL (HZ/4)
1845
1846/* bit defines for adapter->led_status */
1847#define E1000_LED_ON 0
1848
Bruce Allana4f58f52009-06-02 11:29:18 +00001849static void e1000e_led_blink_task(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001850{
Bruce Allana4f58f52009-06-02 11:29:18 +00001851 struct e1000_adapter *adapter = container_of(work,
1852 struct e1000_adapter, led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001853
1854 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
1855 adapter->hw.mac.ops.led_off(&adapter->hw);
1856 else
1857 adapter->hw.mac.ops.led_on(&adapter->hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001858}
Auke Kokbc7f75f2007-09-17 12:30:59 -07001859
Bruce Allana4f58f52009-06-02 11:29:18 +00001860static void e1000_led_blink_callback(unsigned long data)
1861{
1862 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1863
1864 schedule_work(&adapter->led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001865 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1866}
1867
1868static int e1000_phys_id(struct net_device *netdev, u32 data)
1869{
1870 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001871 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001872
Stephen Hemminger5a9147b2007-10-29 10:46:05 -07001873 if (!data)
1874 data = INT_MAX;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001875
Bruce Allan4662e822008-08-26 18:37:06 -07001876 if ((hw->phy.type == e1000_phy_ife) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00001877 (hw->mac.type == e1000_pchlan) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00001878 (hw->mac.type == e1000_pch2lan) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +00001879 (hw->mac.type == e1000_82583) ||
Bruce Allan4662e822008-08-26 18:37:06 -07001880 (hw->mac.type == e1000_82574)) {
Bruce Allana4f58f52009-06-02 11:29:18 +00001881 INIT_WORK(&adapter->led_blink_task, e1000e_led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001882 if (!adapter->blink_timer.function) {
1883 init_timer(&adapter->blink_timer);
1884 adapter->blink_timer.function =
1885 e1000_led_blink_callback;
1886 adapter->blink_timer.data = (unsigned long) adapter;
1887 }
1888 mod_timer(&adapter->blink_timer, jiffies);
1889 msleep_interruptible(data * 1000);
1890 del_timer_sync(&adapter->blink_timer);
Bruce Allan4662e822008-08-26 18:37:06 -07001891 if (hw->phy.type == e1000_phy_ife)
1892 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001893 } else {
Bruce Allan4662e822008-08-26 18:37:06 -07001894 e1000e_blink_led(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001895 msleep_interruptible(data * 1000);
1896 }
1897
Bruce Allan4662e822008-08-26 18:37:06 -07001898 hw->mac.ops.led_off(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001899 clear_bit(E1000_LED_ON, &adapter->led_status);
Bruce Allan4662e822008-08-26 18:37:06 -07001900 hw->mac.ops.cleanup_led(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001901
1902 return 0;
1903}
1904
Auke Kokde5b3072008-04-23 11:09:08 -07001905static int e1000_get_coalesce(struct net_device *netdev,
1906 struct ethtool_coalesce *ec)
1907{
1908 struct e1000_adapter *adapter = netdev_priv(netdev);
1909
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001910 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07001911 ec->rx_coalesce_usecs = adapter->itr_setting;
1912 else
1913 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1914
1915 return 0;
1916}
1917
1918static int e1000_set_coalesce(struct net_device *netdev,
1919 struct ethtool_coalesce *ec)
1920{
1921 struct e1000_adapter *adapter = netdev_priv(netdev);
1922 struct e1000_hw *hw = &adapter->hw;
1923
1924 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001925 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07001926 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1927 (ec->rx_coalesce_usecs == 2))
1928 return -EINVAL;
1929
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001930 if (ec->rx_coalesce_usecs == 4) {
1931 adapter->itr = adapter->itr_setting = 4;
1932 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07001933 adapter->itr = 20000;
1934 adapter->itr_setting = ec->rx_coalesce_usecs;
1935 } else {
1936 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1937 adapter->itr_setting = adapter->itr & ~3;
1938 }
1939
1940 if (adapter->itr_setting != 0)
1941 ew32(ITR, 1000000000 / (adapter->itr * 256));
1942 else
1943 ew32(ITR, 0);
1944
1945 return 0;
1946}
1947
Auke Kokbc7f75f2007-09-17 12:30:59 -07001948static int e1000_nway_reset(struct net_device *netdev)
1949{
1950 struct e1000_adapter *adapter = netdev_priv(netdev);
1951 if (netif_running(netdev))
1952 e1000e_reinit_locked(adapter);
1953 return 0;
1954}
1955
Auke Kokbc7f75f2007-09-17 12:30:59 -07001956static void e1000_get_ethtool_stats(struct net_device *netdev,
1957 struct ethtool_stats *stats,
1958 u64 *data)
1959{
1960 struct e1000_adapter *adapter = netdev_priv(netdev);
1961 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001962 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001963
1964 e1000e_update_stats(adapter);
1965 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001966 switch (e1000_gstrings_stats[i].type) {
1967 case NETDEV_STATS:
1968 p = (char *) netdev +
1969 e1000_gstrings_stats[i].stat_offset;
1970 break;
1971 case E1000_STATS:
1972 p = (char *) adapter +
1973 e1000_gstrings_stats[i].stat_offset;
1974 break;
1975 }
1976
Auke Kokbc7f75f2007-09-17 12:30:59 -07001977 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1978 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1979 }
1980}
1981
1982static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1983 u8 *data)
1984{
1985 u8 *p = data;
1986 int i;
1987
1988 switch (stringset) {
1989 case ETH_SS_TEST:
Bruce Allanad680762008-03-28 09:15:03 -07001990 memcpy(data, *e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001991 break;
1992 case ETH_SS_STATS:
1993 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1994 memcpy(p, e1000_gstrings_stats[i].stat_string,
1995 ETH_GSTRING_LEN);
1996 p += ETH_GSTRING_LEN;
1997 }
1998 break;
1999 }
2000}
2001
2002static const struct ethtool_ops e1000_ethtool_ops = {
2003 .get_settings = e1000_get_settings,
2004 .set_settings = e1000_set_settings,
2005 .get_drvinfo = e1000_get_drvinfo,
2006 .get_regs_len = e1000_get_regs_len,
2007 .get_regs = e1000_get_regs,
2008 .get_wol = e1000_get_wol,
2009 .set_wol = e1000_set_wol,
2010 .get_msglevel = e1000_get_msglevel,
2011 .set_msglevel = e1000_set_msglevel,
2012 .nway_reset = e1000_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00002013 .get_link = ethtool_op_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002014 .get_eeprom_len = e1000_get_eeprom_len,
2015 .get_eeprom = e1000_get_eeprom,
2016 .set_eeprom = e1000_set_eeprom,
2017 .get_ringparam = e1000_get_ringparam,
2018 .set_ringparam = e1000_set_ringparam,
2019 .get_pauseparam = e1000_get_pauseparam,
2020 .set_pauseparam = e1000_set_pauseparam,
2021 .get_rx_csum = e1000_get_rx_csum,
2022 .set_rx_csum = e1000_set_rx_csum,
2023 .get_tx_csum = e1000_get_tx_csum,
2024 .set_tx_csum = e1000_set_tx_csum,
2025 .get_sg = ethtool_op_get_sg,
2026 .set_sg = ethtool_op_set_sg,
2027 .get_tso = ethtool_op_get_tso,
2028 .set_tso = e1000_set_tso,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002029 .self_test = e1000_diag_test,
2030 .get_strings = e1000_get_strings,
2031 .phys_id = e1000_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002032 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07002033 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07002034 .get_coalesce = e1000_get_coalesce,
2035 .set_coalesce = e1000_set_coalesce,
Bruce Allane7d906f2009-11-20 23:22:57 +00002036 .get_flags = ethtool_op_get_flags,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002037};
2038
2039void e1000e_set_ethtool_ops(struct net_device *netdev)
2040{
2041 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
2042}