blob: a70999b8c6cf32bdf8c81f9423ce0347a9095146 [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 Allana20e4cf2008-11-21 17:01:35 -0800193
194 return e1000_has_link(adapter);
Auke Kok369d7422007-10-15 14:30:59 -0700195}
196
Auke Kokbc7f75f2007-09-17 12:30:59 -0700197static 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
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700338 retval = ((hw->phy.media_type == e1000_media_type_fiber) ?
Auke Kokbc7f75f2007-09-17 12:30:59 -0700339 hw->mac.ops.setup_link(hw) : e1000e_force_mac_fc(hw));
340 }
341
342 clear_bit(__E1000_RESETTING, &adapter->state);
343 return retval;
344}
345
346static u32 e1000_get_rx_csum(struct net_device *netdev)
347{
348 struct e1000_adapter *adapter = netdev_priv(netdev);
349 return (adapter->flags & FLAG_RX_CSUM_ENABLED);
350}
351
352static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
353{
354 struct e1000_adapter *adapter = netdev_priv(netdev);
355
356 if (data)
357 adapter->flags |= FLAG_RX_CSUM_ENABLED;
358 else
359 adapter->flags &= ~FLAG_RX_CSUM_ENABLED;
360
361 if (netif_running(netdev))
362 e1000e_reinit_locked(adapter);
363 else
364 e1000e_reset(adapter);
365 return 0;
366}
367
368static u32 e1000_get_tx_csum(struct net_device *netdev)
369{
370 return ((netdev->features & NETIF_F_HW_CSUM) != 0);
371}
372
373static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
374{
375 if (data)
376 netdev->features |= NETIF_F_HW_CSUM;
377 else
378 netdev->features &= ~NETIF_F_HW_CSUM;
379
380 return 0;
381}
382
383static int e1000_set_tso(struct net_device *netdev, u32 data)
384{
385 struct e1000_adapter *adapter = netdev_priv(netdev);
386
387 if (data) {
388 netdev->features |= NETIF_F_TSO;
389 netdev->features |= NETIF_F_TSO6;
390 } else {
391 netdev->features &= ~NETIF_F_TSO;
392 netdev->features &= ~NETIF_F_TSO6;
393 }
394
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700395 e_info("TSO is %s\n", data ? "Enabled" : "Disabled");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700396 adapter->flags |= FLAG_TSO_FORCE;
397 return 0;
398}
399
400static u32 e1000_get_msglevel(struct net_device *netdev)
401{
402 struct e1000_adapter *adapter = netdev_priv(netdev);
403 return adapter->msg_enable;
404}
405
406static void e1000_set_msglevel(struct net_device *netdev, u32 data)
407{
408 struct e1000_adapter *adapter = netdev_priv(netdev);
409 adapter->msg_enable = data;
410}
411
412static int e1000_get_regs_len(struct net_device *netdev)
413{
414#define E1000_REGS_LEN 32 /* overestimate */
415 return E1000_REGS_LEN * sizeof(u32);
416}
417
418static void e1000_get_regs(struct net_device *netdev,
419 struct ethtool_regs *regs, void *p)
420{
421 struct e1000_adapter *adapter = netdev_priv(netdev);
422 struct e1000_hw *hw = &adapter->hw;
423 u32 *regs_buff = p;
424 u16 phy_data;
425 u8 revision_id;
426
427 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
428
429 pci_read_config_byte(adapter->pdev, PCI_REVISION_ID, &revision_id);
430
431 regs->version = (1 << 24) | (revision_id << 16) | adapter->pdev->device;
432
433 regs_buff[0] = er32(CTRL);
434 regs_buff[1] = er32(STATUS);
435
436 regs_buff[2] = er32(RCTL);
437 regs_buff[3] = er32(RDLEN);
438 regs_buff[4] = er32(RDH);
439 regs_buff[5] = er32(RDT);
440 regs_buff[6] = er32(RDTR);
441
442 regs_buff[7] = er32(TCTL);
443 regs_buff[8] = er32(TDLEN);
444 regs_buff[9] = er32(TDH);
445 regs_buff[10] = er32(TDT);
446 regs_buff[11] = er32(TIDV);
447
448 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700449
450 /* ethtool doesn't use anything past this point, so all this
451 * code is likely legacy junk for apps that may or may not
452 * exist */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700453 if (hw->phy.type == e1000_phy_m88) {
454 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
455 regs_buff[13] = (u32)phy_data; /* cable length */
456 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
457 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
458 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
459 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
460 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
461 regs_buff[18] = regs_buff[13]; /* cable polarity */
462 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
463 regs_buff[20] = regs_buff[17]; /* polarity correction */
464 /* phy receive errors */
465 regs_buff[22] = adapter->phy_stats.receive_errors;
466 regs_buff[23] = regs_buff[13]; /* mdix mode */
467 }
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700468 regs_buff[21] = 0; /* was idle_errors */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700469 e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
470 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
471 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
472}
473
474static int e1000_get_eeprom_len(struct net_device *netdev)
475{
476 struct e1000_adapter *adapter = netdev_priv(netdev);
477 return adapter->hw.nvm.word_size * 2;
478}
479
480static int e1000_get_eeprom(struct net_device *netdev,
481 struct ethtool_eeprom *eeprom, u8 *bytes)
482{
483 struct e1000_adapter *adapter = netdev_priv(netdev);
484 struct e1000_hw *hw = &adapter->hw;
485 u16 *eeprom_buff;
486 int first_word;
487 int last_word;
488 int ret_val = 0;
489 u16 i;
490
491 if (eeprom->len == 0)
492 return -EINVAL;
493
494 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
495
496 first_word = eeprom->offset >> 1;
497 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
498
499 eeprom_buff = kmalloc(sizeof(u16) *
500 (last_word - first_word + 1), GFP_KERNEL);
501 if (!eeprom_buff)
502 return -ENOMEM;
503
504 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
505 ret_val = e1000_read_nvm(hw, first_word,
506 last_word - first_word + 1,
507 eeprom_buff);
508 } else {
509 for (i = 0; i < last_word - first_word + 1; i++) {
510 ret_val = e1000_read_nvm(hw, first_word + i, 1,
511 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800512 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700513 break;
514 }
515 }
516
Bruce Allane2434552008-11-21 17:02:41 -0800517 if (ret_val) {
518 /* a read error occurred, throw away the result */
519 memset(eeprom_buff, 0xff, sizeof(eeprom_buff));
520 } else {
521 /* Device's eeprom is always little-endian, word addressable */
522 for (i = 0; i < last_word - first_word + 1; i++)
523 le16_to_cpus(&eeprom_buff[i]);
524 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700525
526 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
527 kfree(eeprom_buff);
528
529 return ret_val;
530}
531
532static int e1000_set_eeprom(struct net_device *netdev,
533 struct ethtool_eeprom *eeprom, u8 *bytes)
534{
535 struct e1000_adapter *adapter = netdev_priv(netdev);
536 struct e1000_hw *hw = &adapter->hw;
537 u16 *eeprom_buff;
538 void *ptr;
539 int max_len;
540 int first_word;
541 int last_word;
542 int ret_val = 0;
543 u16 i;
544
545 if (eeprom->len == 0)
546 return -EOPNOTSUPP;
547
548 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
549 return -EFAULT;
550
Bruce Allan4a770352008-10-01 17:18:35 -0700551 if (adapter->flags & FLAG_READ_ONLY_NVM)
552 return -EINVAL;
553
Auke Kokbc7f75f2007-09-17 12:30:59 -0700554 max_len = hw->nvm.word_size * 2;
555
556 first_word = eeprom->offset >> 1;
557 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
558 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
559 if (!eeprom_buff)
560 return -ENOMEM;
561
562 ptr = (void *)eeprom_buff;
563
564 if (eeprom->offset & 1) {
565 /* need read/modify/write of first changed EEPROM word */
566 /* only the second byte of the word is being modified */
567 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
568 ptr++;
569 }
570 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0))
571 /* need read/modify/write of last changed EEPROM word */
572 /* only the first byte of the word is being modified */
573 ret_val = e1000_read_nvm(hw, last_word, 1,
574 &eeprom_buff[last_word - first_word]);
575
Bruce Allane2434552008-11-21 17:02:41 -0800576 if (ret_val)
577 goto out;
578
Auke Kokbc7f75f2007-09-17 12:30:59 -0700579 /* Device's eeprom is always little-endian, word addressable */
580 for (i = 0; i < last_word - first_word + 1; i++)
581 le16_to_cpus(&eeprom_buff[i]);
582
583 memcpy(ptr, bytes, eeprom->len);
584
585 for (i = 0; i < last_word - first_word + 1; i++)
586 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
587
588 ret_val = e1000_write_nvm(hw, first_word,
589 last_word - first_word + 1, eeprom_buff);
590
Bruce Allane2434552008-11-21 17:02:41 -0800591 if (ret_val)
592 goto out;
593
Bruce Allanad680762008-03-28 09:15:03 -0700594 /*
595 * Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800596 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700597 */
Bruce Allane2434552008-11-21 17:02:41 -0800598 if ((first_word <= NVM_CHECKSUM_REG) ||
599 (hw->mac.type == e1000_82574) || (hw->mac.type == e1000_82573))
600 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700601
Bruce Allane2434552008-11-21 17:02:41 -0800602out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700603 kfree(eeprom_buff);
604 return ret_val;
605}
606
607static void e1000_get_drvinfo(struct net_device *netdev,
608 struct ethtool_drvinfo *drvinfo)
609{
610 struct e1000_adapter *adapter = netdev_priv(netdev);
611 char firmware_version[32];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700612
613 strncpy(drvinfo->driver, e1000e_driver_name, 32);
614 strncpy(drvinfo->version, e1000e_driver_version, 32);
615
Bruce Allanad680762008-03-28 09:15:03 -0700616 /*
617 * EEPROM image version # is reported as firmware version # for
618 * PCI-E controllers
619 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700620 sprintf(firmware_version, "%d.%d-%d",
Bruce Allan84527592008-11-21 17:00:22 -0800621 (adapter->eeprom_vers & 0xF000) >> 12,
622 (adapter->eeprom_vers & 0x0FF0) >> 4,
623 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700624
625 strncpy(drvinfo->fw_version, firmware_version, 32);
626 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700627 drvinfo->regdump_len = e1000_get_regs_len(netdev);
628 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
629}
630
631static void e1000_get_ringparam(struct net_device *netdev,
632 struct ethtool_ringparam *ring)
633{
634 struct e1000_adapter *adapter = netdev_priv(netdev);
635 struct e1000_ring *tx_ring = adapter->tx_ring;
636 struct e1000_ring *rx_ring = adapter->rx_ring;
637
638 ring->rx_max_pending = E1000_MAX_RXD;
639 ring->tx_max_pending = E1000_MAX_TXD;
640 ring->rx_mini_max_pending = 0;
641 ring->rx_jumbo_max_pending = 0;
642 ring->rx_pending = rx_ring->count;
643 ring->tx_pending = tx_ring->count;
644 ring->rx_mini_pending = 0;
645 ring->rx_jumbo_pending = 0;
646}
647
648static int e1000_set_ringparam(struct net_device *netdev,
649 struct ethtool_ringparam *ring)
650{
651 struct e1000_adapter *adapter = netdev_priv(netdev);
652 struct e1000_ring *tx_ring, *tx_old;
653 struct e1000_ring *rx_ring, *rx_old;
654 int err;
655
656 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
657 return -EINVAL;
658
659 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
660 msleep(1);
661
662 if (netif_running(adapter->netdev))
663 e1000e_down(adapter);
664
665 tx_old = adapter->tx_ring;
666 rx_old = adapter->rx_ring;
667
668 err = -ENOMEM;
669 tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
670 if (!tx_ring)
671 goto err_alloc_tx;
Bruce Allancef8c792008-04-02 13:48:23 -0700672 /*
673 * use a memcpy to save any previously configured
674 * items like napi structs from having to be
675 * reinitialized
676 */
677 memcpy(tx_ring, tx_old, sizeof(struct e1000_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700678
679 rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
680 if (!rx_ring)
681 goto err_alloc_rx;
Bruce Allancef8c792008-04-02 13:48:23 -0700682 memcpy(rx_ring, rx_old, sizeof(struct e1000_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700683
684 adapter->tx_ring = tx_ring;
685 adapter->rx_ring = rx_ring;
686
687 rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
688 rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD));
689 rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
690
691 tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
692 tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
693 tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
694
695 if (netif_running(adapter->netdev)) {
696 /* Try to get new resources before deleting old */
697 err = e1000e_setup_rx_resources(adapter);
698 if (err)
699 goto err_setup_rx;
700 err = e1000e_setup_tx_resources(adapter);
701 if (err)
702 goto err_setup_tx;
703
Bruce Allanad680762008-03-28 09:15:03 -0700704 /*
705 * restore the old in order to free it,
706 * then add in the new
707 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700708 adapter->rx_ring = rx_old;
709 adapter->tx_ring = tx_old;
710 e1000e_free_rx_resources(adapter);
711 e1000e_free_tx_resources(adapter);
712 kfree(tx_old);
713 kfree(rx_old);
714 adapter->rx_ring = rx_ring;
715 adapter->tx_ring = tx_ring;
716 err = e1000e_up(adapter);
717 if (err)
718 goto err_setup;
719 }
720
721 clear_bit(__E1000_RESETTING, &adapter->state);
722 return 0;
723err_setup_tx:
724 e1000e_free_rx_resources(adapter);
725err_setup_rx:
726 adapter->rx_ring = rx_old;
727 adapter->tx_ring = tx_old;
728 kfree(rx_ring);
729err_alloc_rx:
730 kfree(tx_ring);
731err_alloc_tx:
732 e1000e_up(adapter);
733err_setup:
734 clear_bit(__E1000_RESETTING, &adapter->state);
735 return err;
736}
737
Bruce Allancef8c792008-04-02 13:48:23 -0700738static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
739 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800740{
Bruce Allancef8c792008-04-02 13:48:23 -0700741 u32 pat, val;
Joe Perches2a887192007-11-13 20:53:51 -0800742 static const u32 test[] =
743 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Bruce Allancef8c792008-04-02 13:48:23 -0700744 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800745 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700746 (test[pat] & write));
747 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
748 if (val != (test[pat] & write & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700749 e_err("pattern test reg %04X failed: got 0x%08X "
750 "expected 0x%08X\n", reg + offset, val,
751 (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800752 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700753 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800754 }
755 }
Bruce Allancef8c792008-04-02 13:48:23 -0700756 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700757}
758
Joe Perches2a887192007-11-13 20:53:51 -0800759static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
760 int reg, u32 mask, u32 write)
761{
Bruce Allancef8c792008-04-02 13:48:23 -0700762 u32 val;
Joe Perches2a887192007-11-13 20:53:51 -0800763 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700764 val = __er32(&adapter->hw, reg);
765 if ((write & mask) != (val & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700766 e_err("set/check reg %04X test failed: got 0x%08X "
767 "expected 0x%08X\n", reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800768 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700769 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800770 }
Bruce Allancef8c792008-04-02 13:48:23 -0700771 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700772}
Bruce Allancef8c792008-04-02 13:48:23 -0700773#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
774 do { \
775 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
776 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800777 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700778#define REG_PATTERN_TEST(reg, mask, write) \
779 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800780
Bruce Allancef8c792008-04-02 13:48:23 -0700781#define REG_SET_AND_CHECK(reg, mask, write) \
782 do { \
783 if (reg_set_and_check(adapter, data, reg, mask, write)) \
784 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800785 } while (0)
786
Auke Kokbc7f75f2007-09-17 12:30:59 -0700787static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
788{
789 struct e1000_hw *hw = &adapter->hw;
790 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700791 u32 value;
792 u32 before;
793 u32 after;
794 u32 i;
795 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000796 u32 mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700797
Bruce Allanad680762008-03-28 09:15:03 -0700798 /*
799 * The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700800 * Some bits that get toggled are ignored.
801 */
802 switch (mac->type) {
803 /* there are several bits on newer hardware that are r/w */
804 case e1000_82571:
805 case e1000_82572:
806 case e1000_80003es2lan:
807 toggle = 0x7FFFF3FF;
808 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000809 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700810 toggle = 0x7FFFF033;
811 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700812 }
813
814 before = er32(STATUS);
815 value = (er32(STATUS) & toggle);
816 ew32(STATUS, toggle);
817 after = er32(STATUS) & toggle;
818 if (value != after) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700819 e_err("failed STATUS register test got: 0x%08X expected: "
820 "0x%08X\n", after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700821 *data = 1;
822 return 1;
823 }
824 /* restore previous status */
825 ew32(STATUS, before);
826
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700827 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700828 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
829 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
830 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
831 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
832 }
833
834 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
835 REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
836 REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF);
837 REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF);
838 REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF);
839 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
840 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
841 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
842 REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
843 REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF);
844
845 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
846
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700847 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700848 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
849 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
850
Auke Kok86582512007-10-04 15:00:08 -0700851 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
852 REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700853 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700854 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
855 REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
856 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000857 mask = 0x8003FFFF;
858 switch (mac->type) {
859 case e1000_ich10lan:
860 case e1000_pchlan:
861 mask |= (1 << 18);
862 break;
863 default:
864 break;
865 }
Auke Kok86582512007-10-04 15:00:08 -0700866 for (i = 0; i < mac->rar_entry_count; i++)
867 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
Bruce Allana4f58f52009-06-02 11:29:18 +0000868 mask, 0xFFFFFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700869
870 for (i = 0; i < mac->mta_reg_count; i++)
871 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
872
873 *data = 0;
874 return 0;
875}
876
877static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
878{
879 u16 temp;
880 u16 checksum = 0;
881 u16 i;
882
883 *data = 0;
884 /* Read and add up the contents of the EEPROM */
885 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
886 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
887 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800888 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700889 }
890 checksum += temp;
891 }
892
893 /* If Checksum is not Correct return error else test passed */
894 if ((checksum != (u16) NVM_SUM) && !(*data))
895 *data = 2;
896
897 return *data;
898}
899
900static irqreturn_t e1000_test_intr(int irq, void *data)
901{
902 struct net_device *netdev = (struct net_device *) data;
903 struct e1000_adapter *adapter = netdev_priv(netdev);
904 struct e1000_hw *hw = &adapter->hw;
905
906 adapter->test_icr |= er32(ICR);
907
908 return IRQ_HANDLED;
909}
910
911static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
912{
913 struct net_device *netdev = adapter->netdev;
914 struct e1000_hw *hw = &adapter->hw;
915 u32 mask;
916 u32 shared_int = 1;
917 u32 irq = adapter->pdev->irq;
918 int i;
Bruce Allan4662e822008-08-26 18:37:06 -0700919 int ret_val = 0;
920 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700921
922 *data = 0;
923
Bruce Allan4662e822008-08-26 18:37:06 -0700924 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
925 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
926 int_mode = adapter->int_mode;
927 e1000e_reset_interrupt_capability(adapter);
928 adapter->int_mode = E1000E_INT_MODE_LEGACY;
929 e1000e_set_interrupt_capability(adapter);
930 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700931 /* Hook up test interrupt handler just for this test */
932 if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
933 netdev)) {
934 shared_int = 0;
935 } else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED,
936 netdev->name, netdev)) {
937 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700938 ret_val = -1;
939 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700940 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700941 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700942
943 /* Disable all the interrupts */
944 ew32(IMC, 0xFFFFFFFF);
945 msleep(10);
946
947 /* Test each interrupt */
948 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700949 /* Interrupt to test */
950 mask = 1 << i;
951
Bruce Allanf4187b52008-08-26 18:36:50 -0700952 if (adapter->flags & FLAG_IS_ICH) {
953 switch (mask) {
954 case E1000_ICR_RXSEQ:
955 continue;
956 case 0x00000100:
957 if (adapter->hw.mac.type == e1000_ich8lan ||
958 adapter->hw.mac.type == e1000_ich9lan)
959 continue;
960 break;
961 default:
962 break;
963 }
964 }
965
Auke Kokbc7f75f2007-09-17 12:30:59 -0700966 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700967 /*
968 * Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700969 * the cause register and then force the same
970 * interrupt and see if one gets posted. If
971 * an interrupt was posted to the bus, the
972 * test failed.
973 */
974 adapter->test_icr = 0;
975 ew32(IMC, mask);
976 ew32(ICS, mask);
977 msleep(10);
978
979 if (adapter->test_icr & mask) {
980 *data = 3;
981 break;
982 }
983 }
984
Bruce Allanad680762008-03-28 09:15:03 -0700985 /*
986 * Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700987 * the cause register and then force the same
988 * interrupt and see if one gets posted. If
989 * an interrupt was not posted to the bus, the
990 * test failed.
991 */
992 adapter->test_icr = 0;
993 ew32(IMS, mask);
994 ew32(ICS, mask);
995 msleep(10);
996
997 if (!(adapter->test_icr & mask)) {
998 *data = 4;
999 break;
1000 }
1001
1002 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -07001003 /*
1004 * Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001005 * the cause register and then force the other
1006 * interrupts and see if any get posted. If
1007 * an interrupt was posted to the bus, the
1008 * test failed.
1009 */
1010 adapter->test_icr = 0;
1011 ew32(IMC, ~mask & 0x00007FFF);
1012 ew32(ICS, ~mask & 0x00007FFF);
1013 msleep(10);
1014
1015 if (adapter->test_icr) {
1016 *data = 5;
1017 break;
1018 }
1019 }
1020 }
1021
1022 /* Disable all the interrupts */
1023 ew32(IMC, 0xFFFFFFFF);
1024 msleep(10);
1025
1026 /* Unhook test interrupt handler */
1027 free_irq(irq, netdev);
1028
Bruce Allan4662e822008-08-26 18:37:06 -07001029out:
1030 if (int_mode == E1000E_INT_MODE_MSIX) {
1031 e1000e_reset_interrupt_capability(adapter);
1032 adapter->int_mode = int_mode;
1033 e1000e_set_interrupt_capability(adapter);
1034 }
1035
1036 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001037}
1038
1039static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1040{
1041 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1042 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1043 struct pci_dev *pdev = adapter->pdev;
1044 int i;
1045
1046 if (tx_ring->desc && tx_ring->buffer_info) {
1047 for (i = 0; i < tx_ring->count; i++) {
1048 if (tx_ring->buffer_info[i].dma)
1049 pci_unmap_single(pdev,
1050 tx_ring->buffer_info[i].dma,
1051 tx_ring->buffer_info[i].length,
1052 PCI_DMA_TODEVICE);
1053 if (tx_ring->buffer_info[i].skb)
1054 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1055 }
1056 }
1057
1058 if (rx_ring->desc && rx_ring->buffer_info) {
1059 for (i = 0; i < rx_ring->count; i++) {
1060 if (rx_ring->buffer_info[i].dma)
1061 pci_unmap_single(pdev,
1062 rx_ring->buffer_info[i].dma,
1063 2048, PCI_DMA_FROMDEVICE);
1064 if (rx_ring->buffer_info[i].skb)
1065 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1066 }
1067 }
1068
1069 if (tx_ring->desc) {
1070 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1071 tx_ring->dma);
1072 tx_ring->desc = NULL;
1073 }
1074 if (rx_ring->desc) {
1075 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1076 rx_ring->dma);
1077 rx_ring->desc = NULL;
1078 }
1079
1080 kfree(tx_ring->buffer_info);
1081 tx_ring->buffer_info = NULL;
1082 kfree(rx_ring->buffer_info);
1083 rx_ring->buffer_info = NULL;
1084}
1085
1086static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1087{
1088 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1089 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1090 struct pci_dev *pdev = adapter->pdev;
1091 struct e1000_hw *hw = &adapter->hw;
1092 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001093 int i;
1094 int ret_val;
1095
1096 /* Setup Tx descriptor ring and Tx buffers */
1097
1098 if (!tx_ring->count)
1099 tx_ring->count = E1000_DEFAULT_TXD;
1100
Bruce Allancef8c792008-04-02 13:48:23 -07001101 tx_ring->buffer_info = kcalloc(tx_ring->count,
1102 sizeof(struct e1000_buffer),
1103 GFP_KERNEL);
1104 if (!(tx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001105 ret_val = 1;
1106 goto err_nomem;
1107 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001108
1109 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1110 tx_ring->size = ALIGN(tx_ring->size, 4096);
1111 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1112 &tx_ring->dma, GFP_KERNEL);
1113 if (!tx_ring->desc) {
1114 ret_val = 2;
1115 goto err_nomem;
1116 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001117 tx_ring->next_to_use = 0;
1118 tx_ring->next_to_clean = 0;
1119
Bruce Allancef8c792008-04-02 13:48:23 -07001120 ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001121 ew32(TDBAH, ((u64) tx_ring->dma >> 32));
Bruce Allancef8c792008-04-02 13:48:23 -07001122 ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001123 ew32(TDH, 0);
1124 ew32(TDT, 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001125 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1126 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1127 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001128
1129 for (i = 0; i < tx_ring->count; i++) {
1130 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1131 struct sk_buff *skb;
1132 unsigned int skb_size = 1024;
1133
1134 skb = alloc_skb(skb_size, GFP_KERNEL);
1135 if (!skb) {
1136 ret_val = 3;
1137 goto err_nomem;
1138 }
1139 skb_put(skb, skb_size);
1140 tx_ring->buffer_info[i].skb = skb;
1141 tx_ring->buffer_info[i].length = skb->len;
1142 tx_ring->buffer_info[i].dma =
1143 pci_map_single(pdev, skb->data, skb->len,
1144 PCI_DMA_TODEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001145 if (pci_dma_mapping_error(pdev, tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001146 ret_val = 4;
1147 goto err_nomem;
1148 }
Bruce Allancef8c792008-04-02 13:48:23 -07001149 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001150 tx_desc->lower.data = cpu_to_le32(skb->len);
1151 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1152 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001153 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001154 tx_desc->upper.data = 0;
1155 }
1156
1157 /* Setup Rx descriptor ring and Rx buffers */
1158
1159 if (!rx_ring->count)
1160 rx_ring->count = E1000_DEFAULT_RXD;
1161
Bruce Allancef8c792008-04-02 13:48:23 -07001162 rx_ring->buffer_info = kcalloc(rx_ring->count,
1163 sizeof(struct e1000_buffer),
1164 GFP_KERNEL);
1165 if (!(rx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001166 ret_val = 5;
1167 goto err_nomem;
1168 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001169
1170 rx_ring->size = rx_ring->count * sizeof(struct e1000_rx_desc);
1171 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1172 &rx_ring->dma, GFP_KERNEL);
1173 if (!rx_ring->desc) {
1174 ret_val = 6;
1175 goto err_nomem;
1176 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001177 rx_ring->next_to_use = 0;
1178 rx_ring->next_to_clean = 0;
1179
1180 rctl = er32(RCTL);
1181 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1182 ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
1183 ew32(RDBAH, ((u64) rx_ring->dma >> 32));
1184 ew32(RDLEN, rx_ring->size);
1185 ew32(RDH, 0);
1186 ew32(RDT, 0);
1187 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allancef8c792008-04-02 13:48:23 -07001188 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1189 E1000_RCTL_SBP | E1000_RCTL_SECRC |
Auke Kokbc7f75f2007-09-17 12:30:59 -07001190 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1191 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1192 ew32(RCTL, rctl);
1193
1194 for (i = 0; i < rx_ring->count; i++) {
1195 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
1196 struct sk_buff *skb;
1197
1198 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1199 if (!skb) {
1200 ret_val = 7;
1201 goto err_nomem;
1202 }
1203 skb_reserve(skb, NET_IP_ALIGN);
1204 rx_ring->buffer_info[i].skb = skb;
1205 rx_ring->buffer_info[i].dma =
1206 pci_map_single(pdev, skb->data, 2048,
1207 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001208 if (pci_dma_mapping_error(pdev, rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001209 ret_val = 8;
1210 goto err_nomem;
1211 }
1212 rx_desc->buffer_addr =
1213 cpu_to_le64(rx_ring->buffer_info[i].dma);
1214 memset(skb->data, 0x00, skb->len);
1215 }
1216
1217 return 0;
1218
1219err_nomem:
1220 e1000_free_desc_rings(adapter);
1221 return ret_val;
1222}
1223
1224static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1225{
1226 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1227 e1e_wphy(&adapter->hw, 29, 0x001F);
1228 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1229 e1e_wphy(&adapter->hw, 29, 0x001A);
1230 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1231}
1232
1233static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1234{
1235 struct e1000_hw *hw = &adapter->hw;
1236 u32 ctrl_reg = 0;
1237 u32 stat_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001238 u16 phy_reg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001239
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001240 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001241
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001242 if (hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001243 /* Auto-MDI/MDIX Off */
1244 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1245 /* reset to update Auto-MDI/MDIX */
1246 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1247 /* autoneg off */
1248 e1e_wphy(hw, PHY_CONTROL, 0x8140);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001249 } else if (hw->phy.type == e1000_phy_gg82563)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001250 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
1251
1252 ctrl_reg = er32(CTRL);
1253
Bruce Allancef8c792008-04-02 13:48:23 -07001254 switch (hw->phy.type) {
1255 case e1000_phy_ife:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001256 /* force 100, set loopback */
1257 e1e_wphy(hw, PHY_CONTROL, 0x6100);
1258
1259 /* Now set up the MAC to the same speed/duplex as the PHY. */
1260 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1261 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1262 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1263 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1264 E1000_CTRL_FD); /* Force Duplex to FULL */
Bruce Allancef8c792008-04-02 13:48:23 -07001265 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001266 case e1000_phy_bm:
1267 /* Set Default MAC Interface speed to 1GB */
1268 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1269 phy_reg &= ~0x0007;
1270 phy_reg |= 0x006;
1271 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1272 /* Assert SW reset for above settings to take effect */
1273 e1000e_commit_phy(hw);
1274 mdelay(1);
1275 /* Force Full Duplex */
1276 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1277 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1278 /* Set Link Up (in force link) */
1279 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1280 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1281 /* Force Link */
1282 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1283 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1284 /* Set Early Link Enable */
1285 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1286 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
1287 /* fall through */
Bruce Allancef8c792008-04-02 13:48:23 -07001288 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001289 /* force 1000, set loopback */
1290 e1e_wphy(hw, PHY_CONTROL, 0x4140);
Bruce Allancef8c792008-04-02 13:48:23 -07001291 mdelay(250);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001292
1293 /* Now set up the MAC to the same speed/duplex as the PHY. */
1294 ctrl_reg = er32(CTRL);
1295 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1296 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1297 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1298 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1299 E1000_CTRL_FD); /* Force Duplex to FULL */
Bruce Allancef8c792008-04-02 13:48:23 -07001300
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001301 if (adapter->flags & FLAG_IS_ICH)
Bruce Allancef8c792008-04-02 13:48:23 -07001302 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001303 }
1304
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001305 if (hw->phy.media_type == e1000_media_type_copper &&
1306 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001307 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1308 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001309 /*
1310 * Set the ILOS bit on the fiber Nic if half duplex link is
1311 * detected.
1312 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001313 stat_reg = er32(STATUS);
1314 if ((stat_reg & E1000_STATUS_FD) == 0)
1315 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1316 }
1317
1318 ew32(CTRL, ctrl_reg);
1319
Bruce Allanad680762008-03-28 09:15:03 -07001320 /*
1321 * Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001322 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1323 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001324 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001325 e1000_phy_disable_receiver(adapter);
1326
1327 udelay(500);
1328
1329 return 0;
1330}
1331
1332static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1333{
1334 struct e1000_hw *hw = &adapter->hw;
1335 u32 ctrl = er32(CTRL);
1336 int link = 0;
1337
1338 /* special requirements for 82571/82572 fiber adapters */
1339
Bruce Allanad680762008-03-28 09:15:03 -07001340 /*
1341 * jump through hoops to make sure link is up because serdes
1342 * link is hardwired up
1343 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001344 ctrl |= E1000_CTRL_SLU;
1345 ew32(CTRL, ctrl);
1346
1347 /* disable autoneg */
1348 ctrl = er32(TXCW);
1349 ctrl &= ~(1 << 31);
1350 ew32(TXCW, ctrl);
1351
1352 link = (er32(STATUS) & E1000_STATUS_LU);
1353
1354 if (!link) {
1355 /* set invert loss of signal */
1356 ctrl = er32(CTRL);
1357 ctrl |= E1000_CTRL_ILOS;
1358 ew32(CTRL, ctrl);
1359 }
1360
Bruce Allanad680762008-03-28 09:15:03 -07001361 /*
1362 * special write to serdes control register to enable SerDes analog
1363 * loopback
1364 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001365#define E1000_SERDES_LB_ON 0x410
1366 ew32(SCTL, E1000_SERDES_LB_ON);
1367 msleep(10);
1368
1369 return 0;
1370}
1371
1372/* only call this for fiber/serdes connections to es2lan */
1373static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1374{
1375 struct e1000_hw *hw = &adapter->hw;
1376 u32 ctrlext = er32(CTRL_EXT);
1377 u32 ctrl = er32(CTRL);
1378
Bruce Allanad680762008-03-28 09:15:03 -07001379 /*
1380 * save CTRL_EXT to restore later, reuse an empty variable (unused
1381 * on mac_type 80003es2lan)
1382 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001383 adapter->tx_fifo_head = ctrlext;
1384
1385 /* clear the serdes mode bits, putting the device into mac loopback */
1386 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1387 ew32(CTRL_EXT, ctrlext);
1388
1389 /* force speed to 1000/FD, link up */
1390 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1391 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1392 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1393 ew32(CTRL, ctrl);
1394
1395 /* set mac loopback */
1396 ctrl = er32(RCTL);
1397 ctrl |= E1000_RCTL_LBM_MAC;
1398 ew32(RCTL, ctrl);
1399
1400 /* set testing mode parameters (no need to reset later) */
1401#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1402#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1403 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001404 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001405
1406 return 0;
1407}
1408
1409static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1410{
1411 struct e1000_hw *hw = &adapter->hw;
1412 u32 rctl;
1413
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001414 if (hw->phy.media_type == e1000_media_type_fiber ||
1415 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001416 switch (hw->mac.type) {
1417 case e1000_80003es2lan:
1418 return e1000_set_es2lan_mac_loopback(adapter);
1419 break;
1420 case e1000_82571:
1421 case e1000_82572:
1422 return e1000_set_82571_fiber_loopback(adapter);
1423 break;
1424 default:
1425 rctl = er32(RCTL);
1426 rctl |= E1000_RCTL_LBM_TCVR;
1427 ew32(RCTL, rctl);
1428 return 0;
1429 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001430 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001431 return e1000_integrated_phy_loopback(adapter);
1432 }
1433
1434 return 7;
1435}
1436
1437static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1438{
1439 struct e1000_hw *hw = &adapter->hw;
1440 u32 rctl;
1441 u16 phy_reg;
1442
1443 rctl = er32(RCTL);
1444 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1445 ew32(RCTL, rctl);
1446
1447 switch (hw->mac.type) {
1448 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001449 if (hw->phy.media_type == e1000_media_type_fiber ||
1450 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001451 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001452 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001453 adapter->tx_fifo_head = 0;
1454 }
1455 /* fall through */
1456 case e1000_82571:
1457 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001458 if (hw->phy.media_type == e1000_media_type_fiber ||
1459 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001460#define E1000_SERDES_LB_OFF 0x400
1461 ew32(SCTL, E1000_SERDES_LB_OFF);
1462 msleep(10);
1463 break;
1464 }
1465 /* Fall Through */
1466 default:
1467 hw->mac.autoneg = 1;
1468 if (hw->phy.type == e1000_phy_gg82563)
1469 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1470 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1471 if (phy_reg & MII_CR_LOOPBACK) {
1472 phy_reg &= ~MII_CR_LOOPBACK;
1473 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1474 e1000e_commit_phy(hw);
1475 }
1476 break;
1477 }
1478}
1479
1480static void e1000_create_lbtest_frame(struct sk_buff *skb,
1481 unsigned int frame_size)
1482{
1483 memset(skb->data, 0xFF, frame_size);
1484 frame_size &= ~1;
1485 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1486 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1487 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1488}
1489
1490static int e1000_check_lbtest_frame(struct sk_buff *skb,
1491 unsigned int frame_size)
1492{
1493 frame_size &= ~1;
1494 if (*(skb->data + 3) == 0xFF)
1495 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1496 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1497 return 0;
1498 return 13;
1499}
1500
1501static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1502{
1503 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1504 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1505 struct pci_dev *pdev = adapter->pdev;
1506 struct e1000_hw *hw = &adapter->hw;
1507 int i, j, k, l;
1508 int lc;
1509 int good_cnt;
1510 int ret_val = 0;
1511 unsigned long time;
1512
1513 ew32(RDT, rx_ring->count - 1);
1514
Bruce Allanad680762008-03-28 09:15:03 -07001515 /*
1516 * Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001517 * The idea is to wrap the largest ring a number of times using 64
1518 * send/receive pairs during each loop
1519 */
1520
1521 if (rx_ring->count <= tx_ring->count)
1522 lc = ((tx_ring->count / 64) * 2) + 1;
1523 else
1524 lc = ((rx_ring->count / 64) * 2) + 1;
1525
1526 k = 0;
1527 l = 0;
1528 for (j = 0; j <= lc; j++) { /* loop count loop */
1529 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001530 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1531 1024);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001532 pci_dma_sync_single_for_device(pdev,
1533 tx_ring->buffer_info[k].dma,
1534 tx_ring->buffer_info[k].length,
1535 PCI_DMA_TODEVICE);
1536 k++;
1537 if (k == tx_ring->count)
1538 k = 0;
1539 }
1540 ew32(TDT, k);
1541 msleep(200);
1542 time = jiffies; /* set the start time for the receive */
1543 good_cnt = 0;
1544 do { /* receive the sent packets */
1545 pci_dma_sync_single_for_cpu(pdev,
1546 rx_ring->buffer_info[l].dma, 2048,
1547 PCI_DMA_FROMDEVICE);
1548
1549 ret_val = e1000_check_lbtest_frame(
1550 rx_ring->buffer_info[l].skb, 1024);
1551 if (!ret_val)
1552 good_cnt++;
1553 l++;
1554 if (l == rx_ring->count)
1555 l = 0;
Bruce Allanad680762008-03-28 09:15:03 -07001556 /*
1557 * time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001558 * enough time to complete the receives, if it's
1559 * exceeded, break and error off
1560 */
1561 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1562 if (good_cnt != 64) {
1563 ret_val = 13; /* ret_val is the same as mis-compare */
1564 break;
1565 }
Bruce Allancef8c792008-04-02 13:48:23 -07001566 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001567 ret_val = 14; /* error code for time out error */
1568 break;
1569 }
1570 } /* end loop count loop */
1571 return ret_val;
1572}
1573
1574static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1575{
Bruce Allanad680762008-03-28 09:15:03 -07001576 /*
1577 * PHY loopback cannot be performed if SoL/IDER
1578 * sessions are active
1579 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001580 if (e1000_check_reset_block(&adapter->hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001581 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001582 *data = 0;
1583 goto out;
1584 }
1585
1586 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001587 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001588 goto out;
1589
1590 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001591 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001592 goto err_loopback;
1593
1594 *data = e1000_run_loopback_test(adapter);
1595 e1000_loopback_cleanup(adapter);
1596
1597err_loopback:
1598 e1000_free_desc_rings(adapter);
1599out:
1600 return *data;
1601}
1602
1603static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1604{
1605 struct e1000_hw *hw = &adapter->hw;
1606
1607 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001608 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001609 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001610 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001611
Bruce Allanad680762008-03-28 09:15:03 -07001612 /*
1613 * On some blade server designs, link establishment
1614 * could take as long as 2-3 minutes
1615 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001616 do {
1617 hw->mac.ops.check_for_link(hw);
1618 if (hw->mac.serdes_has_link)
1619 return *data;
1620 msleep(20);
1621 } while (i++ < 3750);
1622
1623 *data = 1;
1624 } else {
1625 hw->mac.ops.check_for_link(hw);
1626 if (hw->mac.autoneg)
1627 msleep(4000);
1628
1629 if (!(er32(STATUS) &
1630 E1000_STATUS_LU))
1631 *data = 1;
1632 }
1633 return *data;
1634}
1635
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001636static int e1000e_get_sset_count(struct net_device *netdev, int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001637{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001638 switch (sset) {
1639 case ETH_SS_TEST:
1640 return E1000_TEST_LEN;
1641 case ETH_SS_STATS:
1642 return E1000_STATS_LEN;
1643 default:
1644 return -EOPNOTSUPP;
1645 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001646}
1647
1648static void e1000_diag_test(struct net_device *netdev,
1649 struct ethtool_test *eth_test, u64 *data)
1650{
1651 struct e1000_adapter *adapter = netdev_priv(netdev);
1652 u16 autoneg_advertised;
1653 u8 forced_speed_duplex;
1654 u8 autoneg;
1655 bool if_running = netif_running(netdev);
1656
1657 set_bit(__E1000_TESTING, &adapter->state);
1658 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1659 /* Offline tests */
1660
1661 /* save speed, duplex, autoneg settings */
1662 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1663 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1664 autoneg = adapter->hw.mac.autoneg;
1665
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001666 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001667
Bruce Allanad680762008-03-28 09:15:03 -07001668 /*
1669 * Link test performed before hardware reset so autoneg doesn't
1670 * interfere with test result
1671 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001672 if (e1000_link_test(adapter, &data[4]))
1673 eth_test->flags |= ETH_TEST_FL_FAILED;
1674
1675 if (if_running)
1676 /* indicate we're in test mode */
1677 dev_close(netdev);
1678 else
1679 e1000e_reset(adapter);
1680
1681 if (e1000_reg_test(adapter, &data[0]))
1682 eth_test->flags |= ETH_TEST_FL_FAILED;
1683
1684 e1000e_reset(adapter);
1685 if (e1000_eeprom_test(adapter, &data[1]))
1686 eth_test->flags |= ETH_TEST_FL_FAILED;
1687
1688 e1000e_reset(adapter);
1689 if (e1000_intr_test(adapter, &data[2]))
1690 eth_test->flags |= ETH_TEST_FL_FAILED;
1691
1692 e1000e_reset(adapter);
1693 /* make sure the phy is powered up */
1694 e1000e_power_up_phy(adapter);
1695 if (e1000_loopback_test(adapter, &data[3]))
1696 eth_test->flags |= ETH_TEST_FL_FAILED;
1697
1698 /* restore speed, duplex, autoneg settings */
1699 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1700 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1701 adapter->hw.mac.autoneg = autoneg;
1702
1703 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001704 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001705 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001706 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001707
1708 clear_bit(__E1000_TESTING, &adapter->state);
1709 if (if_running)
1710 dev_open(netdev);
1711 } else {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001712 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001713 /* Online tests */
1714 if (e1000_link_test(adapter, &data[4]))
1715 eth_test->flags |= ETH_TEST_FL_FAILED;
1716
1717 /* Online tests aren't run; pass by default */
1718 data[0] = 0;
1719 data[1] = 0;
1720 data[2] = 0;
1721 data[3] = 0;
1722
1723 clear_bit(__E1000_TESTING, &adapter->state);
1724 }
1725 msleep_interruptible(4 * 1000);
1726}
1727
1728static void e1000_get_wol(struct net_device *netdev,
1729 struct ethtool_wolinfo *wol)
1730{
1731 struct e1000_adapter *adapter = netdev_priv(netdev);
1732
1733 wol->supported = 0;
1734 wol->wolopts = 0;
1735
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001736 if (!(adapter->flags & FLAG_HAS_WOL) ||
1737 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001738 return;
1739
1740 wol->supported = WAKE_UCAST | WAKE_MCAST |
Mitch Williamsefb90e42008-01-29 12:43:02 -08001741 WAKE_BCAST | WAKE_MAGIC |
1742 WAKE_PHY | WAKE_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001743
1744 /* apply any specific unsupported masks here */
1745 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1746 wol->supported &= ~WAKE_UCAST;
1747
1748 if (adapter->wol & E1000_WUFC_EX)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001749 e_err("Interface does not support directed (unicast) "
1750 "frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001751 }
1752
1753 if (adapter->wol & E1000_WUFC_EX)
1754 wol->wolopts |= WAKE_UCAST;
1755 if (adapter->wol & E1000_WUFC_MC)
1756 wol->wolopts |= WAKE_MCAST;
1757 if (adapter->wol & E1000_WUFC_BC)
1758 wol->wolopts |= WAKE_BCAST;
1759 if (adapter->wol & E1000_WUFC_MAG)
1760 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001761 if (adapter->wol & E1000_WUFC_LNKC)
1762 wol->wolopts |= WAKE_PHY;
1763 if (adapter->wol & E1000_WUFC_ARP)
1764 wol->wolopts |= WAKE_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001765}
1766
1767static int e1000_set_wol(struct net_device *netdev,
1768 struct ethtool_wolinfo *wol)
1769{
1770 struct e1000_adapter *adapter = netdev_priv(netdev);
1771
Mitch Williamsefb90e42008-01-29 12:43:02 -08001772 if (wol->wolopts & WAKE_MAGICSECURE)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001773 return -EOPNOTSUPP;
1774
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001775 if (!(adapter->flags & FLAG_HAS_WOL) ||
1776 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001777 return wol->wolopts ? -EOPNOTSUPP : 0;
1778
1779 /* these settings will always override what we currently have */
1780 adapter->wol = 0;
1781
1782 if (wol->wolopts & WAKE_UCAST)
1783 adapter->wol |= E1000_WUFC_EX;
1784 if (wol->wolopts & WAKE_MCAST)
1785 adapter->wol |= E1000_WUFC_MC;
1786 if (wol->wolopts & WAKE_BCAST)
1787 adapter->wol |= E1000_WUFC_BC;
1788 if (wol->wolopts & WAKE_MAGIC)
1789 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001790 if (wol->wolopts & WAKE_PHY)
1791 adapter->wol |= E1000_WUFC_LNKC;
1792 if (wol->wolopts & WAKE_ARP)
1793 adapter->wol |= E1000_WUFC_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001794
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001795 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1796
Auke Kokbc7f75f2007-09-17 12:30:59 -07001797 return 0;
1798}
1799
1800/* toggle LED 4 times per second = 2 "blinks" per second */
1801#define E1000_ID_INTERVAL (HZ/4)
1802
1803/* bit defines for adapter->led_status */
1804#define E1000_LED_ON 0
1805
Bruce Allana4f58f52009-06-02 11:29:18 +00001806static void e1000e_led_blink_task(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001807{
Bruce Allana4f58f52009-06-02 11:29:18 +00001808 struct e1000_adapter *adapter = container_of(work,
1809 struct e1000_adapter, led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001810
1811 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
1812 adapter->hw.mac.ops.led_off(&adapter->hw);
1813 else
1814 adapter->hw.mac.ops.led_on(&adapter->hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001815}
Auke Kokbc7f75f2007-09-17 12:30:59 -07001816
Bruce Allana4f58f52009-06-02 11:29:18 +00001817static void e1000_led_blink_callback(unsigned long data)
1818{
1819 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1820
1821 schedule_work(&adapter->led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001822 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1823}
1824
1825static int e1000_phys_id(struct net_device *netdev, u32 data)
1826{
1827 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001828 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001829
Stephen Hemminger5a9147b2007-10-29 10:46:05 -07001830 if (!data)
1831 data = INT_MAX;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001832
Bruce Allan4662e822008-08-26 18:37:06 -07001833 if ((hw->phy.type == e1000_phy_ife) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00001834 (hw->mac.type == e1000_pchlan) ||
Bruce Allan4662e822008-08-26 18:37:06 -07001835 (hw->mac.type == e1000_82574)) {
Bruce Allana4f58f52009-06-02 11:29:18 +00001836 INIT_WORK(&adapter->led_blink_task, e1000e_led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001837 if (!adapter->blink_timer.function) {
1838 init_timer(&adapter->blink_timer);
1839 adapter->blink_timer.function =
1840 e1000_led_blink_callback;
1841 adapter->blink_timer.data = (unsigned long) adapter;
1842 }
1843 mod_timer(&adapter->blink_timer, jiffies);
1844 msleep_interruptible(data * 1000);
1845 del_timer_sync(&adapter->blink_timer);
Bruce Allan4662e822008-08-26 18:37:06 -07001846 if (hw->phy.type == e1000_phy_ife)
1847 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001848 } else {
Bruce Allan4662e822008-08-26 18:37:06 -07001849 e1000e_blink_led(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001850 msleep_interruptible(data * 1000);
1851 }
1852
Bruce Allan4662e822008-08-26 18:37:06 -07001853 hw->mac.ops.led_off(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001854 clear_bit(E1000_LED_ON, &adapter->led_status);
Bruce Allan4662e822008-08-26 18:37:06 -07001855 hw->mac.ops.cleanup_led(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001856
1857 return 0;
1858}
1859
Auke Kokde5b3072008-04-23 11:09:08 -07001860static int e1000_get_coalesce(struct net_device *netdev,
1861 struct ethtool_coalesce *ec)
1862{
1863 struct e1000_adapter *adapter = netdev_priv(netdev);
1864
1865 if (adapter->itr_setting <= 3)
1866 ec->rx_coalesce_usecs = adapter->itr_setting;
1867 else
1868 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1869
1870 return 0;
1871}
1872
1873static int e1000_set_coalesce(struct net_device *netdev,
1874 struct ethtool_coalesce *ec)
1875{
1876 struct e1000_adapter *adapter = netdev_priv(netdev);
1877 struct e1000_hw *hw = &adapter->hw;
1878
1879 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
1880 ((ec->rx_coalesce_usecs > 3) &&
1881 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1882 (ec->rx_coalesce_usecs == 2))
1883 return -EINVAL;
1884
1885 if (ec->rx_coalesce_usecs <= 3) {
1886 adapter->itr = 20000;
1887 adapter->itr_setting = ec->rx_coalesce_usecs;
1888 } else {
1889 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1890 adapter->itr_setting = adapter->itr & ~3;
1891 }
1892
1893 if (adapter->itr_setting != 0)
1894 ew32(ITR, 1000000000 / (adapter->itr * 256));
1895 else
1896 ew32(ITR, 0);
1897
1898 return 0;
1899}
1900
Auke Kokbc7f75f2007-09-17 12:30:59 -07001901static int e1000_nway_reset(struct net_device *netdev)
1902{
1903 struct e1000_adapter *adapter = netdev_priv(netdev);
1904 if (netif_running(netdev))
1905 e1000e_reinit_locked(adapter);
1906 return 0;
1907}
1908
Auke Kokbc7f75f2007-09-17 12:30:59 -07001909static void e1000_get_ethtool_stats(struct net_device *netdev,
1910 struct ethtool_stats *stats,
1911 u64 *data)
1912{
1913 struct e1000_adapter *adapter = netdev_priv(netdev);
1914 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001915 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001916
1917 e1000e_update_stats(adapter);
1918 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001919 switch (e1000_gstrings_stats[i].type) {
1920 case NETDEV_STATS:
1921 p = (char *) netdev +
1922 e1000_gstrings_stats[i].stat_offset;
1923 break;
1924 case E1000_STATS:
1925 p = (char *) adapter +
1926 e1000_gstrings_stats[i].stat_offset;
1927 break;
1928 }
1929
Auke Kokbc7f75f2007-09-17 12:30:59 -07001930 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1931 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1932 }
1933}
1934
1935static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1936 u8 *data)
1937{
1938 u8 *p = data;
1939 int i;
1940
1941 switch (stringset) {
1942 case ETH_SS_TEST:
Bruce Allanad680762008-03-28 09:15:03 -07001943 memcpy(data, *e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001944 break;
1945 case ETH_SS_STATS:
1946 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1947 memcpy(p, e1000_gstrings_stats[i].stat_string,
1948 ETH_GSTRING_LEN);
1949 p += ETH_GSTRING_LEN;
1950 }
1951 break;
1952 }
1953}
1954
1955static const struct ethtool_ops e1000_ethtool_ops = {
1956 .get_settings = e1000_get_settings,
1957 .set_settings = e1000_set_settings,
1958 .get_drvinfo = e1000_get_drvinfo,
1959 .get_regs_len = e1000_get_regs_len,
1960 .get_regs = e1000_get_regs,
1961 .get_wol = e1000_get_wol,
1962 .set_wol = e1000_set_wol,
1963 .get_msglevel = e1000_get_msglevel,
1964 .set_msglevel = e1000_set_msglevel,
1965 .nway_reset = e1000_nway_reset,
Auke Kok369d7422007-10-15 14:30:59 -07001966 .get_link = e1000_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001967 .get_eeprom_len = e1000_get_eeprom_len,
1968 .get_eeprom = e1000_get_eeprom,
1969 .set_eeprom = e1000_set_eeprom,
1970 .get_ringparam = e1000_get_ringparam,
1971 .set_ringparam = e1000_set_ringparam,
1972 .get_pauseparam = e1000_get_pauseparam,
1973 .set_pauseparam = e1000_set_pauseparam,
1974 .get_rx_csum = e1000_get_rx_csum,
1975 .set_rx_csum = e1000_set_rx_csum,
1976 .get_tx_csum = e1000_get_tx_csum,
1977 .set_tx_csum = e1000_set_tx_csum,
1978 .get_sg = ethtool_op_get_sg,
1979 .set_sg = ethtool_op_set_sg,
1980 .get_tso = ethtool_op_get_tso,
1981 .set_tso = e1000_set_tso,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001982 .self_test = e1000_diag_test,
1983 .get_strings = e1000_get_strings,
1984 .phys_id = e1000_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001985 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001986 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07001987 .get_coalesce = e1000_get_coalesce,
1988 .set_coalesce = e1000_set_coalesce,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001989};
1990
1991void e1000e_set_ethtool_ops(struct net_device *netdev)
1992{
1993 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
1994}