blob: f9ac9a87ffabdad68735f3a1084cd3fb12130c97 [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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/uaccess.h>
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034struct e1000_stats {
35 char stat_string[ETH_GSTRING_LEN];
36 int sizeof_stat;
37 int stat_offset;
38};
39
Julia Lawall030ed682008-02-11 09:25:40 -080040#define E1000_STAT(m) FIELD_SIZEOF(struct e1000_adapter, m), \
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 offsetof(struct e1000_adapter, m)
42static const struct e1000_stats e1000_gstrings_stats[] = {
Mitch Williams49559852006-09-27 12:53:37 -070043 { "rx_packets", E1000_STAT(stats.gprc) },
44 { "tx_packets", E1000_STAT(stats.gptc) },
45 { "rx_bytes", E1000_STAT(stats.gorcl) },
46 { "tx_bytes", E1000_STAT(stats.gotcl) },
47 { "rx_broadcast", E1000_STAT(stats.bprc) },
48 { "tx_broadcast", E1000_STAT(stats.bptc) },
49 { "rx_multicast", E1000_STAT(stats.mprc) },
50 { "tx_multicast", E1000_STAT(stats.mptc) },
51 { "rx_errors", E1000_STAT(stats.rxerrc) },
52 { "tx_errors", E1000_STAT(stats.txerrc) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 { "tx_dropped", E1000_STAT(net_stats.tx_dropped) },
Mitch Williams49559852006-09-27 12:53:37 -070054 { "multicast", E1000_STAT(stats.mprc) },
55 { "collisions", E1000_STAT(stats.colc) },
56 { "rx_length_errors", E1000_STAT(stats.rlerrc) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 { "rx_over_errors", E1000_STAT(net_stats.rx_over_errors) },
Mitch Williams49559852006-09-27 12:53:37 -070058 { "rx_crc_errors", E1000_STAT(stats.crcerrs) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 { "rx_frame_errors", E1000_STAT(net_stats.rx_frame_errors) },
Malli Chilakala26483452005-04-28 19:44:46 -070060 { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
Mitch Williams49559852006-09-27 12:53:37 -070061 { "rx_missed_errors", E1000_STAT(stats.mpc) },
62 { "tx_aborted_errors", E1000_STAT(stats.ecol) },
63 { "tx_carrier_errors", E1000_STAT(stats.tncrs) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 { "tx_fifo_errors", E1000_STAT(net_stats.tx_fifo_errors) },
65 { "tx_heartbeat_errors", E1000_STAT(net_stats.tx_heartbeat_errors) },
Mitch Williams49559852006-09-27 12:53:37 -070066 { "tx_window_errors", E1000_STAT(stats.latecol) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
68 { "tx_deferred_ok", E1000_STAT(stats.dc) },
69 { "tx_single_coll_ok", E1000_STAT(stats.scc) },
70 { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
Jeff Kirsher6b7660c2006-01-12 16:50:35 -080071 { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -080072 { "tx_restart_queue", E1000_STAT(restart_queue) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 { "rx_long_length_errors", E1000_STAT(stats.roc) },
74 { "rx_short_length_errors", E1000_STAT(stats.ruc) },
75 { "rx_align_errors", E1000_STAT(stats.algnerrc) },
76 { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
77 { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
78 { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
79 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
80 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
81 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
82 { "rx_long_byte_count", E1000_STAT(stats.gorcl) },
83 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -040084 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
85 { "rx_header_split", E1000_STAT(rx_hdr_split) },
Jeff Kirsher6b7660c2006-01-12 16:50:35 -080086 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
Jeff Garzik15e376b2006-12-15 11:16:33 -050087 { "tx_smbus", E1000_STAT(stats.mgptc) },
88 { "rx_smbus", E1000_STAT(stats.mgprc) },
89 { "dropped_smbus", E1000_STAT(stats.mgpdc) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070090};
Jeff Kirsher7bfa4812006-01-12 16:50:41 -080091
Jeff Kirsher7bfa4812006-01-12 16:50:41 -080092#define E1000_QUEUE_STATS_LEN 0
Denis Chengff8ac602007-09-02 18:30:18 +080093#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Jeff Kirsher7bfa4812006-01-12 16:50:41 -080094#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN + E1000_QUEUE_STATS_LEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
96 "Register test (offline)", "Eeprom test (offline)",
97 "Interrupt test (offline)", "Loopback test (offline)",
98 "Link test (on/offline)"
99};
Alejandro Martinez Ruiz4c3616c2007-10-18 10:00:15 +0200100#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Joe Perches64798842008-07-11 15:17:02 -0700102static int e1000_get_settings(struct net_device *netdev,
103 struct ethtool_cmd *ecmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700105 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 struct e1000_hw *hw = &adapter->hw;
107
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800108 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 ecmd->supported = (SUPPORTED_10baseT_Half |
111 SUPPORTED_10baseT_Full |
112 SUPPORTED_100baseT_Half |
113 SUPPORTED_100baseT_Full |
114 SUPPORTED_1000baseT_Full|
115 SUPPORTED_Autoneg |
116 SUPPORTED_TP);
Auke Kokcd94dd02006-06-27 09:08:22 -0700117 if (hw->phy_type == e1000_phy_ife)
118 ecmd->supported &= ~SUPPORTED_1000baseT_Full;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 ecmd->advertising = ADVERTISED_TP;
120
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800121 if (hw->autoneg == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 ecmd->advertising |= ADVERTISED_Autoneg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 /* the e1000 autoneg seems to match ethtool nicely */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 ecmd->advertising |= hw->autoneg_advertised;
125 }
126
127 ecmd->port = PORT_TP;
128 ecmd->phy_address = hw->phy_addr;
129
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800130 if (hw->mac_type == e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 ecmd->transceiver = XCVR_EXTERNAL;
132 else
133 ecmd->transceiver = XCVR_INTERNAL;
134
135 } else {
136 ecmd->supported = (SUPPORTED_1000baseT_Full |
137 SUPPORTED_FIBRE |
138 SUPPORTED_Autoneg);
139
Malli Chilakala012609a2005-06-17 17:43:06 -0700140 ecmd->advertising = (ADVERTISED_1000baseT_Full |
141 ADVERTISED_FIBRE |
142 ADVERTISED_Autoneg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 ecmd->port = PORT_FIBRE;
145
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800146 if (hw->mac_type >= e1000_82545)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 ecmd->transceiver = XCVR_INTERNAL;
148 else
149 ecmd->transceiver = XCVR_EXTERNAL;
150 }
151
Joe Perches1dc32912008-07-11 15:17:08 -0700152 if (er32(STATUS) & E1000_STATUS_LU) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 e1000_get_speed_and_duplex(hw, &adapter->link_speed,
155 &adapter->link_duplex);
156 ecmd->speed = adapter->link_speed;
157
158 /* unfortunatly FULL_DUPLEX != DUPLEX_FULL
159 * and HALF_DUPLEX != DUPLEX_HALF */
160
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800161 if (adapter->link_duplex == FULL_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 ecmd->duplex = DUPLEX_FULL;
163 else
164 ecmd->duplex = DUPLEX_HALF;
165 } else {
166 ecmd->speed = -1;
167 ecmd->duplex = -1;
168 }
169
170 ecmd->autoneg = ((hw->media_type == e1000_media_type_fiber) ||
171 hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
172 return 0;
173}
174
Joe Perches64798842008-07-11 15:17:02 -0700175static int e1000_set_settings(struct net_device *netdev,
176 struct ethtool_cmd *ecmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700178 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 struct e1000_hw *hw = &adapter->hw;
180
Jeff Kirsher57128192006-01-12 16:50:28 -0800181 /* When SoL/IDER sessions are active, autoneg/speed/duplex
182 * cannot be changed */
183 if (e1000_check_phy_reset_block(hw)) {
184 DPRINTK(DRV, ERR, "Cannot change link characteristics "
185 "when SoL/IDER is active.\n");
186 return -EINVAL;
187 }
188
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700189 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
190 msleep(1);
191
Jeff Kirsher57128192006-01-12 16:50:28 -0800192 if (ecmd->autoneg == AUTONEG_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 hw->autoneg = 1;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800194 if (hw->media_type == e1000_media_type_fiber)
Malli Chilakala012609a2005-06-17 17:43:06 -0700195 hw->autoneg_advertised = ADVERTISED_1000baseT_Full |
196 ADVERTISED_FIBRE |
197 ADVERTISED_Autoneg;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800198 else
Jeff Kirsher2f2ca262006-09-27 12:53:40 -0700199 hw->autoneg_advertised = ecmd->advertising |
200 ADVERTISED_TP |
201 ADVERTISED_Autoneg;
Malli Chilakala012609a2005-06-17 17:43:06 -0700202 ecmd->advertising = hw->autoneg_advertised;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 } else
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700204 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
205 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 return -EINVAL;
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700207 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209 /* reset the link */
210
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700211 if (netif_running(adapter->netdev)) {
212 e1000_down(adapter);
213 e1000_up(adapter);
214 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 e1000_reset(adapter);
216
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700217 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 return 0;
219}
220
Joe Perches64798842008-07-11 15:17:02 -0700221static void e1000_get_pauseparam(struct net_device *netdev,
222 struct ethtool_pauseparam *pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700224 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 struct e1000_hw *hw = &adapter->hw;
226
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800227 pause->autoneg =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800229
Jeff Kirsher11241b12006-09-27 12:53:28 -0700230 if (hw->fc == E1000_FC_RX_PAUSE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 pause->rx_pause = 1;
Jeff Kirsher11241b12006-09-27 12:53:28 -0700232 else if (hw->fc == E1000_FC_TX_PAUSE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 pause->tx_pause = 1;
Jeff Kirsher11241b12006-09-27 12:53:28 -0700234 else if (hw->fc == E1000_FC_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 pause->rx_pause = 1;
236 pause->tx_pause = 1;
237 }
238}
239
Joe Perches64798842008-07-11 15:17:02 -0700240static int e1000_set_pauseparam(struct net_device *netdev,
241 struct ethtool_pauseparam *pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700243 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700245 int retval = 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 adapter->fc_autoneg = pause->autoneg;
248
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700249 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
250 msleep(1);
251
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800252 if (pause->rx_pause && pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700253 hw->fc = E1000_FC_FULL;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800254 else if (pause->rx_pause && !pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700255 hw->fc = E1000_FC_RX_PAUSE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800256 else if (!pause->rx_pause && pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700257 hw->fc = E1000_FC_TX_PAUSE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800258 else if (!pause->rx_pause && !pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700259 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261 hw->original_fc = hw->fc;
262
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800263 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700264 if (netif_running(adapter->netdev)) {
265 e1000_down(adapter);
266 e1000_up(adapter);
267 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 e1000_reset(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800269 } else
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700270 retval = ((hw->media_type == e1000_media_type_fiber) ?
Auke Kok90fb5132006-11-01 08:47:30 -0800271 e1000_setup_link(hw) : e1000_force_mac_fc(hw));
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800272
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700273 clear_bit(__E1000_RESETTING, &adapter->flags);
274 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275}
276
Joe Perches64798842008-07-11 15:17:02 -0700277static u32 e1000_get_rx_csum(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700279 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 return adapter->rx_csum;
281}
282
Joe Perches64798842008-07-11 15:17:02 -0700283static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700285 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 adapter->rx_csum = data;
287
Auke Kok2db10a02006-06-27 09:06:28 -0700288 if (netif_running(netdev))
289 e1000_reinit_locked(adapter);
290 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 e1000_reset(adapter);
292 return 0;
293}
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800294
Joe Perches64798842008-07-11 15:17:02 -0700295static u32 e1000_get_tx_csum(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296{
297 return (netdev->features & NETIF_F_HW_CSUM) != 0;
298}
299
Joe Perches64798842008-07-11 15:17:02 -0700300static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700302 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700303 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
Joe Perches1dc32912008-07-11 15:17:08 -0700305 if (hw->mac_type < e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 if (!data)
307 return -EINVAL;
308 return 0;
309 }
310
311 if (data)
312 netdev->features |= NETIF_F_HW_CSUM;
313 else
314 netdev->features &= ~NETIF_F_HW_CSUM;
315
316 return 0;
317}
318
Joe Perches64798842008-07-11 15:17:02 -0700319static int e1000_set_tso(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700321 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700322 struct e1000_hw *hw = &adapter->hw;
323
324 if ((hw->mac_type < e1000_82544) ||
325 (hw->mac_type == e1000_82547))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 return data ? -EINVAL : 0;
327
328 if (data)
329 netdev->features |= NETIF_F_TSO;
330 else
331 netdev->features &= ~NETIF_F_TSO;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -0800332
Andy Gospodarek581abbc2008-06-19 17:19:02 -0400333 if (data && (adapter->hw.mac_type > e1000_82547_rev_2))
Auke Kok87ca4e52006-11-01 08:47:36 -0800334 netdev->features |= NETIF_F_TSO6;
335 else
336 netdev->features &= ~NETIF_F_TSO6;
Auke Kok87ca4e52006-11-01 08:47:36 -0800337
Jeff Kirsher7e6c9862006-03-02 18:19:30 -0800338 DPRINTK(PROBE, INFO, "TSO is %s\n", data ? "Enabled" : "Disabled");
Joe Perchesc3033b02008-03-21 11:06:25 -0700339 adapter->tso_force = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 return 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800341}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Joe Perches64798842008-07-11 15:17:02 -0700343static u32 e1000_get_msglevel(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700345 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 return adapter->msg_enable;
347}
348
Joe Perches64798842008-07-11 15:17:02 -0700349static void e1000_set_msglevel(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700351 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 adapter->msg_enable = data;
353}
354
Joe Perches64798842008-07-11 15:17:02 -0700355static int e1000_get_regs_len(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
357#define E1000_REGS_LEN 32
Joe Perches406874a2008-04-03 10:06:32 -0700358 return E1000_REGS_LEN * sizeof(u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359}
360
Joe Perches64798842008-07-11 15:17:02 -0700361static void e1000_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
362 void *p)
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 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700366 u32 *regs_buff = p;
367 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Joe Perches406874a2008-04-03 10:06:32 -0700369 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
372
Joe Perches1dc32912008-07-11 15:17:08 -0700373 regs_buff[0] = er32(CTRL);
374 regs_buff[1] = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Joe Perches1dc32912008-07-11 15:17:08 -0700376 regs_buff[2] = er32(RCTL);
377 regs_buff[3] = er32(RDLEN);
378 regs_buff[4] = er32(RDH);
379 regs_buff[5] = er32(RDT);
380 regs_buff[6] = er32(RDTR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Joe Perches1dc32912008-07-11 15:17:08 -0700382 regs_buff[7] = er32(TCTL);
383 regs_buff[8] = er32(TDLEN);
384 regs_buff[9] = er32(TDH);
385 regs_buff[10] = er32(TDT);
386 regs_buff[11] = er32(TIDV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Joe Perches1dc32912008-07-11 15:17:08 -0700388 regs_buff[12] = hw->phy_type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800389 if (hw->phy_type == e1000_phy_igp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
391 IGP01E1000_PHY_AGC_A);
392 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A &
393 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700394 regs_buff[13] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
396 IGP01E1000_PHY_AGC_B);
397 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B &
398 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700399 regs_buff[14] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
401 IGP01E1000_PHY_AGC_C);
402 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C &
403 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700404 regs_buff[15] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
406 IGP01E1000_PHY_AGC_D);
407 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D &
408 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700409 regs_buff[16] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 regs_buff[17] = 0; /* extended 10bt distance (not needed) */
411 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
412 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS &
413 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700414 regs_buff[18] = (u32)phy_data; /* cable polarity */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
416 IGP01E1000_PHY_PCS_INIT_REG);
417 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG &
418 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700419 regs_buff[19] = (u32)phy_data; /* cable polarity */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 regs_buff[20] = 0; /* polarity correction enabled (always) */
421 regs_buff[22] = 0; /* phy receive errors (unavailable) */
422 regs_buff[23] = regs_buff[18]; /* mdix mode */
423 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
424 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -0700425 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700426 regs_buff[13] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
428 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
429 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
Auke Kok8fc897b2006-08-28 14:56:16 -0700430 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700431 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 regs_buff[18] = regs_buff[13]; /* cable polarity */
433 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
434 regs_buff[20] = regs_buff[17]; /* polarity correction */
435 /* phy receive errors */
436 regs_buff[22] = adapter->phy_stats.receive_errors;
437 regs_buff[23] = regs_buff[13]; /* mdix mode */
438 }
439 regs_buff[21] = adapter->phy_stats.idle_errors; /* phy idle errors */
440 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700441 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800443 if (hw->mac_type >= e1000_82540 &&
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -0700444 hw->mac_type < e1000_82571 &&
445 hw->media_type == e1000_media_type_copper) {
Joe Perches1dc32912008-07-11 15:17:08 -0700446 regs_buff[26] = er32(MANC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 }
448}
449
Joe Perches64798842008-07-11 15:17:02 -0700450static int e1000_get_eeprom_len(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700452 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700453 struct e1000_hw *hw = &adapter->hw;
454
455 return hw->eeprom.word_size * 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456}
457
Joe Perches64798842008-07-11 15:17:02 -0700458static int e1000_get_eeprom(struct net_device *netdev,
459 struct ethtool_eeprom *eeprom, u8 *bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700461 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700463 u16 *eeprom_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 int first_word, last_word;
465 int ret_val = 0;
Joe Perches406874a2008-04-03 10:06:32 -0700466 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800468 if (eeprom->len == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 return -EINVAL;
470
471 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
472
473 first_word = eeprom->offset >> 1;
474 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
475
Joe Perches406874a2008-04-03 10:06:32 -0700476 eeprom_buff = kmalloc(sizeof(u16) *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 (last_word - first_word + 1), GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800478 if (!eeprom_buff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 return -ENOMEM;
480
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800481 if (hw->eeprom.type == e1000_eeprom_spi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 ret_val = e1000_read_eeprom(hw, first_word,
483 last_word - first_word + 1,
484 eeprom_buff);
485 else {
486 for (i = 0; i < last_word - first_word + 1; i++)
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800487 if ((ret_val = e1000_read_eeprom(hw, first_word + i, 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 &eeprom_buff[i])))
489 break;
490 }
491
492 /* Device's eeprom is always little-endian, word addressable */
493 for (i = 0; i < last_word - first_word + 1; i++)
494 le16_to_cpus(&eeprom_buff[i]);
495
Joe Perches406874a2008-04-03 10:06:32 -0700496 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 eeprom->len);
498 kfree(eeprom_buff);
499
500 return ret_val;
501}
502
Joe Perches64798842008-07-11 15:17:02 -0700503static int e1000_set_eeprom(struct net_device *netdev,
504 struct ethtool_eeprom *eeprom, u8 *bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700506 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700508 u16 *eeprom_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 void *ptr;
510 int max_len, first_word, last_word, ret_val = 0;
Joe Perches406874a2008-04-03 10:06:32 -0700511 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800513 if (eeprom->len == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 return -EOPNOTSUPP;
515
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800516 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 return -EFAULT;
518
519 max_len = hw->eeprom.word_size * 2;
520
521 first_word = eeprom->offset >> 1;
522 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
523 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800524 if (!eeprom_buff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 return -ENOMEM;
526
527 ptr = (void *)eeprom_buff;
528
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800529 if (eeprom->offset & 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 /* need read/modify/write of first changed EEPROM word */
531 /* only the second byte of the word is being modified */
532 ret_val = e1000_read_eeprom(hw, first_word, 1,
533 &eeprom_buff[0]);
534 ptr++;
535 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800536 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 /* need read/modify/write of last changed EEPROM word */
538 /* only the first byte of the word is being modified */
539 ret_val = e1000_read_eeprom(hw, last_word, 1,
540 &eeprom_buff[last_word - first_word]);
541 }
542
543 /* Device's eeprom is always little-endian, word addressable */
544 for (i = 0; i < last_word - first_word + 1; i++)
545 le16_to_cpus(&eeprom_buff[i]);
546
547 memcpy(ptr, bytes, eeprom->len);
548
549 for (i = 0; i < last_word - first_word + 1; i++)
550 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
551
552 ret_val = e1000_write_eeprom(hw, first_word,
553 last_word - first_word + 1, eeprom_buff);
554
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800555 /* Update the checksum over the first part of the EEPROM if needed
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -0400556 * and flush shadow RAM for 82573 conrollers */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800557 if ((ret_val == 0) && ((first_word <= EEPROM_CHECKSUM_REG) ||
Mallikarjuna R Chilakalaa7990ba2005-10-04 07:08:19 -0400558 (hw->mac_type == e1000_82573)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 e1000_update_eeprom_checksum(hw);
560
561 kfree(eeprom_buff);
562 return ret_val;
563}
564
Joe Perches64798842008-07-11 15:17:02 -0700565static void e1000_get_drvinfo(struct net_device *netdev,
566 struct ethtool_drvinfo *drvinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700568 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700569 struct e1000_hw *hw = &adapter->hw;
Jeff Kirshera2917e22006-01-12 16:51:23 -0800570 char firmware_version[32];
Joe Perches406874a2008-04-03 10:06:32 -0700571 u16 eeprom_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573 strncpy(drvinfo->driver, e1000_driver_name, 32);
574 strncpy(drvinfo->version, e1000_driver_version, 32);
Jeff Kirshera2917e22006-01-12 16:51:23 -0800575
576 /* EEPROM image version # is reported as firmware version # for
577 * 8257{1|2|3} controllers */
Joe Perches1dc32912008-07-11 15:17:08 -0700578 e1000_read_eeprom(hw, 5, 1, &eeprom_data);
579 switch (hw->mac_type) {
Jeff Kirshera2917e22006-01-12 16:51:23 -0800580 case e1000_82571:
581 case e1000_82572:
582 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800583 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -0700584 case e1000_ich8lan:
Jeff Kirshera2917e22006-01-12 16:51:23 -0800585 sprintf(firmware_version, "%d.%d-%d",
586 (eeprom_data & 0xF000) >> 12,
587 (eeprom_data & 0x0FF0) >> 4,
588 eeprom_data & 0x000F);
589 break;
590 default:
591 sprintf(firmware_version, "N/A");
592 }
593
594 strncpy(drvinfo->fw_version, firmware_version, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 drvinfo->regdump_len = e1000_get_regs_len(netdev);
597 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
598}
599
Joe Perches64798842008-07-11 15:17:02 -0700600static void e1000_get_ringparam(struct net_device *netdev,
601 struct ethtool_ringparam *ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700603 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700604 struct e1000_hw *hw = &adapter->hw;
605 e1000_mac_type mac_type = hw->mac_type;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400606 struct e1000_tx_ring *txdr = adapter->tx_ring;
607 struct e1000_rx_ring *rxdr = adapter->rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
610 E1000_MAX_82544_RXD;
611 ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD :
612 E1000_MAX_82544_TXD;
613 ring->rx_mini_max_pending = 0;
614 ring->rx_jumbo_max_pending = 0;
615 ring->rx_pending = rxdr->count;
616 ring->tx_pending = txdr->count;
617 ring->rx_mini_pending = 0;
618 ring->rx_jumbo_pending = 0;
619}
620
Joe Perches64798842008-07-11 15:17:02 -0700621static int e1000_set_ringparam(struct net_device *netdev,
622 struct ethtool_ringparam *ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700624 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700625 struct e1000_hw *hw = &adapter->hw;
626 e1000_mac_type mac_type = hw->mac_type;
Vasily Averin793fab722006-09-27 12:54:14 -0700627 struct e1000_tx_ring *txdr, *tx_old;
628 struct e1000_rx_ring *rxdr, *rx_old;
Yan Burman1c7e5b12007-03-06 08:58:04 -0800629 int i, err;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400630
Jeff Kirsher0989aa42006-03-02 18:17:16 -0800631 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
632 return -EINVAL;
633
Auke Kok2db10a02006-06-27 09:06:28 -0700634 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
635 msleep(1);
636
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400637 if (netif_running(adapter->netdev))
638 e1000_down(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640 tx_old = adapter->tx_ring;
641 rx_old = adapter->rx_ring;
642
Vasily Averin793fab722006-09-27 12:54:14 -0700643 err = -ENOMEM;
Yan Burman1c7e5b12007-03-06 08:58:04 -0800644 txdr = kcalloc(adapter->num_tx_queues, sizeof(struct e1000_tx_ring), GFP_KERNEL);
Vasily Averin793fab722006-09-27 12:54:14 -0700645 if (!txdr)
646 goto err_alloc_tx;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400647
Yan Burman1c7e5b12007-03-06 08:58:04 -0800648 rxdr = kcalloc(adapter->num_rx_queues, sizeof(struct e1000_rx_ring), GFP_KERNEL);
Vasily Averin793fab722006-09-27 12:54:14 -0700649 if (!rxdr)
650 goto err_alloc_rx;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400651
Vasily Averin793fab722006-09-27 12:54:14 -0700652 adapter->tx_ring = txdr;
653 adapter->rx_ring = rxdr;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400654
Joe Perches406874a2008-04-03 10:06:32 -0700655 rxdr->count = max(ring->rx_pending,(u32)E1000_MIN_RXD);
656 rxdr->count = min(rxdr->count,(u32)(mac_type < e1000_82544 ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 E1000_MAX_RXD : E1000_MAX_82544_RXD));
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700658 rxdr->count = ALIGN(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Joe Perches406874a2008-04-03 10:06:32 -0700660 txdr->count = max(ring->tx_pending,(u32)E1000_MIN_TXD);
661 txdr->count = min(txdr->count,(u32)(mac_type < e1000_82544 ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 E1000_MAX_TXD : E1000_MAX_82544_TXD));
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700663 txdr->count = ALIGN(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800665 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400666 txdr[i].count = txdr->count;
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800667 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400668 rxdr[i].count = rxdr->count;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400669
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800670 if (netif_running(adapter->netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 /* Try to get new resources before deleting old */
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400672 if ((err = e1000_setup_all_rx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 goto err_setup_rx;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400674 if ((err = e1000_setup_all_tx_resources(adapter)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 goto err_setup_tx;
676
677 /* save the new, restore the old in order to free it,
678 * then restore the new back again */
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 adapter->rx_ring = rx_old;
681 adapter->tx_ring = tx_old;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400682 e1000_free_all_rx_resources(adapter);
683 e1000_free_all_tx_resources(adapter);
684 kfree(tx_old);
685 kfree(rx_old);
Vasily Averin793fab722006-09-27 12:54:14 -0700686 adapter->rx_ring = rxdr;
687 adapter->tx_ring = txdr;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800688 if ((err = e1000_up(adapter)))
Auke Kok2db10a02006-06-27 09:06:28 -0700689 goto err_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 }
691
Auke Kok2db10a02006-06-27 09:06:28 -0700692 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 return 0;
694err_setup_tx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400695 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696err_setup_rx:
697 adapter->rx_ring = rx_old;
698 adapter->tx_ring = tx_old;
Vasily Averin793fab722006-09-27 12:54:14 -0700699 kfree(rxdr);
700err_alloc_rx:
701 kfree(txdr);
702err_alloc_tx:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 e1000_up(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -0700704err_setup:
705 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 return err;
707}
708
Joe Perches64798842008-07-11 15:17:02 -0700709static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data, int reg,
710 u32 mask, u32 write)
Joe Perches7e643002007-11-13 20:52:05 -0800711{
Joe Perches1dc32912008-07-11 15:17:08 -0700712 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700713 static const u32 test[] =
Joe Perches7e643002007-11-13 20:52:05 -0800714 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Joe Perches1dc32912008-07-11 15:17:08 -0700715 u8 __iomem *address = hw->hw_addr + reg;
Joe Perches406874a2008-04-03 10:06:32 -0700716 u32 read;
Joe Perches7e643002007-11-13 20:52:05 -0800717 int i;
718
719 for (i = 0; i < ARRAY_SIZE(test); i++) {
720 writel(write & test[i], address);
721 read = readl(address);
722 if (read != (write & test[i] & mask)) {
723 DPRINTK(DRV, ERR, "pattern test reg %04X failed: "
724 "got 0x%08X expected 0x%08X\n",
Jeff Garzikcba05162007-11-23 21:50:34 -0500725 reg, read, (write & test[i] & mask));
Joe Perches7e643002007-11-13 20:52:05 -0800726 *data = reg;
727 return true;
728 }
729 }
730 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731}
732
Joe Perches64798842008-07-11 15:17:02 -0700733static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data, int reg,
734 u32 mask, u32 write)
Joe Perches7e643002007-11-13 20:52:05 -0800735{
Joe Perches1dc32912008-07-11 15:17:08 -0700736 struct e1000_hw *hw = &adapter->hw;
737 u8 __iomem *address = hw->hw_addr + reg;
Joe Perches406874a2008-04-03 10:06:32 -0700738 u32 read;
Joe Perches7e643002007-11-13 20:52:05 -0800739
740 writel(write & mask, address);
741 read = readl(address);
742 if ((read & mask) != (write & mask)) {
743 DPRINTK(DRV, ERR, "set/check reg %04X test failed: "
744 "got 0x%08X expected 0x%08X\n",
745 reg, (read & mask), (write & mask));
746 *data = reg;
747 return true;
748 }
749 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750}
751
Joe Perches7e643002007-11-13 20:52:05 -0800752#define REG_PATTERN_TEST(reg, mask, write) \
753 do { \
754 if (reg_pattern_test(adapter, data, \
Joe Perches1dc32912008-07-11 15:17:08 -0700755 (hw->mac_type >= e1000_82543) \
Joe Perches7e643002007-11-13 20:52:05 -0800756 ? E1000_##reg : E1000_82542_##reg, \
757 mask, write)) \
758 return 1; \
759 } while (0)
760
761#define REG_SET_AND_CHECK(reg, mask, write) \
762 do { \
763 if (reg_set_and_check(adapter, data, \
Joe Perches1dc32912008-07-11 15:17:08 -0700764 (hw->mac_type >= e1000_82543) \
Joe Perches7e643002007-11-13 20:52:05 -0800765 ? E1000_##reg : E1000_82542_##reg, \
766 mask, write)) \
767 return 1; \
768 } while (0)
769
Joe Perches64798842008-07-11 15:17:02 -0700770static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771{
Joe Perches406874a2008-04-03 10:06:32 -0700772 u32 value, before, after;
773 u32 i, toggle;
Joe Perches1dc32912008-07-11 15:17:08 -0700774 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776 /* The status register is Read Only, so a write should fail.
777 * Some bits that get toggled are ignored.
778 */
Joe Perches1dc32912008-07-11 15:17:08 -0700779 switch (hw->mac_type) {
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400780 /* there are several bits on newer hardware that are r/w */
781 case e1000_82571:
782 case e1000_82572:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -0800783 case e1000_80003es2lan:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400784 toggle = 0x7FFFF3FF;
785 break;
Malli Chilakalab01f6692005-06-17 17:42:29 -0700786 case e1000_82573:
Auke Kokcd94dd02006-06-27 09:08:22 -0700787 case e1000_ich8lan:
Malli Chilakalab01f6692005-06-17 17:42:29 -0700788 toggle = 0x7FFFF033;
789 break;
790 default:
791 toggle = 0xFFFFF833;
792 break;
793 }
794
Joe Perches1dc32912008-07-11 15:17:08 -0700795 before = er32(STATUS);
796 value = (er32(STATUS) & toggle);
797 ew32(STATUS, toggle);
798 after = er32(STATUS) & toggle;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800799 if (value != after) {
Malli Chilakalab01f6692005-06-17 17:42:29 -0700800 DPRINTK(DRV, ERR, "failed STATUS register test got: "
801 "0x%08X expected: 0x%08X\n", after, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 *data = 1;
803 return 1;
804 }
Malli Chilakalab01f6692005-06-17 17:42:29 -0700805 /* restore previous status */
Joe Perches1dc32912008-07-11 15:17:08 -0700806 ew32(STATUS, before);
Auke Kok90fb5132006-11-01 08:47:30 -0800807
Joe Perches1dc32912008-07-11 15:17:08 -0700808 if (hw->mac_type != e1000_ich8lan) {
Auke Kokcd94dd02006-06-27 09:08:22 -0700809 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
810 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
811 REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF);
812 REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF);
813 }
Auke Kok90fb5132006-11-01 08:47:30 -0800814
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF);
816 REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
817 REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF);
818 REG_PATTERN_TEST(RDH, 0x0000FFFF, 0x0000FFFF);
819 REG_PATTERN_TEST(RDT, 0x0000FFFF, 0x0000FFFF);
820 REG_PATTERN_TEST(FCRTH, 0x0000FFF8, 0x0000FFF8);
821 REG_PATTERN_TEST(FCTTV, 0x0000FFFF, 0x0000FFFF);
822 REG_PATTERN_TEST(TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
823 REG_PATTERN_TEST(TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
824 REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF);
825
826 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000);
Auke Kok90fb5132006-11-01 08:47:30 -0800827
Joe Perches1dc32912008-07-11 15:17:08 -0700828 before = (hw->mac_type == e1000_ich8lan ?
Auke Kok90fb5132006-11-01 08:47:30 -0800829 0x06C3B33E : 0x06DFB3FE);
Auke Kokcd94dd02006-06-27 09:08:22 -0700830 REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);
832
Joe Perches1dc32912008-07-11 15:17:08 -0700833 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Auke Kokcd94dd02006-06-27 09:08:22 -0700835 REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
Joe Perches1dc32912008-07-11 15:17:08 -0700837 if (hw->mac_type != e1000_ich8lan)
Auke Kokcd94dd02006-06-27 09:08:22 -0700838 REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
840 REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
Joe Perches1dc32912008-07-11 15:17:08 -0700841 value = (hw->mac_type == e1000_ich8lan ?
Auke Kok90fb5132006-11-01 08:47:30 -0800842 E1000_RAR_ENTRIES_ICH8LAN : E1000_RAR_ENTRIES);
Auke Kokcd94dd02006-06-27 09:08:22 -0700843 for (i = 0; i < value; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF,
Auke Kok90fb5132006-11-01 08:47:30 -0800845 0xFFFFFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 }
847
848 } else {
849
850 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF);
851 REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF);
852 REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF);
853 REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF);
854
855 }
856
Joe Perches1dc32912008-07-11 15:17:08 -0700857 value = (hw->mac_type == e1000_ich8lan ?
Auke Kokcd94dd02006-06-27 09:08:22 -0700858 E1000_MC_TBL_SIZE_ICH8LAN : E1000_MC_TBL_SIZE);
859 for (i = 0; i < value; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
861
862 *data = 0;
863 return 0;
864}
865
Joe Perches64798842008-07-11 15:17:02 -0700866static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867{
Joe Perches1dc32912008-07-11 15:17:08 -0700868 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700869 u16 temp;
870 u16 checksum = 0;
871 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
873 *data = 0;
874 /* Read and add up the contents of the EEPROM */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800875 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
Joe Perches1dc32912008-07-11 15:17:08 -0700876 if ((e1000_read_eeprom(hw, i, 1, &temp)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 *data = 1;
878 break;
879 }
880 checksum += temp;
881 }
882
883 /* If Checksum is not Correct return error else test passed */
Joe Perchese982f172008-07-11 15:17:18 -0700884 if ((checksum != (u16)EEPROM_SUM) && !(*data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 *data = 2;
886
887 return *data;
888}
889
Joe Perches64798842008-07-11 15:17:02 -0700890static irqreturn_t e1000_test_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891{
Joe Perchese982f172008-07-11 15:17:18 -0700892 struct net_device *netdev = (struct net_device *)data;
Malli Chilakala60490fe2005-06-17 17:41:45 -0700893 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700894 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
Joe Perches1dc32912008-07-11 15:17:08 -0700896 adapter->test_icr |= er32(ICR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
898 return IRQ_HANDLED;
899}
900
Joe Perches64798842008-07-11 15:17:02 -0700901static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902{
903 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -0700904 u32 mask, i = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -0700905 bool shared_int = true;
Joe Perches406874a2008-04-03 10:06:32 -0700906 u32 irq = adapter->pdev->irq;
Joe Perches1dc32912008-07-11 15:17:08 -0700907 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
909 *data = 0;
910
Auke Kok8fc897b2006-08-28 14:56:16 -0700911 /* NOTE: we don't test MSI interrupts here, yet */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 /* Hook up test interrupt handler just for this test */
Auke Kok90fb5132006-11-01 08:47:30 -0800913 if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
914 netdev))
Joe Perchesc3033b02008-03-21 11:06:25 -0700915 shared_int = false;
Auke Kok8fc897b2006-08-28 14:56:16 -0700916 else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED,
Auke Kok90fb5132006-11-01 08:47:30 -0800917 netdev->name, netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 *data = 1;
919 return -1;
920 }
Auke Kok8fc897b2006-08-28 14:56:16 -0700921 DPRINTK(HW, INFO, "testing %s interrupt\n",
Auke Kokb9b6e782006-06-08 09:28:38 -0700922 (shared_int ? "shared" : "unshared"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 /* Disable all the interrupts */
Joe Perches1dc32912008-07-11 15:17:08 -0700925 ew32(IMC, 0xFFFFFFFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400926 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928 /* Test each interrupt */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800929 for (; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
Joe Perches1dc32912008-07-11 15:17:08 -0700931 if (hw->mac_type == e1000_ich8lan && i == 8)
Auke Kokcd94dd02006-06-27 09:08:22 -0700932 continue;
Auke Kok90fb5132006-11-01 08:47:30 -0800933
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 /* Interrupt to test */
935 mask = 1 << i;
936
Auke Kok76c224b2006-05-23 13:36:06 -0700937 if (!shared_int) {
938 /* Disable the interrupt to be reported in
939 * the cause register and then force the same
940 * interrupt and see if one gets posted. If
941 * an interrupt was posted to the bus, the
942 * test failed.
943 */
944 adapter->test_icr = 0;
Joe Perches1dc32912008-07-11 15:17:08 -0700945 ew32(IMC, mask);
946 ew32(ICS, mask);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400947 msleep(10);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800948
Auke Kok76c224b2006-05-23 13:36:06 -0700949 if (adapter->test_icr & mask) {
950 *data = 3;
951 break;
952 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 }
954
955 /* Enable the interrupt to be reported in
956 * the cause register and then force the same
957 * interrupt and see if one gets posted. If
958 * an interrupt was not posted to the bus, the
959 * test failed.
960 */
961 adapter->test_icr = 0;
Joe Perches1dc32912008-07-11 15:17:08 -0700962 ew32(IMS, mask);
963 ew32(ICS, mask);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400964 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800966 if (!(adapter->test_icr & mask)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 *data = 4;
968 break;
969 }
970
Auke Kok76c224b2006-05-23 13:36:06 -0700971 if (!shared_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 /* Disable the other interrupts to be reported in
973 * the cause register and then force the other
974 * interrupts and see if any get posted. If
975 * an interrupt was posted to the bus, the
976 * test failed.
977 */
978 adapter->test_icr = 0;
Joe Perches1dc32912008-07-11 15:17:08 -0700979 ew32(IMC, ~mask & 0x00007FFF);
980 ew32(ICS, ~mask & 0x00007FFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400981 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800983 if (adapter->test_icr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 *data = 5;
985 break;
986 }
987 }
988 }
989
990 /* Disable all the interrupts */
Joe Perches1dc32912008-07-11 15:17:08 -0700991 ew32(IMC, 0xFFFFFFFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400992 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
994 /* Unhook test interrupt handler */
995 free_irq(irq, netdev);
996
997 return *data;
998}
999
Joe Perches64798842008-07-11 15:17:02 -07001000static void e1000_free_desc_rings(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001002 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1003 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 struct pci_dev *pdev = adapter->pdev;
1005 int i;
1006
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001007 if (txdr->desc && txdr->buffer_info) {
1008 for (i = 0; i < txdr->count; i++) {
1009 if (txdr->buffer_info[i].dma)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 pci_unmap_single(pdev, txdr->buffer_info[i].dma,
1011 txdr->buffer_info[i].length,
1012 PCI_DMA_TODEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001013 if (txdr->buffer_info[i].skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 dev_kfree_skb(txdr->buffer_info[i].skb);
1015 }
1016 }
1017
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001018 if (rxdr->desc && rxdr->buffer_info) {
1019 for (i = 0; i < rxdr->count; i++) {
1020 if (rxdr->buffer_info[i].dma)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 pci_unmap_single(pdev, rxdr->buffer_info[i].dma,
1022 rxdr->buffer_info[i].length,
1023 PCI_DMA_FROMDEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001024 if (rxdr->buffer_info[i].skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 dev_kfree_skb(rxdr->buffer_info[i].skb);
1026 }
1027 }
1028
Jeff Kirsherf5645112006-01-12 16:51:01 -08001029 if (txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 pci_free_consistent(pdev, txdr->size, txdr->desc, txdr->dma);
John W. Linville6b27adb2005-11-08 15:59:30 -05001031 txdr->desc = NULL;
1032 }
Jeff Kirsherf5645112006-01-12 16:51:01 -08001033 if (rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 pci_free_consistent(pdev, rxdr->size, rxdr->desc, rxdr->dma);
John W. Linville6b27adb2005-11-08 15:59:30 -05001035 rxdr->desc = NULL;
1036 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037
Jesper Juhlb4558ea2005-10-28 16:53:13 -04001038 kfree(txdr->buffer_info);
John W. Linville6b27adb2005-11-08 15:59:30 -05001039 txdr->buffer_info = NULL;
Jesper Juhlb4558ea2005-10-28 16:53:13 -04001040 kfree(rxdr->buffer_info);
John W. Linville6b27adb2005-11-08 15:59:30 -05001041 rxdr->buffer_info = NULL;
Jeff Kirsherf5645112006-01-12 16:51:01 -08001042
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 return;
1044}
1045
Joe Perches64798842008-07-11 15:17:02 -07001046static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047{
Joe Perches1dc32912008-07-11 15:17:08 -07001048 struct e1000_hw *hw = &adapter->hw;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001049 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1050 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 struct pci_dev *pdev = adapter->pdev;
Joe Perches406874a2008-04-03 10:06:32 -07001052 u32 rctl;
Yan Burman1c7e5b12007-03-06 08:58:04 -08001053 int i, ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
1055 /* Setup Tx descriptor ring and Tx buffers */
1056
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001057 if (!txdr->count)
1058 txdr->count = E1000_DEFAULT_TXD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
Yan Burman1c7e5b12007-03-06 08:58:04 -08001060 if (!(txdr->buffer_info = kcalloc(txdr->count,
1061 sizeof(struct e1000_buffer),
1062 GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 ret_val = 1;
1064 goto err_nomem;
1065 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
1067 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001068 txdr->size = ALIGN(txdr->size, 4096);
Yan Burman1c7e5b12007-03-06 08:58:04 -08001069 if (!(txdr->desc = pci_alloc_consistent(pdev, txdr->size,
1070 &txdr->dma))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 ret_val = 2;
1072 goto err_nomem;
1073 }
1074 memset(txdr->desc, 0, txdr->size);
1075 txdr->next_to_use = txdr->next_to_clean = 0;
1076
Joe Perchese982f172008-07-11 15:17:18 -07001077 ew32(TDBAL, ((u64)txdr->dma & 0x00000000FFFFFFFF));
1078 ew32(TDBAH, ((u64)txdr->dma >> 32));
Joe Perches1dc32912008-07-11 15:17:08 -07001079 ew32(TDLEN, txdr->count * sizeof(struct e1000_tx_desc));
1080 ew32(TDH, 0);
1081 ew32(TDT, 0);
1082 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN |
1083 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1084 E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001086 for (i = 0; i < txdr->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i);
1088 struct sk_buff *skb;
1089 unsigned int size = 1024;
1090
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001091 if (!(skb = alloc_skb(size, GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 ret_val = 3;
1093 goto err_nomem;
1094 }
1095 skb_put(skb, size);
1096 txdr->buffer_info[i].skb = skb;
1097 txdr->buffer_info[i].length = skb->len;
1098 txdr->buffer_info[i].dma =
1099 pci_map_single(pdev, skb->data, skb->len,
1100 PCI_DMA_TODEVICE);
1101 tx_desc->buffer_addr = cpu_to_le64(txdr->buffer_info[i].dma);
1102 tx_desc->lower.data = cpu_to_le32(skb->len);
1103 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1104 E1000_TXD_CMD_IFCS |
1105 E1000_TXD_CMD_RPS);
1106 tx_desc->upper.data = 0;
1107 }
1108
1109 /* Setup Rx descriptor ring and Rx buffers */
1110
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001111 if (!rxdr->count)
1112 rxdr->count = E1000_DEFAULT_RXD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
Yan Burman1c7e5b12007-03-06 08:58:04 -08001114 if (!(rxdr->buffer_info = kcalloc(rxdr->count,
1115 sizeof(struct e1000_buffer),
1116 GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 ret_val = 4;
1118 goto err_nomem;
1119 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
1121 rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001122 if (!(rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 ret_val = 5;
1124 goto err_nomem;
1125 }
1126 memset(rxdr->desc, 0, rxdr->size);
1127 rxdr->next_to_use = rxdr->next_to_clean = 0;
1128
Joe Perches1dc32912008-07-11 15:17:08 -07001129 rctl = er32(RCTL);
1130 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Joe Perchese982f172008-07-11 15:17:18 -07001131 ew32(RDBAL, ((u64)rxdr->dma & 0xFFFFFFFF));
1132 ew32(RDBAH, ((u64)rxdr->dma >> 32));
Joe Perches1dc32912008-07-11 15:17:08 -07001133 ew32(RDLEN, rxdr->size);
1134 ew32(RDH, 0);
1135 ew32(RDT, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
1137 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
Joe Perches1dc32912008-07-11 15:17:08 -07001138 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
1139 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001141 for (i = 0; i < rxdr->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i);
1143 struct sk_buff *skb;
1144
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001145 if (!(skb = alloc_skb(E1000_RXBUFFER_2048 + NET_IP_ALIGN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 GFP_KERNEL))) {
1147 ret_val = 6;
1148 goto err_nomem;
1149 }
1150 skb_reserve(skb, NET_IP_ALIGN);
1151 rxdr->buffer_info[i].skb = skb;
1152 rxdr->buffer_info[i].length = E1000_RXBUFFER_2048;
1153 rxdr->buffer_info[i].dma =
1154 pci_map_single(pdev, skb->data, E1000_RXBUFFER_2048,
1155 PCI_DMA_FROMDEVICE);
1156 rx_desc->buffer_addr = cpu_to_le64(rxdr->buffer_info[i].dma);
1157 memset(skb->data, 0x00, skb->len);
1158 }
1159
1160 return 0;
1161
1162err_nomem:
1163 e1000_free_desc_rings(adapter);
1164 return ret_val;
1165}
1166
Joe Perches64798842008-07-11 15:17:02 -07001167static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168{
Joe Perches1dc32912008-07-11 15:17:08 -07001169 struct e1000_hw *hw = &adapter->hw;
1170
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
Joe Perches1dc32912008-07-11 15:17:08 -07001172 e1000_write_phy_reg(hw, 29, 0x001F);
1173 e1000_write_phy_reg(hw, 30, 0x8FFC);
1174 e1000_write_phy_reg(hw, 29, 0x001A);
1175 e1000_write_phy_reg(hw, 30, 0x8FF0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176}
1177
Joe Perches64798842008-07-11 15:17:02 -07001178static void e1000_phy_reset_clk_and_crs(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179{
Joe Perches1dc32912008-07-11 15:17:08 -07001180 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001181 u16 phy_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
1183 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1184 * Extended PHY Specific Control Register to 25MHz clock. This
1185 * value defaults back to a 2.5MHz clock when the PHY is reset.
1186 */
Joe Perches1dc32912008-07-11 15:17:08 -07001187 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 phy_reg |= M88E1000_EPSCR_TX_CLK_25;
Joe Perches1dc32912008-07-11 15:17:08 -07001189 e1000_write_phy_reg(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 M88E1000_EXT_PHY_SPEC_CTRL, phy_reg);
1191
1192 /* In addition, because of the s/w reset above, we need to enable
1193 * CRS on TX. This must be set for both full and half duplex
1194 * operation.
1195 */
Joe Perches1dc32912008-07-11 15:17:08 -07001196 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 phy_reg |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Joe Perches1dc32912008-07-11 15:17:08 -07001198 e1000_write_phy_reg(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 M88E1000_PHY_SPEC_CTRL, phy_reg);
1200}
1201
Joe Perches64798842008-07-11 15:17:02 -07001202static int e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203{
Joe Perches1dc32912008-07-11 15:17:08 -07001204 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001205 u32 ctrl_reg;
1206 u16 phy_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
1208 /* Setup the Device Control Register for PHY loopback test. */
1209
Joe Perches1dc32912008-07-11 15:17:08 -07001210 ctrl_reg = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 ctrl_reg |= (E1000_CTRL_ILOS | /* Invert Loss-Of-Signal */
1212 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1213 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1214 E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */
1215 E1000_CTRL_FD); /* Force Duplex to FULL */
1216
Joe Perches1dc32912008-07-11 15:17:08 -07001217 ew32(CTRL, ctrl_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
1219 /* Read the PHY Specific Control Register (0x10) */
Joe Perches1dc32912008-07-11 15:17:08 -07001220 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
1222 /* Clear Auto-Crossover bits in PHY Specific Control Register
1223 * (bits 6:5).
1224 */
1225 phy_reg &= ~M88E1000_PSCR_AUTO_X_MODE;
Joe Perches1dc32912008-07-11 15:17:08 -07001226 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
1228 /* Perform software reset on the PHY */
Joe Perches1dc32912008-07-11 15:17:08 -07001229 e1000_phy_reset(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
1231 /* Have to setup TX_CLK and TX_CRS after software reset */
1232 e1000_phy_reset_clk_and_crs(adapter);
1233
Joe Perches1dc32912008-07-11 15:17:08 -07001234 e1000_write_phy_reg(hw, PHY_CTRL, 0x8100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
1236 /* Wait for reset to complete. */
1237 udelay(500);
1238
1239 /* Have to setup TX_CLK and TX_CRS after software reset */
1240 e1000_phy_reset_clk_and_crs(adapter);
1241
1242 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1243 e1000_phy_disable_receiver(adapter);
1244
1245 /* Set the loopback bit in the PHY control register. */
Joe Perches1dc32912008-07-11 15:17:08 -07001246 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 phy_reg |= MII_CR_LOOPBACK;
Joe Perches1dc32912008-07-11 15:17:08 -07001248 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
1250 /* Setup TX_CLK and TX_CRS one more time. */
1251 e1000_phy_reset_clk_and_crs(adapter);
1252
1253 /* Check Phy Configuration */
Joe Perches1dc32912008-07-11 15:17:08 -07001254 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001255 if (phy_reg != 0x4100)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 return 9;
1257
Joe Perches1dc32912008-07-11 15:17:08 -07001258 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001259 if (phy_reg != 0x0070)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 return 10;
1261
Joe Perches1dc32912008-07-11 15:17:08 -07001262 e1000_read_phy_reg(hw, 29, &phy_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001263 if (phy_reg != 0x001A)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 return 11;
1265
1266 return 0;
1267}
1268
Joe Perches64798842008-07-11 15:17:02 -07001269static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270{
Joe Perches1dc32912008-07-11 15:17:08 -07001271 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001272 u32 ctrl_reg = 0;
1273 u32 stat_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
Joe Perches1dc32912008-07-11 15:17:08 -07001275 hw->autoneg = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
Joe Perches1dc32912008-07-11 15:17:08 -07001277 if (hw->phy_type == e1000_phy_m88) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 /* Auto-MDI/MDIX Off */
Joe Perches1dc32912008-07-11 15:17:08 -07001279 e1000_write_phy_reg(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 M88E1000_PHY_SPEC_CTRL, 0x0808);
1281 /* reset to update Auto-MDI/MDIX */
Joe Perches1dc32912008-07-11 15:17:08 -07001282 e1000_write_phy_reg(hw, PHY_CTRL, 0x9140);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 /* autoneg off */
Joe Perches1dc32912008-07-11 15:17:08 -07001284 e1000_write_phy_reg(hw, PHY_CTRL, 0x8140);
1285 } else if (hw->phy_type == e1000_phy_gg82563)
1286 e1000_write_phy_reg(hw,
Jeff Kirsher87041632006-03-02 18:21:24 -08001287 GG82563_PHY_KMRN_MODE_CTRL,
Auke Kokacfbc9f2006-06-27 09:06:24 -07001288 0x1CC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
Joe Perches1dc32912008-07-11 15:17:08 -07001290 ctrl_reg = er32(CTRL);
Auke Kokcd94dd02006-06-27 09:08:22 -07001291
Joe Perches1dc32912008-07-11 15:17:08 -07001292 if (hw->phy_type == e1000_phy_ife) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001293 /* force 100, set loopback */
Joe Perches1dc32912008-07-11 15:17:08 -07001294 e1000_write_phy_reg(hw, PHY_CTRL, 0x6100);
Auke Kokcd94dd02006-06-27 09:08:22 -07001295
1296 /* Now set up the MAC to the same speed/duplex as the PHY. */
1297 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1298 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1299 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1300 E1000_CTRL_SPD_100 |/* Force Speed to 100 */
1301 E1000_CTRL_FD); /* Force Duplex to FULL */
1302 } else {
1303 /* force 1000, set loopback */
Joe Perches1dc32912008-07-11 15:17:08 -07001304 e1000_write_phy_reg(hw, PHY_CTRL, 0x4140);
Auke Kokcd94dd02006-06-27 09:08:22 -07001305
1306 /* Now set up the MAC to the same speed/duplex as the PHY. */
Joe Perches1dc32912008-07-11 15:17:08 -07001307 ctrl_reg = er32(CTRL);
Auke Kokcd94dd02006-06-27 09:08:22 -07001308 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1309 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1310 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1311 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1312 E1000_CTRL_FD); /* Force Duplex to FULL */
1313 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Joe Perches1dc32912008-07-11 15:17:08 -07001315 if (hw->media_type == e1000_media_type_copper &&
1316 hw->phy_type == e1000_phy_m88)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
Auke Kok8fc897b2006-08-28 14:56:16 -07001318 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 /* Set the ILOS bit on the fiber Nic is half
1320 * duplex link is detected. */
Joe Perches1dc32912008-07-11 15:17:08 -07001321 stat_reg = er32(STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001322 if ((stat_reg & E1000_STATUS_FD) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1324 }
1325
Joe Perches1dc32912008-07-11 15:17:08 -07001326 ew32(CTRL, ctrl_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
1328 /* Disable the receiver on the PHY so when a cable is plugged in, the
1329 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1330 */
Joe Perches1dc32912008-07-11 15:17:08 -07001331 if (hw->phy_type == e1000_phy_m88)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 e1000_phy_disable_receiver(adapter);
1333
1334 udelay(500);
1335
1336 return 0;
1337}
1338
Joe Perches64798842008-07-11 15:17:02 -07001339static int e1000_set_phy_loopback(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340{
Joe Perches1dc32912008-07-11 15:17:08 -07001341 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001342 u16 phy_reg = 0;
1343 u16 count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
Joe Perches1dc32912008-07-11 15:17:08 -07001345 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 case e1000_82543:
Joe Perches1dc32912008-07-11 15:17:08 -07001347 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 /* Attempt to setup Loopback mode on Non-integrated PHY.
1349 * Some PHY registers get corrupted at random, so
1350 * attempt this 10 times.
1351 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001352 while (e1000_nonintegrated_phy_loopback(adapter) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 count++ < 10);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001354 if (count < 11)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 return 0;
1356 }
1357 break;
1358
1359 case e1000_82544:
1360 case e1000_82540:
1361 case e1000_82545:
1362 case e1000_82545_rev_3:
1363 case e1000_82546:
1364 case e1000_82546_rev_3:
1365 case e1000_82541:
1366 case e1000_82541_rev_2:
1367 case e1000_82547:
1368 case e1000_82547_rev_2:
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -04001369 case e1000_82571:
1370 case e1000_82572:
Malli Chilakala45643272005-06-17 17:42:42 -07001371 case e1000_82573:
Jeff Kirsher6418ecc2006-03-02 18:21:10 -08001372 case e1000_80003es2lan:
Auke Kokcd94dd02006-06-27 09:08:22 -07001373 case e1000_ich8lan:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 return e1000_integrated_phy_loopback(adapter);
1375 break;
1376
1377 default:
1378 /* Default PHY loopback work is to read the MII
1379 * control register and assert bit 14 (loopback mode).
1380 */
Joe Perches1dc32912008-07-11 15:17:08 -07001381 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 phy_reg |= MII_CR_LOOPBACK;
Joe Perches1dc32912008-07-11 15:17:08 -07001383 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 return 0;
1385 break;
1386 }
1387
1388 return 8;
1389}
1390
Joe Perches64798842008-07-11 15:17:02 -07001391static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392{
Jeff Kirsher49273162006-01-12 16:50:44 -08001393 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001394 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
Jeff Kirsher49273162006-01-12 16:50:44 -08001396 if (hw->media_type == e1000_media_type_fiber ||
1397 hw->media_type == e1000_media_type_internal_serdes) {
1398 switch (hw->mac_type) {
1399 case e1000_82545:
1400 case e1000_82546:
1401 case e1000_82545_rev_3:
1402 case e1000_82546_rev_3:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 return e1000_set_phy_loopback(adapter);
Jeff Kirsher49273162006-01-12 16:50:44 -08001404 break;
1405 case e1000_82571:
1406 case e1000_82572:
1407#define E1000_SERDES_LB_ON 0x410
1408 e1000_set_phy_loopback(adapter);
Joe Perches1dc32912008-07-11 15:17:08 -07001409 ew32(SCTL, E1000_SERDES_LB_ON);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001410 msleep(10);
Jeff Kirsher49273162006-01-12 16:50:44 -08001411 return 0;
1412 break;
1413 default:
Joe Perches1dc32912008-07-11 15:17:08 -07001414 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 rctl |= E1000_RCTL_LBM_TCVR;
Joe Perches1dc32912008-07-11 15:17:08 -07001416 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 return 0;
1418 }
Jeff Kirsher49273162006-01-12 16:50:44 -08001419 } else if (hw->media_type == e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 return e1000_set_phy_loopback(adapter);
1421
1422 return 7;
1423}
1424
Joe Perches64798842008-07-11 15:17:02 -07001425static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426{
Jeff Kirsher49273162006-01-12 16:50:44 -08001427 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001428 u32 rctl;
1429 u16 phy_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
Joe Perches1dc32912008-07-11 15:17:08 -07001431 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
Joe Perches1dc32912008-07-11 15:17:08 -07001433 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
Jeff Kirsher49273162006-01-12 16:50:44 -08001435 switch (hw->mac_type) {
1436 case e1000_82571:
1437 case e1000_82572:
1438 if (hw->media_type == e1000_media_type_fiber ||
1439 hw->media_type == e1000_media_type_internal_serdes) {
1440#define E1000_SERDES_LB_OFF 0x400
Joe Perches1dc32912008-07-11 15:17:08 -07001441 ew32(SCTL, E1000_SERDES_LB_OFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001442 msleep(10);
Jeff Kirsher49273162006-01-12 16:50:44 -08001443 break;
Jeff Kirsherfd803242005-12-13 00:06:22 -05001444 }
Jeff Kirsher49273162006-01-12 16:50:44 -08001445 /* Fall Through */
1446 case e1000_82545:
1447 case e1000_82546:
1448 case e1000_82545_rev_3:
1449 case e1000_82546_rev_3:
1450 default:
Joe Perchesc3033b02008-03-21 11:06:25 -07001451 hw->autoneg = true;
Auke Kok8fc897b2006-08-28 14:56:16 -07001452 if (hw->phy_type == e1000_phy_gg82563)
Jeff Kirsher87041632006-03-02 18:21:24 -08001453 e1000_write_phy_reg(hw,
1454 GG82563_PHY_KMRN_MODE_CTRL,
1455 0x180);
Jeff Kirsher49273162006-01-12 16:50:44 -08001456 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
1457 if (phy_reg & MII_CR_LOOPBACK) {
1458 phy_reg &= ~MII_CR_LOOPBACK;
1459 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
1460 e1000_phy_reset(hw);
1461 }
1462 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 }
1464}
1465
Joe Perches64798842008-07-11 15:17:02 -07001466static void e1000_create_lbtest_frame(struct sk_buff *skb,
1467 unsigned int frame_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468{
1469 memset(skb->data, 0xFF, frame_size);
Jeff Kirsherce7393b2006-01-12 16:51:12 -08001470 frame_size &= ~1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1472 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1473 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1474}
1475
Joe Perches64798842008-07-11 15:17:02 -07001476static int e1000_check_lbtest_frame(struct sk_buff *skb,
1477 unsigned int frame_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478{
Jeff Kirsherce7393b2006-01-12 16:51:12 -08001479 frame_size &= ~1;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001480 if (*(skb->data + 3) == 0xFF) {
1481 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
1483 return 0;
1484 }
1485 }
1486 return 13;
1487}
1488
Joe Perches64798842008-07-11 15:17:02 -07001489static int e1000_run_loopback_test(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490{
Joe Perches1dc32912008-07-11 15:17:08 -07001491 struct e1000_hw *hw = &adapter->hw;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001492 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1493 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 struct pci_dev *pdev = adapter->pdev;
Malli Chilakalae4eff722005-04-28 19:38:30 -07001495 int i, j, k, l, lc, good_cnt, ret_val=0;
1496 unsigned long time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
Joe Perches1dc32912008-07-11 15:17:08 -07001498 ew32(RDT, rxdr->count - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001500 /* Calculate the loop count based on the largest descriptor ring
Malli Chilakalae4eff722005-04-28 19:38:30 -07001501 * The idea is to wrap the largest ring a number of times using 64
1502 * send/receive pairs during each loop
1503 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001505 if (rxdr->count <= txdr->count)
Malli Chilakalae4eff722005-04-28 19:38:30 -07001506 lc = ((txdr->count / 64) * 2) + 1;
1507 else
1508 lc = ((rxdr->count / 64) * 2) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
Malli Chilakalae4eff722005-04-28 19:38:30 -07001510 k = l = 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001511 for (j = 0; j <= lc; j++) { /* loop count loop */
1512 for (i = 0; i < 64; i++) { /* send the packets */
1513 e1000_create_lbtest_frame(txdr->buffer_info[i].skb,
Malli Chilakalae4eff722005-04-28 19:38:30 -07001514 1024);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001515 pci_dma_sync_single_for_device(pdev,
Malli Chilakalae4eff722005-04-28 19:38:30 -07001516 txdr->buffer_info[k].dma,
1517 txdr->buffer_info[k].length,
1518 PCI_DMA_TODEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001519 if (unlikely(++k == txdr->count)) k = 0;
Malli Chilakalae4eff722005-04-28 19:38:30 -07001520 }
Joe Perches1dc32912008-07-11 15:17:08 -07001521 ew32(TDT, k);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001522 msleep(200);
Malli Chilakalae4eff722005-04-28 19:38:30 -07001523 time = jiffies; /* set the start time for the receive */
1524 good_cnt = 0;
1525 do { /* receive the sent packets */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001526 pci_dma_sync_single_for_cpu(pdev,
Malli Chilakalae4eff722005-04-28 19:38:30 -07001527 rxdr->buffer_info[l].dma,
1528 rxdr->buffer_info[l].length,
1529 PCI_DMA_FROMDEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001530
Malli Chilakalae4eff722005-04-28 19:38:30 -07001531 ret_val = e1000_check_lbtest_frame(
1532 rxdr->buffer_info[l].skb,
1533 1024);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001534 if (!ret_val)
Malli Chilakalae4eff722005-04-28 19:38:30 -07001535 good_cnt++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001536 if (unlikely(++l == rxdr->count)) l = 0;
1537 /* time + 20 msecs (200 msecs on 2.4) is more than
1538 * enough time to complete the receives, if it's
Malli Chilakalae4eff722005-04-28 19:38:30 -07001539 * exceeded, break and error off
1540 */
1541 } while (good_cnt < 64 && jiffies < (time + 20));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001542 if (good_cnt != 64) {
Malli Chilakalae4eff722005-04-28 19:38:30 -07001543 ret_val = 13; /* ret_val is the same as mis-compare */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001544 break;
Malli Chilakalae4eff722005-04-28 19:38:30 -07001545 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001546 if (jiffies >= (time + 2)) {
Malli Chilakalae4eff722005-04-28 19:38:30 -07001547 ret_val = 14; /* error code for time out error */
1548 break;
1549 }
1550 } /* end loop count loop */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 return ret_val;
1552}
1553
Joe Perches64798842008-07-11 15:17:02 -07001554static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555{
Joe Perches1dc32912008-07-11 15:17:08 -07001556 struct e1000_hw *hw = &adapter->hw;
1557
Jeff Kirsher57128192006-01-12 16:50:28 -08001558 /* PHY loopback cannot be performed if SoL/IDER
1559 * sessions are active */
Joe Perches1dc32912008-07-11 15:17:08 -07001560 if (e1000_check_phy_reset_block(hw)) {
Jeff Kirsher57128192006-01-12 16:50:28 -08001561 DPRINTK(DRV, ERR, "Cannot do PHY loopback test "
1562 "when SoL/IDER is active.\n");
1563 *data = 0;
1564 goto out;
1565 }
1566
1567 if ((*data = e1000_setup_desc_rings(adapter)))
1568 goto out;
1569 if ((*data = e1000_setup_loopback_test(adapter)))
1570 goto err_loopback;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 *data = e1000_run_loopback_test(adapter);
1572 e1000_loopback_cleanup(adapter);
Jeff Kirsher57128192006-01-12 16:50:28 -08001573
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574err_loopback:
Jeff Kirsher57128192006-01-12 16:50:28 -08001575 e1000_free_desc_rings(adapter);
1576out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 return *data;
1578}
1579
Joe Perches64798842008-07-11 15:17:02 -07001580static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581{
Joe Perches1dc32912008-07-11 15:17:08 -07001582 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 *data = 0;
Joe Perches1dc32912008-07-11 15:17:08 -07001584 if (hw->media_type == e1000_media_type_internal_serdes) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 int i = 0;
Joe Perches1dc32912008-07-11 15:17:08 -07001586 hw->serdes_link_down = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
Malli Chilakala26483452005-04-28 19:44:46 -07001588 /* On some blade server designs, link establishment
1589 * could take as long as 2-3 minutes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 do {
Joe Perches1dc32912008-07-11 15:17:08 -07001591 e1000_check_for_link(hw);
1592 if (!hw->serdes_link_down)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 return *data;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001594 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 } while (i++ < 3750);
1596
Malli Chilakala26483452005-04-28 19:44:46 -07001597 *data = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 } else {
Joe Perches1dc32912008-07-11 15:17:08 -07001599 e1000_check_for_link(hw);
1600 if (hw->autoneg) /* if auto_neg is set wait for it */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001601 msleep(4000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602
Joe Perches1dc32912008-07-11 15:17:08 -07001603 if (!(er32(STATUS) & E1000_STATUS_LU)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 *data = 1;
1605 }
1606 }
1607 return *data;
1608}
1609
Joe Perches64798842008-07-11 15:17:02 -07001610static int e1000_get_sset_count(struct net_device *netdev, int sset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001612 switch (sset) {
1613 case ETH_SS_TEST:
1614 return E1000_TEST_LEN;
1615 case ETH_SS_STATS:
1616 return E1000_STATS_LEN;
1617 default:
1618 return -EOPNOTSUPP;
1619 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620}
1621
Joe Perches64798842008-07-11 15:17:02 -07001622static void e1000_diag_test(struct net_device *netdev,
1623 struct ethtool_test *eth_test, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001625 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001626 struct e1000_hw *hw = &adapter->hw;
Joe Perchesc3033b02008-03-21 11:06:25 -07001627 bool if_running = netif_running(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628
Auke Kok1314bbf2006-09-27 12:54:02 -07001629 set_bit(__E1000_TESTING, &adapter->flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001630 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 /* Offline tests */
1632
1633 /* save speed, duplex, autoneg settings */
Joe Perches1dc32912008-07-11 15:17:08 -07001634 u16 autoneg_advertised = hw->autoneg_advertised;
1635 u8 forced_speed_duplex = hw->forced_speed_duplex;
1636 u8 autoneg = hw->autoneg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
Jesse Brandeburgd6582662006-08-16 13:31:33 -07001638 DPRINTK(HW, INFO, "offline testing starting\n");
1639
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 /* Link test performed before hardware reset so autoneg doesn't
1641 * interfere with test result */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001642 if (e1000_link_test(adapter, &data[4]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 eth_test->flags |= ETH_TEST_FL_FAILED;
1644
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001645 if (if_running)
Auke Kok2db10a02006-06-27 09:06:28 -07001646 /* indicate we're in test mode */
1647 dev_close(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 else
1649 e1000_reset(adapter);
1650
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001651 if (e1000_reg_test(adapter, &data[0]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 eth_test->flags |= ETH_TEST_FL_FAILED;
1653
1654 e1000_reset(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001655 if (e1000_eeprom_test(adapter, &data[1]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 eth_test->flags |= ETH_TEST_FL_FAILED;
1657
1658 e1000_reset(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001659 if (e1000_intr_test(adapter, &data[2]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 eth_test->flags |= ETH_TEST_FL_FAILED;
1661
1662 e1000_reset(adapter);
Jesse Brandeburgd6582662006-08-16 13:31:33 -07001663 /* make sure the phy is powered up */
1664 e1000_power_up_phy(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001665 if (e1000_loopback_test(adapter, &data[3]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 eth_test->flags |= ETH_TEST_FL_FAILED;
1667
1668 /* restore speed, duplex, autoneg settings */
Joe Perches1dc32912008-07-11 15:17:08 -07001669 hw->autoneg_advertised = autoneg_advertised;
1670 hw->forced_speed_duplex = forced_speed_duplex;
1671 hw->autoneg = autoneg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
1673 e1000_reset(adapter);
Auke Kok1314bbf2006-09-27 12:54:02 -07001674 clear_bit(__E1000_TESTING, &adapter->flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001675 if (if_running)
Auke Kok2db10a02006-06-27 09:06:28 -07001676 dev_open(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 } else {
Jesse Brandeburgd6582662006-08-16 13:31:33 -07001678 DPRINTK(HW, INFO, "online testing starting\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 /* Online tests */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001680 if (e1000_link_test(adapter, &data[4]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 eth_test->flags |= ETH_TEST_FL_FAILED;
1682
Auke Kok90fb5132006-11-01 08:47:30 -08001683 /* Online tests aren't run; pass by default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 data[0] = 0;
1685 data[1] = 0;
1686 data[2] = 0;
1687 data[3] = 0;
Auke Kok2db10a02006-06-27 09:06:28 -07001688
Auke Kok1314bbf2006-09-27 12:54:02 -07001689 clear_bit(__E1000_TESTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 }
Mallikarjuna R Chilakala352c9f82005-10-04 07:07:24 -04001691 msleep_interruptible(4 * 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692}
1693
Joe Perches64798842008-07-11 15:17:02 -07001694static int e1000_wol_exclusion(struct e1000_adapter *adapter,
1695 struct ethtool_wolinfo *wol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001698 int retval = 1; /* fail by default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001700 switch (hw->device_id) {
Auke Kokdc1f71f2006-10-24 14:45:55 -07001701 case E1000_DEV_ID_82542:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 case E1000_DEV_ID_82543GC_FIBER:
1703 case E1000_DEV_ID_82543GC_COPPER:
1704 case E1000_DEV_ID_82544EI_FIBER:
1705 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1706 case E1000_DEV_ID_82545EM_FIBER:
1707 case E1000_DEV_ID_82545EM_COPPER:
Jeff Kirsher84916822006-03-02 18:18:48 -08001708 case E1000_DEV_ID_82546GB_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001709 case E1000_DEV_ID_82546GB_PCIE:
Auke Kokce57a022007-08-09 14:09:34 -07001710 case E1000_DEV_ID_82571EB_SERDES_QUAD:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001711 /* these don't support WoL at all */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 wol->supported = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001713 break;
1714 case E1000_DEV_ID_82546EB_FIBER:
1715 case E1000_DEV_ID_82546GB_FIBER:
1716 case E1000_DEV_ID_82571EB_FIBER:
1717 case E1000_DEV_ID_82571EB_SERDES:
1718 case E1000_DEV_ID_82571EB_COPPER:
1719 /* Wake events not supported on port B */
Joe Perches1dc32912008-07-11 15:17:08 -07001720 if (er32(STATUS) & E1000_STATUS_FUNC_1) {
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001721 wol->supported = 0;
1722 break;
1723 }
1724 /* return success for non excluded adapter ports */
1725 retval = 0;
1726 break;
Jesse Brandeburg5881cde2006-08-31 14:27:47 -07001727 case E1000_DEV_ID_82571EB_QUAD_COPPER:
Auke Kokce57a022007-08-09 14:09:34 -07001728 case E1000_DEV_ID_82571EB_QUAD_FIBER:
Auke Kokfc2307d2006-11-01 08:47:56 -08001729 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
Auke Kokf4ec7f92007-08-30 11:23:58 -07001730 case E1000_DEV_ID_82571PT_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001731 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1732 /* quad port adapters only support WoL on port A */
1733 if (!adapter->quad_port_a) {
1734 wol->supported = 0;
1735 break;
1736 }
1737 /* return success for non excluded adapter ports */
1738 retval = 0;
1739 break;
1740 default:
1741 /* dual port cards only support WoL on port A from now on
1742 * unless it was enabled in the eeprom for port B
1743 * so exclude FUNC_1 ports from having WoL enabled */
Joe Perches1dc32912008-07-11 15:17:08 -07001744 if (er32(STATUS) & E1000_STATUS_FUNC_1 &&
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001745 !adapter->eeprom_wol) {
1746 wol->supported = 0;
1747 break;
1748 }
1749
1750 retval = 0;
1751 }
1752
1753 return retval;
1754}
1755
Joe Perches64798842008-07-11 15:17:02 -07001756static void e1000_get_wol(struct net_device *netdev,
1757 struct ethtool_wolinfo *wol)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001758{
1759 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001760 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001761
1762 wol->supported = WAKE_UCAST | WAKE_MCAST |
1763 WAKE_BCAST | WAKE_MAGIC;
1764 wol->wolopts = 0;
1765
1766 /* this function will set ->supported = 0 and return 1 if wol is not
1767 * supported by this hardware */
1768 if (e1000_wol_exclusion(adapter, wol))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 return;
1770
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001771 /* apply any specific unsupported masks here */
Joe Perches1dc32912008-07-11 15:17:08 -07001772 switch (hw->device_id) {
Jeff Kirsher84916822006-03-02 18:18:48 -08001773 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001774 /* KSP3 does not suppport UCAST wake-ups */
1775 wol->supported &= ~WAKE_UCAST;
Jeff Kirsher84916822006-03-02 18:18:48 -08001776
1777 if (adapter->wol & E1000_WUFC_EX)
1778 DPRINTK(DRV, ERR, "Interface does not support "
1779 "directed (unicast) frame wake-up packets\n");
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001780 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 default:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001782 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 }
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001784
1785 if (adapter->wol & E1000_WUFC_EX)
1786 wol->wolopts |= WAKE_UCAST;
1787 if (adapter->wol & E1000_WUFC_MC)
1788 wol->wolopts |= WAKE_MCAST;
1789 if (adapter->wol & E1000_WUFC_BC)
1790 wol->wolopts |= WAKE_BCAST;
1791 if (adapter->wol & E1000_WUFC_MAG)
1792 wol->wolopts |= WAKE_MAGIC;
1793
1794 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795}
1796
Joe Perches64798842008-07-11 15:17:02 -07001797static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001799 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 struct e1000_hw *hw = &adapter->hw;
1801
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001802 if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
1803 return -EOPNOTSUPP;
1804
1805 if (e1000_wol_exclusion(adapter, wol))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 return wol->wolopts ? -EOPNOTSUPP : 0;
1807
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001808 switch (hw->device_id) {
Jeff Kirsher84916822006-03-02 18:18:48 -08001809 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jeff Kirsher84916822006-03-02 18:18:48 -08001810 if (wol->wolopts & WAKE_UCAST) {
1811 DPRINTK(DRV, ERR, "Interface does not support "
1812 "directed (unicast) frame wake-up packets\n");
1813 return -EOPNOTSUPP;
1814 }
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001815 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 default:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001817 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 }
1819
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001820 /* these settings will always override what we currently have */
1821 adapter->wol = 0;
1822
1823 if (wol->wolopts & WAKE_UCAST)
1824 adapter->wol |= E1000_WUFC_EX;
1825 if (wol->wolopts & WAKE_MCAST)
1826 adapter->wol |= E1000_WUFC_MC;
1827 if (wol->wolopts & WAKE_BCAST)
1828 adapter->wol |= E1000_WUFC_BC;
1829 if (wol->wolopts & WAKE_MAGIC)
1830 adapter->wol |= E1000_WUFC_MAG;
1831
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 return 0;
1833}
1834
1835/* toggle LED 4 times per second = 2 "blinks" per second */
1836#define E1000_ID_INTERVAL (HZ/4)
1837
1838/* bit defines for adapter->led_status */
1839#define E1000_LED_ON 0
1840
Joe Perches64798842008-07-11 15:17:02 -07001841static void e1000_led_blink_callback(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842{
1843 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Joe Perches1dc32912008-07-11 15:17:08 -07001844 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001846 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
Joe Perches1dc32912008-07-11 15:17:08 -07001847 e1000_led_off(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 else
Joe Perches1dc32912008-07-11 15:17:08 -07001849 e1000_led_on(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850
1851 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1852}
1853
Joe Perches64798842008-07-11 15:17:02 -07001854static int e1000_phys_id(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001856 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001857 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
Stephen Hemmingerabec42a2007-10-29 10:46:19 -07001859 if (!data)
1860 data = INT_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861
Joe Perches1dc32912008-07-11 15:17:08 -07001862 if (hw->mac_type < e1000_82571) {
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001863 if (!adapter->blink_timer.function) {
Malli Chilakalad439d4b2005-06-17 17:43:56 -07001864 init_timer(&adapter->blink_timer);
1865 adapter->blink_timer.function = e1000_led_blink_callback;
Joe Perchese982f172008-07-11 15:17:18 -07001866 adapter->blink_timer.data = (unsigned long)adapter;
Malli Chilakalad439d4b2005-06-17 17:43:56 -07001867 }
Joe Perches1dc32912008-07-11 15:17:08 -07001868 e1000_setup_led(hw);
Malli Chilakalad439d4b2005-06-17 17:43:56 -07001869 mod_timer(&adapter->blink_timer, jiffies);
1870 msleep_interruptible(data * 1000);
1871 del_timer_sync(&adapter->blink_timer);
Joe Perches1dc32912008-07-11 15:17:08 -07001872 } else if (hw->phy_type == e1000_phy_ife) {
Auke Kokcd94dd02006-06-27 09:08:22 -07001873 if (!adapter->blink_timer.function) {
1874 init_timer(&adapter->blink_timer);
1875 adapter->blink_timer.function = e1000_led_blink_callback;
Joe Perchese982f172008-07-11 15:17:18 -07001876 adapter->blink_timer.data = (unsigned long)adapter;
Auke Kokcd94dd02006-06-27 09:08:22 -07001877 }
1878 mod_timer(&adapter->blink_timer, jiffies);
Jeff Kirsherd8c2bd32006-01-12 16:50:37 -08001879 msleep_interruptible(data * 1000);
Auke Kokcd94dd02006-06-27 09:08:22 -07001880 del_timer_sync(&adapter->blink_timer);
1881 e1000_write_phy_reg(&(adapter->hw), IFE_PHY_SPECIAL_CONTROL_LED, 0);
Jeff Kirsherd8c2bd32006-01-12 16:50:37 -08001882 } else {
Joe Perches1dc32912008-07-11 15:17:08 -07001883 e1000_blink_led_start(hw);
Malli Chilakalad439d4b2005-06-17 17:43:56 -07001884 msleep_interruptible(data * 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 }
1886
Joe Perches1dc32912008-07-11 15:17:08 -07001887 e1000_led_off(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 clear_bit(E1000_LED_ON, &adapter->led_status);
Joe Perches1dc32912008-07-11 15:17:08 -07001889 e1000_cleanup_led(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890
1891 return 0;
1892}
1893
Joe Perches64798842008-07-11 15:17:02 -07001894static int e1000_nway_reset(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001896 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kok2db10a02006-06-27 09:06:28 -07001897 if (netif_running(netdev))
1898 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 return 0;
1900}
1901
Joe Perches64798842008-07-11 15:17:02 -07001902static void e1000_get_ethtool_stats(struct net_device *netdev,
1903 struct ethtool_stats *stats, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001905 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 int i;
1907
1908 e1000_update_stats(adapter);
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001909 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1910 char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
1911 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
Joe Perches406874a2008-04-03 10:06:32 -07001912 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001914/* BUG_ON(i != E1000_STATS_LEN); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915}
1916
Joe Perches64798842008-07-11 15:17:02 -07001917static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1918 u8 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919{
Joe Perches406874a2008-04-03 10:06:32 -07001920 u8 *p = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 int i;
1922
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001923 switch (stringset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 case ETH_SS_TEST:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001925 memcpy(data, *e1000_gstrings_test,
Roel Kluinc32bc6e2007-12-05 11:57:30 -08001926 sizeof(e1000_gstrings_test));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 break;
1928 case ETH_SS_STATS:
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001929 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1930 memcpy(p, e1000_gstrings_stats[i].stat_string,
1931 ETH_GSTRING_LEN);
1932 p += ETH_GSTRING_LEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001934/* BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 break;
1936 }
1937}
1938
Jeff Garzik7282d492006-09-13 14:30:00 -04001939static const struct ethtool_ops e1000_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 .get_settings = e1000_get_settings,
1941 .set_settings = e1000_set_settings,
1942 .get_drvinfo = e1000_get_drvinfo,
1943 .get_regs_len = e1000_get_regs_len,
1944 .get_regs = e1000_get_regs,
1945 .get_wol = e1000_get_wol,
1946 .set_wol = e1000_set_wol,
Auke Kok8fc897b2006-08-28 14:56:16 -07001947 .get_msglevel = e1000_get_msglevel,
1948 .set_msglevel = e1000_set_msglevel,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 .nway_reset = e1000_nway_reset,
1950 .get_link = ethtool_op_get_link,
1951 .get_eeprom_len = e1000_get_eeprom_len,
1952 .get_eeprom = e1000_get_eeprom,
1953 .set_eeprom = e1000_set_eeprom,
1954 .get_ringparam = e1000_get_ringparam,
1955 .set_ringparam = e1000_set_ringparam,
Auke Kok8fc897b2006-08-28 14:56:16 -07001956 .get_pauseparam = e1000_get_pauseparam,
1957 .set_pauseparam = e1000_set_pauseparam,
1958 .get_rx_csum = e1000_get_rx_csum,
1959 .set_rx_csum = e1000_set_rx_csum,
1960 .get_tx_csum = e1000_get_tx_csum,
1961 .set_tx_csum = e1000_set_tx_csum,
Auke Kok8fc897b2006-08-28 14:56:16 -07001962 .set_sg = ethtool_op_set_sg,
Auke Kok8fc897b2006-08-28 14:56:16 -07001963 .set_tso = e1000_set_tso,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 .self_test = e1000_diag_test,
1965 .get_strings = e1000_get_strings,
1966 .phys_id = e1000_phys_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 .get_ethtool_stats = e1000_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001968 .get_sset_count = e1000_get_sset_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969};
1970
1971void e1000_set_ethtool_ops(struct net_device *netdev)
1972{
1973 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
1974}