blob: fd7921482d2bbb7bd24cc197db0a2d689727df5b [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanad680762008-03-28 09:15:03 -07004 Copyright(c) 1999 - 2008 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>
34#include <linux/delay.h>
35
36#include "e1000.h"
37
Ajit Khapardee0f36a92009-10-13 01:45:09 +000038enum {NETDEV_STATS, E1000_STATS};
39
Auke Kokbc7f75f2007-09-17 12:30:59 -070040struct e1000_stats {
41 char stat_string[ETH_GSTRING_LEN];
Ajit Khapardee0f36a92009-10-13 01:45:09 +000042 int type;
Auke Kokbc7f75f2007-09-17 12:30:59 -070043 int sizeof_stat;
44 int stat_offset;
45};
46
Ajit Khapardee0f36a92009-10-13 01:45:09 +000047#define E1000_STAT(m) E1000_STATS, \
48 sizeof(((struct e1000_adapter *)0)->m), \
49 offsetof(struct e1000_adapter, m)
50#define E1000_NETDEV_STAT(m) NETDEV_STATS, \
51 sizeof(((struct net_device *)0)->m), \
52 offsetof(struct net_device, m)
53
Auke Kokbc7f75f2007-09-17 12:30:59 -070054static const struct e1000_stats e1000_gstrings_stats[] = {
55 { "rx_packets", E1000_STAT(stats.gprc) },
56 { "tx_packets", E1000_STAT(stats.gptc) },
Bruce Allan7c257692008-04-23 11:09:00 -070057 { "rx_bytes", E1000_STAT(stats.gorc) },
58 { "tx_bytes", E1000_STAT(stats.gotc) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070059 { "rx_broadcast", E1000_STAT(stats.bprc) },
60 { "tx_broadcast", E1000_STAT(stats.bptc) },
61 { "rx_multicast", E1000_STAT(stats.mprc) },
62 { "tx_multicast", E1000_STAT(stats.mptc) },
Ajit Khaparde7274c202009-10-07 02:44:26 +000063 { "rx_errors", E1000_NETDEV_STAT(stats.rx_errors) },
64 { "tx_errors", E1000_NETDEV_STAT(stats.tx_errors) },
65 { "tx_dropped", E1000_NETDEV_STAT(stats.tx_dropped) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070066 { "multicast", E1000_STAT(stats.mprc) },
67 { "collisions", E1000_STAT(stats.colc) },
Ajit Khaparde7274c202009-10-07 02:44:26 +000068 { "rx_length_errors", E1000_NETDEV_STAT(stats.rx_length_errors) },
69 { "rx_over_errors", E1000_NETDEV_STAT(stats.rx_over_errors) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070070 { "rx_crc_errors", E1000_STAT(stats.crcerrs) },
Ajit Khaparde7274c202009-10-07 02:44:26 +000071 { "rx_frame_errors", E1000_NETDEV_STAT(stats.rx_frame_errors) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070072 { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
73 { "rx_missed_errors", E1000_STAT(stats.mpc) },
74 { "tx_aborted_errors", E1000_STAT(stats.ecol) },
75 { "tx_carrier_errors", E1000_STAT(stats.tncrs) },
Ajit Khaparde7274c202009-10-07 02:44:26 +000076 { "tx_fifo_errors", E1000_NETDEV_STAT(stats.tx_fifo_errors) },
77 { "tx_heartbeat_errors", E1000_NETDEV_STAT(stats.tx_heartbeat_errors) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070078 { "tx_window_errors", E1000_STAT(stats.latecol) },
79 { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
80 { "tx_deferred_ok", E1000_STAT(stats.dc) },
81 { "tx_single_coll_ok", E1000_STAT(stats.scc) },
82 { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
83 { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
84 { "tx_restart_queue", E1000_STAT(restart_queue) },
85 { "rx_long_length_errors", E1000_STAT(stats.roc) },
86 { "rx_short_length_errors", E1000_STAT(stats.ruc) },
87 { "rx_align_errors", E1000_STAT(stats.algnerrc) },
88 { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
89 { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
90 { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
91 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
92 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
93 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
Bruce Allan7c257692008-04-23 11:09:00 -070094 { "rx_long_byte_count", E1000_STAT(stats.gorc) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070095 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
96 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
97 { "rx_header_split", E1000_STAT(rx_hdr_split) },
98 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
99 { "tx_smbus", E1000_STAT(stats.mgptc) },
100 { "rx_smbus", E1000_STAT(stats.mgprc) },
101 { "dropped_smbus", E1000_STAT(stats.mgpdc) },
102 { "rx_dma_failed", E1000_STAT(rx_dma_failed) },
103 { "tx_dma_failed", E1000_STAT(tx_dma_failed) },
104};
105
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200106#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700107#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
108static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
109 "Register test (offline)", "Eeprom test (offline)",
110 "Interrupt test (offline)", "Loopback test (offline)",
111 "Link test (on/offline)"
112};
Bruce Allanad680762008-03-28 09:15:03 -0700113#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700114
115static int e1000_get_settings(struct net_device *netdev,
116 struct ethtool_cmd *ecmd)
117{
118 struct e1000_adapter *adapter = netdev_priv(netdev);
119 struct e1000_hw *hw = &adapter->hw;
Auke Kok369d7422007-10-15 14:30:59 -0700120 u32 status;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700121
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
Auke Kok369d7422007-10-15 14:30:59 -0700158 status = er32(STATUS);
159 if (status & E1000_STATUS_LU) {
160 if (status & E1000_STATUS_SPEED_1000)
161 ecmd->speed = 1000;
162 else if (status & E1000_STATUS_SPEED_100)
163 ecmd->speed = 100;
164 else
165 ecmd->speed = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700166
Auke Kok369d7422007-10-15 14:30:59 -0700167 if (status & E1000_STATUS_FD)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700168 ecmd->duplex = DUPLEX_FULL;
169 else
170 ecmd->duplex = DUPLEX_HALF;
171 } else {
172 ecmd->speed = -1;
173 ecmd->duplex = -1;
174 }
175
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700176 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -0700177 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000178
179 /* MDI-X => 2; MDI =>1; Invalid =>0 */
180 if ((hw->phy.media_type == e1000_media_type_copper) &&
181 !hw->mac.get_link_status)
182 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
183 ETH_TP_MDI;
184 else
185 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
186
Auke Kokbc7f75f2007-09-17 12:30:59 -0700187 return 0;
188}
189
Auke Kok369d7422007-10-15 14:30:59 -0700190static u32 e1000_get_link(struct net_device *netdev)
191{
192 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan7ea96552009-11-20 23:23:34 +0000193 struct e1000_mac_info *mac = &adapter->hw.mac;
194
195 /*
196 * If the link is not reported up to netdev, interrupts are disabled,
197 * and so the physical link state may have changed since we last
198 * looked. Set get_link_status to make sure that the true link
199 * state is interrogated, rather than pulling a cached and possibly
200 * stale link state from the driver.
201 */
202 if (!netif_carrier_ok(netdev))
203 mac->get_link_status = 1;
Bruce Allana20e4cf2008-11-21 17:01:35 -0800204
205 return e1000_has_link(adapter);
Auke Kok369d7422007-10-15 14:30:59 -0700206}
207
Auke Kokbc7f75f2007-09-17 12:30:59 -0700208static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
209{
210 struct e1000_mac_info *mac = &adapter->hw.mac;
211
212 mac->autoneg = 0;
213
214 /* Fiber NICs only allow 1000 gbps Full duplex */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700215 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -0700216 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700217 e_err("Unsupported Speed/Duplex configuration\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700218 return -EINVAL;
219 }
220
221 switch (spddplx) {
222 case SPEED_10 + DUPLEX_HALF:
223 mac->forced_speed_duplex = ADVERTISE_10_HALF;
224 break;
225 case SPEED_10 + DUPLEX_FULL:
226 mac->forced_speed_duplex = ADVERTISE_10_FULL;
227 break;
228 case SPEED_100 + DUPLEX_HALF:
229 mac->forced_speed_duplex = ADVERTISE_100_HALF;
230 break;
231 case SPEED_100 + DUPLEX_FULL:
232 mac->forced_speed_duplex = ADVERTISE_100_FULL;
233 break;
234 case SPEED_1000 + DUPLEX_FULL:
235 mac->autoneg = 1;
236 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
237 break;
238 case SPEED_1000 + DUPLEX_HALF: /* not supported */
239 default:
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700240 e_err("Unsupported Speed/Duplex configuration\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700241 return -EINVAL;
242 }
243 return 0;
244}
245
246static int e1000_set_settings(struct net_device *netdev,
247 struct ethtool_cmd *ecmd)
248{
249 struct e1000_adapter *adapter = netdev_priv(netdev);
250 struct e1000_hw *hw = &adapter->hw;
251
Bruce Allanad680762008-03-28 09:15:03 -0700252 /*
253 * When SoL/IDER sessions are active, autoneg/speed/duplex
254 * cannot be changed
255 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700256 if (e1000_check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700257 e_err("Cannot change link characteristics when SoL/IDER is "
258 "active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700259 return -EINVAL;
260 }
261
262 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
263 msleep(1);
264
265 if (ecmd->autoneg == AUTONEG_ENABLE) {
266 hw->mac.autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700267 if (hw->phy.media_type == e1000_media_type_fiber)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700268 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
269 ADVERTISED_FIBRE |
270 ADVERTISED_Autoneg;
271 else
272 hw->phy.autoneg_advertised = ecmd->advertising |
273 ADVERTISED_TP |
274 ADVERTISED_Autoneg;
275 ecmd->advertising = hw->phy.autoneg_advertised;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700276 if (adapter->fc_autoneg)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800277 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700278 } else {
279 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
280 clear_bit(__E1000_RESETTING, &adapter->state);
281 return -EINVAL;
282 }
283 }
284
285 /* reset the link */
286
287 if (netif_running(adapter->netdev)) {
288 e1000e_down(adapter);
289 e1000e_up(adapter);
290 } else {
291 e1000e_reset(adapter);
292 }
293
294 clear_bit(__E1000_RESETTING, &adapter->state);
295 return 0;
296}
297
298static void e1000_get_pauseparam(struct net_device *netdev,
299 struct ethtool_pauseparam *pause)
300{
301 struct e1000_adapter *adapter = netdev_priv(netdev);
302 struct e1000_hw *hw = &adapter->hw;
303
304 pause->autoneg =
305 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
306
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800307 if (hw->fc.current_mode == e1000_fc_rx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700308 pause->rx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800309 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700310 pause->tx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800311 } else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700312 pause->rx_pause = 1;
313 pause->tx_pause = 1;
314 }
315}
316
317static int e1000_set_pauseparam(struct net_device *netdev,
318 struct ethtool_pauseparam *pause)
319{
320 struct e1000_adapter *adapter = netdev_priv(netdev);
321 struct e1000_hw *hw = &adapter->hw;
322 int retval = 0;
323
324 adapter->fc_autoneg = pause->autoneg;
325
326 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
327 msleep(1);
328
Auke Kokbc7f75f2007-09-17 12:30:59 -0700329 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800330 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700331 if (netif_running(adapter->netdev)) {
332 e1000e_down(adapter);
333 e1000e_up(adapter);
334 } else {
335 e1000e_reset(adapter);
336 }
337 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800338 if (pause->rx_pause && pause->tx_pause)
339 hw->fc.requested_mode = e1000_fc_full;
340 else if (pause->rx_pause && !pause->tx_pause)
341 hw->fc.requested_mode = e1000_fc_rx_pause;
342 else if (!pause->rx_pause && pause->tx_pause)
343 hw->fc.requested_mode = e1000_fc_tx_pause;
344 else if (!pause->rx_pause && !pause->tx_pause)
345 hw->fc.requested_mode = e1000_fc_none;
346
347 hw->fc.current_mode = hw->fc.requested_mode;
348
Bruce Allan945eb312009-10-28 18:28:30 +0000349 if (hw->phy.media_type == e1000_media_type_fiber) {
350 retval = hw->mac.ops.setup_link(hw);
351 /* implicit goto out */
352 } else {
353 retval = e1000e_force_mac_fc(hw);
354 if (retval)
355 goto out;
356 e1000e_set_fc_watermarks(hw);
357 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700358 }
359
Bruce Allan945eb312009-10-28 18:28:30 +0000360out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700361 clear_bit(__E1000_RESETTING, &adapter->state);
362 return retval;
363}
364
365static u32 e1000_get_rx_csum(struct net_device *netdev)
366{
367 struct e1000_adapter *adapter = netdev_priv(netdev);
368 return (adapter->flags & FLAG_RX_CSUM_ENABLED);
369}
370
371static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
372{
373 struct e1000_adapter *adapter = netdev_priv(netdev);
374
375 if (data)
376 adapter->flags |= FLAG_RX_CSUM_ENABLED;
377 else
378 adapter->flags &= ~FLAG_RX_CSUM_ENABLED;
379
380 if (netif_running(netdev))
381 e1000e_reinit_locked(adapter);
382 else
383 e1000e_reset(adapter);
384 return 0;
385}
386
387static u32 e1000_get_tx_csum(struct net_device *netdev)
388{
389 return ((netdev->features & NETIF_F_HW_CSUM) != 0);
390}
391
392static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
393{
394 if (data)
395 netdev->features |= NETIF_F_HW_CSUM;
396 else
397 netdev->features &= ~NETIF_F_HW_CSUM;
398
399 return 0;
400}
401
402static int e1000_set_tso(struct net_device *netdev, u32 data)
403{
404 struct e1000_adapter *adapter = netdev_priv(netdev);
405
406 if (data) {
407 netdev->features |= NETIF_F_TSO;
408 netdev->features |= NETIF_F_TSO6;
409 } else {
410 netdev->features &= ~NETIF_F_TSO;
411 netdev->features &= ~NETIF_F_TSO6;
412 }
413
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700414 e_info("TSO is %s\n", data ? "Enabled" : "Disabled");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700415 adapter->flags |= FLAG_TSO_FORCE;
416 return 0;
417}
418
419static u32 e1000_get_msglevel(struct net_device *netdev)
420{
421 struct e1000_adapter *adapter = netdev_priv(netdev);
422 return adapter->msg_enable;
423}
424
425static void e1000_set_msglevel(struct net_device *netdev, u32 data)
426{
427 struct e1000_adapter *adapter = netdev_priv(netdev);
428 adapter->msg_enable = data;
429}
430
431static int e1000_get_regs_len(struct net_device *netdev)
432{
433#define E1000_REGS_LEN 32 /* overestimate */
434 return E1000_REGS_LEN * sizeof(u32);
435}
436
437static void e1000_get_regs(struct net_device *netdev,
438 struct ethtool_regs *regs, void *p)
439{
440 struct e1000_adapter *adapter = netdev_priv(netdev);
441 struct e1000_hw *hw = &adapter->hw;
442 u32 *regs_buff = p;
443 u16 phy_data;
444 u8 revision_id;
445
446 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
447
448 pci_read_config_byte(adapter->pdev, PCI_REVISION_ID, &revision_id);
449
450 regs->version = (1 << 24) | (revision_id << 16) | adapter->pdev->device;
451
452 regs_buff[0] = er32(CTRL);
453 regs_buff[1] = er32(STATUS);
454
455 regs_buff[2] = er32(RCTL);
456 regs_buff[3] = er32(RDLEN);
457 regs_buff[4] = er32(RDH);
458 regs_buff[5] = er32(RDT);
459 regs_buff[6] = er32(RDTR);
460
461 regs_buff[7] = er32(TCTL);
462 regs_buff[8] = er32(TDLEN);
463 regs_buff[9] = er32(TDH);
464 regs_buff[10] = er32(TDT);
465 regs_buff[11] = er32(TIDV);
466
467 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700468
469 /* ethtool doesn't use anything past this point, so all this
470 * code is likely legacy junk for apps that may or may not
471 * exist */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700472 if (hw->phy.type == e1000_phy_m88) {
473 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
474 regs_buff[13] = (u32)phy_data; /* cable length */
475 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
476 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
477 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
478 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
479 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
480 regs_buff[18] = regs_buff[13]; /* cable polarity */
481 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
482 regs_buff[20] = regs_buff[17]; /* polarity correction */
483 /* phy receive errors */
484 regs_buff[22] = adapter->phy_stats.receive_errors;
485 regs_buff[23] = regs_buff[13]; /* mdix mode */
486 }
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700487 regs_buff[21] = 0; /* was idle_errors */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700488 e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
489 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
490 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
491}
492
493static int e1000_get_eeprom_len(struct net_device *netdev)
494{
495 struct e1000_adapter *adapter = netdev_priv(netdev);
496 return adapter->hw.nvm.word_size * 2;
497}
498
499static int e1000_get_eeprom(struct net_device *netdev,
500 struct ethtool_eeprom *eeprom, u8 *bytes)
501{
502 struct e1000_adapter *adapter = netdev_priv(netdev);
503 struct e1000_hw *hw = &adapter->hw;
504 u16 *eeprom_buff;
505 int first_word;
506 int last_word;
507 int ret_val = 0;
508 u16 i;
509
510 if (eeprom->len == 0)
511 return -EINVAL;
512
513 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
514
515 first_word = eeprom->offset >> 1;
516 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
517
518 eeprom_buff = kmalloc(sizeof(u16) *
519 (last_word - first_word + 1), GFP_KERNEL);
520 if (!eeprom_buff)
521 return -ENOMEM;
522
523 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
524 ret_val = e1000_read_nvm(hw, first_word,
525 last_word - first_word + 1,
526 eeprom_buff);
527 } else {
528 for (i = 0; i < last_word - first_word + 1; i++) {
529 ret_val = e1000_read_nvm(hw, first_word + i, 1,
530 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800531 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700532 break;
533 }
534 }
535
Bruce Allane2434552008-11-21 17:02:41 -0800536 if (ret_val) {
537 /* a read error occurred, throw away the result */
538 memset(eeprom_buff, 0xff, sizeof(eeprom_buff));
539 } else {
540 /* Device's eeprom is always little-endian, word addressable */
541 for (i = 0; i < last_word - first_word + 1; i++)
542 le16_to_cpus(&eeprom_buff[i]);
543 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700544
545 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
546 kfree(eeprom_buff);
547
548 return ret_val;
549}
550
551static int e1000_set_eeprom(struct net_device *netdev,
552 struct ethtool_eeprom *eeprom, u8 *bytes)
553{
554 struct e1000_adapter *adapter = netdev_priv(netdev);
555 struct e1000_hw *hw = &adapter->hw;
556 u16 *eeprom_buff;
557 void *ptr;
558 int max_len;
559 int first_word;
560 int last_word;
561 int ret_val = 0;
562 u16 i;
563
564 if (eeprom->len == 0)
565 return -EOPNOTSUPP;
566
567 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
568 return -EFAULT;
569
Bruce Allan4a770352008-10-01 17:18:35 -0700570 if (adapter->flags & FLAG_READ_ONLY_NVM)
571 return -EINVAL;
572
Auke Kokbc7f75f2007-09-17 12:30:59 -0700573 max_len = hw->nvm.word_size * 2;
574
575 first_word = eeprom->offset >> 1;
576 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
577 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
578 if (!eeprom_buff)
579 return -ENOMEM;
580
581 ptr = (void *)eeprom_buff;
582
583 if (eeprom->offset & 1) {
584 /* need read/modify/write of first changed EEPROM word */
585 /* only the second byte of the word is being modified */
586 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
587 ptr++;
588 }
589 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0))
590 /* need read/modify/write of last changed EEPROM word */
591 /* only the first byte of the word is being modified */
592 ret_val = e1000_read_nvm(hw, last_word, 1,
593 &eeprom_buff[last_word - first_word]);
594
Bruce Allane2434552008-11-21 17:02:41 -0800595 if (ret_val)
596 goto out;
597
Auke Kokbc7f75f2007-09-17 12:30:59 -0700598 /* Device's eeprom is always little-endian, word addressable */
599 for (i = 0; i < last_word - first_word + 1; i++)
600 le16_to_cpus(&eeprom_buff[i]);
601
602 memcpy(ptr, bytes, eeprom->len);
603
604 for (i = 0; i < last_word - first_word + 1; i++)
605 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
606
607 ret_val = e1000_write_nvm(hw, first_word,
608 last_word - first_word + 1, eeprom_buff);
609
Bruce Allane2434552008-11-21 17:02:41 -0800610 if (ret_val)
611 goto out;
612
Bruce Allanad680762008-03-28 09:15:03 -0700613 /*
614 * Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800615 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700616 */
Bruce Allane2434552008-11-21 17:02:41 -0800617 if ((first_word <= NVM_CHECKSUM_REG) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +0000618 (hw->mac.type == e1000_82583) ||
619 (hw->mac.type == e1000_82574) ||
620 (hw->mac.type == e1000_82573))
Bruce Allane2434552008-11-21 17:02:41 -0800621 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700622
Bruce Allane2434552008-11-21 17:02:41 -0800623out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700624 kfree(eeprom_buff);
625 return ret_val;
626}
627
628static void e1000_get_drvinfo(struct net_device *netdev,
629 struct ethtool_drvinfo *drvinfo)
630{
631 struct e1000_adapter *adapter = netdev_priv(netdev);
632 char firmware_version[32];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700633
634 strncpy(drvinfo->driver, e1000e_driver_name, 32);
635 strncpy(drvinfo->version, e1000e_driver_version, 32);
636
Bruce Allanad680762008-03-28 09:15:03 -0700637 /*
638 * EEPROM image version # is reported as firmware version # for
639 * PCI-E controllers
640 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700641 sprintf(firmware_version, "%d.%d-%d",
Bruce Allan84527592008-11-21 17:00:22 -0800642 (adapter->eeprom_vers & 0xF000) >> 12,
643 (adapter->eeprom_vers & 0x0FF0) >> 4,
644 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700645
646 strncpy(drvinfo->fw_version, firmware_version, 32);
647 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700648 drvinfo->regdump_len = e1000_get_regs_len(netdev);
649 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
650}
651
652static void e1000_get_ringparam(struct net_device *netdev,
653 struct ethtool_ringparam *ring)
654{
655 struct e1000_adapter *adapter = netdev_priv(netdev);
656 struct e1000_ring *tx_ring = adapter->tx_ring;
657 struct e1000_ring *rx_ring = adapter->rx_ring;
658
659 ring->rx_max_pending = E1000_MAX_RXD;
660 ring->tx_max_pending = E1000_MAX_TXD;
661 ring->rx_mini_max_pending = 0;
662 ring->rx_jumbo_max_pending = 0;
663 ring->rx_pending = rx_ring->count;
664 ring->tx_pending = tx_ring->count;
665 ring->rx_mini_pending = 0;
666 ring->rx_jumbo_pending = 0;
667}
668
669static int e1000_set_ringparam(struct net_device *netdev,
670 struct ethtool_ringparam *ring)
671{
672 struct e1000_adapter *adapter = netdev_priv(netdev);
673 struct e1000_ring *tx_ring, *tx_old;
674 struct e1000_ring *rx_ring, *rx_old;
675 int err;
676
677 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
678 return -EINVAL;
679
680 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
681 msleep(1);
682
683 if (netif_running(adapter->netdev))
684 e1000e_down(adapter);
685
686 tx_old = adapter->tx_ring;
687 rx_old = adapter->rx_ring;
688
689 err = -ENOMEM;
690 tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
691 if (!tx_ring)
692 goto err_alloc_tx;
Bruce Allancef8c792008-04-02 13:48:23 -0700693 /*
694 * use a memcpy to save any previously configured
695 * items like napi structs from having to be
696 * reinitialized
697 */
698 memcpy(tx_ring, tx_old, sizeof(struct e1000_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700699
700 rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
701 if (!rx_ring)
702 goto err_alloc_rx;
Bruce Allancef8c792008-04-02 13:48:23 -0700703 memcpy(rx_ring, rx_old, sizeof(struct e1000_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700704
705 adapter->tx_ring = tx_ring;
706 adapter->rx_ring = rx_ring;
707
708 rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
709 rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD));
710 rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
711
712 tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
713 tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
714 tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
715
716 if (netif_running(adapter->netdev)) {
717 /* Try to get new resources before deleting old */
718 err = e1000e_setup_rx_resources(adapter);
719 if (err)
720 goto err_setup_rx;
721 err = e1000e_setup_tx_resources(adapter);
722 if (err)
723 goto err_setup_tx;
724
Bruce Allanad680762008-03-28 09:15:03 -0700725 /*
726 * restore the old in order to free it,
727 * then add in the new
728 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700729 adapter->rx_ring = rx_old;
730 adapter->tx_ring = tx_old;
731 e1000e_free_rx_resources(adapter);
732 e1000e_free_tx_resources(adapter);
733 kfree(tx_old);
734 kfree(rx_old);
735 adapter->rx_ring = rx_ring;
736 adapter->tx_ring = tx_ring;
737 err = e1000e_up(adapter);
738 if (err)
739 goto err_setup;
740 }
741
742 clear_bit(__E1000_RESETTING, &adapter->state);
743 return 0;
744err_setup_tx:
745 e1000e_free_rx_resources(adapter);
746err_setup_rx:
747 adapter->rx_ring = rx_old;
748 adapter->tx_ring = tx_old;
749 kfree(rx_ring);
750err_alloc_rx:
751 kfree(tx_ring);
752err_alloc_tx:
753 e1000e_up(adapter);
754err_setup:
755 clear_bit(__E1000_RESETTING, &adapter->state);
756 return err;
757}
758
Bruce Allancef8c792008-04-02 13:48:23 -0700759static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
760 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800761{
Bruce Allancef8c792008-04-02 13:48:23 -0700762 u32 pat, val;
Joe Perches2a887192007-11-13 20:53:51 -0800763 static const u32 test[] =
764 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Bruce Allancef8c792008-04-02 13:48:23 -0700765 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800766 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700767 (test[pat] & write));
768 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
769 if (val != (test[pat] & write & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700770 e_err("pattern test reg %04X failed: got 0x%08X "
771 "expected 0x%08X\n", reg + offset, val,
772 (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800773 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700774 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800775 }
776 }
Bruce Allancef8c792008-04-02 13:48:23 -0700777 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700778}
779
Joe Perches2a887192007-11-13 20:53:51 -0800780static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
781 int reg, u32 mask, u32 write)
782{
Bruce Allancef8c792008-04-02 13:48:23 -0700783 u32 val;
Joe Perches2a887192007-11-13 20:53:51 -0800784 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700785 val = __er32(&adapter->hw, reg);
786 if ((write & mask) != (val & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700787 e_err("set/check reg %04X test failed: got 0x%08X "
788 "expected 0x%08X\n", reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800789 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700790 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800791 }
Bruce Allancef8c792008-04-02 13:48:23 -0700792 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700793}
Bruce Allancef8c792008-04-02 13:48:23 -0700794#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
795 do { \
796 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
797 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800798 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700799#define REG_PATTERN_TEST(reg, mask, write) \
800 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800801
Bruce Allancef8c792008-04-02 13:48:23 -0700802#define REG_SET_AND_CHECK(reg, mask, write) \
803 do { \
804 if (reg_set_and_check(adapter, data, reg, mask, write)) \
805 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800806 } while (0)
807
Auke Kokbc7f75f2007-09-17 12:30:59 -0700808static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
809{
810 struct e1000_hw *hw = &adapter->hw;
811 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700812 u32 value;
813 u32 before;
814 u32 after;
815 u32 i;
816 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000817 u32 mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700818
Bruce Allanad680762008-03-28 09:15:03 -0700819 /*
820 * The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700821 * Some bits that get toggled are ignored.
822 */
823 switch (mac->type) {
824 /* there are several bits on newer hardware that are r/w */
825 case e1000_82571:
826 case e1000_82572:
827 case e1000_80003es2lan:
828 toggle = 0x7FFFF3FF;
829 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000830 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700831 toggle = 0x7FFFF033;
832 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700833 }
834
835 before = er32(STATUS);
836 value = (er32(STATUS) & toggle);
837 ew32(STATUS, toggle);
838 after = er32(STATUS) & toggle;
839 if (value != after) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700840 e_err("failed STATUS register test got: 0x%08X expected: "
841 "0x%08X\n", after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700842 *data = 1;
843 return 1;
844 }
845 /* restore previous status */
846 ew32(STATUS, before);
847
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700848 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700849 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
850 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
851 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
852 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
853 }
854
855 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
856 REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
857 REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF);
858 REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF);
859 REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF);
860 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
861 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
862 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
863 REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
864 REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF);
865
866 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
867
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700868 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700869 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
870 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
871
Auke Kok86582512007-10-04 15:00:08 -0700872 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
873 REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700874 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700875 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
876 REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
877 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000878 mask = 0x8003FFFF;
879 switch (mac->type) {
880 case e1000_ich10lan:
881 case e1000_pchlan:
882 mask |= (1 << 18);
883 break;
884 default:
885 break;
886 }
Auke Kok86582512007-10-04 15:00:08 -0700887 for (i = 0; i < mac->rar_entry_count; i++)
888 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
Bruce Allana4f58f52009-06-02 11:29:18 +0000889 mask, 0xFFFFFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700890
891 for (i = 0; i < mac->mta_reg_count; i++)
892 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
893
894 *data = 0;
895 return 0;
896}
897
898static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
899{
900 u16 temp;
901 u16 checksum = 0;
902 u16 i;
903
904 *data = 0;
905 /* Read and add up the contents of the EEPROM */
906 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
907 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
908 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800909 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700910 }
911 checksum += temp;
912 }
913
914 /* If Checksum is not Correct return error else test passed */
915 if ((checksum != (u16) NVM_SUM) && !(*data))
916 *data = 2;
917
918 return *data;
919}
920
921static irqreturn_t e1000_test_intr(int irq, void *data)
922{
923 struct net_device *netdev = (struct net_device *) data;
924 struct e1000_adapter *adapter = netdev_priv(netdev);
925 struct e1000_hw *hw = &adapter->hw;
926
927 adapter->test_icr |= er32(ICR);
928
929 return IRQ_HANDLED;
930}
931
932static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
933{
934 struct net_device *netdev = adapter->netdev;
935 struct e1000_hw *hw = &adapter->hw;
936 u32 mask;
937 u32 shared_int = 1;
938 u32 irq = adapter->pdev->irq;
939 int i;
Bruce Allan4662e822008-08-26 18:37:06 -0700940 int ret_val = 0;
941 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700942
943 *data = 0;
944
Bruce Allan4662e822008-08-26 18:37:06 -0700945 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
946 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
947 int_mode = adapter->int_mode;
948 e1000e_reset_interrupt_capability(adapter);
949 adapter->int_mode = E1000E_INT_MODE_LEGACY;
950 e1000e_set_interrupt_capability(adapter);
951 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700952 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800953 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700954 netdev)) {
955 shared_int = 0;
Joe Perchesa0607fd2009-11-18 23:29:17 -0800956 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700957 netdev->name, netdev)) {
958 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700959 ret_val = -1;
960 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700961 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700962 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700963
964 /* Disable all the interrupts */
965 ew32(IMC, 0xFFFFFFFF);
966 msleep(10);
967
968 /* Test each interrupt */
969 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700970 /* Interrupt to test */
971 mask = 1 << i;
972
Bruce Allanf4187b52008-08-26 18:36:50 -0700973 if (adapter->flags & FLAG_IS_ICH) {
974 switch (mask) {
975 case E1000_ICR_RXSEQ:
976 continue;
977 case 0x00000100:
978 if (adapter->hw.mac.type == e1000_ich8lan ||
979 adapter->hw.mac.type == e1000_ich9lan)
980 continue;
981 break;
982 default:
983 break;
984 }
985 }
986
Auke Kokbc7f75f2007-09-17 12:30:59 -0700987 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700988 /*
989 * Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700990 * the cause register and then force the same
991 * interrupt and see if one gets posted. If
992 * an interrupt was posted to the bus, the
993 * test failed.
994 */
995 adapter->test_icr = 0;
996 ew32(IMC, mask);
997 ew32(ICS, mask);
998 msleep(10);
999
1000 if (adapter->test_icr & mask) {
1001 *data = 3;
1002 break;
1003 }
1004 }
1005
Bruce Allanad680762008-03-28 09:15:03 -07001006 /*
1007 * Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001008 * the cause register and then force the same
1009 * interrupt and see if one gets posted. If
1010 * an interrupt was not posted to the bus, the
1011 * test failed.
1012 */
1013 adapter->test_icr = 0;
1014 ew32(IMS, mask);
1015 ew32(ICS, mask);
1016 msleep(10);
1017
1018 if (!(adapter->test_icr & mask)) {
1019 *data = 4;
1020 break;
1021 }
1022
1023 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -07001024 /*
1025 * Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001026 * the cause register and then force the other
1027 * interrupts and see if any get posted. If
1028 * an interrupt was posted to the bus, the
1029 * test failed.
1030 */
1031 adapter->test_icr = 0;
1032 ew32(IMC, ~mask & 0x00007FFF);
1033 ew32(ICS, ~mask & 0x00007FFF);
1034 msleep(10);
1035
1036 if (adapter->test_icr) {
1037 *data = 5;
1038 break;
1039 }
1040 }
1041 }
1042
1043 /* Disable all the interrupts */
1044 ew32(IMC, 0xFFFFFFFF);
1045 msleep(10);
1046
1047 /* Unhook test interrupt handler */
1048 free_irq(irq, netdev);
1049
Bruce Allan4662e822008-08-26 18:37:06 -07001050out:
1051 if (int_mode == E1000E_INT_MODE_MSIX) {
1052 e1000e_reset_interrupt_capability(adapter);
1053 adapter->int_mode = int_mode;
1054 e1000e_set_interrupt_capability(adapter);
1055 }
1056
1057 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001058}
1059
1060static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1061{
1062 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1063 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1064 struct pci_dev *pdev = adapter->pdev;
1065 int i;
1066
1067 if (tx_ring->desc && tx_ring->buffer_info) {
1068 for (i = 0; i < tx_ring->count; i++) {
1069 if (tx_ring->buffer_info[i].dma)
1070 pci_unmap_single(pdev,
1071 tx_ring->buffer_info[i].dma,
1072 tx_ring->buffer_info[i].length,
1073 PCI_DMA_TODEVICE);
1074 if (tx_ring->buffer_info[i].skb)
1075 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1076 }
1077 }
1078
1079 if (rx_ring->desc && rx_ring->buffer_info) {
1080 for (i = 0; i < rx_ring->count; i++) {
1081 if (rx_ring->buffer_info[i].dma)
1082 pci_unmap_single(pdev,
1083 rx_ring->buffer_info[i].dma,
1084 2048, PCI_DMA_FROMDEVICE);
1085 if (rx_ring->buffer_info[i].skb)
1086 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1087 }
1088 }
1089
1090 if (tx_ring->desc) {
1091 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1092 tx_ring->dma);
1093 tx_ring->desc = NULL;
1094 }
1095 if (rx_ring->desc) {
1096 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1097 rx_ring->dma);
1098 rx_ring->desc = NULL;
1099 }
1100
1101 kfree(tx_ring->buffer_info);
1102 tx_ring->buffer_info = NULL;
1103 kfree(rx_ring->buffer_info);
1104 rx_ring->buffer_info = NULL;
1105}
1106
1107static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1108{
1109 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1110 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1111 struct pci_dev *pdev = adapter->pdev;
1112 struct e1000_hw *hw = &adapter->hw;
1113 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001114 int i;
1115 int ret_val;
1116
1117 /* Setup Tx descriptor ring and Tx buffers */
1118
1119 if (!tx_ring->count)
1120 tx_ring->count = E1000_DEFAULT_TXD;
1121
Bruce Allancef8c792008-04-02 13:48:23 -07001122 tx_ring->buffer_info = kcalloc(tx_ring->count,
1123 sizeof(struct e1000_buffer),
1124 GFP_KERNEL);
1125 if (!(tx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001126 ret_val = 1;
1127 goto err_nomem;
1128 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001129
1130 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1131 tx_ring->size = ALIGN(tx_ring->size, 4096);
1132 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1133 &tx_ring->dma, GFP_KERNEL);
1134 if (!tx_ring->desc) {
1135 ret_val = 2;
1136 goto err_nomem;
1137 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001138 tx_ring->next_to_use = 0;
1139 tx_ring->next_to_clean = 0;
1140
Bruce Allancef8c792008-04-02 13:48:23 -07001141 ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001142 ew32(TDBAH, ((u64) tx_ring->dma >> 32));
Bruce Allancef8c792008-04-02 13:48:23 -07001143 ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001144 ew32(TDH, 0);
1145 ew32(TDT, 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001146 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1147 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1148 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001149
1150 for (i = 0; i < tx_ring->count; i++) {
1151 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1152 struct sk_buff *skb;
1153 unsigned int skb_size = 1024;
1154
1155 skb = alloc_skb(skb_size, GFP_KERNEL);
1156 if (!skb) {
1157 ret_val = 3;
1158 goto err_nomem;
1159 }
1160 skb_put(skb, skb_size);
1161 tx_ring->buffer_info[i].skb = skb;
1162 tx_ring->buffer_info[i].length = skb->len;
1163 tx_ring->buffer_info[i].dma =
1164 pci_map_single(pdev, skb->data, skb->len,
1165 PCI_DMA_TODEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001166 if (pci_dma_mapping_error(pdev, tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001167 ret_val = 4;
1168 goto err_nomem;
1169 }
Bruce Allancef8c792008-04-02 13:48:23 -07001170 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001171 tx_desc->lower.data = cpu_to_le32(skb->len);
1172 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1173 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001174 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001175 tx_desc->upper.data = 0;
1176 }
1177
1178 /* Setup Rx descriptor ring and Rx buffers */
1179
1180 if (!rx_ring->count)
1181 rx_ring->count = E1000_DEFAULT_RXD;
1182
Bruce Allancef8c792008-04-02 13:48:23 -07001183 rx_ring->buffer_info = kcalloc(rx_ring->count,
1184 sizeof(struct e1000_buffer),
1185 GFP_KERNEL);
1186 if (!(rx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001187 ret_val = 5;
1188 goto err_nomem;
1189 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001190
1191 rx_ring->size = rx_ring->count * sizeof(struct e1000_rx_desc);
1192 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1193 &rx_ring->dma, GFP_KERNEL);
1194 if (!rx_ring->desc) {
1195 ret_val = 6;
1196 goto err_nomem;
1197 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001198 rx_ring->next_to_use = 0;
1199 rx_ring->next_to_clean = 0;
1200
1201 rctl = er32(RCTL);
1202 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1203 ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
1204 ew32(RDBAH, ((u64) rx_ring->dma >> 32));
1205 ew32(RDLEN, rx_ring->size);
1206 ew32(RDH, 0);
1207 ew32(RDT, 0);
1208 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allancef8c792008-04-02 13:48:23 -07001209 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1210 E1000_RCTL_SBP | E1000_RCTL_SECRC |
Auke Kokbc7f75f2007-09-17 12:30:59 -07001211 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1212 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1213 ew32(RCTL, rctl);
1214
1215 for (i = 0; i < rx_ring->count; i++) {
1216 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
1217 struct sk_buff *skb;
1218
1219 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1220 if (!skb) {
1221 ret_val = 7;
1222 goto err_nomem;
1223 }
1224 skb_reserve(skb, NET_IP_ALIGN);
1225 rx_ring->buffer_info[i].skb = skb;
1226 rx_ring->buffer_info[i].dma =
1227 pci_map_single(pdev, skb->data, 2048,
1228 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001229 if (pci_dma_mapping_error(pdev, rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001230 ret_val = 8;
1231 goto err_nomem;
1232 }
1233 rx_desc->buffer_addr =
1234 cpu_to_le64(rx_ring->buffer_info[i].dma);
1235 memset(skb->data, 0x00, skb->len);
1236 }
1237
1238 return 0;
1239
1240err_nomem:
1241 e1000_free_desc_rings(adapter);
1242 return ret_val;
1243}
1244
1245static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1246{
1247 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1248 e1e_wphy(&adapter->hw, 29, 0x001F);
1249 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1250 e1e_wphy(&adapter->hw, 29, 0x001A);
1251 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1252}
1253
1254static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1255{
1256 struct e1000_hw *hw = &adapter->hw;
1257 u32 ctrl_reg = 0;
1258 u32 stat_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001259 u16 phy_reg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001260
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001261 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001262
Bruce Allanbb436b22009-11-20 23:24:11 +00001263 /* Workaround: K1 must be disabled for stable 1Gbps operation */
1264 if (hw->mac.type == e1000_pchlan)
1265 e1000_configure_k1_ich8lan(hw, false);
1266
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001267 if (hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001268 /* Auto-MDI/MDIX Off */
1269 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1270 /* reset to update Auto-MDI/MDIX */
1271 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1272 /* autoneg off */
1273 e1e_wphy(hw, PHY_CONTROL, 0x8140);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001274 } else if (hw->phy.type == e1000_phy_gg82563)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001275 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
1276
1277 ctrl_reg = er32(CTRL);
1278
Bruce Allancef8c792008-04-02 13:48:23 -07001279 switch (hw->phy.type) {
1280 case e1000_phy_ife:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001281 /* force 100, set loopback */
1282 e1e_wphy(hw, PHY_CONTROL, 0x6100);
1283
1284 /* Now set up the MAC to the same speed/duplex as the PHY. */
1285 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1286 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1287 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1288 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1289 E1000_CTRL_FD); /* Force Duplex to FULL */
Bruce Allancef8c792008-04-02 13:48:23 -07001290 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001291 case e1000_phy_bm:
1292 /* Set Default MAC Interface speed to 1GB */
1293 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1294 phy_reg &= ~0x0007;
1295 phy_reg |= 0x006;
1296 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1297 /* Assert SW reset for above settings to take effect */
1298 e1000e_commit_phy(hw);
1299 mdelay(1);
1300 /* Force Full Duplex */
1301 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1302 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1303 /* Set Link Up (in force link) */
1304 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1305 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1306 /* Force Link */
1307 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1308 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1309 /* Set Early Link Enable */
1310 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1311 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
1312 /* fall through */
Bruce Allancef8c792008-04-02 13:48:23 -07001313 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001314 /* force 1000, set loopback */
1315 e1e_wphy(hw, PHY_CONTROL, 0x4140);
Bruce Allancef8c792008-04-02 13:48:23 -07001316 mdelay(250);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001317
1318 /* Now set up the MAC to the same speed/duplex as the PHY. */
1319 ctrl_reg = er32(CTRL);
1320 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1321 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1322 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1323 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1324 E1000_CTRL_FD); /* Force Duplex to FULL */
Bruce Allancef8c792008-04-02 13:48:23 -07001325
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001326 if (adapter->flags & FLAG_IS_ICH)
Bruce Allancef8c792008-04-02 13:48:23 -07001327 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001328 }
1329
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001330 if (hw->phy.media_type == e1000_media_type_copper &&
1331 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001332 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1333 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001334 /*
1335 * Set the ILOS bit on the fiber Nic if half duplex link is
1336 * detected.
1337 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001338 stat_reg = er32(STATUS);
1339 if ((stat_reg & E1000_STATUS_FD) == 0)
1340 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1341 }
1342
1343 ew32(CTRL, ctrl_reg);
1344
Bruce Allanad680762008-03-28 09:15:03 -07001345 /*
1346 * Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001347 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1348 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001349 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001350 e1000_phy_disable_receiver(adapter);
1351
1352 udelay(500);
1353
1354 return 0;
1355}
1356
1357static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1358{
1359 struct e1000_hw *hw = &adapter->hw;
1360 u32 ctrl = er32(CTRL);
1361 int link = 0;
1362
1363 /* special requirements for 82571/82572 fiber adapters */
1364
Bruce Allanad680762008-03-28 09:15:03 -07001365 /*
1366 * jump through hoops to make sure link is up because serdes
1367 * link is hardwired up
1368 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001369 ctrl |= E1000_CTRL_SLU;
1370 ew32(CTRL, ctrl);
1371
1372 /* disable autoneg */
1373 ctrl = er32(TXCW);
1374 ctrl &= ~(1 << 31);
1375 ew32(TXCW, ctrl);
1376
1377 link = (er32(STATUS) & E1000_STATUS_LU);
1378
1379 if (!link) {
1380 /* set invert loss of signal */
1381 ctrl = er32(CTRL);
1382 ctrl |= E1000_CTRL_ILOS;
1383 ew32(CTRL, ctrl);
1384 }
1385
Bruce Allanad680762008-03-28 09:15:03 -07001386 /*
1387 * special write to serdes control register to enable SerDes analog
1388 * loopback
1389 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001390#define E1000_SERDES_LB_ON 0x410
1391 ew32(SCTL, E1000_SERDES_LB_ON);
1392 msleep(10);
1393
1394 return 0;
1395}
1396
1397/* only call this for fiber/serdes connections to es2lan */
1398static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1399{
1400 struct e1000_hw *hw = &adapter->hw;
1401 u32 ctrlext = er32(CTRL_EXT);
1402 u32 ctrl = er32(CTRL);
1403
Bruce Allanad680762008-03-28 09:15:03 -07001404 /*
1405 * save CTRL_EXT to restore later, reuse an empty variable (unused
1406 * on mac_type 80003es2lan)
1407 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001408 adapter->tx_fifo_head = ctrlext;
1409
1410 /* clear the serdes mode bits, putting the device into mac loopback */
1411 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1412 ew32(CTRL_EXT, ctrlext);
1413
1414 /* force speed to 1000/FD, link up */
1415 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1416 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1417 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1418 ew32(CTRL, ctrl);
1419
1420 /* set mac loopback */
1421 ctrl = er32(RCTL);
1422 ctrl |= E1000_RCTL_LBM_MAC;
1423 ew32(RCTL, ctrl);
1424
1425 /* set testing mode parameters (no need to reset later) */
1426#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1427#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1428 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001429 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001430
1431 return 0;
1432}
1433
1434static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1435{
1436 struct e1000_hw *hw = &adapter->hw;
1437 u32 rctl;
1438
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001439 if (hw->phy.media_type == e1000_media_type_fiber ||
1440 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001441 switch (hw->mac.type) {
1442 case e1000_80003es2lan:
1443 return e1000_set_es2lan_mac_loopback(adapter);
1444 break;
1445 case e1000_82571:
1446 case e1000_82572:
1447 return e1000_set_82571_fiber_loopback(adapter);
1448 break;
1449 default:
1450 rctl = er32(RCTL);
1451 rctl |= E1000_RCTL_LBM_TCVR;
1452 ew32(RCTL, rctl);
1453 return 0;
1454 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001455 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001456 return e1000_integrated_phy_loopback(adapter);
1457 }
1458
1459 return 7;
1460}
1461
1462static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1463{
1464 struct e1000_hw *hw = &adapter->hw;
1465 u32 rctl;
1466 u16 phy_reg;
1467
1468 rctl = er32(RCTL);
1469 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1470 ew32(RCTL, rctl);
1471
1472 switch (hw->mac.type) {
1473 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001474 if (hw->phy.media_type == e1000_media_type_fiber ||
1475 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001476 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001477 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001478 adapter->tx_fifo_head = 0;
1479 }
1480 /* fall through */
1481 case e1000_82571:
1482 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001483 if (hw->phy.media_type == e1000_media_type_fiber ||
1484 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001485#define E1000_SERDES_LB_OFF 0x400
1486 ew32(SCTL, E1000_SERDES_LB_OFF);
1487 msleep(10);
1488 break;
1489 }
1490 /* Fall Through */
1491 default:
1492 hw->mac.autoneg = 1;
1493 if (hw->phy.type == e1000_phy_gg82563)
1494 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1495 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1496 if (phy_reg & MII_CR_LOOPBACK) {
1497 phy_reg &= ~MII_CR_LOOPBACK;
1498 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1499 e1000e_commit_phy(hw);
1500 }
1501 break;
1502 }
1503}
1504
1505static void e1000_create_lbtest_frame(struct sk_buff *skb,
1506 unsigned int frame_size)
1507{
1508 memset(skb->data, 0xFF, frame_size);
1509 frame_size &= ~1;
1510 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1511 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1512 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1513}
1514
1515static int e1000_check_lbtest_frame(struct sk_buff *skb,
1516 unsigned int frame_size)
1517{
1518 frame_size &= ~1;
1519 if (*(skb->data + 3) == 0xFF)
1520 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1521 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1522 return 0;
1523 return 13;
1524}
1525
1526static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1527{
1528 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1529 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1530 struct pci_dev *pdev = adapter->pdev;
1531 struct e1000_hw *hw = &adapter->hw;
1532 int i, j, k, l;
1533 int lc;
1534 int good_cnt;
1535 int ret_val = 0;
1536 unsigned long time;
1537
1538 ew32(RDT, rx_ring->count - 1);
1539
Bruce Allanad680762008-03-28 09:15:03 -07001540 /*
1541 * Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001542 * The idea is to wrap the largest ring a number of times using 64
1543 * send/receive pairs during each loop
1544 */
1545
1546 if (rx_ring->count <= tx_ring->count)
1547 lc = ((tx_ring->count / 64) * 2) + 1;
1548 else
1549 lc = ((rx_ring->count / 64) * 2) + 1;
1550
1551 k = 0;
1552 l = 0;
1553 for (j = 0; j <= lc; j++) { /* loop count loop */
1554 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001555 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1556 1024);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001557 pci_dma_sync_single_for_device(pdev,
1558 tx_ring->buffer_info[k].dma,
1559 tx_ring->buffer_info[k].length,
1560 PCI_DMA_TODEVICE);
1561 k++;
1562 if (k == tx_ring->count)
1563 k = 0;
1564 }
1565 ew32(TDT, k);
1566 msleep(200);
1567 time = jiffies; /* set the start time for the receive */
1568 good_cnt = 0;
1569 do { /* receive the sent packets */
1570 pci_dma_sync_single_for_cpu(pdev,
1571 rx_ring->buffer_info[l].dma, 2048,
1572 PCI_DMA_FROMDEVICE);
1573
1574 ret_val = e1000_check_lbtest_frame(
1575 rx_ring->buffer_info[l].skb, 1024);
1576 if (!ret_val)
1577 good_cnt++;
1578 l++;
1579 if (l == rx_ring->count)
1580 l = 0;
Bruce Allanad680762008-03-28 09:15:03 -07001581 /*
1582 * time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001583 * enough time to complete the receives, if it's
1584 * exceeded, break and error off
1585 */
1586 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1587 if (good_cnt != 64) {
1588 ret_val = 13; /* ret_val is the same as mis-compare */
1589 break;
1590 }
Bruce Allancef8c792008-04-02 13:48:23 -07001591 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001592 ret_val = 14; /* error code for time out error */
1593 break;
1594 }
1595 } /* end loop count loop */
1596 return ret_val;
1597}
1598
1599static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1600{
Bruce Allanad680762008-03-28 09:15:03 -07001601 /*
1602 * PHY loopback cannot be performed if SoL/IDER
1603 * sessions are active
1604 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001605 if (e1000_check_reset_block(&adapter->hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001606 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001607 *data = 0;
1608 goto out;
1609 }
1610
1611 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001612 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001613 goto out;
1614
1615 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001616 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001617 goto err_loopback;
1618
1619 *data = e1000_run_loopback_test(adapter);
1620 e1000_loopback_cleanup(adapter);
1621
1622err_loopback:
1623 e1000_free_desc_rings(adapter);
1624out:
1625 return *data;
1626}
1627
1628static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1629{
1630 struct e1000_hw *hw = &adapter->hw;
1631
1632 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001633 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001634 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001635 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001636
Bruce Allanad680762008-03-28 09:15:03 -07001637 /*
1638 * On some blade server designs, link establishment
1639 * could take as long as 2-3 minutes
1640 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001641 do {
1642 hw->mac.ops.check_for_link(hw);
1643 if (hw->mac.serdes_has_link)
1644 return *data;
1645 msleep(20);
1646 } while (i++ < 3750);
1647
1648 *data = 1;
1649 } else {
1650 hw->mac.ops.check_for_link(hw);
1651 if (hw->mac.autoneg)
1652 msleep(4000);
1653
1654 if (!(er32(STATUS) &
1655 E1000_STATUS_LU))
1656 *data = 1;
1657 }
1658 return *data;
1659}
1660
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001661static int e1000e_get_sset_count(struct net_device *netdev, int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001662{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001663 switch (sset) {
1664 case ETH_SS_TEST:
1665 return E1000_TEST_LEN;
1666 case ETH_SS_STATS:
1667 return E1000_STATS_LEN;
1668 default:
1669 return -EOPNOTSUPP;
1670 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001671}
1672
1673static void e1000_diag_test(struct net_device *netdev,
1674 struct ethtool_test *eth_test, u64 *data)
1675{
1676 struct e1000_adapter *adapter = netdev_priv(netdev);
1677 u16 autoneg_advertised;
1678 u8 forced_speed_duplex;
1679 u8 autoneg;
1680 bool if_running = netif_running(netdev);
1681
1682 set_bit(__E1000_TESTING, &adapter->state);
1683 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1684 /* Offline tests */
1685
1686 /* save speed, duplex, autoneg settings */
1687 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1688 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1689 autoneg = adapter->hw.mac.autoneg;
1690
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001691 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001692
Bruce Allanad680762008-03-28 09:15:03 -07001693 /*
1694 * Link test performed before hardware reset so autoneg doesn't
1695 * interfere with test result
1696 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001697 if (e1000_link_test(adapter, &data[4]))
1698 eth_test->flags |= ETH_TEST_FL_FAILED;
1699
1700 if (if_running)
1701 /* indicate we're in test mode */
1702 dev_close(netdev);
1703 else
1704 e1000e_reset(adapter);
1705
1706 if (e1000_reg_test(adapter, &data[0]))
1707 eth_test->flags |= ETH_TEST_FL_FAILED;
1708
1709 e1000e_reset(adapter);
1710 if (e1000_eeprom_test(adapter, &data[1]))
1711 eth_test->flags |= ETH_TEST_FL_FAILED;
1712
1713 e1000e_reset(adapter);
1714 if (e1000_intr_test(adapter, &data[2]))
1715 eth_test->flags |= ETH_TEST_FL_FAILED;
1716
1717 e1000e_reset(adapter);
1718 /* make sure the phy is powered up */
1719 e1000e_power_up_phy(adapter);
1720 if (e1000_loopback_test(adapter, &data[3]))
1721 eth_test->flags |= ETH_TEST_FL_FAILED;
1722
1723 /* restore speed, duplex, autoneg settings */
1724 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1725 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1726 adapter->hw.mac.autoneg = autoneg;
1727
1728 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001729 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001730 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001731 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001732
1733 clear_bit(__E1000_TESTING, &adapter->state);
1734 if (if_running)
1735 dev_open(netdev);
1736 } else {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001737 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001738 /* Online tests */
1739 if (e1000_link_test(adapter, &data[4]))
1740 eth_test->flags |= ETH_TEST_FL_FAILED;
1741
1742 /* Online tests aren't run; pass by default */
1743 data[0] = 0;
1744 data[1] = 0;
1745 data[2] = 0;
1746 data[3] = 0;
1747
1748 clear_bit(__E1000_TESTING, &adapter->state);
1749 }
1750 msleep_interruptible(4 * 1000);
1751}
1752
1753static void e1000_get_wol(struct net_device *netdev,
1754 struct ethtool_wolinfo *wol)
1755{
1756 struct e1000_adapter *adapter = netdev_priv(netdev);
1757
1758 wol->supported = 0;
1759 wol->wolopts = 0;
1760
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001761 if (!(adapter->flags & FLAG_HAS_WOL) ||
1762 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001763 return;
1764
1765 wol->supported = WAKE_UCAST | WAKE_MCAST |
Mitch Williamsefb90e42008-01-29 12:43:02 -08001766 WAKE_BCAST | WAKE_MAGIC |
1767 WAKE_PHY | WAKE_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001768
1769 /* apply any specific unsupported masks here */
1770 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1771 wol->supported &= ~WAKE_UCAST;
1772
1773 if (adapter->wol & E1000_WUFC_EX)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001774 e_err("Interface does not support directed (unicast) "
1775 "frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001776 }
1777
1778 if (adapter->wol & E1000_WUFC_EX)
1779 wol->wolopts |= WAKE_UCAST;
1780 if (adapter->wol & E1000_WUFC_MC)
1781 wol->wolopts |= WAKE_MCAST;
1782 if (adapter->wol & E1000_WUFC_BC)
1783 wol->wolopts |= WAKE_BCAST;
1784 if (adapter->wol & E1000_WUFC_MAG)
1785 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001786 if (adapter->wol & E1000_WUFC_LNKC)
1787 wol->wolopts |= WAKE_PHY;
1788 if (adapter->wol & E1000_WUFC_ARP)
1789 wol->wolopts |= WAKE_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001790}
1791
1792static int e1000_set_wol(struct net_device *netdev,
1793 struct ethtool_wolinfo *wol)
1794{
1795 struct e1000_adapter *adapter = netdev_priv(netdev);
1796
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001797 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001798 !device_can_wakeup(&adapter->pdev->dev) ||
1799 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
1800 WAKE_MAGIC | WAKE_PHY | WAKE_ARP)))
1801 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001802
1803 /* these settings will always override what we currently have */
1804 adapter->wol = 0;
1805
1806 if (wol->wolopts & WAKE_UCAST)
1807 adapter->wol |= E1000_WUFC_EX;
1808 if (wol->wolopts & WAKE_MCAST)
1809 adapter->wol |= E1000_WUFC_MC;
1810 if (wol->wolopts & WAKE_BCAST)
1811 adapter->wol |= E1000_WUFC_BC;
1812 if (wol->wolopts & WAKE_MAGIC)
1813 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001814 if (wol->wolopts & WAKE_PHY)
1815 adapter->wol |= E1000_WUFC_LNKC;
1816 if (wol->wolopts & WAKE_ARP)
1817 adapter->wol |= E1000_WUFC_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001818
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001819 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1820
Auke Kokbc7f75f2007-09-17 12:30:59 -07001821 return 0;
1822}
1823
1824/* toggle LED 4 times per second = 2 "blinks" per second */
1825#define E1000_ID_INTERVAL (HZ/4)
1826
1827/* bit defines for adapter->led_status */
1828#define E1000_LED_ON 0
1829
Bruce Allana4f58f52009-06-02 11:29:18 +00001830static void e1000e_led_blink_task(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001831{
Bruce Allana4f58f52009-06-02 11:29:18 +00001832 struct e1000_adapter *adapter = container_of(work,
1833 struct e1000_adapter, led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001834
1835 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
1836 adapter->hw.mac.ops.led_off(&adapter->hw);
1837 else
1838 adapter->hw.mac.ops.led_on(&adapter->hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001839}
Auke Kokbc7f75f2007-09-17 12:30:59 -07001840
Bruce Allana4f58f52009-06-02 11:29:18 +00001841static void e1000_led_blink_callback(unsigned long data)
1842{
1843 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1844
1845 schedule_work(&adapter->led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001846 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1847}
1848
1849static int e1000_phys_id(struct net_device *netdev, u32 data)
1850{
1851 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001852 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001853
Stephen Hemminger5a9147b2007-10-29 10:46:05 -07001854 if (!data)
1855 data = INT_MAX;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001856
Bruce Allan4662e822008-08-26 18:37:06 -07001857 if ((hw->phy.type == e1000_phy_ife) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00001858 (hw->mac.type == e1000_pchlan) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +00001859 (hw->mac.type == e1000_82583) ||
Bruce Allan4662e822008-08-26 18:37:06 -07001860 (hw->mac.type == e1000_82574)) {
Bruce Allana4f58f52009-06-02 11:29:18 +00001861 INIT_WORK(&adapter->led_blink_task, e1000e_led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001862 if (!adapter->blink_timer.function) {
1863 init_timer(&adapter->blink_timer);
1864 adapter->blink_timer.function =
1865 e1000_led_blink_callback;
1866 adapter->blink_timer.data = (unsigned long) adapter;
1867 }
1868 mod_timer(&adapter->blink_timer, jiffies);
1869 msleep_interruptible(data * 1000);
1870 del_timer_sync(&adapter->blink_timer);
Bruce Allan4662e822008-08-26 18:37:06 -07001871 if (hw->phy.type == e1000_phy_ife)
1872 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001873 } else {
Bruce Allan4662e822008-08-26 18:37:06 -07001874 e1000e_blink_led(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001875 msleep_interruptible(data * 1000);
1876 }
1877
Bruce Allan4662e822008-08-26 18:37:06 -07001878 hw->mac.ops.led_off(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001879 clear_bit(E1000_LED_ON, &adapter->led_status);
Bruce Allan4662e822008-08-26 18:37:06 -07001880 hw->mac.ops.cleanup_led(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001881
1882 return 0;
1883}
1884
Auke Kokde5b3072008-04-23 11:09:08 -07001885static int e1000_get_coalesce(struct net_device *netdev,
1886 struct ethtool_coalesce *ec)
1887{
1888 struct e1000_adapter *adapter = netdev_priv(netdev);
1889
1890 if (adapter->itr_setting <= 3)
1891 ec->rx_coalesce_usecs = adapter->itr_setting;
1892 else
1893 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1894
1895 return 0;
1896}
1897
1898static int e1000_set_coalesce(struct net_device *netdev,
1899 struct ethtool_coalesce *ec)
1900{
1901 struct e1000_adapter *adapter = netdev_priv(netdev);
1902 struct e1000_hw *hw = &adapter->hw;
1903
1904 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
1905 ((ec->rx_coalesce_usecs > 3) &&
1906 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1907 (ec->rx_coalesce_usecs == 2))
1908 return -EINVAL;
1909
1910 if (ec->rx_coalesce_usecs <= 3) {
1911 adapter->itr = 20000;
1912 adapter->itr_setting = ec->rx_coalesce_usecs;
1913 } else {
1914 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1915 adapter->itr_setting = adapter->itr & ~3;
1916 }
1917
1918 if (adapter->itr_setting != 0)
1919 ew32(ITR, 1000000000 / (adapter->itr * 256));
1920 else
1921 ew32(ITR, 0);
1922
1923 return 0;
1924}
1925
Auke Kokbc7f75f2007-09-17 12:30:59 -07001926static int e1000_nway_reset(struct net_device *netdev)
1927{
1928 struct e1000_adapter *adapter = netdev_priv(netdev);
1929 if (netif_running(netdev))
1930 e1000e_reinit_locked(adapter);
1931 return 0;
1932}
1933
Auke Kokbc7f75f2007-09-17 12:30:59 -07001934static void e1000_get_ethtool_stats(struct net_device *netdev,
1935 struct ethtool_stats *stats,
1936 u64 *data)
1937{
1938 struct e1000_adapter *adapter = netdev_priv(netdev);
1939 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001940 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001941
1942 e1000e_update_stats(adapter);
1943 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001944 switch (e1000_gstrings_stats[i].type) {
1945 case NETDEV_STATS:
1946 p = (char *) netdev +
1947 e1000_gstrings_stats[i].stat_offset;
1948 break;
1949 case E1000_STATS:
1950 p = (char *) adapter +
1951 e1000_gstrings_stats[i].stat_offset;
1952 break;
1953 }
1954
Auke Kokbc7f75f2007-09-17 12:30:59 -07001955 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1956 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1957 }
1958}
1959
1960static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1961 u8 *data)
1962{
1963 u8 *p = data;
1964 int i;
1965
1966 switch (stringset) {
1967 case ETH_SS_TEST:
Bruce Allanad680762008-03-28 09:15:03 -07001968 memcpy(data, *e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001969 break;
1970 case ETH_SS_STATS:
1971 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1972 memcpy(p, e1000_gstrings_stats[i].stat_string,
1973 ETH_GSTRING_LEN);
1974 p += ETH_GSTRING_LEN;
1975 }
1976 break;
1977 }
1978}
1979
1980static const struct ethtool_ops e1000_ethtool_ops = {
1981 .get_settings = e1000_get_settings,
1982 .set_settings = e1000_set_settings,
1983 .get_drvinfo = e1000_get_drvinfo,
1984 .get_regs_len = e1000_get_regs_len,
1985 .get_regs = e1000_get_regs,
1986 .get_wol = e1000_get_wol,
1987 .set_wol = e1000_set_wol,
1988 .get_msglevel = e1000_get_msglevel,
1989 .set_msglevel = e1000_set_msglevel,
1990 .nway_reset = e1000_nway_reset,
Auke Kok369d7422007-10-15 14:30:59 -07001991 .get_link = e1000_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001992 .get_eeprom_len = e1000_get_eeprom_len,
1993 .get_eeprom = e1000_get_eeprom,
1994 .set_eeprom = e1000_set_eeprom,
1995 .get_ringparam = e1000_get_ringparam,
1996 .set_ringparam = e1000_set_ringparam,
1997 .get_pauseparam = e1000_get_pauseparam,
1998 .set_pauseparam = e1000_set_pauseparam,
1999 .get_rx_csum = e1000_get_rx_csum,
2000 .set_rx_csum = e1000_set_rx_csum,
2001 .get_tx_csum = e1000_get_tx_csum,
2002 .set_tx_csum = e1000_set_tx_csum,
2003 .get_sg = ethtool_op_get_sg,
2004 .set_sg = ethtool_op_set_sg,
2005 .get_tso = ethtool_op_get_tso,
2006 .set_tso = e1000_set_tso,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002007 .self_test = e1000_diag_test,
2008 .get_strings = e1000_get_strings,
2009 .phys_id = e1000_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002010 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07002011 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07002012 .get_coalesce = e1000_get_coalesce,
2013 .set_coalesce = e1000_set_coalesce,
Bruce Allane7d906f2009-11-20 23:22:57 +00002014 .get_flags = ethtool_op_get_flags,
2015 .set_flags = ethtool_op_set_flags,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002016};
2017
2018void e1000e_set_ethtool_ops(struct net_device *netdev)
2019{
2020 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
2021}