blob: 8a78a143e5918ebcf16cf958a68f957d85cd8a10 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allanad680762008-03-28 09:15:03 -07004 Copyright(c) 1999 - 2008 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29/* ethtool support for e1000 */
30
31#include <linux/netdevice.h>
32#include <linux/ethtool.h>
33#include <linux/pci.h>
34#include <linux/delay.h>
35
36#include "e1000.h"
37
38struct e1000_stats {
39 char stat_string[ETH_GSTRING_LEN];
40 int sizeof_stat;
41 int stat_offset;
42};
43
44#define E1000_STAT(m) sizeof(((struct e1000_adapter *)0)->m), \
45 offsetof(struct e1000_adapter, m)
Ajit Khaparde7274c202009-10-07 02:44:26 +000046#define E1000_NETDEV_STAT(m) sizeof(((struct net_device *)0)->m), \
47 offsetof(struct net_device, m)
Auke Kokbc7f75f2007-09-17 12:30:59 -070048static const struct e1000_stats e1000_gstrings_stats[] = {
49 { "rx_packets", E1000_STAT(stats.gprc) },
50 { "tx_packets", E1000_STAT(stats.gptc) },
Bruce Allan7c257692008-04-23 11:09:00 -070051 { "rx_bytes", E1000_STAT(stats.gorc) },
52 { "tx_bytes", E1000_STAT(stats.gotc) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070053 { "rx_broadcast", E1000_STAT(stats.bprc) },
54 { "tx_broadcast", E1000_STAT(stats.bptc) },
55 { "rx_multicast", E1000_STAT(stats.mprc) },
56 { "tx_multicast", E1000_STAT(stats.mptc) },
Ajit Khaparde7274c202009-10-07 02:44:26 +000057 { "rx_errors", E1000_NETDEV_STAT(stats.rx_errors) },
58 { "tx_errors", E1000_NETDEV_STAT(stats.tx_errors) },
59 { "tx_dropped", E1000_NETDEV_STAT(stats.tx_dropped) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070060 { "multicast", E1000_STAT(stats.mprc) },
61 { "collisions", E1000_STAT(stats.colc) },
Ajit Khaparde7274c202009-10-07 02:44:26 +000062 { "rx_length_errors", E1000_NETDEV_STAT(stats.rx_length_errors) },
63 { "rx_over_errors", E1000_NETDEV_STAT(stats.rx_over_errors) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070064 { "rx_crc_errors", E1000_STAT(stats.crcerrs) },
Ajit Khaparde7274c202009-10-07 02:44:26 +000065 { "rx_frame_errors", E1000_NETDEV_STAT(stats.rx_frame_errors) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070066 { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
67 { "rx_missed_errors", E1000_STAT(stats.mpc) },
68 { "tx_aborted_errors", E1000_STAT(stats.ecol) },
69 { "tx_carrier_errors", E1000_STAT(stats.tncrs) },
Ajit Khaparde7274c202009-10-07 02:44:26 +000070 { "tx_fifo_errors", E1000_NETDEV_STAT(stats.tx_fifo_errors) },
71 { "tx_heartbeat_errors", E1000_NETDEV_STAT(stats.tx_heartbeat_errors) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070072 { "tx_window_errors", E1000_STAT(stats.latecol) },
73 { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
74 { "tx_deferred_ok", E1000_STAT(stats.dc) },
75 { "tx_single_coll_ok", E1000_STAT(stats.scc) },
76 { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
77 { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
78 { "tx_restart_queue", E1000_STAT(restart_queue) },
79 { "rx_long_length_errors", E1000_STAT(stats.roc) },
80 { "rx_short_length_errors", E1000_STAT(stats.ruc) },
81 { "rx_align_errors", E1000_STAT(stats.algnerrc) },
82 { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
83 { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
84 { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
85 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
86 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
87 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
Bruce Allan7c257692008-04-23 11:09:00 -070088 { "rx_long_byte_count", E1000_STAT(stats.gorc) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070089 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
90 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
91 { "rx_header_split", E1000_STAT(rx_hdr_split) },
92 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
93 { "tx_smbus", E1000_STAT(stats.mgptc) },
94 { "rx_smbus", E1000_STAT(stats.mgprc) },
95 { "dropped_smbus", E1000_STAT(stats.mgpdc) },
96 { "rx_dma_failed", E1000_STAT(rx_dma_failed) },
97 { "tx_dma_failed", E1000_STAT(tx_dma_failed) },
98};
99
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200100#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700101#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
102static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
103 "Register test (offline)", "Eeprom test (offline)",
104 "Interrupt test (offline)", "Loopback test (offline)",
105 "Link test (on/offline)"
106};
Bruce Allanad680762008-03-28 09:15:03 -0700107#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700108
109static int e1000_get_settings(struct net_device *netdev,
110 struct ethtool_cmd *ecmd)
111{
112 struct e1000_adapter *adapter = netdev_priv(netdev);
113 struct e1000_hw *hw = &adapter->hw;
Auke Kok369d7422007-10-15 14:30:59 -0700114 u32 status;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700115
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700116 if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700117
118 ecmd->supported = (SUPPORTED_10baseT_Half |
119 SUPPORTED_10baseT_Full |
120 SUPPORTED_100baseT_Half |
121 SUPPORTED_100baseT_Full |
122 SUPPORTED_1000baseT_Full |
123 SUPPORTED_Autoneg |
124 SUPPORTED_TP);
125 if (hw->phy.type == e1000_phy_ife)
126 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
127 ecmd->advertising = ADVERTISED_TP;
128
129 if (hw->mac.autoneg == 1) {
130 ecmd->advertising |= ADVERTISED_Autoneg;
131 /* the e1000 autoneg seems to match ethtool nicely */
132 ecmd->advertising |= hw->phy.autoneg_advertised;
133 }
134
135 ecmd->port = PORT_TP;
136 ecmd->phy_address = hw->phy.addr;
137 ecmd->transceiver = XCVR_INTERNAL;
138
139 } else {
140 ecmd->supported = (SUPPORTED_1000baseT_Full |
141 SUPPORTED_FIBRE |
142 SUPPORTED_Autoneg);
143
144 ecmd->advertising = (ADVERTISED_1000baseT_Full |
145 ADVERTISED_FIBRE |
146 ADVERTISED_Autoneg);
147
148 ecmd->port = PORT_FIBRE;
149 ecmd->transceiver = XCVR_EXTERNAL;
150 }
151
Auke Kok369d7422007-10-15 14:30:59 -0700152 status = er32(STATUS);
153 if (status & E1000_STATUS_LU) {
154 if (status & E1000_STATUS_SPEED_1000)
155 ecmd->speed = 1000;
156 else if (status & E1000_STATUS_SPEED_100)
157 ecmd->speed = 100;
158 else
159 ecmd->speed = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700160
Auke Kok369d7422007-10-15 14:30:59 -0700161 if (status & E1000_STATUS_FD)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700162 ecmd->duplex = DUPLEX_FULL;
163 else
164 ecmd->duplex = DUPLEX_HALF;
165 } else {
166 ecmd->speed = -1;
167 ecmd->duplex = -1;
168 }
169
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700170 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -0700171 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000172
173 /* MDI-X => 2; MDI =>1; Invalid =>0 */
174 if ((hw->phy.media_type == e1000_media_type_copper) &&
175 !hw->mac.get_link_status)
176 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
177 ETH_TP_MDI;
178 else
179 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
180
Auke Kokbc7f75f2007-09-17 12:30:59 -0700181 return 0;
182}
183
Auke Kok369d7422007-10-15 14:30:59 -0700184static u32 e1000_get_link(struct net_device *netdev)
185{
186 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allana20e4cf2008-11-21 17:01:35 -0800187
188 return e1000_has_link(adapter);
Auke Kok369d7422007-10-15 14:30:59 -0700189}
190
Auke Kokbc7f75f2007-09-17 12:30:59 -0700191static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
192{
193 struct e1000_mac_info *mac = &adapter->hw.mac;
194
195 mac->autoneg = 0;
196
197 /* Fiber NICs only allow 1000 gbps Full duplex */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700198 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -0700199 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700200 e_err("Unsupported Speed/Duplex configuration\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700201 return -EINVAL;
202 }
203
204 switch (spddplx) {
205 case SPEED_10 + DUPLEX_HALF:
206 mac->forced_speed_duplex = ADVERTISE_10_HALF;
207 break;
208 case SPEED_10 + DUPLEX_FULL:
209 mac->forced_speed_duplex = ADVERTISE_10_FULL;
210 break;
211 case SPEED_100 + DUPLEX_HALF:
212 mac->forced_speed_duplex = ADVERTISE_100_HALF;
213 break;
214 case SPEED_100 + DUPLEX_FULL:
215 mac->forced_speed_duplex = ADVERTISE_100_FULL;
216 break;
217 case SPEED_1000 + DUPLEX_FULL:
218 mac->autoneg = 1;
219 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
220 break;
221 case SPEED_1000 + DUPLEX_HALF: /* not supported */
222 default:
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700223 e_err("Unsupported Speed/Duplex configuration\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700224 return -EINVAL;
225 }
226 return 0;
227}
228
229static int e1000_set_settings(struct net_device *netdev,
230 struct ethtool_cmd *ecmd)
231{
232 struct e1000_adapter *adapter = netdev_priv(netdev);
233 struct e1000_hw *hw = &adapter->hw;
234
Bruce Allanad680762008-03-28 09:15:03 -0700235 /*
236 * When SoL/IDER sessions are active, autoneg/speed/duplex
237 * cannot be changed
238 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700239 if (e1000_check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700240 e_err("Cannot change link characteristics when SoL/IDER is "
241 "active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700242 return -EINVAL;
243 }
244
245 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
246 msleep(1);
247
248 if (ecmd->autoneg == AUTONEG_ENABLE) {
249 hw->mac.autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700250 if (hw->phy.media_type == e1000_media_type_fiber)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700251 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
252 ADVERTISED_FIBRE |
253 ADVERTISED_Autoneg;
254 else
255 hw->phy.autoneg_advertised = ecmd->advertising |
256 ADVERTISED_TP |
257 ADVERTISED_Autoneg;
258 ecmd->advertising = hw->phy.autoneg_advertised;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700259 if (adapter->fc_autoneg)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800260 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700261 } else {
262 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
263 clear_bit(__E1000_RESETTING, &adapter->state);
264 return -EINVAL;
265 }
266 }
267
268 /* reset the link */
269
270 if (netif_running(adapter->netdev)) {
271 e1000e_down(adapter);
272 e1000e_up(adapter);
273 } else {
274 e1000e_reset(adapter);
275 }
276
277 clear_bit(__E1000_RESETTING, &adapter->state);
278 return 0;
279}
280
281static void e1000_get_pauseparam(struct net_device *netdev,
282 struct ethtool_pauseparam *pause)
283{
284 struct e1000_adapter *adapter = netdev_priv(netdev);
285 struct e1000_hw *hw = &adapter->hw;
286
287 pause->autoneg =
288 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
289
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800290 if (hw->fc.current_mode == e1000_fc_rx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700291 pause->rx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800292 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700293 pause->tx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800294 } else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700295 pause->rx_pause = 1;
296 pause->tx_pause = 1;
297 }
298}
299
300static int e1000_set_pauseparam(struct net_device *netdev,
301 struct ethtool_pauseparam *pause)
302{
303 struct e1000_adapter *adapter = netdev_priv(netdev);
304 struct e1000_hw *hw = &adapter->hw;
305 int retval = 0;
306
307 adapter->fc_autoneg = pause->autoneg;
308
309 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
310 msleep(1);
311
Auke Kokbc7f75f2007-09-17 12:30:59 -0700312 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800313 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700314 if (netif_running(adapter->netdev)) {
315 e1000e_down(adapter);
316 e1000e_up(adapter);
317 } else {
318 e1000e_reset(adapter);
319 }
320 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800321 if (pause->rx_pause && pause->tx_pause)
322 hw->fc.requested_mode = e1000_fc_full;
323 else if (pause->rx_pause && !pause->tx_pause)
324 hw->fc.requested_mode = e1000_fc_rx_pause;
325 else if (!pause->rx_pause && pause->tx_pause)
326 hw->fc.requested_mode = e1000_fc_tx_pause;
327 else if (!pause->rx_pause && !pause->tx_pause)
328 hw->fc.requested_mode = e1000_fc_none;
329
330 hw->fc.current_mode = hw->fc.requested_mode;
331
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700332 retval = ((hw->phy.media_type == e1000_media_type_fiber) ?
Auke Kokbc7f75f2007-09-17 12:30:59 -0700333 hw->mac.ops.setup_link(hw) : e1000e_force_mac_fc(hw));
334 }
335
336 clear_bit(__E1000_RESETTING, &adapter->state);
337 return retval;
338}
339
340static u32 e1000_get_rx_csum(struct net_device *netdev)
341{
342 struct e1000_adapter *adapter = netdev_priv(netdev);
343 return (adapter->flags & FLAG_RX_CSUM_ENABLED);
344}
345
346static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
347{
348 struct e1000_adapter *adapter = netdev_priv(netdev);
349
350 if (data)
351 adapter->flags |= FLAG_RX_CSUM_ENABLED;
352 else
353 adapter->flags &= ~FLAG_RX_CSUM_ENABLED;
354
355 if (netif_running(netdev))
356 e1000e_reinit_locked(adapter);
357 else
358 e1000e_reset(adapter);
359 return 0;
360}
361
362static u32 e1000_get_tx_csum(struct net_device *netdev)
363{
364 return ((netdev->features & NETIF_F_HW_CSUM) != 0);
365}
366
367static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
368{
369 if (data)
370 netdev->features |= NETIF_F_HW_CSUM;
371 else
372 netdev->features &= ~NETIF_F_HW_CSUM;
373
374 return 0;
375}
376
377static int e1000_set_tso(struct net_device *netdev, u32 data)
378{
379 struct e1000_adapter *adapter = netdev_priv(netdev);
380
381 if (data) {
382 netdev->features |= NETIF_F_TSO;
383 netdev->features |= NETIF_F_TSO6;
384 } else {
385 netdev->features &= ~NETIF_F_TSO;
386 netdev->features &= ~NETIF_F_TSO6;
387 }
388
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700389 e_info("TSO is %s\n", data ? "Enabled" : "Disabled");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700390 adapter->flags |= FLAG_TSO_FORCE;
391 return 0;
392}
393
394static u32 e1000_get_msglevel(struct net_device *netdev)
395{
396 struct e1000_adapter *adapter = netdev_priv(netdev);
397 return adapter->msg_enable;
398}
399
400static void e1000_set_msglevel(struct net_device *netdev, u32 data)
401{
402 struct e1000_adapter *adapter = netdev_priv(netdev);
403 adapter->msg_enable = data;
404}
405
406static int e1000_get_regs_len(struct net_device *netdev)
407{
408#define E1000_REGS_LEN 32 /* overestimate */
409 return E1000_REGS_LEN * sizeof(u32);
410}
411
412static void e1000_get_regs(struct net_device *netdev,
413 struct ethtool_regs *regs, void *p)
414{
415 struct e1000_adapter *adapter = netdev_priv(netdev);
416 struct e1000_hw *hw = &adapter->hw;
417 u32 *regs_buff = p;
418 u16 phy_data;
419 u8 revision_id;
420
421 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
422
423 pci_read_config_byte(adapter->pdev, PCI_REVISION_ID, &revision_id);
424
425 regs->version = (1 << 24) | (revision_id << 16) | adapter->pdev->device;
426
427 regs_buff[0] = er32(CTRL);
428 regs_buff[1] = er32(STATUS);
429
430 regs_buff[2] = er32(RCTL);
431 regs_buff[3] = er32(RDLEN);
432 regs_buff[4] = er32(RDH);
433 regs_buff[5] = er32(RDT);
434 regs_buff[6] = er32(RDTR);
435
436 regs_buff[7] = er32(TCTL);
437 regs_buff[8] = er32(TDLEN);
438 regs_buff[9] = er32(TDH);
439 regs_buff[10] = er32(TDT);
440 regs_buff[11] = er32(TIDV);
441
442 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700443
444 /* ethtool doesn't use anything past this point, so all this
445 * code is likely legacy junk for apps that may or may not
446 * exist */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700447 if (hw->phy.type == e1000_phy_m88) {
448 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
449 regs_buff[13] = (u32)phy_data; /* cable length */
450 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
451 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
452 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
453 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
454 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
455 regs_buff[18] = regs_buff[13]; /* cable polarity */
456 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
457 regs_buff[20] = regs_buff[17]; /* polarity correction */
458 /* phy receive errors */
459 regs_buff[22] = adapter->phy_stats.receive_errors;
460 regs_buff[23] = regs_buff[13]; /* mdix mode */
461 }
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700462 regs_buff[21] = 0; /* was idle_errors */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700463 e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
464 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
465 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
466}
467
468static int e1000_get_eeprom_len(struct net_device *netdev)
469{
470 struct e1000_adapter *adapter = netdev_priv(netdev);
471 return adapter->hw.nvm.word_size * 2;
472}
473
474static int e1000_get_eeprom(struct net_device *netdev,
475 struct ethtool_eeprom *eeprom, u8 *bytes)
476{
477 struct e1000_adapter *adapter = netdev_priv(netdev);
478 struct e1000_hw *hw = &adapter->hw;
479 u16 *eeprom_buff;
480 int first_word;
481 int last_word;
482 int ret_val = 0;
483 u16 i;
484
485 if (eeprom->len == 0)
486 return -EINVAL;
487
488 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
489
490 first_word = eeprom->offset >> 1;
491 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
492
493 eeprom_buff = kmalloc(sizeof(u16) *
494 (last_word - first_word + 1), GFP_KERNEL);
495 if (!eeprom_buff)
496 return -ENOMEM;
497
498 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
499 ret_val = e1000_read_nvm(hw, first_word,
500 last_word - first_word + 1,
501 eeprom_buff);
502 } else {
503 for (i = 0; i < last_word - first_word + 1; i++) {
504 ret_val = e1000_read_nvm(hw, first_word + i, 1,
505 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800506 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700507 break;
508 }
509 }
510
Bruce Allane2434552008-11-21 17:02:41 -0800511 if (ret_val) {
512 /* a read error occurred, throw away the result */
513 memset(eeprom_buff, 0xff, sizeof(eeprom_buff));
514 } else {
515 /* Device's eeprom is always little-endian, word addressable */
516 for (i = 0; i < last_word - first_word + 1; i++)
517 le16_to_cpus(&eeprom_buff[i]);
518 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700519
520 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
521 kfree(eeprom_buff);
522
523 return ret_val;
524}
525
526static int e1000_set_eeprom(struct net_device *netdev,
527 struct ethtool_eeprom *eeprom, u8 *bytes)
528{
529 struct e1000_adapter *adapter = netdev_priv(netdev);
530 struct e1000_hw *hw = &adapter->hw;
531 u16 *eeprom_buff;
532 void *ptr;
533 int max_len;
534 int first_word;
535 int last_word;
536 int ret_val = 0;
537 u16 i;
538
539 if (eeprom->len == 0)
540 return -EOPNOTSUPP;
541
542 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
543 return -EFAULT;
544
Bruce Allan4a770352008-10-01 17:18:35 -0700545 if (adapter->flags & FLAG_READ_ONLY_NVM)
546 return -EINVAL;
547
Auke Kokbc7f75f2007-09-17 12:30:59 -0700548 max_len = hw->nvm.word_size * 2;
549
550 first_word = eeprom->offset >> 1;
551 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
552 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
553 if (!eeprom_buff)
554 return -ENOMEM;
555
556 ptr = (void *)eeprom_buff;
557
558 if (eeprom->offset & 1) {
559 /* need read/modify/write of first changed EEPROM word */
560 /* only the second byte of the word is being modified */
561 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
562 ptr++;
563 }
564 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0))
565 /* need read/modify/write of last changed EEPROM word */
566 /* only the first byte of the word is being modified */
567 ret_val = e1000_read_nvm(hw, last_word, 1,
568 &eeprom_buff[last_word - first_word]);
569
Bruce Allane2434552008-11-21 17:02:41 -0800570 if (ret_val)
571 goto out;
572
Auke Kokbc7f75f2007-09-17 12:30:59 -0700573 /* Device's eeprom is always little-endian, word addressable */
574 for (i = 0; i < last_word - first_word + 1; i++)
575 le16_to_cpus(&eeprom_buff[i]);
576
577 memcpy(ptr, bytes, eeprom->len);
578
579 for (i = 0; i < last_word - first_word + 1; i++)
580 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
581
582 ret_val = e1000_write_nvm(hw, first_word,
583 last_word - first_word + 1, eeprom_buff);
584
Bruce Allane2434552008-11-21 17:02:41 -0800585 if (ret_val)
586 goto out;
587
Bruce Allanad680762008-03-28 09:15:03 -0700588 /*
589 * Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800590 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700591 */
Bruce Allane2434552008-11-21 17:02:41 -0800592 if ((first_word <= NVM_CHECKSUM_REG) ||
593 (hw->mac.type == e1000_82574) || (hw->mac.type == e1000_82573))
594 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700595
Bruce Allane2434552008-11-21 17:02:41 -0800596out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700597 kfree(eeprom_buff);
598 return ret_val;
599}
600
601static void e1000_get_drvinfo(struct net_device *netdev,
602 struct ethtool_drvinfo *drvinfo)
603{
604 struct e1000_adapter *adapter = netdev_priv(netdev);
605 char firmware_version[32];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700606
607 strncpy(drvinfo->driver, e1000e_driver_name, 32);
608 strncpy(drvinfo->version, e1000e_driver_version, 32);
609
Bruce Allanad680762008-03-28 09:15:03 -0700610 /*
611 * EEPROM image version # is reported as firmware version # for
612 * PCI-E controllers
613 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700614 sprintf(firmware_version, "%d.%d-%d",
Bruce Allan84527592008-11-21 17:00:22 -0800615 (adapter->eeprom_vers & 0xF000) >> 12,
616 (adapter->eeprom_vers & 0x0FF0) >> 4,
617 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700618
619 strncpy(drvinfo->fw_version, firmware_version, 32);
620 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700621 drvinfo->regdump_len = e1000_get_regs_len(netdev);
622 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
623}
624
625static void e1000_get_ringparam(struct net_device *netdev,
626 struct ethtool_ringparam *ring)
627{
628 struct e1000_adapter *adapter = netdev_priv(netdev);
629 struct e1000_ring *tx_ring = adapter->tx_ring;
630 struct e1000_ring *rx_ring = adapter->rx_ring;
631
632 ring->rx_max_pending = E1000_MAX_RXD;
633 ring->tx_max_pending = E1000_MAX_TXD;
634 ring->rx_mini_max_pending = 0;
635 ring->rx_jumbo_max_pending = 0;
636 ring->rx_pending = rx_ring->count;
637 ring->tx_pending = tx_ring->count;
638 ring->rx_mini_pending = 0;
639 ring->rx_jumbo_pending = 0;
640}
641
642static int e1000_set_ringparam(struct net_device *netdev,
643 struct ethtool_ringparam *ring)
644{
645 struct e1000_adapter *adapter = netdev_priv(netdev);
646 struct e1000_ring *tx_ring, *tx_old;
647 struct e1000_ring *rx_ring, *rx_old;
648 int err;
649
650 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
651 return -EINVAL;
652
653 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
654 msleep(1);
655
656 if (netif_running(adapter->netdev))
657 e1000e_down(adapter);
658
659 tx_old = adapter->tx_ring;
660 rx_old = adapter->rx_ring;
661
662 err = -ENOMEM;
663 tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
664 if (!tx_ring)
665 goto err_alloc_tx;
Bruce Allancef8c792008-04-02 13:48:23 -0700666 /*
667 * use a memcpy to save any previously configured
668 * items like napi structs from having to be
669 * reinitialized
670 */
671 memcpy(tx_ring, tx_old, sizeof(struct e1000_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700672
673 rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
674 if (!rx_ring)
675 goto err_alloc_rx;
Bruce Allancef8c792008-04-02 13:48:23 -0700676 memcpy(rx_ring, rx_old, sizeof(struct e1000_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700677
678 adapter->tx_ring = tx_ring;
679 adapter->rx_ring = rx_ring;
680
681 rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
682 rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD));
683 rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
684
685 tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
686 tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
687 tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
688
689 if (netif_running(adapter->netdev)) {
690 /* Try to get new resources before deleting old */
691 err = e1000e_setup_rx_resources(adapter);
692 if (err)
693 goto err_setup_rx;
694 err = e1000e_setup_tx_resources(adapter);
695 if (err)
696 goto err_setup_tx;
697
Bruce Allanad680762008-03-28 09:15:03 -0700698 /*
699 * restore the old in order to free it,
700 * then add in the new
701 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700702 adapter->rx_ring = rx_old;
703 adapter->tx_ring = tx_old;
704 e1000e_free_rx_resources(adapter);
705 e1000e_free_tx_resources(adapter);
706 kfree(tx_old);
707 kfree(rx_old);
708 adapter->rx_ring = rx_ring;
709 adapter->tx_ring = tx_ring;
710 err = e1000e_up(adapter);
711 if (err)
712 goto err_setup;
713 }
714
715 clear_bit(__E1000_RESETTING, &adapter->state);
716 return 0;
717err_setup_tx:
718 e1000e_free_rx_resources(adapter);
719err_setup_rx:
720 adapter->rx_ring = rx_old;
721 adapter->tx_ring = tx_old;
722 kfree(rx_ring);
723err_alloc_rx:
724 kfree(tx_ring);
725err_alloc_tx:
726 e1000e_up(adapter);
727err_setup:
728 clear_bit(__E1000_RESETTING, &adapter->state);
729 return err;
730}
731
Bruce Allancef8c792008-04-02 13:48:23 -0700732static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
733 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800734{
Bruce Allancef8c792008-04-02 13:48:23 -0700735 u32 pat, val;
Joe Perches2a887192007-11-13 20:53:51 -0800736 static const u32 test[] =
737 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Bruce Allancef8c792008-04-02 13:48:23 -0700738 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800739 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700740 (test[pat] & write));
741 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
742 if (val != (test[pat] & write & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700743 e_err("pattern test reg %04X failed: got 0x%08X "
744 "expected 0x%08X\n", reg + offset, val,
745 (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800746 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700747 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800748 }
749 }
Bruce Allancef8c792008-04-02 13:48:23 -0700750 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700751}
752
Joe Perches2a887192007-11-13 20:53:51 -0800753static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
754 int reg, u32 mask, u32 write)
755{
Bruce Allancef8c792008-04-02 13:48:23 -0700756 u32 val;
Joe Perches2a887192007-11-13 20:53:51 -0800757 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700758 val = __er32(&adapter->hw, reg);
759 if ((write & mask) != (val & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700760 e_err("set/check reg %04X test failed: got 0x%08X "
761 "expected 0x%08X\n", reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800762 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700763 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800764 }
Bruce Allancef8c792008-04-02 13:48:23 -0700765 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700766}
Bruce Allancef8c792008-04-02 13:48:23 -0700767#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
768 do { \
769 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
770 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800771 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700772#define REG_PATTERN_TEST(reg, mask, write) \
773 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800774
Bruce Allancef8c792008-04-02 13:48:23 -0700775#define REG_SET_AND_CHECK(reg, mask, write) \
776 do { \
777 if (reg_set_and_check(adapter, data, reg, mask, write)) \
778 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800779 } while (0)
780
Auke Kokbc7f75f2007-09-17 12:30:59 -0700781static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
782{
783 struct e1000_hw *hw = &adapter->hw;
784 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700785 u32 value;
786 u32 before;
787 u32 after;
788 u32 i;
789 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000790 u32 mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700791
Bruce Allanad680762008-03-28 09:15:03 -0700792 /*
793 * The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700794 * Some bits that get toggled are ignored.
795 */
796 switch (mac->type) {
797 /* there are several bits on newer hardware that are r/w */
798 case e1000_82571:
799 case e1000_82572:
800 case e1000_80003es2lan:
801 toggle = 0x7FFFF3FF;
802 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000803 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700804 toggle = 0x7FFFF033;
805 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700806 }
807
808 before = er32(STATUS);
809 value = (er32(STATUS) & toggle);
810 ew32(STATUS, toggle);
811 after = er32(STATUS) & toggle;
812 if (value != after) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700813 e_err("failed STATUS register test got: 0x%08X expected: "
814 "0x%08X\n", after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700815 *data = 1;
816 return 1;
817 }
818 /* restore previous status */
819 ew32(STATUS, before);
820
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700821 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700822 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
823 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
824 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
825 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
826 }
827
828 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
829 REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
830 REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF);
831 REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF);
832 REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF);
833 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
834 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
835 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
836 REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
837 REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF);
838
839 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
840
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700841 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700842 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
843 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
844
Auke Kok86582512007-10-04 15:00:08 -0700845 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
846 REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700847 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700848 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
849 REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
850 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000851 mask = 0x8003FFFF;
852 switch (mac->type) {
853 case e1000_ich10lan:
854 case e1000_pchlan:
855 mask |= (1 << 18);
856 break;
857 default:
858 break;
859 }
Auke Kok86582512007-10-04 15:00:08 -0700860 for (i = 0; i < mac->rar_entry_count; i++)
861 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
Bruce Allana4f58f52009-06-02 11:29:18 +0000862 mask, 0xFFFFFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700863
864 for (i = 0; i < mac->mta_reg_count; i++)
865 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
866
867 *data = 0;
868 return 0;
869}
870
871static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
872{
873 u16 temp;
874 u16 checksum = 0;
875 u16 i;
876
877 *data = 0;
878 /* Read and add up the contents of the EEPROM */
879 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
880 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
881 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800882 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700883 }
884 checksum += temp;
885 }
886
887 /* If Checksum is not Correct return error else test passed */
888 if ((checksum != (u16) NVM_SUM) && !(*data))
889 *data = 2;
890
891 return *data;
892}
893
894static irqreturn_t e1000_test_intr(int irq, void *data)
895{
896 struct net_device *netdev = (struct net_device *) data;
897 struct e1000_adapter *adapter = netdev_priv(netdev);
898 struct e1000_hw *hw = &adapter->hw;
899
900 adapter->test_icr |= er32(ICR);
901
902 return IRQ_HANDLED;
903}
904
905static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
906{
907 struct net_device *netdev = adapter->netdev;
908 struct e1000_hw *hw = &adapter->hw;
909 u32 mask;
910 u32 shared_int = 1;
911 u32 irq = adapter->pdev->irq;
912 int i;
Bruce Allan4662e822008-08-26 18:37:06 -0700913 int ret_val = 0;
914 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700915
916 *data = 0;
917
Bruce Allan4662e822008-08-26 18:37:06 -0700918 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
919 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
920 int_mode = adapter->int_mode;
921 e1000e_reset_interrupt_capability(adapter);
922 adapter->int_mode = E1000E_INT_MODE_LEGACY;
923 e1000e_set_interrupt_capability(adapter);
924 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700925 /* Hook up test interrupt handler just for this test */
926 if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
927 netdev)) {
928 shared_int = 0;
929 } else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED,
930 netdev->name, netdev)) {
931 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700932 ret_val = -1;
933 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700934 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700935 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700936
937 /* Disable all the interrupts */
938 ew32(IMC, 0xFFFFFFFF);
939 msleep(10);
940
941 /* Test each interrupt */
942 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700943 /* Interrupt to test */
944 mask = 1 << i;
945
Bruce Allanf4187b52008-08-26 18:36:50 -0700946 if (adapter->flags & FLAG_IS_ICH) {
947 switch (mask) {
948 case E1000_ICR_RXSEQ:
949 continue;
950 case 0x00000100:
951 if (adapter->hw.mac.type == e1000_ich8lan ||
952 adapter->hw.mac.type == e1000_ich9lan)
953 continue;
954 break;
955 default:
956 break;
957 }
958 }
959
Auke Kokbc7f75f2007-09-17 12:30:59 -0700960 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700961 /*
962 * Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700963 * the cause register and then force the same
964 * interrupt and see if one gets posted. If
965 * an interrupt was posted to the bus, the
966 * test failed.
967 */
968 adapter->test_icr = 0;
969 ew32(IMC, mask);
970 ew32(ICS, mask);
971 msleep(10);
972
973 if (adapter->test_icr & mask) {
974 *data = 3;
975 break;
976 }
977 }
978
Bruce Allanad680762008-03-28 09:15:03 -0700979 /*
980 * Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700981 * the cause register and then force the same
982 * interrupt and see if one gets posted. If
983 * an interrupt was not posted to the bus, the
984 * test failed.
985 */
986 adapter->test_icr = 0;
987 ew32(IMS, mask);
988 ew32(ICS, mask);
989 msleep(10);
990
991 if (!(adapter->test_icr & mask)) {
992 *data = 4;
993 break;
994 }
995
996 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700997 /*
998 * Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700999 * the cause register and then force the other
1000 * interrupts and see if any get posted. If
1001 * an interrupt was posted to the bus, the
1002 * test failed.
1003 */
1004 adapter->test_icr = 0;
1005 ew32(IMC, ~mask & 0x00007FFF);
1006 ew32(ICS, ~mask & 0x00007FFF);
1007 msleep(10);
1008
1009 if (adapter->test_icr) {
1010 *data = 5;
1011 break;
1012 }
1013 }
1014 }
1015
1016 /* Disable all the interrupts */
1017 ew32(IMC, 0xFFFFFFFF);
1018 msleep(10);
1019
1020 /* Unhook test interrupt handler */
1021 free_irq(irq, netdev);
1022
Bruce Allan4662e822008-08-26 18:37:06 -07001023out:
1024 if (int_mode == E1000E_INT_MODE_MSIX) {
1025 e1000e_reset_interrupt_capability(adapter);
1026 adapter->int_mode = int_mode;
1027 e1000e_set_interrupt_capability(adapter);
1028 }
1029
1030 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001031}
1032
1033static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1034{
1035 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1036 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1037 struct pci_dev *pdev = adapter->pdev;
1038 int i;
1039
1040 if (tx_ring->desc && tx_ring->buffer_info) {
1041 for (i = 0; i < tx_ring->count; i++) {
1042 if (tx_ring->buffer_info[i].dma)
1043 pci_unmap_single(pdev,
1044 tx_ring->buffer_info[i].dma,
1045 tx_ring->buffer_info[i].length,
1046 PCI_DMA_TODEVICE);
1047 if (tx_ring->buffer_info[i].skb)
1048 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1049 }
1050 }
1051
1052 if (rx_ring->desc && rx_ring->buffer_info) {
1053 for (i = 0; i < rx_ring->count; i++) {
1054 if (rx_ring->buffer_info[i].dma)
1055 pci_unmap_single(pdev,
1056 rx_ring->buffer_info[i].dma,
1057 2048, PCI_DMA_FROMDEVICE);
1058 if (rx_ring->buffer_info[i].skb)
1059 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1060 }
1061 }
1062
1063 if (tx_ring->desc) {
1064 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1065 tx_ring->dma);
1066 tx_ring->desc = NULL;
1067 }
1068 if (rx_ring->desc) {
1069 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1070 rx_ring->dma);
1071 rx_ring->desc = NULL;
1072 }
1073
1074 kfree(tx_ring->buffer_info);
1075 tx_ring->buffer_info = NULL;
1076 kfree(rx_ring->buffer_info);
1077 rx_ring->buffer_info = NULL;
1078}
1079
1080static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1081{
1082 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1083 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1084 struct pci_dev *pdev = adapter->pdev;
1085 struct e1000_hw *hw = &adapter->hw;
1086 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001087 int i;
1088 int ret_val;
1089
1090 /* Setup Tx descriptor ring and Tx buffers */
1091
1092 if (!tx_ring->count)
1093 tx_ring->count = E1000_DEFAULT_TXD;
1094
Bruce Allancef8c792008-04-02 13:48:23 -07001095 tx_ring->buffer_info = kcalloc(tx_ring->count,
1096 sizeof(struct e1000_buffer),
1097 GFP_KERNEL);
1098 if (!(tx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001099 ret_val = 1;
1100 goto err_nomem;
1101 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001102
1103 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1104 tx_ring->size = ALIGN(tx_ring->size, 4096);
1105 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1106 &tx_ring->dma, GFP_KERNEL);
1107 if (!tx_ring->desc) {
1108 ret_val = 2;
1109 goto err_nomem;
1110 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001111 tx_ring->next_to_use = 0;
1112 tx_ring->next_to_clean = 0;
1113
Bruce Allancef8c792008-04-02 13:48:23 -07001114 ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001115 ew32(TDBAH, ((u64) tx_ring->dma >> 32));
Bruce Allancef8c792008-04-02 13:48:23 -07001116 ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001117 ew32(TDH, 0);
1118 ew32(TDT, 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001119 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1120 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1121 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001122
1123 for (i = 0; i < tx_ring->count; i++) {
1124 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1125 struct sk_buff *skb;
1126 unsigned int skb_size = 1024;
1127
1128 skb = alloc_skb(skb_size, GFP_KERNEL);
1129 if (!skb) {
1130 ret_val = 3;
1131 goto err_nomem;
1132 }
1133 skb_put(skb, skb_size);
1134 tx_ring->buffer_info[i].skb = skb;
1135 tx_ring->buffer_info[i].length = skb->len;
1136 tx_ring->buffer_info[i].dma =
1137 pci_map_single(pdev, skb->data, skb->len,
1138 PCI_DMA_TODEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001139 if (pci_dma_mapping_error(pdev, tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001140 ret_val = 4;
1141 goto err_nomem;
1142 }
Bruce Allancef8c792008-04-02 13:48:23 -07001143 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001144 tx_desc->lower.data = cpu_to_le32(skb->len);
1145 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1146 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001147 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001148 tx_desc->upper.data = 0;
1149 }
1150
1151 /* Setup Rx descriptor ring and Rx buffers */
1152
1153 if (!rx_ring->count)
1154 rx_ring->count = E1000_DEFAULT_RXD;
1155
Bruce Allancef8c792008-04-02 13:48:23 -07001156 rx_ring->buffer_info = kcalloc(rx_ring->count,
1157 sizeof(struct e1000_buffer),
1158 GFP_KERNEL);
1159 if (!(rx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001160 ret_val = 5;
1161 goto err_nomem;
1162 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001163
1164 rx_ring->size = rx_ring->count * sizeof(struct e1000_rx_desc);
1165 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1166 &rx_ring->dma, GFP_KERNEL);
1167 if (!rx_ring->desc) {
1168 ret_val = 6;
1169 goto err_nomem;
1170 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001171 rx_ring->next_to_use = 0;
1172 rx_ring->next_to_clean = 0;
1173
1174 rctl = er32(RCTL);
1175 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1176 ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
1177 ew32(RDBAH, ((u64) rx_ring->dma >> 32));
1178 ew32(RDLEN, rx_ring->size);
1179 ew32(RDH, 0);
1180 ew32(RDT, 0);
1181 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allancef8c792008-04-02 13:48:23 -07001182 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1183 E1000_RCTL_SBP | E1000_RCTL_SECRC |
Auke Kokbc7f75f2007-09-17 12:30:59 -07001184 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1185 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1186 ew32(RCTL, rctl);
1187
1188 for (i = 0; i < rx_ring->count; i++) {
1189 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
1190 struct sk_buff *skb;
1191
1192 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1193 if (!skb) {
1194 ret_val = 7;
1195 goto err_nomem;
1196 }
1197 skb_reserve(skb, NET_IP_ALIGN);
1198 rx_ring->buffer_info[i].skb = skb;
1199 rx_ring->buffer_info[i].dma =
1200 pci_map_single(pdev, skb->data, 2048,
1201 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001202 if (pci_dma_mapping_error(pdev, rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001203 ret_val = 8;
1204 goto err_nomem;
1205 }
1206 rx_desc->buffer_addr =
1207 cpu_to_le64(rx_ring->buffer_info[i].dma);
1208 memset(skb->data, 0x00, skb->len);
1209 }
1210
1211 return 0;
1212
1213err_nomem:
1214 e1000_free_desc_rings(adapter);
1215 return ret_val;
1216}
1217
1218static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1219{
1220 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1221 e1e_wphy(&adapter->hw, 29, 0x001F);
1222 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1223 e1e_wphy(&adapter->hw, 29, 0x001A);
1224 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1225}
1226
1227static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1228{
1229 struct e1000_hw *hw = &adapter->hw;
1230 u32 ctrl_reg = 0;
1231 u32 stat_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001232 u16 phy_reg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001233
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001234 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001235
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001236 if (hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001237 /* Auto-MDI/MDIX Off */
1238 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1239 /* reset to update Auto-MDI/MDIX */
1240 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1241 /* autoneg off */
1242 e1e_wphy(hw, PHY_CONTROL, 0x8140);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001243 } else if (hw->phy.type == e1000_phy_gg82563)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001244 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
1245
1246 ctrl_reg = er32(CTRL);
1247
Bruce Allancef8c792008-04-02 13:48:23 -07001248 switch (hw->phy.type) {
1249 case e1000_phy_ife:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001250 /* force 100, set loopback */
1251 e1e_wphy(hw, PHY_CONTROL, 0x6100);
1252
1253 /* Now set up the MAC to the same speed/duplex as the PHY. */
1254 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1255 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1256 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1257 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1258 E1000_CTRL_FD); /* Force Duplex to FULL */
Bruce Allancef8c792008-04-02 13:48:23 -07001259 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001260 case e1000_phy_bm:
1261 /* Set Default MAC Interface speed to 1GB */
1262 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1263 phy_reg &= ~0x0007;
1264 phy_reg |= 0x006;
1265 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1266 /* Assert SW reset for above settings to take effect */
1267 e1000e_commit_phy(hw);
1268 mdelay(1);
1269 /* Force Full Duplex */
1270 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1271 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1272 /* Set Link Up (in force link) */
1273 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1274 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1275 /* Force Link */
1276 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1277 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1278 /* Set Early Link Enable */
1279 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1280 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
1281 /* fall through */
Bruce Allancef8c792008-04-02 13:48:23 -07001282 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001283 /* force 1000, set loopback */
1284 e1e_wphy(hw, PHY_CONTROL, 0x4140);
Bruce Allancef8c792008-04-02 13:48:23 -07001285 mdelay(250);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001286
1287 /* Now set up the MAC to the same speed/duplex as the PHY. */
1288 ctrl_reg = er32(CTRL);
1289 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1290 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1291 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1292 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1293 E1000_CTRL_FD); /* Force Duplex to FULL */
Bruce Allancef8c792008-04-02 13:48:23 -07001294
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001295 if (adapter->flags & FLAG_IS_ICH)
Bruce Allancef8c792008-04-02 13:48:23 -07001296 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001297 }
1298
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001299 if (hw->phy.media_type == e1000_media_type_copper &&
1300 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001301 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1302 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001303 /*
1304 * Set the ILOS bit on the fiber Nic if half duplex link is
1305 * detected.
1306 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001307 stat_reg = er32(STATUS);
1308 if ((stat_reg & E1000_STATUS_FD) == 0)
1309 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1310 }
1311
1312 ew32(CTRL, ctrl_reg);
1313
Bruce Allanad680762008-03-28 09:15:03 -07001314 /*
1315 * Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001316 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1317 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001318 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001319 e1000_phy_disable_receiver(adapter);
1320
1321 udelay(500);
1322
1323 return 0;
1324}
1325
1326static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1327{
1328 struct e1000_hw *hw = &adapter->hw;
1329 u32 ctrl = er32(CTRL);
1330 int link = 0;
1331
1332 /* special requirements for 82571/82572 fiber adapters */
1333
Bruce Allanad680762008-03-28 09:15:03 -07001334 /*
1335 * jump through hoops to make sure link is up because serdes
1336 * link is hardwired up
1337 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001338 ctrl |= E1000_CTRL_SLU;
1339 ew32(CTRL, ctrl);
1340
1341 /* disable autoneg */
1342 ctrl = er32(TXCW);
1343 ctrl &= ~(1 << 31);
1344 ew32(TXCW, ctrl);
1345
1346 link = (er32(STATUS) & E1000_STATUS_LU);
1347
1348 if (!link) {
1349 /* set invert loss of signal */
1350 ctrl = er32(CTRL);
1351 ctrl |= E1000_CTRL_ILOS;
1352 ew32(CTRL, ctrl);
1353 }
1354
Bruce Allanad680762008-03-28 09:15:03 -07001355 /*
1356 * special write to serdes control register to enable SerDes analog
1357 * loopback
1358 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001359#define E1000_SERDES_LB_ON 0x410
1360 ew32(SCTL, E1000_SERDES_LB_ON);
1361 msleep(10);
1362
1363 return 0;
1364}
1365
1366/* only call this for fiber/serdes connections to es2lan */
1367static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1368{
1369 struct e1000_hw *hw = &adapter->hw;
1370 u32 ctrlext = er32(CTRL_EXT);
1371 u32 ctrl = er32(CTRL);
1372
Bruce Allanad680762008-03-28 09:15:03 -07001373 /*
1374 * save CTRL_EXT to restore later, reuse an empty variable (unused
1375 * on mac_type 80003es2lan)
1376 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001377 adapter->tx_fifo_head = ctrlext;
1378
1379 /* clear the serdes mode bits, putting the device into mac loopback */
1380 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1381 ew32(CTRL_EXT, ctrlext);
1382
1383 /* force speed to 1000/FD, link up */
1384 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1385 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1386 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1387 ew32(CTRL, ctrl);
1388
1389 /* set mac loopback */
1390 ctrl = er32(RCTL);
1391 ctrl |= E1000_RCTL_LBM_MAC;
1392 ew32(RCTL, ctrl);
1393
1394 /* set testing mode parameters (no need to reset later) */
1395#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1396#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1397 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001398 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001399
1400 return 0;
1401}
1402
1403static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1404{
1405 struct e1000_hw *hw = &adapter->hw;
1406 u32 rctl;
1407
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001408 if (hw->phy.media_type == e1000_media_type_fiber ||
1409 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001410 switch (hw->mac.type) {
1411 case e1000_80003es2lan:
1412 return e1000_set_es2lan_mac_loopback(adapter);
1413 break;
1414 case e1000_82571:
1415 case e1000_82572:
1416 return e1000_set_82571_fiber_loopback(adapter);
1417 break;
1418 default:
1419 rctl = er32(RCTL);
1420 rctl |= E1000_RCTL_LBM_TCVR;
1421 ew32(RCTL, rctl);
1422 return 0;
1423 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001424 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001425 return e1000_integrated_phy_loopback(adapter);
1426 }
1427
1428 return 7;
1429}
1430
1431static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1432{
1433 struct e1000_hw *hw = &adapter->hw;
1434 u32 rctl;
1435 u16 phy_reg;
1436
1437 rctl = er32(RCTL);
1438 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1439 ew32(RCTL, rctl);
1440
1441 switch (hw->mac.type) {
1442 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001443 if (hw->phy.media_type == e1000_media_type_fiber ||
1444 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001445 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001446 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001447 adapter->tx_fifo_head = 0;
1448 }
1449 /* fall through */
1450 case e1000_82571:
1451 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001452 if (hw->phy.media_type == e1000_media_type_fiber ||
1453 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001454#define E1000_SERDES_LB_OFF 0x400
1455 ew32(SCTL, E1000_SERDES_LB_OFF);
1456 msleep(10);
1457 break;
1458 }
1459 /* Fall Through */
1460 default:
1461 hw->mac.autoneg = 1;
1462 if (hw->phy.type == e1000_phy_gg82563)
1463 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1464 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1465 if (phy_reg & MII_CR_LOOPBACK) {
1466 phy_reg &= ~MII_CR_LOOPBACK;
1467 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1468 e1000e_commit_phy(hw);
1469 }
1470 break;
1471 }
1472}
1473
1474static void e1000_create_lbtest_frame(struct sk_buff *skb,
1475 unsigned int frame_size)
1476{
1477 memset(skb->data, 0xFF, frame_size);
1478 frame_size &= ~1;
1479 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1480 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1481 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1482}
1483
1484static int e1000_check_lbtest_frame(struct sk_buff *skb,
1485 unsigned int frame_size)
1486{
1487 frame_size &= ~1;
1488 if (*(skb->data + 3) == 0xFF)
1489 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1490 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1491 return 0;
1492 return 13;
1493}
1494
1495static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1496{
1497 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1498 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1499 struct pci_dev *pdev = adapter->pdev;
1500 struct e1000_hw *hw = &adapter->hw;
1501 int i, j, k, l;
1502 int lc;
1503 int good_cnt;
1504 int ret_val = 0;
1505 unsigned long time;
1506
1507 ew32(RDT, rx_ring->count - 1);
1508
Bruce Allanad680762008-03-28 09:15:03 -07001509 /*
1510 * Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001511 * The idea is to wrap the largest ring a number of times using 64
1512 * send/receive pairs during each loop
1513 */
1514
1515 if (rx_ring->count <= tx_ring->count)
1516 lc = ((tx_ring->count / 64) * 2) + 1;
1517 else
1518 lc = ((rx_ring->count / 64) * 2) + 1;
1519
1520 k = 0;
1521 l = 0;
1522 for (j = 0; j <= lc; j++) { /* loop count loop */
1523 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001524 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1525 1024);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001526 pci_dma_sync_single_for_device(pdev,
1527 tx_ring->buffer_info[k].dma,
1528 tx_ring->buffer_info[k].length,
1529 PCI_DMA_TODEVICE);
1530 k++;
1531 if (k == tx_ring->count)
1532 k = 0;
1533 }
1534 ew32(TDT, k);
1535 msleep(200);
1536 time = jiffies; /* set the start time for the receive */
1537 good_cnt = 0;
1538 do { /* receive the sent packets */
1539 pci_dma_sync_single_for_cpu(pdev,
1540 rx_ring->buffer_info[l].dma, 2048,
1541 PCI_DMA_FROMDEVICE);
1542
1543 ret_val = e1000_check_lbtest_frame(
1544 rx_ring->buffer_info[l].skb, 1024);
1545 if (!ret_val)
1546 good_cnt++;
1547 l++;
1548 if (l == rx_ring->count)
1549 l = 0;
Bruce Allanad680762008-03-28 09:15:03 -07001550 /*
1551 * time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001552 * enough time to complete the receives, if it's
1553 * exceeded, break and error off
1554 */
1555 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1556 if (good_cnt != 64) {
1557 ret_val = 13; /* ret_val is the same as mis-compare */
1558 break;
1559 }
Bruce Allancef8c792008-04-02 13:48:23 -07001560 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001561 ret_val = 14; /* error code for time out error */
1562 break;
1563 }
1564 } /* end loop count loop */
1565 return ret_val;
1566}
1567
1568static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1569{
Bruce Allanad680762008-03-28 09:15:03 -07001570 /*
1571 * PHY loopback cannot be performed if SoL/IDER
1572 * sessions are active
1573 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001574 if (e1000_check_reset_block(&adapter->hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001575 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001576 *data = 0;
1577 goto out;
1578 }
1579
1580 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001581 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001582 goto out;
1583
1584 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001585 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001586 goto err_loopback;
1587
1588 *data = e1000_run_loopback_test(adapter);
1589 e1000_loopback_cleanup(adapter);
1590
1591err_loopback:
1592 e1000_free_desc_rings(adapter);
1593out:
1594 return *data;
1595}
1596
1597static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1598{
1599 struct e1000_hw *hw = &adapter->hw;
1600
1601 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001602 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001603 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001604 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001605
Bruce Allanad680762008-03-28 09:15:03 -07001606 /*
1607 * On some blade server designs, link establishment
1608 * could take as long as 2-3 minutes
1609 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001610 do {
1611 hw->mac.ops.check_for_link(hw);
1612 if (hw->mac.serdes_has_link)
1613 return *data;
1614 msleep(20);
1615 } while (i++ < 3750);
1616
1617 *data = 1;
1618 } else {
1619 hw->mac.ops.check_for_link(hw);
1620 if (hw->mac.autoneg)
1621 msleep(4000);
1622
1623 if (!(er32(STATUS) &
1624 E1000_STATUS_LU))
1625 *data = 1;
1626 }
1627 return *data;
1628}
1629
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001630static int e1000e_get_sset_count(struct net_device *netdev, int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001631{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001632 switch (sset) {
1633 case ETH_SS_TEST:
1634 return E1000_TEST_LEN;
1635 case ETH_SS_STATS:
1636 return E1000_STATS_LEN;
1637 default:
1638 return -EOPNOTSUPP;
1639 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001640}
1641
1642static void e1000_diag_test(struct net_device *netdev,
1643 struct ethtool_test *eth_test, u64 *data)
1644{
1645 struct e1000_adapter *adapter = netdev_priv(netdev);
1646 u16 autoneg_advertised;
1647 u8 forced_speed_duplex;
1648 u8 autoneg;
1649 bool if_running = netif_running(netdev);
1650
1651 set_bit(__E1000_TESTING, &adapter->state);
1652 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1653 /* Offline tests */
1654
1655 /* save speed, duplex, autoneg settings */
1656 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1657 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1658 autoneg = adapter->hw.mac.autoneg;
1659
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001660 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001661
Bruce Allanad680762008-03-28 09:15:03 -07001662 /*
1663 * Link test performed before hardware reset so autoneg doesn't
1664 * interfere with test result
1665 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001666 if (e1000_link_test(adapter, &data[4]))
1667 eth_test->flags |= ETH_TEST_FL_FAILED;
1668
1669 if (if_running)
1670 /* indicate we're in test mode */
1671 dev_close(netdev);
1672 else
1673 e1000e_reset(adapter);
1674
1675 if (e1000_reg_test(adapter, &data[0]))
1676 eth_test->flags |= ETH_TEST_FL_FAILED;
1677
1678 e1000e_reset(adapter);
1679 if (e1000_eeprom_test(adapter, &data[1]))
1680 eth_test->flags |= ETH_TEST_FL_FAILED;
1681
1682 e1000e_reset(adapter);
1683 if (e1000_intr_test(adapter, &data[2]))
1684 eth_test->flags |= ETH_TEST_FL_FAILED;
1685
1686 e1000e_reset(adapter);
1687 /* make sure the phy is powered up */
1688 e1000e_power_up_phy(adapter);
1689 if (e1000_loopback_test(adapter, &data[3]))
1690 eth_test->flags |= ETH_TEST_FL_FAILED;
1691
1692 /* restore speed, duplex, autoneg settings */
1693 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1694 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1695 adapter->hw.mac.autoneg = autoneg;
1696
1697 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001698 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001699 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001700 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001701
1702 clear_bit(__E1000_TESTING, &adapter->state);
1703 if (if_running)
1704 dev_open(netdev);
1705 } else {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001706 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001707 /* Online tests */
1708 if (e1000_link_test(adapter, &data[4]))
1709 eth_test->flags |= ETH_TEST_FL_FAILED;
1710
1711 /* Online tests aren't run; pass by default */
1712 data[0] = 0;
1713 data[1] = 0;
1714 data[2] = 0;
1715 data[3] = 0;
1716
1717 clear_bit(__E1000_TESTING, &adapter->state);
1718 }
1719 msleep_interruptible(4 * 1000);
1720}
1721
1722static void e1000_get_wol(struct net_device *netdev,
1723 struct ethtool_wolinfo *wol)
1724{
1725 struct e1000_adapter *adapter = netdev_priv(netdev);
1726
1727 wol->supported = 0;
1728 wol->wolopts = 0;
1729
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001730 if (!(adapter->flags & FLAG_HAS_WOL) ||
1731 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001732 return;
1733
1734 wol->supported = WAKE_UCAST | WAKE_MCAST |
Mitch Williamsefb90e42008-01-29 12:43:02 -08001735 WAKE_BCAST | WAKE_MAGIC |
1736 WAKE_PHY | WAKE_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001737
1738 /* apply any specific unsupported masks here */
1739 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1740 wol->supported &= ~WAKE_UCAST;
1741
1742 if (adapter->wol & E1000_WUFC_EX)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001743 e_err("Interface does not support directed (unicast) "
1744 "frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001745 }
1746
1747 if (adapter->wol & E1000_WUFC_EX)
1748 wol->wolopts |= WAKE_UCAST;
1749 if (adapter->wol & E1000_WUFC_MC)
1750 wol->wolopts |= WAKE_MCAST;
1751 if (adapter->wol & E1000_WUFC_BC)
1752 wol->wolopts |= WAKE_BCAST;
1753 if (adapter->wol & E1000_WUFC_MAG)
1754 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001755 if (adapter->wol & E1000_WUFC_LNKC)
1756 wol->wolopts |= WAKE_PHY;
1757 if (adapter->wol & E1000_WUFC_ARP)
1758 wol->wolopts |= WAKE_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001759}
1760
1761static int e1000_set_wol(struct net_device *netdev,
1762 struct ethtool_wolinfo *wol)
1763{
1764 struct e1000_adapter *adapter = netdev_priv(netdev);
1765
Mitch Williamsefb90e42008-01-29 12:43:02 -08001766 if (wol->wolopts & WAKE_MAGICSECURE)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001767 return -EOPNOTSUPP;
1768
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001769 if (!(adapter->flags & FLAG_HAS_WOL) ||
1770 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001771 return wol->wolopts ? -EOPNOTSUPP : 0;
1772
1773 /* these settings will always override what we currently have */
1774 adapter->wol = 0;
1775
1776 if (wol->wolopts & WAKE_UCAST)
1777 adapter->wol |= E1000_WUFC_EX;
1778 if (wol->wolopts & WAKE_MCAST)
1779 adapter->wol |= E1000_WUFC_MC;
1780 if (wol->wolopts & WAKE_BCAST)
1781 adapter->wol |= E1000_WUFC_BC;
1782 if (wol->wolopts & WAKE_MAGIC)
1783 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001784 if (wol->wolopts & WAKE_PHY)
1785 adapter->wol |= E1000_WUFC_LNKC;
1786 if (wol->wolopts & WAKE_ARP)
1787 adapter->wol |= E1000_WUFC_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001788
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001789 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1790
Auke Kokbc7f75f2007-09-17 12:30:59 -07001791 return 0;
1792}
1793
1794/* toggle LED 4 times per second = 2 "blinks" per second */
1795#define E1000_ID_INTERVAL (HZ/4)
1796
1797/* bit defines for adapter->led_status */
1798#define E1000_LED_ON 0
1799
Bruce Allana4f58f52009-06-02 11:29:18 +00001800static void e1000e_led_blink_task(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001801{
Bruce Allana4f58f52009-06-02 11:29:18 +00001802 struct e1000_adapter *adapter = container_of(work,
1803 struct e1000_adapter, led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001804
1805 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
1806 adapter->hw.mac.ops.led_off(&adapter->hw);
1807 else
1808 adapter->hw.mac.ops.led_on(&adapter->hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001809}
Auke Kokbc7f75f2007-09-17 12:30:59 -07001810
Bruce Allana4f58f52009-06-02 11:29:18 +00001811static void e1000_led_blink_callback(unsigned long data)
1812{
1813 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1814
1815 schedule_work(&adapter->led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001816 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1817}
1818
1819static int e1000_phys_id(struct net_device *netdev, u32 data)
1820{
1821 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001822 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001823
Stephen Hemminger5a9147b2007-10-29 10:46:05 -07001824 if (!data)
1825 data = INT_MAX;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001826
Bruce Allan4662e822008-08-26 18:37:06 -07001827 if ((hw->phy.type == e1000_phy_ife) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00001828 (hw->mac.type == e1000_pchlan) ||
Bruce Allan4662e822008-08-26 18:37:06 -07001829 (hw->mac.type == e1000_82574)) {
Bruce Allana4f58f52009-06-02 11:29:18 +00001830 INIT_WORK(&adapter->led_blink_task, e1000e_led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001831 if (!adapter->blink_timer.function) {
1832 init_timer(&adapter->blink_timer);
1833 adapter->blink_timer.function =
1834 e1000_led_blink_callback;
1835 adapter->blink_timer.data = (unsigned long) adapter;
1836 }
1837 mod_timer(&adapter->blink_timer, jiffies);
1838 msleep_interruptible(data * 1000);
1839 del_timer_sync(&adapter->blink_timer);
Bruce Allan4662e822008-08-26 18:37:06 -07001840 if (hw->phy.type == e1000_phy_ife)
1841 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001842 } else {
Bruce Allan4662e822008-08-26 18:37:06 -07001843 e1000e_blink_led(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001844 msleep_interruptible(data * 1000);
1845 }
1846
Bruce Allan4662e822008-08-26 18:37:06 -07001847 hw->mac.ops.led_off(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001848 clear_bit(E1000_LED_ON, &adapter->led_status);
Bruce Allan4662e822008-08-26 18:37:06 -07001849 hw->mac.ops.cleanup_led(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001850
1851 return 0;
1852}
1853
Auke Kokde5b3072008-04-23 11:09:08 -07001854static int e1000_get_coalesce(struct net_device *netdev,
1855 struct ethtool_coalesce *ec)
1856{
1857 struct e1000_adapter *adapter = netdev_priv(netdev);
1858
1859 if (adapter->itr_setting <= 3)
1860 ec->rx_coalesce_usecs = adapter->itr_setting;
1861 else
1862 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1863
1864 return 0;
1865}
1866
1867static int e1000_set_coalesce(struct net_device *netdev,
1868 struct ethtool_coalesce *ec)
1869{
1870 struct e1000_adapter *adapter = netdev_priv(netdev);
1871 struct e1000_hw *hw = &adapter->hw;
1872
1873 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
1874 ((ec->rx_coalesce_usecs > 3) &&
1875 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1876 (ec->rx_coalesce_usecs == 2))
1877 return -EINVAL;
1878
1879 if (ec->rx_coalesce_usecs <= 3) {
1880 adapter->itr = 20000;
1881 adapter->itr_setting = ec->rx_coalesce_usecs;
1882 } else {
1883 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1884 adapter->itr_setting = adapter->itr & ~3;
1885 }
1886
1887 if (adapter->itr_setting != 0)
1888 ew32(ITR, 1000000000 / (adapter->itr * 256));
1889 else
1890 ew32(ITR, 0);
1891
1892 return 0;
1893}
1894
Auke Kokbc7f75f2007-09-17 12:30:59 -07001895static int e1000_nway_reset(struct net_device *netdev)
1896{
1897 struct e1000_adapter *adapter = netdev_priv(netdev);
1898 if (netif_running(netdev))
1899 e1000e_reinit_locked(adapter);
1900 return 0;
1901}
1902
Auke Kokbc7f75f2007-09-17 12:30:59 -07001903static void e1000_get_ethtool_stats(struct net_device *netdev,
1904 struct ethtool_stats *stats,
1905 u64 *data)
1906{
1907 struct e1000_adapter *adapter = netdev_priv(netdev);
1908 int i;
1909
1910 e1000e_update_stats(adapter);
1911 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1912 char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
1913 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1914 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1915 }
1916}
1917
1918static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1919 u8 *data)
1920{
1921 u8 *p = data;
1922 int i;
1923
1924 switch (stringset) {
1925 case ETH_SS_TEST:
Bruce Allanad680762008-03-28 09:15:03 -07001926 memcpy(data, *e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001927 break;
1928 case ETH_SS_STATS:
1929 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1930 memcpy(p, e1000_gstrings_stats[i].stat_string,
1931 ETH_GSTRING_LEN);
1932 p += ETH_GSTRING_LEN;
1933 }
1934 break;
1935 }
1936}
1937
1938static const struct ethtool_ops e1000_ethtool_ops = {
1939 .get_settings = e1000_get_settings,
1940 .set_settings = e1000_set_settings,
1941 .get_drvinfo = e1000_get_drvinfo,
1942 .get_regs_len = e1000_get_regs_len,
1943 .get_regs = e1000_get_regs,
1944 .get_wol = e1000_get_wol,
1945 .set_wol = e1000_set_wol,
1946 .get_msglevel = e1000_get_msglevel,
1947 .set_msglevel = e1000_set_msglevel,
1948 .nway_reset = e1000_nway_reset,
Auke Kok369d7422007-10-15 14:30:59 -07001949 .get_link = e1000_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001950 .get_eeprom_len = e1000_get_eeprom_len,
1951 .get_eeprom = e1000_get_eeprom,
1952 .set_eeprom = e1000_set_eeprom,
1953 .get_ringparam = e1000_get_ringparam,
1954 .set_ringparam = e1000_set_ringparam,
1955 .get_pauseparam = e1000_get_pauseparam,
1956 .set_pauseparam = e1000_set_pauseparam,
1957 .get_rx_csum = e1000_get_rx_csum,
1958 .set_rx_csum = e1000_set_rx_csum,
1959 .get_tx_csum = e1000_get_tx_csum,
1960 .set_tx_csum = e1000_set_tx_csum,
1961 .get_sg = ethtool_op_get_sg,
1962 .set_sg = ethtool_op_set_sg,
1963 .get_tso = ethtool_op_get_tso,
1964 .set_tso = e1000_set_tso,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001965 .self_test = e1000_diag_test,
1966 .get_strings = e1000_get_strings,
1967 .phys_id = e1000_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001968 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001969 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07001970 .get_coalesce = e1000_get_coalesce,
1971 .set_coalesce = e1000_set_coalesce,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001972};
1973
1974void e1000e_set_ethtool_ops(struct net_device *netdev)
1975{
1976 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
1977}