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