blob: 1ff43b470302b32a5743b8d530fea4706ae2d7b0 [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
Ajit Khapardee0f36a92009-10-13 01:45:09 +000038enum {NETDEV_STATS, E1000_STATS};
39
Auke Kokbc7f75f2007-09-17 12:30:59 -070040struct e1000_stats {
41 char stat_string[ETH_GSTRING_LEN];
Ajit Khapardee0f36a92009-10-13 01:45:09 +000042 int type;
Auke Kokbc7f75f2007-09-17 12:30:59 -070043 int sizeof_stat;
44 int stat_offset;
45};
46
Ajit Khapardee0f36a92009-10-13 01:45:09 +000047#define E1000_STAT(m) E1000_STATS, \
48 sizeof(((struct e1000_adapter *)0)->m), \
49 offsetof(struct e1000_adapter, m)
50#define E1000_NETDEV_STAT(m) NETDEV_STATS, \
51 sizeof(((struct net_device *)0)->m), \
52 offsetof(struct net_device, m)
53
Auke Kokbc7f75f2007-09-17 12:30:59 -070054static const struct e1000_stats e1000_gstrings_stats[] = {
55 { "rx_packets", E1000_STAT(stats.gprc) },
56 { "tx_packets", E1000_STAT(stats.gptc) },
Bruce Allan7c257692008-04-23 11:09:00 -070057 { "rx_bytes", E1000_STAT(stats.gorc) },
58 { "tx_bytes", E1000_STAT(stats.gotc) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070059 { "rx_broadcast", E1000_STAT(stats.bprc) },
60 { "tx_broadcast", E1000_STAT(stats.bptc) },
61 { "rx_multicast", E1000_STAT(stats.mprc) },
62 { "tx_multicast", E1000_STAT(stats.mptc) },
Ajit Khaparde7274c202009-10-07 02:44:26 +000063 { "rx_errors", E1000_NETDEV_STAT(stats.rx_errors) },
64 { "tx_errors", E1000_NETDEV_STAT(stats.tx_errors) },
65 { "tx_dropped", E1000_NETDEV_STAT(stats.tx_dropped) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070066 { "multicast", E1000_STAT(stats.mprc) },
67 { "collisions", E1000_STAT(stats.colc) },
Ajit Khaparde7274c202009-10-07 02:44:26 +000068 { "rx_length_errors", E1000_NETDEV_STAT(stats.rx_length_errors) },
69 { "rx_over_errors", E1000_NETDEV_STAT(stats.rx_over_errors) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070070 { "rx_crc_errors", E1000_STAT(stats.crcerrs) },
Ajit Khaparde7274c202009-10-07 02:44:26 +000071 { "rx_frame_errors", E1000_NETDEV_STAT(stats.rx_frame_errors) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070072 { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
73 { "rx_missed_errors", E1000_STAT(stats.mpc) },
74 { "tx_aborted_errors", E1000_STAT(stats.ecol) },
75 { "tx_carrier_errors", E1000_STAT(stats.tncrs) },
Ajit Khaparde7274c202009-10-07 02:44:26 +000076 { "tx_fifo_errors", E1000_NETDEV_STAT(stats.tx_fifo_errors) },
77 { "tx_heartbeat_errors", E1000_NETDEV_STAT(stats.tx_heartbeat_errors) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070078 { "tx_window_errors", E1000_STAT(stats.latecol) },
79 { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
80 { "tx_deferred_ok", E1000_STAT(stats.dc) },
81 { "tx_single_coll_ok", E1000_STAT(stats.scc) },
82 { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
83 { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
84 { "tx_restart_queue", E1000_STAT(restart_queue) },
85 { "rx_long_length_errors", E1000_STAT(stats.roc) },
86 { "rx_short_length_errors", E1000_STAT(stats.ruc) },
87 { "rx_align_errors", E1000_STAT(stats.algnerrc) },
88 { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
89 { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
90 { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
91 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
92 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
93 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
Bruce Allan7c257692008-04-23 11:09:00 -070094 { "rx_long_byte_count", E1000_STAT(stats.gorc) },
Auke Kokbc7f75f2007-09-17 12:30:59 -070095 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
96 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
97 { "rx_header_split", E1000_STAT(rx_hdr_split) },
98 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
99 { "tx_smbus", E1000_STAT(stats.mgptc) },
100 { "rx_smbus", E1000_STAT(stats.mgprc) },
101 { "dropped_smbus", E1000_STAT(stats.mgpdc) },
102 { "rx_dma_failed", E1000_STAT(rx_dma_failed) },
103 { "tx_dma_failed", E1000_STAT(tx_dma_failed) },
104};
105
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200106#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700107#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
108static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
109 "Register test (offline)", "Eeprom test (offline)",
110 "Interrupt test (offline)", "Loopback test (offline)",
111 "Link test (on/offline)"
112};
Bruce Allanad680762008-03-28 09:15:03 -0700113#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700114
115static int e1000_get_settings(struct net_device *netdev,
116 struct ethtool_cmd *ecmd)
117{
118 struct e1000_adapter *adapter = netdev_priv(netdev);
119 struct e1000_hw *hw = &adapter->hw;
Auke Kok369d7422007-10-15 14:30:59 -0700120 u32 status;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700121
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700122 if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700123
124 ecmd->supported = (SUPPORTED_10baseT_Half |
125 SUPPORTED_10baseT_Full |
126 SUPPORTED_100baseT_Half |
127 SUPPORTED_100baseT_Full |
128 SUPPORTED_1000baseT_Full |
129 SUPPORTED_Autoneg |
130 SUPPORTED_TP);
131 if (hw->phy.type == e1000_phy_ife)
132 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
133 ecmd->advertising = ADVERTISED_TP;
134
135 if (hw->mac.autoneg == 1) {
136 ecmd->advertising |= ADVERTISED_Autoneg;
137 /* the e1000 autoneg seems to match ethtool nicely */
138 ecmd->advertising |= hw->phy.autoneg_advertised;
139 }
140
141 ecmd->port = PORT_TP;
142 ecmd->phy_address = hw->phy.addr;
143 ecmd->transceiver = XCVR_INTERNAL;
144
145 } else {
146 ecmd->supported = (SUPPORTED_1000baseT_Full |
147 SUPPORTED_FIBRE |
148 SUPPORTED_Autoneg);
149
150 ecmd->advertising = (ADVERTISED_1000baseT_Full |
151 ADVERTISED_FIBRE |
152 ADVERTISED_Autoneg);
153
154 ecmd->port = PORT_FIBRE;
155 ecmd->transceiver = XCVR_EXTERNAL;
156 }
157
Auke Kok369d7422007-10-15 14:30:59 -0700158 status = er32(STATUS);
159 if (status & E1000_STATUS_LU) {
160 if (status & E1000_STATUS_SPEED_1000)
161 ecmd->speed = 1000;
162 else if (status & E1000_STATUS_SPEED_100)
163 ecmd->speed = 100;
164 else
165 ecmd->speed = 10;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700166
Auke Kok369d7422007-10-15 14:30:59 -0700167 if (status & E1000_STATUS_FD)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700168 ecmd->duplex = DUPLEX_FULL;
169 else
170 ecmd->duplex = DUPLEX_HALF;
171 } else {
172 ecmd->speed = -1;
173 ecmd->duplex = -1;
174 }
175
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700176 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -0700177 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000178
179 /* MDI-X => 2; MDI =>1; Invalid =>0 */
180 if ((hw->phy.media_type == e1000_media_type_copper) &&
181 !hw->mac.get_link_status)
182 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
183 ETH_TP_MDI;
184 else
185 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
186
Auke Kokbc7f75f2007-09-17 12:30:59 -0700187 return 0;
188}
189
Auke Kok369d7422007-10-15 14:30:59 -0700190static u32 e1000_get_link(struct net_device *netdev)
191{
192 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allana20e4cf2008-11-21 17:01:35 -0800193
194 return e1000_has_link(adapter);
Auke Kok369d7422007-10-15 14:30:59 -0700195}
196
Auke Kokbc7f75f2007-09-17 12:30:59 -0700197static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
198{
199 struct e1000_mac_info *mac = &adapter->hw.mac;
200
201 mac->autoneg = 0;
202
203 /* Fiber NICs only allow 1000 gbps Full duplex */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700204 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -0700205 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700206 e_err("Unsupported Speed/Duplex configuration\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700207 return -EINVAL;
208 }
209
210 switch (spddplx) {
211 case SPEED_10 + DUPLEX_HALF:
212 mac->forced_speed_duplex = ADVERTISE_10_HALF;
213 break;
214 case SPEED_10 + DUPLEX_FULL:
215 mac->forced_speed_duplex = ADVERTISE_10_FULL;
216 break;
217 case SPEED_100 + DUPLEX_HALF:
218 mac->forced_speed_duplex = ADVERTISE_100_HALF;
219 break;
220 case SPEED_100 + DUPLEX_FULL:
221 mac->forced_speed_duplex = ADVERTISE_100_FULL;
222 break;
223 case SPEED_1000 + DUPLEX_FULL:
224 mac->autoneg = 1;
225 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
226 break;
227 case SPEED_1000 + DUPLEX_HALF: /* not supported */
228 default:
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700229 e_err("Unsupported Speed/Duplex configuration\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700230 return -EINVAL;
231 }
232 return 0;
233}
234
235static int e1000_set_settings(struct net_device *netdev,
236 struct ethtool_cmd *ecmd)
237{
238 struct e1000_adapter *adapter = netdev_priv(netdev);
239 struct e1000_hw *hw = &adapter->hw;
240
Bruce Allanad680762008-03-28 09:15:03 -0700241 /*
242 * When SoL/IDER sessions are active, autoneg/speed/duplex
243 * cannot be changed
244 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700245 if (e1000_check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700246 e_err("Cannot change link characteristics when SoL/IDER is "
247 "active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700248 return -EINVAL;
249 }
250
251 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
252 msleep(1);
253
254 if (ecmd->autoneg == AUTONEG_ENABLE) {
255 hw->mac.autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700256 if (hw->phy.media_type == e1000_media_type_fiber)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700257 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
258 ADVERTISED_FIBRE |
259 ADVERTISED_Autoneg;
260 else
261 hw->phy.autoneg_advertised = ecmd->advertising |
262 ADVERTISED_TP |
263 ADVERTISED_Autoneg;
264 ecmd->advertising = hw->phy.autoneg_advertised;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700265 if (adapter->fc_autoneg)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800266 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700267 } else {
268 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
269 clear_bit(__E1000_RESETTING, &adapter->state);
270 return -EINVAL;
271 }
272 }
273
274 /* reset the link */
275
276 if (netif_running(adapter->netdev)) {
277 e1000e_down(adapter);
278 e1000e_up(adapter);
279 } else {
280 e1000e_reset(adapter);
281 }
282
283 clear_bit(__E1000_RESETTING, &adapter->state);
284 return 0;
285}
286
287static void e1000_get_pauseparam(struct net_device *netdev,
288 struct ethtool_pauseparam *pause)
289{
290 struct e1000_adapter *adapter = netdev_priv(netdev);
291 struct e1000_hw *hw = &adapter->hw;
292
293 pause->autoneg =
294 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
295
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800296 if (hw->fc.current_mode == e1000_fc_rx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700297 pause->rx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800298 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700299 pause->tx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800300 } else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700301 pause->rx_pause = 1;
302 pause->tx_pause = 1;
303 }
304}
305
306static int e1000_set_pauseparam(struct net_device *netdev,
307 struct ethtool_pauseparam *pause)
308{
309 struct e1000_adapter *adapter = netdev_priv(netdev);
310 struct e1000_hw *hw = &adapter->hw;
311 int retval = 0;
312
313 adapter->fc_autoneg = pause->autoneg;
314
315 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
316 msleep(1);
317
Auke Kokbc7f75f2007-09-17 12:30:59 -0700318 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800319 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700320 if (netif_running(adapter->netdev)) {
321 e1000e_down(adapter);
322 e1000e_up(adapter);
323 } else {
324 e1000e_reset(adapter);
325 }
326 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800327 if (pause->rx_pause && pause->tx_pause)
328 hw->fc.requested_mode = e1000_fc_full;
329 else if (pause->rx_pause && !pause->tx_pause)
330 hw->fc.requested_mode = e1000_fc_rx_pause;
331 else if (!pause->rx_pause && pause->tx_pause)
332 hw->fc.requested_mode = e1000_fc_tx_pause;
333 else if (!pause->rx_pause && !pause->tx_pause)
334 hw->fc.requested_mode = e1000_fc_none;
335
336 hw->fc.current_mode = hw->fc.requested_mode;
337
Bruce Allan945eb312009-10-28 18:28:30 +0000338 if (hw->phy.media_type == e1000_media_type_fiber) {
339 retval = hw->mac.ops.setup_link(hw);
340 /* implicit goto out */
341 } else {
342 retval = e1000e_force_mac_fc(hw);
343 if (retval)
344 goto out;
345 e1000e_set_fc_watermarks(hw);
346 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700347 }
348
Bruce Allan945eb312009-10-28 18:28:30 +0000349out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700350 clear_bit(__E1000_RESETTING, &adapter->state);
351 return retval;
352}
353
354static u32 e1000_get_rx_csum(struct net_device *netdev)
355{
356 struct e1000_adapter *adapter = netdev_priv(netdev);
357 return (adapter->flags & FLAG_RX_CSUM_ENABLED);
358}
359
360static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
361{
362 struct e1000_adapter *adapter = netdev_priv(netdev);
363
364 if (data)
365 adapter->flags |= FLAG_RX_CSUM_ENABLED;
366 else
367 adapter->flags &= ~FLAG_RX_CSUM_ENABLED;
368
369 if (netif_running(netdev))
370 e1000e_reinit_locked(adapter);
371 else
372 e1000e_reset(adapter);
373 return 0;
374}
375
376static u32 e1000_get_tx_csum(struct net_device *netdev)
377{
378 return ((netdev->features & NETIF_F_HW_CSUM) != 0);
379}
380
381static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
382{
383 if (data)
384 netdev->features |= NETIF_F_HW_CSUM;
385 else
386 netdev->features &= ~NETIF_F_HW_CSUM;
387
388 return 0;
389}
390
391static int e1000_set_tso(struct net_device *netdev, u32 data)
392{
393 struct e1000_adapter *adapter = netdev_priv(netdev);
394
395 if (data) {
396 netdev->features |= NETIF_F_TSO;
397 netdev->features |= NETIF_F_TSO6;
398 } else {
399 netdev->features &= ~NETIF_F_TSO;
400 netdev->features &= ~NETIF_F_TSO6;
401 }
402
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700403 e_info("TSO is %s\n", data ? "Enabled" : "Disabled");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700404 adapter->flags |= FLAG_TSO_FORCE;
405 return 0;
406}
407
408static u32 e1000_get_msglevel(struct net_device *netdev)
409{
410 struct e1000_adapter *adapter = netdev_priv(netdev);
411 return adapter->msg_enable;
412}
413
414static void e1000_set_msglevel(struct net_device *netdev, u32 data)
415{
416 struct e1000_adapter *adapter = netdev_priv(netdev);
417 adapter->msg_enable = data;
418}
419
420static int e1000_get_regs_len(struct net_device *netdev)
421{
422#define E1000_REGS_LEN 32 /* overestimate */
423 return E1000_REGS_LEN * sizeof(u32);
424}
425
426static void e1000_get_regs(struct net_device *netdev,
427 struct ethtool_regs *regs, void *p)
428{
429 struct e1000_adapter *adapter = netdev_priv(netdev);
430 struct e1000_hw *hw = &adapter->hw;
431 u32 *regs_buff = p;
432 u16 phy_data;
433 u8 revision_id;
434
435 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
436
437 pci_read_config_byte(adapter->pdev, PCI_REVISION_ID, &revision_id);
438
439 regs->version = (1 << 24) | (revision_id << 16) | adapter->pdev->device;
440
441 regs_buff[0] = er32(CTRL);
442 regs_buff[1] = er32(STATUS);
443
444 regs_buff[2] = er32(RCTL);
445 regs_buff[3] = er32(RDLEN);
446 regs_buff[4] = er32(RDH);
447 regs_buff[5] = er32(RDT);
448 regs_buff[6] = er32(RDTR);
449
450 regs_buff[7] = er32(TCTL);
451 regs_buff[8] = er32(TDLEN);
452 regs_buff[9] = er32(TDH);
453 regs_buff[10] = er32(TDT);
454 regs_buff[11] = er32(TIDV);
455
456 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700457
458 /* ethtool doesn't use anything past this point, so all this
459 * code is likely legacy junk for apps that may or may not
460 * exist */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700461 if (hw->phy.type == e1000_phy_m88) {
462 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
463 regs_buff[13] = (u32)phy_data; /* cable length */
464 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
465 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
466 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
467 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
468 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
469 regs_buff[18] = regs_buff[13]; /* cable polarity */
470 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
471 regs_buff[20] = regs_buff[17]; /* polarity correction */
472 /* phy receive errors */
473 regs_buff[22] = adapter->phy_stats.receive_errors;
474 regs_buff[23] = regs_buff[13]; /* mdix mode */
475 }
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700476 regs_buff[21] = 0; /* was idle_errors */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700477 e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
478 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
479 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
480}
481
482static int e1000_get_eeprom_len(struct net_device *netdev)
483{
484 struct e1000_adapter *adapter = netdev_priv(netdev);
485 return adapter->hw.nvm.word_size * 2;
486}
487
488static int e1000_get_eeprom(struct net_device *netdev,
489 struct ethtool_eeprom *eeprom, u8 *bytes)
490{
491 struct e1000_adapter *adapter = netdev_priv(netdev);
492 struct e1000_hw *hw = &adapter->hw;
493 u16 *eeprom_buff;
494 int first_word;
495 int last_word;
496 int ret_val = 0;
497 u16 i;
498
499 if (eeprom->len == 0)
500 return -EINVAL;
501
502 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
503
504 first_word = eeprom->offset >> 1;
505 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
506
507 eeprom_buff = kmalloc(sizeof(u16) *
508 (last_word - first_word + 1), GFP_KERNEL);
509 if (!eeprom_buff)
510 return -ENOMEM;
511
512 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
513 ret_val = e1000_read_nvm(hw, first_word,
514 last_word - first_word + 1,
515 eeprom_buff);
516 } else {
517 for (i = 0; i < last_word - first_word + 1; i++) {
518 ret_val = e1000_read_nvm(hw, first_word + i, 1,
519 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800520 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700521 break;
522 }
523 }
524
Bruce Allane2434552008-11-21 17:02:41 -0800525 if (ret_val) {
526 /* a read error occurred, throw away the result */
527 memset(eeprom_buff, 0xff, sizeof(eeprom_buff));
528 } else {
529 /* Device's eeprom is always little-endian, word addressable */
530 for (i = 0; i < last_word - first_word + 1; i++)
531 le16_to_cpus(&eeprom_buff[i]);
532 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700533
534 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
535 kfree(eeprom_buff);
536
537 return ret_val;
538}
539
540static int e1000_set_eeprom(struct net_device *netdev,
541 struct ethtool_eeprom *eeprom, u8 *bytes)
542{
543 struct e1000_adapter *adapter = netdev_priv(netdev);
544 struct e1000_hw *hw = &adapter->hw;
545 u16 *eeprom_buff;
546 void *ptr;
547 int max_len;
548 int first_word;
549 int last_word;
550 int ret_val = 0;
551 u16 i;
552
553 if (eeprom->len == 0)
554 return -EOPNOTSUPP;
555
556 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
557 return -EFAULT;
558
Bruce Allan4a770352008-10-01 17:18:35 -0700559 if (adapter->flags & FLAG_READ_ONLY_NVM)
560 return -EINVAL;
561
Auke Kokbc7f75f2007-09-17 12:30:59 -0700562 max_len = hw->nvm.word_size * 2;
563
564 first_word = eeprom->offset >> 1;
565 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
566 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
567 if (!eeprom_buff)
568 return -ENOMEM;
569
570 ptr = (void *)eeprom_buff;
571
572 if (eeprom->offset & 1) {
573 /* need read/modify/write of first changed EEPROM word */
574 /* only the second byte of the word is being modified */
575 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
576 ptr++;
577 }
578 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0))
579 /* need read/modify/write of last changed EEPROM word */
580 /* only the first byte of the word is being modified */
581 ret_val = e1000_read_nvm(hw, last_word, 1,
582 &eeprom_buff[last_word - first_word]);
583
Bruce Allane2434552008-11-21 17:02:41 -0800584 if (ret_val)
585 goto out;
586
Auke Kokbc7f75f2007-09-17 12:30:59 -0700587 /* Device's eeprom is always little-endian, word addressable */
588 for (i = 0; i < last_word - first_word + 1; i++)
589 le16_to_cpus(&eeprom_buff[i]);
590
591 memcpy(ptr, bytes, eeprom->len);
592
593 for (i = 0; i < last_word - first_word + 1; i++)
594 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
595
596 ret_val = e1000_write_nvm(hw, first_word,
597 last_word - first_word + 1, eeprom_buff);
598
Bruce Allane2434552008-11-21 17:02:41 -0800599 if (ret_val)
600 goto out;
601
Bruce Allanad680762008-03-28 09:15:03 -0700602 /*
603 * Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800604 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700605 */
Bruce Allane2434552008-11-21 17:02:41 -0800606 if ((first_word <= NVM_CHECKSUM_REG) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +0000607 (hw->mac.type == e1000_82583) ||
608 (hw->mac.type == e1000_82574) ||
609 (hw->mac.type == e1000_82573))
Bruce Allane2434552008-11-21 17:02:41 -0800610 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700611
Bruce Allane2434552008-11-21 17:02:41 -0800612out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700613 kfree(eeprom_buff);
614 return ret_val;
615}
616
617static void e1000_get_drvinfo(struct net_device *netdev,
618 struct ethtool_drvinfo *drvinfo)
619{
620 struct e1000_adapter *adapter = netdev_priv(netdev);
621 char firmware_version[32];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700622
623 strncpy(drvinfo->driver, e1000e_driver_name, 32);
624 strncpy(drvinfo->version, e1000e_driver_version, 32);
625
Bruce Allanad680762008-03-28 09:15:03 -0700626 /*
627 * EEPROM image version # is reported as firmware version # for
628 * PCI-E controllers
629 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700630 sprintf(firmware_version, "%d.%d-%d",
Bruce Allan84527592008-11-21 17:00:22 -0800631 (adapter->eeprom_vers & 0xF000) >> 12,
632 (adapter->eeprom_vers & 0x0FF0) >> 4,
633 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700634
635 strncpy(drvinfo->fw_version, firmware_version, 32);
636 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700637 drvinfo->regdump_len = e1000_get_regs_len(netdev);
638 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
639}
640
641static void e1000_get_ringparam(struct net_device *netdev,
642 struct ethtool_ringparam *ring)
643{
644 struct e1000_adapter *adapter = netdev_priv(netdev);
645 struct e1000_ring *tx_ring = adapter->tx_ring;
646 struct e1000_ring *rx_ring = adapter->rx_ring;
647
648 ring->rx_max_pending = E1000_MAX_RXD;
649 ring->tx_max_pending = E1000_MAX_TXD;
650 ring->rx_mini_max_pending = 0;
651 ring->rx_jumbo_max_pending = 0;
652 ring->rx_pending = rx_ring->count;
653 ring->tx_pending = tx_ring->count;
654 ring->rx_mini_pending = 0;
655 ring->rx_jumbo_pending = 0;
656}
657
658static int e1000_set_ringparam(struct net_device *netdev,
659 struct ethtool_ringparam *ring)
660{
661 struct e1000_adapter *adapter = netdev_priv(netdev);
662 struct e1000_ring *tx_ring, *tx_old;
663 struct e1000_ring *rx_ring, *rx_old;
664 int err;
665
666 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
667 return -EINVAL;
668
669 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
670 msleep(1);
671
672 if (netif_running(adapter->netdev))
673 e1000e_down(adapter);
674
675 tx_old = adapter->tx_ring;
676 rx_old = adapter->rx_ring;
677
678 err = -ENOMEM;
679 tx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
680 if (!tx_ring)
681 goto err_alloc_tx;
Bruce Allancef8c792008-04-02 13:48:23 -0700682 /*
683 * use a memcpy to save any previously configured
684 * items like napi structs from having to be
685 * reinitialized
686 */
687 memcpy(tx_ring, tx_old, sizeof(struct e1000_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700688
689 rx_ring = kzalloc(sizeof(struct e1000_ring), GFP_KERNEL);
690 if (!rx_ring)
691 goto err_alloc_rx;
Bruce Allancef8c792008-04-02 13:48:23 -0700692 memcpy(rx_ring, rx_old, sizeof(struct e1000_ring));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700693
694 adapter->tx_ring = tx_ring;
695 adapter->rx_ring = rx_ring;
696
697 rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
698 rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD));
699 rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
700
701 tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
702 tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
703 tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
704
705 if (netif_running(adapter->netdev)) {
706 /* Try to get new resources before deleting old */
707 err = e1000e_setup_rx_resources(adapter);
708 if (err)
709 goto err_setup_rx;
710 err = e1000e_setup_tx_resources(adapter);
711 if (err)
712 goto err_setup_tx;
713
Bruce Allanad680762008-03-28 09:15:03 -0700714 /*
715 * restore the old in order to free it,
716 * then add in the new
717 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700718 adapter->rx_ring = rx_old;
719 adapter->tx_ring = tx_old;
720 e1000e_free_rx_resources(adapter);
721 e1000e_free_tx_resources(adapter);
722 kfree(tx_old);
723 kfree(rx_old);
724 adapter->rx_ring = rx_ring;
725 adapter->tx_ring = tx_ring;
726 err = e1000e_up(adapter);
727 if (err)
728 goto err_setup;
729 }
730
731 clear_bit(__E1000_RESETTING, &adapter->state);
732 return 0;
733err_setup_tx:
734 e1000e_free_rx_resources(adapter);
735err_setup_rx:
736 adapter->rx_ring = rx_old;
737 adapter->tx_ring = tx_old;
738 kfree(rx_ring);
739err_alloc_rx:
740 kfree(tx_ring);
741err_alloc_tx:
742 e1000e_up(adapter);
743err_setup:
744 clear_bit(__E1000_RESETTING, &adapter->state);
745 return err;
746}
747
Bruce Allancef8c792008-04-02 13:48:23 -0700748static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
749 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800750{
Bruce Allancef8c792008-04-02 13:48:23 -0700751 u32 pat, val;
Joe Perches2a887192007-11-13 20:53:51 -0800752 static const u32 test[] =
753 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Bruce Allancef8c792008-04-02 13:48:23 -0700754 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800755 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700756 (test[pat] & write));
757 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
758 if (val != (test[pat] & write & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700759 e_err("pattern test reg %04X failed: got 0x%08X "
760 "expected 0x%08X\n", reg + offset, val,
761 (test[pat] & 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 }
765 }
Bruce Allancef8c792008-04-02 13:48:23 -0700766 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700767}
768
Joe Perches2a887192007-11-13 20:53:51 -0800769static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
770 int reg, u32 mask, u32 write)
771{
Bruce Allancef8c792008-04-02 13:48:23 -0700772 u32 val;
Joe Perches2a887192007-11-13 20:53:51 -0800773 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700774 val = __er32(&adapter->hw, reg);
775 if ((write & mask) != (val & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700776 e_err("set/check reg %04X test failed: got 0x%08X "
777 "expected 0x%08X\n", reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800778 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700779 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800780 }
Bruce Allancef8c792008-04-02 13:48:23 -0700781 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700782}
Bruce Allancef8c792008-04-02 13:48:23 -0700783#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
784 do { \
785 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
786 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800787 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700788#define REG_PATTERN_TEST(reg, mask, write) \
789 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800790
Bruce Allancef8c792008-04-02 13:48:23 -0700791#define REG_SET_AND_CHECK(reg, mask, write) \
792 do { \
793 if (reg_set_and_check(adapter, data, reg, mask, write)) \
794 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800795 } while (0)
796
Auke Kokbc7f75f2007-09-17 12:30:59 -0700797static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
798{
799 struct e1000_hw *hw = &adapter->hw;
800 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700801 u32 value;
802 u32 before;
803 u32 after;
804 u32 i;
805 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000806 u32 mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700807
Bruce Allanad680762008-03-28 09:15:03 -0700808 /*
809 * The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700810 * Some bits that get toggled are ignored.
811 */
812 switch (mac->type) {
813 /* there are several bits on newer hardware that are r/w */
814 case e1000_82571:
815 case e1000_82572:
816 case e1000_80003es2lan:
817 toggle = 0x7FFFF3FF;
818 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000819 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700820 toggle = 0x7FFFF033;
821 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700822 }
823
824 before = er32(STATUS);
825 value = (er32(STATUS) & toggle);
826 ew32(STATUS, toggle);
827 after = er32(STATUS) & toggle;
828 if (value != after) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700829 e_err("failed STATUS register test got: 0x%08X expected: "
830 "0x%08X\n", after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700831 *data = 1;
832 return 1;
833 }
834 /* restore previous status */
835 ew32(STATUS, before);
836
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700837 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700838 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
839 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
840 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
841 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
842 }
843
844 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
845 REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
846 REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF);
847 REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF);
848 REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF);
849 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
850 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
851 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
852 REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
853 REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF);
854
855 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
856
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700857 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700858 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
859 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
860
Auke Kok86582512007-10-04 15:00:08 -0700861 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
862 REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700863 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700864 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
865 REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
866 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000867 mask = 0x8003FFFF;
868 switch (mac->type) {
869 case e1000_ich10lan:
870 case e1000_pchlan:
871 mask |= (1 << 18);
872 break;
873 default:
874 break;
875 }
Auke Kok86582512007-10-04 15:00:08 -0700876 for (i = 0; i < mac->rar_entry_count; i++)
877 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
Bruce Allana4f58f52009-06-02 11:29:18 +0000878 mask, 0xFFFFFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700879
880 for (i = 0; i < mac->mta_reg_count; i++)
881 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
882
883 *data = 0;
884 return 0;
885}
886
887static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
888{
889 u16 temp;
890 u16 checksum = 0;
891 u16 i;
892
893 *data = 0;
894 /* Read and add up the contents of the EEPROM */
895 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
896 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
897 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800898 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700899 }
900 checksum += temp;
901 }
902
903 /* If Checksum is not Correct return error else test passed */
904 if ((checksum != (u16) NVM_SUM) && !(*data))
905 *data = 2;
906
907 return *data;
908}
909
910static irqreturn_t e1000_test_intr(int irq, void *data)
911{
912 struct net_device *netdev = (struct net_device *) data;
913 struct e1000_adapter *adapter = netdev_priv(netdev);
914 struct e1000_hw *hw = &adapter->hw;
915
916 adapter->test_icr |= er32(ICR);
917
918 return IRQ_HANDLED;
919}
920
921static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
922{
923 struct net_device *netdev = adapter->netdev;
924 struct e1000_hw *hw = &adapter->hw;
925 u32 mask;
926 u32 shared_int = 1;
927 u32 irq = adapter->pdev->irq;
928 int i;
Bruce Allan4662e822008-08-26 18:37:06 -0700929 int ret_val = 0;
930 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700931
932 *data = 0;
933
Bruce Allan4662e822008-08-26 18:37:06 -0700934 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
935 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
936 int_mode = adapter->int_mode;
937 e1000e_reset_interrupt_capability(adapter);
938 adapter->int_mode = E1000E_INT_MODE_LEGACY;
939 e1000e_set_interrupt_capability(adapter);
940 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700941 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800942 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700943 netdev)) {
944 shared_int = 0;
Joe Perchesa0607fd2009-11-18 23:29:17 -0800945 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700946 netdev->name, netdev)) {
947 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700948 ret_val = -1;
949 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700950 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700951 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700952
953 /* Disable all the interrupts */
954 ew32(IMC, 0xFFFFFFFF);
955 msleep(10);
956
957 /* Test each interrupt */
958 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700959 /* Interrupt to test */
960 mask = 1 << i;
961
Bruce Allanf4187b52008-08-26 18:36:50 -0700962 if (adapter->flags & FLAG_IS_ICH) {
963 switch (mask) {
964 case E1000_ICR_RXSEQ:
965 continue;
966 case 0x00000100:
967 if (adapter->hw.mac.type == e1000_ich8lan ||
968 adapter->hw.mac.type == e1000_ich9lan)
969 continue;
970 break;
971 default:
972 break;
973 }
974 }
975
Auke Kokbc7f75f2007-09-17 12:30:59 -0700976 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700977 /*
978 * Disable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700979 * the cause register and then force the same
980 * interrupt and see if one gets posted. If
981 * an interrupt was posted to the bus, the
982 * test failed.
983 */
984 adapter->test_icr = 0;
985 ew32(IMC, mask);
986 ew32(ICS, mask);
987 msleep(10);
988
989 if (adapter->test_icr & mask) {
990 *data = 3;
991 break;
992 }
993 }
994
Bruce Allanad680762008-03-28 09:15:03 -0700995 /*
996 * Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700997 * the cause register and then force the same
998 * interrupt and see if one gets posted. If
999 * an interrupt was not posted to the bus, the
1000 * test failed.
1001 */
1002 adapter->test_icr = 0;
1003 ew32(IMS, mask);
1004 ew32(ICS, mask);
1005 msleep(10);
1006
1007 if (!(adapter->test_icr & mask)) {
1008 *data = 4;
1009 break;
1010 }
1011
1012 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -07001013 /*
1014 * Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001015 * the cause register and then force the other
1016 * interrupts and see if any get posted. If
1017 * an interrupt was posted to the bus, the
1018 * test failed.
1019 */
1020 adapter->test_icr = 0;
1021 ew32(IMC, ~mask & 0x00007FFF);
1022 ew32(ICS, ~mask & 0x00007FFF);
1023 msleep(10);
1024
1025 if (adapter->test_icr) {
1026 *data = 5;
1027 break;
1028 }
1029 }
1030 }
1031
1032 /* Disable all the interrupts */
1033 ew32(IMC, 0xFFFFFFFF);
1034 msleep(10);
1035
1036 /* Unhook test interrupt handler */
1037 free_irq(irq, netdev);
1038
Bruce Allan4662e822008-08-26 18:37:06 -07001039out:
1040 if (int_mode == E1000E_INT_MODE_MSIX) {
1041 e1000e_reset_interrupt_capability(adapter);
1042 adapter->int_mode = int_mode;
1043 e1000e_set_interrupt_capability(adapter);
1044 }
1045
1046 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001047}
1048
1049static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1050{
1051 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1052 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1053 struct pci_dev *pdev = adapter->pdev;
1054 int i;
1055
1056 if (tx_ring->desc && tx_ring->buffer_info) {
1057 for (i = 0; i < tx_ring->count; i++) {
1058 if (tx_ring->buffer_info[i].dma)
1059 pci_unmap_single(pdev,
1060 tx_ring->buffer_info[i].dma,
1061 tx_ring->buffer_info[i].length,
1062 PCI_DMA_TODEVICE);
1063 if (tx_ring->buffer_info[i].skb)
1064 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1065 }
1066 }
1067
1068 if (rx_ring->desc && rx_ring->buffer_info) {
1069 for (i = 0; i < rx_ring->count; i++) {
1070 if (rx_ring->buffer_info[i].dma)
1071 pci_unmap_single(pdev,
1072 rx_ring->buffer_info[i].dma,
1073 2048, PCI_DMA_FROMDEVICE);
1074 if (rx_ring->buffer_info[i].skb)
1075 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1076 }
1077 }
1078
1079 if (tx_ring->desc) {
1080 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1081 tx_ring->dma);
1082 tx_ring->desc = NULL;
1083 }
1084 if (rx_ring->desc) {
1085 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1086 rx_ring->dma);
1087 rx_ring->desc = NULL;
1088 }
1089
1090 kfree(tx_ring->buffer_info);
1091 tx_ring->buffer_info = NULL;
1092 kfree(rx_ring->buffer_info);
1093 rx_ring->buffer_info = NULL;
1094}
1095
1096static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1097{
1098 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1099 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1100 struct pci_dev *pdev = adapter->pdev;
1101 struct e1000_hw *hw = &adapter->hw;
1102 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001103 int i;
1104 int ret_val;
1105
1106 /* Setup Tx descriptor ring and Tx buffers */
1107
1108 if (!tx_ring->count)
1109 tx_ring->count = E1000_DEFAULT_TXD;
1110
Bruce Allancef8c792008-04-02 13:48:23 -07001111 tx_ring->buffer_info = kcalloc(tx_ring->count,
1112 sizeof(struct e1000_buffer),
1113 GFP_KERNEL);
1114 if (!(tx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001115 ret_val = 1;
1116 goto err_nomem;
1117 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001118
1119 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1120 tx_ring->size = ALIGN(tx_ring->size, 4096);
1121 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1122 &tx_ring->dma, GFP_KERNEL);
1123 if (!tx_ring->desc) {
1124 ret_val = 2;
1125 goto err_nomem;
1126 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001127 tx_ring->next_to_use = 0;
1128 tx_ring->next_to_clean = 0;
1129
Bruce Allancef8c792008-04-02 13:48:23 -07001130 ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001131 ew32(TDBAH, ((u64) tx_ring->dma >> 32));
Bruce Allancef8c792008-04-02 13:48:23 -07001132 ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001133 ew32(TDH, 0);
1134 ew32(TDT, 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001135 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1136 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1137 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001138
1139 for (i = 0; i < tx_ring->count; i++) {
1140 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1141 struct sk_buff *skb;
1142 unsigned int skb_size = 1024;
1143
1144 skb = alloc_skb(skb_size, GFP_KERNEL);
1145 if (!skb) {
1146 ret_val = 3;
1147 goto err_nomem;
1148 }
1149 skb_put(skb, skb_size);
1150 tx_ring->buffer_info[i].skb = skb;
1151 tx_ring->buffer_info[i].length = skb->len;
1152 tx_ring->buffer_info[i].dma =
1153 pci_map_single(pdev, skb->data, skb->len,
1154 PCI_DMA_TODEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001155 if (pci_dma_mapping_error(pdev, tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001156 ret_val = 4;
1157 goto err_nomem;
1158 }
Bruce Allancef8c792008-04-02 13:48:23 -07001159 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001160 tx_desc->lower.data = cpu_to_le32(skb->len);
1161 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1162 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001163 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001164 tx_desc->upper.data = 0;
1165 }
1166
1167 /* Setup Rx descriptor ring and Rx buffers */
1168
1169 if (!rx_ring->count)
1170 rx_ring->count = E1000_DEFAULT_RXD;
1171
Bruce Allancef8c792008-04-02 13:48:23 -07001172 rx_ring->buffer_info = kcalloc(rx_ring->count,
1173 sizeof(struct e1000_buffer),
1174 GFP_KERNEL);
1175 if (!(rx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001176 ret_val = 5;
1177 goto err_nomem;
1178 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001179
1180 rx_ring->size = rx_ring->count * sizeof(struct e1000_rx_desc);
1181 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1182 &rx_ring->dma, GFP_KERNEL);
1183 if (!rx_ring->desc) {
1184 ret_val = 6;
1185 goto err_nomem;
1186 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001187 rx_ring->next_to_use = 0;
1188 rx_ring->next_to_clean = 0;
1189
1190 rctl = er32(RCTL);
1191 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1192 ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
1193 ew32(RDBAH, ((u64) rx_ring->dma >> 32));
1194 ew32(RDLEN, rx_ring->size);
1195 ew32(RDH, 0);
1196 ew32(RDT, 0);
1197 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allancef8c792008-04-02 13:48:23 -07001198 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1199 E1000_RCTL_SBP | E1000_RCTL_SECRC |
Auke Kokbc7f75f2007-09-17 12:30:59 -07001200 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1201 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1202 ew32(RCTL, rctl);
1203
1204 for (i = 0; i < rx_ring->count; i++) {
1205 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
1206 struct sk_buff *skb;
1207
1208 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1209 if (!skb) {
1210 ret_val = 7;
1211 goto err_nomem;
1212 }
1213 skb_reserve(skb, NET_IP_ALIGN);
1214 rx_ring->buffer_info[i].skb = skb;
1215 rx_ring->buffer_info[i].dma =
1216 pci_map_single(pdev, skb->data, 2048,
1217 PCI_DMA_FROMDEVICE);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001218 if (pci_dma_mapping_error(pdev, rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001219 ret_val = 8;
1220 goto err_nomem;
1221 }
1222 rx_desc->buffer_addr =
1223 cpu_to_le64(rx_ring->buffer_info[i].dma);
1224 memset(skb->data, 0x00, skb->len);
1225 }
1226
1227 return 0;
1228
1229err_nomem:
1230 e1000_free_desc_rings(adapter);
1231 return ret_val;
1232}
1233
1234static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1235{
1236 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1237 e1e_wphy(&adapter->hw, 29, 0x001F);
1238 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1239 e1e_wphy(&adapter->hw, 29, 0x001A);
1240 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1241}
1242
1243static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1244{
1245 struct e1000_hw *hw = &adapter->hw;
1246 u32 ctrl_reg = 0;
1247 u32 stat_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001248 u16 phy_reg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001249
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001250 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001251
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001252 if (hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001253 /* Auto-MDI/MDIX Off */
1254 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1255 /* reset to update Auto-MDI/MDIX */
1256 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1257 /* autoneg off */
1258 e1e_wphy(hw, PHY_CONTROL, 0x8140);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001259 } else if (hw->phy.type == e1000_phy_gg82563)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001260 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
1261
1262 ctrl_reg = er32(CTRL);
1263
Bruce Allancef8c792008-04-02 13:48:23 -07001264 switch (hw->phy.type) {
1265 case e1000_phy_ife:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001266 /* force 100, set loopback */
1267 e1e_wphy(hw, PHY_CONTROL, 0x6100);
1268
1269 /* Now set up the MAC to the same speed/duplex as the PHY. */
1270 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1271 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1272 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1273 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1274 E1000_CTRL_FD); /* Force Duplex to FULL */
Bruce Allancef8c792008-04-02 13:48:23 -07001275 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001276 case e1000_phy_bm:
1277 /* Set Default MAC Interface speed to 1GB */
1278 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1279 phy_reg &= ~0x0007;
1280 phy_reg |= 0x006;
1281 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1282 /* Assert SW reset for above settings to take effect */
1283 e1000e_commit_phy(hw);
1284 mdelay(1);
1285 /* Force Full Duplex */
1286 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1287 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1288 /* Set Link Up (in force link) */
1289 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1290 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1291 /* Force Link */
1292 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1293 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1294 /* Set Early Link Enable */
1295 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1296 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
1297 /* fall through */
Bruce Allancef8c792008-04-02 13:48:23 -07001298 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001299 /* force 1000, set loopback */
1300 e1e_wphy(hw, PHY_CONTROL, 0x4140);
Bruce Allancef8c792008-04-02 13:48:23 -07001301 mdelay(250);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001302
1303 /* Now set up the MAC to the same speed/duplex as the PHY. */
1304 ctrl_reg = er32(CTRL);
1305 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1306 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1307 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1308 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1309 E1000_CTRL_FD); /* Force Duplex to FULL */
Bruce Allancef8c792008-04-02 13:48:23 -07001310
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001311 if (adapter->flags & FLAG_IS_ICH)
Bruce Allancef8c792008-04-02 13:48:23 -07001312 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001313 }
1314
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001315 if (hw->phy.media_type == e1000_media_type_copper &&
1316 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001317 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1318 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001319 /*
1320 * Set the ILOS bit on the fiber Nic if half duplex link is
1321 * detected.
1322 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001323 stat_reg = er32(STATUS);
1324 if ((stat_reg & E1000_STATUS_FD) == 0)
1325 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1326 }
1327
1328 ew32(CTRL, ctrl_reg);
1329
Bruce Allanad680762008-03-28 09:15:03 -07001330 /*
1331 * Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001332 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1333 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001334 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001335 e1000_phy_disable_receiver(adapter);
1336
1337 udelay(500);
1338
1339 return 0;
1340}
1341
1342static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1343{
1344 struct e1000_hw *hw = &adapter->hw;
1345 u32 ctrl = er32(CTRL);
1346 int link = 0;
1347
1348 /* special requirements for 82571/82572 fiber adapters */
1349
Bruce Allanad680762008-03-28 09:15:03 -07001350 /*
1351 * jump through hoops to make sure link is up because serdes
1352 * link is hardwired up
1353 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001354 ctrl |= E1000_CTRL_SLU;
1355 ew32(CTRL, ctrl);
1356
1357 /* disable autoneg */
1358 ctrl = er32(TXCW);
1359 ctrl &= ~(1 << 31);
1360 ew32(TXCW, ctrl);
1361
1362 link = (er32(STATUS) & E1000_STATUS_LU);
1363
1364 if (!link) {
1365 /* set invert loss of signal */
1366 ctrl = er32(CTRL);
1367 ctrl |= E1000_CTRL_ILOS;
1368 ew32(CTRL, ctrl);
1369 }
1370
Bruce Allanad680762008-03-28 09:15:03 -07001371 /*
1372 * special write to serdes control register to enable SerDes analog
1373 * loopback
1374 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001375#define E1000_SERDES_LB_ON 0x410
1376 ew32(SCTL, E1000_SERDES_LB_ON);
1377 msleep(10);
1378
1379 return 0;
1380}
1381
1382/* only call this for fiber/serdes connections to es2lan */
1383static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1384{
1385 struct e1000_hw *hw = &adapter->hw;
1386 u32 ctrlext = er32(CTRL_EXT);
1387 u32 ctrl = er32(CTRL);
1388
Bruce Allanad680762008-03-28 09:15:03 -07001389 /*
1390 * save CTRL_EXT to restore later, reuse an empty variable (unused
1391 * on mac_type 80003es2lan)
1392 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001393 adapter->tx_fifo_head = ctrlext;
1394
1395 /* clear the serdes mode bits, putting the device into mac loopback */
1396 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1397 ew32(CTRL_EXT, ctrlext);
1398
1399 /* force speed to 1000/FD, link up */
1400 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1401 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1402 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1403 ew32(CTRL, ctrl);
1404
1405 /* set mac loopback */
1406 ctrl = er32(RCTL);
1407 ctrl |= E1000_RCTL_LBM_MAC;
1408 ew32(RCTL, ctrl);
1409
1410 /* set testing mode parameters (no need to reset later) */
1411#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1412#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1413 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001414 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001415
1416 return 0;
1417}
1418
1419static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1420{
1421 struct e1000_hw *hw = &adapter->hw;
1422 u32 rctl;
1423
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001424 if (hw->phy.media_type == e1000_media_type_fiber ||
1425 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001426 switch (hw->mac.type) {
1427 case e1000_80003es2lan:
1428 return e1000_set_es2lan_mac_loopback(adapter);
1429 break;
1430 case e1000_82571:
1431 case e1000_82572:
1432 return e1000_set_82571_fiber_loopback(adapter);
1433 break;
1434 default:
1435 rctl = er32(RCTL);
1436 rctl |= E1000_RCTL_LBM_TCVR;
1437 ew32(RCTL, rctl);
1438 return 0;
1439 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001440 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001441 return e1000_integrated_phy_loopback(adapter);
1442 }
1443
1444 return 7;
1445}
1446
1447static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1448{
1449 struct e1000_hw *hw = &adapter->hw;
1450 u32 rctl;
1451 u16 phy_reg;
1452
1453 rctl = er32(RCTL);
1454 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1455 ew32(RCTL, rctl);
1456
1457 switch (hw->mac.type) {
1458 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001459 if (hw->phy.media_type == e1000_media_type_fiber ||
1460 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001461 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001462 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001463 adapter->tx_fifo_head = 0;
1464 }
1465 /* fall through */
1466 case e1000_82571:
1467 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001468 if (hw->phy.media_type == e1000_media_type_fiber ||
1469 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001470#define E1000_SERDES_LB_OFF 0x400
1471 ew32(SCTL, E1000_SERDES_LB_OFF);
1472 msleep(10);
1473 break;
1474 }
1475 /* Fall Through */
1476 default:
1477 hw->mac.autoneg = 1;
1478 if (hw->phy.type == e1000_phy_gg82563)
1479 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1480 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1481 if (phy_reg & MII_CR_LOOPBACK) {
1482 phy_reg &= ~MII_CR_LOOPBACK;
1483 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1484 e1000e_commit_phy(hw);
1485 }
1486 break;
1487 }
1488}
1489
1490static void e1000_create_lbtest_frame(struct sk_buff *skb,
1491 unsigned int frame_size)
1492{
1493 memset(skb->data, 0xFF, frame_size);
1494 frame_size &= ~1;
1495 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1496 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1497 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1498}
1499
1500static int e1000_check_lbtest_frame(struct sk_buff *skb,
1501 unsigned int frame_size)
1502{
1503 frame_size &= ~1;
1504 if (*(skb->data + 3) == 0xFF)
1505 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1506 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1507 return 0;
1508 return 13;
1509}
1510
1511static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1512{
1513 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1514 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1515 struct pci_dev *pdev = adapter->pdev;
1516 struct e1000_hw *hw = &adapter->hw;
1517 int i, j, k, l;
1518 int lc;
1519 int good_cnt;
1520 int ret_val = 0;
1521 unsigned long time;
1522
1523 ew32(RDT, rx_ring->count - 1);
1524
Bruce Allanad680762008-03-28 09:15:03 -07001525 /*
1526 * Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001527 * The idea is to wrap the largest ring a number of times using 64
1528 * send/receive pairs during each loop
1529 */
1530
1531 if (rx_ring->count <= tx_ring->count)
1532 lc = ((tx_ring->count / 64) * 2) + 1;
1533 else
1534 lc = ((rx_ring->count / 64) * 2) + 1;
1535
1536 k = 0;
1537 l = 0;
1538 for (j = 0; j <= lc; j++) { /* loop count loop */
1539 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001540 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1541 1024);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001542 pci_dma_sync_single_for_device(pdev,
1543 tx_ring->buffer_info[k].dma,
1544 tx_ring->buffer_info[k].length,
1545 PCI_DMA_TODEVICE);
1546 k++;
1547 if (k == tx_ring->count)
1548 k = 0;
1549 }
1550 ew32(TDT, k);
1551 msleep(200);
1552 time = jiffies; /* set the start time for the receive */
1553 good_cnt = 0;
1554 do { /* receive the sent packets */
1555 pci_dma_sync_single_for_cpu(pdev,
1556 rx_ring->buffer_info[l].dma, 2048,
1557 PCI_DMA_FROMDEVICE);
1558
1559 ret_val = e1000_check_lbtest_frame(
1560 rx_ring->buffer_info[l].skb, 1024);
1561 if (!ret_val)
1562 good_cnt++;
1563 l++;
1564 if (l == rx_ring->count)
1565 l = 0;
Bruce Allanad680762008-03-28 09:15:03 -07001566 /*
1567 * time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001568 * enough time to complete the receives, if it's
1569 * exceeded, break and error off
1570 */
1571 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1572 if (good_cnt != 64) {
1573 ret_val = 13; /* ret_val is the same as mis-compare */
1574 break;
1575 }
Bruce Allancef8c792008-04-02 13:48:23 -07001576 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001577 ret_val = 14; /* error code for time out error */
1578 break;
1579 }
1580 } /* end loop count loop */
1581 return ret_val;
1582}
1583
1584static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1585{
Bruce Allanad680762008-03-28 09:15:03 -07001586 /*
1587 * PHY loopback cannot be performed if SoL/IDER
1588 * sessions are active
1589 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001590 if (e1000_check_reset_block(&adapter->hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001591 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001592 *data = 0;
1593 goto out;
1594 }
1595
1596 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001597 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001598 goto out;
1599
1600 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001601 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001602 goto err_loopback;
1603
1604 *data = e1000_run_loopback_test(adapter);
1605 e1000_loopback_cleanup(adapter);
1606
1607err_loopback:
1608 e1000_free_desc_rings(adapter);
1609out:
1610 return *data;
1611}
1612
1613static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1614{
1615 struct e1000_hw *hw = &adapter->hw;
1616
1617 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001618 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001619 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001620 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001621
Bruce Allanad680762008-03-28 09:15:03 -07001622 /*
1623 * On some blade server designs, link establishment
1624 * could take as long as 2-3 minutes
1625 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001626 do {
1627 hw->mac.ops.check_for_link(hw);
1628 if (hw->mac.serdes_has_link)
1629 return *data;
1630 msleep(20);
1631 } while (i++ < 3750);
1632
1633 *data = 1;
1634 } else {
1635 hw->mac.ops.check_for_link(hw);
1636 if (hw->mac.autoneg)
1637 msleep(4000);
1638
1639 if (!(er32(STATUS) &
1640 E1000_STATUS_LU))
1641 *data = 1;
1642 }
1643 return *data;
1644}
1645
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001646static int e1000e_get_sset_count(struct net_device *netdev, int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001647{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001648 switch (sset) {
1649 case ETH_SS_TEST:
1650 return E1000_TEST_LEN;
1651 case ETH_SS_STATS:
1652 return E1000_STATS_LEN;
1653 default:
1654 return -EOPNOTSUPP;
1655 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001656}
1657
1658static void e1000_diag_test(struct net_device *netdev,
1659 struct ethtool_test *eth_test, u64 *data)
1660{
1661 struct e1000_adapter *adapter = netdev_priv(netdev);
1662 u16 autoneg_advertised;
1663 u8 forced_speed_duplex;
1664 u8 autoneg;
1665 bool if_running = netif_running(netdev);
1666
1667 set_bit(__E1000_TESTING, &adapter->state);
1668 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1669 /* Offline tests */
1670
1671 /* save speed, duplex, autoneg settings */
1672 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1673 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1674 autoneg = adapter->hw.mac.autoneg;
1675
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001676 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001677
Bruce Allanad680762008-03-28 09:15:03 -07001678 /*
1679 * Link test performed before hardware reset so autoneg doesn't
1680 * interfere with test result
1681 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001682 if (e1000_link_test(adapter, &data[4]))
1683 eth_test->flags |= ETH_TEST_FL_FAILED;
1684
1685 if (if_running)
1686 /* indicate we're in test mode */
1687 dev_close(netdev);
1688 else
1689 e1000e_reset(adapter);
1690
1691 if (e1000_reg_test(adapter, &data[0]))
1692 eth_test->flags |= ETH_TEST_FL_FAILED;
1693
1694 e1000e_reset(adapter);
1695 if (e1000_eeprom_test(adapter, &data[1]))
1696 eth_test->flags |= ETH_TEST_FL_FAILED;
1697
1698 e1000e_reset(adapter);
1699 if (e1000_intr_test(adapter, &data[2]))
1700 eth_test->flags |= ETH_TEST_FL_FAILED;
1701
1702 e1000e_reset(adapter);
1703 /* make sure the phy is powered up */
1704 e1000e_power_up_phy(adapter);
1705 if (e1000_loopback_test(adapter, &data[3]))
1706 eth_test->flags |= ETH_TEST_FL_FAILED;
1707
1708 /* restore speed, duplex, autoneg settings */
1709 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1710 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1711 adapter->hw.mac.autoneg = autoneg;
1712
1713 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001714 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001715 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001716 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001717
1718 clear_bit(__E1000_TESTING, &adapter->state);
1719 if (if_running)
1720 dev_open(netdev);
1721 } else {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001722 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001723 /* Online tests */
1724 if (e1000_link_test(adapter, &data[4]))
1725 eth_test->flags |= ETH_TEST_FL_FAILED;
1726
1727 /* Online tests aren't run; pass by default */
1728 data[0] = 0;
1729 data[1] = 0;
1730 data[2] = 0;
1731 data[3] = 0;
1732
1733 clear_bit(__E1000_TESTING, &adapter->state);
1734 }
1735 msleep_interruptible(4 * 1000);
1736}
1737
1738static void e1000_get_wol(struct net_device *netdev,
1739 struct ethtool_wolinfo *wol)
1740{
1741 struct e1000_adapter *adapter = netdev_priv(netdev);
1742
1743 wol->supported = 0;
1744 wol->wolopts = 0;
1745
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001746 if (!(adapter->flags & FLAG_HAS_WOL) ||
1747 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001748 return;
1749
1750 wol->supported = WAKE_UCAST | WAKE_MCAST |
Mitch Williamsefb90e42008-01-29 12:43:02 -08001751 WAKE_BCAST | WAKE_MAGIC |
1752 WAKE_PHY | WAKE_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001753
1754 /* apply any specific unsupported masks here */
1755 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1756 wol->supported &= ~WAKE_UCAST;
1757
1758 if (adapter->wol & E1000_WUFC_EX)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001759 e_err("Interface does not support directed (unicast) "
1760 "frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001761 }
1762
1763 if (adapter->wol & E1000_WUFC_EX)
1764 wol->wolopts |= WAKE_UCAST;
1765 if (adapter->wol & E1000_WUFC_MC)
1766 wol->wolopts |= WAKE_MCAST;
1767 if (adapter->wol & E1000_WUFC_BC)
1768 wol->wolopts |= WAKE_BCAST;
1769 if (adapter->wol & E1000_WUFC_MAG)
1770 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001771 if (adapter->wol & E1000_WUFC_LNKC)
1772 wol->wolopts |= WAKE_PHY;
1773 if (adapter->wol & E1000_WUFC_ARP)
1774 wol->wolopts |= WAKE_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001775}
1776
1777static int e1000_set_wol(struct net_device *netdev,
1778 struct ethtool_wolinfo *wol)
1779{
1780 struct e1000_adapter *adapter = netdev_priv(netdev);
1781
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001782 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001783 !device_can_wakeup(&adapter->pdev->dev) ||
1784 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
1785 WAKE_MAGIC | WAKE_PHY | WAKE_ARP)))
1786 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001787
1788 /* these settings will always override what we currently have */
1789 adapter->wol = 0;
1790
1791 if (wol->wolopts & WAKE_UCAST)
1792 adapter->wol |= E1000_WUFC_EX;
1793 if (wol->wolopts & WAKE_MCAST)
1794 adapter->wol |= E1000_WUFC_MC;
1795 if (wol->wolopts & WAKE_BCAST)
1796 adapter->wol |= E1000_WUFC_BC;
1797 if (wol->wolopts & WAKE_MAGIC)
1798 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001799 if (wol->wolopts & WAKE_PHY)
1800 adapter->wol |= E1000_WUFC_LNKC;
1801 if (wol->wolopts & WAKE_ARP)
1802 adapter->wol |= E1000_WUFC_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001803
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001804 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1805
Auke Kokbc7f75f2007-09-17 12:30:59 -07001806 return 0;
1807}
1808
1809/* toggle LED 4 times per second = 2 "blinks" per second */
1810#define E1000_ID_INTERVAL (HZ/4)
1811
1812/* bit defines for adapter->led_status */
1813#define E1000_LED_ON 0
1814
Bruce Allana4f58f52009-06-02 11:29:18 +00001815static void e1000e_led_blink_task(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001816{
Bruce Allana4f58f52009-06-02 11:29:18 +00001817 struct e1000_adapter *adapter = container_of(work,
1818 struct e1000_adapter, led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001819
1820 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
1821 adapter->hw.mac.ops.led_off(&adapter->hw);
1822 else
1823 adapter->hw.mac.ops.led_on(&adapter->hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001824}
Auke Kokbc7f75f2007-09-17 12:30:59 -07001825
Bruce Allana4f58f52009-06-02 11:29:18 +00001826static void e1000_led_blink_callback(unsigned long data)
1827{
1828 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1829
1830 schedule_work(&adapter->led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001831 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1832}
1833
1834static int e1000_phys_id(struct net_device *netdev, u32 data)
1835{
1836 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001837 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001838
Stephen Hemminger5a9147b2007-10-29 10:46:05 -07001839 if (!data)
1840 data = INT_MAX;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001841
Bruce Allan4662e822008-08-26 18:37:06 -07001842 if ((hw->phy.type == e1000_phy_ife) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00001843 (hw->mac.type == e1000_pchlan) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +00001844 (hw->mac.type == e1000_82583) ||
Bruce Allan4662e822008-08-26 18:37:06 -07001845 (hw->mac.type == e1000_82574)) {
Bruce Allana4f58f52009-06-02 11:29:18 +00001846 INIT_WORK(&adapter->led_blink_task, e1000e_led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001847 if (!adapter->blink_timer.function) {
1848 init_timer(&adapter->blink_timer);
1849 adapter->blink_timer.function =
1850 e1000_led_blink_callback;
1851 adapter->blink_timer.data = (unsigned long) adapter;
1852 }
1853 mod_timer(&adapter->blink_timer, jiffies);
1854 msleep_interruptible(data * 1000);
1855 del_timer_sync(&adapter->blink_timer);
Bruce Allan4662e822008-08-26 18:37:06 -07001856 if (hw->phy.type == e1000_phy_ife)
1857 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001858 } else {
Bruce Allan4662e822008-08-26 18:37:06 -07001859 e1000e_blink_led(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001860 msleep_interruptible(data * 1000);
1861 }
1862
Bruce Allan4662e822008-08-26 18:37:06 -07001863 hw->mac.ops.led_off(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001864 clear_bit(E1000_LED_ON, &adapter->led_status);
Bruce Allan4662e822008-08-26 18:37:06 -07001865 hw->mac.ops.cleanup_led(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001866
1867 return 0;
1868}
1869
Auke Kokde5b3072008-04-23 11:09:08 -07001870static int e1000_get_coalesce(struct net_device *netdev,
1871 struct ethtool_coalesce *ec)
1872{
1873 struct e1000_adapter *adapter = netdev_priv(netdev);
1874
1875 if (adapter->itr_setting <= 3)
1876 ec->rx_coalesce_usecs = adapter->itr_setting;
1877 else
1878 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1879
1880 return 0;
1881}
1882
1883static int e1000_set_coalesce(struct net_device *netdev,
1884 struct ethtool_coalesce *ec)
1885{
1886 struct e1000_adapter *adapter = netdev_priv(netdev);
1887 struct e1000_hw *hw = &adapter->hw;
1888
1889 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
1890 ((ec->rx_coalesce_usecs > 3) &&
1891 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1892 (ec->rx_coalesce_usecs == 2))
1893 return -EINVAL;
1894
1895 if (ec->rx_coalesce_usecs <= 3) {
1896 adapter->itr = 20000;
1897 adapter->itr_setting = ec->rx_coalesce_usecs;
1898 } else {
1899 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1900 adapter->itr_setting = adapter->itr & ~3;
1901 }
1902
1903 if (adapter->itr_setting != 0)
1904 ew32(ITR, 1000000000 / (adapter->itr * 256));
1905 else
1906 ew32(ITR, 0);
1907
1908 return 0;
1909}
1910
Auke Kokbc7f75f2007-09-17 12:30:59 -07001911static int e1000_nway_reset(struct net_device *netdev)
1912{
1913 struct e1000_adapter *adapter = netdev_priv(netdev);
1914 if (netif_running(netdev))
1915 e1000e_reinit_locked(adapter);
1916 return 0;
1917}
1918
Auke Kokbc7f75f2007-09-17 12:30:59 -07001919static void e1000_get_ethtool_stats(struct net_device *netdev,
1920 struct ethtool_stats *stats,
1921 u64 *data)
1922{
1923 struct e1000_adapter *adapter = netdev_priv(netdev);
1924 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001925 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001926
1927 e1000e_update_stats(adapter);
1928 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001929 switch (e1000_gstrings_stats[i].type) {
1930 case NETDEV_STATS:
1931 p = (char *) netdev +
1932 e1000_gstrings_stats[i].stat_offset;
1933 break;
1934 case E1000_STATS:
1935 p = (char *) adapter +
1936 e1000_gstrings_stats[i].stat_offset;
1937 break;
1938 }
1939
Auke Kokbc7f75f2007-09-17 12:30:59 -07001940 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1941 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1942 }
1943}
1944
1945static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1946 u8 *data)
1947{
1948 u8 *p = data;
1949 int i;
1950
1951 switch (stringset) {
1952 case ETH_SS_TEST:
Bruce Allanad680762008-03-28 09:15:03 -07001953 memcpy(data, *e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001954 break;
1955 case ETH_SS_STATS:
1956 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1957 memcpy(p, e1000_gstrings_stats[i].stat_string,
1958 ETH_GSTRING_LEN);
1959 p += ETH_GSTRING_LEN;
1960 }
1961 break;
1962 }
1963}
1964
1965static const struct ethtool_ops e1000_ethtool_ops = {
1966 .get_settings = e1000_get_settings,
1967 .set_settings = e1000_set_settings,
1968 .get_drvinfo = e1000_get_drvinfo,
1969 .get_regs_len = e1000_get_regs_len,
1970 .get_regs = e1000_get_regs,
1971 .get_wol = e1000_get_wol,
1972 .set_wol = e1000_set_wol,
1973 .get_msglevel = e1000_get_msglevel,
1974 .set_msglevel = e1000_set_msglevel,
1975 .nway_reset = e1000_nway_reset,
Auke Kok369d7422007-10-15 14:30:59 -07001976 .get_link = e1000_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001977 .get_eeprom_len = e1000_get_eeprom_len,
1978 .get_eeprom = e1000_get_eeprom,
1979 .set_eeprom = e1000_set_eeprom,
1980 .get_ringparam = e1000_get_ringparam,
1981 .set_ringparam = e1000_set_ringparam,
1982 .get_pauseparam = e1000_get_pauseparam,
1983 .set_pauseparam = e1000_set_pauseparam,
1984 .get_rx_csum = e1000_get_rx_csum,
1985 .set_rx_csum = e1000_set_rx_csum,
1986 .get_tx_csum = e1000_get_tx_csum,
1987 .set_tx_csum = e1000_set_tx_csum,
1988 .get_sg = ethtool_op_get_sg,
1989 .set_sg = ethtool_op_set_sg,
1990 .get_tso = ethtool_op_get_tso,
1991 .set_tso = e1000_set_tso,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001992 .self_test = e1000_diag_test,
1993 .get_strings = e1000_get_strings,
1994 .phys_id = e1000_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001995 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001996 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07001997 .get_coalesce = e1000_get_coalesce,
1998 .set_coalesce = e1000_set_coalesce,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001999};
2000
2001void e1000e_set_ethtool_ops(struct net_device *netdev)
2002{
2003 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
2004}