blob: 966d52a529ec0bf21f0a5bfd59f86f0d42adf3cc [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
Nicholas Nunley35574762006-09-27 12:53:34 -070035extern int e1000_up(struct e1000_adapter *adapter);
36extern void e1000_down(struct e1000_adapter *adapter);
37extern void e1000_reinit_locked(struct e1000_adapter *adapter);
38extern void e1000_reset(struct e1000_adapter *adapter);
Joe Perches406874a2008-04-03 10:06:32 -070039extern int e1000_set_spd_dplx(struct e1000_adapter *adapter, u16 spddplx);
Nicholas Nunley35574762006-09-27 12:53:34 -070040extern int e1000_setup_all_rx_resources(struct e1000_adapter *adapter);
41extern int e1000_setup_all_tx_resources(struct e1000_adapter *adapter);
42extern void e1000_free_all_rx_resources(struct e1000_adapter *adapter);
43extern void e1000_free_all_tx_resources(struct e1000_adapter *adapter);
44extern void e1000_update_stats(struct e1000_adapter *adapter);
45
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047struct e1000_stats {
48 char stat_string[ETH_GSTRING_LEN];
49 int sizeof_stat;
50 int stat_offset;
51};
52
Julia Lawall030ed682008-02-11 09:25:40 -080053#define E1000_STAT(m) FIELD_SIZEOF(struct e1000_adapter, m), \
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 offsetof(struct e1000_adapter, m)
55static const struct e1000_stats e1000_gstrings_stats[] = {
Mitch Williams49559852006-09-27 12:53:37 -070056 { "rx_packets", E1000_STAT(stats.gprc) },
57 { "tx_packets", E1000_STAT(stats.gptc) },
58 { "rx_bytes", E1000_STAT(stats.gorcl) },
59 { "tx_bytes", E1000_STAT(stats.gotcl) },
60 { "rx_broadcast", E1000_STAT(stats.bprc) },
61 { "tx_broadcast", E1000_STAT(stats.bptc) },
62 { "rx_multicast", E1000_STAT(stats.mprc) },
63 { "tx_multicast", E1000_STAT(stats.mptc) },
64 { "rx_errors", E1000_STAT(stats.rxerrc) },
65 { "tx_errors", E1000_STAT(stats.txerrc) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 { "tx_dropped", E1000_STAT(net_stats.tx_dropped) },
Mitch Williams49559852006-09-27 12:53:37 -070067 { "multicast", E1000_STAT(stats.mprc) },
68 { "collisions", E1000_STAT(stats.colc) },
69 { "rx_length_errors", E1000_STAT(stats.rlerrc) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 { "rx_over_errors", E1000_STAT(net_stats.rx_over_errors) },
Mitch Williams49559852006-09-27 12:53:37 -070071 { "rx_crc_errors", E1000_STAT(stats.crcerrs) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 { "rx_frame_errors", E1000_STAT(net_stats.rx_frame_errors) },
Malli Chilakala26483452005-04-28 19:44:46 -070073 { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
Mitch Williams49559852006-09-27 12:53:37 -070074 { "rx_missed_errors", E1000_STAT(stats.mpc) },
75 { "tx_aborted_errors", E1000_STAT(stats.ecol) },
76 { "tx_carrier_errors", E1000_STAT(stats.tncrs) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 { "tx_fifo_errors", E1000_STAT(net_stats.tx_fifo_errors) },
78 { "tx_heartbeat_errors", E1000_STAT(net_stats.tx_heartbeat_errors) },
Mitch Williams49559852006-09-27 12:53:37 -070079 { "tx_window_errors", E1000_STAT(stats.latecol) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
81 { "tx_deferred_ok", E1000_STAT(stats.dc) },
82 { "tx_single_coll_ok", E1000_STAT(stats.scc) },
83 { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
Jeff Kirsher6b7660c2006-01-12 16:50:35 -080084 { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -080085 { "tx_restart_queue", E1000_STAT(restart_queue) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 { "rx_long_length_errors", E1000_STAT(stats.roc) },
87 { "rx_short_length_errors", E1000_STAT(stats.ruc) },
88 { "rx_align_errors", E1000_STAT(stats.algnerrc) },
89 { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
90 { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
91 { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
92 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
93 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
94 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
95 { "rx_long_byte_count", E1000_STAT(stats.gorcl) },
96 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -040097 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
98 { "rx_header_split", E1000_STAT(rx_hdr_split) },
Jeff Kirsher6b7660c2006-01-12 16:50:35 -080099 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
Jeff Garzik15e376b2006-12-15 11:16:33 -0500100 { "tx_smbus", E1000_STAT(stats.mgptc) },
101 { "rx_smbus", E1000_STAT(stats.mgprc) },
102 { "dropped_smbus", E1000_STAT(stats.mgpdc) },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103};
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800104
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800105#define E1000_QUEUE_STATS_LEN 0
Denis Chengff8ac602007-09-02 18:30:18 +0800106#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800107#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN + E1000_QUEUE_STATS_LEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
109 "Register test (offline)", "Eeprom test (offline)",
110 "Interrupt test (offline)", "Loopback test (offline)",
111 "Link test (on/offline)"
112};
Alejandro Martinez Ruiz4c3616c2007-10-18 10:00:15 +0200113#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Joe Perches64798842008-07-11 15:17:02 -0700115static int e1000_get_settings(struct net_device *netdev,
116 struct ethtool_cmd *ecmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700118 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 struct e1000_hw *hw = &adapter->hw;
120
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800121 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123 ecmd->supported = (SUPPORTED_10baseT_Half |
124 SUPPORTED_10baseT_Full |
125 SUPPORTED_100baseT_Half |
126 SUPPORTED_100baseT_Full |
127 SUPPORTED_1000baseT_Full|
128 SUPPORTED_Autoneg |
129 SUPPORTED_TP);
Auke Kokcd94dd02006-06-27 09:08:22 -0700130 if (hw->phy_type == e1000_phy_ife)
131 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 ecmd->advertising = ADVERTISED_TP;
133
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800134 if (hw->autoneg == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 ecmd->advertising |= ADVERTISED_Autoneg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 /* the e1000 autoneg seems to match ethtool nicely */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 ecmd->advertising |= hw->autoneg_advertised;
138 }
139
140 ecmd->port = PORT_TP;
141 ecmd->phy_address = hw->phy_addr;
142
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800143 if (hw->mac_type == e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 ecmd->transceiver = XCVR_EXTERNAL;
145 else
146 ecmd->transceiver = XCVR_INTERNAL;
147
148 } else {
149 ecmd->supported = (SUPPORTED_1000baseT_Full |
150 SUPPORTED_FIBRE |
151 SUPPORTED_Autoneg);
152
Malli Chilakala012609a2005-06-17 17:43:06 -0700153 ecmd->advertising = (ADVERTISED_1000baseT_Full |
154 ADVERTISED_FIBRE |
155 ADVERTISED_Autoneg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157 ecmd->port = PORT_FIBRE;
158
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800159 if (hw->mac_type >= e1000_82545)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 ecmd->transceiver = XCVR_INTERNAL;
161 else
162 ecmd->transceiver = XCVR_EXTERNAL;
163 }
164
Joe Perches1dc32912008-07-11 15:17:08 -0700165 if (er32(STATUS) & E1000_STATUS_LU) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 e1000_get_speed_and_duplex(hw, &adapter->link_speed,
168 &adapter->link_duplex);
169 ecmd->speed = adapter->link_speed;
170
171 /* unfortunatly FULL_DUPLEX != DUPLEX_FULL
172 * and HALF_DUPLEX != DUPLEX_HALF */
173
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800174 if (adapter->link_duplex == FULL_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 ecmd->duplex = DUPLEX_FULL;
176 else
177 ecmd->duplex = DUPLEX_HALF;
178 } else {
179 ecmd->speed = -1;
180 ecmd->duplex = -1;
181 }
182
183 ecmd->autoneg = ((hw->media_type == e1000_media_type_fiber) ||
184 hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
185 return 0;
186}
187
Joe Perches64798842008-07-11 15:17:02 -0700188static int e1000_set_settings(struct net_device *netdev,
189 struct ethtool_cmd *ecmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700191 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 struct e1000_hw *hw = &adapter->hw;
193
Jeff Kirsher57128192006-01-12 16:50:28 -0800194 /* When SoL/IDER sessions are active, autoneg/speed/duplex
195 * cannot be changed */
196 if (e1000_check_phy_reset_block(hw)) {
197 DPRINTK(DRV, ERR, "Cannot change link characteristics "
198 "when SoL/IDER is active.\n");
199 return -EINVAL;
200 }
201
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700202 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
203 msleep(1);
204
Jeff Kirsher57128192006-01-12 16:50:28 -0800205 if (ecmd->autoneg == AUTONEG_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 hw->autoneg = 1;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800207 if (hw->media_type == e1000_media_type_fiber)
Malli Chilakala012609a2005-06-17 17:43:06 -0700208 hw->autoneg_advertised = ADVERTISED_1000baseT_Full |
209 ADVERTISED_FIBRE |
210 ADVERTISED_Autoneg;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800211 else
Jeff Kirsher2f2ca262006-09-27 12:53:40 -0700212 hw->autoneg_advertised = ecmd->advertising |
213 ADVERTISED_TP |
214 ADVERTISED_Autoneg;
Malli Chilakala012609a2005-06-17 17:43:06 -0700215 ecmd->advertising = hw->autoneg_advertised;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 } else
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700217 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
218 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 return -EINVAL;
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700220 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 /* reset the link */
223
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700224 if (netif_running(adapter->netdev)) {
225 e1000_down(adapter);
226 e1000_up(adapter);
227 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 e1000_reset(adapter);
229
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700230 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 return 0;
232}
233
Joe Perches64798842008-07-11 15:17:02 -0700234static void e1000_get_pauseparam(struct net_device *netdev,
235 struct ethtool_pauseparam *pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700237 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 struct e1000_hw *hw = &adapter->hw;
239
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800240 pause->autoneg =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800242
Jeff Kirsher11241b12006-09-27 12:53:28 -0700243 if (hw->fc == E1000_FC_RX_PAUSE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 pause->rx_pause = 1;
Jeff Kirsher11241b12006-09-27 12:53:28 -0700245 else if (hw->fc == E1000_FC_TX_PAUSE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 pause->tx_pause = 1;
Jeff Kirsher11241b12006-09-27 12:53:28 -0700247 else if (hw->fc == E1000_FC_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 pause->rx_pause = 1;
249 pause->tx_pause = 1;
250 }
251}
252
Joe Perches64798842008-07-11 15:17:02 -0700253static int e1000_set_pauseparam(struct net_device *netdev,
254 struct ethtool_pauseparam *pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700256 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700258 int retval = 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 adapter->fc_autoneg = pause->autoneg;
261
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700262 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
263 msleep(1);
264
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800265 if (pause->rx_pause && pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700266 hw->fc = E1000_FC_FULL;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800267 else if (pause->rx_pause && !pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700268 hw->fc = E1000_FC_RX_PAUSE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800269 else if (!pause->rx_pause && pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700270 hw->fc = E1000_FC_TX_PAUSE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800271 else if (!pause->rx_pause && !pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700272 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274 hw->original_fc = hw->fc;
275
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800276 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700277 if (netif_running(adapter->netdev)) {
278 e1000_down(adapter);
279 e1000_up(adapter);
280 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 e1000_reset(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800282 } else
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700283 retval = ((hw->media_type == e1000_media_type_fiber) ?
Auke Kok90fb5132006-11-01 08:47:30 -0800284 e1000_setup_link(hw) : e1000_force_mac_fc(hw));
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800285
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700286 clear_bit(__E1000_RESETTING, &adapter->flags);
287 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}
289
Joe Perches64798842008-07-11 15:17:02 -0700290static u32 e1000_get_rx_csum(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700292 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 return adapter->rx_csum;
294}
295
Joe Perches64798842008-07-11 15:17:02 -0700296static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700298 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 adapter->rx_csum = data;
300
Auke Kok2db10a02006-06-27 09:06:28 -0700301 if (netif_running(netdev))
302 e1000_reinit_locked(adapter);
303 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 e1000_reset(adapter);
305 return 0;
306}
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800307
Joe Perches64798842008-07-11 15:17:02 -0700308static u32 e1000_get_tx_csum(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
310 return (netdev->features & NETIF_F_HW_CSUM) != 0;
311}
312
Joe Perches64798842008-07-11 15:17:02 -0700313static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700315 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700316 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Joe Perches1dc32912008-07-11 15:17:08 -0700318 if (hw->mac_type < e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 if (!data)
320 return -EINVAL;
321 return 0;
322 }
323
324 if (data)
325 netdev->features |= NETIF_F_HW_CSUM;
326 else
327 netdev->features &= ~NETIF_F_HW_CSUM;
328
329 return 0;
330}
331
Joe Perches64798842008-07-11 15:17:02 -0700332static int e1000_set_tso(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700334 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700335 struct e1000_hw *hw = &adapter->hw;
336
337 if ((hw->mac_type < e1000_82544) ||
338 (hw->mac_type == e1000_82547))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 return data ? -EINVAL : 0;
340
341 if (data)
342 netdev->features |= NETIF_F_TSO;
343 else
344 netdev->features &= ~NETIF_F_TSO;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -0800345
Andy Gospodarek581abbc2008-06-19 17:19:02 -0400346 if (data && (adapter->hw.mac_type > e1000_82547_rev_2))
Auke Kok87ca4e52006-11-01 08:47:36 -0800347 netdev->features |= NETIF_F_TSO6;
348 else
349 netdev->features &= ~NETIF_F_TSO6;
Auke Kok87ca4e52006-11-01 08:47:36 -0800350
Jeff Kirsher7e6c9862006-03-02 18:19:30 -0800351 DPRINTK(PROBE, INFO, "TSO is %s\n", data ? "Enabled" : "Disabled");
Joe Perchesc3033b02008-03-21 11:06:25 -0700352 adapter->tso_force = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 return 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800354}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Joe Perches64798842008-07-11 15:17:02 -0700356static u32 e1000_get_msglevel(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700358 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 return adapter->msg_enable;
360}
361
Joe Perches64798842008-07-11 15:17:02 -0700362static void e1000_set_msglevel(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700364 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 adapter->msg_enable = data;
366}
367
Joe Perches64798842008-07-11 15:17:02 -0700368static int e1000_get_regs_len(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
370#define E1000_REGS_LEN 32
Joe Perches406874a2008-04-03 10:06:32 -0700371 return E1000_REGS_LEN * sizeof(u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372}
373
Joe Perches64798842008-07-11 15:17:02 -0700374static void e1000_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
375 void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700377 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700379 u32 *regs_buff = p;
380 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Joe Perches406874a2008-04-03 10:06:32 -0700382 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
385
Joe Perches1dc32912008-07-11 15:17:08 -0700386 regs_buff[0] = er32(CTRL);
387 regs_buff[1] = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Joe Perches1dc32912008-07-11 15:17:08 -0700389 regs_buff[2] = er32(RCTL);
390 regs_buff[3] = er32(RDLEN);
391 regs_buff[4] = er32(RDH);
392 regs_buff[5] = er32(RDT);
393 regs_buff[6] = er32(RDTR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Joe Perches1dc32912008-07-11 15:17:08 -0700395 regs_buff[7] = er32(TCTL);
396 regs_buff[8] = er32(TDLEN);
397 regs_buff[9] = er32(TDH);
398 regs_buff[10] = er32(TDT);
399 regs_buff[11] = er32(TIDV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Joe Perches1dc32912008-07-11 15:17:08 -0700401 regs_buff[12] = hw->phy_type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800402 if (hw->phy_type == e1000_phy_igp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
404 IGP01E1000_PHY_AGC_A);
405 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A &
406 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700407 regs_buff[13] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
409 IGP01E1000_PHY_AGC_B);
410 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B &
411 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700412 regs_buff[14] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
414 IGP01E1000_PHY_AGC_C);
415 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C &
416 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700417 regs_buff[15] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
419 IGP01E1000_PHY_AGC_D);
420 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D &
421 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700422 regs_buff[16] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 regs_buff[17] = 0; /* extended 10bt distance (not needed) */
424 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
425 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS &
426 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700427 regs_buff[18] = (u32)phy_data; /* cable polarity */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
429 IGP01E1000_PHY_PCS_INIT_REG);
430 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG &
431 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700432 regs_buff[19] = (u32)phy_data; /* cable polarity */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 regs_buff[20] = 0; /* polarity correction enabled (always) */
434 regs_buff[22] = 0; /* phy receive errors (unavailable) */
435 regs_buff[23] = regs_buff[18]; /* mdix mode */
436 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
437 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -0700438 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700439 regs_buff[13] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
441 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
442 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
Auke Kok8fc897b2006-08-28 14:56:16 -0700443 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700444 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 regs_buff[18] = regs_buff[13]; /* cable polarity */
446 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
447 regs_buff[20] = regs_buff[17]; /* polarity correction */
448 /* phy receive errors */
449 regs_buff[22] = adapter->phy_stats.receive_errors;
450 regs_buff[23] = regs_buff[13]; /* mdix mode */
451 }
452 regs_buff[21] = adapter->phy_stats.idle_errors; /* phy idle errors */
453 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700454 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800456 if (hw->mac_type >= e1000_82540 &&
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -0700457 hw->mac_type < e1000_82571 &&
458 hw->media_type == e1000_media_type_copper) {
Joe Perches1dc32912008-07-11 15:17:08 -0700459 regs_buff[26] = er32(MANC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 }
461}
462
Joe Perches64798842008-07-11 15:17:02 -0700463static int e1000_get_eeprom_len(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700465 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700466 struct e1000_hw *hw = &adapter->hw;
467
468 return hw->eeprom.word_size * 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469}
470
Joe Perches64798842008-07-11 15:17:02 -0700471static int e1000_get_eeprom(struct net_device *netdev,
472 struct ethtool_eeprom *eeprom, u8 *bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700474 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700476 u16 *eeprom_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 int first_word, last_word;
478 int ret_val = 0;
Joe Perches406874a2008-04-03 10:06:32 -0700479 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800481 if (eeprom->len == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 return -EINVAL;
483
484 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
485
486 first_word = eeprom->offset >> 1;
487 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
488
Joe Perches406874a2008-04-03 10:06:32 -0700489 eeprom_buff = kmalloc(sizeof(u16) *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 (last_word - first_word + 1), GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800491 if (!eeprom_buff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 return -ENOMEM;
493
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800494 if (hw->eeprom.type == e1000_eeprom_spi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 ret_val = e1000_read_eeprom(hw, first_word,
496 last_word - first_word + 1,
497 eeprom_buff);
498 else {
499 for (i = 0; i < last_word - first_word + 1; i++)
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800500 if ((ret_val = e1000_read_eeprom(hw, first_word + i, 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 &eeprom_buff[i])))
502 break;
503 }
504
505 /* Device's eeprom is always little-endian, word addressable */
506 for (i = 0; i < last_word - first_word + 1; i++)
507 le16_to_cpus(&eeprom_buff[i]);
508
Joe Perches406874a2008-04-03 10:06:32 -0700509 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 eeprom->len);
511 kfree(eeprom_buff);
512
513 return ret_val;
514}
515
Joe Perches64798842008-07-11 15:17:02 -0700516static int e1000_set_eeprom(struct net_device *netdev,
517 struct ethtool_eeprom *eeprom, u8 *bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700519 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700521 u16 *eeprom_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 void *ptr;
523 int max_len, first_word, last_word, ret_val = 0;
Joe Perches406874a2008-04-03 10:06:32 -0700524 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800526 if (eeprom->len == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 return -EOPNOTSUPP;
528
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800529 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 return -EFAULT;
531
532 max_len = hw->eeprom.word_size * 2;
533
534 first_word = eeprom->offset >> 1;
535 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
536 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800537 if (!eeprom_buff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 return -ENOMEM;
539
540 ptr = (void *)eeprom_buff;
541
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800542 if (eeprom->offset & 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 /* need read/modify/write of first changed EEPROM word */
544 /* only the second byte of the word is being modified */
545 ret_val = e1000_read_eeprom(hw, first_word, 1,
546 &eeprom_buff[0]);
547 ptr++;
548 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800549 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 /* need read/modify/write of last changed EEPROM word */
551 /* only the first byte of the word is being modified */
552 ret_val = e1000_read_eeprom(hw, last_word, 1,
553 &eeprom_buff[last_word - first_word]);
554 }
555
556 /* Device's eeprom is always little-endian, word addressable */
557 for (i = 0; i < last_word - first_word + 1; i++)
558 le16_to_cpus(&eeprom_buff[i]);
559
560 memcpy(ptr, bytes, eeprom->len);
561
562 for (i = 0; i < last_word - first_word + 1; i++)
563 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
564
565 ret_val = e1000_write_eeprom(hw, first_word,
566 last_word - first_word + 1, eeprom_buff);
567
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800568 /* Update the checksum over the first part of the EEPROM if needed
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -0400569 * and flush shadow RAM for 82573 conrollers */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800570 if ((ret_val == 0) && ((first_word <= EEPROM_CHECKSUM_REG) ||
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -0400571 (hw->mac_type == e1000_82573)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 e1000_update_eeprom_checksum(hw);
573
574 kfree(eeprom_buff);
575 return ret_val;
576}
577
Joe Perches64798842008-07-11 15:17:02 -0700578static void e1000_get_drvinfo(struct net_device *netdev,
579 struct ethtool_drvinfo *drvinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700581 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700582 struct e1000_hw *hw = &adapter->hw;
Jeff Kirshera2917e22006-01-12 16:51:23 -0800583 char firmware_version[32];
Joe Perches406874a2008-04-03 10:06:32 -0700584 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 strncpy(drvinfo->driver, e1000_driver_name, 32);
587 strncpy(drvinfo->version, e1000_driver_version, 32);
Jeff Kirshera2917e22006-01-12 16:51:23 -0800588
589 /* EEPROM image version # is reported as firmware version # for
590 * 8257{1|2|3} controllers */
Joe Perches1dc32912008-07-11 15:17:08 -0700591 e1000_read_eeprom(hw, 5, 1, &eeprom_data);
592 switch (hw->mac_type) {
Jeff Kirshera2917e22006-01-12 16:51:23 -0800593 case e1000_82571:
594 case e1000_82572:
595 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800596 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -0700597 case e1000_ich8lan:
Jeff Kirshera2917e22006-01-12 16:51:23 -0800598 sprintf(firmware_version, "%d.%d-%d",
599 (eeprom_data & 0xF000) >> 12,
600 (eeprom_data & 0x0FF0) >> 4,
601 eeprom_data & 0x000F);
602 break;
603 default:
604 sprintf(firmware_version, "N/A");
605 }
606
607 strncpy(drvinfo->fw_version, firmware_version, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 drvinfo->regdump_len = e1000_get_regs_len(netdev);
610 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
611}
612
Joe Perches64798842008-07-11 15:17:02 -0700613static void e1000_get_ringparam(struct net_device *netdev,
614 struct ethtool_ringparam *ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700616 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700617 struct e1000_hw *hw = &adapter->hw;
618 e1000_mac_type mac_type = hw->mac_type;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400619 struct e1000_tx_ring *txdr = adapter->tx_ring;
620 struct e1000_rx_ring *rxdr = adapter->rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
623 E1000_MAX_82544_RXD;
624 ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD :
625 E1000_MAX_82544_TXD;
626 ring->rx_mini_max_pending = 0;
627 ring->rx_jumbo_max_pending = 0;
628 ring->rx_pending = rxdr->count;
629 ring->tx_pending = txdr->count;
630 ring->rx_mini_pending = 0;
631 ring->rx_jumbo_pending = 0;
632}
633
Joe Perches64798842008-07-11 15:17:02 -0700634static int e1000_set_ringparam(struct net_device *netdev,
635 struct ethtool_ringparam *ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700637 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700638 struct e1000_hw *hw = &adapter->hw;
639 e1000_mac_type mac_type = hw->mac_type;
Vasily Averin793fab722006-09-27 12:54:14 -0700640 struct e1000_tx_ring *txdr, *tx_old;
641 struct e1000_rx_ring *rxdr, *rx_old;
Yan Burman1c7e5b12007-03-06 08:58:04 -0800642 int i, err;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400643
Jeff Kirsher0989aa42006-03-02 18:17:16 -0800644 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
645 return -EINVAL;
646
Auke Kok2db10a02006-06-27 09:06:28 -0700647 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
648 msleep(1);
649
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400650 if (netif_running(adapter->netdev))
651 e1000_down(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
653 tx_old = adapter->tx_ring;
654 rx_old = adapter->rx_ring;
655
Vasily Averin793fab722006-09-27 12:54:14 -0700656 err = -ENOMEM;
Yan Burman1c7e5b12007-03-06 08:58:04 -0800657 txdr = kcalloc(adapter->num_tx_queues, sizeof(struct e1000_tx_ring), GFP_KERNEL);
Vasily Averin793fab722006-09-27 12:54:14 -0700658 if (!txdr)
659 goto err_alloc_tx;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400660
Yan Burman1c7e5b12007-03-06 08:58:04 -0800661 rxdr = kcalloc(adapter->num_rx_queues, sizeof(struct e1000_rx_ring), GFP_KERNEL);
Vasily Averin793fab722006-09-27 12:54:14 -0700662 if (!rxdr)
663 goto err_alloc_rx;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400664
Vasily Averin793fab722006-09-27 12:54:14 -0700665 adapter->tx_ring = txdr;
666 adapter->rx_ring = rxdr;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400667
Joe Perches406874a2008-04-03 10:06:32 -0700668 rxdr->count = max(ring->rx_pending,(u32)E1000_MIN_RXD);
669 rxdr->count = min(rxdr->count,(u32)(mac_type < e1000_82544 ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 E1000_MAX_RXD : E1000_MAX_82544_RXD));
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700671 rxdr->count = ALIGN(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Joe Perches406874a2008-04-03 10:06:32 -0700673 txdr->count = max(ring->tx_pending,(u32)E1000_MIN_TXD);
674 txdr->count = min(txdr->count,(u32)(mac_type < e1000_82544 ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 E1000_MAX_TXD : E1000_MAX_82544_TXD));
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700676 txdr->count = ALIGN(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800678 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400679 txdr[i].count = txdr->count;
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800680 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400681 rxdr[i].count = rxdr->count;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400682
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800683 if (netif_running(adapter->netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 /* Try to get new resources before deleting old */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400685 if ((err = e1000_setup_all_rx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 goto err_setup_rx;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400687 if ((err = e1000_setup_all_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 goto err_setup_tx;
689
690 /* save the new, restore the old in order to free it,
691 * then restore the new back again */
692
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 adapter->rx_ring = rx_old;
694 adapter->tx_ring = tx_old;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400695 e1000_free_all_rx_resources(adapter);
696 e1000_free_all_tx_resources(adapter);
697 kfree(tx_old);
698 kfree(rx_old);
Vasily Averin793fab722006-09-27 12:54:14 -0700699 adapter->rx_ring = rxdr;
700 adapter->tx_ring = txdr;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800701 if ((err = e1000_up(adapter)))
Auke Kok2db10a02006-06-27 09:06:28 -0700702 goto err_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 }
704
Auke Kok2db10a02006-06-27 09:06:28 -0700705 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 return 0;
707err_setup_tx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400708 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709err_setup_rx:
710 adapter->rx_ring = rx_old;
711 adapter->tx_ring = tx_old;
Vasily Averin793fab722006-09-27 12:54:14 -0700712 kfree(rxdr);
713err_alloc_rx:
714 kfree(txdr);
715err_alloc_tx:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 e1000_up(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -0700717err_setup:
718 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 return err;
720}
721
Joe Perches64798842008-07-11 15:17:02 -0700722static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data, int reg,
723 u32 mask, u32 write)
Joe Perches7e643002007-11-13 20:52:05 -0800724{
Joe Perches1dc32912008-07-11 15:17:08 -0700725 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700726 static const u32 test[] =
Joe Perches7e643002007-11-13 20:52:05 -0800727 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Joe Perches1dc32912008-07-11 15:17:08 -0700728 u8 __iomem *address = hw->hw_addr + reg;
Joe Perches406874a2008-04-03 10:06:32 -0700729 u32 read;
Joe Perches7e643002007-11-13 20:52:05 -0800730 int i;
731
732 for (i = 0; i < ARRAY_SIZE(test); i++) {
733 writel(write & test[i], address);
734 read = readl(address);
735 if (read != (write & test[i] & mask)) {
736 DPRINTK(DRV, ERR, "pattern test reg %04X failed: "
737 "got 0x%08X expected 0x%08X\n",
Jeff Garzikcba05162007-11-23 21:50:34 -0500738 reg, read, (write & test[i] & mask));
Joe Perches7e643002007-11-13 20:52:05 -0800739 *data = reg;
740 return true;
741 }
742 }
743 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744}
745
Joe Perches64798842008-07-11 15:17:02 -0700746static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data, int reg,
747 u32 mask, u32 write)
Joe Perches7e643002007-11-13 20:52:05 -0800748{
Joe Perches1dc32912008-07-11 15:17:08 -0700749 struct e1000_hw *hw = &adapter->hw;
750 u8 __iomem *address = hw->hw_addr + reg;
Joe Perches406874a2008-04-03 10:06:32 -0700751 u32 read;
Joe Perches7e643002007-11-13 20:52:05 -0800752
753 writel(write & mask, address);
754 read = readl(address);
755 if ((read & mask) != (write & mask)) {
756 DPRINTK(DRV, ERR, "set/check reg %04X test failed: "
757 "got 0x%08X expected 0x%08X\n",
758 reg, (read & mask), (write & mask));
759 *data = reg;
760 return true;
761 }
762 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763}
764
Joe Perches7e643002007-11-13 20:52:05 -0800765#define REG_PATTERN_TEST(reg, mask, write) \
766 do { \
767 if (reg_pattern_test(adapter, data, \
Joe Perches1dc32912008-07-11 15:17:08 -0700768 (hw->mac_type >= e1000_82543) \
Joe Perches7e643002007-11-13 20:52:05 -0800769 ? E1000_##reg : E1000_82542_##reg, \
770 mask, write)) \
771 return 1; \
772 } while (0)
773
774#define REG_SET_AND_CHECK(reg, mask, write) \
775 do { \
776 if (reg_set_and_check(adapter, data, \
Joe Perches1dc32912008-07-11 15:17:08 -0700777 (hw->mac_type >= e1000_82543) \
Joe Perches7e643002007-11-13 20:52:05 -0800778 ? E1000_##reg : E1000_82542_##reg, \
779 mask, write)) \
780 return 1; \
781 } while (0)
782
Joe Perches64798842008-07-11 15:17:02 -0700783static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784{
Joe Perches406874a2008-04-03 10:06:32 -0700785 u32 value, before, after;
786 u32 i, toggle;
Joe Perches1dc32912008-07-11 15:17:08 -0700787 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
789 /* The status register is Read Only, so a write should fail.
790 * Some bits that get toggled are ignored.
791 */
Joe Perches1dc32912008-07-11 15:17:08 -0700792 switch (hw->mac_type) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400793 /* there are several bits on newer hardware that are r/w */
794 case e1000_82571:
795 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800796 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400797 toggle = 0x7FFFF3FF;
798 break;
Malli Chilakalab01f6692005-06-17 17:42:29 -0700799 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -0700800 case e1000_ich8lan:
Malli Chilakalab01f6692005-06-17 17:42:29 -0700801 toggle = 0x7FFFF033;
802 break;
803 default:
804 toggle = 0xFFFFF833;
805 break;
806 }
807
Joe Perches1dc32912008-07-11 15:17:08 -0700808 before = er32(STATUS);
809 value = (er32(STATUS) & toggle);
810 ew32(STATUS, toggle);
811 after = er32(STATUS) & toggle;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800812 if (value != after) {
Malli Chilakalab01f6692005-06-17 17:42:29 -0700813 DPRINTK(DRV, ERR, "failed STATUS register test got: "
814 "0x%08X expected: 0x%08X\n", after, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 *data = 1;
816 return 1;
817 }
Malli Chilakalab01f6692005-06-17 17:42:29 -0700818 /* restore previous status */
Joe Perches1dc32912008-07-11 15:17:08 -0700819 ew32(STATUS, before);
Auke Kok90fb5132006-11-01 08:47:30 -0800820
Joe Perches1dc32912008-07-11 15:17:08 -0700821 if (hw->mac_type != e1000_ich8lan) {
Auke Kokcd94dd02006-06-27 09:08:22 -0700822 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
823 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
824 REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF);
825 REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF);
826 }
Auke Kok90fb5132006-11-01 08:47:30 -0800827
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF);
829 REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
830 REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF);
831 REG_PATTERN_TEST(RDH, 0x0000FFFF, 0x0000FFFF);
832 REG_PATTERN_TEST(RDT, 0x0000FFFF, 0x0000FFFF);
833 REG_PATTERN_TEST(FCRTH, 0x0000FFF8, 0x0000FFF8);
834 REG_PATTERN_TEST(FCTTV, 0x0000FFFF, 0x0000FFFF);
835 REG_PATTERN_TEST(TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
836 REG_PATTERN_TEST(TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
837 REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF);
838
839 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000);
Auke Kok90fb5132006-11-01 08:47:30 -0800840
Joe Perches1dc32912008-07-11 15:17:08 -0700841 before = (hw->mac_type == e1000_ich8lan ?
Auke Kok90fb5132006-11-01 08:47:30 -0800842 0x06C3B33E : 0x06DFB3FE);
Auke Kokcd94dd02006-06-27 09:08:22 -0700843 REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);
845
Joe Perches1dc32912008-07-11 15:17:08 -0700846 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
Auke Kokcd94dd02006-06-27 09:08:22 -0700848 REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
Joe Perches1dc32912008-07-11 15:17:08 -0700850 if (hw->mac_type != e1000_ich8lan)
Auke Kokcd94dd02006-06-27 09:08:22 -0700851 REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
853 REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
Joe Perches1dc32912008-07-11 15:17:08 -0700854 value = (hw->mac_type == e1000_ich8lan ?
Auke Kok90fb5132006-11-01 08:47:30 -0800855 E1000_RAR_ENTRIES_ICH8LAN : E1000_RAR_ENTRIES);
Auke Kokcd94dd02006-06-27 09:08:22 -0700856 for (i = 0; i < value; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF,
Auke Kok90fb5132006-11-01 08:47:30 -0800858 0xFFFFFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 }
860
861 } else {
862
863 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF);
864 REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF);
865 REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF);
866 REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF);
867
868 }
869
Joe Perches1dc32912008-07-11 15:17:08 -0700870 value = (hw->mac_type == e1000_ich8lan ?
Auke Kokcd94dd02006-06-27 09:08:22 -0700871 E1000_MC_TBL_SIZE_ICH8LAN : E1000_MC_TBL_SIZE);
872 for (i = 0; i < value; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
874
875 *data = 0;
876 return 0;
877}
878
Joe Perches64798842008-07-11 15:17:02 -0700879static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880{
Joe Perches1dc32912008-07-11 15:17:08 -0700881 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700882 u16 temp;
883 u16 checksum = 0;
884 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
886 *data = 0;
887 /* Read and add up the contents of the EEPROM */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800888 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
Joe Perches1dc32912008-07-11 15:17:08 -0700889 if ((e1000_read_eeprom(hw, i, 1, &temp)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 *data = 1;
891 break;
892 }
893 checksum += temp;
894 }
895
896 /* If Checksum is not Correct return error else test passed */
Joe Perches406874a2008-04-03 10:06:32 -0700897 if ((checksum != (u16) EEPROM_SUM) && !(*data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 *data = 2;
899
900 return *data;
901}
902
Joe Perches64798842008-07-11 15:17:02 -0700903static irqreturn_t e1000_test_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904{
905 struct net_device *netdev = (struct net_device *) data;
Malli Chilakala60490fe2005-06-17 17:41:45 -0700906 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700907 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Joe Perches1dc32912008-07-11 15:17:08 -0700909 adapter->test_icr |= er32(ICR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
911 return IRQ_HANDLED;
912}
913
Joe Perches64798842008-07-11 15:17:02 -0700914static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915{
916 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -0700917 u32 mask, i = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -0700918 bool shared_int = true;
Joe Perches406874a2008-04-03 10:06:32 -0700919 u32 irq = adapter->pdev->irq;
Joe Perches1dc32912008-07-11 15:17:08 -0700920 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
922 *data = 0;
923
Auke Kok8fc897b2006-08-28 14:56:16 -0700924 /* NOTE: we don't test MSI interrupts here, yet */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 /* Hook up test interrupt handler just for this test */
Auke Kok90fb5132006-11-01 08:47:30 -0800926 if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
927 netdev))
Joe Perchesc3033b02008-03-21 11:06:25 -0700928 shared_int = false;
Auke Kok8fc897b2006-08-28 14:56:16 -0700929 else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED,
Auke Kok90fb5132006-11-01 08:47:30 -0800930 netdev->name, netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 *data = 1;
932 return -1;
933 }
Auke Kok8fc897b2006-08-28 14:56:16 -0700934 DPRINTK(HW, INFO, "testing %s interrupt\n",
Auke Kokb9b6e782006-06-08 09:28:38 -0700935 (shared_int ? "shared" : "unshared"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
937 /* Disable all the interrupts */
Joe Perches1dc32912008-07-11 15:17:08 -0700938 ew32(IMC, 0xFFFFFFFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400939 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941 /* Test each interrupt */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800942 for (; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
Joe Perches1dc32912008-07-11 15:17:08 -0700944 if (hw->mac_type == e1000_ich8lan && i == 8)
Auke Kokcd94dd02006-06-27 09:08:22 -0700945 continue;
Auke Kok90fb5132006-11-01 08:47:30 -0800946
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 /* Interrupt to test */
948 mask = 1 << i;
949
Auke Kok76c224b2006-05-23 13:36:06 -0700950 if (!shared_int) {
951 /* Disable the interrupt to be reported in
952 * the cause register and then force the same
953 * interrupt and see if one gets posted. If
954 * an interrupt was posted to the bus, the
955 * test failed.
956 */
957 adapter->test_icr = 0;
Joe Perches1dc32912008-07-11 15:17:08 -0700958 ew32(IMC, mask);
959 ew32(ICS, mask);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400960 msleep(10);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800961
Auke Kok76c224b2006-05-23 13:36:06 -0700962 if (adapter->test_icr & mask) {
963 *data = 3;
964 break;
965 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 }
967
968 /* Enable the interrupt to be reported in
969 * the cause register and then force the same
970 * interrupt and see if one gets posted. If
971 * an interrupt was not posted to the bus, the
972 * test failed.
973 */
974 adapter->test_icr = 0;
Joe Perches1dc32912008-07-11 15:17:08 -0700975 ew32(IMS, mask);
976 ew32(ICS, mask);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400977 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800979 if (!(adapter->test_icr & mask)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 *data = 4;
981 break;
982 }
983
Auke Kok76c224b2006-05-23 13:36:06 -0700984 if (!shared_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 /* Disable the other interrupts to be reported in
986 * the cause register and then force the other
987 * interrupts and see if any get posted. If
988 * an interrupt was posted to the bus, the
989 * test failed.
990 */
991 adapter->test_icr = 0;
Joe Perches1dc32912008-07-11 15:17:08 -0700992 ew32(IMC, ~mask & 0x00007FFF);
993 ew32(ICS, ~mask & 0x00007FFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400994 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800996 if (adapter->test_icr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 *data = 5;
998 break;
999 }
1000 }
1001 }
1002
1003 /* Disable all the interrupts */
Joe Perches1dc32912008-07-11 15:17:08 -07001004 ew32(IMC, 0xFFFFFFFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001005 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
1007 /* Unhook test interrupt handler */
1008 free_irq(irq, netdev);
1009
1010 return *data;
1011}
1012
Joe Perches64798842008-07-11 15:17:02 -07001013static void e1000_free_desc_rings(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001015 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1016 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 struct pci_dev *pdev = adapter->pdev;
1018 int i;
1019
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001020 if (txdr->desc && txdr->buffer_info) {
1021 for (i = 0; i < txdr->count; i++) {
1022 if (txdr->buffer_info[i].dma)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 pci_unmap_single(pdev, txdr->buffer_info[i].dma,
1024 txdr->buffer_info[i].length,
1025 PCI_DMA_TODEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001026 if (txdr->buffer_info[i].skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 dev_kfree_skb(txdr->buffer_info[i].skb);
1028 }
1029 }
1030
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001031 if (rxdr->desc && rxdr->buffer_info) {
1032 for (i = 0; i < rxdr->count; i++) {
1033 if (rxdr->buffer_info[i].dma)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 pci_unmap_single(pdev, rxdr->buffer_info[i].dma,
1035 rxdr->buffer_info[i].length,
1036 PCI_DMA_FROMDEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001037 if (rxdr->buffer_info[i].skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 dev_kfree_skb(rxdr->buffer_info[i].skb);
1039 }
1040 }
1041
Jeff Kirsherf5645112006-01-12 16:51:01 -08001042 if (txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 pci_free_consistent(pdev, txdr->size, txdr->desc, txdr->dma);
John W. Linville6b27adb2005-11-08 15:59:30 -05001044 txdr->desc = NULL;
1045 }
Jeff Kirsherf5645112006-01-12 16:51:01 -08001046 if (rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 pci_free_consistent(pdev, rxdr->size, rxdr->desc, rxdr->dma);
John W. Linville6b27adb2005-11-08 15:59:30 -05001048 rxdr->desc = NULL;
1049 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
Jesper Juhlb4558ea2005-10-28 16:53:13 -04001051 kfree(txdr->buffer_info);
John W. Linville6b27adb2005-11-08 15:59:30 -05001052 txdr->buffer_info = NULL;
Jesper Juhlb4558ea2005-10-28 16:53:13 -04001053 kfree(rxdr->buffer_info);
John W. Linville6b27adb2005-11-08 15:59:30 -05001054 rxdr->buffer_info = NULL;
Jeff Kirsherf5645112006-01-12 16:51:01 -08001055
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 return;
1057}
1058
Joe Perches64798842008-07-11 15:17:02 -07001059static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060{
Joe Perches1dc32912008-07-11 15:17:08 -07001061 struct e1000_hw *hw = &adapter->hw;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001062 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1063 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 struct pci_dev *pdev = adapter->pdev;
Joe Perches406874a2008-04-03 10:06:32 -07001065 u32 rctl;
Yan Burman1c7e5b12007-03-06 08:58:04 -08001066 int i, ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
1068 /* Setup Tx descriptor ring and Tx buffers */
1069
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001070 if (!txdr->count)
1071 txdr->count = E1000_DEFAULT_TXD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
Yan Burman1c7e5b12007-03-06 08:58:04 -08001073 if (!(txdr->buffer_info = kcalloc(txdr->count,
1074 sizeof(struct e1000_buffer),
1075 GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 ret_val = 1;
1077 goto err_nomem;
1078 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
1080 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001081 txdr->size = ALIGN(txdr->size, 4096);
Yan Burman1c7e5b12007-03-06 08:58:04 -08001082 if (!(txdr->desc = pci_alloc_consistent(pdev, txdr->size,
1083 &txdr->dma))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 ret_val = 2;
1085 goto err_nomem;
1086 }
1087 memset(txdr->desc, 0, txdr->size);
1088 txdr->next_to_use = txdr->next_to_clean = 0;
1089
Joe Perches1dc32912008-07-11 15:17:08 -07001090 ew32(TDBAL, ((u64) txdr->dma & 0x00000000FFFFFFFF));
1091 ew32(TDBAH, ((u64) txdr->dma >> 32));
1092 ew32(TDLEN, txdr->count * sizeof(struct e1000_tx_desc));
1093 ew32(TDH, 0);
1094 ew32(TDT, 0);
1095 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN |
1096 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1097 E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001099 for (i = 0; i < txdr->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i);
1101 struct sk_buff *skb;
1102 unsigned int size = 1024;
1103
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001104 if (!(skb = alloc_skb(size, GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 ret_val = 3;
1106 goto err_nomem;
1107 }
1108 skb_put(skb, size);
1109 txdr->buffer_info[i].skb = skb;
1110 txdr->buffer_info[i].length = skb->len;
1111 txdr->buffer_info[i].dma =
1112 pci_map_single(pdev, skb->data, skb->len,
1113 PCI_DMA_TODEVICE);
1114 tx_desc->buffer_addr = cpu_to_le64(txdr->buffer_info[i].dma);
1115 tx_desc->lower.data = cpu_to_le32(skb->len);
1116 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1117 E1000_TXD_CMD_IFCS |
1118 E1000_TXD_CMD_RPS);
1119 tx_desc->upper.data = 0;
1120 }
1121
1122 /* Setup Rx descriptor ring and Rx buffers */
1123
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001124 if (!rxdr->count)
1125 rxdr->count = E1000_DEFAULT_RXD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Yan Burman1c7e5b12007-03-06 08:58:04 -08001127 if (!(rxdr->buffer_info = kcalloc(rxdr->count,
1128 sizeof(struct e1000_buffer),
1129 GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 ret_val = 4;
1131 goto err_nomem;
1132 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
1134 rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001135 if (!(rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 ret_val = 5;
1137 goto err_nomem;
1138 }
1139 memset(rxdr->desc, 0, rxdr->size);
1140 rxdr->next_to_use = rxdr->next_to_clean = 0;
1141
Joe Perches1dc32912008-07-11 15:17:08 -07001142 rctl = er32(RCTL);
1143 ew32(RCTL, rctl & ~E1000_RCTL_EN);
1144 ew32(RDBAL, ((u64) rxdr->dma & 0xFFFFFFFF));
1145 ew32(RDBAH, ((u64) rxdr->dma >> 32));
1146 ew32(RDLEN, rxdr->size);
1147 ew32(RDH, 0);
1148 ew32(RDT, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
1150 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
Joe Perches1dc32912008-07-11 15:17:08 -07001151 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
1152 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001154 for (i = 0; i < rxdr->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i);
1156 struct sk_buff *skb;
1157
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001158 if (!(skb = alloc_skb(E1000_RXBUFFER_2048 + NET_IP_ALIGN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 GFP_KERNEL))) {
1160 ret_val = 6;
1161 goto err_nomem;
1162 }
1163 skb_reserve(skb, NET_IP_ALIGN);
1164 rxdr->buffer_info[i].skb = skb;
1165 rxdr->buffer_info[i].length = E1000_RXBUFFER_2048;
1166 rxdr->buffer_info[i].dma =
1167 pci_map_single(pdev, skb->data, E1000_RXBUFFER_2048,
1168 PCI_DMA_FROMDEVICE);
1169 rx_desc->buffer_addr = cpu_to_le64(rxdr->buffer_info[i].dma);
1170 memset(skb->data, 0x00, skb->len);
1171 }
1172
1173 return 0;
1174
1175err_nomem:
1176 e1000_free_desc_rings(adapter);
1177 return ret_val;
1178}
1179
Joe Perches64798842008-07-11 15:17:02 -07001180static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181{
Joe Perches1dc32912008-07-11 15:17:08 -07001182 struct e1000_hw *hw = &adapter->hw;
1183
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
Joe Perches1dc32912008-07-11 15:17:08 -07001185 e1000_write_phy_reg(hw, 29, 0x001F);
1186 e1000_write_phy_reg(hw, 30, 0x8FFC);
1187 e1000_write_phy_reg(hw, 29, 0x001A);
1188 e1000_write_phy_reg(hw, 30, 0x8FF0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189}
1190
Joe Perches64798842008-07-11 15:17:02 -07001191static void e1000_phy_reset_clk_and_crs(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192{
Joe Perches1dc32912008-07-11 15:17:08 -07001193 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001194 u16 phy_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
1196 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1197 * Extended PHY Specific Control Register to 25MHz clock. This
1198 * value defaults back to a 2.5MHz clock when the PHY is reset.
1199 */
Joe Perches1dc32912008-07-11 15:17:08 -07001200 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 phy_reg |= M88E1000_EPSCR_TX_CLK_25;
Joe Perches1dc32912008-07-11 15:17:08 -07001202 e1000_write_phy_reg(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 M88E1000_EXT_PHY_SPEC_CTRL, phy_reg);
1204
1205 /* In addition, because of the s/w reset above, we need to enable
1206 * CRS on TX. This must be set for both full and half duplex
1207 * operation.
1208 */
Joe Perches1dc32912008-07-11 15:17:08 -07001209 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 phy_reg |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Joe Perches1dc32912008-07-11 15:17:08 -07001211 e1000_write_phy_reg(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 M88E1000_PHY_SPEC_CTRL, phy_reg);
1213}
1214
Joe Perches64798842008-07-11 15:17:02 -07001215static int e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216{
Joe Perches1dc32912008-07-11 15:17:08 -07001217 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001218 u32 ctrl_reg;
1219 u16 phy_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
1221 /* Setup the Device Control Register for PHY loopback test. */
1222
Joe Perches1dc32912008-07-11 15:17:08 -07001223 ctrl_reg = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 ctrl_reg |= (E1000_CTRL_ILOS | /* Invert Loss-Of-Signal */
1225 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1226 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1227 E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */
1228 E1000_CTRL_FD); /* Force Duplex to FULL */
1229
Joe Perches1dc32912008-07-11 15:17:08 -07001230 ew32(CTRL, ctrl_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
1232 /* Read the PHY Specific Control Register (0x10) */
Joe Perches1dc32912008-07-11 15:17:08 -07001233 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
1235 /* Clear Auto-Crossover bits in PHY Specific Control Register
1236 * (bits 6:5).
1237 */
1238 phy_reg &= ~M88E1000_PSCR_AUTO_X_MODE;
Joe Perches1dc32912008-07-11 15:17:08 -07001239 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
1241 /* Perform software reset on the PHY */
Joe Perches1dc32912008-07-11 15:17:08 -07001242 e1000_phy_reset(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
1244 /* Have to setup TX_CLK and TX_CRS after software reset */
1245 e1000_phy_reset_clk_and_crs(adapter);
1246
Joe Perches1dc32912008-07-11 15:17:08 -07001247 e1000_write_phy_reg(hw, PHY_CTRL, 0x8100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
1249 /* Wait for reset to complete. */
1250 udelay(500);
1251
1252 /* Have to setup TX_CLK and TX_CRS after software reset */
1253 e1000_phy_reset_clk_and_crs(adapter);
1254
1255 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1256 e1000_phy_disable_receiver(adapter);
1257
1258 /* Set the loopback bit in the PHY control register. */
Joe Perches1dc32912008-07-11 15:17:08 -07001259 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 phy_reg |= MII_CR_LOOPBACK;
Joe Perches1dc32912008-07-11 15:17:08 -07001261 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
1263 /* Setup TX_CLK and TX_CRS one more time. */
1264 e1000_phy_reset_clk_and_crs(adapter);
1265
1266 /* Check Phy Configuration */
Joe Perches1dc32912008-07-11 15:17:08 -07001267 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001268 if (phy_reg != 0x4100)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 return 9;
1270
Joe Perches1dc32912008-07-11 15:17:08 -07001271 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001272 if (phy_reg != 0x0070)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 return 10;
1274
Joe Perches1dc32912008-07-11 15:17:08 -07001275 e1000_read_phy_reg(hw, 29, &phy_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001276 if (phy_reg != 0x001A)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 return 11;
1278
1279 return 0;
1280}
1281
Joe Perches64798842008-07-11 15:17:02 -07001282static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283{
Joe Perches1dc32912008-07-11 15:17:08 -07001284 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001285 u32 ctrl_reg = 0;
1286 u32 stat_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
Joe Perches1dc32912008-07-11 15:17:08 -07001288 hw->autoneg = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
Joe Perches1dc32912008-07-11 15:17:08 -07001290 if (hw->phy_type == e1000_phy_m88) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 /* Auto-MDI/MDIX Off */
Joe Perches1dc32912008-07-11 15:17:08 -07001292 e1000_write_phy_reg(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 M88E1000_PHY_SPEC_CTRL, 0x0808);
1294 /* reset to update Auto-MDI/MDIX */
Joe Perches1dc32912008-07-11 15:17:08 -07001295 e1000_write_phy_reg(hw, PHY_CTRL, 0x9140);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 /* autoneg off */
Joe Perches1dc32912008-07-11 15:17:08 -07001297 e1000_write_phy_reg(hw, PHY_CTRL, 0x8140);
1298 } else if (hw->phy_type == e1000_phy_gg82563)
1299 e1000_write_phy_reg(hw,
Jeff Kirsher87041632006-03-02 18:21:24 -08001300 GG82563_PHY_KMRN_MODE_CTRL,
Auke Kokacfbc9f2006-06-27 09:06:24 -07001301 0x1CC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
Joe Perches1dc32912008-07-11 15:17:08 -07001303 ctrl_reg = er32(CTRL);
Auke Kokcd94dd02006-06-27 09:08:22 -07001304
Joe Perches1dc32912008-07-11 15:17:08 -07001305 if (hw->phy_type == e1000_phy_ife) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001306 /* force 100, set loopback */
Joe Perches1dc32912008-07-11 15:17:08 -07001307 e1000_write_phy_reg(hw, PHY_CTRL, 0x6100);
Auke Kokcd94dd02006-06-27 09:08:22 -07001308
1309 /* Now set up the MAC to the same speed/duplex as the PHY. */
1310 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1311 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1312 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1313 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1314 E1000_CTRL_FD); /* Force Duplex to FULL */
1315 } else {
1316 /* force 1000, set loopback */
Joe Perches1dc32912008-07-11 15:17:08 -07001317 e1000_write_phy_reg(hw, PHY_CTRL, 0x4140);
Auke Kokcd94dd02006-06-27 09:08:22 -07001318
1319 /* Now set up the MAC to the same speed/duplex as the PHY. */
Joe Perches1dc32912008-07-11 15:17:08 -07001320 ctrl_reg = er32(CTRL);
Auke Kokcd94dd02006-06-27 09:08:22 -07001321 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1322 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1323 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1324 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1325 E1000_CTRL_FD); /* Force Duplex to FULL */
1326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Joe Perches1dc32912008-07-11 15:17:08 -07001328 if (hw->media_type == e1000_media_type_copper &&
1329 hw->phy_type == e1000_phy_m88)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
Auke Kok8fc897b2006-08-28 14:56:16 -07001331 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 /* Set the ILOS bit on the fiber Nic is half
1333 * duplex link is detected. */
Joe Perches1dc32912008-07-11 15:17:08 -07001334 stat_reg = er32(STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001335 if ((stat_reg & E1000_STATUS_FD) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1337 }
1338
Joe Perches1dc32912008-07-11 15:17:08 -07001339 ew32(CTRL, ctrl_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
1341 /* Disable the receiver on the PHY so when a cable is plugged in, the
1342 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1343 */
Joe Perches1dc32912008-07-11 15:17:08 -07001344 if (hw->phy_type == e1000_phy_m88)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 e1000_phy_disable_receiver(adapter);
1346
1347 udelay(500);
1348
1349 return 0;
1350}
1351
Joe Perches64798842008-07-11 15:17:02 -07001352static int e1000_set_phy_loopback(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353{
Joe Perches1dc32912008-07-11 15:17:08 -07001354 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001355 u16 phy_reg = 0;
1356 u16 count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Joe Perches1dc32912008-07-11 15:17:08 -07001358 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 case e1000_82543:
Joe Perches1dc32912008-07-11 15:17:08 -07001360 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 /* Attempt to setup Loopback mode on Non-integrated PHY.
1362 * Some PHY registers get corrupted at random, so
1363 * attempt this 10 times.
1364 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001365 while (e1000_nonintegrated_phy_loopback(adapter) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 count++ < 10);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001367 if (count < 11)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 return 0;
1369 }
1370 break;
1371
1372 case e1000_82544:
1373 case e1000_82540:
1374 case e1000_82545:
1375 case e1000_82545_rev_3:
1376 case e1000_82546:
1377 case e1000_82546_rev_3:
1378 case e1000_82541:
1379 case e1000_82541_rev_2:
1380 case e1000_82547:
1381 case e1000_82547_rev_2:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001382 case e1000_82571:
1383 case e1000_82572:
Malli Chilakala45643272005-06-17 17:42:42 -07001384 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001385 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07001386 case e1000_ich8lan:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 return e1000_integrated_phy_loopback(adapter);
1388 break;
1389
1390 default:
1391 /* Default PHY loopback work is to read the MII
1392 * control register and assert bit 14 (loopback mode).
1393 */
Joe Perches1dc32912008-07-11 15:17:08 -07001394 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 phy_reg |= MII_CR_LOOPBACK;
Joe Perches1dc32912008-07-11 15:17:08 -07001396 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 return 0;
1398 break;
1399 }
1400
1401 return 8;
1402}
1403
Joe Perches64798842008-07-11 15:17:02 -07001404static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405{
Jeff Kirsher49273162006-01-12 16:50:44 -08001406 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001407 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Jeff Kirsher49273162006-01-12 16:50:44 -08001409 if (hw->media_type == e1000_media_type_fiber ||
1410 hw->media_type == e1000_media_type_internal_serdes) {
1411 switch (hw->mac_type) {
1412 case e1000_82545:
1413 case e1000_82546:
1414 case e1000_82545_rev_3:
1415 case e1000_82546_rev_3:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 return e1000_set_phy_loopback(adapter);
Jeff Kirsher49273162006-01-12 16:50:44 -08001417 break;
1418 case e1000_82571:
1419 case e1000_82572:
1420#define E1000_SERDES_LB_ON 0x410
1421 e1000_set_phy_loopback(adapter);
Joe Perches1dc32912008-07-11 15:17:08 -07001422 ew32(SCTL, E1000_SERDES_LB_ON);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001423 msleep(10);
Jeff Kirsher49273162006-01-12 16:50:44 -08001424 return 0;
1425 break;
1426 default:
Joe Perches1dc32912008-07-11 15:17:08 -07001427 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 rctl |= E1000_RCTL_LBM_TCVR;
Joe Perches1dc32912008-07-11 15:17:08 -07001429 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 return 0;
1431 }
Jeff Kirsher49273162006-01-12 16:50:44 -08001432 } else if (hw->media_type == e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 return e1000_set_phy_loopback(adapter);
1434
1435 return 7;
1436}
1437
Joe Perches64798842008-07-11 15:17:02 -07001438static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
Jeff Kirsher49273162006-01-12 16:50:44 -08001440 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001441 u32 rctl;
1442 u16 phy_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
Joe Perches1dc32912008-07-11 15:17:08 -07001444 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
Joe Perches1dc32912008-07-11 15:17:08 -07001446 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
Jeff Kirsher49273162006-01-12 16:50:44 -08001448 switch (hw->mac_type) {
1449 case e1000_82571:
1450 case e1000_82572:
1451 if (hw->media_type == e1000_media_type_fiber ||
1452 hw->media_type == e1000_media_type_internal_serdes) {
1453#define E1000_SERDES_LB_OFF 0x400
Joe Perches1dc32912008-07-11 15:17:08 -07001454 ew32(SCTL, E1000_SERDES_LB_OFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001455 msleep(10);
Jeff Kirsher49273162006-01-12 16:50:44 -08001456 break;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001457 }
Jeff Kirsher49273162006-01-12 16:50:44 -08001458 /* Fall Through */
1459 case e1000_82545:
1460 case e1000_82546:
1461 case e1000_82545_rev_3:
1462 case e1000_82546_rev_3:
1463 default:
Joe Perchesc3033b02008-03-21 11:06:25 -07001464 hw->autoneg = true;
Auke Kok8fc897b2006-08-28 14:56:16 -07001465 if (hw->phy_type == e1000_phy_gg82563)
Jeff Kirsher87041632006-03-02 18:21:24 -08001466 e1000_write_phy_reg(hw,
1467 GG82563_PHY_KMRN_MODE_CTRL,
1468 0x180);
Jeff Kirsher49273162006-01-12 16:50:44 -08001469 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
1470 if (phy_reg & MII_CR_LOOPBACK) {
1471 phy_reg &= ~MII_CR_LOOPBACK;
1472 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
1473 e1000_phy_reset(hw);
1474 }
1475 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 }
1477}
1478
Joe Perches64798842008-07-11 15:17:02 -07001479static void e1000_create_lbtest_frame(struct sk_buff *skb,
1480 unsigned int frame_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481{
1482 memset(skb->data, 0xFF, frame_size);
Jeff Kirsherce7393b2006-01-12 16:51:12 -08001483 frame_size &= ~1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1485 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1486 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1487}
1488
Joe Perches64798842008-07-11 15:17:02 -07001489static int e1000_check_lbtest_frame(struct sk_buff *skb,
1490 unsigned int frame_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491{
Jeff Kirsherce7393b2006-01-12 16:51:12 -08001492 frame_size &= ~1;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001493 if (*(skb->data + 3) == 0xFF) {
1494 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
1496 return 0;
1497 }
1498 }
1499 return 13;
1500}
1501
Joe Perches64798842008-07-11 15:17:02 -07001502static int e1000_run_loopback_test(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503{
Joe Perches1dc32912008-07-11 15:17:08 -07001504 struct e1000_hw *hw = &adapter->hw;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001505 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1506 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 struct pci_dev *pdev = adapter->pdev;
Malli Chilakalae4eff722005-04-28 19:38:30 -07001508 int i, j, k, l, lc, good_cnt, ret_val=0;
1509 unsigned long time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Joe Perches1dc32912008-07-11 15:17:08 -07001511 ew32(RDT, rxdr->count - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001513 /* Calculate the loop count based on the largest descriptor ring
Malli Chilakalae4eff722005-04-28 19:38:30 -07001514 * The idea is to wrap the largest ring a number of times using 64
1515 * send/receive pairs during each loop
1516 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001518 if (rxdr->count <= txdr->count)
Malli Chilakalae4eff722005-04-28 19:38:30 -07001519 lc = ((txdr->count / 64) * 2) + 1;
1520 else
1521 lc = ((rxdr->count / 64) * 2) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
Malli Chilakalae4eff722005-04-28 19:38:30 -07001523 k = l = 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001524 for (j = 0; j <= lc; j++) { /* loop count loop */
1525 for (i = 0; i < 64; i++) { /* send the packets */
1526 e1000_create_lbtest_frame(txdr->buffer_info[i].skb,
Malli Chilakalae4eff722005-04-28 19:38:30 -07001527 1024);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001528 pci_dma_sync_single_for_device(pdev,
Malli Chilakalae4eff722005-04-28 19:38:30 -07001529 txdr->buffer_info[k].dma,
1530 txdr->buffer_info[k].length,
1531 PCI_DMA_TODEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001532 if (unlikely(++k == txdr->count)) k = 0;
Malli Chilakalae4eff722005-04-28 19:38:30 -07001533 }
Joe Perches1dc32912008-07-11 15:17:08 -07001534 ew32(TDT, k);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001535 msleep(200);
Malli Chilakalae4eff722005-04-28 19:38:30 -07001536 time = jiffies; /* set the start time for the receive */
1537 good_cnt = 0;
1538 do { /* receive the sent packets */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001539 pci_dma_sync_single_for_cpu(pdev,
Malli Chilakalae4eff722005-04-28 19:38:30 -07001540 rxdr->buffer_info[l].dma,
1541 rxdr->buffer_info[l].length,
1542 PCI_DMA_FROMDEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001543
Malli Chilakalae4eff722005-04-28 19:38:30 -07001544 ret_val = e1000_check_lbtest_frame(
1545 rxdr->buffer_info[l].skb,
1546 1024);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001547 if (!ret_val)
Malli Chilakalae4eff722005-04-28 19:38:30 -07001548 good_cnt++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001549 if (unlikely(++l == rxdr->count)) l = 0;
1550 /* time + 20 msecs (200 msecs on 2.4) is more than
1551 * enough time to complete the receives, if it's
Malli Chilakalae4eff722005-04-28 19:38:30 -07001552 * exceeded, break and error off
1553 */
1554 } while (good_cnt < 64 && jiffies < (time + 20));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001555 if (good_cnt != 64) {
Malli Chilakalae4eff722005-04-28 19:38:30 -07001556 ret_val = 13; /* ret_val is the same as mis-compare */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001557 break;
Malli Chilakalae4eff722005-04-28 19:38:30 -07001558 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001559 if (jiffies >= (time + 2)) {
Malli Chilakalae4eff722005-04-28 19:38:30 -07001560 ret_val = 14; /* error code for time out error */
1561 break;
1562 }
1563 } /* end loop count loop */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 return ret_val;
1565}
1566
Joe Perches64798842008-07-11 15:17:02 -07001567static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568{
Joe Perches1dc32912008-07-11 15:17:08 -07001569 struct e1000_hw *hw = &adapter->hw;
1570
Jeff Kirsher57128192006-01-12 16:50:28 -08001571 /* PHY loopback cannot be performed if SoL/IDER
1572 * sessions are active */
Joe Perches1dc32912008-07-11 15:17:08 -07001573 if (e1000_check_phy_reset_block(hw)) {
Jeff Kirsher57128192006-01-12 16:50:28 -08001574 DPRINTK(DRV, ERR, "Cannot do PHY loopback test "
1575 "when SoL/IDER is active.\n");
1576 *data = 0;
1577 goto out;
1578 }
1579
1580 if ((*data = e1000_setup_desc_rings(adapter)))
1581 goto out;
1582 if ((*data = e1000_setup_loopback_test(adapter)))
1583 goto err_loopback;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 *data = e1000_run_loopback_test(adapter);
1585 e1000_loopback_cleanup(adapter);
Jeff Kirsher57128192006-01-12 16:50:28 -08001586
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587err_loopback:
Jeff Kirsher57128192006-01-12 16:50:28 -08001588 e1000_free_desc_rings(adapter);
1589out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 return *data;
1591}
1592
Joe Perches64798842008-07-11 15:17:02 -07001593static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594{
Joe Perches1dc32912008-07-11 15:17:08 -07001595 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 *data = 0;
Joe Perches1dc32912008-07-11 15:17:08 -07001597 if (hw->media_type == e1000_media_type_internal_serdes) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 int i = 0;
Joe Perches1dc32912008-07-11 15:17:08 -07001599 hw->serdes_link_down = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600
Malli Chilakala26483452005-04-28 19:44:46 -07001601 /* On some blade server designs, link establishment
1602 * could take as long as 2-3 minutes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 do {
Joe Perches1dc32912008-07-11 15:17:08 -07001604 e1000_check_for_link(hw);
1605 if (!hw->serdes_link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 return *data;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001607 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 } while (i++ < 3750);
1609
Malli Chilakala26483452005-04-28 19:44:46 -07001610 *data = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 } else {
Joe Perches1dc32912008-07-11 15:17:08 -07001612 e1000_check_for_link(hw);
1613 if (hw->autoneg) /* if auto_neg is set wait for it */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001614 msleep(4000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615
Joe Perches1dc32912008-07-11 15:17:08 -07001616 if (!(er32(STATUS) & E1000_STATUS_LU)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 *data = 1;
1618 }
1619 }
1620 return *data;
1621}
1622
Joe Perches64798842008-07-11 15:17:02 -07001623static int e1000_get_sset_count(struct net_device *netdev, int sset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001625 switch (sset) {
1626 case ETH_SS_TEST:
1627 return E1000_TEST_LEN;
1628 case ETH_SS_STATS:
1629 return E1000_STATS_LEN;
1630 default:
1631 return -EOPNOTSUPP;
1632 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633}
1634
Joe Perches64798842008-07-11 15:17:02 -07001635static void e1000_diag_test(struct net_device *netdev,
1636 struct ethtool_test *eth_test, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001638 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001639 struct e1000_hw *hw = &adapter->hw;
Joe Perchesc3033b02008-03-21 11:06:25 -07001640 bool if_running = netif_running(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
Auke Kok1314bbf2006-09-27 12:54:02 -07001642 set_bit(__E1000_TESTING, &adapter->flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001643 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 /* Offline tests */
1645
1646 /* save speed, duplex, autoneg settings */
Joe Perches1dc32912008-07-11 15:17:08 -07001647 u16 autoneg_advertised = hw->autoneg_advertised;
1648 u8 forced_speed_duplex = hw->forced_speed_duplex;
1649 u8 autoneg = hw->autoneg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
Jesse Brandeburgd6582662006-08-16 13:31:33 -07001651 DPRINTK(HW, INFO, "offline testing starting\n");
1652
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 /* Link test performed before hardware reset so autoneg doesn't
1654 * interfere with test result */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001655 if (e1000_link_test(adapter, &data[4]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 eth_test->flags |= ETH_TEST_FL_FAILED;
1657
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001658 if (if_running)
Auke Kok2db10a02006-06-27 09:06:28 -07001659 /* indicate we're in test mode */
1660 dev_close(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 else
1662 e1000_reset(adapter);
1663
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001664 if (e1000_reg_test(adapter, &data[0]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 eth_test->flags |= ETH_TEST_FL_FAILED;
1666
1667 e1000_reset(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001668 if (e1000_eeprom_test(adapter, &data[1]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 eth_test->flags |= ETH_TEST_FL_FAILED;
1670
1671 e1000_reset(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001672 if (e1000_intr_test(adapter, &data[2]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 eth_test->flags |= ETH_TEST_FL_FAILED;
1674
1675 e1000_reset(adapter);
Jesse Brandeburgd6582662006-08-16 13:31:33 -07001676 /* make sure the phy is powered up */
1677 e1000_power_up_phy(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001678 if (e1000_loopback_test(adapter, &data[3]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 eth_test->flags |= ETH_TEST_FL_FAILED;
1680
1681 /* restore speed, duplex, autoneg settings */
Joe Perches1dc32912008-07-11 15:17:08 -07001682 hw->autoneg_advertised = autoneg_advertised;
1683 hw->forced_speed_duplex = forced_speed_duplex;
1684 hw->autoneg = autoneg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
1686 e1000_reset(adapter);
Auke Kok1314bbf2006-09-27 12:54:02 -07001687 clear_bit(__E1000_TESTING, &adapter->flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001688 if (if_running)
Auke Kok2db10a02006-06-27 09:06:28 -07001689 dev_open(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 } else {
Jesse Brandeburgd6582662006-08-16 13:31:33 -07001691 DPRINTK(HW, INFO, "online testing starting\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 /* Online tests */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001693 if (e1000_link_test(adapter, &data[4]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 eth_test->flags |= ETH_TEST_FL_FAILED;
1695
Auke Kok90fb5132006-11-01 08:47:30 -08001696 /* Online tests aren't run; pass by default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 data[0] = 0;
1698 data[1] = 0;
1699 data[2] = 0;
1700 data[3] = 0;
Auke Kok2db10a02006-06-27 09:06:28 -07001701
Auke Kok1314bbf2006-09-27 12:54:02 -07001702 clear_bit(__E1000_TESTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 }
Mallikarjuna R Chilakala352c9f82005-10-04 07:07:24 -04001704 msleep_interruptible(4 * 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705}
1706
Joe Perches64798842008-07-11 15:17:02 -07001707static int e1000_wol_exclusion(struct e1000_adapter *adapter,
1708 struct ethtool_wolinfo *wol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001711 int retval = 1; /* fail by default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001713 switch (hw->device_id) {
Auke Kokdc1f71f2006-10-24 14:45:55 -07001714 case E1000_DEV_ID_82542:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 case E1000_DEV_ID_82543GC_FIBER:
1716 case E1000_DEV_ID_82543GC_COPPER:
1717 case E1000_DEV_ID_82544EI_FIBER:
1718 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1719 case E1000_DEV_ID_82545EM_FIBER:
1720 case E1000_DEV_ID_82545EM_COPPER:
Jeff Kirsher84916822006-03-02 18:18:48 -08001721 case E1000_DEV_ID_82546GB_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001722 case E1000_DEV_ID_82546GB_PCIE:
Auke Kokce57a022007-08-09 14:09:34 -07001723 case E1000_DEV_ID_82571EB_SERDES_QUAD:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001724 /* these don't support WoL at all */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 wol->supported = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001726 break;
1727 case E1000_DEV_ID_82546EB_FIBER:
1728 case E1000_DEV_ID_82546GB_FIBER:
1729 case E1000_DEV_ID_82571EB_FIBER:
1730 case E1000_DEV_ID_82571EB_SERDES:
1731 case E1000_DEV_ID_82571EB_COPPER:
1732 /* Wake events not supported on port B */
Joe Perches1dc32912008-07-11 15:17:08 -07001733 if (er32(STATUS) & E1000_STATUS_FUNC_1) {
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001734 wol->supported = 0;
1735 break;
1736 }
1737 /* return success for non excluded adapter ports */
1738 retval = 0;
1739 break;
Jesse Brandeburg5881cde2006-08-31 14:27:47 -07001740 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokce57a022007-08-09 14:09:34 -07001741 case E1000_DEV_ID_82571EB_QUAD_FIBER:
Auke Kokfc2307d2006-11-01 08:47:56 -08001742 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
Auke Kokf4ec7f92007-08-30 11:23:58 -07001743 case E1000_DEV_ID_82571PT_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001744 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1745 /* quad port adapters only support WoL on port A */
1746 if (!adapter->quad_port_a) {
1747 wol->supported = 0;
1748 break;
1749 }
1750 /* return success for non excluded adapter ports */
1751 retval = 0;
1752 break;
1753 default:
1754 /* dual port cards only support WoL on port A from now on
1755 * unless it was enabled in the eeprom for port B
1756 * so exclude FUNC_1 ports from having WoL enabled */
Joe Perches1dc32912008-07-11 15:17:08 -07001757 if (er32(STATUS) & E1000_STATUS_FUNC_1 &&
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001758 !adapter->eeprom_wol) {
1759 wol->supported = 0;
1760 break;
1761 }
1762
1763 retval = 0;
1764 }
1765
1766 return retval;
1767}
1768
Joe Perches64798842008-07-11 15:17:02 -07001769static void e1000_get_wol(struct net_device *netdev,
1770 struct ethtool_wolinfo *wol)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001771{
1772 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001773 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001774
1775 wol->supported = WAKE_UCAST | WAKE_MCAST |
1776 WAKE_BCAST | WAKE_MAGIC;
1777 wol->wolopts = 0;
1778
1779 /* this function will set ->supported = 0 and return 1 if wol is not
1780 * supported by this hardware */
1781 if (e1000_wol_exclusion(adapter, wol))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 return;
1783
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001784 /* apply any specific unsupported masks here */
Joe Perches1dc32912008-07-11 15:17:08 -07001785 switch (hw->device_id) {
Jeff Kirsher84916822006-03-02 18:18:48 -08001786 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001787 /* KSP3 does not suppport UCAST wake-ups */
1788 wol->supported &= ~WAKE_UCAST;
Jeff Kirsher84916822006-03-02 18:18:48 -08001789
1790 if (adapter->wol & E1000_WUFC_EX)
1791 DPRINTK(DRV, ERR, "Interface does not support "
1792 "directed (unicast) frame wake-up packets\n");
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001793 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 default:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001795 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 }
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001797
1798 if (adapter->wol & E1000_WUFC_EX)
1799 wol->wolopts |= WAKE_UCAST;
1800 if (adapter->wol & E1000_WUFC_MC)
1801 wol->wolopts |= WAKE_MCAST;
1802 if (adapter->wol & E1000_WUFC_BC)
1803 wol->wolopts |= WAKE_BCAST;
1804 if (adapter->wol & E1000_WUFC_MAG)
1805 wol->wolopts |= WAKE_MAGIC;
1806
1807 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808}
1809
Joe Perches64798842008-07-11 15:17:02 -07001810static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001812 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 struct e1000_hw *hw = &adapter->hw;
1814
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001815 if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
1816 return -EOPNOTSUPP;
1817
1818 if (e1000_wol_exclusion(adapter, wol))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 return wol->wolopts ? -EOPNOTSUPP : 0;
1820
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001821 switch (hw->device_id) {
Jeff Kirsher84916822006-03-02 18:18:48 -08001822 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jeff Kirsher84916822006-03-02 18:18:48 -08001823 if (wol->wolopts & WAKE_UCAST) {
1824 DPRINTK(DRV, ERR, "Interface does not support "
1825 "directed (unicast) frame wake-up packets\n");
1826 return -EOPNOTSUPP;
1827 }
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001828 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 default:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001830 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 }
1832
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001833 /* these settings will always override what we currently have */
1834 adapter->wol = 0;
1835
1836 if (wol->wolopts & WAKE_UCAST)
1837 adapter->wol |= E1000_WUFC_EX;
1838 if (wol->wolopts & WAKE_MCAST)
1839 adapter->wol |= E1000_WUFC_MC;
1840 if (wol->wolopts & WAKE_BCAST)
1841 adapter->wol |= E1000_WUFC_BC;
1842 if (wol->wolopts & WAKE_MAGIC)
1843 adapter->wol |= E1000_WUFC_MAG;
1844
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 return 0;
1846}
1847
1848/* toggle LED 4 times per second = 2 "blinks" per second */
1849#define E1000_ID_INTERVAL (HZ/4)
1850
1851/* bit defines for adapter->led_status */
1852#define E1000_LED_ON 0
1853
Joe Perches64798842008-07-11 15:17:02 -07001854static void e1000_led_blink_callback(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855{
1856 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Joe Perches1dc32912008-07-11 15:17:08 -07001857 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001859 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
Joe Perches1dc32912008-07-11 15:17:08 -07001860 e1000_led_off(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 else
Joe Perches1dc32912008-07-11 15:17:08 -07001862 e1000_led_on(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863
1864 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1865}
1866
Joe Perches64798842008-07-11 15:17:02 -07001867static int e1000_phys_id(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001869 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001870 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871
Stephen Hemmingerabec42a2007-10-29 10:46:19 -07001872 if (!data)
1873 data = INT_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
Joe Perches1dc32912008-07-11 15:17:08 -07001875 if (hw->mac_type < e1000_82571) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001876 if (!adapter->blink_timer.function) {
Malli Chilakalad439d4b2005-06-17 17:43:56 -07001877 init_timer(&adapter->blink_timer);
1878 adapter->blink_timer.function = e1000_led_blink_callback;
1879 adapter->blink_timer.data = (unsigned long) adapter;
1880 }
Joe Perches1dc32912008-07-11 15:17:08 -07001881 e1000_setup_led(hw);
Malli Chilakalad439d4b2005-06-17 17:43:56 -07001882 mod_timer(&adapter->blink_timer, jiffies);
1883 msleep_interruptible(data * 1000);
1884 del_timer_sync(&adapter->blink_timer);
Joe Perches1dc32912008-07-11 15:17:08 -07001885 } else if (hw->phy_type == e1000_phy_ife) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001886 if (!adapter->blink_timer.function) {
1887 init_timer(&adapter->blink_timer);
1888 adapter->blink_timer.function = e1000_led_blink_callback;
1889 adapter->blink_timer.data = (unsigned long) adapter;
1890 }
1891 mod_timer(&adapter->blink_timer, jiffies);
Jeff Kirsherd8c2bd32006-01-12 16:50:37 -08001892 msleep_interruptible(data * 1000);
Auke Kokcd94dd02006-06-27 09:08:22 -07001893 del_timer_sync(&adapter->blink_timer);
1894 e1000_write_phy_reg(&(adapter->hw), IFE_PHY_SPECIAL_CONTROL_LED, 0);
Jeff Kirsherd8c2bd32006-01-12 16:50:37 -08001895 } else {
Joe Perches1dc32912008-07-11 15:17:08 -07001896 e1000_blink_led_start(hw);
Malli Chilakalad439d4b2005-06-17 17:43:56 -07001897 msleep_interruptible(data * 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 }
1899
Joe Perches1dc32912008-07-11 15:17:08 -07001900 e1000_led_off(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 clear_bit(E1000_LED_ON, &adapter->led_status);
Joe Perches1dc32912008-07-11 15:17:08 -07001902 e1000_cleanup_led(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903
1904 return 0;
1905}
1906
Joe Perches64798842008-07-11 15:17:02 -07001907static int e1000_nway_reset(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001909 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kok2db10a02006-06-27 09:06:28 -07001910 if (netif_running(netdev))
1911 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 return 0;
1913}
1914
Joe Perches64798842008-07-11 15:17:02 -07001915static void e1000_get_ethtool_stats(struct net_device *netdev,
1916 struct ethtool_stats *stats, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001918 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 int i;
1920
1921 e1000_update_stats(adapter);
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001922 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1923 char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
1924 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
Joe Perches406874a2008-04-03 10:06:32 -07001925 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001927/* BUG_ON(i != E1000_STATS_LEN); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928}
1929
Joe Perches64798842008-07-11 15:17:02 -07001930static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1931 u8 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932{
Joe Perches406874a2008-04-03 10:06:32 -07001933 u8 *p = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 int i;
1935
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001936 switch (stringset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 case ETH_SS_TEST:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001938 memcpy(data, *e1000_gstrings_test,
Roel Kluinc32bc6e2007-12-05 11:57:30 -08001939 sizeof(e1000_gstrings_test));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 break;
1941 case ETH_SS_STATS:
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001942 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1943 memcpy(p, e1000_gstrings_stats[i].stat_string,
1944 ETH_GSTRING_LEN);
1945 p += ETH_GSTRING_LEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001947/* BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 break;
1949 }
1950}
1951
Jeff Garzik7282d492006-09-13 14:30:00 -04001952static const struct ethtool_ops e1000_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 .get_settings = e1000_get_settings,
1954 .set_settings = e1000_set_settings,
1955 .get_drvinfo = e1000_get_drvinfo,
1956 .get_regs_len = e1000_get_regs_len,
1957 .get_regs = e1000_get_regs,
1958 .get_wol = e1000_get_wol,
1959 .set_wol = e1000_set_wol,
Auke Kok8fc897b2006-08-28 14:56:16 -07001960 .get_msglevel = e1000_get_msglevel,
1961 .set_msglevel = e1000_set_msglevel,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 .nway_reset = e1000_nway_reset,
1963 .get_link = ethtool_op_get_link,
1964 .get_eeprom_len = e1000_get_eeprom_len,
1965 .get_eeprom = e1000_get_eeprom,
1966 .set_eeprom = e1000_set_eeprom,
1967 .get_ringparam = e1000_get_ringparam,
1968 .set_ringparam = e1000_set_ringparam,
Auke Kok8fc897b2006-08-28 14:56:16 -07001969 .get_pauseparam = e1000_get_pauseparam,
1970 .set_pauseparam = e1000_set_pauseparam,
1971 .get_rx_csum = e1000_get_rx_csum,
1972 .set_rx_csum = e1000_set_rx_csum,
1973 .get_tx_csum = e1000_get_tx_csum,
1974 .set_tx_csum = e1000_set_tx_csum,
Auke Kok8fc897b2006-08-28 14:56:16 -07001975 .set_sg = ethtool_op_set_sg,
Auke Kok8fc897b2006-08-28 14:56:16 -07001976 .set_tso = e1000_set_tso,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 .self_test = e1000_diag_test,
1978 .get_strings = e1000_get_strings,
1979 .phys_id = e1000_phys_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001981 .get_sset_count = e1000_get_sset_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982};
1983
1984void e1000_set_ethtool_ops(struct net_device *netdev)
1985{
1986 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
1987}