blob: 02193a19ab1e826c865e8019c1957526c287c38e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2
Auke Kok0abb6eb2006-09-27 12:53:14 -07003 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2006 Intel Corporation.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 more details.
Auke Kok0abb6eb2006-09-27 12:53:14 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 You should have received a copy of the GNU General Public License along with
Auke Kok0abb6eb2006-09-27 12:53:14 -070016 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 Contact Information:
23 Linux NICS <linux.nics@intel.com>
Auke Kok3d41e302006-04-14 19:05:31 -070024 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29/* ethtool support for e1000 */
30
31#include "e1000.h"
32
33#include <asm/uaccess.h>
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035struct e1000_stats {
36 char stat_string[ETH_GSTRING_LEN];
37 int sizeof_stat;
38 int stat_offset;
39};
40
41#define E1000_STAT(m) sizeof(((struct e1000_adapter *)0)->m), \
42 offsetof(struct e1000_adapter, m)
43static const struct e1000_stats e1000_gstrings_stats[] = {
44 { "rx_packets", E1000_STAT(net_stats.rx_packets) },
45 { "tx_packets", E1000_STAT(net_stats.tx_packets) },
46 { "rx_bytes", E1000_STAT(net_stats.rx_bytes) },
47 { "tx_bytes", E1000_STAT(net_stats.tx_bytes) },
48 { "rx_errors", E1000_STAT(net_stats.rx_errors) },
49 { "tx_errors", E1000_STAT(net_stats.tx_errors) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 { "tx_dropped", E1000_STAT(net_stats.tx_dropped) },
51 { "multicast", E1000_STAT(net_stats.multicast) },
52 { "collisions", E1000_STAT(net_stats.collisions) },
53 { "rx_length_errors", E1000_STAT(net_stats.rx_length_errors) },
54 { "rx_over_errors", E1000_STAT(net_stats.rx_over_errors) },
55 { "rx_crc_errors", E1000_STAT(net_stats.rx_crc_errors) },
56 { "rx_frame_errors", E1000_STAT(net_stats.rx_frame_errors) },
Malli Chilakala26483452005-04-28 19:44:46 -070057 { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 { "rx_missed_errors", E1000_STAT(net_stats.rx_missed_errors) },
59 { "tx_aborted_errors", E1000_STAT(net_stats.tx_aborted_errors) },
60 { "tx_carrier_errors", E1000_STAT(net_stats.tx_carrier_errors) },
61 { "tx_fifo_errors", E1000_STAT(net_stats.tx_fifo_errors) },
62 { "tx_heartbeat_errors", E1000_STAT(net_stats.tx_heartbeat_errors) },
63 { "tx_window_errors", E1000_STAT(net_stats.tx_window_errors) },
64 { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
65 { "tx_deferred_ok", E1000_STAT(stats.dc) },
66 { "tx_single_coll_ok", E1000_STAT(stats.scc) },
67 { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
Jeff Kirsher6b7660c2006-01-12 16:50:35 -080068 { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 { "rx_long_length_errors", E1000_STAT(stats.roc) },
70 { "rx_short_length_errors", E1000_STAT(stats.ruc) },
71 { "rx_align_errors", E1000_STAT(stats.algnerrc) },
72 { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
73 { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
74 { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
75 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
76 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
77 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
78 { "rx_long_byte_count", E1000_STAT(stats.gorcl) },
79 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -040080 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
81 { "rx_header_split", E1000_STAT(rx_hdr_split) },
Jeff Kirsher6b7660c2006-01-12 16:50:35 -080082 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070083};
Jeff Kirsher7bfa4812006-01-12 16:50:41 -080084
Jeff Kirsher7bfa4812006-01-12 16:50:41 -080085#define E1000_QUEUE_STATS_LEN 0
Jeff Kirsher7bfa4812006-01-12 16:50:41 -080086#define E1000_GLOBAL_STATS_LEN \
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 sizeof(e1000_gstrings_stats) / sizeof(struct e1000_stats)
Jeff Kirsher7bfa4812006-01-12 16:50:41 -080088#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN + E1000_QUEUE_STATS_LEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
90 "Register test (offline)", "Eeprom test (offline)",
91 "Interrupt test (offline)", "Loopback test (offline)",
92 "Link test (on/offline)"
93};
94#define E1000_TEST_LEN sizeof(e1000_gstrings_test) / ETH_GSTRING_LEN
95
96static int
97e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
98{
Malli Chilakala60490fe2005-06-17 17:41:45 -070099 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 struct e1000_hw *hw = &adapter->hw;
101
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800102 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 ecmd->supported = (SUPPORTED_10baseT_Half |
105 SUPPORTED_10baseT_Full |
106 SUPPORTED_100baseT_Half |
107 SUPPORTED_100baseT_Full |
108 SUPPORTED_1000baseT_Full|
109 SUPPORTED_Autoneg |
110 SUPPORTED_TP);
Auke Kokcd94dd02006-06-27 09:08:22 -0700111 if (hw->phy_type == e1000_phy_ife)
112 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 ecmd->advertising = ADVERTISED_TP;
114
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800115 if (hw->autoneg == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 ecmd->advertising |= ADVERTISED_Autoneg;
117
118 /* the e1000 autoneg seems to match ethtool nicely */
119
120 ecmd->advertising |= hw->autoneg_advertised;
121 }
122
123 ecmd->port = PORT_TP;
124 ecmd->phy_address = hw->phy_addr;
125
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800126 if (hw->mac_type == e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 ecmd->transceiver = XCVR_EXTERNAL;
128 else
129 ecmd->transceiver = XCVR_INTERNAL;
130
131 } else {
132 ecmd->supported = (SUPPORTED_1000baseT_Full |
133 SUPPORTED_FIBRE |
134 SUPPORTED_Autoneg);
135
Malli Chilakala012609a2005-06-17 17:43:06 -0700136 ecmd->advertising = (ADVERTISED_1000baseT_Full |
137 ADVERTISED_FIBRE |
138 ADVERTISED_Autoneg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140 ecmd->port = PORT_FIBRE;
141
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800142 if (hw->mac_type >= e1000_82545)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 ecmd->transceiver = XCVR_INTERNAL;
144 else
145 ecmd->transceiver = XCVR_EXTERNAL;
146 }
147
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800148 if (netif_carrier_ok(adapter->netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150 e1000_get_speed_and_duplex(hw, &adapter->link_speed,
151 &adapter->link_duplex);
152 ecmd->speed = adapter->link_speed;
153
154 /* unfortunatly FULL_DUPLEX != DUPLEX_FULL
155 * and HALF_DUPLEX != DUPLEX_HALF */
156
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800157 if (adapter->link_duplex == FULL_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 ecmd->duplex = DUPLEX_FULL;
159 else
160 ecmd->duplex = DUPLEX_HALF;
161 } else {
162 ecmd->speed = -1;
163 ecmd->duplex = -1;
164 }
165
166 ecmd->autoneg = ((hw->media_type == e1000_media_type_fiber) ||
167 hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
168 return 0;
169}
170
171static int
172e1000_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
173{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700174 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 struct e1000_hw *hw = &adapter->hw;
176
Jeff Kirsher57128192006-01-12 16:50:28 -0800177 /* When SoL/IDER sessions are active, autoneg/speed/duplex
178 * cannot be changed */
179 if (e1000_check_phy_reset_block(hw)) {
180 DPRINTK(DRV, ERR, "Cannot change link characteristics "
181 "when SoL/IDER is active.\n");
182 return -EINVAL;
183 }
184
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700185 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
186 msleep(1);
187
Jeff Kirsher57128192006-01-12 16:50:28 -0800188 if (ecmd->autoneg == AUTONEG_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 hw->autoneg = 1;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800190 if (hw->media_type == e1000_media_type_fiber)
Malli Chilakala012609a2005-06-17 17:43:06 -0700191 hw->autoneg_advertised = ADVERTISED_1000baseT_Full |
192 ADVERTISED_FIBRE |
193 ADVERTISED_Autoneg;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800194 else
Malli Chilakala012609a2005-06-17 17:43:06 -0700195 hw->autoneg_advertised = ADVERTISED_10baseT_Half |
196 ADVERTISED_10baseT_Full |
197 ADVERTISED_100baseT_Half |
198 ADVERTISED_100baseT_Full |
199 ADVERTISED_1000baseT_Full|
200 ADVERTISED_Autoneg |
201 ADVERTISED_TP;
202 ecmd->advertising = hw->autoneg_advertised;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 } else
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700204 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
205 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 return -EINVAL;
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700207 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209 /* reset the link */
210
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700211 if (netif_running(adapter->netdev)) {
212 e1000_down(adapter);
213 e1000_up(adapter);
214 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 e1000_reset(adapter);
216
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700217 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 return 0;
219}
220
221static void
222e1000_get_pauseparam(struct net_device *netdev,
223 struct ethtool_pauseparam *pause)
224{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700225 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 struct e1000_hw *hw = &adapter->hw;
227
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800228 pause->autoneg =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800230
Jeff Kirsher11241b12006-09-27 12:53:28 -0700231 if (hw->fc == E1000_FC_RX_PAUSE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 pause->rx_pause = 1;
Jeff Kirsher11241b12006-09-27 12:53:28 -0700233 else if (hw->fc == E1000_FC_TX_PAUSE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 pause->tx_pause = 1;
Jeff Kirsher11241b12006-09-27 12:53:28 -0700235 else if (hw->fc == E1000_FC_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 pause->rx_pause = 1;
237 pause->tx_pause = 1;
238 }
239}
240
241static int
242e1000_set_pauseparam(struct net_device *netdev,
243 struct ethtool_pauseparam *pause)
244{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700245 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700247 int retval = 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 adapter->fc_autoneg = pause->autoneg;
250
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700251 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
252 msleep(1);
253
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800254 if (pause->rx_pause && pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700255 hw->fc = E1000_FC_FULL;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800256 else if (pause->rx_pause && !pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700257 hw->fc = E1000_FC_RX_PAUSE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800258 else if (!pause->rx_pause && pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700259 hw->fc = E1000_FC_TX_PAUSE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800260 else if (!pause->rx_pause && !pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700261 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 hw->original_fc = hw->fc;
264
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800265 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700266 if (netif_running(adapter->netdev)) {
267 e1000_down(adapter);
268 e1000_up(adapter);
269 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 e1000_reset(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800271 } else
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700272 retval = ((hw->media_type == e1000_media_type_fiber) ?
273 e1000_setup_link(hw) : e1000_force_mac_fc(hw));
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800274
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700275 clear_bit(__E1000_RESETTING, &adapter->flags);
276 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}
278
279static uint32_t
280e1000_get_rx_csum(struct net_device *netdev)
281{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700282 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 return adapter->rx_csum;
284}
285
286static int
287e1000_set_rx_csum(struct net_device *netdev, uint32_t data)
288{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700289 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 adapter->rx_csum = data;
291
Auke Kok2db10a02006-06-27 09:06:28 -0700292 if (netif_running(netdev))
293 e1000_reinit_locked(adapter);
294 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 e1000_reset(adapter);
296 return 0;
297}
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299static uint32_t
300e1000_get_tx_csum(struct net_device *netdev)
301{
302 return (netdev->features & NETIF_F_HW_CSUM) != 0;
303}
304
305static int
306e1000_set_tx_csum(struct net_device *netdev, uint32_t data)
307{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700308 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800310 if (adapter->hw.mac_type < e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 if (!data)
312 return -EINVAL;
313 return 0;
314 }
315
316 if (data)
317 netdev->features |= NETIF_F_HW_CSUM;
318 else
319 netdev->features &= ~NETIF_F_HW_CSUM;
320
321 return 0;
322}
323
324#ifdef NETIF_F_TSO
325static int
326e1000_set_tso(struct net_device *netdev, uint32_t data)
327{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700328 struct e1000_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800329 if ((adapter->hw.mac_type < e1000_82544) ||
330 (adapter->hw.mac_type == e1000_82547))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 return data ? -EINVAL : 0;
332
333 if (data)
334 netdev->features |= NETIF_F_TSO;
335 else
336 netdev->features &= ~NETIF_F_TSO;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -0800337
338 DPRINTK(PROBE, INFO, "TSO is %s\n", data ? "Enabled" : "Disabled");
339 adapter->tso_force = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 return 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800341}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342#endif /* NETIF_F_TSO */
343
344static uint32_t
345e1000_get_msglevel(struct net_device *netdev)
346{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700347 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 return adapter->msg_enable;
349}
350
351static void
352e1000_set_msglevel(struct net_device *netdev, uint32_t data)
353{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700354 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 adapter->msg_enable = data;
356}
357
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800358static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359e1000_get_regs_len(struct net_device *netdev)
360{
361#define E1000_REGS_LEN 32
362 return E1000_REGS_LEN * sizeof(uint32_t);
363}
364
365static void
366e1000_get_regs(struct net_device *netdev,
367 struct ethtool_regs *regs, void *p)
368{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700369 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 struct e1000_hw *hw = &adapter->hw;
371 uint32_t *regs_buff = p;
372 uint16_t phy_data;
373
374 memset(p, 0, E1000_REGS_LEN * sizeof(uint32_t));
375
376 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
377
378 regs_buff[0] = E1000_READ_REG(hw, CTRL);
379 regs_buff[1] = E1000_READ_REG(hw, STATUS);
380
381 regs_buff[2] = E1000_READ_REG(hw, RCTL);
382 regs_buff[3] = E1000_READ_REG(hw, RDLEN);
383 regs_buff[4] = E1000_READ_REG(hw, RDH);
384 regs_buff[5] = E1000_READ_REG(hw, RDT);
385 regs_buff[6] = E1000_READ_REG(hw, RDTR);
386
387 regs_buff[7] = E1000_READ_REG(hw, TCTL);
388 regs_buff[8] = E1000_READ_REG(hw, TDLEN);
389 regs_buff[9] = E1000_READ_REG(hw, TDH);
390 regs_buff[10] = E1000_READ_REG(hw, TDT);
391 regs_buff[11] = E1000_READ_REG(hw, TIDV);
392
393 regs_buff[12] = adapter->hw.phy_type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800394 if (hw->phy_type == e1000_phy_igp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
396 IGP01E1000_PHY_AGC_A);
397 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A &
398 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
399 regs_buff[13] = (uint32_t)phy_data; /* cable length */
400 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
401 IGP01E1000_PHY_AGC_B);
402 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B &
403 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
404 regs_buff[14] = (uint32_t)phy_data; /* cable length */
405 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
406 IGP01E1000_PHY_AGC_C);
407 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C &
408 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
409 regs_buff[15] = (uint32_t)phy_data; /* cable length */
410 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
411 IGP01E1000_PHY_AGC_D);
412 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D &
413 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
414 regs_buff[16] = (uint32_t)phy_data; /* cable length */
415 regs_buff[17] = 0; /* extended 10bt distance (not needed) */
416 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
417 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS &
418 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
419 regs_buff[18] = (uint32_t)phy_data; /* cable polarity */
420 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
421 IGP01E1000_PHY_PCS_INIT_REG);
422 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG &
423 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
424 regs_buff[19] = (uint32_t)phy_data; /* cable polarity */
425 regs_buff[20] = 0; /* polarity correction enabled (always) */
426 regs_buff[22] = 0; /* phy receive errors (unavailable) */
427 regs_buff[23] = regs_buff[18]; /* mdix mode */
428 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
429 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -0700430 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 regs_buff[13] = (uint32_t)phy_data; /* cable length */
432 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
433 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
434 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
Auke Kok8fc897b2006-08-28 14:56:16 -0700435 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 regs_buff[17] = (uint32_t)phy_data; /* extended 10bt distance */
437 regs_buff[18] = regs_buff[13]; /* cable polarity */
438 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
439 regs_buff[20] = regs_buff[17]; /* polarity correction */
440 /* phy receive errors */
441 regs_buff[22] = adapter->phy_stats.receive_errors;
442 regs_buff[23] = regs_buff[13]; /* mdix mode */
443 }
444 regs_buff[21] = adapter->phy_stats.idle_errors; /* phy idle errors */
445 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
446 regs_buff[24] = (uint32_t)phy_data; /* phy local receiver status */
447 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800448 if (hw->mac_type >= e1000_82540 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 hw->media_type == e1000_media_type_copper) {
450 regs_buff[26] = E1000_READ_REG(hw, MANC);
451 }
452}
453
454static int
455e1000_get_eeprom_len(struct net_device *netdev)
456{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700457 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 return adapter->hw.eeprom.word_size * 2;
459}
460
461static int
462e1000_get_eeprom(struct net_device *netdev,
463 struct ethtool_eeprom *eeprom, uint8_t *bytes)
464{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700465 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 struct e1000_hw *hw = &adapter->hw;
467 uint16_t *eeprom_buff;
468 int first_word, last_word;
469 int ret_val = 0;
470 uint16_t i;
471
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800472 if (eeprom->len == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 return -EINVAL;
474
475 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
476
477 first_word = eeprom->offset >> 1;
478 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
479
480 eeprom_buff = kmalloc(sizeof(uint16_t) *
481 (last_word - first_word + 1), GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800482 if (!eeprom_buff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 return -ENOMEM;
484
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800485 if (hw->eeprom.type == e1000_eeprom_spi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 ret_val = e1000_read_eeprom(hw, first_word,
487 last_word - first_word + 1,
488 eeprom_buff);
489 else {
490 for (i = 0; i < last_word - first_word + 1; i++)
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800491 if ((ret_val = e1000_read_eeprom(hw, first_word + i, 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 &eeprom_buff[i])))
493 break;
494 }
495
496 /* Device's eeprom is always little-endian, word addressable */
497 for (i = 0; i < last_word - first_word + 1; i++)
498 le16_to_cpus(&eeprom_buff[i]);
499
500 memcpy(bytes, (uint8_t *)eeprom_buff + (eeprom->offset & 1),
501 eeprom->len);
502 kfree(eeprom_buff);
503
504 return ret_val;
505}
506
507static int
508e1000_set_eeprom(struct net_device *netdev,
509 struct ethtool_eeprom *eeprom, uint8_t *bytes)
510{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700511 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 struct e1000_hw *hw = &adapter->hw;
513 uint16_t *eeprom_buff;
514 void *ptr;
515 int max_len, first_word, last_word, ret_val = 0;
516 uint16_t i;
517
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800518 if (eeprom->len == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 return -EOPNOTSUPP;
520
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800521 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 return -EFAULT;
523
524 max_len = hw->eeprom.word_size * 2;
525
526 first_word = eeprom->offset >> 1;
527 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
528 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800529 if (!eeprom_buff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 return -ENOMEM;
531
532 ptr = (void *)eeprom_buff;
533
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800534 if (eeprom->offset & 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 /* need read/modify/write of first changed EEPROM word */
536 /* only the second byte of the word is being modified */
537 ret_val = e1000_read_eeprom(hw, first_word, 1,
538 &eeprom_buff[0]);
539 ptr++;
540 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800541 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 /* need read/modify/write of last changed EEPROM word */
543 /* only the first byte of the word is being modified */
544 ret_val = e1000_read_eeprom(hw, last_word, 1,
545 &eeprom_buff[last_word - first_word]);
546 }
547
548 /* Device's eeprom is always little-endian, word addressable */
549 for (i = 0; i < last_word - first_word + 1; i++)
550 le16_to_cpus(&eeprom_buff[i]);
551
552 memcpy(ptr, bytes, eeprom->len);
553
554 for (i = 0; i < last_word - first_word + 1; i++)
555 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
556
557 ret_val = e1000_write_eeprom(hw, first_word,
558 last_word - first_word + 1, eeprom_buff);
559
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800560 /* Update the checksum over the first part of the EEPROM if needed
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -0400561 * and flush shadow RAM for 82573 conrollers */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800562 if ((ret_val == 0) && ((first_word <= EEPROM_CHECKSUM_REG) ||
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -0400563 (hw->mac_type == e1000_82573)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 e1000_update_eeprom_checksum(hw);
565
566 kfree(eeprom_buff);
567 return ret_val;
568}
569
570static void
571e1000_get_drvinfo(struct net_device *netdev,
572 struct ethtool_drvinfo *drvinfo)
573{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700574 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirshera2917e22006-01-12 16:51:23 -0800575 char firmware_version[32];
576 uint16_t eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 strncpy(drvinfo->driver, e1000_driver_name, 32);
579 strncpy(drvinfo->version, e1000_driver_version, 32);
Jeff Kirshera2917e22006-01-12 16:51:23 -0800580
581 /* EEPROM image version # is reported as firmware version # for
582 * 8257{1|2|3} controllers */
583 e1000_read_eeprom(&adapter->hw, 5, 1, &eeprom_data);
584 switch (adapter->hw.mac_type) {
585 case e1000_82571:
586 case e1000_82572:
587 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800588 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -0700589 case e1000_ich8lan:
Jeff Kirshera2917e22006-01-12 16:51:23 -0800590 sprintf(firmware_version, "%d.%d-%d",
591 (eeprom_data & 0xF000) >> 12,
592 (eeprom_data & 0x0FF0) >> 4,
593 eeprom_data & 0x000F);
594 break;
595 default:
596 sprintf(firmware_version, "N/A");
597 }
598
599 strncpy(drvinfo->fw_version, firmware_version, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
601 drvinfo->n_stats = E1000_STATS_LEN;
602 drvinfo->testinfo_len = E1000_TEST_LEN;
603 drvinfo->regdump_len = e1000_get_regs_len(netdev);
604 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
605}
606
607static void
608e1000_get_ringparam(struct net_device *netdev,
609 struct ethtool_ringparam *ring)
610{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700611 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 e1000_mac_type mac_type = adapter->hw.mac_type;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400613 struct e1000_tx_ring *txdr = adapter->tx_ring;
614 struct e1000_rx_ring *rxdr = adapter->rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
616 ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
617 E1000_MAX_82544_RXD;
618 ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD :
619 E1000_MAX_82544_TXD;
620 ring->rx_mini_max_pending = 0;
621 ring->rx_jumbo_max_pending = 0;
622 ring->rx_pending = rxdr->count;
623 ring->tx_pending = txdr->count;
624 ring->rx_mini_pending = 0;
625 ring->rx_jumbo_pending = 0;
626}
627
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800628static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629e1000_set_ringparam(struct net_device *netdev,
630 struct ethtool_ringparam *ring)
631{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700632 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 e1000_mac_type mac_type = adapter->hw.mac_type;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400634 struct e1000_tx_ring *txdr, *tx_old, *tx_new;
635 struct e1000_rx_ring *rxdr, *rx_old, *rx_new;
636 int i, err, tx_ring_size, rx_ring_size;
637
Jeff Kirsher0989aa42006-03-02 18:17:16 -0800638 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
639 return -EINVAL;
640
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800641 tx_ring_size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues;
642 rx_ring_size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400643
Auke Kok2db10a02006-06-27 09:06:28 -0700644 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
645 msleep(1);
646
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400647 if (netif_running(adapter->netdev))
648 e1000_down(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
650 tx_old = adapter->tx_ring;
651 rx_old = adapter->rx_ring;
652
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400653 adapter->tx_ring = kmalloc(tx_ring_size, GFP_KERNEL);
654 if (!adapter->tx_ring) {
655 err = -ENOMEM;
656 goto err_setup_rx;
657 }
658 memset(adapter->tx_ring, 0, tx_ring_size);
659
660 adapter->rx_ring = kmalloc(rx_ring_size, GFP_KERNEL);
661 if (!adapter->rx_ring) {
662 kfree(adapter->tx_ring);
663 err = -ENOMEM;
664 goto err_setup_rx;
665 }
666 memset(adapter->rx_ring, 0, rx_ring_size);
667
668 txdr = adapter->tx_ring;
669 rxdr = adapter->rx_ring;
670
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 rxdr->count = max(ring->rx_pending,(uint32_t)E1000_MIN_RXD);
672 rxdr->count = min(rxdr->count,(uint32_t)(mac_type < e1000_82544 ?
673 E1000_MAX_RXD : E1000_MAX_82544_RXD));
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800674 E1000_ROUNDUP(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
676 txdr->count = max(ring->tx_pending,(uint32_t)E1000_MIN_TXD);
677 txdr->count = min(txdr->count,(uint32_t)(mac_type < e1000_82544 ?
678 E1000_MAX_TXD : E1000_MAX_82544_TXD));
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800679 E1000_ROUNDUP(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800681 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400682 txdr[i].count = txdr->count;
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800683 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400684 rxdr[i].count = rxdr->count;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400685
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800686 if (netif_running(adapter->netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 /* Try to get new resources before deleting old */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400688 if ((err = e1000_setup_all_rx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 goto err_setup_rx;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400690 if ((err = e1000_setup_all_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 goto err_setup_tx;
692
693 /* save the new, restore the old in order to free it,
694 * then restore the new back again */
695
696 rx_new = adapter->rx_ring;
697 tx_new = adapter->tx_ring;
698 adapter->rx_ring = rx_old;
699 adapter->tx_ring = tx_old;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400700 e1000_free_all_rx_resources(adapter);
701 e1000_free_all_tx_resources(adapter);
702 kfree(tx_old);
703 kfree(rx_old);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 adapter->rx_ring = rx_new;
705 adapter->tx_ring = tx_new;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800706 if ((err = e1000_up(adapter)))
Auke Kok2db10a02006-06-27 09:06:28 -0700707 goto err_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 }
709
Auke Kok2db10a02006-06-27 09:06:28 -0700710 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 return 0;
712err_setup_tx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400713 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714err_setup_rx:
715 adapter->rx_ring = rx_old;
716 adapter->tx_ring = tx_old;
717 e1000_up(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -0700718err_setup:
719 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 return err;
721}
722
723#define REG_PATTERN_TEST(R, M, W) \
724{ \
725 uint32_t pat, value; \
726 uint32_t test[] = \
727 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF}; \
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800728 for (pat = 0; pat < sizeof(test)/sizeof(test[0]); pat++) { \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W)); \
730 value = E1000_READ_REG(&adapter->hw, R); \
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800731 if (value != (test[pat] & W & M)) { \
Malli Chilakalab01f6692005-06-17 17:42:29 -0700732 DPRINTK(DRV, ERR, "pattern test reg %04X failed: got " \
733 "0x%08X expected 0x%08X\n", \
734 E1000_##R, value, (test[pat] & W & M)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 *data = (adapter->hw.mac_type < e1000_82543) ? \
736 E1000_82542_##R : E1000_##R; \
737 return 1; \
738 } \
739 } \
740}
741
742#define REG_SET_AND_CHECK(R, M, W) \
743{ \
744 uint32_t value; \
745 E1000_WRITE_REG(&adapter->hw, R, W & M); \
746 value = E1000_READ_REG(&adapter->hw, R); \
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800747 if ((W & M) != (value & M)) { \
Malli Chilakalab01f6692005-06-17 17:42:29 -0700748 DPRINTK(DRV, ERR, "set/check reg %04X test failed: got 0x%08X "\
749 "expected 0x%08X\n", E1000_##R, (value & M), (W & M)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 *data = (adapter->hw.mac_type < e1000_82543) ? \
751 E1000_82542_##R : E1000_##R; \
752 return 1; \
753 } \
754}
755
756static int
757e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data)
758{
Malli Chilakalab01f6692005-06-17 17:42:29 -0700759 uint32_t value, before, after;
760 uint32_t i, toggle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 /* The status register is Read Only, so a write should fail.
763 * Some bits that get toggled are ignored.
764 */
Malli Chilakalab01f6692005-06-17 17:42:29 -0700765 switch (adapter->hw.mac_type) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400766 /* there are several bits on newer hardware that are r/w */
767 case e1000_82571:
768 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800769 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400770 toggle = 0x7FFFF3FF;
771 break;
Malli Chilakalab01f6692005-06-17 17:42:29 -0700772 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -0700773 case e1000_ich8lan:
Malli Chilakalab01f6692005-06-17 17:42:29 -0700774 toggle = 0x7FFFF033;
775 break;
776 default:
777 toggle = 0xFFFFF833;
778 break;
779 }
780
781 before = E1000_READ_REG(&adapter->hw, STATUS);
782 value = (E1000_READ_REG(&adapter->hw, STATUS) & toggle);
783 E1000_WRITE_REG(&adapter->hw, STATUS, toggle);
784 after = E1000_READ_REG(&adapter->hw, STATUS) & toggle;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800785 if (value != after) {
Malli Chilakalab01f6692005-06-17 17:42:29 -0700786 DPRINTK(DRV, ERR, "failed STATUS register test got: "
787 "0x%08X expected: 0x%08X\n", after, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 *data = 1;
789 return 1;
790 }
Malli Chilakalab01f6692005-06-17 17:42:29 -0700791 /* restore previous status */
792 E1000_WRITE_REG(&adapter->hw, STATUS, before);
Auke Kokcd94dd02006-06-27 09:08:22 -0700793 if (adapter->hw.mac_type != e1000_ich8lan) {
794 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
795 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
796 REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF);
797 REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF);
798 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF);
800 REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
801 REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF);
802 REG_PATTERN_TEST(RDH, 0x0000FFFF, 0x0000FFFF);
803 REG_PATTERN_TEST(RDT, 0x0000FFFF, 0x0000FFFF);
804 REG_PATTERN_TEST(FCRTH, 0x0000FFF8, 0x0000FFF8);
805 REG_PATTERN_TEST(FCTTV, 0x0000FFFF, 0x0000FFFF);
806 REG_PATTERN_TEST(TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
807 REG_PATTERN_TEST(TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
808 REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF);
809
810 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000);
Auke Kokcd94dd02006-06-27 09:08:22 -0700811 before = (adapter->hw.mac_type == e1000_ich8lan ?
812 0x06C3B33E : 0x06DFB3FE);
813 REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);
815
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800816 if (adapter->hw.mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Auke Kokcd94dd02006-06-27 09:08:22 -0700818 REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
Auke Kokcd94dd02006-06-27 09:08:22 -0700820 if (adapter->hw.mac_type != e1000_ich8lan)
821 REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
823 REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
Auke Kokcd94dd02006-06-27 09:08:22 -0700824 value = (adapter->hw.mac_type == e1000_ich8lan ?
825 E1000_RAR_ENTRIES_ICH8LAN : E1000_RAR_ENTRIES);
826 for (i = 0; i < value; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF,
828 0xFFFFFFFF);
829 }
830
831 } else {
832
833 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF);
834 REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF);
835 REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF);
836 REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF);
837
838 }
839
Auke Kokcd94dd02006-06-27 09:08:22 -0700840 value = (adapter->hw.mac_type == e1000_ich8lan ?
841 E1000_MC_TBL_SIZE_ICH8LAN : E1000_MC_TBL_SIZE);
842 for (i = 0; i < value; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
844
845 *data = 0;
846 return 0;
847}
848
849static int
850e1000_eeprom_test(struct e1000_adapter *adapter, uint64_t *data)
851{
852 uint16_t temp;
853 uint16_t checksum = 0;
854 uint16_t i;
855
856 *data = 0;
857 /* Read and add up the contents of the EEPROM */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800858 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
859 if ((e1000_read_eeprom(&adapter->hw, i, 1, &temp)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 *data = 1;
861 break;
862 }
863 checksum += temp;
864 }
865
866 /* If Checksum is not Correct return error else test passed */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800867 if ((checksum != (uint16_t) EEPROM_SUM) && !(*data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 *data = 2;
869
870 return *data;
871}
872
873static irqreturn_t
874e1000_test_intr(int irq,
875 void *data,
876 struct pt_regs *regs)
877{
878 struct net_device *netdev = (struct net_device *) data;
Malli Chilakala60490fe2005-06-17 17:41:45 -0700879 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
881 adapter->test_icr |= E1000_READ_REG(&adapter->hw, ICR);
882
883 return IRQ_HANDLED;
884}
885
886static int
887e1000_intr_test(struct e1000_adapter *adapter, uint64_t *data)
888{
889 struct net_device *netdev = adapter->netdev;
Auke Kok76c224b2006-05-23 13:36:06 -0700890 uint32_t mask, i=0, shared_int = TRUE;
891 uint32_t irq = adapter->pdev->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
893 *data = 0;
894
Auke Kok8fc897b2006-08-28 14:56:16 -0700895 /* NOTE: we don't test MSI interrupts here, yet */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 /* Hook up test interrupt handler just for this test */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -0700897 if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED,
Auke Kok8fc897b2006-08-28 14:56:16 -0700898 netdev->name, netdev))
899 shared_int = FALSE;
900 else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED,
901 netdev->name, netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 *data = 1;
903 return -1;
904 }
Auke Kok8fc897b2006-08-28 14:56:16 -0700905 DPRINTK(HW, INFO, "testing %s interrupt\n",
Auke Kokb9b6e782006-06-08 09:28:38 -0700906 (shared_int ? "shared" : "unshared"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
908 /* Disable all the interrupts */
909 E1000_WRITE_REG(&adapter->hw, IMC, 0xFFFFFFFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400910 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912 /* Test each interrupt */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800913 for (; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Auke Kokcd94dd02006-06-27 09:08:22 -0700915 if (adapter->hw.mac_type == e1000_ich8lan && i == 8)
916 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 /* Interrupt to test */
918 mask = 1 << i;
919
Auke Kok76c224b2006-05-23 13:36:06 -0700920 if (!shared_int) {
921 /* Disable the interrupt to be reported in
922 * the cause register and then force the same
923 * interrupt and see if one gets posted. If
924 * an interrupt was posted to the bus, the
925 * test failed.
926 */
927 adapter->test_icr = 0;
928 E1000_WRITE_REG(&adapter->hw, IMC, mask);
929 E1000_WRITE_REG(&adapter->hw, ICS, mask);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400930 msleep(10);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800931
Auke Kok76c224b2006-05-23 13:36:06 -0700932 if (adapter->test_icr & mask) {
933 *data = 3;
934 break;
935 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 }
937
938 /* Enable the interrupt to be reported in
939 * the cause register and then force the same
940 * interrupt and see if one gets posted. If
941 * an interrupt was not posted to the bus, the
942 * test failed.
943 */
944 adapter->test_icr = 0;
945 E1000_WRITE_REG(&adapter->hw, IMS, mask);
946 E1000_WRITE_REG(&adapter->hw, ICS, mask);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400947 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800949 if (!(adapter->test_icr & mask)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 *data = 4;
951 break;
952 }
953
Auke Kok76c224b2006-05-23 13:36:06 -0700954 if (!shared_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 /* Disable the other interrupts to be reported in
956 * the cause register and then force the other
957 * interrupts and see if any get posted. If
958 * an interrupt was posted to the bus, the
959 * test failed.
960 */
961 adapter->test_icr = 0;
Malli Chilakala26483452005-04-28 19:44:46 -0700962 E1000_WRITE_REG(&adapter->hw, IMC, ~mask & 0x00007FFF);
963 E1000_WRITE_REG(&adapter->hw, ICS, ~mask & 0x00007FFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400964 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800966 if (adapter->test_icr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 *data = 5;
968 break;
969 }
970 }
971 }
972
973 /* Disable all the interrupts */
974 E1000_WRITE_REG(&adapter->hw, IMC, 0xFFFFFFFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400975 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 /* Unhook test interrupt handler */
978 free_irq(irq, netdev);
979
980 return *data;
981}
982
983static void
984e1000_free_desc_rings(struct e1000_adapter *adapter)
985{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400986 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
987 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 struct pci_dev *pdev = adapter->pdev;
989 int i;
990
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800991 if (txdr->desc && txdr->buffer_info) {
992 for (i = 0; i < txdr->count; i++) {
993 if (txdr->buffer_info[i].dma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 pci_unmap_single(pdev, txdr->buffer_info[i].dma,
995 txdr->buffer_info[i].length,
996 PCI_DMA_TODEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800997 if (txdr->buffer_info[i].skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 dev_kfree_skb(txdr->buffer_info[i].skb);
999 }
1000 }
1001
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001002 if (rxdr->desc && rxdr->buffer_info) {
1003 for (i = 0; i < rxdr->count; i++) {
1004 if (rxdr->buffer_info[i].dma)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 pci_unmap_single(pdev, rxdr->buffer_info[i].dma,
1006 rxdr->buffer_info[i].length,
1007 PCI_DMA_FROMDEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001008 if (rxdr->buffer_info[i].skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 dev_kfree_skb(rxdr->buffer_info[i].skb);
1010 }
1011 }
1012
Jeff Kirsherf5645112006-01-12 16:51:01 -08001013 if (txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 pci_free_consistent(pdev, txdr->size, txdr->desc, txdr->dma);
John W. Linville6b27adb2005-11-08 15:59:30 -05001015 txdr->desc = NULL;
1016 }
Jeff Kirsherf5645112006-01-12 16:51:01 -08001017 if (rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 pci_free_consistent(pdev, rxdr->size, rxdr->desc, rxdr->dma);
John W. Linville6b27adb2005-11-08 15:59:30 -05001019 rxdr->desc = NULL;
1020 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021
Jesper Juhlb4558ea2005-10-28 16:53:13 -04001022 kfree(txdr->buffer_info);
John W. Linville6b27adb2005-11-08 15:59:30 -05001023 txdr->buffer_info = NULL;
Jesper Juhlb4558ea2005-10-28 16:53:13 -04001024 kfree(rxdr->buffer_info);
John W. Linville6b27adb2005-11-08 15:59:30 -05001025 rxdr->buffer_info = NULL;
Jeff Kirsherf5645112006-01-12 16:51:01 -08001026
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 return;
1028}
1029
1030static int
1031e1000_setup_desc_rings(struct e1000_adapter *adapter)
1032{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001033 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1034 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 struct pci_dev *pdev = adapter->pdev;
1036 uint32_t rctl;
1037 int size, i, ret_val;
1038
1039 /* Setup Tx descriptor ring and Tx buffers */
1040
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001041 if (!txdr->count)
1042 txdr->count = E1000_DEFAULT_TXD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
1044 size = txdr->count * sizeof(struct e1000_buffer);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001045 if (!(txdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 ret_val = 1;
1047 goto err_nomem;
1048 }
1049 memset(txdr->buffer_info, 0, size);
1050
1051 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
1052 E1000_ROUNDUP(txdr->size, 4096);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001053 if (!(txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 ret_val = 2;
1055 goto err_nomem;
1056 }
1057 memset(txdr->desc, 0, txdr->size);
1058 txdr->next_to_use = txdr->next_to_clean = 0;
1059
1060 E1000_WRITE_REG(&adapter->hw, TDBAL,
1061 ((uint64_t) txdr->dma & 0x00000000FFFFFFFF));
1062 E1000_WRITE_REG(&adapter->hw, TDBAH, ((uint64_t) txdr->dma >> 32));
1063 E1000_WRITE_REG(&adapter->hw, TDLEN,
1064 txdr->count * sizeof(struct e1000_tx_desc));
1065 E1000_WRITE_REG(&adapter->hw, TDH, 0);
1066 E1000_WRITE_REG(&adapter->hw, TDT, 0);
1067 E1000_WRITE_REG(&adapter->hw, TCTL,
1068 E1000_TCTL_PSP | E1000_TCTL_EN |
1069 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1070 E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
1071
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001072 for (i = 0; i < txdr->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i);
1074 struct sk_buff *skb;
1075 unsigned int size = 1024;
1076
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001077 if (!(skb = alloc_skb(size, GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 ret_val = 3;
1079 goto err_nomem;
1080 }
1081 skb_put(skb, size);
1082 txdr->buffer_info[i].skb = skb;
1083 txdr->buffer_info[i].length = skb->len;
1084 txdr->buffer_info[i].dma =
1085 pci_map_single(pdev, skb->data, skb->len,
1086 PCI_DMA_TODEVICE);
1087 tx_desc->buffer_addr = cpu_to_le64(txdr->buffer_info[i].dma);
1088 tx_desc->lower.data = cpu_to_le32(skb->len);
1089 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1090 E1000_TXD_CMD_IFCS |
1091 E1000_TXD_CMD_RPS);
1092 tx_desc->upper.data = 0;
1093 }
1094
1095 /* Setup Rx descriptor ring and Rx buffers */
1096
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001097 if (!rxdr->count)
1098 rxdr->count = E1000_DEFAULT_RXD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
1100 size = rxdr->count * sizeof(struct e1000_buffer);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001101 if (!(rxdr->buffer_info = kmalloc(size, GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 ret_val = 4;
1103 goto err_nomem;
1104 }
1105 memset(rxdr->buffer_info, 0, size);
1106
1107 rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001108 if (!(rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 ret_val = 5;
1110 goto err_nomem;
1111 }
1112 memset(rxdr->desc, 0, rxdr->size);
1113 rxdr->next_to_use = rxdr->next_to_clean = 0;
1114
1115 rctl = E1000_READ_REG(&adapter->hw, RCTL);
1116 E1000_WRITE_REG(&adapter->hw, RCTL, rctl & ~E1000_RCTL_EN);
1117 E1000_WRITE_REG(&adapter->hw, RDBAL,
1118 ((uint64_t) rxdr->dma & 0xFFFFFFFF));
1119 E1000_WRITE_REG(&adapter->hw, RDBAH, ((uint64_t) rxdr->dma >> 32));
1120 E1000_WRITE_REG(&adapter->hw, RDLEN, rxdr->size);
1121 E1000_WRITE_REG(&adapter->hw, RDH, 0);
1122 E1000_WRITE_REG(&adapter->hw, RDT, 0);
1123 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
1124 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
1125 (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT);
1126 E1000_WRITE_REG(&adapter->hw, RCTL, rctl);
1127
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001128 for (i = 0; i < rxdr->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i);
1130 struct sk_buff *skb;
1131
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001132 if (!(skb = alloc_skb(E1000_RXBUFFER_2048 + NET_IP_ALIGN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 GFP_KERNEL))) {
1134 ret_val = 6;
1135 goto err_nomem;
1136 }
1137 skb_reserve(skb, NET_IP_ALIGN);
1138 rxdr->buffer_info[i].skb = skb;
1139 rxdr->buffer_info[i].length = E1000_RXBUFFER_2048;
1140 rxdr->buffer_info[i].dma =
1141 pci_map_single(pdev, skb->data, E1000_RXBUFFER_2048,
1142 PCI_DMA_FROMDEVICE);
1143 rx_desc->buffer_addr = cpu_to_le64(rxdr->buffer_info[i].dma);
1144 memset(skb->data, 0x00, skb->len);
1145 }
1146
1147 return 0;
1148
1149err_nomem:
1150 e1000_free_desc_rings(adapter);
1151 return ret_val;
1152}
1153
1154static void
1155e1000_phy_disable_receiver(struct e1000_adapter *adapter)
1156{
1157 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1158 e1000_write_phy_reg(&adapter->hw, 29, 0x001F);
1159 e1000_write_phy_reg(&adapter->hw, 30, 0x8FFC);
1160 e1000_write_phy_reg(&adapter->hw, 29, 0x001A);
1161 e1000_write_phy_reg(&adapter->hw, 30, 0x8FF0);
1162}
1163
1164static void
1165e1000_phy_reset_clk_and_crs(struct e1000_adapter *adapter)
1166{
1167 uint16_t phy_reg;
1168
1169 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1170 * Extended PHY Specific Control Register to 25MHz clock. This
1171 * value defaults back to a 2.5MHz clock when the PHY is reset.
1172 */
1173 e1000_read_phy_reg(&adapter->hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
1174 phy_reg |= M88E1000_EPSCR_TX_CLK_25;
1175 e1000_write_phy_reg(&adapter->hw,
1176 M88E1000_EXT_PHY_SPEC_CTRL, phy_reg);
1177
1178 /* In addition, because of the s/w reset above, we need to enable
1179 * CRS on TX. This must be set for both full and half duplex
1180 * operation.
1181 */
1182 e1000_read_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
1183 phy_reg |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1184 e1000_write_phy_reg(&adapter->hw,
1185 M88E1000_PHY_SPEC_CTRL, phy_reg);
1186}
1187
1188static int
1189e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter)
1190{
1191 uint32_t ctrl_reg;
1192 uint16_t phy_reg;
1193
1194 /* Setup the Device Control Register for PHY loopback test. */
1195
1196 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
1197 ctrl_reg |= (E1000_CTRL_ILOS | /* Invert Loss-Of-Signal */
1198 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1199 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1200 E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */
1201 E1000_CTRL_FD); /* Force Duplex to FULL */
1202
1203 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl_reg);
1204
1205 /* Read the PHY Specific Control Register (0x10) */
1206 e1000_read_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
1207
1208 /* Clear Auto-Crossover bits in PHY Specific Control Register
1209 * (bits 6:5).
1210 */
1211 phy_reg &= ~M88E1000_PSCR_AUTO_X_MODE;
1212 e1000_write_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, phy_reg);
1213
1214 /* Perform software reset on the PHY */
1215 e1000_phy_reset(&adapter->hw);
1216
1217 /* Have to setup TX_CLK and TX_CRS after software reset */
1218 e1000_phy_reset_clk_and_crs(adapter);
1219
1220 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x8100);
1221
1222 /* Wait for reset to complete. */
1223 udelay(500);
1224
1225 /* Have to setup TX_CLK and TX_CRS after software reset */
1226 e1000_phy_reset_clk_and_crs(adapter);
1227
1228 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1229 e1000_phy_disable_receiver(adapter);
1230
1231 /* Set the loopback bit in the PHY control register. */
1232 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
1233 phy_reg |= MII_CR_LOOPBACK;
1234 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg);
1235
1236 /* Setup TX_CLK and TX_CRS one more time. */
1237 e1000_phy_reset_clk_and_crs(adapter);
1238
1239 /* Check Phy Configuration */
1240 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001241 if (phy_reg != 0x4100)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 return 9;
1243
1244 e1000_read_phy_reg(&adapter->hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001245 if (phy_reg != 0x0070)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 return 10;
1247
1248 e1000_read_phy_reg(&adapter->hw, 29, &phy_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001249 if (phy_reg != 0x001A)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 return 11;
1251
1252 return 0;
1253}
1254
1255static int
1256e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
1257{
1258 uint32_t ctrl_reg = 0;
1259 uint32_t stat_reg = 0;
1260
1261 adapter->hw.autoneg = FALSE;
1262
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001263 if (adapter->hw.phy_type == e1000_phy_m88) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 /* Auto-MDI/MDIX Off */
1265 e1000_write_phy_reg(&adapter->hw,
1266 M88E1000_PHY_SPEC_CTRL, 0x0808);
1267 /* reset to update Auto-MDI/MDIX */
1268 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x9140);
1269 /* autoneg off */
1270 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x8140);
Auke Kok8fc897b2006-08-28 14:56:16 -07001271 } else if (adapter->hw.phy_type == e1000_phy_gg82563)
Jeff Kirsher87041632006-03-02 18:21:24 -08001272 e1000_write_phy_reg(&adapter->hw,
1273 GG82563_PHY_KMRN_MODE_CTRL,
Auke Kokacfbc9f2006-06-27 09:06:24 -07001274 0x1CC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
Auke Kokcd94dd02006-06-27 09:08:22 -07001277
1278 if (adapter->hw.phy_type == e1000_phy_ife) {
1279 /* force 100, set loopback */
1280 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x6100);
1281
1282 /* Now set up the MAC to the same speed/duplex as the PHY. */
1283 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1284 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1285 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1286 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1287 E1000_CTRL_FD); /* Force Duplex to FULL */
1288 } else {
1289 /* force 1000, set loopback */
1290 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x4140);
1291
1292 /* Now set up the MAC to the same speed/duplex as the PHY. */
1293 ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL);
1294 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1295 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1296 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1297 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1298 E1000_CTRL_FD); /* Force Duplex to FULL */
1299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001301 if (adapter->hw.media_type == e1000_media_type_copper &&
Auke Kok8fc897b2006-08-28 14:56:16 -07001302 adapter->hw.phy_type == e1000_phy_m88)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
Auke Kok8fc897b2006-08-28 14:56:16 -07001304 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 /* Set the ILOS bit on the fiber Nic is half
1306 * duplex link is detected. */
1307 stat_reg = E1000_READ_REG(&adapter->hw, STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001308 if ((stat_reg & E1000_STATUS_FD) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1310 }
1311
1312 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl_reg);
1313
1314 /* Disable the receiver on the PHY so when a cable is plugged in, the
1315 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1316 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001317 if (adapter->hw.phy_type == e1000_phy_m88)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 e1000_phy_disable_receiver(adapter);
1319
1320 udelay(500);
1321
1322 return 0;
1323}
1324
1325static int
1326e1000_set_phy_loopback(struct e1000_adapter *adapter)
1327{
1328 uint16_t phy_reg = 0;
1329 uint16_t count = 0;
1330
1331 switch (adapter->hw.mac_type) {
1332 case e1000_82543:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001333 if (adapter->hw.media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 /* Attempt to setup Loopback mode on Non-integrated PHY.
1335 * Some PHY registers get corrupted at random, so
1336 * attempt this 10 times.
1337 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001338 while (e1000_nonintegrated_phy_loopback(adapter) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 count++ < 10);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001340 if (count < 11)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 return 0;
1342 }
1343 break;
1344
1345 case e1000_82544:
1346 case e1000_82540:
1347 case e1000_82545:
1348 case e1000_82545_rev_3:
1349 case e1000_82546:
1350 case e1000_82546_rev_3:
1351 case e1000_82541:
1352 case e1000_82541_rev_2:
1353 case e1000_82547:
1354 case e1000_82547_rev_2:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001355 case e1000_82571:
1356 case e1000_82572:
Malli Chilakala45643272005-06-17 17:42:42 -07001357 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001358 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07001359 case e1000_ich8lan:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 return e1000_integrated_phy_loopback(adapter);
1361 break;
1362
1363 default:
1364 /* Default PHY loopback work is to read the MII
1365 * control register and assert bit 14 (loopback mode).
1366 */
1367 e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg);
1368 phy_reg |= MII_CR_LOOPBACK;
1369 e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg);
1370 return 0;
1371 break;
1372 }
1373
1374 return 8;
1375}
1376
1377static int
1378e1000_setup_loopback_test(struct e1000_adapter *adapter)
1379{
Jeff Kirsher49273162006-01-12 16:50:44 -08001380 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 uint32_t rctl;
1382
Jeff Kirsher49273162006-01-12 16:50:44 -08001383 if (hw->media_type == e1000_media_type_fiber ||
1384 hw->media_type == e1000_media_type_internal_serdes) {
1385 switch (hw->mac_type) {
1386 case e1000_82545:
1387 case e1000_82546:
1388 case e1000_82545_rev_3:
1389 case e1000_82546_rev_3:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 return e1000_set_phy_loopback(adapter);
Jeff Kirsher49273162006-01-12 16:50:44 -08001391 break;
1392 case e1000_82571:
1393 case e1000_82572:
1394#define E1000_SERDES_LB_ON 0x410
1395 e1000_set_phy_loopback(adapter);
1396 E1000_WRITE_REG(hw, SCTL, E1000_SERDES_LB_ON);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001397 msleep(10);
Jeff Kirsher49273162006-01-12 16:50:44 -08001398 return 0;
1399 break;
1400 default:
1401 rctl = E1000_READ_REG(hw, RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 rctl |= E1000_RCTL_LBM_TCVR;
Jeff Kirsher49273162006-01-12 16:50:44 -08001403 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 return 0;
1405 }
Jeff Kirsher49273162006-01-12 16:50:44 -08001406 } else if (hw->media_type == e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 return e1000_set_phy_loopback(adapter);
1408
1409 return 7;
1410}
1411
1412static void
1413e1000_loopback_cleanup(struct e1000_adapter *adapter)
1414{
Jeff Kirsher49273162006-01-12 16:50:44 -08001415 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 uint32_t rctl;
1417 uint16_t phy_reg;
1418
Jeff Kirsher49273162006-01-12 16:50:44 -08001419 rctl = E1000_READ_REG(hw, RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
Jeff Kirsher49273162006-01-12 16:50:44 -08001421 E1000_WRITE_REG(hw, RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
Jeff Kirsher49273162006-01-12 16:50:44 -08001423 switch (hw->mac_type) {
1424 case e1000_82571:
1425 case e1000_82572:
1426 if (hw->media_type == e1000_media_type_fiber ||
1427 hw->media_type == e1000_media_type_internal_serdes) {
1428#define E1000_SERDES_LB_OFF 0x400
1429 E1000_WRITE_REG(hw, SCTL, E1000_SERDES_LB_OFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001430 msleep(10);
Jeff Kirsher49273162006-01-12 16:50:44 -08001431 break;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001432 }
Jeff Kirsher49273162006-01-12 16:50:44 -08001433 /* Fall Through */
1434 case e1000_82545:
1435 case e1000_82546:
1436 case e1000_82545_rev_3:
1437 case e1000_82546_rev_3:
1438 default:
1439 hw->autoneg = TRUE;
Auke Kok8fc897b2006-08-28 14:56:16 -07001440 if (hw->phy_type == e1000_phy_gg82563)
Jeff Kirsher87041632006-03-02 18:21:24 -08001441 e1000_write_phy_reg(hw,
1442 GG82563_PHY_KMRN_MODE_CTRL,
1443 0x180);
Jeff Kirsher49273162006-01-12 16:50:44 -08001444 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
1445 if (phy_reg & MII_CR_LOOPBACK) {
1446 phy_reg &= ~MII_CR_LOOPBACK;
1447 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
1448 e1000_phy_reset(hw);
1449 }
1450 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 }
1452}
1453
1454static void
1455e1000_create_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
1456{
1457 memset(skb->data, 0xFF, frame_size);
Jeff Kirsherce7393b2006-01-12 16:51:12 -08001458 frame_size &= ~1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1460 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1461 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1462}
1463
1464static int
1465e1000_check_lbtest_frame(struct sk_buff *skb, unsigned int frame_size)
1466{
Jeff Kirsherce7393b2006-01-12 16:51:12 -08001467 frame_size &= ~1;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001468 if (*(skb->data + 3) == 0xFF) {
1469 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
1471 return 0;
1472 }
1473 }
1474 return 13;
1475}
1476
1477static int
1478e1000_run_loopback_test(struct e1000_adapter *adapter)
1479{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001480 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1481 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 struct pci_dev *pdev = adapter->pdev;
Malli Chilakalae4eff722005-04-28 19:38:30 -07001483 int i, j, k, l, lc, good_cnt, ret_val=0;
1484 unsigned long time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485
1486 E1000_WRITE_REG(&adapter->hw, RDT, rxdr->count - 1);
1487
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001488 /* Calculate the loop count based on the largest descriptor ring
Malli Chilakalae4eff722005-04-28 19:38:30 -07001489 * The idea is to wrap the largest ring a number of times using 64
1490 * send/receive pairs during each loop
1491 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001493 if (rxdr->count <= txdr->count)
Malli Chilakalae4eff722005-04-28 19:38:30 -07001494 lc = ((txdr->count / 64) * 2) + 1;
1495 else
1496 lc = ((rxdr->count / 64) * 2) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
Malli Chilakalae4eff722005-04-28 19:38:30 -07001498 k = l = 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001499 for (j = 0; j <= lc; j++) { /* loop count loop */
1500 for (i = 0; i < 64; i++) { /* send the packets */
1501 e1000_create_lbtest_frame(txdr->buffer_info[i].skb,
Malli Chilakalae4eff722005-04-28 19:38:30 -07001502 1024);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001503 pci_dma_sync_single_for_device(pdev,
Malli Chilakalae4eff722005-04-28 19:38:30 -07001504 txdr->buffer_info[k].dma,
1505 txdr->buffer_info[k].length,
1506 PCI_DMA_TODEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001507 if (unlikely(++k == txdr->count)) k = 0;
Malli Chilakalae4eff722005-04-28 19:38:30 -07001508 }
1509 E1000_WRITE_REG(&adapter->hw, TDT, k);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001510 msleep(200);
Malli Chilakalae4eff722005-04-28 19:38:30 -07001511 time = jiffies; /* set the start time for the receive */
1512 good_cnt = 0;
1513 do { /* receive the sent packets */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001514 pci_dma_sync_single_for_cpu(pdev,
Malli Chilakalae4eff722005-04-28 19:38:30 -07001515 rxdr->buffer_info[l].dma,
1516 rxdr->buffer_info[l].length,
1517 PCI_DMA_FROMDEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001518
Malli Chilakalae4eff722005-04-28 19:38:30 -07001519 ret_val = e1000_check_lbtest_frame(
1520 rxdr->buffer_info[l].skb,
1521 1024);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001522 if (!ret_val)
Malli Chilakalae4eff722005-04-28 19:38:30 -07001523 good_cnt++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001524 if (unlikely(++l == rxdr->count)) l = 0;
1525 /* time + 20 msecs (200 msecs on 2.4) is more than
1526 * enough time to complete the receives, if it's
Malli Chilakalae4eff722005-04-28 19:38:30 -07001527 * exceeded, break and error off
1528 */
1529 } while (good_cnt < 64 && jiffies < (time + 20));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001530 if (good_cnt != 64) {
Malli Chilakalae4eff722005-04-28 19:38:30 -07001531 ret_val = 13; /* ret_val is the same as mis-compare */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001532 break;
Malli Chilakalae4eff722005-04-28 19:38:30 -07001533 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001534 if (jiffies >= (time + 2)) {
Malli Chilakalae4eff722005-04-28 19:38:30 -07001535 ret_val = 14; /* error code for time out error */
1536 break;
1537 }
1538 } /* end loop count loop */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 return ret_val;
1540}
1541
1542static int
1543e1000_loopback_test(struct e1000_adapter *adapter, uint64_t *data)
1544{
Jeff Kirsher57128192006-01-12 16:50:28 -08001545 /* PHY loopback cannot be performed if SoL/IDER
1546 * sessions are active */
1547 if (e1000_check_phy_reset_block(&adapter->hw)) {
1548 DPRINTK(DRV, ERR, "Cannot do PHY loopback test "
1549 "when SoL/IDER is active.\n");
1550 *data = 0;
1551 goto out;
1552 }
1553
1554 if ((*data = e1000_setup_desc_rings(adapter)))
1555 goto out;
1556 if ((*data = e1000_setup_loopback_test(adapter)))
1557 goto err_loopback;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 *data = e1000_run_loopback_test(adapter);
1559 e1000_loopback_cleanup(adapter);
Jeff Kirsher57128192006-01-12 16:50:28 -08001560
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561err_loopback:
Jeff Kirsher57128192006-01-12 16:50:28 -08001562 e1000_free_desc_rings(adapter);
1563out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 return *data;
1565}
1566
1567static int
1568e1000_link_test(struct e1000_adapter *adapter, uint64_t *data)
1569{
1570 *data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 if (adapter->hw.media_type == e1000_media_type_internal_serdes) {
1572 int i = 0;
1573 adapter->hw.serdes_link_down = TRUE;
1574
Malli Chilakala26483452005-04-28 19:44:46 -07001575 /* On some blade server designs, link establishment
1576 * could take as long as 2-3 minutes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 do {
1578 e1000_check_for_link(&adapter->hw);
1579 if (adapter->hw.serdes_link_down == FALSE)
1580 return *data;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001581 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 } while (i++ < 3750);
1583
Malli Chilakala26483452005-04-28 19:44:46 -07001584 *data = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 } else {
1586 e1000_check_for_link(&adapter->hw);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001587 if (adapter->hw.autoneg) /* if auto_neg is set wait for it */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001588 msleep(4000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001590 if (!(E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 *data = 1;
1592 }
1593 }
1594 return *data;
1595}
1596
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001597static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598e1000_diag_test_count(struct net_device *netdev)
1599{
1600 return E1000_TEST_LEN;
1601}
1602
Jesse Brandeburgd6582662006-08-16 13:31:33 -07001603extern void e1000_power_up_phy(struct e1000_adapter *);
1604
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605static void
1606e1000_diag_test(struct net_device *netdev,
1607 struct ethtool_test *eth_test, uint64_t *data)
1608{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001609 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 boolean_t if_running = netif_running(netdev);
1611
Auke Kok2db10a02006-06-27 09:06:28 -07001612 set_bit(__E1000_DRIVER_TESTING, &adapter->flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001613 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 /* Offline tests */
1615
1616 /* save speed, duplex, autoneg settings */
1617 uint16_t autoneg_advertised = adapter->hw.autoneg_advertised;
1618 uint8_t forced_speed_duplex = adapter->hw.forced_speed_duplex;
1619 uint8_t autoneg = adapter->hw.autoneg;
1620
Jesse Brandeburgd6582662006-08-16 13:31:33 -07001621 DPRINTK(HW, INFO, "offline testing starting\n");
1622
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 /* Link test performed before hardware reset so autoneg doesn't
1624 * interfere with test result */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001625 if (e1000_link_test(adapter, &data[4]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 eth_test->flags |= ETH_TEST_FL_FAILED;
1627
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001628 if (if_running)
Auke Kok2db10a02006-06-27 09:06:28 -07001629 /* indicate we're in test mode */
1630 dev_close(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 else
1632 e1000_reset(adapter);
1633
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001634 if (e1000_reg_test(adapter, &data[0]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 eth_test->flags |= ETH_TEST_FL_FAILED;
1636
1637 e1000_reset(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001638 if (e1000_eeprom_test(adapter, &data[1]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 eth_test->flags |= ETH_TEST_FL_FAILED;
1640
1641 e1000_reset(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001642 if (e1000_intr_test(adapter, &data[2]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 eth_test->flags |= ETH_TEST_FL_FAILED;
1644
1645 e1000_reset(adapter);
Jesse Brandeburgd6582662006-08-16 13:31:33 -07001646 /* make sure the phy is powered up */
1647 e1000_power_up_phy(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001648 if (e1000_loopback_test(adapter, &data[3]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 eth_test->flags |= ETH_TEST_FL_FAILED;
1650
1651 /* restore speed, duplex, autoneg settings */
1652 adapter->hw.autoneg_advertised = autoneg_advertised;
1653 adapter->hw.forced_speed_duplex = forced_speed_duplex;
1654 adapter->hw.autoneg = autoneg;
1655
1656 e1000_reset(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -07001657 clear_bit(__E1000_DRIVER_TESTING, &adapter->flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001658 if (if_running)
Auke Kok2db10a02006-06-27 09:06:28 -07001659 dev_open(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 } else {
Jesse Brandeburgd6582662006-08-16 13:31:33 -07001661 DPRINTK(HW, INFO, "online testing starting\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 /* Online tests */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001663 if (e1000_link_test(adapter, &data[4]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 eth_test->flags |= ETH_TEST_FL_FAILED;
1665
1666 /* Offline tests aren't run; pass by default */
1667 data[0] = 0;
1668 data[1] = 0;
1669 data[2] = 0;
1670 data[3] = 0;
Auke Kok2db10a02006-06-27 09:06:28 -07001671
1672 clear_bit(__E1000_DRIVER_TESTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 }
Mallikarjuna R Chilakala352c9f82005-10-04 07:07:24 -04001674 msleep_interruptible(4 * 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675}
1676
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001677static int e1000_wol_exclusion(struct e1000_adapter *adapter, struct ethtool_wolinfo *wol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001680 int retval = 1; /* fail by default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001682 switch (hw->device_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 case E1000_DEV_ID_82543GC_FIBER:
1684 case E1000_DEV_ID_82543GC_COPPER:
1685 case E1000_DEV_ID_82544EI_FIBER:
1686 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1687 case E1000_DEV_ID_82545EM_FIBER:
1688 case E1000_DEV_ID_82545EM_COPPER:
Jeff Kirsher84916822006-03-02 18:18:48 -08001689 case E1000_DEV_ID_82546GB_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001690 case E1000_DEV_ID_82546GB_PCIE:
1691 /* these don't support WoL at all */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 wol->supported = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001693 break;
1694 case E1000_DEV_ID_82546EB_FIBER:
1695 case E1000_DEV_ID_82546GB_FIBER:
1696 case E1000_DEV_ID_82571EB_FIBER:
1697 case E1000_DEV_ID_82571EB_SERDES:
1698 case E1000_DEV_ID_82571EB_COPPER:
1699 /* Wake events not supported on port B */
1700 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) {
1701 wol->supported = 0;
1702 break;
1703 }
1704 /* return success for non excluded adapter ports */
1705 retval = 0;
1706 break;
Jesse Brandeburg5881cde2006-08-31 14:27:47 -07001707 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001708 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1709 /* quad port adapters only support WoL on port A */
1710 if (!adapter->quad_port_a) {
1711 wol->supported = 0;
1712 break;
1713 }
1714 /* return success for non excluded adapter ports */
1715 retval = 0;
1716 break;
1717 default:
1718 /* dual port cards only support WoL on port A from now on
1719 * unless it was enabled in the eeprom for port B
1720 * so exclude FUNC_1 ports from having WoL enabled */
1721 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1 &&
1722 !adapter->eeprom_wol) {
1723 wol->supported = 0;
1724 break;
1725 }
1726
1727 retval = 0;
1728 }
1729
1730 return retval;
1731}
1732
1733static void
1734e1000_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1735{
1736 struct e1000_adapter *adapter = netdev_priv(netdev);
1737
1738 wol->supported = WAKE_UCAST | WAKE_MCAST |
1739 WAKE_BCAST | WAKE_MAGIC;
1740 wol->wolopts = 0;
1741
1742 /* this function will set ->supported = 0 and return 1 if wol is not
1743 * supported by this hardware */
1744 if (e1000_wol_exclusion(adapter, wol))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 return;
1746
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001747 /* apply any specific unsupported masks here */
1748 switch (adapter->hw.device_id) {
Jeff Kirsher84916822006-03-02 18:18:48 -08001749 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001750 /* KSP3 does not suppport UCAST wake-ups */
1751 wol->supported &= ~WAKE_UCAST;
Jeff Kirsher84916822006-03-02 18:18:48 -08001752
1753 if (adapter->wol & E1000_WUFC_EX)
1754 DPRINTK(DRV, ERR, "Interface does not support "
1755 "directed (unicast) frame wake-up packets\n");
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001756 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 default:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001758 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 }
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001760
1761 if (adapter->wol & E1000_WUFC_EX)
1762 wol->wolopts |= WAKE_UCAST;
1763 if (adapter->wol & E1000_WUFC_MC)
1764 wol->wolopts |= WAKE_MCAST;
1765 if (adapter->wol & E1000_WUFC_BC)
1766 wol->wolopts |= WAKE_BCAST;
1767 if (adapter->wol & E1000_WUFC_MAG)
1768 wol->wolopts |= WAKE_MAGIC;
1769
1770 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771}
1772
1773static int
1774e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1775{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001776 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 struct e1000_hw *hw = &adapter->hw;
1778
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001779 if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
1780 return -EOPNOTSUPP;
1781
1782 if (e1000_wol_exclusion(adapter, wol))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 return wol->wolopts ? -EOPNOTSUPP : 0;
1784
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001785 switch (hw->device_id) {
Jeff Kirsher84916822006-03-02 18:18:48 -08001786 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jeff Kirsher84916822006-03-02 18:18:48 -08001787 if (wol->wolopts & WAKE_UCAST) {
1788 DPRINTK(DRV, ERR, "Interface does not support "
1789 "directed (unicast) frame wake-up packets\n");
1790 return -EOPNOTSUPP;
1791 }
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001792 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 default:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001794 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 }
1796
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001797 /* these settings will always override what we currently have */
1798 adapter->wol = 0;
1799
1800 if (wol->wolopts & WAKE_UCAST)
1801 adapter->wol |= E1000_WUFC_EX;
1802 if (wol->wolopts & WAKE_MCAST)
1803 adapter->wol |= E1000_WUFC_MC;
1804 if (wol->wolopts & WAKE_BCAST)
1805 adapter->wol |= E1000_WUFC_BC;
1806 if (wol->wolopts & WAKE_MAGIC)
1807 adapter->wol |= E1000_WUFC_MAG;
1808
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 return 0;
1810}
1811
1812/* toggle LED 4 times per second = 2 "blinks" per second */
1813#define E1000_ID_INTERVAL (HZ/4)
1814
1815/* bit defines for adapter->led_status */
1816#define E1000_LED_ON 0
1817
1818static void
1819e1000_led_blink_callback(unsigned long data)
1820{
1821 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
1822
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001823 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 e1000_led_off(&adapter->hw);
1825 else
1826 e1000_led_on(&adapter->hw);
1827
1828 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1829}
1830
1831static int
1832e1000_phys_id(struct net_device *netdev, uint32_t data)
1833{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001834 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001836 if (!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ);
1838
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001839 if (adapter->hw.mac_type < e1000_82571) {
1840 if (!adapter->blink_timer.function) {
Malli Chilakalad439d4b2005-06-17 17:43:56 -07001841 init_timer(&adapter->blink_timer);
1842 adapter->blink_timer.function = e1000_led_blink_callback;
1843 adapter->blink_timer.data = (unsigned long) adapter;
1844 }
1845 e1000_setup_led(&adapter->hw);
1846 mod_timer(&adapter->blink_timer, jiffies);
1847 msleep_interruptible(data * 1000);
1848 del_timer_sync(&adapter->blink_timer);
Auke Kokcd94dd02006-06-27 09:08:22 -07001849 } else if (adapter->hw.phy_type == e1000_phy_ife) {
1850 if (!adapter->blink_timer.function) {
1851 init_timer(&adapter->blink_timer);
1852 adapter->blink_timer.function = e1000_led_blink_callback;
1853 adapter->blink_timer.data = (unsigned long) adapter;
1854 }
1855 mod_timer(&adapter->blink_timer, jiffies);
Jeff Kirsherd8c2bd32006-01-12 16:50:37 -08001856 msleep_interruptible(data * 1000);
Auke Kokcd94dd02006-06-27 09:08:22 -07001857 del_timer_sync(&adapter->blink_timer);
1858 e1000_write_phy_reg(&(adapter->hw), IFE_PHY_SPECIAL_CONTROL_LED, 0);
Jeff Kirsherd8c2bd32006-01-12 16:50:37 -08001859 } else {
Auke Kokf1b3a852006-06-27 09:07:56 -07001860 e1000_blink_led_start(&adapter->hw);
Malli Chilakalad439d4b2005-06-17 17:43:56 -07001861 msleep_interruptible(data * 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 }
1863
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 e1000_led_off(&adapter->hw);
1865 clear_bit(E1000_LED_ON, &adapter->led_status);
1866 e1000_cleanup_led(&adapter->hw);
1867
1868 return 0;
1869}
1870
1871static int
1872e1000_nway_reset(struct net_device *netdev)
1873{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001874 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kok2db10a02006-06-27 09:06:28 -07001875 if (netif_running(netdev))
1876 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 return 0;
1878}
1879
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001880static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881e1000_get_stats_count(struct net_device *netdev)
1882{
1883 return E1000_STATS_LEN;
1884}
1885
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001886static void
1887e1000_get_ethtool_stats(struct net_device *netdev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 struct ethtool_stats *stats, uint64_t *data)
1889{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001890 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 int i;
1892
1893 e1000_update_stats(adapter);
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001894 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1895 char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
1896 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
1898 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001899/* BUG_ON(i != E1000_STATS_LEN); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900}
1901
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001902static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903e1000_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
1904{
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001905 uint8_t *p = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 int i;
1907
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001908 switch (stringset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 case ETH_SS_TEST:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001910 memcpy(data, *e1000_gstrings_test,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 E1000_TEST_LEN*ETH_GSTRING_LEN);
1912 break;
1913 case ETH_SS_STATS:
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001914 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1915 memcpy(p, e1000_gstrings_stats[i].stat_string,
1916 ETH_GSTRING_LEN);
1917 p += ETH_GSTRING_LEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001919/* BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 break;
1921 }
1922}
1923
Jeff Garzik7282d492006-09-13 14:30:00 -04001924static const struct ethtool_ops e1000_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 .get_settings = e1000_get_settings,
1926 .set_settings = e1000_set_settings,
1927 .get_drvinfo = e1000_get_drvinfo,
1928 .get_regs_len = e1000_get_regs_len,
1929 .get_regs = e1000_get_regs,
1930 .get_wol = e1000_get_wol,
1931 .set_wol = e1000_set_wol,
Auke Kok8fc897b2006-08-28 14:56:16 -07001932 .get_msglevel = e1000_get_msglevel,
1933 .set_msglevel = e1000_set_msglevel,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 .nway_reset = e1000_nway_reset,
1935 .get_link = ethtool_op_get_link,
1936 .get_eeprom_len = e1000_get_eeprom_len,
1937 .get_eeprom = e1000_get_eeprom,
1938 .set_eeprom = e1000_set_eeprom,
1939 .get_ringparam = e1000_get_ringparam,
1940 .set_ringparam = e1000_set_ringparam,
Auke Kok8fc897b2006-08-28 14:56:16 -07001941 .get_pauseparam = e1000_get_pauseparam,
1942 .set_pauseparam = e1000_set_pauseparam,
1943 .get_rx_csum = e1000_get_rx_csum,
1944 .set_rx_csum = e1000_set_rx_csum,
1945 .get_tx_csum = e1000_get_tx_csum,
1946 .set_tx_csum = e1000_set_tx_csum,
1947 .get_sg = ethtool_op_get_sg,
1948 .set_sg = ethtool_op_set_sg,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949#ifdef NETIF_F_TSO
Auke Kok8fc897b2006-08-28 14:56:16 -07001950 .get_tso = ethtool_op_get_tso,
1951 .set_tso = e1000_set_tso,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952#endif
1953 .self_test_count = e1000_diag_test_count,
1954 .self_test = e1000_diag_test,
1955 .get_strings = e1000_get_strings,
1956 .phys_id = e1000_phys_id,
1957 .get_stats_count = e1000_get_stats_count,
1958 .get_ethtool_stats = e1000_get_ethtool_stats,
Auke Kok8fc897b2006-08-28 14:56:16 -07001959 .get_perm_addr = ethtool_op_get_perm_addr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960};
1961
1962void e1000_set_ethtool_ops(struct net_device *netdev)
1963{
1964 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
1965}