iwlwifi: Fix TKIP update key and get_free_ucode_key
[linux-2.6] / drivers / net / e1000e / ethtool.c
1 /*******************************************************************************
2
3   Intel PRO/1000 Linux driver
4   Copyright(c) 1999 - 2008 Intel Corporation.
5
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
38 struct e1000_stats {
39         char stat_string[ETH_GSTRING_LEN];
40         int sizeof_stat;
41         int stat_offset;
42 };
43
44 #define E1000_STAT(m) sizeof(((struct e1000_adapter *)0)->m), \
45                       offsetof(struct e1000_adapter, m)
46 static const struct e1000_stats e1000_gstrings_stats[] = {
47         { "rx_packets", E1000_STAT(stats.gprc) },
48         { "tx_packets", E1000_STAT(stats.gptc) },
49         { "rx_bytes", E1000_STAT(stats.gorcl) },
50         { "tx_bytes", E1000_STAT(stats.gotcl) },
51         { "rx_broadcast", E1000_STAT(stats.bprc) },
52         { "tx_broadcast", E1000_STAT(stats.bptc) },
53         { "rx_multicast", E1000_STAT(stats.mprc) },
54         { "tx_multicast", E1000_STAT(stats.mptc) },
55         { "rx_errors", E1000_STAT(net_stats.rx_errors) },
56         { "tx_errors", E1000_STAT(net_stats.tx_errors) },
57         { "tx_dropped", E1000_STAT(net_stats.tx_dropped) },
58         { "multicast", E1000_STAT(stats.mprc) },
59         { "collisions", E1000_STAT(stats.colc) },
60         { "rx_length_errors", E1000_STAT(net_stats.rx_length_errors) },
61         { "rx_over_errors", E1000_STAT(net_stats.rx_over_errors) },
62         { "rx_crc_errors", E1000_STAT(stats.crcerrs) },
63         { "rx_frame_errors", E1000_STAT(net_stats.rx_frame_errors) },
64         { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
65         { "rx_missed_errors", E1000_STAT(stats.mpc) },
66         { "tx_aborted_errors", E1000_STAT(stats.ecol) },
67         { "tx_carrier_errors", E1000_STAT(stats.tncrs) },
68         { "tx_fifo_errors", E1000_STAT(net_stats.tx_fifo_errors) },
69         { "tx_heartbeat_errors", E1000_STAT(net_stats.tx_heartbeat_errors) },
70         { "tx_window_errors", E1000_STAT(stats.latecol) },
71         { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
72         { "tx_deferred_ok", E1000_STAT(stats.dc) },
73         { "tx_single_coll_ok", E1000_STAT(stats.scc) },
74         { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
75         { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
76         { "tx_restart_queue", E1000_STAT(restart_queue) },
77         { "rx_long_length_errors", E1000_STAT(stats.roc) },
78         { "rx_short_length_errors", E1000_STAT(stats.ruc) },
79         { "rx_align_errors", E1000_STAT(stats.algnerrc) },
80         { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
81         { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
82         { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
83         { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
84         { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
85         { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
86         { "rx_long_byte_count", E1000_STAT(stats.gorcl) },
87         { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
88         { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
89         { "rx_header_split", E1000_STAT(rx_hdr_split) },
90         { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
91         { "tx_smbus", E1000_STAT(stats.mgptc) },
92         { "rx_smbus", E1000_STAT(stats.mgprc) },
93         { "dropped_smbus", E1000_STAT(stats.mgpdc) },
94         { "rx_dma_failed", E1000_STAT(rx_dma_failed) },
95         { "tx_dma_failed", E1000_STAT(tx_dma_failed) },
96 };
97
98 #define E1000_GLOBAL_STATS_LEN  ARRAY_SIZE(e1000_gstrings_stats)
99 #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
100 static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
101         "Register test  (offline)", "Eeprom test    (offline)",
102         "Interrupt test (offline)", "Loopback test  (offline)",
103         "Link test   (on/offline)"
104 };
105 #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
106
107 static int e1000_get_settings(struct net_device *netdev,
108                               struct ethtool_cmd *ecmd)
109 {
110         struct e1000_adapter *adapter = netdev_priv(netdev);
111         struct e1000_hw *hw = &adapter->hw;
112         u32 status;
113
114         if (hw->phy.media_type == e1000_media_type_copper) {
115
116                 ecmd->supported = (SUPPORTED_10baseT_Half |
117                                    SUPPORTED_10baseT_Full |
118                                    SUPPORTED_100baseT_Half |
119                                    SUPPORTED_100baseT_Full |
120                                    SUPPORTED_1000baseT_Full |
121                                    SUPPORTED_Autoneg |
122                                    SUPPORTED_TP);
123                 if (hw->phy.type == e1000_phy_ife)
124                         ecmd->supported &= ~SUPPORTED_1000baseT_Full;
125                 ecmd->advertising = ADVERTISED_TP;
126
127                 if (hw->mac.autoneg == 1) {
128                         ecmd->advertising |= ADVERTISED_Autoneg;
129                         /* the e1000 autoneg seems to match ethtool nicely */
130                         ecmd->advertising |= hw->phy.autoneg_advertised;
131                 }
132
133                 ecmd->port = PORT_TP;
134                 ecmd->phy_address = hw->phy.addr;
135                 ecmd->transceiver = XCVR_INTERNAL;
136
137         } else {
138                 ecmd->supported   = (SUPPORTED_1000baseT_Full |
139                                      SUPPORTED_FIBRE |
140                                      SUPPORTED_Autoneg);
141
142                 ecmd->advertising = (ADVERTISED_1000baseT_Full |
143                                      ADVERTISED_FIBRE |
144                                      ADVERTISED_Autoneg);
145
146                 ecmd->port = PORT_FIBRE;
147                 ecmd->transceiver = XCVR_EXTERNAL;
148         }
149
150         status = er32(STATUS);
151         if (status & E1000_STATUS_LU) {
152                 if (status & E1000_STATUS_SPEED_1000)
153                         ecmd->speed = 1000;
154                 else if (status & E1000_STATUS_SPEED_100)
155                         ecmd->speed = 100;
156                 else
157                         ecmd->speed = 10;
158
159                 if (status & E1000_STATUS_FD)
160                         ecmd->duplex = DUPLEX_FULL;
161                 else
162                         ecmd->duplex = DUPLEX_HALF;
163         } else {
164                 ecmd->speed = -1;
165                 ecmd->duplex = -1;
166         }
167
168         ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
169                          hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
170         return 0;
171 }
172
173 static u32 e1000_get_link(struct net_device *netdev)
174 {
175         struct e1000_adapter *adapter = netdev_priv(netdev);
176         struct e1000_hw *hw = &adapter->hw;
177         u32 status;
178         
179         status = er32(STATUS);
180         return (status & E1000_STATUS_LU);
181 }
182
183 static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
184 {
185         struct e1000_mac_info *mac = &adapter->hw.mac;
186
187         mac->autoneg = 0;
188
189         /* Fiber NICs only allow 1000 gbps Full duplex */
190         if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
191                 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
192                 ndev_err(adapter->netdev, "Unsupported Speed/Duplex "
193                          "configuration\n");
194                 return -EINVAL;
195         }
196
197         switch (spddplx) {
198         case SPEED_10 + DUPLEX_HALF:
199                 mac->forced_speed_duplex = ADVERTISE_10_HALF;
200                 break;
201         case SPEED_10 + DUPLEX_FULL:
202                 mac->forced_speed_duplex = ADVERTISE_10_FULL;
203                 break;
204         case SPEED_100 + DUPLEX_HALF:
205                 mac->forced_speed_duplex = ADVERTISE_100_HALF;
206                 break;
207         case SPEED_100 + DUPLEX_FULL:
208                 mac->forced_speed_duplex = ADVERTISE_100_FULL;
209                 break;
210         case SPEED_1000 + DUPLEX_FULL:
211                 mac->autoneg = 1;
212                 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
213                 break;
214         case SPEED_1000 + DUPLEX_HALF: /* not supported */
215         default:
216                 ndev_err(adapter->netdev, "Unsupported Speed/Duplex "
217                          "configuration\n");
218                 return -EINVAL;
219         }
220         return 0;
221 }
222
223 static int e1000_set_settings(struct net_device *netdev,
224                               struct ethtool_cmd *ecmd)
225 {
226         struct e1000_adapter *adapter = netdev_priv(netdev);
227         struct e1000_hw *hw = &adapter->hw;
228
229         /*
230          * When SoL/IDER sessions are active, autoneg/speed/duplex
231          * cannot be changed
232          */
233         if (e1000_check_reset_block(hw)) {
234                 ndev_err(netdev, "Cannot change link "
235                          "characteristics when SoL/IDER is active.\n");
236                 return -EINVAL;
237         }
238
239         while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
240                 msleep(1);
241
242         if (ecmd->autoneg == AUTONEG_ENABLE) {
243                 hw->mac.autoneg = 1;
244                 if (hw->phy.media_type == e1000_media_type_fiber)
245                         hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
246                                                      ADVERTISED_FIBRE |
247                                                      ADVERTISED_Autoneg;
248                 else
249                         hw->phy.autoneg_advertised = ecmd->advertising |
250                                                      ADVERTISED_TP |
251                                                      ADVERTISED_Autoneg;
252                 ecmd->advertising = hw->phy.autoneg_advertised;
253                 if (adapter->fc_autoneg)
254                         hw->fc.original_type = e1000_fc_default;
255         } else {
256                 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
257                         clear_bit(__E1000_RESETTING, &adapter->state);
258                         return -EINVAL;
259                 }
260         }
261
262         /* reset the link */
263
264         if (netif_running(adapter->netdev)) {
265                 e1000e_down(adapter);
266                 e1000e_up(adapter);
267         } else {
268                 e1000e_reset(adapter);
269         }
270
271         clear_bit(__E1000_RESETTING, &adapter->state);
272         return 0;
273 }
274
275 static void e1000_get_pauseparam(struct net_device *netdev,
276                                  struct ethtool_pauseparam *pause)
277 {
278         struct e1000_adapter *adapter = netdev_priv(netdev);
279         struct e1000_hw *hw = &adapter->hw;
280
281         pause->autoneg =
282                 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
283
284         if (hw->fc.type == e1000_fc_rx_pause) {
285                 pause->rx_pause = 1;
286         } else if (hw->fc.type == e1000_fc_tx_pause) {
287                 pause->tx_pause = 1;
288         } else if (hw->fc.type == e1000_fc_full) {
289                 pause->rx_pause = 1;
290                 pause->tx_pause = 1;
291         }
292 }
293
294 static int e1000_set_pauseparam(struct net_device *netdev,
295                                 struct ethtool_pauseparam *pause)
296 {
297         struct e1000_adapter *adapter = netdev_priv(netdev);
298         struct e1000_hw *hw = &adapter->hw;
299         int retval = 0;
300
301         adapter->fc_autoneg = pause->autoneg;
302
303         while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
304                 msleep(1);
305
306         if (pause->rx_pause && pause->tx_pause)
307                 hw->fc.type = e1000_fc_full;
308         else if (pause->rx_pause && !pause->tx_pause)
309                 hw->fc.type = e1000_fc_rx_pause;
310         else if (!pause->rx_pause && pause->tx_pause)
311                 hw->fc.type = e1000_fc_tx_pause;
312         else if (!pause->rx_pause && !pause->tx_pause)
313                 hw->fc.type = e1000_fc_none;
314
315         hw->fc.original_type = hw->fc.type;
316
317         if (adapter->fc_autoneg == AUTONEG_ENABLE) {
318                 hw->fc.type = e1000_fc_default;
319                 if (netif_running(adapter->netdev)) {
320                         e1000e_down(adapter);
321                         e1000e_up(adapter);
322                 } else {
323                         e1000e_reset(adapter);
324                 }
325         } else {
326                 retval = ((hw->phy.media_type == e1000_media_type_fiber) ?
327                           hw->mac.ops.setup_link(hw) : e1000e_force_mac_fc(hw));
328         }
329
330         clear_bit(__E1000_RESETTING, &adapter->state);
331         return retval;
332 }
333
334 static u32 e1000_get_rx_csum(struct net_device *netdev)
335 {
336         struct e1000_adapter *adapter = netdev_priv(netdev);
337         return (adapter->flags & FLAG_RX_CSUM_ENABLED);
338 }
339
340 static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
341 {
342         struct e1000_adapter *adapter = netdev_priv(netdev);
343
344         if (data)
345                 adapter->flags |= FLAG_RX_CSUM_ENABLED;
346         else
347                 adapter->flags &= ~FLAG_RX_CSUM_ENABLED;
348
349         if (netif_running(netdev))
350                 e1000e_reinit_locked(adapter);
351         else
352                 e1000e_reset(adapter);
353         return 0;
354 }
355
356 static u32 e1000_get_tx_csum(struct net_device *netdev)
357 {
358         return ((netdev->features & NETIF_F_HW_CSUM) != 0);
359 }
360
361 static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
362 {
363         if (data)
364                 netdev->features |= NETIF_F_HW_CSUM;
365         else
366                 netdev->features &= ~NETIF_F_HW_CSUM;
367
368         return 0;
369 }
370
371 static int e1000_set_tso(struct net_device *netdev, u32 data)
372 {
373         struct e1000_adapter *adapter = netdev_priv(netdev);
374
375         if (data) {
376                 netdev->features |= NETIF_F_TSO;
377                 netdev->features |= NETIF_F_TSO6;
378         } else {
379                 netdev->features &= ~NETIF_F_TSO;
380                 netdev->features &= ~NETIF_F_TSO6;
381         }
382
383         ndev_info(netdev, "TSO is %s\n",
384                   data ? "Enabled" : "Disabled");
385         adapter->flags |= FLAG_TSO_FORCE;
386         return 0;
387 }
388
389 static u32 e1000_get_msglevel(struct net_device *netdev)
390 {
391         struct e1000_adapter *adapter = netdev_priv(netdev);
392         return adapter->msg_enable;
393 }
394
395 static void e1000_set_msglevel(struct net_device *netdev, u32 data)
396 {
397         struct e1000_adapter *adapter = netdev_priv(netdev);
398         adapter->msg_enable = data;
399 }
400
401 static int e1000_get_regs_len(struct net_device *netdev)
402 {
403 #define E1000_REGS_LEN 32 /* overestimate */
404         return E1000_REGS_LEN * sizeof(u32);
405 }
406
407 static void e1000_get_regs(struct net_device *netdev,
408                            struct ethtool_regs *regs, void *p)
409 {
410         struct e1000_adapter *adapter = netdev_priv(netdev);
411         struct e1000_hw *hw = &adapter->hw;
412         u32 *regs_buff = p;
413         u16 phy_data;
414         u8 revision_id;
415
416         memset(p, 0, E1000_REGS_LEN * sizeof(u32));
417
418         pci_read_config_byte(adapter->pdev, PCI_REVISION_ID, &revision_id);
419
420         regs->version = (1 << 24) | (revision_id << 16) | adapter->pdev->device;
421
422         regs_buff[0]  = er32(CTRL);
423         regs_buff[1]  = er32(STATUS);
424
425         regs_buff[2]  = er32(RCTL);
426         regs_buff[3]  = er32(RDLEN);
427         regs_buff[4]  = er32(RDH);
428         regs_buff[5]  = er32(RDT);
429         regs_buff[6]  = er32(RDTR);
430
431         regs_buff[7]  = er32(TCTL);
432         regs_buff[8]  = er32(TDLEN);
433         regs_buff[9]  = er32(TDH);
434         regs_buff[10] = er32(TDT);
435         regs_buff[11] = er32(TIDV);
436
437         regs_buff[12] = adapter->hw.phy.type;  /* PHY type (IGP=1, M88=0) */
438         if (hw->phy.type == e1000_phy_m88) {
439                 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
440                 regs_buff[13] = (u32)phy_data; /* cable length */
441                 regs_buff[14] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
442                 regs_buff[15] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
443                 regs_buff[16] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
444                 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
445                 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
446                 regs_buff[18] = regs_buff[13]; /* cable polarity */
447                 regs_buff[19] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
448                 regs_buff[20] = regs_buff[17]; /* polarity correction */
449                 /* phy receive errors */
450                 regs_buff[22] = adapter->phy_stats.receive_errors;
451                 regs_buff[23] = regs_buff[13]; /* mdix mode */
452         }
453         regs_buff[21] = adapter->phy_stats.idle_errors;  /* phy idle errors */
454         e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
455         regs_buff[24] = (u32)phy_data;  /* phy local receiver status */
456         regs_buff[25] = regs_buff[24];  /* phy remote receiver status */
457 }
458
459 static int e1000_get_eeprom_len(struct net_device *netdev)
460 {
461         struct e1000_adapter *adapter = netdev_priv(netdev);
462         return adapter->hw.nvm.word_size * 2;
463 }
464
465 static int e1000_get_eeprom(struct net_device *netdev,
466                             struct ethtool_eeprom *eeprom, u8 *bytes)
467 {
468         struct e1000_adapter *adapter = netdev_priv(netdev);
469         struct e1000_hw *hw = &adapter->hw;
470         u16 *eeprom_buff;
471         int first_word;
472         int last_word;
473         int ret_val = 0;
474         u16 i;
475
476         if (eeprom->len == 0)
477                 return -EINVAL;
478
479         eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
480
481         first_word = eeprom->offset >> 1;
482         last_word = (eeprom->offset + eeprom->len - 1) >> 1;
483
484         eeprom_buff = kmalloc(sizeof(u16) *
485                         (last_word - first_word + 1), GFP_KERNEL);
486         if (!eeprom_buff)
487                 return -ENOMEM;
488
489         if (hw->nvm.type == e1000_nvm_eeprom_spi) {
490                 ret_val = e1000_read_nvm(hw, first_word,
491                                          last_word - first_word + 1,
492                                          eeprom_buff);
493         } else {
494                 for (i = 0; i < last_word - first_word + 1; i++) {
495                         ret_val = e1000_read_nvm(hw, first_word + i, 1,
496                                                       &eeprom_buff[i]);
497                         if (ret_val)
498                                 break;
499                 }
500         }
501
502         /* Device's eeprom is always little-endian, word addressable */
503         for (i = 0; i < last_word - first_word + 1; i++)
504                 le16_to_cpus(&eeprom_buff[i]);
505
506         memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
507         kfree(eeprom_buff);
508
509         return ret_val;
510 }
511
512 static int e1000_set_eeprom(struct net_device *netdev,
513                             struct ethtool_eeprom *eeprom, u8 *bytes)
514 {
515         struct e1000_adapter *adapter = netdev_priv(netdev);
516         struct e1000_hw *hw = &adapter->hw;
517         u16 *eeprom_buff;
518         void *ptr;
519         int max_len;
520         int first_word;
521         int last_word;
522         int ret_val = 0;
523         u16 i;
524
525         if (eeprom->len == 0)
526                 return -EOPNOTSUPP;
527
528         if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
529                 return -EFAULT;
530
531         max_len = hw->nvm.word_size * 2;
532
533         first_word = eeprom->offset >> 1;
534         last_word = (eeprom->offset + eeprom->len - 1) >> 1;
535         eeprom_buff = kmalloc(max_len, GFP_KERNEL);
536         if (!eeprom_buff)
537                 return -ENOMEM;
538
539         ptr = (void *)eeprom_buff;
540
541         if (eeprom->offset & 1) {
542                 /* need read/modify/write of first changed EEPROM word */
543                 /* only the second byte of the word is being modified */
544                 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
545                 ptr++;
546         }
547         if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0))
548                 /* need read/modify/write of last changed EEPROM word */
549                 /* only the first byte of the word is being modified */
550                 ret_val = e1000_read_nvm(hw, last_word, 1,
551                                   &eeprom_buff[last_word - first_word]);
552
553         /* Device's eeprom is always little-endian, word addressable */
554         for (i = 0; i < last_word - first_word + 1; i++)
555                 le16_to_cpus(&eeprom_buff[i]);
556
557         memcpy(ptr, bytes, eeprom->len);
558
559         for (i = 0; i < last_word - first_word + 1; i++)
560                 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
561
562         ret_val = e1000_write_nvm(hw, first_word,
563                                   last_word - first_word + 1, eeprom_buff);
564
565         /*
566          * Update the checksum over the first part of the EEPROM if needed
567          * and flush shadow RAM for 82573 controllers
568          */
569         if ((ret_val == 0) && ((first_word <= NVM_CHECKSUM_REG) ||
570                                (hw->mac.type == e1000_82573)))
571                 e1000e_update_nvm_checksum(hw);
572
573         kfree(eeprom_buff);
574         return ret_val;
575 }
576
577 static void e1000_get_drvinfo(struct net_device *netdev,
578                               struct ethtool_drvinfo *drvinfo)
579 {
580         struct e1000_adapter *adapter = netdev_priv(netdev);
581         char firmware_version[32];
582         u16 eeprom_data;
583
584         strncpy(drvinfo->driver,  e1000e_driver_name, 32);
585         strncpy(drvinfo->version, e1000e_driver_version, 32);
586
587         /*
588          * EEPROM image version # is reported as firmware version # for
589          * PCI-E controllers
590          */
591         e1000_read_nvm(&adapter->hw, 5, 1, &eeprom_data);
592         sprintf(firmware_version, "%d.%d-%d",
593                 (eeprom_data & 0xF000) >> 12,
594                 (eeprom_data & 0x0FF0) >> 4,
595                 eeprom_data & 0x000F);
596
597         strncpy(drvinfo->fw_version, firmware_version, 32);
598         strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
599         drvinfo->regdump_len = e1000_get_regs_len(netdev);
600         drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
601 }
602
603 static void e1000_get_ringparam(struct net_device *netdev,
604                                 struct ethtool_ringparam *ring)
605 {
606         struct e1000_adapter *adapter = netdev_priv(netdev);
607         struct e1000_ring *tx_ring = adapter->tx_ring;
608         struct e1000_ring *rx_ring = adapter->rx_ring;
609
610         ring->rx_max_pending = E1000_MAX_RXD;
611         ring->tx_max_pending = E1000_MAX_TXD;
612         ring->rx_mini_max_pending = 0;
613         ring->rx_jumbo_max_pending = 0;
614         ring->rx_pending = rx_ring->count;
615         ring->tx_pending = tx_ring->count;
616         ring->rx_mini_pending = 0;
617         ring->rx_jumbo_pending = 0;
618 }
619
620 static int e1000_set_ringparam(struct net_device *netdev,
621                                struct ethtool_ringparam *ring)
622 {
623         struct e1000_adapter *adapter = netdev_priv(netdev);
624         struct e1000_ring *tx_ring, *tx_old;
625         struct e1000_ring *rx_ring, *rx_old;
626         int err;
627
628         if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
629                 return -EINVAL;
630
631         while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
632                 msleep(1);
633
634         if (netif_running(adapter->netdev))
635                 e1000e_down(adapter);
636
637         tx_old = adapter->tx_ring;
638         rx_old = adapter->rx_ring;
639
640         err = -ENOMEM;
641         tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
642         if (!tx_ring)
643                 goto err_alloc_tx;
644
645         rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
646         if (!rx_ring)
647                 goto err_alloc_rx;
648
649         adapter->tx_ring = tx_ring;
650         adapter->rx_ring = rx_ring;
651
652         rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
653         rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD));
654         rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
655
656         tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
657         tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
658         tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
659
660         if (netif_running(adapter->netdev)) {
661                 /* Try to get new resources before deleting old */
662                 err = e1000e_setup_rx_resources(adapter);
663                 if (err)
664                         goto err_setup_rx;
665                 err = e1000e_setup_tx_resources(adapter);
666                 if (err)
667                         goto err_setup_tx;
668
669                 /*
670                  * restore the old in order to free it,
671                  * then add in the new
672                  */
673                 adapter->rx_ring = rx_old;
674                 adapter->tx_ring = tx_old;
675                 e1000e_free_rx_resources(adapter);
676                 e1000e_free_tx_resources(adapter);
677                 kfree(tx_old);
678                 kfree(rx_old);
679                 adapter->rx_ring = rx_ring;
680                 adapter->tx_ring = tx_ring;
681                 err = e1000e_up(adapter);
682                 if (err)
683                         goto err_setup;
684         }
685
686         clear_bit(__E1000_RESETTING, &adapter->state);
687         return 0;
688 err_setup_tx:
689         e1000e_free_rx_resources(adapter);
690 err_setup_rx:
691         adapter->rx_ring = rx_old;
692         adapter->tx_ring = tx_old;
693         kfree(rx_ring);
694 err_alloc_rx:
695         kfree(tx_ring);
696 err_alloc_tx:
697         e1000e_up(adapter);
698 err_setup:
699         clear_bit(__E1000_RESETTING, &adapter->state);
700         return err;
701 }
702
703 static bool reg_pattern_test_array(struct e1000_adapter *adapter, u64 *data,
704                                    int reg, int offset, u32 mask, u32 write)
705 {
706         int i;
707         u32 read;
708         static const u32 test[] =
709                 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
710         for (i = 0; i < ARRAY_SIZE(test); i++) {
711                 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
712                                       (test[i] & write));
713                 read = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
714                 if (read != (test[i] & write & mask)) {
715                         ndev_err(adapter->netdev, "pattern test reg %04X "
716                                  "failed: got 0x%08X expected 0x%08X\n",
717                                  reg + offset,
718                                  read, (test[i] & write & mask));
719                         *data = reg;
720                         return true;
721                 }
722         }
723         return false;
724 }
725
726 static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
727                               int reg, u32 mask, u32 write)
728 {
729         u32 read;
730         __ew32(&adapter->hw, reg, write & mask);
731         read = __er32(&adapter->hw, reg);
732         if ((write & mask) != (read & mask)) {
733                 ndev_err(adapter->netdev, "set/check reg %04X test failed: "
734                          "got 0x%08X expected 0x%08X\n", reg, (read & mask),
735                          (write & mask));
736                 *data = reg;
737                 return true;
738         }
739         return false;
740 }
741
742 #define REG_PATTERN_TEST(R, M, W) \
743         do { \
744                 if (reg_pattern_test_array(adapter, data, R, 0, M, W)) \
745                         return 1; \
746         } while (0)
747
748 #define REG_PATTERN_TEST_ARRAY(R, offset, M, W) \
749         do { \
750                 if (reg_pattern_test_array(adapter, data, R, offset, M, W)) \
751                         return 1; \
752         } while (0)
753
754 #define REG_SET_AND_CHECK(R, M, W) \
755         do { \
756                 if (reg_set_and_check(adapter, data, R, M, W)) \
757                         return 1; \
758         } while (0)
759
760 static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
761 {
762         struct e1000_hw *hw = &adapter->hw;
763         struct e1000_mac_info *mac = &adapter->hw.mac;
764         struct net_device *netdev = adapter->netdev;
765         u32 value;
766         u32 before;
767         u32 after;
768         u32 i;
769         u32 toggle;
770
771         /*
772          * The status register is Read Only, so a write should fail.
773          * Some bits that get toggled are ignored.
774          */
775         switch (mac->type) {
776         /* there are several bits on newer hardware that are r/w */
777         case e1000_82571:
778         case e1000_82572:
779         case e1000_80003es2lan:
780                 toggle = 0x7FFFF3FF;
781                 break;
782         case e1000_82573:
783         case e1000_ich8lan:
784         case e1000_ich9lan:
785                 toggle = 0x7FFFF033;
786                 break;
787         default:
788                 toggle = 0xFFFFF833;
789                 break;
790         }
791
792         before = er32(STATUS);
793         value = (er32(STATUS) & toggle);
794         ew32(STATUS, toggle);
795         after = er32(STATUS) & toggle;
796         if (value != after) {
797                 ndev_err(netdev, "failed STATUS register test got: "
798                          "0x%08X expected: 0x%08X\n", after, value);
799                 *data = 1;
800                 return 1;
801         }
802         /* restore previous status */
803         ew32(STATUS, before);
804
805         if ((mac->type != e1000_ich8lan) &&
806             (mac->type != e1000_ich9lan)) {
807                 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
808                 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
809                 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
810                 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
811         }
812
813         REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
814         REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
815         REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF);
816         REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF);
817         REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF);
818         REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
819         REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
820         REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
821         REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
822         REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF);
823
824         REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
825
826         before = (((mac->type == e1000_ich8lan) ||
827                    (mac->type == e1000_ich9lan)) ? 0x06C3B33E : 0x06DFB3FE);
828         REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
829         REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
830
831         REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
832         REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
833         if ((mac->type != e1000_ich8lan) &&
834             (mac->type != e1000_ich9lan))
835                 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
836         REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
837         REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
838         for (i = 0; i < mac->rar_entry_count; i++)
839                 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
840                                        0x8003FFFF, 0xFFFFFFFF);
841
842         for (i = 0; i < mac->mta_reg_count; i++)
843                 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
844
845         *data = 0;
846         return 0;
847 }
848
849 static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
850 {
851         u16 temp;
852         u16 checksum = 0;
853         u16 i;
854
855         *data = 0;
856         /* Read and add up the contents of the EEPROM */
857         for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
858                 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
859                         *data = 1;
860                         break;
861                 }
862                 checksum += temp;
863         }
864
865         /* If Checksum is not Correct return error else test passed */
866         if ((checksum != (u16) NVM_SUM) && !(*data))
867                 *data = 2;
868
869         return *data;
870 }
871
872 static irqreturn_t e1000_test_intr(int irq, void *data)
873 {
874         struct net_device *netdev = (struct net_device *) data;
875         struct e1000_adapter *adapter = netdev_priv(netdev);
876         struct e1000_hw *hw = &adapter->hw;
877
878         adapter->test_icr |= er32(ICR);
879
880         return IRQ_HANDLED;
881 }
882
883 static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
884 {
885         struct net_device *netdev = adapter->netdev;
886         struct e1000_hw *hw = &adapter->hw;
887         u32 mask;
888         u32 shared_int = 1;
889         u32 irq = adapter->pdev->irq;
890         int i;
891
892         *data = 0;
893
894         /* NOTE: we don't test MSI interrupts here, yet */
895         /* Hook up test interrupt handler just for this test */
896         if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
897                          netdev)) {
898                 shared_int = 0;
899         } else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED,
900                  netdev->name, netdev)) {
901                 *data = 1;
902                 return -1;
903         }
904         ndev_info(netdev, "testing %s interrupt\n",
905                   (shared_int ? "shared" : "unshared"));
906
907         /* Disable all the interrupts */
908         ew32(IMC, 0xFFFFFFFF);
909         msleep(10);
910
911         /* Test each interrupt */
912         for (i = 0; i < 10; i++) {
913
914                 if (((adapter->hw.mac.type == e1000_ich8lan) ||
915                      (adapter->hw.mac.type == e1000_ich9lan)) && i == 8)
916                         continue;
917
918                 /* Interrupt to test */
919                 mask = 1 << i;
920
921                 if (!shared_int) {
922                         /*
923                          * Disable the interrupt to be reported in
924                          * the cause register and then force the same
925                          * interrupt and see if one gets posted.  If
926                          * an interrupt was posted to the bus, the
927                          * test failed.
928                          */
929                         adapter->test_icr = 0;
930                         ew32(IMC, mask);
931                         ew32(ICS, mask);
932                         msleep(10);
933
934                         if (adapter->test_icr & mask) {
935                                 *data = 3;
936                                 break;
937                         }
938                 }
939
940                 /*
941                  * Enable the interrupt to be reported in
942                  * the cause register and then force the same
943                  * interrupt and see if one gets posted.  If
944                  * an interrupt was not posted to the bus, the
945                  * test failed.
946                  */
947                 adapter->test_icr = 0;
948                 ew32(IMS, mask);
949                 ew32(ICS, mask);
950                 msleep(10);
951
952                 if (!(adapter->test_icr & mask)) {
953                         *data = 4;
954                         break;
955                 }
956
957                 if (!shared_int) {
958                         /*
959                          * Disable the other interrupts to be reported in
960                          * the cause register and then force the other
961                          * interrupts and see if any get posted.  If
962                          * an interrupt was posted to the bus, the
963                          * test failed.
964                          */
965                         adapter->test_icr = 0;
966                         ew32(IMC, ~mask & 0x00007FFF);
967                         ew32(ICS, ~mask & 0x00007FFF);
968                         msleep(10);
969
970                         if (adapter->test_icr) {
971                                 *data = 5;
972                                 break;
973                         }
974                 }
975         }
976
977         /* Disable all the interrupts */
978         ew32(IMC, 0xFFFFFFFF);
979         msleep(10);
980
981         /* Unhook test interrupt handler */
982         free_irq(irq, netdev);
983
984         return *data;
985 }
986
987 static void e1000_free_desc_rings(struct e1000_adapter *adapter)
988 {
989         struct e1000_ring *tx_ring = &adapter->test_tx_ring;
990         struct e1000_ring *rx_ring = &adapter->test_rx_ring;
991         struct pci_dev *pdev = adapter->pdev;
992         int i;
993
994         if (tx_ring->desc && tx_ring->buffer_info) {
995                 for (i = 0; i < tx_ring->count; i++) {
996                         if (tx_ring->buffer_info[i].dma)
997                                 pci_unmap_single(pdev,
998                                         tx_ring->buffer_info[i].dma,
999                                         tx_ring->buffer_info[i].length,
1000                                         PCI_DMA_TODEVICE);
1001                         if (tx_ring->buffer_info[i].skb)
1002                                 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1003                 }
1004         }
1005
1006         if (rx_ring->desc && rx_ring->buffer_info) {
1007                 for (i = 0; i < rx_ring->count; i++) {
1008                         if (rx_ring->buffer_info[i].dma)
1009                                 pci_unmap_single(pdev,
1010                                         rx_ring->buffer_info[i].dma,
1011                                         2048, PCI_DMA_FROMDEVICE);
1012                         if (rx_ring->buffer_info[i].skb)
1013                                 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1014                 }
1015         }
1016
1017         if (tx_ring->desc) {
1018                 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1019                                   tx_ring->dma);
1020                 tx_ring->desc = NULL;
1021         }
1022         if (rx_ring->desc) {
1023                 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1024                                   rx_ring->dma);
1025                 rx_ring->desc = NULL;
1026         }
1027
1028         kfree(tx_ring->buffer_info);
1029         tx_ring->buffer_info = NULL;
1030         kfree(rx_ring->buffer_info);
1031         rx_ring->buffer_info = NULL;
1032 }
1033
1034 static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1035 {
1036         struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1037         struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1038         struct pci_dev *pdev = adapter->pdev;
1039         struct e1000_hw *hw = &adapter->hw;
1040         u32 rctl;
1041         int size;
1042         int i;
1043         int ret_val;
1044
1045         /* Setup Tx descriptor ring and Tx buffers */
1046
1047         if (!tx_ring->count)
1048                 tx_ring->count = E1000_DEFAULT_TXD;
1049
1050         size = tx_ring->count * sizeof(struct e1000_buffer);
1051         tx_ring->buffer_info = kmalloc(size, GFP_KERNEL);
1052         if (!tx_ring->buffer_info) {
1053                 ret_val = 1;
1054                 goto err_nomem;
1055         }
1056         memset(tx_ring->buffer_info, 0, size);
1057
1058         tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1059         tx_ring->size = ALIGN(tx_ring->size, 4096);
1060         tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1061                                            &tx_ring->dma, GFP_KERNEL);
1062         if (!tx_ring->desc) {
1063                 ret_val = 2;
1064                 goto err_nomem;
1065         }
1066         memset(tx_ring->desc, 0, tx_ring->size);
1067         tx_ring->next_to_use = 0;
1068         tx_ring->next_to_clean = 0;
1069
1070         ew32(TDBAL,
1071                         ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
1072         ew32(TDBAH, ((u64) tx_ring->dma >> 32));
1073         ew32(TDLEN,
1074                         tx_ring->count * sizeof(struct e1000_tx_desc));
1075         ew32(TDH, 0);
1076         ew32(TDT, 0);
1077         ew32(TCTL,
1078                         E1000_TCTL_PSP | E1000_TCTL_EN |
1079                         E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1080                         E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
1081
1082         for (i = 0; i < tx_ring->count; i++) {
1083                 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1084                 struct sk_buff *skb;
1085                 unsigned int skb_size = 1024;
1086
1087                 skb = alloc_skb(skb_size, GFP_KERNEL);
1088                 if (!skb) {
1089                         ret_val = 3;
1090                         goto err_nomem;
1091                 }
1092                 skb_put(skb, skb_size);
1093                 tx_ring->buffer_info[i].skb = skb;
1094                 tx_ring->buffer_info[i].length = skb->len;
1095                 tx_ring->buffer_info[i].dma =
1096                         pci_map_single(pdev, skb->data, skb->len,
1097                                        PCI_DMA_TODEVICE);
1098                 if (pci_dma_mapping_error(tx_ring->buffer_info[i].dma)) {
1099                         ret_val = 4;
1100                         goto err_nomem;
1101                 }
1102                 tx_desc->buffer_addr = cpu_to_le64(
1103                                          tx_ring->buffer_info[i].dma);
1104                 tx_desc->lower.data = cpu_to_le32(skb->len);
1105                 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1106                                                    E1000_TXD_CMD_IFCS |
1107                                                    E1000_TXD_CMD_RPS);
1108                 tx_desc->upper.data = 0;
1109         }
1110
1111         /* Setup Rx descriptor ring and Rx buffers */
1112
1113         if (!rx_ring->count)
1114                 rx_ring->count = E1000_DEFAULT_RXD;
1115
1116         size = rx_ring->count * sizeof(struct e1000_buffer);
1117         rx_ring->buffer_info = kmalloc(size, GFP_KERNEL);
1118         if (!rx_ring->buffer_info) {
1119                 ret_val = 5;
1120                 goto err_nomem;
1121         }
1122         memset(rx_ring->buffer_info, 0, size);
1123
1124         rx_ring->size = rx_ring->count * sizeof(struct e1000_rx_desc);
1125         rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1126                                            &rx_ring->dma, GFP_KERNEL);
1127         if (!rx_ring->desc) {
1128                 ret_val = 6;
1129                 goto err_nomem;
1130         }
1131         memset(rx_ring->desc, 0, rx_ring->size);
1132         rx_ring->next_to_use = 0;
1133         rx_ring->next_to_clean = 0;
1134
1135         rctl = er32(RCTL);
1136         ew32(RCTL, rctl & ~E1000_RCTL_EN);
1137         ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
1138         ew32(RDBAH, ((u64) rx_ring->dma >> 32));
1139         ew32(RDLEN, rx_ring->size);
1140         ew32(RDH, 0);
1141         ew32(RDT, 0);
1142         rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
1143                 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1144                 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1145         ew32(RCTL, rctl);
1146
1147         for (i = 0; i < rx_ring->count; i++) {
1148                 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
1149                 struct sk_buff *skb;
1150
1151                 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1152                 if (!skb) {
1153                         ret_val = 7;
1154                         goto err_nomem;
1155                 }
1156                 skb_reserve(skb, NET_IP_ALIGN);
1157                 rx_ring->buffer_info[i].skb = skb;
1158                 rx_ring->buffer_info[i].dma =
1159                         pci_map_single(pdev, skb->data, 2048,
1160                                        PCI_DMA_FROMDEVICE);
1161                 if (pci_dma_mapping_error(rx_ring->buffer_info[i].dma)) {
1162                         ret_val = 8;
1163                         goto err_nomem;
1164                 }
1165                 rx_desc->buffer_addr =
1166                         cpu_to_le64(rx_ring->buffer_info[i].dma);
1167                 memset(skb->data, 0x00, skb->len);
1168         }
1169
1170         return 0;
1171
1172 err_nomem:
1173         e1000_free_desc_rings(adapter);
1174         return ret_val;
1175 }
1176
1177 static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1178 {
1179         /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1180         e1e_wphy(&adapter->hw, 29, 0x001F);
1181         e1e_wphy(&adapter->hw, 30, 0x8FFC);
1182         e1e_wphy(&adapter->hw, 29, 0x001A);
1183         e1e_wphy(&adapter->hw, 30, 0x8FF0);
1184 }
1185
1186 static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1187 {
1188         struct e1000_hw *hw = &adapter->hw;
1189         u32 ctrl_reg = 0;
1190         u32 stat_reg = 0;
1191
1192         hw->mac.autoneg = 0;
1193
1194         if (hw->phy.type == e1000_phy_m88) {
1195                 /* Auto-MDI/MDIX Off */
1196                 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1197                 /* reset to update Auto-MDI/MDIX */
1198                 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1199                 /* autoneg off */
1200                 e1e_wphy(hw, PHY_CONTROL, 0x8140);
1201         } else if (hw->phy.type == e1000_phy_gg82563)
1202                 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
1203
1204         ctrl_reg = er32(CTRL);
1205
1206         if (hw->phy.type == e1000_phy_ife) {
1207                 /* force 100, set loopback */
1208                 e1e_wphy(hw, PHY_CONTROL, 0x6100);
1209
1210                 /* Now set up the MAC to the same speed/duplex as the PHY. */
1211                 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1212                 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1213                              E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1214                              E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1215                              E1000_CTRL_FD);     /* Force Duplex to FULL */
1216         } else {
1217                 /* force 1000, set loopback */
1218                 e1e_wphy(hw, PHY_CONTROL, 0x4140);
1219
1220                 /* Now set up the MAC to the same speed/duplex as the PHY. */
1221                 ctrl_reg = er32(CTRL);
1222                 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1223                 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1224                              E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1225                              E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1226                              E1000_CTRL_FD);     /* Force Duplex to FULL */
1227         }
1228
1229         if (hw->phy.media_type == e1000_media_type_copper &&
1230             hw->phy.type == e1000_phy_m88) {
1231                 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1232         } else {
1233                 /*
1234                  * Set the ILOS bit on the fiber Nic if half duplex link is
1235                  * detected.
1236                  */
1237                 stat_reg = er32(STATUS);
1238                 if ((stat_reg & E1000_STATUS_FD) == 0)
1239                         ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1240         }
1241
1242         ew32(CTRL, ctrl_reg);
1243
1244         /*
1245          * Disable the receiver on the PHY so when a cable is plugged in, the
1246          * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1247          */
1248         if (hw->phy.type == e1000_phy_m88)
1249                 e1000_phy_disable_receiver(adapter);
1250
1251         udelay(500);
1252
1253         return 0;
1254 }
1255
1256 static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1257 {
1258         struct e1000_hw *hw = &adapter->hw;
1259         u32 ctrl = er32(CTRL);
1260         int link = 0;
1261
1262         /* special requirements for 82571/82572 fiber adapters */
1263
1264         /*
1265          * jump through hoops to make sure link is up because serdes
1266          * link is hardwired up
1267          */
1268         ctrl |= E1000_CTRL_SLU;
1269         ew32(CTRL, ctrl);
1270
1271         /* disable autoneg */
1272         ctrl = er32(TXCW);
1273         ctrl &= ~(1 << 31);
1274         ew32(TXCW, ctrl);
1275
1276         link = (er32(STATUS) & E1000_STATUS_LU);
1277
1278         if (!link) {
1279                 /* set invert loss of signal */
1280                 ctrl = er32(CTRL);
1281                 ctrl |= E1000_CTRL_ILOS;
1282                 ew32(CTRL, ctrl);
1283         }
1284
1285         /*
1286          * special write to serdes control register to enable SerDes analog
1287          * loopback
1288          */
1289 #define E1000_SERDES_LB_ON 0x410
1290         ew32(SCTL, E1000_SERDES_LB_ON);
1291         msleep(10);
1292
1293         return 0;
1294 }
1295
1296 /* only call this for fiber/serdes connections to es2lan */
1297 static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1298 {
1299         struct e1000_hw *hw = &adapter->hw;
1300         u32 ctrlext = er32(CTRL_EXT);
1301         u32 ctrl = er32(CTRL);
1302
1303         /*
1304          * save CTRL_EXT to restore later, reuse an empty variable (unused
1305          * on mac_type 80003es2lan)
1306          */
1307         adapter->tx_fifo_head = ctrlext;
1308
1309         /* clear the serdes mode bits, putting the device into mac loopback */
1310         ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1311         ew32(CTRL_EXT, ctrlext);
1312
1313         /* force speed to 1000/FD, link up */
1314         ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1315         ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1316                  E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1317         ew32(CTRL, ctrl);
1318
1319         /* set mac loopback */
1320         ctrl = er32(RCTL);
1321         ctrl |= E1000_RCTL_LBM_MAC;
1322         ew32(RCTL, ctrl);
1323
1324         /* set testing mode parameters (no need to reset later) */
1325 #define KMRNCTRLSTA_OPMODE (0x1F << 16)
1326 #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1327         ew32(KMRNCTRLSTA,
1328                 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
1329
1330         return 0;
1331 }
1332
1333 static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1334 {
1335         struct e1000_hw *hw = &adapter->hw;
1336         u32 rctl;
1337
1338         if (hw->phy.media_type == e1000_media_type_fiber ||
1339             hw->phy.media_type == e1000_media_type_internal_serdes) {
1340                 switch (hw->mac.type) {
1341                 case e1000_80003es2lan:
1342                         return e1000_set_es2lan_mac_loopback(adapter);
1343                         break;
1344                 case e1000_82571:
1345                 case e1000_82572:
1346                         return e1000_set_82571_fiber_loopback(adapter);
1347                         break;
1348                 default:
1349                         rctl = er32(RCTL);
1350                         rctl |= E1000_RCTL_LBM_TCVR;
1351                         ew32(RCTL, rctl);
1352                         return 0;
1353                 }
1354         } else if (hw->phy.media_type == e1000_media_type_copper) {
1355                 return e1000_integrated_phy_loopback(adapter);
1356         }
1357
1358         return 7;
1359 }
1360
1361 static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1362 {
1363         struct e1000_hw *hw = &adapter->hw;
1364         u32 rctl;
1365         u16 phy_reg;
1366
1367         rctl = er32(RCTL);
1368         rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1369         ew32(RCTL, rctl);
1370
1371         switch (hw->mac.type) {
1372         case e1000_80003es2lan:
1373                 if (hw->phy.media_type == e1000_media_type_fiber ||
1374                     hw->phy.media_type == e1000_media_type_internal_serdes) {
1375                         /* restore CTRL_EXT, stealing space from tx_fifo_head */
1376                         ew32(CTRL_EXT, adapter->tx_fifo_head);
1377                         adapter->tx_fifo_head = 0;
1378                 }
1379                 /* fall through */
1380         case e1000_82571:
1381         case e1000_82572:
1382                 if (hw->phy.media_type == e1000_media_type_fiber ||
1383                     hw->phy.media_type == e1000_media_type_internal_serdes) {
1384 #define E1000_SERDES_LB_OFF 0x400
1385                         ew32(SCTL, E1000_SERDES_LB_OFF);
1386                         msleep(10);
1387                         break;
1388                 }
1389                 /* Fall Through */
1390         default:
1391                 hw->mac.autoneg = 1;
1392                 if (hw->phy.type == e1000_phy_gg82563)
1393                         e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1394                 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1395                 if (phy_reg & MII_CR_LOOPBACK) {
1396                         phy_reg &= ~MII_CR_LOOPBACK;
1397                         e1e_wphy(hw, PHY_CONTROL, phy_reg);
1398                         e1000e_commit_phy(hw);
1399                 }
1400                 break;
1401         }
1402 }
1403
1404 static void e1000_create_lbtest_frame(struct sk_buff *skb,
1405                                       unsigned int frame_size)
1406 {
1407         memset(skb->data, 0xFF, frame_size);
1408         frame_size &= ~1;
1409         memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1410         memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1411         memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1412 }
1413
1414 static int e1000_check_lbtest_frame(struct sk_buff *skb,
1415                                     unsigned int frame_size)
1416 {
1417         frame_size &= ~1;
1418         if (*(skb->data + 3) == 0xFF)
1419                 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1420                    (*(skb->data + frame_size / 2 + 12) == 0xAF))
1421                         return 0;
1422         return 13;
1423 }
1424
1425 static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1426 {
1427         struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1428         struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1429         struct pci_dev *pdev = adapter->pdev;
1430         struct e1000_hw *hw = &adapter->hw;
1431         int i, j, k, l;
1432         int lc;
1433         int good_cnt;
1434         int ret_val = 0;
1435         unsigned long time;
1436
1437         ew32(RDT, rx_ring->count - 1);
1438
1439         /*
1440          * Calculate the loop count based on the largest descriptor ring
1441          * The idea is to wrap the largest ring a number of times using 64
1442          * send/receive pairs during each loop
1443          */
1444
1445         if (rx_ring->count <= tx_ring->count)
1446                 lc = ((tx_ring->count / 64) * 2) + 1;
1447         else
1448                 lc = ((rx_ring->count / 64) * 2) + 1;
1449
1450         k = 0;
1451         l = 0;
1452         for (j = 0; j <= lc; j++) { /* loop count loop */
1453                 for (i = 0; i < 64; i++) { /* send the packets */
1454                         e1000_create_lbtest_frame(
1455                                 tx_ring->buffer_info[i].skb, 1024);
1456                         pci_dma_sync_single_for_device(pdev,
1457                                         tx_ring->buffer_info[k].dma,
1458                                         tx_ring->buffer_info[k].length,
1459                                         PCI_DMA_TODEVICE);
1460                         k++;
1461                         if (k == tx_ring->count)
1462                                 k = 0;
1463                 }
1464                 ew32(TDT, k);
1465                 msleep(200);
1466                 time = jiffies; /* set the start time for the receive */
1467                 good_cnt = 0;
1468                 do { /* receive the sent packets */
1469                         pci_dma_sync_single_for_cpu(pdev,
1470                                         rx_ring->buffer_info[l].dma, 2048,
1471                                         PCI_DMA_FROMDEVICE);
1472
1473                         ret_val = e1000_check_lbtest_frame(
1474                                         rx_ring->buffer_info[l].skb, 1024);
1475                         if (!ret_val)
1476                                 good_cnt++;
1477                         l++;
1478                         if (l == rx_ring->count)
1479                                 l = 0;
1480                         /*
1481                          * time + 20 msecs (200 msecs on 2.4) is more than
1482                          * enough time to complete the receives, if it's
1483                          * exceeded, break and error off
1484                          */
1485                 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1486                 if (good_cnt != 64) {
1487                         ret_val = 13; /* ret_val is the same as mis-compare */
1488                         break;
1489                 }
1490                 if (jiffies >= (time + 2)) {
1491                         ret_val = 14; /* error code for time out error */
1492                         break;
1493                 }
1494         } /* end loop count loop */
1495         return ret_val;
1496 }
1497
1498 static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1499 {
1500         /*
1501          * PHY loopback cannot be performed if SoL/IDER
1502          * sessions are active
1503          */
1504         if (e1000_check_reset_block(&adapter->hw)) {
1505                 ndev_err(adapter->netdev, "Cannot do PHY loopback test "
1506                          "when SoL/IDER is active.\n");
1507                 *data = 0;
1508                 goto out;
1509         }
1510
1511         *data = e1000_setup_desc_rings(adapter);
1512         if (*data)
1513                 goto out;
1514
1515         *data = e1000_setup_loopback_test(adapter);
1516         if (*data)
1517                 goto err_loopback;
1518
1519         *data = e1000_run_loopback_test(adapter);
1520         e1000_loopback_cleanup(adapter);
1521
1522 err_loopback:
1523         e1000_free_desc_rings(adapter);
1524 out:
1525         return *data;
1526 }
1527
1528 static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1529 {
1530         struct e1000_hw *hw = &adapter->hw;
1531
1532         *data = 0;
1533         if (hw->phy.media_type == e1000_media_type_internal_serdes) {
1534                 int i = 0;
1535                 hw->mac.serdes_has_link = 0;
1536
1537                 /*
1538                  * On some blade server designs, link establishment
1539                  * could take as long as 2-3 minutes
1540                  */
1541                 do {
1542                         hw->mac.ops.check_for_link(hw);
1543                         if (hw->mac.serdes_has_link)
1544                                 return *data;
1545                         msleep(20);
1546                 } while (i++ < 3750);
1547
1548                 *data = 1;
1549         } else {
1550                 hw->mac.ops.check_for_link(hw);
1551                 if (hw->mac.autoneg)
1552                         msleep(4000);
1553
1554                 if (!(er32(STATUS) &
1555                       E1000_STATUS_LU))
1556                         *data = 1;
1557         }
1558         return *data;
1559 }
1560
1561 static int e1000e_get_sset_count(struct net_device *netdev, int sset)
1562 {
1563         switch (sset) {
1564         case ETH_SS_TEST:
1565                 return E1000_TEST_LEN;
1566         case ETH_SS_STATS:
1567                 return E1000_STATS_LEN;
1568         default:
1569                 return -EOPNOTSUPP;
1570         }
1571 }
1572
1573 static void e1000_diag_test(struct net_device *netdev,
1574                             struct ethtool_test *eth_test, u64 *data)
1575 {
1576         struct e1000_adapter *adapter = netdev_priv(netdev);
1577         u16 autoneg_advertised;
1578         u8 forced_speed_duplex;
1579         u8 autoneg;
1580         bool if_running = netif_running(netdev);
1581
1582         set_bit(__E1000_TESTING, &adapter->state);
1583         if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1584                 /* Offline tests */
1585
1586                 /* save speed, duplex, autoneg settings */
1587                 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1588                 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1589                 autoneg = adapter->hw.mac.autoneg;
1590
1591                 ndev_info(netdev, "offline testing starting\n");
1592
1593                 /*
1594                  * Link test performed before hardware reset so autoneg doesn't
1595                  * interfere with test result
1596                  */
1597                 if (e1000_link_test(adapter, &data[4]))
1598                         eth_test->flags |= ETH_TEST_FL_FAILED;
1599
1600                 if (if_running)
1601                         /* indicate we're in test mode */
1602                         dev_close(netdev);
1603                 else
1604                         e1000e_reset(adapter);
1605
1606                 if (e1000_reg_test(adapter, &data[0]))
1607                         eth_test->flags |= ETH_TEST_FL_FAILED;
1608
1609                 e1000e_reset(adapter);
1610                 if (e1000_eeprom_test(adapter, &data[1]))
1611                         eth_test->flags |= ETH_TEST_FL_FAILED;
1612
1613                 e1000e_reset(adapter);
1614                 if (e1000_intr_test(adapter, &data[2]))
1615                         eth_test->flags |= ETH_TEST_FL_FAILED;
1616
1617                 e1000e_reset(adapter);
1618                 /* make sure the phy is powered up */
1619                 e1000e_power_up_phy(adapter);
1620                 if (e1000_loopback_test(adapter, &data[3]))
1621                         eth_test->flags |= ETH_TEST_FL_FAILED;
1622
1623                 /* restore speed, duplex, autoneg settings */
1624                 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1625                 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1626                 adapter->hw.mac.autoneg = autoneg;
1627
1628                 /* force this routine to wait until autoneg complete/timeout */
1629                 adapter->hw.phy.autoneg_wait_to_complete = 1;
1630                 e1000e_reset(adapter);
1631                 adapter->hw.phy.autoneg_wait_to_complete = 0;
1632
1633                 clear_bit(__E1000_TESTING, &adapter->state);
1634                 if (if_running)
1635                         dev_open(netdev);
1636         } else {
1637                 ndev_info(netdev, "online testing starting\n");
1638                 /* Online tests */
1639                 if (e1000_link_test(adapter, &data[4]))
1640                         eth_test->flags |= ETH_TEST_FL_FAILED;
1641
1642                 /* Online tests aren't run; pass by default */
1643                 data[0] = 0;
1644                 data[1] = 0;
1645                 data[2] = 0;
1646                 data[3] = 0;
1647
1648                 clear_bit(__E1000_TESTING, &adapter->state);
1649         }
1650         msleep_interruptible(4 * 1000);
1651 }
1652
1653 static void e1000_get_wol(struct net_device *netdev,
1654                           struct ethtool_wolinfo *wol)
1655 {
1656         struct e1000_adapter *adapter = netdev_priv(netdev);
1657
1658         wol->supported = 0;
1659         wol->wolopts = 0;
1660
1661         if (!(adapter->flags & FLAG_HAS_WOL))
1662                 return;
1663
1664         wol->supported = WAKE_UCAST | WAKE_MCAST |
1665                          WAKE_BCAST | WAKE_MAGIC |
1666                          WAKE_PHY | WAKE_ARP;
1667
1668         /* apply any specific unsupported masks here */
1669         if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1670                 wol->supported &= ~WAKE_UCAST;
1671
1672                 if (adapter->wol & E1000_WUFC_EX)
1673                         ndev_err(netdev, "Interface does not support "
1674                                  "directed (unicast) frame wake-up packets\n");
1675         }
1676
1677         if (adapter->wol & E1000_WUFC_EX)
1678                 wol->wolopts |= WAKE_UCAST;
1679         if (adapter->wol & E1000_WUFC_MC)
1680                 wol->wolopts |= WAKE_MCAST;
1681         if (adapter->wol & E1000_WUFC_BC)
1682                 wol->wolopts |= WAKE_BCAST;
1683         if (adapter->wol & E1000_WUFC_MAG)
1684                 wol->wolopts |= WAKE_MAGIC;
1685         if (adapter->wol & E1000_WUFC_LNKC)
1686                 wol->wolopts |= WAKE_PHY;
1687         if (adapter->wol & E1000_WUFC_ARP)
1688                 wol->wolopts |= WAKE_ARP;
1689 }
1690
1691 static int e1000_set_wol(struct net_device *netdev,
1692                          struct ethtool_wolinfo *wol)
1693 {
1694         struct e1000_adapter *adapter = netdev_priv(netdev);
1695
1696         if (wol->wolopts & WAKE_MAGICSECURE)
1697                 return -EOPNOTSUPP;
1698
1699         if (!(adapter->flags & FLAG_HAS_WOL))
1700                 return wol->wolopts ? -EOPNOTSUPP : 0;
1701
1702         /* these settings will always override what we currently have */
1703         adapter->wol = 0;
1704
1705         if (wol->wolopts & WAKE_UCAST)
1706                 adapter->wol |= E1000_WUFC_EX;
1707         if (wol->wolopts & WAKE_MCAST)
1708                 adapter->wol |= E1000_WUFC_MC;
1709         if (wol->wolopts & WAKE_BCAST)
1710                 adapter->wol |= E1000_WUFC_BC;
1711         if (wol->wolopts & WAKE_MAGIC)
1712                 adapter->wol |= E1000_WUFC_MAG;
1713         if (wol->wolopts & WAKE_PHY)
1714                 adapter->wol |= E1000_WUFC_LNKC;
1715         if (wol->wolopts & WAKE_ARP)
1716                 adapter->wol |= E1000_WUFC_ARP;
1717
1718         return 0;
1719 }
1720
1721 /* toggle LED 4 times per second = 2 "blinks" per second */
1722 #define E1000_ID_INTERVAL       (HZ/4)
1723
1724 /* bit defines for adapter->led_status */
1725 #define E1000_LED_ON            0
1726
1727 static void e1000_led_blink_callback(unsigned long data)
1728 {
1729         struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1730
1731         if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
1732                 adapter->hw.mac.ops.led_off(&adapter->hw);
1733         else
1734                 adapter->hw.mac.ops.led_on(&adapter->hw);
1735
1736         mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1737 }
1738
1739 static int e1000_phys_id(struct net_device *netdev, u32 data)
1740 {
1741         struct e1000_adapter *adapter = netdev_priv(netdev);
1742
1743         if (!data)
1744                 data = INT_MAX;
1745
1746         if (adapter->hw.phy.type == e1000_phy_ife) {
1747                 if (!adapter->blink_timer.function) {
1748                         init_timer(&adapter->blink_timer);
1749                         adapter->blink_timer.function =
1750                                 e1000_led_blink_callback;
1751                         adapter->blink_timer.data = (unsigned long) adapter;
1752                 }
1753                 mod_timer(&adapter->blink_timer, jiffies);
1754                 msleep_interruptible(data * 1000);
1755                 del_timer_sync(&adapter->blink_timer);
1756                 e1e_wphy(&adapter->hw,
1757                                     IFE_PHY_SPECIAL_CONTROL_LED, 0);
1758         } else {
1759                 e1000e_blink_led(&adapter->hw);
1760                 msleep_interruptible(data * 1000);
1761         }
1762
1763         adapter->hw.mac.ops.led_off(&adapter->hw);
1764         clear_bit(E1000_LED_ON, &adapter->led_status);
1765         adapter->hw.mac.ops.cleanup_led(&adapter->hw);
1766
1767         return 0;
1768 }
1769
1770 static int e1000_nway_reset(struct net_device *netdev)
1771 {
1772         struct e1000_adapter *adapter = netdev_priv(netdev);
1773         if (netif_running(netdev))
1774                 e1000e_reinit_locked(adapter);
1775         return 0;
1776 }
1777
1778 static void e1000_get_ethtool_stats(struct net_device *netdev,
1779                                     struct ethtool_stats *stats,
1780                                     u64 *data)
1781 {
1782         struct e1000_adapter *adapter = netdev_priv(netdev);
1783         int i;
1784
1785         e1000e_update_stats(adapter);
1786         for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1787                 char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
1788                 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1789                         sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1790         }
1791 }
1792
1793 static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1794                               u8 *data)
1795 {
1796         u8 *p = data;
1797         int i;
1798
1799         switch (stringset) {
1800         case ETH_SS_TEST:
1801                 memcpy(data, *e1000_gstrings_test, sizeof(e1000_gstrings_test));
1802                 break;
1803         case ETH_SS_STATS:
1804                 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1805                         memcpy(p, e1000_gstrings_stats[i].stat_string,
1806                                ETH_GSTRING_LEN);
1807                         p += ETH_GSTRING_LEN;
1808                 }
1809                 break;
1810         }
1811 }
1812
1813 static const struct ethtool_ops e1000_ethtool_ops = {
1814         .get_settings           = e1000_get_settings,
1815         .set_settings           = e1000_set_settings,
1816         .get_drvinfo            = e1000_get_drvinfo,
1817         .get_regs_len           = e1000_get_regs_len,
1818         .get_regs               = e1000_get_regs,
1819         .get_wol                = e1000_get_wol,
1820         .set_wol                = e1000_set_wol,
1821         .get_msglevel           = e1000_get_msglevel,
1822         .set_msglevel           = e1000_set_msglevel,
1823         .nway_reset             = e1000_nway_reset,
1824         .get_link               = e1000_get_link,
1825         .get_eeprom_len         = e1000_get_eeprom_len,
1826         .get_eeprom             = e1000_get_eeprom,
1827         .set_eeprom             = e1000_set_eeprom,
1828         .get_ringparam          = e1000_get_ringparam,
1829         .set_ringparam          = e1000_set_ringparam,
1830         .get_pauseparam         = e1000_get_pauseparam,
1831         .set_pauseparam         = e1000_set_pauseparam,
1832         .get_rx_csum            = e1000_get_rx_csum,
1833         .set_rx_csum            = e1000_set_rx_csum,
1834         .get_tx_csum            = e1000_get_tx_csum,
1835         .set_tx_csum            = e1000_set_tx_csum,
1836         .get_sg                 = ethtool_op_get_sg,
1837         .set_sg                 = ethtool_op_set_sg,
1838         .get_tso                = ethtool_op_get_tso,
1839         .set_tso                = e1000_set_tso,
1840         .self_test              = e1000_diag_test,
1841         .get_strings            = e1000_get_strings,
1842         .phys_id                = e1000_phys_id,
1843         .get_ethtool_stats      = e1000_get_ethtool_stats,
1844         .get_sset_count         = e1000e_get_sset_count,
1845 };
1846
1847 void e1000e_set_ethtool_ops(struct net_device *netdev)
1848 {
1849         SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
1850 }