blob: 0c085992546836ce583700c052043a37a3b7157c [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allan0d6057e2011-01-04 01:16:44 +00004 Copyright(c) 1999 - 2011 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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
Auke Kokbc7f75f2007-09-17 12:30:59 -070035#include <linux/delay.h>
36
37#include "e1000.h"
38
Ajit Khapardee0f36a92009-10-13 01:45:09 +000039enum {NETDEV_STATS, E1000_STATS};
40
Auke Kokbc7f75f2007-09-17 12:30:59 -070041struct e1000_stats {
42 char stat_string[ETH_GSTRING_LEN];
Ajit Khapardee0f36a92009-10-13 01:45:09 +000043 int type;
Auke Kokbc7f75f2007-09-17 12:30:59 -070044 int sizeof_stat;
45 int stat_offset;
46};
47
Bruce Allanf0f1a172010-12-11 05:53:32 +000048#define E1000_STAT(str, m) { \
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000049 .stat_string = str, \
50 .type = E1000_STATS, \
51 .sizeof_stat = sizeof(((struct e1000_adapter *)0)->m), \
52 .stat_offset = offsetof(struct e1000_adapter, m) }
Bruce Allanf0f1a172010-12-11 05:53:32 +000053#define E1000_NETDEV_STAT(str, m) { \
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000054 .stat_string = str, \
55 .type = NETDEV_STATS, \
56 .sizeof_stat = sizeof(((struct rtnl_link_stats64 *)0)->m), \
57 .stat_offset = offsetof(struct rtnl_link_stats64, m) }
Ajit Khapardee0f36a92009-10-13 01:45:09 +000058
Auke Kokbc7f75f2007-09-17 12:30:59 -070059static const struct e1000_stats e1000_gstrings_stats[] = {
Bruce Allanf0f1a172010-12-11 05:53:32 +000060 E1000_STAT("rx_packets", stats.gprc),
61 E1000_STAT("tx_packets", stats.gptc),
62 E1000_STAT("rx_bytes", stats.gorc),
63 E1000_STAT("tx_bytes", stats.gotc),
64 E1000_STAT("rx_broadcast", stats.bprc),
65 E1000_STAT("tx_broadcast", stats.bptc),
66 E1000_STAT("rx_multicast", stats.mprc),
67 E1000_STAT("tx_multicast", stats.mptc),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000068 E1000_NETDEV_STAT("rx_errors", rx_errors),
69 E1000_NETDEV_STAT("tx_errors", tx_errors),
70 E1000_NETDEV_STAT("tx_dropped", tx_dropped),
Bruce Allanf0f1a172010-12-11 05:53:32 +000071 E1000_STAT("multicast", stats.mprc),
72 E1000_STAT("collisions", stats.colc),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000073 E1000_NETDEV_STAT("rx_length_errors", rx_length_errors),
74 E1000_NETDEV_STAT("rx_over_errors", rx_over_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000075 E1000_STAT("rx_crc_errors", stats.crcerrs),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000076 E1000_NETDEV_STAT("rx_frame_errors", rx_frame_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000077 E1000_STAT("rx_no_buffer_count", stats.rnbc),
78 E1000_STAT("rx_missed_errors", stats.mpc),
79 E1000_STAT("tx_aborted_errors", stats.ecol),
80 E1000_STAT("tx_carrier_errors", stats.tncrs),
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +000081 E1000_NETDEV_STAT("tx_fifo_errors", tx_fifo_errors),
82 E1000_NETDEV_STAT("tx_heartbeat_errors", tx_heartbeat_errors),
Bruce Allanf0f1a172010-12-11 05:53:32 +000083 E1000_STAT("tx_window_errors", stats.latecol),
84 E1000_STAT("tx_abort_late_coll", stats.latecol),
85 E1000_STAT("tx_deferred_ok", stats.dc),
86 E1000_STAT("tx_single_coll_ok", stats.scc),
87 E1000_STAT("tx_multi_coll_ok", stats.mcc),
88 E1000_STAT("tx_timeout_count", tx_timeout_count),
89 E1000_STAT("tx_restart_queue", restart_queue),
90 E1000_STAT("rx_long_length_errors", stats.roc),
91 E1000_STAT("rx_short_length_errors", stats.ruc),
92 E1000_STAT("rx_align_errors", stats.algnerrc),
93 E1000_STAT("tx_tcp_seg_good", stats.tsctc),
94 E1000_STAT("tx_tcp_seg_failed", stats.tsctfc),
95 E1000_STAT("rx_flow_control_xon", stats.xonrxc),
96 E1000_STAT("rx_flow_control_xoff", stats.xoffrxc),
97 E1000_STAT("tx_flow_control_xon", stats.xontxc),
98 E1000_STAT("tx_flow_control_xoff", stats.xofftxc),
99 E1000_STAT("rx_long_byte_count", stats.gorc),
100 E1000_STAT("rx_csum_offload_good", hw_csum_good),
101 E1000_STAT("rx_csum_offload_errors", hw_csum_err),
102 E1000_STAT("rx_header_split", rx_hdr_split),
103 E1000_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),
104 E1000_STAT("tx_smbus", stats.mgptc),
105 E1000_STAT("rx_smbus", stats.mgprc),
106 E1000_STAT("dropped_smbus", stats.mgpdc),
107 E1000_STAT("rx_dma_failed", rx_dma_failed),
108 E1000_STAT("tx_dma_failed", tx_dma_failed),
Auke Kokbc7f75f2007-09-17 12:30:59 -0700109};
110
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200111#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700112#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN)
113static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
114 "Register test (offline)", "Eeprom test (offline)",
115 "Interrupt test (offline)", "Loopback test (offline)",
116 "Link test (on/offline)"
117};
Bruce Allanad680762008-03-28 09:15:03 -0700118#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700119
120static int e1000_get_settings(struct net_device *netdev,
121 struct ethtool_cmd *ecmd)
122{
123 struct e1000_adapter *adapter = netdev_priv(netdev);
124 struct e1000_hw *hw = &adapter->hw;
125
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700126 if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700127
128 ecmd->supported = (SUPPORTED_10baseT_Half |
129 SUPPORTED_10baseT_Full |
130 SUPPORTED_100baseT_Half |
131 SUPPORTED_100baseT_Full |
132 SUPPORTED_1000baseT_Full |
133 SUPPORTED_Autoneg |
134 SUPPORTED_TP);
135 if (hw->phy.type == e1000_phy_ife)
136 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
137 ecmd->advertising = ADVERTISED_TP;
138
139 if (hw->mac.autoneg == 1) {
140 ecmd->advertising |= ADVERTISED_Autoneg;
141 /* the e1000 autoneg seems to match ethtool nicely */
142 ecmd->advertising |= hw->phy.autoneg_advertised;
143 }
144
145 ecmd->port = PORT_TP;
146 ecmd->phy_address = hw->phy.addr;
147 ecmd->transceiver = XCVR_INTERNAL;
148
149 } else {
150 ecmd->supported = (SUPPORTED_1000baseT_Full |
151 SUPPORTED_FIBRE |
152 SUPPORTED_Autoneg);
153
154 ecmd->advertising = (ADVERTISED_1000baseT_Full |
155 ADVERTISED_FIBRE |
156 ADVERTISED_Autoneg);
157
158 ecmd->port = PORT_FIBRE;
159 ecmd->transceiver = XCVR_EXTERNAL;
160 }
161
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000162 ecmd->speed = -1;
163 ecmd->duplex = -1;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700164
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000165 if (netif_running(netdev)) {
166 if (netif_carrier_ok(netdev)) {
167 ecmd->speed = adapter->link_speed;
168 ecmd->duplex = adapter->link_duplex - 1;
169 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700170 } else {
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000171 u32 status = er32(STATUS);
172 if (status & E1000_STATUS_LU) {
173 if (status & E1000_STATUS_SPEED_1000)
174 ecmd->speed = 1000;
175 else if (status & E1000_STATUS_SPEED_100)
176 ecmd->speed = 100;
177 else
178 ecmd->speed = 10;
179
180 if (status & E1000_STATUS_FD)
181 ecmd->duplex = DUPLEX_FULL;
182 else
183 ecmd->duplex = DUPLEX_HALF;
184 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700185 }
186
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700187 ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) ||
Auke Kokbc7f75f2007-09-17 12:30:59 -0700188 hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
Chaitanya Lala18760f12009-06-08 14:28:54 +0000189
190 /* MDI-X => 2; MDI =>1; Invalid =>0 */
191 if ((hw->phy.media_type == e1000_media_type_copper) &&
Bruce Allan0c6bdb32010-06-17 18:58:43 +0000192 netif_carrier_ok(netdev))
Chaitanya Lala18760f12009-06-08 14:28:54 +0000193 ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X :
194 ETH_TP_MDI;
195 else
196 ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID;
197
Auke Kokbc7f75f2007-09-17 12:30:59 -0700198 return 0;
199}
200
201static int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx)
202{
203 struct e1000_mac_info *mac = &adapter->hw.mac;
204
205 mac->autoneg = 0;
206
207 /* Fiber NICs only allow 1000 gbps Full duplex */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700208 if ((adapter->hw.phy.media_type == e1000_media_type_fiber) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -0700209 spddplx != (SPEED_1000 + DUPLEX_FULL)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700210 e_err("Unsupported Speed/Duplex configuration\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700211 return -EINVAL;
212 }
213
214 switch (spddplx) {
215 case SPEED_10 + DUPLEX_HALF:
216 mac->forced_speed_duplex = ADVERTISE_10_HALF;
217 break;
218 case SPEED_10 + DUPLEX_FULL:
219 mac->forced_speed_duplex = ADVERTISE_10_FULL;
220 break;
221 case SPEED_100 + DUPLEX_HALF:
222 mac->forced_speed_duplex = ADVERTISE_100_HALF;
223 break;
224 case SPEED_100 + DUPLEX_FULL:
225 mac->forced_speed_duplex = ADVERTISE_100_FULL;
226 break;
227 case SPEED_1000 + DUPLEX_FULL:
228 mac->autoneg = 1;
229 adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
230 break;
231 case SPEED_1000 + DUPLEX_HALF: /* not supported */
232 default:
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700233 e_err("Unsupported Speed/Duplex configuration\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700234 return -EINVAL;
235 }
236 return 0;
237}
238
239static int e1000_set_settings(struct net_device *netdev,
240 struct ethtool_cmd *ecmd)
241{
242 struct e1000_adapter *adapter = netdev_priv(netdev);
243 struct e1000_hw *hw = &adapter->hw;
244
Bruce Allanad680762008-03-28 09:15:03 -0700245 /*
246 * When SoL/IDER sessions are active, autoneg/speed/duplex
247 * cannot be changed
248 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700249 if (e1000_check_reset_block(hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700250 e_err("Cannot change link characteristics when SoL/IDER is "
251 "active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700252 return -EINVAL;
253 }
254
255 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
256 msleep(1);
257
258 if (ecmd->autoneg == AUTONEG_ENABLE) {
259 hw->mac.autoneg = 1;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700260 if (hw->phy.media_type == e1000_media_type_fiber)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700261 hw->phy.autoneg_advertised = ADVERTISED_1000baseT_Full |
262 ADVERTISED_FIBRE |
263 ADVERTISED_Autoneg;
264 else
265 hw->phy.autoneg_advertised = ecmd->advertising |
266 ADVERTISED_TP |
267 ADVERTISED_Autoneg;
268 ecmd->advertising = hw->phy.autoneg_advertised;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700269 if (adapter->fc_autoneg)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800270 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700271 } else {
272 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
273 clear_bit(__E1000_RESETTING, &adapter->state);
274 return -EINVAL;
275 }
276 }
277
278 /* reset the link */
279
280 if (netif_running(adapter->netdev)) {
281 e1000e_down(adapter);
282 e1000e_up(adapter);
283 } else {
284 e1000e_reset(adapter);
285 }
286
287 clear_bit(__E1000_RESETTING, &adapter->state);
288 return 0;
289}
290
291static void e1000_get_pauseparam(struct net_device *netdev,
292 struct ethtool_pauseparam *pause)
293{
294 struct e1000_adapter *adapter = netdev_priv(netdev);
295 struct e1000_hw *hw = &adapter->hw;
296
297 pause->autoneg =
298 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
299
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800300 if (hw->fc.current_mode == e1000_fc_rx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700301 pause->rx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800302 } else if (hw->fc.current_mode == e1000_fc_tx_pause) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700303 pause->tx_pause = 1;
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800304 } else if (hw->fc.current_mode == e1000_fc_full) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700305 pause->rx_pause = 1;
306 pause->tx_pause = 1;
307 }
308}
309
310static int e1000_set_pauseparam(struct net_device *netdev,
311 struct ethtool_pauseparam *pause)
312{
313 struct e1000_adapter *adapter = netdev_priv(netdev);
314 struct e1000_hw *hw = &adapter->hw;
315 int retval = 0;
316
317 adapter->fc_autoneg = pause->autoneg;
318
319 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
320 msleep(1);
321
Auke Kokbc7f75f2007-09-17 12:30:59 -0700322 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800323 hw->fc.requested_mode = e1000_fc_default;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700324 if (netif_running(adapter->netdev)) {
325 e1000e_down(adapter);
326 e1000e_up(adapter);
327 } else {
328 e1000e_reset(adapter);
329 }
330 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800331 if (pause->rx_pause && pause->tx_pause)
332 hw->fc.requested_mode = e1000_fc_full;
333 else if (pause->rx_pause && !pause->tx_pause)
334 hw->fc.requested_mode = e1000_fc_rx_pause;
335 else if (!pause->rx_pause && pause->tx_pause)
336 hw->fc.requested_mode = e1000_fc_tx_pause;
337 else if (!pause->rx_pause && !pause->tx_pause)
338 hw->fc.requested_mode = e1000_fc_none;
339
340 hw->fc.current_mode = hw->fc.requested_mode;
341
Bruce Allan945eb312009-10-28 18:28:30 +0000342 if (hw->phy.media_type == e1000_media_type_fiber) {
343 retval = hw->mac.ops.setup_link(hw);
344 /* implicit goto out */
345 } else {
346 retval = e1000e_force_mac_fc(hw);
347 if (retval)
348 goto out;
349 e1000e_set_fc_watermarks(hw);
350 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700351 }
352
Bruce Allan945eb312009-10-28 18:28:30 +0000353out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700354 clear_bit(__E1000_RESETTING, &adapter->state);
355 return retval;
356}
357
358static u32 e1000_get_rx_csum(struct net_device *netdev)
359{
360 struct e1000_adapter *adapter = netdev_priv(netdev);
Eric Dumazet807540b2010-09-23 05:40:09 +0000361 return adapter->flags & FLAG_RX_CSUM_ENABLED;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700362}
363
364static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
365{
366 struct e1000_adapter *adapter = netdev_priv(netdev);
367
368 if (data)
369 adapter->flags |= FLAG_RX_CSUM_ENABLED;
370 else
371 adapter->flags &= ~FLAG_RX_CSUM_ENABLED;
372
373 if (netif_running(netdev))
374 e1000e_reinit_locked(adapter);
375 else
376 e1000e_reset(adapter);
377 return 0;
378}
379
380static u32 e1000_get_tx_csum(struct net_device *netdev)
381{
Eric Dumazet807540b2010-09-23 05:40:09 +0000382 return (netdev->features & NETIF_F_HW_CSUM) != 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700383}
384
385static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
386{
387 if (data)
388 netdev->features |= NETIF_F_HW_CSUM;
389 else
390 netdev->features &= ~NETIF_F_HW_CSUM;
391
392 return 0;
393}
394
395static int e1000_set_tso(struct net_device *netdev, u32 data)
396{
397 struct e1000_adapter *adapter = netdev_priv(netdev);
398
399 if (data) {
400 netdev->features |= NETIF_F_TSO;
401 netdev->features |= NETIF_F_TSO6;
402 } else {
403 netdev->features &= ~NETIF_F_TSO;
404 netdev->features &= ~NETIF_F_TSO6;
405 }
406
Auke Kokbc7f75f2007-09-17 12:30:59 -0700407 adapter->flags |= FLAG_TSO_FORCE;
408 return 0;
409}
410
411static u32 e1000_get_msglevel(struct net_device *netdev)
412{
413 struct e1000_adapter *adapter = netdev_priv(netdev);
414 return adapter->msg_enable;
415}
416
417static void e1000_set_msglevel(struct net_device *netdev, u32 data)
418{
419 struct e1000_adapter *adapter = netdev_priv(netdev);
420 adapter->msg_enable = data;
421}
422
423static int e1000_get_regs_len(struct net_device *netdev)
424{
425#define E1000_REGS_LEN 32 /* overestimate */
426 return E1000_REGS_LEN * sizeof(u32);
427}
428
429static void e1000_get_regs(struct net_device *netdev,
430 struct ethtool_regs *regs, void *p)
431{
432 struct e1000_adapter *adapter = netdev_priv(netdev);
433 struct e1000_hw *hw = &adapter->hw;
434 u32 *regs_buff = p;
435 u16 phy_data;
436 u8 revision_id;
437
438 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
439
440 pci_read_config_byte(adapter->pdev, PCI_REVISION_ID, &revision_id);
441
442 regs->version = (1 << 24) | (revision_id << 16) | adapter->pdev->device;
443
444 regs_buff[0] = er32(CTRL);
445 regs_buff[1] = er32(STATUS);
446
447 regs_buff[2] = er32(RCTL);
448 regs_buff[3] = er32(RDLEN);
449 regs_buff[4] = er32(RDH);
450 regs_buff[5] = er32(RDT);
451 regs_buff[6] = er32(RDTR);
452
453 regs_buff[7] = er32(TCTL);
454 regs_buff[8] = er32(TDLEN);
455 regs_buff[9] = er32(TDH);
456 regs_buff[10] = er32(TDT);
457 regs_buff[11] = er32(TIDV);
458
459 regs_buff[12] = adapter->hw.phy.type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700460
461 /* ethtool doesn't use anything past this point, so all this
462 * code is likely legacy junk for apps that may or may not
463 * exist */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700464 if (hw->phy.type == e1000_phy_m88) {
465 e1e_rphy(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
466 regs_buff[13] = (u32)phy_data; /* cable length */
467 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
468 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
469 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
470 e1e_rphy(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
471 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
472 regs_buff[18] = regs_buff[13]; /* cable polarity */
473 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
474 regs_buff[20] = regs_buff[17]; /* polarity correction */
475 /* phy receive errors */
476 regs_buff[22] = adapter->phy_stats.receive_errors;
477 regs_buff[23] = regs_buff[13]; /* mdix mode */
478 }
Jesse Brandeburg23033fa2008-10-02 16:33:30 -0700479 regs_buff[21] = 0; /* was idle_errors */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700480 e1e_rphy(hw, PHY_1000T_STATUS, &phy_data);
481 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
482 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
483}
484
485static int e1000_get_eeprom_len(struct net_device *netdev)
486{
487 struct e1000_adapter *adapter = netdev_priv(netdev);
488 return adapter->hw.nvm.word_size * 2;
489}
490
491static int e1000_get_eeprom(struct net_device *netdev,
492 struct ethtool_eeprom *eeprom, u8 *bytes)
493{
494 struct e1000_adapter *adapter = netdev_priv(netdev);
495 struct e1000_hw *hw = &adapter->hw;
496 u16 *eeprom_buff;
497 int first_word;
498 int last_word;
499 int ret_val = 0;
500 u16 i;
501
502 if (eeprom->len == 0)
503 return -EINVAL;
504
505 eeprom->magic = adapter->pdev->vendor | (adapter->pdev->device << 16);
506
507 first_word = eeprom->offset >> 1;
508 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
509
510 eeprom_buff = kmalloc(sizeof(u16) *
511 (last_word - first_word + 1), GFP_KERNEL);
512 if (!eeprom_buff)
513 return -ENOMEM;
514
515 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
516 ret_val = e1000_read_nvm(hw, first_word,
517 last_word - first_word + 1,
518 eeprom_buff);
519 } else {
520 for (i = 0; i < last_word - first_word + 1; i++) {
521 ret_val = e1000_read_nvm(hw, first_word + i, 1,
522 &eeprom_buff[i]);
Bruce Allane2434552008-11-21 17:02:41 -0800523 if (ret_val)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700524 break;
525 }
526 }
527
Bruce Allane2434552008-11-21 17:02:41 -0800528 if (ret_val) {
529 /* a read error occurred, throw away the result */
Roel Kluin8528b012009-12-01 15:54:24 +0000530 memset(eeprom_buff, 0xff, sizeof(u16) *
531 (last_word - first_word + 1));
Bruce Allane2434552008-11-21 17:02:41 -0800532 } else {
533 /* Device's eeprom is always little-endian, word addressable */
534 for (i = 0; i < last_word - first_word + 1; i++)
535 le16_to_cpus(&eeprom_buff[i]);
536 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700537
538 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
539 kfree(eeprom_buff);
540
541 return ret_val;
542}
543
544static int e1000_set_eeprom(struct net_device *netdev,
545 struct ethtool_eeprom *eeprom, u8 *bytes)
546{
547 struct e1000_adapter *adapter = netdev_priv(netdev);
548 struct e1000_hw *hw = &adapter->hw;
549 u16 *eeprom_buff;
550 void *ptr;
551 int max_len;
552 int first_word;
553 int last_word;
554 int ret_val = 0;
555 u16 i;
556
557 if (eeprom->len == 0)
558 return -EOPNOTSUPP;
559
560 if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16)))
561 return -EFAULT;
562
Bruce Allan4a770352008-10-01 17:18:35 -0700563 if (adapter->flags & FLAG_READ_ONLY_NVM)
564 return -EINVAL;
565
Auke Kokbc7f75f2007-09-17 12:30:59 -0700566 max_len = hw->nvm.word_size * 2;
567
568 first_word = eeprom->offset >> 1;
569 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
570 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
571 if (!eeprom_buff)
572 return -ENOMEM;
573
574 ptr = (void *)eeprom_buff;
575
576 if (eeprom->offset & 1) {
577 /* need read/modify/write of first changed EEPROM word */
578 /* only the second byte of the word is being modified */
579 ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]);
580 ptr++;
581 }
582 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0))
583 /* need read/modify/write of last changed EEPROM word */
584 /* only the first byte of the word is being modified */
585 ret_val = e1000_read_nvm(hw, last_word, 1,
586 &eeprom_buff[last_word - first_word]);
587
Bruce Allane2434552008-11-21 17:02:41 -0800588 if (ret_val)
589 goto out;
590
Auke Kokbc7f75f2007-09-17 12:30:59 -0700591 /* Device's eeprom is always little-endian, word addressable */
592 for (i = 0; i < last_word - first_word + 1; i++)
593 le16_to_cpus(&eeprom_buff[i]);
594
595 memcpy(ptr, bytes, eeprom->len);
596
597 for (i = 0; i < last_word - first_word + 1; i++)
598 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
599
600 ret_val = e1000_write_nvm(hw, first_word,
601 last_word - first_word + 1, eeprom_buff);
602
Bruce Allane2434552008-11-21 17:02:41 -0800603 if (ret_val)
604 goto out;
605
Bruce Allanad680762008-03-28 09:15:03 -0700606 /*
607 * Update the checksum over the first part of the EEPROM if needed
Bruce Allane2434552008-11-21 17:02:41 -0800608 * and flush shadow RAM for applicable controllers
Bruce Allanad680762008-03-28 09:15:03 -0700609 */
Bruce Allane2434552008-11-21 17:02:41 -0800610 if ((first_word <= NVM_CHECKSUM_REG) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +0000611 (hw->mac.type == e1000_82583) ||
612 (hw->mac.type == e1000_82574) ||
613 (hw->mac.type == e1000_82573))
Bruce Allane2434552008-11-21 17:02:41 -0800614 ret_val = e1000e_update_nvm_checksum(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700615
Bruce Allane2434552008-11-21 17:02:41 -0800616out:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700617 kfree(eeprom_buff);
618 return ret_val;
619}
620
621static void e1000_get_drvinfo(struct net_device *netdev,
622 struct ethtool_drvinfo *drvinfo)
623{
624 struct e1000_adapter *adapter = netdev_priv(netdev);
625 char firmware_version[32];
Auke Kokbc7f75f2007-09-17 12:30:59 -0700626
Bruce Allane0dc4f12011-01-06 14:29:50 +0000627 strncpy(drvinfo->driver, e1000e_driver_name,
628 sizeof(drvinfo->driver) - 1);
629 strncpy(drvinfo->version, e1000e_driver_version,
630 sizeof(drvinfo->version) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700631
Bruce Allanad680762008-03-28 09:15:03 -0700632 /*
633 * EEPROM image version # is reported as firmware version # for
634 * PCI-E controllers
635 */
Bruce Allane0dc4f12011-01-06 14:29:50 +0000636 snprintf(firmware_version, sizeof(firmware_version), "%d.%d-%d",
Bruce Allan84527592008-11-21 17:00:22 -0800637 (adapter->eeprom_vers & 0xF000) >> 12,
638 (adapter->eeprom_vers & 0x0FF0) >> 4,
639 (adapter->eeprom_vers & 0x000F));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700640
Bruce Allane0dc4f12011-01-06 14:29:50 +0000641 strncpy(drvinfo->fw_version, firmware_version,
642 sizeof(drvinfo->fw_version) - 1);
643 strncpy(drvinfo->bus_info, pci_name(adapter->pdev),
644 sizeof(drvinfo->bus_info) - 1);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700645 drvinfo->regdump_len = e1000_get_regs_len(netdev);
646 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
647}
648
649static void e1000_get_ringparam(struct net_device *netdev,
650 struct ethtool_ringparam *ring)
651{
652 struct e1000_adapter *adapter = netdev_priv(netdev);
653 struct e1000_ring *tx_ring = adapter->tx_ring;
654 struct e1000_ring *rx_ring = adapter->rx_ring;
655
656 ring->rx_max_pending = E1000_MAX_RXD;
657 ring->tx_max_pending = E1000_MAX_TXD;
658 ring->rx_mini_max_pending = 0;
659 ring->rx_jumbo_max_pending = 0;
660 ring->rx_pending = rx_ring->count;
661 ring->tx_pending = tx_ring->count;
662 ring->rx_mini_pending = 0;
663 ring->rx_jumbo_pending = 0;
664}
665
666static int e1000_set_ringparam(struct net_device *netdev,
667 struct ethtool_ringparam *ring)
668{
669 struct e1000_adapter *adapter = netdev_priv(netdev);
670 struct e1000_ring *tx_ring, *tx_old;
671 struct e1000_ring *rx_ring, *rx_old;
672 int err;
673
674 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
675 return -EINVAL;
676
677 while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
678 msleep(1);
679
680 if (netif_running(adapter->netdev))
681 e1000e_down(adapter);
682
683 tx_old = adapter->tx_ring;
684 rx_old = adapter->rx_ring;
685
686 err = -ENOMEM;
Bruce Allan05b93212011-01-05 07:10:38 +0000687 tx_ring = kmemdup(tx_old, sizeof(struct e1000_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700688 if (!tx_ring)
689 goto err_alloc_tx;
690
Bruce Allan05b93212011-01-05 07:10:38 +0000691 rx_ring = kmemdup(rx_old, sizeof(struct e1000_ring), GFP_KERNEL);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700692 if (!rx_ring)
693 goto err_alloc_rx;
694
695 adapter->tx_ring = tx_ring;
696 adapter->rx_ring = rx_ring;
697
698 rx_ring->count = max(ring->rx_pending, (u32)E1000_MIN_RXD);
699 rx_ring->count = min(rx_ring->count, (u32)(E1000_MAX_RXD));
700 rx_ring->count = ALIGN(rx_ring->count, REQ_RX_DESCRIPTOR_MULTIPLE);
701
702 tx_ring->count = max(ring->tx_pending, (u32)E1000_MIN_TXD);
703 tx_ring->count = min(tx_ring->count, (u32)(E1000_MAX_TXD));
704 tx_ring->count = ALIGN(tx_ring->count, REQ_TX_DESCRIPTOR_MULTIPLE);
705
706 if (netif_running(adapter->netdev)) {
707 /* Try to get new resources before deleting old */
708 err = e1000e_setup_rx_resources(adapter);
709 if (err)
710 goto err_setup_rx;
711 err = e1000e_setup_tx_resources(adapter);
712 if (err)
713 goto err_setup_tx;
714
Bruce Allanad680762008-03-28 09:15:03 -0700715 /*
716 * restore the old in order to free it,
717 * then add in the new
718 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700719 adapter->rx_ring = rx_old;
720 adapter->tx_ring = tx_old;
721 e1000e_free_rx_resources(adapter);
722 e1000e_free_tx_resources(adapter);
723 kfree(tx_old);
724 kfree(rx_old);
725 adapter->rx_ring = rx_ring;
726 adapter->tx_ring = tx_ring;
727 err = e1000e_up(adapter);
728 if (err)
729 goto err_setup;
730 }
731
732 clear_bit(__E1000_RESETTING, &adapter->state);
733 return 0;
734err_setup_tx:
735 e1000e_free_rx_resources(adapter);
736err_setup_rx:
737 adapter->rx_ring = rx_old;
738 adapter->tx_ring = tx_old;
739 kfree(rx_ring);
740err_alloc_rx:
741 kfree(tx_ring);
742err_alloc_tx:
743 e1000e_up(adapter);
744err_setup:
745 clear_bit(__E1000_RESETTING, &adapter->state);
746 return err;
747}
748
Bruce Allancef8c792008-04-02 13:48:23 -0700749static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data,
750 int reg, int offset, u32 mask, u32 write)
Joe Perches2a887192007-11-13 20:53:51 -0800751{
Bruce Allancef8c792008-04-02 13:48:23 -0700752 u32 pat, val;
Bruce Allan64806412010-12-11 05:53:42 +0000753 static const u32 test[] = {
754 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Bruce Allancef8c792008-04-02 13:48:23 -0700755 for (pat = 0; pat < ARRAY_SIZE(test); pat++) {
Joe Perches2a887192007-11-13 20:53:51 -0800756 E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset,
Bruce Allancef8c792008-04-02 13:48:23 -0700757 (test[pat] & write));
758 val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset);
759 if (val != (test[pat] & write & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700760 e_err("pattern test reg %04X failed: got 0x%08X "
761 "expected 0x%08X\n", reg + offset, val,
762 (test[pat] & write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800763 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700764 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800765 }
766 }
Bruce Allancef8c792008-04-02 13:48:23 -0700767 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700768}
769
Joe Perches2a887192007-11-13 20:53:51 -0800770static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data,
771 int reg, u32 mask, u32 write)
772{
Bruce Allancef8c792008-04-02 13:48:23 -0700773 u32 val;
Joe Perches2a887192007-11-13 20:53:51 -0800774 __ew32(&adapter->hw, reg, write & mask);
Bruce Allancef8c792008-04-02 13:48:23 -0700775 val = __er32(&adapter->hw, reg);
776 if ((write & mask) != (val & mask)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700777 e_err("set/check reg %04X test failed: got 0x%08X "
778 "expected 0x%08X\n", reg, (val & mask), (write & mask));
Joe Perches2a887192007-11-13 20:53:51 -0800779 *data = reg;
Bruce Allancef8c792008-04-02 13:48:23 -0700780 return 1;
Joe Perches2a887192007-11-13 20:53:51 -0800781 }
Bruce Allancef8c792008-04-02 13:48:23 -0700782 return 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700783}
Bruce Allancef8c792008-04-02 13:48:23 -0700784#define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \
785 do { \
786 if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \
787 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800788 } while (0)
Bruce Allancef8c792008-04-02 13:48:23 -0700789#define REG_PATTERN_TEST(reg, mask, write) \
790 REG_PATTERN_TEST_ARRAY(reg, 0, mask, write)
Joe Perches2a887192007-11-13 20:53:51 -0800791
Bruce Allancef8c792008-04-02 13:48:23 -0700792#define REG_SET_AND_CHECK(reg, mask, write) \
793 do { \
794 if (reg_set_and_check(adapter, data, reg, mask, write)) \
795 return 1; \
Joe Perches2a887192007-11-13 20:53:51 -0800796 } while (0)
797
Auke Kokbc7f75f2007-09-17 12:30:59 -0700798static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
799{
800 struct e1000_hw *hw = &adapter->hw;
801 struct e1000_mac_info *mac = &adapter->hw.mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700802 u32 value;
803 u32 before;
804 u32 after;
805 u32 i;
806 u32 toggle;
Bruce Allana4f58f52009-06-02 11:29:18 +0000807 u32 mask;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700808
Bruce Allanad680762008-03-28 09:15:03 -0700809 /*
810 * The status register is Read Only, so a write should fail.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700811 * Some bits that get toggled are ignored.
812 */
813 switch (mac->type) {
814 /* there are several bits on newer hardware that are r/w */
815 case e1000_82571:
816 case e1000_82572:
817 case e1000_80003es2lan:
818 toggle = 0x7FFFF3FF;
819 break;
Bruce Allana4f58f52009-06-02 11:29:18 +0000820 default:
Auke Kokbc7f75f2007-09-17 12:30:59 -0700821 toggle = 0x7FFFF033;
822 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700823 }
824
825 before = er32(STATUS);
826 value = (er32(STATUS) & toggle);
827 ew32(STATUS, toggle);
828 after = er32(STATUS) & toggle;
829 if (value != after) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700830 e_err("failed STATUS register test got: 0x%08X expected: "
831 "0x%08X\n", after, value);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700832 *data = 1;
833 return 1;
834 }
835 /* restore previous status */
836 ew32(STATUS, before);
837
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700838 if (!(adapter->flags & FLAG_IS_ICH)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700839 REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
840 REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF);
841 REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF);
842 REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF);
843 }
844
845 REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF);
846 REG_PATTERN_TEST(E1000_RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
847 REG_PATTERN_TEST(E1000_RDLEN, 0x000FFF80, 0x000FFFFF);
848 REG_PATTERN_TEST(E1000_RDH, 0x0000FFFF, 0x0000FFFF);
849 REG_PATTERN_TEST(E1000_RDT, 0x0000FFFF, 0x0000FFFF);
850 REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8);
851 REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF);
852 REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
853 REG_PATTERN_TEST(E1000_TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
854 REG_PATTERN_TEST(E1000_TDLEN, 0x000FFF80, 0x000FFFFF);
855
856 REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000);
857
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700858 before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700859 REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB);
860 REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000);
861
Auke Kok86582512007-10-04 15:00:08 -0700862 REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF);
863 REG_PATTERN_TEST(E1000_RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
Bruce Allan97ac8ca2008-04-29 09:16:05 -0700864 if (!(adapter->flags & FLAG_IS_ICH))
Auke Kok86582512007-10-04 15:00:08 -0700865 REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF);
866 REG_PATTERN_TEST(E1000_TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
867 REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF);
Bruce Allana4f58f52009-06-02 11:29:18 +0000868 mask = 0x8003FFFF;
869 switch (mac->type) {
870 case e1000_ich10lan:
871 case e1000_pchlan:
Bruce Alland3738bb2010-06-16 13:27:28 +0000872 case e1000_pch2lan:
Bruce Allana4f58f52009-06-02 11:29:18 +0000873 mask |= (1 << 18);
874 break;
875 default:
876 break;
877 }
Auke Kok86582512007-10-04 15:00:08 -0700878 for (i = 0; i < mac->rar_entry_count; i++)
879 REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1),
Bruce Allana4f58f52009-06-02 11:29:18 +0000880 mask, 0xFFFFFFFF);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700881
882 for (i = 0; i < mac->mta_reg_count; i++)
883 REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF);
884
885 *data = 0;
886 return 0;
887}
888
889static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
890{
891 u16 temp;
892 u16 checksum = 0;
893 u16 i;
894
895 *data = 0;
896 /* Read and add up the contents of the EEPROM */
897 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
898 if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) {
899 *data = 1;
Bruce Allane2434552008-11-21 17:02:41 -0800900 return *data;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700901 }
902 checksum += temp;
903 }
904
905 /* If Checksum is not Correct return error else test passed */
906 if ((checksum != (u16) NVM_SUM) && !(*data))
907 *data = 2;
908
909 return *data;
910}
911
912static irqreturn_t e1000_test_intr(int irq, void *data)
913{
914 struct net_device *netdev = (struct net_device *) data;
915 struct e1000_adapter *adapter = netdev_priv(netdev);
916 struct e1000_hw *hw = &adapter->hw;
917
918 adapter->test_icr |= er32(ICR);
919
920 return IRQ_HANDLED;
921}
922
923static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
924{
925 struct net_device *netdev = adapter->netdev;
926 struct e1000_hw *hw = &adapter->hw;
927 u32 mask;
928 u32 shared_int = 1;
929 u32 irq = adapter->pdev->irq;
930 int i;
Bruce Allan4662e822008-08-26 18:37:06 -0700931 int ret_val = 0;
932 int int_mode = E1000E_INT_MODE_LEGACY;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700933
934 *data = 0;
935
Bruce Allan4662e822008-08-26 18:37:06 -0700936 /* NOTE: we don't test MSI/MSI-X interrupts here, yet */
937 if (adapter->int_mode == E1000E_INT_MODE_MSIX) {
938 int_mode = adapter->int_mode;
939 e1000e_reset_interrupt_capability(adapter);
940 adapter->int_mode = E1000E_INT_MODE_LEGACY;
941 e1000e_set_interrupt_capability(adapter);
942 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700943 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800944 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700945 netdev)) {
946 shared_int = 0;
Joe Perchesa0607fd2009-11-18 23:29:17 -0800947 } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700948 netdev->name, netdev)) {
949 *data = 1;
Bruce Allan4662e822008-08-26 18:37:06 -0700950 ret_val = -1;
951 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700952 }
Jeff Kirsher44defeb2008-08-04 17:20:41 -0700953 e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared"));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700954
955 /* Disable all the interrupts */
956 ew32(IMC, 0xFFFFFFFF);
957 msleep(10);
958
959 /* Test each interrupt */
960 for (i = 0; i < 10; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700961 /* Interrupt to test */
962 mask = 1 << i;
963
Bruce Allanf4187b52008-08-26 18:36:50 -0700964 if (adapter->flags & FLAG_IS_ICH) {
965 switch (mask) {
966 case E1000_ICR_RXSEQ:
967 continue;
968 case 0x00000100:
969 if (adapter->hw.mac.type == e1000_ich8lan ||
970 adapter->hw.mac.type == e1000_ich9lan)
971 continue;
972 break;
973 default:
974 break;
975 }
976 }
977
Auke Kokbc7f75f2007-09-17 12:30:59 -0700978 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -0700979 /*
980 * Disable 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 posted to the bus, the
984 * test failed.
985 */
986 adapter->test_icr = 0;
987 ew32(IMC, mask);
988 ew32(ICS, mask);
989 msleep(10);
990
991 if (adapter->test_icr & mask) {
992 *data = 3;
993 break;
994 }
995 }
996
Bruce Allanad680762008-03-28 09:15:03 -0700997 /*
998 * Enable the interrupt to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -0700999 * the cause register and then force the same
1000 * interrupt and see if one gets posted. If
1001 * an interrupt was not posted to the bus, the
1002 * test failed.
1003 */
1004 adapter->test_icr = 0;
1005 ew32(IMS, mask);
1006 ew32(ICS, mask);
1007 msleep(10);
1008
1009 if (!(adapter->test_icr & mask)) {
1010 *data = 4;
1011 break;
1012 }
1013
1014 if (!shared_int) {
Bruce Allanad680762008-03-28 09:15:03 -07001015 /*
1016 * Disable the other interrupts to be reported in
Auke Kokbc7f75f2007-09-17 12:30:59 -07001017 * the cause register and then force the other
1018 * interrupts and see if any get posted. If
1019 * an interrupt was posted to the bus, the
1020 * test failed.
1021 */
1022 adapter->test_icr = 0;
1023 ew32(IMC, ~mask & 0x00007FFF);
1024 ew32(ICS, ~mask & 0x00007FFF);
1025 msleep(10);
1026
1027 if (adapter->test_icr) {
1028 *data = 5;
1029 break;
1030 }
1031 }
1032 }
1033
1034 /* Disable all the interrupts */
1035 ew32(IMC, 0xFFFFFFFF);
1036 msleep(10);
1037
1038 /* Unhook test interrupt handler */
1039 free_irq(irq, netdev);
1040
Bruce Allan4662e822008-08-26 18:37:06 -07001041out:
1042 if (int_mode == E1000E_INT_MODE_MSIX) {
1043 e1000e_reset_interrupt_capability(adapter);
1044 adapter->int_mode = int_mode;
1045 e1000e_set_interrupt_capability(adapter);
1046 }
1047
1048 return ret_val;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001049}
1050
1051static void e1000_free_desc_rings(struct e1000_adapter *adapter)
1052{
1053 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1054 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1055 struct pci_dev *pdev = adapter->pdev;
1056 int i;
1057
1058 if (tx_ring->desc && tx_ring->buffer_info) {
1059 for (i = 0; i < tx_ring->count; i++) {
1060 if (tx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001061 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001062 tx_ring->buffer_info[i].dma,
1063 tx_ring->buffer_info[i].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001064 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001065 if (tx_ring->buffer_info[i].skb)
1066 dev_kfree_skb(tx_ring->buffer_info[i].skb);
1067 }
1068 }
1069
1070 if (rx_ring->desc && rx_ring->buffer_info) {
1071 for (i = 0; i < rx_ring->count; i++) {
1072 if (rx_ring->buffer_info[i].dma)
Nick Nunley0be3f552010-04-27 13:09:05 +00001073 dma_unmap_single(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001074 rx_ring->buffer_info[i].dma,
Nick Nunley0be3f552010-04-27 13:09:05 +00001075 2048, DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001076 if (rx_ring->buffer_info[i].skb)
1077 dev_kfree_skb(rx_ring->buffer_info[i].skb);
1078 }
1079 }
1080
1081 if (tx_ring->desc) {
1082 dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
1083 tx_ring->dma);
1084 tx_ring->desc = NULL;
1085 }
1086 if (rx_ring->desc) {
1087 dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
1088 rx_ring->dma);
1089 rx_ring->desc = NULL;
1090 }
1091
1092 kfree(tx_ring->buffer_info);
1093 tx_ring->buffer_info = NULL;
1094 kfree(rx_ring->buffer_info);
1095 rx_ring->buffer_info = NULL;
1096}
1097
1098static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
1099{
1100 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1101 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1102 struct pci_dev *pdev = adapter->pdev;
1103 struct e1000_hw *hw = &adapter->hw;
1104 u32 rctl;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001105 int i;
1106 int ret_val;
1107
1108 /* Setup Tx descriptor ring and Tx buffers */
1109
1110 if (!tx_ring->count)
1111 tx_ring->count = E1000_DEFAULT_TXD;
1112
Bruce Allancef8c792008-04-02 13:48:23 -07001113 tx_ring->buffer_info = kcalloc(tx_ring->count,
1114 sizeof(struct e1000_buffer),
1115 GFP_KERNEL);
1116 if (!(tx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001117 ret_val = 1;
1118 goto err_nomem;
1119 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001120
1121 tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
1122 tx_ring->size = ALIGN(tx_ring->size, 4096);
1123 tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size,
1124 &tx_ring->dma, GFP_KERNEL);
1125 if (!tx_ring->desc) {
1126 ret_val = 2;
1127 goto err_nomem;
1128 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001129 tx_ring->next_to_use = 0;
1130 tx_ring->next_to_clean = 0;
1131
Bruce Allancef8c792008-04-02 13:48:23 -07001132 ew32(TDBAL, ((u64) tx_ring->dma & 0x00000000FFFFFFFF));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001133 ew32(TDBAH, ((u64) tx_ring->dma >> 32));
Bruce Allancef8c792008-04-02 13:48:23 -07001134 ew32(TDLEN, tx_ring->count * sizeof(struct e1000_tx_desc));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001135 ew32(TDH, 0);
1136 ew32(TDT, 0);
Bruce Allancef8c792008-04-02 13:48:23 -07001137 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR |
1138 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1139 E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001140
1141 for (i = 0; i < tx_ring->count; i++) {
1142 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i);
1143 struct sk_buff *skb;
1144 unsigned int skb_size = 1024;
1145
1146 skb = alloc_skb(skb_size, GFP_KERNEL);
1147 if (!skb) {
1148 ret_val = 3;
1149 goto err_nomem;
1150 }
1151 skb_put(skb, skb_size);
1152 tx_ring->buffer_info[i].skb = skb;
1153 tx_ring->buffer_info[i].length = skb->len;
1154 tx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001155 dma_map_single(&pdev->dev, skb->data, skb->len,
1156 DMA_TO_DEVICE);
1157 if (dma_mapping_error(&pdev->dev,
1158 tx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001159 ret_val = 4;
1160 goto err_nomem;
1161 }
Bruce Allancef8c792008-04-02 13:48:23 -07001162 tx_desc->buffer_addr = cpu_to_le64(tx_ring->buffer_info[i].dma);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001163 tx_desc->lower.data = cpu_to_le32(skb->len);
1164 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1165 E1000_TXD_CMD_IFCS |
Bruce Allancef8c792008-04-02 13:48:23 -07001166 E1000_TXD_CMD_RS);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001167 tx_desc->upper.data = 0;
1168 }
1169
1170 /* Setup Rx descriptor ring and Rx buffers */
1171
1172 if (!rx_ring->count)
1173 rx_ring->count = E1000_DEFAULT_RXD;
1174
Bruce Allancef8c792008-04-02 13:48:23 -07001175 rx_ring->buffer_info = kcalloc(rx_ring->count,
1176 sizeof(struct e1000_buffer),
1177 GFP_KERNEL);
1178 if (!(rx_ring->buffer_info)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001179 ret_val = 5;
1180 goto err_nomem;
1181 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001182
1183 rx_ring->size = rx_ring->count * sizeof(struct e1000_rx_desc);
1184 rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size,
1185 &rx_ring->dma, GFP_KERNEL);
1186 if (!rx_ring->desc) {
1187 ret_val = 6;
1188 goto err_nomem;
1189 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001190 rx_ring->next_to_use = 0;
1191 rx_ring->next_to_clean = 0;
1192
1193 rctl = er32(RCTL);
1194 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1195 ew32(RDBAL, ((u64) rx_ring->dma & 0xFFFFFFFF));
1196 ew32(RDBAH, ((u64) rx_ring->dma >> 32));
1197 ew32(RDLEN, rx_ring->size);
1198 ew32(RDH, 0);
1199 ew32(RDT, 0);
1200 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
Bruce Allancef8c792008-04-02 13:48:23 -07001201 E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE |
1202 E1000_RCTL_SBP | E1000_RCTL_SECRC |
Auke Kokbc7f75f2007-09-17 12:30:59 -07001203 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1204 (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
1205 ew32(RCTL, rctl);
1206
1207 for (i = 0; i < rx_ring->count; i++) {
1208 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rx_ring, i);
1209 struct sk_buff *skb;
1210
1211 skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL);
1212 if (!skb) {
1213 ret_val = 7;
1214 goto err_nomem;
1215 }
1216 skb_reserve(skb, NET_IP_ALIGN);
1217 rx_ring->buffer_info[i].skb = skb;
1218 rx_ring->buffer_info[i].dma =
Nick Nunley0be3f552010-04-27 13:09:05 +00001219 dma_map_single(&pdev->dev, skb->data, 2048,
1220 DMA_FROM_DEVICE);
1221 if (dma_mapping_error(&pdev->dev,
1222 rx_ring->buffer_info[i].dma)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001223 ret_val = 8;
1224 goto err_nomem;
1225 }
1226 rx_desc->buffer_addr =
1227 cpu_to_le64(rx_ring->buffer_info[i].dma);
1228 memset(skb->data, 0x00, skb->len);
1229 }
1230
1231 return 0;
1232
1233err_nomem:
1234 e1000_free_desc_rings(adapter);
1235 return ret_val;
1236}
1237
1238static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1239{
1240 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1241 e1e_wphy(&adapter->hw, 29, 0x001F);
1242 e1e_wphy(&adapter->hw, 30, 0x8FFC);
1243 e1e_wphy(&adapter->hw, 29, 0x001A);
1244 e1e_wphy(&adapter->hw, 30, 0x8FF0);
1245}
1246
1247static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1248{
1249 struct e1000_hw *hw = &adapter->hw;
1250 u32 ctrl_reg = 0;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001251 u16 phy_reg = 0;
Bruce Allancbd006c2010-11-24 06:01:30 +00001252 s32 ret_val = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001253
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001254 hw->mac.autoneg = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001255
Bruce Allan3af50482010-06-16 13:25:55 +00001256 if (hw->phy.type == e1000_phy_ife) {
1257 /* force 100, set loopback */
1258 e1e_wphy(hw, PHY_CONTROL, 0x6100);
Bruce Allanbb436b22009-11-20 23:24:11 +00001259
Bruce Allan3af50482010-06-16 13:25:55 +00001260 /* Now set up the MAC to the same speed/duplex as the PHY. */
1261 ctrl_reg = er32(CTRL);
1262 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1263 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1264 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1265 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1266 E1000_CTRL_FD); /* Force Duplex to FULL */
1267
1268 ew32(CTRL, ctrl_reg);
1269 udelay(500);
1270
1271 return 0;
1272 }
1273
1274 /* Specific PHY configuration for loopback */
1275 switch (hw->phy.type) {
1276 case e1000_phy_m88:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001277 /* Auto-MDI/MDIX Off */
1278 e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808);
1279 /* reset to update Auto-MDI/MDIX */
1280 e1e_wphy(hw, PHY_CONTROL, 0x9140);
1281 /* autoneg off */
1282 e1e_wphy(hw, PHY_CONTROL, 0x8140);
Bruce Allan3af50482010-06-16 13:25:55 +00001283 break;
1284 case e1000_phy_gg82563:
Auke Kokbc7f75f2007-09-17 12:30:59 -07001285 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC);
Bruce Allancef8c792008-04-02 13:48:23 -07001286 break;
Bruce Allan97ac8ca2008-04-29 09:16:05 -07001287 case e1000_phy_bm:
1288 /* Set Default MAC Interface speed to 1GB */
1289 e1e_rphy(hw, PHY_REG(2, 21), &phy_reg);
1290 phy_reg &= ~0x0007;
1291 phy_reg |= 0x006;
1292 e1e_wphy(hw, PHY_REG(2, 21), phy_reg);
1293 /* Assert SW reset for above settings to take effect */
1294 e1000e_commit_phy(hw);
1295 mdelay(1);
1296 /* Force Full Duplex */
1297 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1298 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C);
1299 /* Set Link Up (in force link) */
1300 e1e_rphy(hw, PHY_REG(776, 16), &phy_reg);
1301 e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040);
1302 /* Force Link */
1303 e1e_rphy(hw, PHY_REG(769, 16), &phy_reg);
1304 e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040);
1305 /* Set Early Link Enable */
1306 e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
1307 e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400);
Bruce Allan3af50482010-06-16 13:25:55 +00001308 break;
1309 case e1000_phy_82577:
1310 case e1000_phy_82578:
1311 /* Workaround: K1 must be disabled for stable 1Gbps operation */
Bruce Allancbd006c2010-11-24 06:01:30 +00001312 ret_val = hw->phy.ops.acquire(hw);
1313 if (ret_val) {
1314 e_err("Cannot setup 1Gbps loopback.\n");
1315 return ret_val;
1316 }
Bruce Allan3af50482010-06-16 13:25:55 +00001317 e1000_configure_k1_ich8lan(hw, false);
Bruce Allancbd006c2010-11-24 06:01:30 +00001318 hw->phy.ops.release(hw);
Bruce Allan3af50482010-06-16 13:25:55 +00001319 break;
Bruce Alland3738bb2010-06-16 13:27:28 +00001320 case e1000_phy_82579:
1321 /* Disable PHY energy detect power down */
1322 e1e_rphy(hw, PHY_REG(0, 21), &phy_reg);
1323 e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3));
1324 /* Disable full chip energy detect */
1325 e1e_rphy(hw, PHY_REG(776, 18), &phy_reg);
1326 e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1);
1327 /* Enable loopback on the PHY */
1328#define I82577_PHY_LBK_CTRL 19
1329 e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001);
1330 break;
Bruce Allancef8c792008-04-02 13:48:23 -07001331 default:
Bruce Allan3af50482010-06-16 13:25:55 +00001332 break;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001333 }
1334
Bruce Allan3af50482010-06-16 13:25:55 +00001335 /* force 1000, set loopback */
1336 e1e_wphy(hw, PHY_CONTROL, 0x4140);
1337 mdelay(250);
1338
1339 /* Now set up the MAC to the same speed/duplex as the PHY. */
1340 ctrl_reg = er32(CTRL);
1341 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1342 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1343 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1344 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1345 E1000_CTRL_FD); /* Force Duplex to FULL */
1346
1347 if (adapter->flags & FLAG_IS_ICH)
1348 ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */
1349
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001350 if (hw->phy.media_type == e1000_media_type_copper &&
1351 hw->phy.type == e1000_phy_m88) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001352 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
1353 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001354 /*
1355 * Set the ILOS bit on the fiber Nic if half duplex link is
1356 * detected.
1357 */
Bruce Allan90da0662011-01-06 07:02:53 +00001358 if ((er32(STATUS) & E1000_STATUS_FD) == 0)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001359 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1360 }
1361
1362 ew32(CTRL, ctrl_reg);
1363
Bruce Allanad680762008-03-28 09:15:03 -07001364 /*
1365 * Disable the receiver on the PHY so when a cable is plugged in, the
Auke Kokbc7f75f2007-09-17 12:30:59 -07001366 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1367 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001368 if (hw->phy.type == e1000_phy_m88)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001369 e1000_phy_disable_receiver(adapter);
1370
1371 udelay(500);
1372
1373 return 0;
1374}
1375
1376static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter)
1377{
1378 struct e1000_hw *hw = &adapter->hw;
1379 u32 ctrl = er32(CTRL);
1380 int link = 0;
1381
1382 /* special requirements for 82571/82572 fiber adapters */
1383
Bruce Allanad680762008-03-28 09:15:03 -07001384 /*
1385 * jump through hoops to make sure link is up because serdes
1386 * link is hardwired up
1387 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001388 ctrl |= E1000_CTRL_SLU;
1389 ew32(CTRL, ctrl);
1390
1391 /* disable autoneg */
1392 ctrl = er32(TXCW);
1393 ctrl &= ~(1 << 31);
1394 ew32(TXCW, ctrl);
1395
1396 link = (er32(STATUS) & E1000_STATUS_LU);
1397
1398 if (!link) {
1399 /* set invert loss of signal */
1400 ctrl = er32(CTRL);
1401 ctrl |= E1000_CTRL_ILOS;
1402 ew32(CTRL, ctrl);
1403 }
1404
Bruce Allanad680762008-03-28 09:15:03 -07001405 /*
1406 * special write to serdes control register to enable SerDes analog
1407 * loopback
1408 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001409#define E1000_SERDES_LB_ON 0x410
1410 ew32(SCTL, E1000_SERDES_LB_ON);
1411 msleep(10);
1412
1413 return 0;
1414}
1415
1416/* only call this for fiber/serdes connections to es2lan */
1417static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter)
1418{
1419 struct e1000_hw *hw = &adapter->hw;
1420 u32 ctrlext = er32(CTRL_EXT);
1421 u32 ctrl = er32(CTRL);
1422
Bruce Allanad680762008-03-28 09:15:03 -07001423 /*
1424 * save CTRL_EXT to restore later, reuse an empty variable (unused
1425 * on mac_type 80003es2lan)
1426 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001427 adapter->tx_fifo_head = ctrlext;
1428
1429 /* clear the serdes mode bits, putting the device into mac loopback */
1430 ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1431 ew32(CTRL_EXT, ctrlext);
1432
1433 /* force speed to 1000/FD, link up */
1434 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1435 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX |
1436 E1000_CTRL_SPD_1000 | E1000_CTRL_FD);
1437 ew32(CTRL, ctrl);
1438
1439 /* set mac loopback */
1440 ctrl = er32(RCTL);
1441 ctrl |= E1000_RCTL_LBM_MAC;
1442 ew32(RCTL, ctrl);
1443
1444 /* set testing mode parameters (no need to reset later) */
1445#define KMRNCTRLSTA_OPMODE (0x1F << 16)
1446#define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582
1447 ew32(KMRNCTRLSTA,
Bruce Allancef8c792008-04-02 13:48:23 -07001448 (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII));
Auke Kokbc7f75f2007-09-17 12:30:59 -07001449
1450 return 0;
1451}
1452
1453static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
1454{
1455 struct e1000_hw *hw = &adapter->hw;
1456 u32 rctl;
1457
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001458 if (hw->phy.media_type == e1000_media_type_fiber ||
1459 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001460 switch (hw->mac.type) {
1461 case e1000_80003es2lan:
1462 return e1000_set_es2lan_mac_loopback(adapter);
1463 break;
1464 case e1000_82571:
1465 case e1000_82572:
1466 return e1000_set_82571_fiber_loopback(adapter);
1467 break;
1468 default:
1469 rctl = er32(RCTL);
1470 rctl |= E1000_RCTL_LBM_TCVR;
1471 ew32(RCTL, rctl);
1472 return 0;
1473 }
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001474 } else if (hw->phy.media_type == e1000_media_type_copper) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001475 return e1000_integrated_phy_loopback(adapter);
1476 }
1477
1478 return 7;
1479}
1480
1481static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
1482{
1483 struct e1000_hw *hw = &adapter->hw;
1484 u32 rctl;
1485 u16 phy_reg;
1486
1487 rctl = er32(RCTL);
1488 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
1489 ew32(RCTL, rctl);
1490
1491 switch (hw->mac.type) {
1492 case e1000_80003es2lan:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001493 if (hw->phy.media_type == e1000_media_type_fiber ||
1494 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001495 /* restore CTRL_EXT, stealing space from tx_fifo_head */
Bruce Allanad680762008-03-28 09:15:03 -07001496 ew32(CTRL_EXT, adapter->tx_fifo_head);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001497 adapter->tx_fifo_head = 0;
1498 }
1499 /* fall through */
1500 case e1000_82571:
1501 case e1000_82572:
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001502 if (hw->phy.media_type == e1000_media_type_fiber ||
1503 hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001504#define E1000_SERDES_LB_OFF 0x400
1505 ew32(SCTL, E1000_SERDES_LB_OFF);
1506 msleep(10);
1507 break;
1508 }
1509 /* Fall Through */
1510 default:
1511 hw->mac.autoneg = 1;
1512 if (hw->phy.type == e1000_phy_gg82563)
1513 e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180);
1514 e1e_rphy(hw, PHY_CONTROL, &phy_reg);
1515 if (phy_reg & MII_CR_LOOPBACK) {
1516 phy_reg &= ~MII_CR_LOOPBACK;
1517 e1e_wphy(hw, PHY_CONTROL, phy_reg);
1518 e1000e_commit_phy(hw);
1519 }
1520 break;
1521 }
1522}
1523
1524static void e1000_create_lbtest_frame(struct sk_buff *skb,
1525 unsigned int frame_size)
1526{
1527 memset(skb->data, 0xFF, frame_size);
1528 frame_size &= ~1;
1529 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1530 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1531 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1532}
1533
1534static int e1000_check_lbtest_frame(struct sk_buff *skb,
1535 unsigned int frame_size)
1536{
1537 frame_size &= ~1;
1538 if (*(skb->data + 3) == 0xFF)
1539 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
1540 (*(skb->data + frame_size / 2 + 12) == 0xAF))
1541 return 0;
1542 return 13;
1543}
1544
1545static int e1000_run_loopback_test(struct e1000_adapter *adapter)
1546{
1547 struct e1000_ring *tx_ring = &adapter->test_tx_ring;
1548 struct e1000_ring *rx_ring = &adapter->test_rx_ring;
1549 struct pci_dev *pdev = adapter->pdev;
1550 struct e1000_hw *hw = &adapter->hw;
1551 int i, j, k, l;
1552 int lc;
1553 int good_cnt;
1554 int ret_val = 0;
1555 unsigned long time;
1556
1557 ew32(RDT, rx_ring->count - 1);
1558
Bruce Allanad680762008-03-28 09:15:03 -07001559 /*
1560 * Calculate the loop count based on the largest descriptor ring
Auke Kokbc7f75f2007-09-17 12:30:59 -07001561 * The idea is to wrap the largest ring a number of times using 64
1562 * send/receive pairs during each loop
1563 */
1564
1565 if (rx_ring->count <= tx_ring->count)
1566 lc = ((tx_ring->count / 64) * 2) + 1;
1567 else
1568 lc = ((rx_ring->count / 64) * 2) + 1;
1569
1570 k = 0;
1571 l = 0;
1572 for (j = 0; j <= lc; j++) { /* loop count loop */
1573 for (i = 0; i < 64; i++) { /* send the packets */
Bruce Allancef8c792008-04-02 13:48:23 -07001574 e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb,
1575 1024);
Nick Nunley0be3f552010-04-27 13:09:05 +00001576 dma_sync_single_for_device(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001577 tx_ring->buffer_info[k].dma,
1578 tx_ring->buffer_info[k].length,
Nick Nunley0be3f552010-04-27 13:09:05 +00001579 DMA_TO_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001580 k++;
1581 if (k == tx_ring->count)
1582 k = 0;
1583 }
1584 ew32(TDT, k);
1585 msleep(200);
1586 time = jiffies; /* set the start time for the receive */
1587 good_cnt = 0;
1588 do { /* receive the sent packets */
Nick Nunley0be3f552010-04-27 13:09:05 +00001589 dma_sync_single_for_cpu(&pdev->dev,
Auke Kokbc7f75f2007-09-17 12:30:59 -07001590 rx_ring->buffer_info[l].dma, 2048,
Nick Nunley0be3f552010-04-27 13:09:05 +00001591 DMA_FROM_DEVICE);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001592
1593 ret_val = e1000_check_lbtest_frame(
1594 rx_ring->buffer_info[l].skb, 1024);
1595 if (!ret_val)
1596 good_cnt++;
1597 l++;
1598 if (l == rx_ring->count)
1599 l = 0;
Bruce Allanad680762008-03-28 09:15:03 -07001600 /*
1601 * time + 20 msecs (200 msecs on 2.4) is more than
Auke Kokbc7f75f2007-09-17 12:30:59 -07001602 * enough time to complete the receives, if it's
1603 * exceeded, break and error off
1604 */
1605 } while ((good_cnt < 64) && !time_after(jiffies, time + 20));
1606 if (good_cnt != 64) {
1607 ret_val = 13; /* ret_val is the same as mis-compare */
1608 break;
1609 }
Bruce Allancef8c792008-04-02 13:48:23 -07001610 if (jiffies >= (time + 20)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001611 ret_val = 14; /* error code for time out error */
1612 break;
1613 }
1614 } /* end loop count loop */
1615 return ret_val;
1616}
1617
1618static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
1619{
Bruce Allanad680762008-03-28 09:15:03 -07001620 /*
1621 * PHY loopback cannot be performed if SoL/IDER
1622 * sessions are active
1623 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001624 if (e1000_check_reset_block(&adapter->hw)) {
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001625 e_err("Cannot do PHY loopback test when SoL/IDER is active.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001626 *data = 0;
1627 goto out;
1628 }
1629
1630 *data = e1000_setup_desc_rings(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001631 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001632 goto out;
1633
1634 *data = e1000_setup_loopback_test(adapter);
Adrian Bunke2655222007-10-15 14:02:21 -07001635 if (*data)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001636 goto err_loopback;
1637
1638 *data = e1000_run_loopback_test(adapter);
1639 e1000_loopback_cleanup(adapter);
1640
1641err_loopback:
1642 e1000_free_desc_rings(adapter);
1643out:
1644 return *data;
1645}
1646
1647static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
1648{
1649 struct e1000_hw *hw = &adapter->hw;
1650
1651 *data = 0;
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001652 if (hw->phy.media_type == e1000_media_type_internal_serdes) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001653 int i = 0;
Alex Chiang612e2442009-02-05 23:55:45 -08001654 hw->mac.serdes_has_link = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001655
Bruce Allanad680762008-03-28 09:15:03 -07001656 /*
1657 * On some blade server designs, link establishment
1658 * could take as long as 2-3 minutes
1659 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001660 do {
1661 hw->mac.ops.check_for_link(hw);
1662 if (hw->mac.serdes_has_link)
1663 return *data;
1664 msleep(20);
1665 } while (i++ < 3750);
1666
1667 *data = 1;
1668 } else {
1669 hw->mac.ops.check_for_link(hw);
1670 if (hw->mac.autoneg)
1671 msleep(4000);
1672
1673 if (!(er32(STATUS) &
1674 E1000_STATUS_LU))
1675 *data = 1;
1676 }
1677 return *data;
1678}
1679
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001680static int e1000e_get_sset_count(struct net_device *netdev, int sset)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001681{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001682 switch (sset) {
1683 case ETH_SS_TEST:
1684 return E1000_TEST_LEN;
1685 case ETH_SS_STATS:
1686 return E1000_STATS_LEN;
1687 default:
1688 return -EOPNOTSUPP;
1689 }
Auke Kokbc7f75f2007-09-17 12:30:59 -07001690}
1691
1692static void e1000_diag_test(struct net_device *netdev,
1693 struct ethtool_test *eth_test, u64 *data)
1694{
1695 struct e1000_adapter *adapter = netdev_priv(netdev);
1696 u16 autoneg_advertised;
1697 u8 forced_speed_duplex;
1698 u8 autoneg;
1699 bool if_running = netif_running(netdev);
1700
1701 set_bit(__E1000_TESTING, &adapter->state);
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001702
1703 if (!if_running) {
1704 /* Get control of and reset hardware */
1705 if (adapter->flags & FLAG_HAS_AMT)
1706 e1000e_get_hw_control(adapter);
1707
1708 e1000e_power_up_phy(adapter);
1709
1710 adapter->hw.phy.autoneg_wait_to_complete = 1;
1711 e1000e_reset(adapter);
1712 adapter->hw.phy.autoneg_wait_to_complete = 0;
1713 }
1714
Auke Kokbc7f75f2007-09-17 12:30:59 -07001715 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1716 /* Offline tests */
1717
1718 /* save speed, duplex, autoneg settings */
1719 autoneg_advertised = adapter->hw.phy.autoneg_advertised;
1720 forced_speed_duplex = adapter->hw.mac.forced_speed_duplex;
1721 autoneg = adapter->hw.mac.autoneg;
1722
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001723 e_info("offline testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001724
Auke Kokbc7f75f2007-09-17 12:30:59 -07001725 if (if_running)
1726 /* indicate we're in test mode */
1727 dev_close(netdev);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001728
1729 if (e1000_reg_test(adapter, &data[0]))
1730 eth_test->flags |= ETH_TEST_FL_FAILED;
1731
1732 e1000e_reset(adapter);
1733 if (e1000_eeprom_test(adapter, &data[1]))
1734 eth_test->flags |= ETH_TEST_FL_FAILED;
1735
1736 e1000e_reset(adapter);
1737 if (e1000_intr_test(adapter, &data[2]))
1738 eth_test->flags |= ETH_TEST_FL_FAILED;
1739
1740 e1000e_reset(adapter);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001741 if (e1000_loopback_test(adapter, &data[3]))
1742 eth_test->flags |= ETH_TEST_FL_FAILED;
1743
Auke Kokbc7f75f2007-09-17 12:30:59 -07001744 /* force this routine to wait until autoneg complete/timeout */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001745 adapter->hw.phy.autoneg_wait_to_complete = 1;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001746 e1000e_reset(adapter);
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001747 adapter->hw.phy.autoneg_wait_to_complete = 0;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001748
Carolyn Wybornyc6ce3852010-10-15 17:35:31 +00001749 if (e1000_link_test(adapter, &data[4]))
1750 eth_test->flags |= ETH_TEST_FL_FAILED;
1751
1752 /* restore speed, duplex, autoneg settings */
1753 adapter->hw.phy.autoneg_advertised = autoneg_advertised;
1754 adapter->hw.mac.forced_speed_duplex = forced_speed_duplex;
1755 adapter->hw.mac.autoneg = autoneg;
1756 e1000e_reset(adapter);
1757
Auke Kokbc7f75f2007-09-17 12:30:59 -07001758 clear_bit(__E1000_TESTING, &adapter->state);
1759 if (if_running)
1760 dev_open(netdev);
1761 } else {
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001762 /* Online tests */
Bruce Allan11b08be2010-05-10 14:59:31 +00001763
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001764 e_info("online testing starting\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001765
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001766 /* register, eeprom, intr and loopback tests not run online */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001767 data[0] = 0;
1768 data[1] = 0;
1769 data[2] = 0;
1770 data[3] = 0;
1771
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001772 if (e1000_link_test(adapter, &data[4]))
1773 eth_test->flags |= ETH_TEST_FL_FAILED;
Bruce Allan11b08be2010-05-10 14:59:31 +00001774
Auke Kokbc7f75f2007-09-17 12:30:59 -07001775 clear_bit(__E1000_TESTING, &adapter->state);
1776 }
Bruce Allan31dbe5b2011-01-06 14:29:52 +00001777
1778 if (!if_running) {
1779 e1000e_reset(adapter);
1780
1781 if (adapter->flags & FLAG_HAS_AMT)
1782 e1000e_release_hw_control(adapter);
1783 }
1784
Auke Kokbc7f75f2007-09-17 12:30:59 -07001785 msleep_interruptible(4 * 1000);
1786}
1787
1788static void e1000_get_wol(struct net_device *netdev,
1789 struct ethtool_wolinfo *wol)
1790{
1791 struct e1000_adapter *adapter = netdev_priv(netdev);
1792
1793 wol->supported = 0;
1794 wol->wolopts = 0;
1795
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001796 if (!(adapter->flags & FLAG_HAS_WOL) ||
1797 !device_can_wakeup(&adapter->pdev->dev))
Auke Kokbc7f75f2007-09-17 12:30:59 -07001798 return;
1799
1800 wol->supported = WAKE_UCAST | WAKE_MCAST |
Mitch Williamsefb90e42008-01-29 12:43:02 -08001801 WAKE_BCAST | WAKE_MAGIC |
1802 WAKE_PHY | WAKE_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001803
1804 /* apply any specific unsupported masks here */
1805 if (adapter->flags & FLAG_NO_WAKE_UCAST) {
1806 wol->supported &= ~WAKE_UCAST;
1807
1808 if (adapter->wol & E1000_WUFC_EX)
Jeff Kirsher44defeb2008-08-04 17:20:41 -07001809 e_err("Interface does not support directed (unicast) "
1810 "frame wake-up packets\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001811 }
1812
1813 if (adapter->wol & E1000_WUFC_EX)
1814 wol->wolopts |= WAKE_UCAST;
1815 if (adapter->wol & E1000_WUFC_MC)
1816 wol->wolopts |= WAKE_MCAST;
1817 if (adapter->wol & E1000_WUFC_BC)
1818 wol->wolopts |= WAKE_BCAST;
1819 if (adapter->wol & E1000_WUFC_MAG)
1820 wol->wolopts |= WAKE_MAGIC;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001821 if (adapter->wol & E1000_WUFC_LNKC)
1822 wol->wolopts |= WAKE_PHY;
1823 if (adapter->wol & E1000_WUFC_ARP)
1824 wol->wolopts |= WAKE_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001825}
1826
1827static int e1000_set_wol(struct net_device *netdev,
1828 struct ethtool_wolinfo *wol)
1829{
1830 struct e1000_adapter *adapter = netdev_priv(netdev);
1831
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001832 if (!(adapter->flags & FLAG_HAS_WOL) ||
Bruce Allan1fbfca32009-11-20 23:22:01 +00001833 !device_can_wakeup(&adapter->pdev->dev) ||
1834 (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
1835 WAKE_MAGIC | WAKE_PHY | WAKE_ARP)))
1836 return -EOPNOTSUPP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001837
1838 /* these settings will always override what we currently have */
1839 adapter->wol = 0;
1840
1841 if (wol->wolopts & WAKE_UCAST)
1842 adapter->wol |= E1000_WUFC_EX;
1843 if (wol->wolopts & WAKE_MCAST)
1844 adapter->wol |= E1000_WUFC_MC;
1845 if (wol->wolopts & WAKE_BCAST)
1846 adapter->wol |= E1000_WUFC_BC;
1847 if (wol->wolopts & WAKE_MAGIC)
1848 adapter->wol |= E1000_WUFC_MAG;
Mitch Williamsefb90e42008-01-29 12:43:02 -08001849 if (wol->wolopts & WAKE_PHY)
1850 adapter->wol |= E1000_WUFC_LNKC;
1851 if (wol->wolopts & WAKE_ARP)
1852 adapter->wol |= E1000_WUFC_ARP;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001853
\"Rafael J. Wysocki\6ff68022008-11-12 09:52:32 +00001854 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1855
Auke Kokbc7f75f2007-09-17 12:30:59 -07001856 return 0;
1857}
1858
1859/* toggle LED 4 times per second = 2 "blinks" per second */
1860#define E1000_ID_INTERVAL (HZ/4)
1861
1862/* bit defines for adapter->led_status */
1863#define E1000_LED_ON 0
1864
Holger Eitzenberger9633e632010-11-17 15:43:52 +00001865void e1000e_led_blink_task(struct work_struct *work)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001866{
Bruce Allana4f58f52009-06-02 11:29:18 +00001867 struct e1000_adapter *adapter = container_of(work,
1868 struct e1000_adapter, led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001869
1870 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
1871 adapter->hw.mac.ops.led_off(&adapter->hw);
1872 else
1873 adapter->hw.mac.ops.led_on(&adapter->hw);
Bruce Allana4f58f52009-06-02 11:29:18 +00001874}
Auke Kokbc7f75f2007-09-17 12:30:59 -07001875
Bruce Allana4f58f52009-06-02 11:29:18 +00001876static void e1000_led_blink_callback(unsigned long data)
1877{
1878 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1879
1880 schedule_work(&adapter->led_blink_task);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001881 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1882}
1883
1884static int e1000_phys_id(struct net_device *netdev, u32 data)
1885{
1886 struct e1000_adapter *adapter = netdev_priv(netdev);
Bruce Allan4662e822008-08-26 18:37:06 -07001887 struct e1000_hw *hw = &adapter->hw;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001888
Stephen Hemminger5a9147b2007-10-29 10:46:05 -07001889 if (!data)
1890 data = INT_MAX;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001891
Bruce Allan4662e822008-08-26 18:37:06 -07001892 if ((hw->phy.type == e1000_phy_ife) ||
Bruce Allana4f58f52009-06-02 11:29:18 +00001893 (hw->mac.type == e1000_pchlan) ||
Bruce Alland3738bb2010-06-16 13:27:28 +00001894 (hw->mac.type == e1000_pch2lan) ||
Bruce Allanf89271dd2009-11-20 23:22:20 +00001895 (hw->mac.type == e1000_82583) ||
Bruce Allan4662e822008-08-26 18:37:06 -07001896 (hw->mac.type == e1000_82574)) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001897 if (!adapter->blink_timer.function) {
1898 init_timer(&adapter->blink_timer);
1899 adapter->blink_timer.function =
1900 e1000_led_blink_callback;
1901 adapter->blink_timer.data = (unsigned long) adapter;
1902 }
1903 mod_timer(&adapter->blink_timer, jiffies);
1904 msleep_interruptible(data * 1000);
1905 del_timer_sync(&adapter->blink_timer);
Bruce Allan4662e822008-08-26 18:37:06 -07001906 if (hw->phy.type == e1000_phy_ife)
1907 e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001908 } else {
Bruce Allan4662e822008-08-26 18:37:06 -07001909 e1000e_blink_led(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001910 msleep_interruptible(data * 1000);
1911 }
1912
Bruce Allan4662e822008-08-26 18:37:06 -07001913 hw->mac.ops.led_off(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001914 clear_bit(E1000_LED_ON, &adapter->led_status);
Bruce Allan4662e822008-08-26 18:37:06 -07001915 hw->mac.ops.cleanup_led(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001916
1917 return 0;
1918}
1919
Auke Kokde5b3072008-04-23 11:09:08 -07001920static int e1000_get_coalesce(struct net_device *netdev,
1921 struct ethtool_coalesce *ec)
1922{
1923 struct e1000_adapter *adapter = netdev_priv(netdev);
1924
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001925 if (adapter->itr_setting <= 4)
Auke Kokde5b3072008-04-23 11:09:08 -07001926 ec->rx_coalesce_usecs = adapter->itr_setting;
1927 else
1928 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1929
1930 return 0;
1931}
1932
1933static int e1000_set_coalesce(struct net_device *netdev,
1934 struct ethtool_coalesce *ec)
1935{
1936 struct e1000_adapter *adapter = netdev_priv(netdev);
1937 struct e1000_hw *hw = &adapter->hw;
1938
1939 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001940 ((ec->rx_coalesce_usecs > 4) &&
Auke Kokde5b3072008-04-23 11:09:08 -07001941 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1942 (ec->rx_coalesce_usecs == 2))
1943 return -EINVAL;
1944
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001945 if (ec->rx_coalesce_usecs == 4) {
1946 adapter->itr = adapter->itr_setting = 4;
1947 } else if (ec->rx_coalesce_usecs <= 3) {
Auke Kokde5b3072008-04-23 11:09:08 -07001948 adapter->itr = 20000;
1949 adapter->itr_setting = ec->rx_coalesce_usecs;
1950 } else {
1951 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1952 adapter->itr_setting = adapter->itr & ~3;
1953 }
1954
1955 if (adapter->itr_setting != 0)
1956 ew32(ITR, 1000000000 / (adapter->itr * 256));
1957 else
1958 ew32(ITR, 0);
1959
1960 return 0;
1961}
1962
Auke Kokbc7f75f2007-09-17 12:30:59 -07001963static int e1000_nway_reset(struct net_device *netdev)
1964{
1965 struct e1000_adapter *adapter = netdev_priv(netdev);
1966 if (netif_running(netdev))
1967 e1000e_reinit_locked(adapter);
1968 return 0;
1969}
1970
Auke Kokbc7f75f2007-09-17 12:30:59 -07001971static void e1000_get_ethtool_stats(struct net_device *netdev,
1972 struct ethtool_stats *stats,
1973 u64 *data)
1974{
1975 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001976 struct rtnl_link_stats64 net_stats;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001977 int i;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001978 char *p = NULL;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001979
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001980 e1000e_get_stats64(netdev, &net_stats);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001981 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001982 switch (e1000_gstrings_stats[i].type) {
1983 case NETDEV_STATS:
Jeff Kirsher67fd4fc2011-01-07 05:12:09 +00001984 p = (char *) &net_stats +
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001985 e1000_gstrings_stats[i].stat_offset;
1986 break;
1987 case E1000_STATS:
1988 p = (char *) adapter +
1989 e1000_gstrings_stats[i].stat_offset;
1990 break;
Bruce Allan61c75812010-12-09 23:04:25 +00001991 default:
1992 data[i] = 0;
1993 continue;
Ajit Khapardee0f36a92009-10-13 01:45:09 +00001994 }
1995
Auke Kokbc7f75f2007-09-17 12:30:59 -07001996 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
1997 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1998 }
1999}
2000
2001static void e1000_get_strings(struct net_device *netdev, u32 stringset,
2002 u8 *data)
2003{
2004 u8 *p = data;
2005 int i;
2006
2007 switch (stringset) {
2008 case ETH_SS_TEST:
Bruce Allan5c1bda02011-01-19 04:23:39 +00002009 memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002010 break;
2011 case ETH_SS_STATS:
2012 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
2013 memcpy(p, e1000_gstrings_stats[i].stat_string,
2014 ETH_GSTRING_LEN);
2015 p += ETH_GSTRING_LEN;
2016 }
2017 break;
2018 }
2019}
2020
2021static const struct ethtool_ops e1000_ethtool_ops = {
2022 .get_settings = e1000_get_settings,
2023 .set_settings = e1000_set_settings,
2024 .get_drvinfo = e1000_get_drvinfo,
2025 .get_regs_len = e1000_get_regs_len,
2026 .get_regs = e1000_get_regs,
2027 .get_wol = e1000_get_wol,
2028 .set_wol = e1000_set_wol,
2029 .get_msglevel = e1000_get_msglevel,
2030 .set_msglevel = e1000_set_msglevel,
2031 .nway_reset = e1000_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00002032 .get_link = ethtool_op_get_link,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002033 .get_eeprom_len = e1000_get_eeprom_len,
2034 .get_eeprom = e1000_get_eeprom,
2035 .set_eeprom = e1000_set_eeprom,
2036 .get_ringparam = e1000_get_ringparam,
2037 .set_ringparam = e1000_set_ringparam,
2038 .get_pauseparam = e1000_get_pauseparam,
2039 .set_pauseparam = e1000_set_pauseparam,
2040 .get_rx_csum = e1000_get_rx_csum,
2041 .set_rx_csum = e1000_set_rx_csum,
2042 .get_tx_csum = e1000_get_tx_csum,
2043 .set_tx_csum = e1000_set_tx_csum,
2044 .get_sg = ethtool_op_get_sg,
2045 .set_sg = ethtool_op_set_sg,
2046 .get_tso = ethtool_op_get_tso,
2047 .set_tso = e1000_set_tso,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002048 .self_test = e1000_diag_test,
2049 .get_strings = e1000_get_strings,
2050 .phys_id = e1000_phys_id,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002051 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07002052 .get_sset_count = e1000e_get_sset_count,
Auke Kokde5b3072008-04-23 11:09:08 -07002053 .get_coalesce = e1000_get_coalesce,
2054 .set_coalesce = e1000_set_coalesce,
Bruce Allane7d906f2009-11-20 23:22:57 +00002055 .get_flags = ethtool_op_get_flags,
Auke Kokbc7f75f2007-09-17 12:30:59 -07002056};
2057
2058void e1000e_set_ethtool_ops(struct net_device *netdev)
2059{
2060 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
2061}