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