]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/net/ethernet/intel/e1000e/ethtool.c
e70b1ebff60df2d0a20a876c04613938b89432cc
[karo-tx-linux.git] / drivers / net / ethernet / intel / e1000e / ethtool.c
1 /* Intel PRO/1000 Linux driver
2  * Copyright(c) 1999 - 2015 Intel Corporation.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms and conditions of the GNU General Public License,
6  * version 2, as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11  * more details.
12  *
13  * The full GNU General Public License is included in this distribution in
14  * the file called "COPYING".
15  *
16  * Contact Information:
17  * Linux NICS <linux.nics@intel.com>
18  * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
19  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
20  */
21
22 /* ethtool support for e1000 */
23
24 #include <linux/netdevice.h>
25 #include <linux/interrupt.h>
26 #include <linux/ethtool.h>
27 #include <linux/pci.h>
28 #include <linux/slab.h>
29 #include <linux/delay.h>
30 #include <linux/vmalloc.h>
31 #include <linux/pm_runtime.h>
32
33 #include "e1000.h"
34
35 enum { NETDEV_STATS, E1000_STATS };
36
37 struct e1000_stats {
38         char stat_string[ETH_GSTRING_LEN];
39         int type;
40         int sizeof_stat;
41         int stat_offset;
42 };
43
44 #define E1000_STAT(str, m) { \
45                 .stat_string = str, \
46                 .type = E1000_STATS, \
47                 .sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
48                 .stat_offset = offsetof(struct e1000_adapter, m) }
49 #define E1000_NETDEV_STAT(str, m) { \
50                 .stat_string = str, \
51                 .type = NETDEV_STATS, \
52                 .sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \
53                 .stat_offset = offsetof(struct rtnl_link_stats64, m) }
54
55 static const struct e1000_stats e1000_gstrings_stats[] = {
56         E1000_STAT("rx_packets", stats.gprc),
57         E1000_STAT("tx_packets", stats.gptc),
58         E1000_STAT("rx_bytes", stats.gorc),
59         E1000_STAT("tx_bytes", stats.gotc),
60         E1000_STAT("rx_broadcast", stats.bprc),
61         E1000_STAT("tx_broadcast", stats.bptc),
62         E1000_STAT("rx_multicast", stats.mprc),
63         E1000_STAT("tx_multicast", stats.mptc),
64         E1000_NETDEV_STAT("rx_errors", rx_errors),
65         E1000_NETDEV_STAT("tx_errors", tx_errors),
66         E1000_NETDEV_STAT("tx_dropped", tx_dropped),
67         E1000_STAT("multicast", stats.mprc),
68         E1000_STAT("collisions", stats.colc),
69         E1000_NETDEV_STAT("rx_length_errors", rx_length_errors),
70         E1000_NETDEV_STAT("rx_over_errors", rx_over_errors),
71         E1000_STAT("rx_crc_errors", stats.crcerrs),
72         E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
73         E1000_STAT("rx_no_buffer_count", stats.rnbc),
74         E1000_STAT("rx_missed_errors", stats.mpc),
75         E1000_STAT("tx_aborted_errors", stats.ecol),
76         E1000_STAT("tx_carrier_errors", stats.tncrs),
77         E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
78         E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
79         E1000_STAT("tx_window_errors", stats.latecol),
80         E1000_STAT("tx_abort_late_coll", stats.latecol),
81         E1000_STAT("tx_deferred_ok", stats.dc),
82         E1000_STAT("tx_single_coll_ok", stats.scc),
83         E1000_STAT("tx_multi_coll_ok", stats.mcc),
84         E1000_STAT("tx_timeout_count", tx_timeout_count),
85         E1000_STAT("tx_restart_queue", restart_queue),
86         E1000_STAT("rx_long_length_errors", stats.roc),
87         E1000_STAT("rx_short_length_errors", stats.ruc),
88         E1000_STAT("rx_align_errors", stats.algnerrc),
89         E1000_STAT("tx_tcp_seg_good", stats.tsctc),
90         E1000_STAT("tx_tcp_seg_failed", stats.tsctfc),
91         E1000_STAT("rx_flow_control_xon", stats.xonrxc),
92         E1000_STAT("rx_flow_control_xoff", stats.xoffrxc),
93         E1000_STAT("tx_flow_control_xon", stats.xontxc),
94         E1000_STAT("tx_flow_control_xoff", stats.xofftxc),
95         E1000_STAT("rx_csum_offload_good", hw_csum_good),
96         E1000_STAT("rx_csum_offload_errors", hw_csum_err),
97         E1000_STAT("rx_header_split", rx_hdr_split),
98         E1000_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),
99         E1000_STAT("tx_smbus", stats.mgptc),
100         E1000_STAT("rx_smbus", stats.mgprc),
101         E1000_STAT("dropped_smbus", stats.mgpdc),
102         E1000_STAT("rx_dma_failed", rx_dma_failed),
103         E1000_STAT("tx_dma_failed", tx_dma_failed),
104         E1000_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
105         E1000_STAT("uncorr_ecc_errors", uncorr_errors),
106         E1000_STAT("corr_ecc_errors", corr_errors),
107         E1000_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
108 };
109
110 #define E1000_GLOBAL_STATS_LEN  ARRAY_SIZE(e1000_gstrings_stats)
111 #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
112 static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
113         "Register test  (offline)", "Eeprom test    (offline)",
114         "Interrupt test (offline)", "Loopback test  (offline)",
115         "Link test   (on/offline)"
116 };
117
118 #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
119
120 static int e1000_get_link_ksettings(struct net_device *netdev,
121                                     struct ethtool_link_ksettings *cmd)
122 {
123         struct e1000_adapter *adapter = netdev_priv(netdev);
124         struct e1000_hw *hw = &adapter->hw;
125         u32 speed, supported, advertising;
126
127         if (hw->phy.media_type == e1000_media_type_copper) {
128                 supported = (SUPPORTED_10baseT_Half |
129                              SUPPORTED_10baseT_Full |
130                              SUPPORTED_100baseT_Half |
131                              SUPPORTED_100baseT_Full |
132                              SUPPORTED_1000baseT_Full |
133                              SUPPORTED_Autoneg |
134                              SUPPORTED_TP);
135                 if (hw->phy.type == e1000_phy_ife)
136                         supported &= ~SUPPORTED_1000baseT_Full;
137                 advertising = ADVERTISED_TP;
138
139                 if (hw->mac.autoneg == 1) {
140                         advertising |= ADVERTISED_Autoneg;
141                         /* the e1000 autoneg seems to match ethtool nicely */
142                         advertising |= hw->phy.autoneg_advertised;
143                 }
144
145                 cmd->base.port = PORT_TP;
146                 cmd->base.phy_address = hw->phy.addr;
147         } else {
148                 supported   = (SUPPORTED_1000baseT_Full |
149                                SUPPORTED_FIBRE |
150                                SUPPORTED_Autoneg);
151
152                 advertising = (ADVERTISED_1000baseT_Full |
153                                ADVERTISED_FIBRE |
154                                ADVERTISED_Autoneg);
155
156                 cmd->base.port = PORT_FIBRE;
157         }
158
159         speed = SPEED_UNKNOWN;
160         cmd->base.duplex = DUPLEX_UNKNOWN;
161
162         if (netif_running(netdev)) {
163                 if (netif_carrier_ok(netdev)) {
164                         speed = adapter->link_speed;
165                         cmd->base.duplex = adapter->link_duplex - 1;
166                 }
167         } else if (!pm_runtime_suspended(netdev->dev.parent)) {
168                 u32 status = er32(STATUS);
169
170                 if (status & E1000_STATUS_LU) {
171                         if (status & E1000_STATUS_SPEED_1000)
172                                 speed = SPEED_1000;
173                         else if (status & E1000_STATUS_SPEED_100)
174                                 speed = SPEED_100;
175                         else
176                                 speed = SPEED_10;
177
178                         if (status & E1000_STATUS_FD)
179                                 cmd->base.duplex = DUPLEX_FULL;
180                         else
181                                 cmd->base.duplex = DUPLEX_HALF;
182                 }
183         }
184
185         cmd->base.speed = speed;
186         cmd->base.autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
187                          hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
188
189         /* MDI-X => 2; MDI =>1; Invalid =>0 */
190         if ((hw->phy.media_type == e1000_media_type_copper) &&
191             netif_carrier_ok(netdev))
192                 cmd->base.eth_tp_mdix = hw->phy.is_mdix ?
193                         ETH_TP_MDI_X : ETH_TP_MDI;
194         else
195                 cmd->base.eth_tp_mdix = ETH_TP_MDI_INVALID;
196
197         if (hw->phy.mdix == AUTO_ALL_MODES)
198                 cmd->base.eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
199         else
200                 cmd->base.eth_tp_mdix_ctrl = hw->phy.mdix;
201
202         if (hw->phy.media_type != e1000_media_type_copper)
203                 cmd->base.eth_tp_mdix_ctrl = ETH_TP_MDI_INVALID;
204
205         ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
206                                                 supported);
207         ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
208                                                 advertising);
209
210         return 0;
211 }
212
213 static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u32 spd, u8 dplx)
214 {
215         struct e1000_mac_info *mac = &adapter->hw.mac;
216
217         mac->autoneg = 0;
218
219         /* Make sure dplx is at most 1 bit and lsb of speed is not set
220          * for the switch() below to work
221          */
222         if ((spd & 1) || (dplx & ~1))
223                 goto err_inval;
224
225         /* Fiber NICs only allow 1000 gbps Full duplex */
226         if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
227             (spd != SPEED_1000) && (dplx != DUPLEX_FULL)) {
228                 goto err_inval;
229         }
230
231         switch (spd + dplx) {
232         case SPEED_10 + DUPLEX_HALF:
233                 mac->forced_speed_duplex = ADVERTISE_10_HALF;
234                 break;
235         case SPEED_10 + DUPLEX_FULL:
236                 mac->forced_speed_duplex = ADVERTISE_10_FULL;
237                 break;
238         case SPEED_100 + DUPLEX_HALF:
239                 mac->forced_speed_duplex = ADVERTISE_100_HALF;
240                 break;
241         case SPEED_100 + DUPLEX_FULL:
242                 mac->forced_speed_duplex = ADVERTISE_100_FULL;
243                 break;
244         case SPEED_1000 + DUPLEX_FULL:
245                 if (adapter->hw.phy.media_type == e1000_media_type_copper) {
246                         mac->autoneg = 1;
247                         adapter->hw.phy.autoneg_advertised =
248                                 ADVERTISE_1000_FULL;
249                 } else {
250                         mac->forced_speed_duplex = ADVERTISE_1000_FULL;
251                 }
252                 break;
253         case SPEED_1000 + DUPLEX_HALF:  /* not supported */
254         default:
255                 goto err_inval;
256         }
257
258         /* clear MDI, MDI(-X) override is only allowed when autoneg enabled */
259         adapter->hw.phy.mdix = AUTO_ALL_MODES;
260
261         return 0;
262
263 err_inval:
264         e_err("Unsupported Speed/Duplex configuration\n");
265         return -EINVAL;
266 }
267
268 static int e1000_set_link_ksettings(struct net_device *netdev,
269                                     const struct ethtool_link_ksettings *cmd)
270 {
271         struct e1000_adapter *adapter = netdev_priv(netdev);
272         struct e1000_hw *hw = &adapter->hw;
273         int ret_val = 0;
274         u32 advertising;
275
276         ethtool_convert_link_mode_to_legacy_u32(&advertising,
277                                                 cmd->link_modes.advertising);
278
279         pm_runtime_get_sync(netdev->dev.parent);
280
281         /* When SoL/IDER sessions are active, autoneg/speed/duplex
282          * cannot be changed
283          */
284         if (hw->phy.ops.check_reset_block &&
285             hw->phy.ops.check_reset_block(hw)) {
286                 e_err("Cannot change link characteristics when SoL/IDER is active.\n");
287                 ret_val = -EINVAL;
288                 goto out;
289         }
290
291         /* MDI setting is only allowed when autoneg enabled because
292          * some hardware doesn't allow MDI setting when speed or
293          * duplex is forced.
294          */
295         if (cmd->base.eth_tp_mdix_ctrl) {
296                 if (hw->phy.media_type != e1000_media_type_copper) {
297                         ret_val = -EOPNOTSUPP;
298                         goto out;
299                 }
300
301                 if ((cmd->base.eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) &&
302                     (cmd->base.autoneg != AUTONEG_ENABLE)) {
303                         e_err("forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n");
304                         ret_val = -EINVAL;
305                         goto out;
306                 }
307         }
308
309         while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
310                 usleep_range(1000, 2000);
311
312         if (cmd->base.autoneg == AUTONEG_ENABLE) {
313                 hw->mac.autoneg = 1;
314                 if (hw->phy.media_type == e1000_media_type_fiber)
315                         hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
316                             ADVERTISED_FIBRE | ADVERTISED_Autoneg;
317                 else
318                         hw->phy.autoneg_advertised = advertising |
319                             ADVERTISED_TP | ADVERTISED_Autoneg;
320                 advertising = hw->phy.autoneg_advertised;
321                 if (adapter->fc_autoneg)
322                         hw->fc.requested_mode = e1000_fc_default;
323         } else {
324                 u32 speed = cmd->base.speed;
325                 /* calling this overrides forced MDI setting */
326                 if (e1000_set_spd_dplx(adapter, speed, cmd->base.duplex)) {
327                         ret_val = -EINVAL;
328                         goto out;
329                 }
330         }
331
332         /* MDI-X => 2; MDI => 1; Auto => 3 */
333         if (cmd->base.eth_tp_mdix_ctrl) {
334                 /* fix up the value for auto (3 => 0) as zero is mapped
335                  * internally to auto
336                  */
337                 if (cmd->base.eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO)
338                         hw->phy.mdix = AUTO_ALL_MODES;
339                 else
340                         hw->phy.mdix = cmd->base.eth_tp_mdix_ctrl;
341         }
342
343         /* reset the link */
344         if (netif_running(adapter->netdev)) {
345                 e1000e_down(adapter, true);
346                 e1000e_up(adapter);
347         } else {
348                 e1000e_reset(adapter);
349         }
350
351 out:
352         pm_runtime_put_sync(netdev->dev.parent);
353         clear_bit(__E1000_RESETTING, &adapter->state);
354         return ret_val;
355 }
356
357 static void e1000_get_pauseparam(struct net_device *netdev,
358                                  struct ethtool_pauseparam *pause)
359 {
360         struct e1000_adapter *adapter = netdev_priv(netdev);
361         struct e1000_hw *hw = &adapter->hw;
362
363         pause->autoneg =
364             (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
365
366         if (hw->fc.current_mode == e1000_fc_rx_pause) {
367                 pause->rx_pause = 1;
368         } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
369                 pause->tx_pause = 1;
370         } else if (hw->fc.current_mode == e1000_fc_full) {
371                 pause->rx_pause = 1;
372                 pause->tx_pause = 1;
373         }
374 }
375
376 static int e1000_set_pauseparam(struct net_device *netdev,
377                                 struct ethtool_pauseparam *pause)
378 {
379         struct e1000_adapter *adapter = netdev_priv(netdev);
380         struct e1000_hw *hw = &adapter->hw;
381         int retval = 0;
382
383         adapter->fc_autoneg = pause->autoneg;
384
385         while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
386                 usleep_range(1000, 2000);
387
388         pm_runtime_get_sync(netdev->dev.parent);
389
390         if (adapter->fc_autoneg == AUTONEG_ENABLE) {
391                 hw->fc.requested_mode = e1000_fc_default;
392                 if (netif_running(adapter->netdev)) {
393                         e1000e_down(adapter, true);
394                         e1000e_up(adapter);
395                 } else {
396                         e1000e_reset(adapter);
397                 }
398         } else {
399                 if (pause->rx_pause && pause->tx_pause)
400                         hw->fc.requested_mode = e1000_fc_full;
401                 else if (pause->rx_pause && !pause->tx_pause)
402                         hw->fc.requested_mode = e1000_fc_rx_pause;
403                 else if (!pause->rx_pause && pause->tx_pause)
404                         hw->fc.requested_mode = e1000_fc_tx_pause;
405                 else if (!pause->rx_pause && !pause->tx_pause)
406                         hw->fc.requested_mode = e1000_fc_none;
407
408                 hw->fc.current_mode = hw->fc.requested_mode;
409
410                 if (hw->phy.media_type == e1000_media_type_fiber) {
411                         retval = hw->mac.ops.setup_link(hw);
412                         /* implicit goto out */
413                 } else {
414                         retval = e1000e_force_mac_fc(hw);
415                         if (retval)
416                                 goto out;
417                         e1000e_set_fc_watermarks(hw);
418                 }
419         }
420
421 out:
422         pm_runtime_put_sync(netdev->dev.parent);
423         clear_bit(__E1000_RESETTING, &adapter->state);
424         return retval;
425 }
426
427 static u32 e1000_get_msglevel(struct net_device *netdev)
428 {
429         struct e1000_adapter *adapter = netdev_priv(netdev);
430         return adapter->msg_enable;
431 }
432
433 static void e1000_set_msglevel(struct net_device *netdev, u32 data)
434 {
435         struct e1000_adapter *adapter = netdev_priv(netdev);
436         adapter->msg_enable = data;
437 }
438
439 static int e1000_get_regs_len(struct net_device __always_unused *netdev)
440 {
441 #define E1000_REGS_LEN 32       /* overestimate */
442         return E1000_REGS_LEN * sizeof(u32);
443 }
444
445 static void e1000_get_regs(struct net_device *netdev,
446                            struct ethtool_regs *regs, void *p)
447 {
448         struct e1000_adapter *adapter = netdev_priv(netdev);
449         struct e1000_hw *hw = &adapter->hw;
450         u32 *regs_buff = p;
451         u16 phy_data;
452
453         pm_runtime_get_sync(netdev->dev.parent);
454
455         memset(p, 0, E1000_REGS_LEN * sizeof(u32));
456
457         regs->version = (1u << 24) |
458                         (adapter->pdev->revision << 16) |
459                         adapter->pdev->device;
460
461         regs_buff[0] = er32(CTRL);
462         regs_buff[1] = er32(STATUS);
463
464         regs_buff[2] = er32(RCTL);
465         regs_buff[3] = er32(RDLEN(0));
466         regs_buff[4] = er32(RDH(0));
467         regs_buff[5] = er32(RDT(0));
468         regs_buff[6] = er32(RDTR);
469
470         regs_buff[7] = er32(TCTL);
471         regs_buff[8] = er32(TDLEN(0));
472         regs_buff[9] = er32(TDH(0));
473         regs_buff[10] = er32(TDT(0));
474         regs_buff[11] = er32(TIDV);
475
476         regs_buff[12] = adapter->hw.phy.type;   /* PHY type (IGP=1, M88=0) */
477
478         /* ethtool doesn't use anything past this point, so all this
479          * code is likely legacy junk for apps that may or may not exist
480          */
481         if (hw->phy.type == e1000_phy_m88) {
482                 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
483                 regs_buff[13] = (u32)phy_data; /* cable length */
484                 regs_buff[14] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
485                 regs_buff[15] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
486                 regs_buff[16] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
487                 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
488                 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
489                 regs_buff[18] = regs_buff[13]; /* cable polarity */
490                 regs_buff[19] = 0;  /* Dummy (to align w/ IGP phy reg dump) */
491                 regs_buff[20] = regs_buff[17]; /* polarity correction */
492                 /* phy receive errors */
493                 regs_buff[22] = adapter->phy_stats.receive_errors;
494                 regs_buff[23] = regs_buff[13]; /* mdix mode */
495         }
496         regs_buff[21] = 0;      /* was idle_errors */
497         e1e_rphy(hw, MII_STAT1000, &phy_data);
498         regs_buff[24] = (u32)phy_data;  /* phy local receiver status */
499         regs_buff[25] = regs_buff[24];  /* phy remote receiver status */
500
501         pm_runtime_put_sync(netdev->dev.parent);
502 }
503
504 static int e1000_get_eeprom_len(struct net_device *netdev)
505 {
506         struct e1000_adapter *adapter = netdev_priv(netdev);
507         return adapter->hw.nvm.word_size * 2;
508 }
509
510 static int e1000_get_eeprom(struct net_device *netdev,
511                             struct ethtool_eeprom *eeprom, u8 *bytes)
512 {
513         struct e1000_adapter *adapter = netdev_priv(netdev);
514         struct e1000_hw *hw = &adapter->hw;
515         u16 *eeprom_buff;
516         int first_word;
517         int last_word;
518         int ret_val = 0;
519         u16 i;
520
521         if (eeprom->len == 0)
522                 return -EINVAL;
523
524         eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
525
526         first_word = eeprom->offset >> 1;
527         last_word = (eeprom->offset + eeprom->len - 1) >> 1;
528
529         eeprom_buff = kmalloc(sizeof(u16) * (last_word - first_word + 1),
530                               GFP_KERNEL);
531         if (!eeprom_buff)
532                 return -ENOMEM;
533
534         pm_runtime_get_sync(netdev->dev.parent);
535
536         if (hw->nvm.type == e1000_nvm_eeprom_spi) {
537                 ret_val = e1000_read_nvm(hw, first_word,
538                                          last_word - first_word + 1,
539                                          eeprom_buff);
540         } else {
541                 for (i = 0; i < last_word - first_word + 1; i++) {
542                         ret_val = e1000_read_nvm(hw, first_word + i, 1,
543                                                  &eeprom_buff[i]);
544                         if (ret_val)
545                                 break;
546                 }
547         }
548
549         pm_runtime_put_sync(netdev->dev.parent);
550
551         if (ret_val) {
552                 /* a read error occurred, throw away the result */
553                 memset(eeprom_buff, 0xff, sizeof(u16) *
554                        (last_word - first_word + 1));
555         } else {
556                 /* Device's eeprom is always little-endian, word addressable */
557                 for (i = 0; i < last_word - first_word + 1; i++)
558                         le16_to_cpus(&eeprom_buff[i]);
559         }
560
561         memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
562         kfree(eeprom_buff);
563
564         return ret_val;
565 }
566
567 static int e1000_set_eeprom(struct net_device *netdev,
568                             struct ethtool_eeprom *eeprom, u8 *bytes)
569 {
570         struct e1000_adapter *adapter = netdev_priv(netdev);
571         struct e1000_hw *hw = &adapter->hw;
572         u16 *eeprom_buff;
573         void *ptr;
574         int max_len;
575         int first_word;
576         int last_word;
577         int ret_val = 0;
578         u16 i;
579
580         if (eeprom->len == 0)
581                 return -EOPNOTSUPP;
582
583         if (eeprom->magic !=
584             (adapter->pdev->vendor | (adapter->pdev->device << 16)))
585                 return -EFAULT;
586
587         if (adapter->flags & FLAG_READ_ONLY_NVM)
588                 return -EINVAL;
589
590         max_len = hw->nvm.word_size * 2;
591
592         first_word = eeprom->offset >> 1;
593         last_word = (eeprom->offset + eeprom->len - 1) >> 1;
594         eeprom_buff = kmalloc(max_len, GFP_KERNEL);
595         if (!eeprom_buff)
596                 return -ENOMEM;
597
598         ptr = (void *)eeprom_buff;
599
600         pm_runtime_get_sync(netdev->dev.parent);
601
602         if (eeprom->offset & 1) {
603                 /* need read/modify/write of first changed EEPROM word */
604                 /* only the second byte of the word is being modified */
605                 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
606                 ptr++;
607         }
608         if (((eeprom->offset + eeprom->len) & 1) && (!ret_val))
609                 /* need read/modify/write of last changed EEPROM word */
610                 /* only the first byte of the word is being modified */
611                 ret_val = e1000_read_nvm(hw, last_word, 1,
612                                          &eeprom_buff[last_word - first_word]);
613
614         if (ret_val)
615                 goto out;
616
617         /* Device's eeprom is always little-endian, word addressable */
618         for (i = 0; i < last_word - first_word + 1; i++)
619                 le16_to_cpus(&eeprom_buff[i]);
620
621         memcpy(ptr, bytes, eeprom->len);
622
623         for (i = 0; i < last_word - first_word + 1; i++)
624                 cpu_to_le16s(&eeprom_buff[i]);
625
626         ret_val = e1000_write_nvm(hw, first_word,
627                                   last_word - first_word + 1, eeprom_buff);
628
629         if (ret_val)
630                 goto out;
631
632         /* Update the checksum over the first part of the EEPROM if needed
633          * and flush shadow RAM for applicable controllers
634          */
635         if ((first_word <= NVM_CHECKSUM_REG) ||
636             (hw->mac.type == e1000_82583) ||
637             (hw->mac.type == e1000_82574) ||
638             (hw->mac.type == e1000_82573))
639                 ret_val = e1000e_update_nvm_checksum(hw);
640
641 out:
642         pm_runtime_put_sync(netdev->dev.parent);
643         kfree(eeprom_buff);
644         return ret_val;
645 }
646
647 static void e1000_get_drvinfo(struct net_device *netdev,
648                               struct ethtool_drvinfo *drvinfo)
649 {
650         struct e1000_adapter *adapter = netdev_priv(netdev);
651
652         strlcpy(drvinfo->driver, e1000e_driver_name, sizeof(drvinfo->driver));
653         strlcpy(drvinfo->version, e1000e_driver_version,
654                 sizeof(drvinfo->version));
655
656         /* EEPROM image version # is reported as firmware version # for
657          * PCI-E controllers
658          */
659         snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
660                  "%d.%d-%d",
661                  (adapter->eeprom_vers & 0xF000) >> 12,
662                  (adapter->eeprom_vers & 0x0FF0) >> 4,
663                  (adapter->eeprom_vers & 0x000F));
664
665         strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
666                 sizeof(drvinfo->bus_info));
667 }
668
669 static void e1000_get_ringparam(struct net_device *netdev,
670                                 struct ethtool_ringparam *ring)
671 {
672         struct e1000_adapter *adapter = netdev_priv(netdev);
673
674         ring->rx_max_pending = E1000_MAX_RXD;
675         ring->tx_max_pending = E1000_MAX_TXD;
676         ring->rx_pending = adapter->rx_ring_count;
677         ring->tx_pending = adapter->tx_ring_count;
678 }
679
680 static int e1000_set_ringparam(struct net_device *netdev,
681                                struct ethtool_ringparam *ring)
682 {
683         struct e1000_adapter *adapter = netdev_priv(netdev);
684         struct e1000_ring *temp_tx = NULL, *temp_rx = NULL;
685         int err = 0, size = sizeof(struct e1000_ring);
686         bool set_tx = false, set_rx = false;
687         u16 new_rx_count, new_tx_count;
688
689         if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
690                 return -EINVAL;
691
692         new_rx_count = clamp_t(u32, ring->rx_pending, E1000_MIN_RXD,
693                                E1000_MAX_RXD);
694         new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
695
696         new_tx_count = clamp_t(u32, ring->tx_pending, E1000_MIN_TXD,
697                                E1000_MAX_TXD);
698         new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
699
700         if ((new_tx_count == adapter->tx_ring_count) &&
701             (new_rx_count == adapter->rx_ring_count))
702                 /* nothing to do */
703                 return 0;
704
705         while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
706                 usleep_range(1000, 2000);
707
708         if (!netif_running(adapter->netdev)) {
709                 /* Set counts now and allocate resources during open() */
710                 adapter->tx_ring->count = new_tx_count;
711                 adapter->rx_ring->count = new_rx_count;
712                 adapter->tx_ring_count = new_tx_count;
713                 adapter->rx_ring_count = new_rx_count;
714                 goto clear_reset;
715         }
716
717         set_tx = (new_tx_count != adapter->tx_ring_count);
718         set_rx = (new_rx_count != adapter->rx_ring_count);
719
720         /* Allocate temporary storage for ring updates */
721         if (set_tx) {
722                 temp_tx = vmalloc(size);
723                 if (!temp_tx) {
724                         err = -ENOMEM;
725                         goto free_temp;
726                 }
727         }
728         if (set_rx) {
729                 temp_rx = vmalloc(size);
730                 if (!temp_rx) {
731                         err = -ENOMEM;
732                         goto free_temp;
733                 }
734         }
735
736         pm_runtime_get_sync(netdev->dev.parent);
737
738         e1000e_down(adapter, true);
739
740         /* We can't just free everything and then setup again, because the
741          * ISRs in MSI-X mode get passed pointers to the Tx and Rx ring
742          * structs.  First, attempt to allocate new resources...
743          */
744         if (set_tx) {
745                 memcpy(temp_tx, adapter->tx_ring, size);
746                 temp_tx->count = new_tx_count;
747                 err = e1000e_setup_tx_resources(temp_tx);
748                 if (err)
749                         goto err_setup;
750         }
751         if (set_rx) {
752                 memcpy(temp_rx, adapter->rx_ring, size);
753                 temp_rx->count = new_rx_count;
754                 err = e1000e_setup_rx_resources(temp_rx);
755                 if (err)
756                         goto err_setup_rx;
757         }
758
759         /* ...then free the old resources and copy back any new ring data */
760         if (set_tx) {
761                 e1000e_free_tx_resources(adapter->tx_ring);
762                 memcpy(adapter->tx_ring, temp_tx, size);
763                 adapter->tx_ring_count = new_tx_count;
764         }
765         if (set_rx) {
766                 e1000e_free_rx_resources(adapter->rx_ring);
767                 memcpy(adapter->rx_ring, temp_rx, size);
768                 adapter->rx_ring_count = new_rx_count;
769         }
770
771 err_setup_rx:
772         if (err && set_tx)
773                 e1000e_free_tx_resources(temp_tx);
774 err_setup:
775         e1000e_up(adapter);
776         pm_runtime_put_sync(netdev->dev.parent);
777 free_temp:
778         vfree(temp_tx);
779         vfree(temp_rx);
780 clear_reset:
781         clear_bit(__E1000_RESETTING, &adapter->state);
782         return err;
783 }
784
785 static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
786                              int reg, int offset, u32 mask, u32 write)
787 {
788         u32 pat, val;
789         static const u32 test[] = {
790                 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF
791         };
792         for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
793                 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
794                                       (test[pat] & write));
795                 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
796                 if (val != (test[pat] & write & mask)) {
797                         e_err("pattern test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
798                               reg + (offset << 2), val,
799                               (test[pat] & write & mask));
800                         *data = reg;
801                         return true;
802                 }
803         }
804         return false;
805 }
806
807 static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
808                               int reg, u32 mask, u32 write)
809 {
810         u32 val;
811
812         __ew32(&adapter->hw, reg, write & mask);
813         val = __er32(&adapter->hw, reg);
814         if ((write & mask) != (val & mask)) {
815                 e_err("set/check test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n",
816                       reg, (val & mask), (write & mask));
817                 *data = reg;
818                 return true;
819         }
820         return false;
821 }
822
823 #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write)                       \
824         do {                                                                   \
825                 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
826                         return 1;                                              \
827         } while (0)
828 #define REG_PATTERN_TEST(reg, mask, write)                                     \
829         REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
830
831 #define REG_SET_AND_CHECK(reg, mask, write)                                    \
832         do {                                                                   \
833                 if (reg_set_and_check(adapter, data, reg, mask, write))        \
834                         return 1;                                              \
835         } while (0)
836
837 static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
838 {
839         struct e1000_hw *hw = &adapter->hw;
840         struct e1000_mac_info *mac = &adapter->hw.mac;
841         u32 value;
842         u32 before;
843         u32 after;
844         u32 i;
845         u32 toggle;
846         u32 mask;
847         u32 wlock_mac = 0;
848
849         /* The status register is Read Only, so a write should fail.
850          * Some bits that get toggled are ignored.  There are several bits
851          * on newer hardware that are r/w.
852          */
853         switch (mac->type) {
854         case e1000_82571:
855         case e1000_82572:
856         case e1000_80003es2lan:
857                 toggle = 0x7FFFF3FF;
858                 break;
859         default:
860                 toggle = 0x7FFFF033;
861                 break;
862         }
863
864         before = er32(STATUS);
865         value = (er32(STATUS) & toggle);
866         ew32(STATUS, toggle);
867         after = er32(STATUS) & toggle;
868         if (value != after) {
869                 e_err("failed STATUS register test got: 0x%08X expected: 0x%08X\n",
870                       after, value);
871                 *data = 1;
872                 return 1;
873         }
874         /* restore previous status */
875         ew32(STATUS, before);
876
877         if (!(adapter->flags & FLAG_IS_ICH)) {
878                 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
879                 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
880                 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
881                 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
882         }
883
884         REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
885         REG_PATTERN_TEST(E1000_RDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
886         REG_PATTERN_TEST(E1000_RDLEN(0), 0x000FFF80, 0x000FFFFF);
887         REG_PATTERN_TEST(E1000_RDH(0), 0x0000FFFF, 0x0000FFFF);
888         REG_PATTERN_TEST(E1000_RDT(0), 0x0000FFFF, 0x0000FFFF);
889         REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
890         REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
891         REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
892         REG_PATTERN_TEST(E1000_TDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF);
893         REG_PATTERN_TEST(E1000_TDLEN(0), 0x000FFF80, 0x000FFFFF);
894
895         REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
896
897         before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
898         REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
899         REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
900
901         REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
902         REG_PATTERN_TEST(E1000_RDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
903         if (!(adapter->flags & FLAG_IS_ICH))
904                 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
905         REG_PATTERN_TEST(E1000_TDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF);
906         REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
907         mask = 0x8003FFFF;
908         switch (mac->type) {
909         case e1000_ich10lan:
910         case e1000_pchlan:
911         case e1000_pch2lan:
912         case e1000_pch_lpt:
913         case e1000_pch_spt:
914                 mask |= BIT(18);
915                 break;
916         default:
917                 break;
918         }
919
920         if ((mac->type == e1000_pch_lpt) || (mac->type == e1000_pch_spt))
921                 wlock_mac = (er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK) >>
922                     E1000_FWSM_WLOCK_MAC_SHIFT;
923
924         for (i = 0; i < mac->rar_entry_count; i++) {
925                 if ((mac->type == e1000_pch_lpt) ||
926                     (mac->type == e1000_pch_spt)) {
927                         /* Cannot test write-protected SHRAL[n] registers */
928                         if ((wlock_mac == 1) || (wlock_mac && (i > wlock_mac)))
929                                 continue;
930
931                         /* SHRAH[9] different than the others */
932                         if (i == 10)
933                                 mask |= BIT(30);
934                         else
935                                 mask &= ~BIT(30);
936                 }
937                 if (mac->type == e1000_pch2lan) {
938                         /* SHRAH[0,1,2] different than previous */
939                         if (i == 1)
940                                 mask &= 0xFFF4FFFF;
941                         /* SHRAH[3] different than SHRAH[0,1,2] */
942                         if (i == 4)
943                                 mask |= BIT(30);
944                         /* RAR[1-6] owned by management engine - skipping */
945                         if (i > 0)
946                                 i += 6;
947                 }
948
949                 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1), mask,
950                                        0xFFFFFFFF);
951                 /* reset index to actual value */
952                 if ((mac->type == e1000_pch2lan) && (i > 6))
953                         i -= 6;
954         }
955
956         for (i = 0; i < mac->mta_reg_count; i++)
957                 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
958
959         *data = 0;
960
961         return 0;
962 }
963
964 static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
965 {
966         u16 temp;
967         u16 checksum = 0;
968         u16 i;
969
970         *data = 0;
971         /* Read and add up the contents of the EEPROM */
972         for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
973                 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
974                         *data = 1;
975                         return *data;
976                 }
977                 checksum += temp;
978         }
979
980         /* If Checksum is not Correct return error else test passed */
981         if ((checksum != (u16)NVM_SUM) && !(*data))
982                 *data = 2;
983
984         return *data;
985 }
986
987 static irqreturn_t e1000_test_intr(int __always_unused irq, void *data)
988 {
989         struct net_device *netdev = (struct net_device *)data;
990         struct e1000_adapter *adapter = netdev_priv(netdev);
991         struct e1000_hw *hw = &adapter->hw;
992
993         adapter->test_icr |= er32(ICR);
994
995         return IRQ_HANDLED;
996 }
997
998 static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
999 {
1000         struct net_device *netdev = adapter->netdev;
1001         struct e1000_hw *hw = &adapter->hw;
1002         u32 mask;
1003         u32 shared_int = 1;
1004         u32 irq = adapter->pdev->irq;
1005         int i;
1006         int ret_val = 0;
1007         int int_mode = E1000E_INT_MODE_LEGACY;
1008
1009         *data = 0;
1010
1011         /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
1012         if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
1013                 int_mode = adapter->int_mode;
1014                 e1000e_reset_interrupt_capability(adapter);
1015                 adapter->int_mode = E1000E_INT_MODE_LEGACY;
1016                 e1000e_set_interrupt_capability(adapter);
1017         }
1018         /* Hook up test interrupt handler just for this test */
1019         if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
1020                          netdev)) {
1021                 shared_int = 0;
1022         } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED, netdev->name,
1023                                netdev)) {
1024                 *data = 1;
1025                 ret_val = -1;
1026                 goto out;
1027         }
1028         e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
1029
1030         /* Disable all the interrupts */
1031         ew32(IMC, 0xFFFFFFFF);
1032         e1e_flush();
1033         usleep_range(10000, 20000);
1034
1035         /* Test each interrupt */
1036         for (i = 0; i < 10; i++) {
1037                 /* Interrupt to test */
1038                 mask = BIT(i);
1039
1040                 if (adapter->flags & FLAG_IS_ICH) {
1041                         switch (mask) {
1042                         case E1000_ICR_RXSEQ:
1043                                 continue;
1044                         case 0x00000100:
1045                                 if (adapter->hw.mac.type == e1000_ich8lan ||
1046                                     adapter->hw.mac.type == e1000_ich9lan)
1047                                         continue;
1048                                 break;
1049                         default:
1050                                 break;
1051                         }
1052                 }
1053
1054                 if (!shared_int) {
1055                         /* Disable the interrupt to be reported in
1056                          * the cause register and then force the same
1057                          * interrupt and see if one gets posted.  If
1058                          * an interrupt was posted to the bus, the
1059                          * test failed.
1060                          */
1061                         adapter->test_icr = 0;
1062                         ew32(IMC, mask);
1063                         ew32(ICS, mask);
1064                         e1e_flush();
1065                         usleep_range(10000, 20000);
1066
1067                         if (adapter->test_icr & mask) {
1068                                 *data = 3;
1069                                 break;
1070                         }
1071                 }
1072
1073                 /* Enable the interrupt to be reported in
1074                  * the cause register and then force the same
1075                  * interrupt and see if one gets posted.  If
1076                  * an interrupt was not posted to the bus, the
1077                  * test failed.
1078                  */
1079                 adapter->test_icr = 0;
1080                 ew32(IMS, mask);
1081                 ew32(ICS, mask);
1082                 e1e_flush();
1083                 usleep_range(10000, 20000);
1084
1085                 if (!(adapter->test_icr & mask)) {
1086                         *data = 4;
1087                         break;
1088                 }
1089
1090                 if (!shared_int) {
1091                         /* Disable the other interrupts to be reported in
1092                          * the cause register and then force the other
1093                          * interrupts and see if any get posted.  If
1094                          * an interrupt was posted to the bus, the
1095                          * test failed.
1096                          */
1097                         adapter->test_icr = 0;
1098                         ew32(IMC, ~mask & 0x00007FFF);
1099                         ew32(ICS, ~mask & 0x00007FFF);
1100                         e1e_flush();
1101                         usleep_range(10000, 20000);
1102
1103                         if (adapter->test_icr) {
1104                                 *data = 5;
1105                                 break;
1106                         }
1107                 }
1108         }
1109
1110         /* Disable all the interrupts */
1111         ew32(IMC, 0xFFFFFFFF);
1112         e1e_flush();
1113         usleep_range(10000, 20000);
1114
1115         /* Unhook test interrupt handler */
1116         free_irq(irq, netdev);
1117
1118 out:
1119         if (int_mode == E1000E_INT_MODE_MSIX) {
1120                 e1000e_reset_interrupt_capability(adapter);
1121                 adapter->int_mode = int_mode;
1122                 e1000e_set_interrupt_capability(adapter);
1123         }
1124
1125         return ret_val;
1126 }
1127
1128 static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1129 {
1130         struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1131         struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1132         struct pci_dev *pdev = adapter->pdev;
1133         struct e1000_buffer *buffer_info;
1134         int i;
1135
1136         if (tx_ring->desc && tx_ring->buffer_info) {
1137                 for (i = 0; i < tx_ring->count; i++) {
1138                         buffer_info = &tx_ring->buffer_info[i];
1139
1140                         if (buffer_info->dma)
1141                                 dma_unmap_single(&pdev->dev,
1142                                                  buffer_info->dma,
1143                                                  buffer_info->length,
1144                                                  DMA_TO_DEVICE);
1145                         if (buffer_info->skb)
1146                                 dev_kfree_skb(buffer_info->skb);
1147                 }
1148         }
1149
1150         if (rx_ring->desc && rx_ring->buffer_info) {
1151                 for (i = 0; i < rx_ring->count; i++) {
1152                         buffer_info = &rx_ring->buffer_info[i];
1153
1154                         if (buffer_info->dma)
1155                                 dma_unmap_single(&pdev->dev,
1156                                                  buffer_info->dma,
1157                                                  2048, DMA_FROM_DEVICE);
1158                         if (buffer_info->skb)
1159                                 dev_kfree_skb(buffer_info->skb);
1160                 }
1161         }
1162
1163         if (tx_ring->desc) {
1164                 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1165                                   tx_ring->dma);
1166                 tx_ring->desc = NULL;
1167         }
1168         if (rx_ring->desc) {
1169                 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1170                                   rx_ring->dma);
1171                 rx_ring->desc = NULL;
1172         }
1173
1174         kfree(tx_ring->buffer_info);
1175         tx_ring->buffer_info = NULL;
1176         kfree(rx_ring->buffer_info);
1177         rx_ring->buffer_info = NULL;
1178 }
1179
1180 static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1181 {
1182         struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1183         struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1184         struct pci_dev *pdev = adapter->pdev;
1185         struct e1000_hw *hw = &adapter->hw;
1186         u32 rctl;
1187         int i;
1188         int ret_val;
1189
1190         /* Setup Tx descriptor ring and Tx buffers */
1191
1192         if (!tx_ring->count)
1193                 tx_ring->count = E1000_DEFAULT_TXD;
1194
1195         tx_ring->buffer_info = kcalloc(tx_ring->count,
1196                                        sizeof(struct e1000_buffer), GFP_KERNEL);
1197         if (!tx_ring->buffer_info) {
1198                 ret_val = 1;
1199                 goto err_nomem;
1200         }
1201
1202         tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1203         tx_ring->size = ALIGN(tx_ring->size, 4096);
1204         tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1205                                            &tx_ring->dma, GFP_KERNEL);
1206         if (!tx_ring->desc) {
1207                 ret_val = 2;
1208                 goto err_nomem;
1209         }
1210         tx_ring->next_to_use = 0;
1211         tx_ring->next_to_clean = 0;
1212
1213         ew32(TDBAL(0), ((u64)tx_ring->dma & 0x00000000FFFFFFFF));
1214         ew32(TDBAH(0), ((u64)tx_ring->dma >> 32));
1215         ew32(TDLEN(0), tx_ring->count * sizeof(struct e1000_tx_desc));
1216         ew32(TDH(0), 0);
1217         ew32(TDT(0), 0);
1218         ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1219              E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1220              E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
1221
1222         for (i = 0; i < tx_ring->count; i++) {
1223                 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1224                 struct sk_buff *skb;
1225                 unsigned int skb_size = 1024;
1226
1227                 skb = alloc_skb(skb_size, GFP_KERNEL);
1228                 if (!skb) {
1229                         ret_val = 3;
1230                         goto err_nomem;
1231                 }
1232                 skb_put(skb, skb_size);
1233                 tx_ring->buffer_info[i].skb = skb;
1234                 tx_ring->buffer_info[i].length = skb->len;
1235                 tx_ring->buffer_info[i].dma =
1236                     dma_map_single(&pdev->dev, skb->data, skb->len,
1237                                    DMA_TO_DEVICE);
1238                 if (dma_mapping_error(&pdev->dev,
1239                                       tx_ring->buffer_info[i].dma)) {
1240                         ret_val = 4;
1241                         goto err_nomem;
1242                 }
1243                 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
1244                 tx_desc->lower.data = cpu_to_le32(skb->len);
1245                 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1246                                                    E1000_TXD_CMD_IFCS |
1247                                                    E1000_TXD_CMD_RS);
1248                 tx_desc->upper.data = 0;
1249         }
1250
1251         /* Setup Rx descriptor ring and Rx buffers */
1252
1253         if (!rx_ring->count)
1254                 rx_ring->count = E1000_DEFAULT_RXD;
1255
1256         rx_ring->buffer_info = kcalloc(rx_ring->count,
1257                                        sizeof(struct e1000_buffer), GFP_KERNEL);
1258         if (!rx_ring->buffer_info) {
1259                 ret_val = 5;
1260                 goto err_nomem;
1261         }
1262
1263         rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended);
1264         rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1265                                            &rx_ring->dma, GFP_KERNEL);
1266         if (!rx_ring->desc) {
1267                 ret_val = 6;
1268                 goto err_nomem;
1269         }
1270         rx_ring->next_to_use = 0;
1271         rx_ring->next_to_clean = 0;
1272
1273         rctl = er32(RCTL);
1274         if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
1275                 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1276         ew32(RDBAL(0), ((u64)rx_ring->dma & 0xFFFFFFFF));
1277         ew32(RDBAH(0), ((u64)rx_ring->dma >> 32));
1278         ew32(RDLEN(0), rx_ring->size);
1279         ew32(RDH(0), 0);
1280         ew32(RDT(0), 0);
1281         rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
1282             E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1283             E1000_RCTL_SBP | E1000_RCTL_SECRC |
1284             E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1285             (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1286         ew32(RCTL, rctl);
1287
1288         for (i = 0; i < rx_ring->count; i++) {
1289                 union e1000_rx_desc_extended *rx_desc;
1290                 struct sk_buff *skb;
1291
1292                 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1293                 if (!skb) {
1294                         ret_val = 7;
1295                         goto err_nomem;
1296                 }
1297                 skb_reserve(skb, NET_IP_ALIGN);
1298                 rx_ring->buffer_info[i].skb = skb;
1299                 rx_ring->buffer_info[i].dma =
1300                     dma_map_single(&pdev->dev, skb->data, 2048,
1301                                    DMA_FROM_DEVICE);
1302                 if (dma_mapping_error(&pdev->dev,
1303                                       rx_ring->buffer_info[i].dma)) {
1304                         ret_val = 8;
1305                         goto err_nomem;
1306                 }
1307                 rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
1308                 rx_desc->read.buffer_addr =
1309                     cpu_to_le64(rx_ring->buffer_info[i].dma);
1310                 memset(skb->data, 0x00, skb->len);
1311         }
1312
1313         return 0;
1314
1315 err_nomem:
1316         e1000_free_desc_rings(adapter);
1317         return ret_val;
1318 }
1319
1320 static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1321 {
1322         /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1323         e1e_wphy(&adapter->hw, 29, 0x001F);
1324         e1e_wphy(&adapter->hw, 30, 0x8FFC);
1325         e1e_wphy(&adapter->hw, 29, 0x001A);
1326         e1e_wphy(&adapter->hw, 30, 0x8FF0);
1327 }
1328
1329 static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1330 {
1331         struct e1000_hw *hw = &adapter->hw;
1332         u32 ctrl_reg = 0;
1333         u16 phy_reg = 0;
1334         s32 ret_val = 0;
1335
1336         hw->mac.autoneg = 0;
1337
1338         if (hw->phy.type == e1000_phy_ife) {
1339                 /* force 100, set loopback */
1340                 e1e_wphy(hw, MII_BMCR, 0x6100);
1341
1342                 /* Now set up the MAC to the same speed/duplex as the PHY. */
1343                 ctrl_reg = er32(CTRL);
1344                 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1345                 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1346                              E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1347                              E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1348                              E1000_CTRL_FD);     /* Force Duplex to FULL */
1349
1350                 ew32(CTRL, ctrl_reg);
1351                 e1e_flush();
1352                 usleep_range(500, 1000);
1353
1354                 return 0;
1355         }
1356
1357         /* Specific PHY configuration for loopback */
1358         switch (hw->phy.type) {
1359         case e1000_phy_m88:
1360                 /* Auto-MDI/MDIX Off */
1361                 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1362                 /* reset to update Auto-MDI/MDIX */
1363                 e1e_wphy(hw, MII_BMCR, 0x9140);
1364                 /* autoneg off */
1365                 e1e_wphy(hw, MII_BMCR, 0x8140);
1366                 break;
1367         case e1000_phy_gg82563:
1368                 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
1369                 break;
1370         case e1000_phy_bm:
1371                 /* Set Default MAC Interface speed to 1GB */
1372                 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1373                 phy_reg &= ~0x0007;
1374                 phy_reg |= 0x006;
1375                 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1376                 /* Assert SW reset for above settings to take effect */
1377                 hw->phy.ops.commit(hw);
1378                 usleep_range(1000, 2000);
1379                 /* Force Full Duplex */
1380                 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1381                 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1382                 /* Set Link Up (in force link) */
1383                 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1384                 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1385                 /* Force Link */
1386                 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1387                 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1388                 /* Set Early Link Enable */
1389                 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1390                 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
1391                 break;
1392         case e1000_phy_82577:
1393         case e1000_phy_82578:
1394                 /* Workaround: K1 must be disabled for stable 1Gbps operation */
1395                 ret_val = hw->phy.ops.acquire(hw);
1396                 if (ret_val) {
1397                         e_err("Cannot setup 1Gbps loopback.\n");
1398                         return ret_val;
1399                 }
1400                 e1000_configure_k1_ich8lan(hw, false);
1401                 hw->phy.ops.release(hw);
1402                 break;
1403         case e1000_phy_82579:
1404                 /* Disable PHY energy detect power down */
1405                 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1406                 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~BIT(3));
1407                 /* Disable full chip energy detect */
1408                 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1409                 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1410                 /* Enable loopback on the PHY */
1411                 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1412                 break;
1413         default:
1414                 break;
1415         }
1416
1417         /* force 1000, set loopback */
1418         e1e_wphy(hw, MII_BMCR, 0x4140);
1419         msleep(250);
1420
1421         /* Now set up the MAC to the same speed/duplex as the PHY. */
1422         ctrl_reg = er32(CTRL);
1423         ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1424         ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1425                      E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1426                      E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1427                      E1000_CTRL_FD);     /* Force Duplex to FULL */
1428
1429         if (adapter->flags & FLAG_IS_ICH)
1430                 ctrl_reg |= E1000_CTRL_SLU;     /* Set Link Up */
1431
1432         if (hw->phy.media_type == e1000_media_type_copper &&
1433             hw->phy.type == e1000_phy_m88) {
1434                 ctrl_reg |= E1000_CTRL_ILOS;    /* Invert Loss of Signal */
1435         } else {
1436                 /* Set the ILOS bit on the fiber Nic if half duplex link is
1437                  * detected.
1438                  */
1439                 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
1440                         ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1441         }
1442
1443         ew32(CTRL, ctrl_reg);
1444
1445         /* Disable the receiver on the PHY so when a cable is plugged in, the
1446          * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1447          */
1448         if (hw->phy.type == e1000_phy_m88)
1449                 e1000_phy_disable_receiver(adapter);
1450
1451         usleep_range(500, 1000);
1452
1453         return 0;
1454 }
1455
1456 static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1457 {
1458         struct e1000_hw *hw = &adapter->hw;
1459         u32 ctrl = er32(CTRL);
1460         int link;
1461
1462         /* special requirements for 82571/82572 fiber adapters */
1463
1464         /* jump through hoops to make sure link is up because serdes
1465          * link is hardwired up
1466          */
1467         ctrl |= E1000_CTRL_SLU;
1468         ew32(CTRL, ctrl);
1469
1470         /* disable autoneg */
1471         ctrl = er32(TXCW);
1472         ctrl &= ~BIT(31);
1473         ew32(TXCW, ctrl);
1474
1475         link = (er32(STATUS) & E1000_STATUS_LU);
1476
1477         if (!link) {
1478                 /* set invert loss of signal */
1479                 ctrl = er32(CTRL);
1480                 ctrl |= E1000_CTRL_ILOS;
1481                 ew32(CTRL, ctrl);
1482         }
1483
1484         /* special write to serdes control register to enable SerDes analog
1485          * loopback
1486          */
1487         ew32(SCTL, E1000_SCTL_ENABLE_SERDES_LOOPBACK);
1488         e1e_flush();
1489         usleep_range(10000, 20000);
1490
1491         return 0;
1492 }
1493
1494 /* only call this for fiber/serdes connections to es2lan */
1495 static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1496 {
1497         struct e1000_hw *hw = &adapter->hw;
1498         u32 ctrlext = er32(CTRL_EXT);
1499         u32 ctrl = er32(CTRL);
1500
1501         /* save CTRL_EXT to restore later, reuse an empty variable (unused
1502          * on mac_type 80003es2lan)
1503          */
1504         adapter->tx_fifo_head = ctrlext;
1505
1506         /* clear the serdes mode bits, putting the device into mac loopback */
1507         ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1508         ew32(CTRL_EXT, ctrlext);
1509
1510         /* force speed to 1000/FD, link up */
1511         ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1512         ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1513                  E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1514         ew32(CTRL, ctrl);
1515
1516         /* set mac loopback */
1517         ctrl = er32(RCTL);
1518         ctrl |= E1000_RCTL_LBM_MAC;
1519         ew32(RCTL, ctrl);
1520
1521         /* set testing mode parameters (no need to reset later) */
1522 #define KMRNCTRLSTA_OPMODE (0x1F << 16)
1523 #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1524         ew32(KMRNCTRLSTA,
1525              (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
1526
1527         return 0;
1528 }
1529
1530 static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1531 {
1532         struct e1000_hw *hw = &adapter->hw;
1533         u32 rctl, fext_nvm11, tarc0;
1534
1535         if (hw->mac.type == e1000_pch_spt) {
1536                 fext_nvm11 = er32(FEXTNVM11);
1537                 fext_nvm11 |= E1000_FEXTNVM11_DISABLE_MULR_FIX;
1538                 ew32(FEXTNVM11, fext_nvm11);
1539                 tarc0 = er32(TARC(0));
1540                 /* clear bits 28 & 29 (control of MULR concurrent requests) */
1541                 tarc0 &= 0xcfffffff;
1542                 /* set bit 29 (value of MULR requests is now 2) */
1543                 tarc0 |= 0x20000000;
1544                 ew32(TARC(0), tarc0);
1545         }
1546         if (hw->phy.media_type == e1000_media_type_fiber ||
1547             hw->phy.media_type == e1000_media_type_internal_serdes) {
1548                 switch (hw->mac.type) {
1549                 case e1000_80003es2lan:
1550                         return e1000_set_es2lan_mac_loopback(adapter);
1551                 case e1000_82571:
1552                 case e1000_82572:
1553                         return e1000_set_82571_fiber_loopback(adapter);
1554                 default:
1555                         rctl = er32(RCTL);
1556                         rctl |= E1000_RCTL_LBM_TCVR;
1557                         ew32(RCTL, rctl);
1558                         return 0;
1559                 }
1560         } else if (hw->phy.media_type == e1000_media_type_copper) {
1561                 return e1000_integrated_phy_loopback(adapter);
1562         }
1563
1564         return 7;
1565 }
1566
1567 static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1568 {
1569         struct e1000_hw *hw = &adapter->hw;
1570         u32 rctl, fext_nvm11, tarc0;
1571         u16 phy_reg;
1572
1573         rctl = er32(RCTL);
1574         rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1575         ew32(RCTL, rctl);
1576
1577         switch (hw->mac.type) {
1578         case e1000_pch_spt:
1579                 fext_nvm11 = er32(FEXTNVM11);
1580                 fext_nvm11 &= ~E1000_FEXTNVM11_DISABLE_MULR_FIX;
1581                 ew32(FEXTNVM11, fext_nvm11);
1582                 tarc0 = er32(TARC(0));
1583                 /* clear bits 28 & 29 (control of MULR concurrent requests) */
1584                 /* set bit 29 (value of MULR requests is now 0) */
1585                 tarc0 &= 0xcfffffff;
1586                 ew32(TARC(0), tarc0);
1587                 /* fall through */
1588         case e1000_80003es2lan:
1589                 if (hw->phy.media_type == e1000_media_type_fiber ||
1590                     hw->phy.media_type == e1000_media_type_internal_serdes) {
1591                         /* restore CTRL_EXT, stealing space from tx_fifo_head */
1592                         ew32(CTRL_EXT, adapter->tx_fifo_head);
1593                         adapter->tx_fifo_head = 0;
1594                 }
1595                 /* fall through */
1596         case e1000_82571:
1597         case e1000_82572:
1598                 if (hw->phy.media_type == e1000_media_type_fiber ||
1599                     hw->phy.media_type == e1000_media_type_internal_serdes) {
1600                         ew32(SCTL, E1000_SCTL_DISABLE_SERDES_LOOPBACK);
1601                         e1e_flush();
1602                         usleep_range(10000, 20000);
1603                         break;
1604                 }
1605                 /* Fall Through */
1606         default:
1607                 hw->mac.autoneg = 1;
1608                 if (hw->phy.type == e1000_phy_gg82563)
1609                         e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1610                 e1e_rphy(hw, MII_BMCR, &phy_reg);
1611                 if (phy_reg & BMCR_LOOPBACK) {
1612                         phy_reg &= ~BMCR_LOOPBACK;
1613                         e1e_wphy(hw, MII_BMCR, phy_reg);
1614                         if (hw->phy.ops.commit)
1615                                 hw->phy.ops.commit(hw);
1616                 }
1617                 break;
1618         }
1619 }
1620
1621 static void e1000_create_lbtest_frame(struct sk_buff *skb,
1622                                       unsigned int frame_size)
1623 {
1624         memset(skb->data, 0xFF, frame_size);
1625         frame_size &= ~1;
1626         memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1627         memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1628         memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1629 }
1630
1631 static int e1000_check_lbtest_frame(struct sk_buff *skb,
1632                                     unsigned int frame_size)
1633 {
1634         frame_size &= ~1;
1635         if (*(skb->data + 3) == 0xFF)
1636                 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1637                     (*(skb->data + frame_size / 2 + 12) == 0xAF))
1638                         return 0;
1639         return 13;
1640 }
1641
1642 static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1643 {
1644         struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1645         struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1646         struct pci_dev *pdev = adapter->pdev;
1647         struct e1000_hw *hw = &adapter->hw;
1648         struct e1000_buffer *buffer_info;
1649         int i, j, k, l;
1650         int lc;
1651         int good_cnt;
1652         int ret_val = 0;
1653         unsigned long time;
1654
1655         ew32(RDT(0), rx_ring->count - 1);
1656
1657         /* Calculate the loop count based on the largest descriptor ring
1658          * The idea is to wrap the largest ring a number of times using 64
1659          * send/receive pairs during each loop
1660          */
1661
1662         if (rx_ring->count <= tx_ring->count)
1663                 lc = ((tx_ring->count / 64) * 2) + 1;
1664         else
1665                 lc = ((rx_ring->count / 64) * 2) + 1;
1666
1667         k = 0;
1668         l = 0;
1669         /* loop count loop */
1670         for (j = 0; j <= lc; j++) {
1671                 /* send the packets */
1672                 for (i = 0; i < 64; i++) {
1673                         buffer_info = &tx_ring->buffer_info[k];
1674
1675                         e1000_create_lbtest_frame(buffer_info->skb, 1024);
1676                         dma_sync_single_for_device(&pdev->dev,
1677                                                    buffer_info->dma,
1678                                                    buffer_info->length,
1679                                                    DMA_TO_DEVICE);
1680                         k++;
1681                         if (k == tx_ring->count)
1682                                 k = 0;
1683                 }
1684                 ew32(TDT(0), k);
1685                 e1e_flush();
1686                 msleep(200);
1687                 time = jiffies; /* set the start time for the receive */
1688                 good_cnt = 0;
1689                 /* receive the sent packets */
1690                 do {
1691                         buffer_info = &rx_ring->buffer_info[l];
1692
1693                         dma_sync_single_for_cpu(&pdev->dev,
1694                                                 buffer_info->dma, 2048,
1695                                                 DMA_FROM_DEVICE);
1696
1697                         ret_val = e1000_check_lbtest_frame(buffer_info->skb,
1698                                                            1024);
1699                         if (!ret_val)
1700                                 good_cnt++;
1701                         l++;
1702                         if (l == rx_ring->count)
1703                                 l = 0;
1704                         /* time + 20 msecs (200 msecs on 2.4) is more than
1705                          * enough time to complete the receives, if it's
1706                          * exceeded, break and error off
1707                          */
1708                 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1709                 if (good_cnt != 64) {
1710                         ret_val = 13;   /* ret_val is the same as mis-compare */
1711                         break;
1712                 }
1713                 if (time_after(jiffies, time + 20)) {
1714                         ret_val = 14;   /* error code for time out error */
1715                         break;
1716                 }
1717         }
1718         return ret_val;
1719 }
1720
1721 static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1722 {
1723         struct e1000_hw *hw = &adapter->hw;
1724
1725         /* PHY loopback cannot be performed if SoL/IDER sessions are active */
1726         if (hw->phy.ops.check_reset_block &&
1727             hw->phy.ops.check_reset_block(hw)) {
1728                 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
1729                 *data = 0;
1730                 goto out;
1731         }
1732
1733         *data = e1000_setup_desc_rings(adapter);
1734         if (*data)
1735                 goto out;
1736
1737         *data = e1000_setup_loopback_test(adapter);
1738         if (*data)
1739                 goto err_loopback;
1740
1741         *data = e1000_run_loopback_test(adapter);
1742         e1000_loopback_cleanup(adapter);
1743
1744 err_loopback:
1745         e1000_free_desc_rings(adapter);
1746 out:
1747         return *data;
1748 }
1749
1750 static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1751 {
1752         struct e1000_hw *hw = &adapter->hw;
1753
1754         *data = 0;
1755         if (hw->phy.media_type == e1000_media_type_internal_serdes) {
1756                 int i = 0;
1757
1758                 hw->mac.serdes_has_link = false;
1759
1760                 /* On some blade server designs, link establishment
1761                  * could take as long as 2-3 minutes
1762                  */
1763                 do {
1764                         hw->mac.ops.check_for_link(hw);
1765                         if (hw->mac.serdes_has_link)
1766                                 return *data;
1767                         msleep(20);
1768                 } while (i++ < 3750);
1769
1770                 *data = 1;
1771         } else {
1772                 hw->mac.ops.check_for_link(hw);
1773                 if (hw->mac.autoneg)
1774                         /* On some Phy/switch combinations, link establishment
1775                          * can take a few seconds more than expected.
1776                          */
1777                         msleep_interruptible(5000);
1778
1779                 if (!(er32(STATUS) & E1000_STATUS_LU))
1780                         *data = 1;
1781         }
1782         return *data;
1783 }
1784
1785 static int e1000e_get_sset_count(struct net_device __always_unused *netdev,
1786                                  int sset)
1787 {
1788         switch (sset) {
1789         case ETH_SS_TEST:
1790                 return E1000_TEST_LEN;
1791         case ETH_SS_STATS:
1792                 return E1000_STATS_LEN;
1793         default:
1794                 return -EOPNOTSUPP;
1795         }
1796 }
1797
1798 static void e1000_diag_test(struct net_device *netdev,
1799                             struct ethtool_test *eth_test, u64 *data)
1800 {
1801         struct e1000_adapter *adapter = netdev_priv(netdev);
1802         u16 autoneg_advertised;
1803         u8 forced_speed_duplex;
1804         u8 autoneg;
1805         bool if_running = netif_running(netdev);
1806
1807         pm_runtime_get_sync(netdev->dev.parent);
1808
1809         set_bit(__E1000_TESTING, &adapter->state);
1810
1811         if (!if_running) {
1812                 /* Get control of and reset hardware */
1813                 if (adapter->flags & FLAG_HAS_AMT)
1814                         e1000e_get_hw_control(adapter);
1815
1816                 e1000e_power_up_phy(adapter);
1817
1818                 adapter->hw.phy.autoneg_wait_to_complete = 1;
1819                 e1000e_reset(adapter);
1820                 adapter->hw.phy.autoneg_wait_to_complete = 0;
1821         }
1822
1823         if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1824                 /* Offline tests */
1825
1826                 /* save speed, duplex, autoneg settings */
1827                 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1828                 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1829                 autoneg = adapter->hw.mac.autoneg;
1830
1831                 e_info("offline testing starting\n");
1832
1833                 if (if_running)
1834                         /* indicate we're in test mode */
1835                         e1000e_close(netdev);
1836
1837                 if (e1000_reg_test(adapter, &data[0]))
1838                         eth_test->flags |= ETH_TEST_FL_FAILED;
1839
1840                 e1000e_reset(adapter);
1841                 if (e1000_eeprom_test(adapter, &data[1]))
1842                         eth_test->flags |= ETH_TEST_FL_FAILED;
1843
1844                 e1000e_reset(adapter);
1845                 if (e1000_intr_test(adapter, &data[2]))
1846                         eth_test->flags |= ETH_TEST_FL_FAILED;
1847
1848                 e1000e_reset(adapter);
1849                 if (e1000_loopback_test(adapter, &data[3]))
1850                         eth_test->flags |= ETH_TEST_FL_FAILED;
1851
1852                 /* force this routine to wait until autoneg complete/timeout */
1853                 adapter->hw.phy.autoneg_wait_to_complete = 1;
1854                 e1000e_reset(adapter);
1855                 adapter->hw.phy.autoneg_wait_to_complete = 0;
1856
1857                 if (e1000_link_test(adapter, &data[4]))
1858                         eth_test->flags |= ETH_TEST_FL_FAILED;
1859
1860                 /* restore speed, duplex, autoneg settings */
1861                 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1862                 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1863                 adapter->hw.mac.autoneg = autoneg;
1864                 e1000e_reset(adapter);
1865
1866                 clear_bit(__E1000_TESTING, &adapter->state);
1867                 if (if_running)
1868                         e1000e_open(netdev);
1869         } else {
1870                 /* Online tests */
1871
1872                 e_info("online testing starting\n");
1873
1874                 /* register, eeprom, intr and loopback tests not run online */
1875                 data[0] = 0;
1876                 data[1] = 0;
1877                 data[2] = 0;
1878                 data[3] = 0;
1879
1880                 if (e1000_link_test(adapter, &data[4]))
1881                         eth_test->flags |= ETH_TEST_FL_FAILED;
1882
1883                 clear_bit(__E1000_TESTING, &adapter->state);
1884         }
1885
1886         if (!if_running) {
1887                 e1000e_reset(adapter);
1888
1889                 if (adapter->flags & FLAG_HAS_AMT)
1890                         e1000e_release_hw_control(adapter);
1891         }
1892
1893         msleep_interruptible(4 * 1000);
1894
1895         pm_runtime_put_sync(netdev->dev.parent);
1896 }
1897
1898 static void e1000_get_wol(struct net_device *netdev,
1899                           struct ethtool_wolinfo *wol)
1900 {
1901         struct e1000_adapter *adapter = netdev_priv(netdev);
1902
1903         wol->supported = 0;
1904         wol->wolopts = 0;
1905
1906         if (!(adapter->flags & FLAG_HAS_WOL) ||
1907             !device_can_wakeup(&adapter->pdev->dev))
1908                 return;
1909
1910         wol->supported = WAKE_UCAST | WAKE_MCAST |
1911             WAKE_BCAST | WAKE_MAGIC | WAKE_PHY;
1912
1913         /* apply any specific unsupported masks here */
1914         if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1915                 wol->supported &= ~WAKE_UCAST;
1916
1917                 if (adapter->wol & E1000_WUFC_EX)
1918                         e_err("Interface does not support directed (unicast) frame wake-up packets\n");
1919         }
1920
1921         if (adapter->wol & E1000_WUFC_EX)
1922                 wol->wolopts |= WAKE_UCAST;
1923         if (adapter->wol & E1000_WUFC_MC)
1924                 wol->wolopts |= WAKE_MCAST;
1925         if (adapter->wol & E1000_WUFC_BC)
1926                 wol->wolopts |= WAKE_BCAST;
1927         if (adapter->wol & E1000_WUFC_MAG)
1928                 wol->wolopts |= WAKE_MAGIC;
1929         if (adapter->wol & E1000_WUFC_LNKC)
1930                 wol->wolopts |= WAKE_PHY;
1931 }
1932
1933 static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1934 {
1935         struct e1000_adapter *adapter = netdev_priv(netdev);
1936
1937         if (!(adapter->flags & FLAG_HAS_WOL) ||
1938             !device_can_wakeup(&adapter->pdev->dev) ||
1939             (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
1940                               WAKE_MAGIC | WAKE_PHY)))
1941                 return -EOPNOTSUPP;
1942
1943         /* these settings will always override what we currently have */
1944         adapter->wol = 0;
1945
1946         if (wol->wolopts & WAKE_UCAST)
1947                 adapter->wol |= E1000_WUFC_EX;
1948         if (wol->wolopts & WAKE_MCAST)
1949                 adapter->wol |= E1000_WUFC_MC;
1950         if (wol->wolopts & WAKE_BCAST)
1951                 adapter->wol |= E1000_WUFC_BC;
1952         if (wol->wolopts & WAKE_MAGIC)
1953                 adapter->wol |= E1000_WUFC_MAG;
1954         if (wol->wolopts & WAKE_PHY)
1955                 adapter->wol |= E1000_WUFC_LNKC;
1956
1957         device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1958
1959         return 0;
1960 }
1961
1962 static int e1000_set_phys_id(struct net_device *netdev,
1963                              enum ethtool_phys_id_state state)
1964 {
1965         struct e1000_adapter *adapter = netdev_priv(netdev);
1966         struct e1000_hw *hw = &adapter->hw;
1967
1968         switch (state) {
1969         case ETHTOOL_ID_ACTIVE:
1970                 pm_runtime_get_sync(netdev->dev.parent);
1971
1972                 if (!hw->mac.ops.blink_led)
1973                         return 2;       /* cycle on/off twice per second */
1974
1975                 hw->mac.ops.blink_led(hw);
1976                 break;
1977
1978         case ETHTOOL_ID_INACTIVE:
1979                 if (hw->phy.type == e1000_phy_ife)
1980                         e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
1981                 hw->mac.ops.led_off(hw);
1982                 hw->mac.ops.cleanup_led(hw);
1983                 pm_runtime_put_sync(netdev->dev.parent);
1984                 break;
1985
1986         case ETHTOOL_ID_ON:
1987                 hw->mac.ops.led_on(hw);
1988                 break;
1989
1990         case ETHTOOL_ID_OFF:
1991                 hw->mac.ops.led_off(hw);
1992                 break;
1993         }
1994
1995         return 0;
1996 }
1997
1998 static int e1000_get_coalesce(struct net_device *netdev,
1999                               struct ethtool_coalesce *ec)
2000 {
2001         struct e1000_adapter *adapter = netdev_priv(netdev);
2002
2003         if (adapter->itr_setting <= 4)
2004                 ec->rx_coalesce_usecs = adapter->itr_setting;
2005         else
2006                 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
2007
2008         return 0;
2009 }
2010
2011 static int e1000_set_coalesce(struct net_device *netdev,
2012                               struct ethtool_coalesce *ec)
2013 {
2014         struct e1000_adapter *adapter = netdev_priv(netdev);
2015
2016         if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
2017             ((ec->rx_coalesce_usecs > 4) &&
2018              (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
2019             (ec->rx_coalesce_usecs == 2))
2020                 return -EINVAL;
2021
2022         if (ec->rx_coalesce_usecs == 4) {
2023                 adapter->itr_setting = 4;
2024                 adapter->itr = adapter->itr_setting;
2025         } else if (ec->rx_coalesce_usecs <= 3) {
2026                 adapter->itr = 20000;
2027                 adapter->itr_setting = ec->rx_coalesce_usecs;
2028         } else {
2029                 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
2030                 adapter->itr_setting = adapter->itr & ~3;
2031         }
2032
2033         pm_runtime_get_sync(netdev->dev.parent);
2034
2035         if (adapter->itr_setting != 0)
2036                 e1000e_write_itr(adapter, adapter->itr);
2037         else
2038                 e1000e_write_itr(adapter, 0);
2039
2040         pm_runtime_put_sync(netdev->dev.parent);
2041
2042         return 0;
2043 }
2044
2045 static int e1000_nway_reset(struct net_device *netdev)
2046 {
2047         struct e1000_adapter *adapter = netdev_priv(netdev);
2048
2049         if (!netif_running(netdev))
2050                 return -EAGAIN;
2051
2052         if (!adapter->hw.mac.autoneg)
2053                 return -EINVAL;
2054
2055         pm_runtime_get_sync(netdev->dev.parent);
2056         e1000e_reinit_locked(adapter);
2057         pm_runtime_put_sync(netdev->dev.parent);
2058
2059         return 0;
2060 }
2061
2062 static void e1000_get_ethtool_stats(struct net_device *netdev,
2063                                     struct ethtool_stats __always_unused *stats,
2064                                     u64 *data)
2065 {
2066         struct e1000_adapter *adapter = netdev_priv(netdev);
2067         struct rtnl_link_stats64 net_stats;
2068         int i;
2069         char *p = NULL;
2070
2071         pm_runtime_get_sync(netdev->dev.parent);
2072
2073         e1000e_get_stats64(netdev, &net_stats);
2074
2075         pm_runtime_put_sync(netdev->dev.parent);
2076
2077         for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
2078                 switch (e1000_gstrings_stats[i].type) {
2079                 case NETDEV_STATS:
2080                         p = (char *)&net_stats +
2081                             e1000_gstrings_stats[i].stat_offset;
2082                         break;
2083                 case E1000_STATS:
2084                         p = (char *)adapter +
2085                             e1000_gstrings_stats[i].stat_offset;
2086                         break;
2087                 default:
2088                         data[i] = 0;
2089                         continue;
2090                 }
2091
2092                 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
2093                            sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
2094         }
2095 }
2096
2097 static void e1000_get_strings(struct net_device __always_unused *netdev,
2098                               u32 stringset, u8 *data)
2099 {
2100         u8 *p = data;
2101         int i;
2102
2103         switch (stringset) {
2104         case ETH_SS_TEST:
2105                 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
2106                 break;
2107         case ETH_SS_STATS:
2108                 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
2109                         memcpy(p, e1000_gstrings_stats[i].stat_string,
2110                                ETH_GSTRING_LEN);
2111                         p += ETH_GSTRING_LEN;
2112                 }
2113                 break;
2114         }
2115 }
2116
2117 static int e1000_get_rxnfc(struct net_device *netdev,
2118                            struct ethtool_rxnfc *info,
2119                            u32 __always_unused *rule_locs)
2120 {
2121         info->data = 0;
2122
2123         switch (info->cmd) {
2124         case ETHTOOL_GRXFH: {
2125                 struct e1000_adapter *adapter = netdev_priv(netdev);
2126                 struct e1000_hw *hw = &adapter->hw;
2127                 u32 mrqc;
2128
2129                 pm_runtime_get_sync(netdev->dev.parent);
2130                 mrqc = er32(MRQC);
2131                 pm_runtime_put_sync(netdev->dev.parent);
2132
2133                 if (!(mrqc & E1000_MRQC_RSS_FIELD_MASK))
2134                         return 0;
2135
2136                 switch (info->flow_type) {
2137                 case TCP_V4_FLOW:
2138                         if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP)
2139                                 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2140                         /* fall through */
2141                 case UDP_V4_FLOW:
2142                 case SCTP_V4_FLOW:
2143                 case AH_ESP_V4_FLOW:
2144                 case IPV4_FLOW:
2145                         if (mrqc & E1000_MRQC_RSS_FIELD_IPV4)
2146                                 info->data |= RXH_IP_SRC | RXH_IP_DST;
2147                         break;
2148                 case TCP_V6_FLOW:
2149                         if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP)
2150                                 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2151                         /* fall through */
2152                 case UDP_V6_FLOW:
2153                 case SCTP_V6_FLOW:
2154                 case AH_ESP_V6_FLOW:
2155                 case IPV6_FLOW:
2156                         if (mrqc & E1000_MRQC_RSS_FIELD_IPV6)
2157                                 info->data |= RXH_IP_SRC | RXH_IP_DST;
2158                         break;
2159                 default:
2160                         break;
2161                 }
2162                 return 0;
2163         }
2164         default:
2165                 return -EOPNOTSUPP;
2166         }
2167 }
2168
2169 static int e1000e_get_eee(struct net_device *netdev, struct ethtool_eee *edata)
2170 {
2171         struct e1000_adapter *adapter = netdev_priv(netdev);
2172         struct e1000_hw *hw = &adapter->hw;
2173         u16 cap_addr, lpa_addr, pcs_stat_addr, phy_data;
2174         u32 ret_val;
2175
2176         if (!(adapter->flags2 & FLAG2_HAS_EEE))
2177                 return -EOPNOTSUPP;
2178
2179         switch (hw->phy.type) {
2180         case e1000_phy_82579:
2181                 cap_addr = I82579_EEE_CAPABILITY;
2182                 lpa_addr = I82579_EEE_LP_ABILITY;
2183                 pcs_stat_addr = I82579_EEE_PCS_STATUS;
2184                 break;
2185         case e1000_phy_i217:
2186                 cap_addr = I217_EEE_CAPABILITY;
2187                 lpa_addr = I217_EEE_LP_ABILITY;
2188                 pcs_stat_addr = I217_EEE_PCS_STATUS;
2189                 break;
2190         default:
2191                 return -EOPNOTSUPP;
2192         }
2193
2194         pm_runtime_get_sync(netdev->dev.parent);
2195
2196         ret_val = hw->phy.ops.acquire(hw);
2197         if (ret_val) {
2198                 pm_runtime_put_sync(netdev->dev.parent);
2199                 return -EBUSY;
2200         }
2201
2202         /* EEE Capability */
2203         ret_val = e1000_read_emi_reg_locked(hw, cap_addr, &phy_data);
2204         if (ret_val)
2205                 goto release;
2206         edata->supported = mmd_eee_cap_to_ethtool_sup_t(phy_data);
2207
2208         /* EEE Advertised */
2209         edata->advertised = mmd_eee_adv_to_ethtool_adv_t(adapter->eee_advert);
2210
2211         /* EEE Link Partner Advertised */
2212         ret_val = e1000_read_emi_reg_locked(hw, lpa_addr, &phy_data);
2213         if (ret_val)
2214                 goto release;
2215         edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data);
2216
2217         /* EEE PCS Status */
2218         ret_val = e1000_read_emi_reg_locked(hw, pcs_stat_addr, &phy_data);
2219         if (ret_val)
2220                 goto release;
2221         if (hw->phy.type == e1000_phy_82579)
2222                 phy_data <<= 8;
2223
2224         /* Result of the EEE auto negotiation - there is no register that
2225          * has the status of the EEE negotiation so do a best-guess based
2226          * on whether Tx or Rx LPI indications have been received.
2227          */
2228         if (phy_data & (E1000_EEE_TX_LPI_RCVD | E1000_EEE_RX_LPI_RCVD))
2229                 edata->eee_active = true;
2230
2231         edata->eee_enabled = !hw->dev_spec.ich8lan.eee_disable;
2232         edata->tx_lpi_enabled = true;
2233         edata->tx_lpi_timer = er32(LPIC) >> E1000_LPIC_LPIET_SHIFT;
2234
2235 release:
2236         hw->phy.ops.release(hw);
2237         if (ret_val)
2238                 ret_val = -ENODATA;
2239
2240         pm_runtime_put_sync(netdev->dev.parent);
2241
2242         return ret_val;
2243 }
2244
2245 static int e1000e_set_eee(struct net_device *netdev, struct ethtool_eee *edata)
2246 {
2247         struct e1000_adapter *adapter = netdev_priv(netdev);
2248         struct e1000_hw *hw = &adapter->hw;
2249         struct ethtool_eee eee_curr;
2250         s32 ret_val;
2251
2252         ret_val = e1000e_get_eee(netdev, &eee_curr);
2253         if (ret_val)
2254                 return ret_val;
2255
2256         if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) {
2257                 e_err("Setting EEE tx-lpi is not supported\n");
2258                 return -EINVAL;
2259         }
2260
2261         if (eee_curr.tx_lpi_timer != edata->tx_lpi_timer) {
2262                 e_err("Setting EEE Tx LPI timer is not supported\n");
2263                 return -EINVAL;
2264         }
2265
2266         if (edata->advertised & ~(ADVERTISE_100_FULL | ADVERTISE_1000_FULL)) {
2267                 e_err("EEE advertisement supports only 100TX and/or 1000T full-duplex\n");
2268                 return -EINVAL;
2269         }
2270
2271         adapter->eee_advert = ethtool_adv_to_mmd_eee_adv_t(edata->advertised);
2272
2273         hw->dev_spec.ich8lan.eee_disable = !edata->eee_enabled;
2274
2275         pm_runtime_get_sync(netdev->dev.parent);
2276
2277         /* reset the link */
2278         if (netif_running(netdev))
2279                 e1000e_reinit_locked(adapter);
2280         else
2281                 e1000e_reset(adapter);
2282
2283         pm_runtime_put_sync(netdev->dev.parent);
2284
2285         return 0;
2286 }
2287
2288 static int e1000e_get_ts_info(struct net_device *netdev,
2289                               struct ethtool_ts_info *info)
2290 {
2291         struct e1000_adapter *adapter = netdev_priv(netdev);
2292
2293         ethtool_op_get_ts_info(netdev, info);
2294
2295         if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
2296                 return 0;
2297
2298         info->so_timestamping |= (SOF_TIMESTAMPING_TX_HARDWARE |
2299                                   SOF_TIMESTAMPING_RX_HARDWARE |
2300                                   SOF_TIMESTAMPING_RAW_HARDWARE);
2301
2302         info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
2303
2304         info->rx_filters = (BIT(HWTSTAMP_FILTER_NONE) |
2305                             BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
2306                             BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
2307                             BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
2308                             BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
2309                             BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
2310                             BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
2311                             BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
2312                             BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
2313                             BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
2314                             BIT(HWTSTAMP_FILTER_ALL));
2315
2316         if (adapter->ptp_clock)
2317                 info->phc_index = ptp_clock_index(adapter->ptp_clock);
2318
2319         return 0;
2320 }
2321
2322 static const struct ethtool_ops e1000_ethtool_ops = {
2323         .get_drvinfo            = e1000_get_drvinfo,
2324         .get_regs_len           = e1000_get_regs_len,
2325         .get_regs               = e1000_get_regs,
2326         .get_wol                = e1000_get_wol,
2327         .set_wol                = e1000_set_wol,
2328         .get_msglevel           = e1000_get_msglevel,
2329         .set_msglevel           = e1000_set_msglevel,
2330         .nway_reset             = e1000_nway_reset,
2331         .get_link               = ethtool_op_get_link,
2332         .get_eeprom_len         = e1000_get_eeprom_len,
2333         .get_eeprom             = e1000_get_eeprom,
2334         .set_eeprom             = e1000_set_eeprom,
2335         .get_ringparam          = e1000_get_ringparam,
2336         .set_ringparam          = e1000_set_ringparam,
2337         .get_pauseparam         = e1000_get_pauseparam,
2338         .set_pauseparam         = e1000_set_pauseparam,
2339         .self_test              = e1000_diag_test,
2340         .get_strings            = e1000_get_strings,
2341         .set_phys_id            = e1000_set_phys_id,
2342         .get_ethtool_stats      = e1000_get_ethtool_stats,
2343         .get_sset_count         = e1000e_get_sset_count,
2344         .get_coalesce           = e1000_get_coalesce,
2345         .set_coalesce           = e1000_set_coalesce,
2346         .get_rxnfc              = e1000_get_rxnfc,
2347         .get_ts_info            = e1000e_get_ts_info,
2348         .get_eee                = e1000e_get_eee,
2349         .set_eee                = e1000e_set_eee,
2350         .get_link_ksettings     = e1000_get_link_ksettings,
2351         .set_link_ksettings     = e1000_set_link_ksettings,
2352 };
2353
2354 void e1000e_set_ethtool_ops(struct net_device *netdev)
2355 {
2356         netdev->ethtool_ops = &e1000_ethtool_ops;
2357 }