blob: e25b339eb5bd9538ab9cd11ecb6651e97faf4b6a [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)
Ajit Khaparde5fe31de2009-10-07 02:42:23 +000042#define E1000_NETDEV_STAT(m) FIELD_SIZEOF(struct net_device, m), \
43 offsetof(struct net_device, m)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044static const struct e1000_stats e1000_gstrings_stats[] = {
Mitch Williams49559852006-09-27 12:53:37 -070045 { "rx_packets", E1000_STAT(stats.gprc) },
46 { "tx_packets", E1000_STAT(stats.gptc) },
47 { "rx_bytes", E1000_STAT(stats.gorcl) },
48 { "tx_bytes", E1000_STAT(stats.gotcl) },
49 { "rx_broadcast", E1000_STAT(stats.bprc) },
50 { "tx_broadcast", E1000_STAT(stats.bptc) },
51 { "rx_multicast", E1000_STAT(stats.mprc) },
52 { "tx_multicast", E1000_STAT(stats.mptc) },
53 { "rx_errors", E1000_STAT(stats.rxerrc) },
54 { "tx_errors", E1000_STAT(stats.txerrc) },
Ajit Khaparde5fe31de2009-10-07 02:42:23 +000055 { "tx_dropped", E1000_NETDEV_STAT(stats.tx_dropped) },
Mitch Williams49559852006-09-27 12:53:37 -070056 { "multicast", E1000_STAT(stats.mprc) },
57 { "collisions", E1000_STAT(stats.colc) },
58 { "rx_length_errors", E1000_STAT(stats.rlerrc) },
Ajit Khaparde5fe31de2009-10-07 02:42:23 +000059 { "rx_over_errors", E1000_NETDEV_STAT(stats.rx_over_errors) },
Mitch Williams49559852006-09-27 12:53:37 -070060 { "rx_crc_errors", E1000_STAT(stats.crcerrs) },
Ajit Khaparde5fe31de2009-10-07 02:42:23 +000061 { "rx_frame_errors", E1000_NETDEV_STAT(stats.rx_frame_errors) },
Malli Chilakala26483452005-04-28 19:44:46 -070062 { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
Mitch Williams49559852006-09-27 12:53:37 -070063 { "rx_missed_errors", E1000_STAT(stats.mpc) },
64 { "tx_aborted_errors", E1000_STAT(stats.ecol) },
65 { "tx_carrier_errors", E1000_STAT(stats.tncrs) },
Ajit Khaparde5fe31de2009-10-07 02:42:23 +000066 { "tx_fifo_errors", E1000_NETDEV_STAT(stats.tx_fifo_errors) },
67 { "tx_heartbeat_errors", E1000_NETDEV_STAT(stats.tx_heartbeat_errors) },
Mitch Williams49559852006-09-27 12:53:37 -070068 { "tx_window_errors", E1000_STAT(stats.latecol) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
70 { "tx_deferred_ok", E1000_STAT(stats.dc) },
71 { "tx_single_coll_ok", E1000_STAT(stats.scc) },
72 { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
Jeff Kirsher6b7660c2006-01-12 16:50:35 -080073 { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -080074 { "tx_restart_queue", E1000_STAT(restart_queue) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 { "rx_long_length_errors", E1000_STAT(stats.roc) },
76 { "rx_short_length_errors", E1000_STAT(stats.ruc) },
77 { "rx_align_errors", E1000_STAT(stats.algnerrc) },
78 { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
79 { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
80 { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
81 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
82 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
83 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
84 { "rx_long_byte_count", E1000_STAT(stats.gorcl) },
85 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -040086 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
Jeff Kirsher6b7660c2006-01-12 16:50:35 -080087 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
Jeff Garzik15e376b2006-12-15 11:16:33 -050088 { "tx_smbus", E1000_STAT(stats.mgptc) },
89 { "rx_smbus", E1000_STAT(stats.mgprc) },
90 { "dropped_smbus", E1000_STAT(stats.mgpdc) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070091};
Jeff Kirsher7bfa4812006-01-12 16:50:41 -080092
Jeff Kirsher7bfa4812006-01-12 16:50:41 -080093#define E1000_QUEUE_STATS_LEN 0
Denis Chengff8ac602007-09-02 18:30:18 +080094#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Jeff Kirsher7bfa4812006-01-12 16:50:41 -080095#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN + E1000_QUEUE_STATS_LEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
97 "Register test (offline)", "Eeprom test (offline)",
98 "Interrupt test (offline)", "Loopback test (offline)",
99 "Link test (on/offline)"
100};
Alejandro Martinez Ruiz4c3616c2007-10-18 10:00:15 +0200101#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Joe Perches64798842008-07-11 15:17:02 -0700103static int e1000_get_settings(struct net_device *netdev,
104 struct ethtool_cmd *ecmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700106 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 struct e1000_hw *hw = &adapter->hw;
108
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800109 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111 ecmd->supported = (SUPPORTED_10baseT_Half |
112 SUPPORTED_10baseT_Full |
113 SUPPORTED_100baseT_Half |
114 SUPPORTED_100baseT_Full |
115 SUPPORTED_1000baseT_Full|
116 SUPPORTED_Autoneg |
117 SUPPORTED_TP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 ecmd->advertising = ADVERTISED_TP;
119
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800120 if (hw->autoneg == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 ecmd->advertising |= ADVERTISED_Autoneg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 /* the e1000 autoneg seems to match ethtool nicely */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 ecmd->advertising |= hw->autoneg_advertised;
124 }
125
126 ecmd->port = PORT_TP;
127 ecmd->phy_address = hw->phy_addr;
128
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800129 if (hw->mac_type == e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 ecmd->transceiver = XCVR_EXTERNAL;
131 else
132 ecmd->transceiver = XCVR_INTERNAL;
133
134 } else {
135 ecmd->supported = (SUPPORTED_1000baseT_Full |
136 SUPPORTED_FIBRE |
137 SUPPORTED_Autoneg);
138
Malli Chilakala012609a2005-06-17 17:43:06 -0700139 ecmd->advertising = (ADVERTISED_1000baseT_Full |
140 ADVERTISED_FIBRE |
141 ADVERTISED_Autoneg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 ecmd->port = PORT_FIBRE;
144
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800145 if (hw->mac_type >= e1000_82545)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 ecmd->transceiver = XCVR_INTERNAL;
147 else
148 ecmd->transceiver = XCVR_EXTERNAL;
149 }
150
Joe Perches1dc32912008-07-11 15:17:08 -0700151 if (er32(STATUS) & E1000_STATUS_LU) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 e1000_get_speed_and_duplex(hw, &adapter->link_speed,
154 &adapter->link_duplex);
155 ecmd->speed = adapter->link_speed;
156
157 /* unfortunatly FULL_DUPLEX != DUPLEX_FULL
158 * and HALF_DUPLEX != DUPLEX_HALF */
159
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800160 if (adapter->link_duplex == FULL_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 ecmd->duplex = DUPLEX_FULL;
162 else
163 ecmd->duplex = DUPLEX_HALF;
164 } else {
165 ecmd->speed = -1;
166 ecmd->duplex = -1;
167 }
168
169 ecmd->autoneg = ((hw->media_type == e1000_media_type_fiber) ||
170 hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
171 return 0;
172}
173
Joe Perches64798842008-07-11 15:17:02 -0700174static int e1000_set_settings(struct net_device *netdev,
175 struct ethtool_cmd *ecmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700177 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 struct e1000_hw *hw = &adapter->hw;
179
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700180 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
181 msleep(1);
182
Jeff Kirsher57128192006-01-12 16:50:28 -0800183 if (ecmd->autoneg == AUTONEG_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 hw->autoneg = 1;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800185 if (hw->media_type == e1000_media_type_fiber)
Malli Chilakala012609a2005-06-17 17:43:06 -0700186 hw->autoneg_advertised = ADVERTISED_1000baseT_Full |
187 ADVERTISED_FIBRE |
188 ADVERTISED_Autoneg;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800189 else
Jeff Kirsher2f2ca262006-09-27 12:53:40 -0700190 hw->autoneg_advertised = ecmd->advertising |
191 ADVERTISED_TP |
192 ADVERTISED_Autoneg;
Malli Chilakala012609a2005-06-17 17:43:06 -0700193 ecmd->advertising = hw->autoneg_advertised;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 } else
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700195 if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) {
196 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 return -EINVAL;
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700198 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 /* reset the link */
201
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700202 if (netif_running(adapter->netdev)) {
203 e1000_down(adapter);
204 e1000_up(adapter);
205 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 e1000_reset(adapter);
207
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700208 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 return 0;
210}
211
Joe Perches64798842008-07-11 15:17:02 -0700212static void e1000_get_pauseparam(struct net_device *netdev,
213 struct ethtool_pauseparam *pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700215 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 struct e1000_hw *hw = &adapter->hw;
217
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800218 pause->autoneg =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800220
Jeff Kirsher11241b12006-09-27 12:53:28 -0700221 if (hw->fc == E1000_FC_RX_PAUSE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 pause->rx_pause = 1;
Jeff Kirsher11241b12006-09-27 12:53:28 -0700223 else if (hw->fc == E1000_FC_TX_PAUSE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 pause->tx_pause = 1;
Jeff Kirsher11241b12006-09-27 12:53:28 -0700225 else if (hw->fc == E1000_FC_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 pause->rx_pause = 1;
227 pause->tx_pause = 1;
228 }
229}
230
Joe Perches64798842008-07-11 15:17:02 -0700231static int e1000_set_pauseparam(struct net_device *netdev,
232 struct ethtool_pauseparam *pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700234 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700236 int retval = 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 adapter->fc_autoneg = pause->autoneg;
239
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700240 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
241 msleep(1);
242
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800243 if (pause->rx_pause && pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700244 hw->fc = E1000_FC_FULL;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800245 else if (pause->rx_pause && !pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700246 hw->fc = E1000_FC_RX_PAUSE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800247 else if (!pause->rx_pause && pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700248 hw->fc = E1000_FC_TX_PAUSE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800249 else if (!pause->rx_pause && !pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700250 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
252 hw->original_fc = hw->fc;
253
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800254 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700255 if (netif_running(adapter->netdev)) {
256 e1000_down(adapter);
257 e1000_up(adapter);
258 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 e1000_reset(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800260 } else
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700261 retval = ((hw->media_type == e1000_media_type_fiber) ?
Auke Kok90fb5132006-11-01 08:47:30 -0800262 e1000_setup_link(hw) : e1000_force_mac_fc(hw));
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800263
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700264 clear_bit(__E1000_RESETTING, &adapter->flags);
265 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266}
267
Joe Perches64798842008-07-11 15:17:02 -0700268static u32 e1000_get_rx_csum(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700270 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 return adapter->rx_csum;
272}
273
Joe Perches64798842008-07-11 15:17:02 -0700274static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700276 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 adapter->rx_csum = data;
278
Auke Kok2db10a02006-06-27 09:06:28 -0700279 if (netif_running(netdev))
280 e1000_reinit_locked(adapter);
281 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 e1000_reset(adapter);
283 return 0;
284}
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800285
Joe Perches64798842008-07-11 15:17:02 -0700286static u32 e1000_get_tx_csum(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 return (netdev->features & NETIF_F_HW_CSUM) != 0;
289}
290
Joe Perches64798842008-07-11 15:17:02 -0700291static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700293 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700294 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Joe Perches1dc32912008-07-11 15:17:08 -0700296 if (hw->mac_type < e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 if (!data)
298 return -EINVAL;
299 return 0;
300 }
301
302 if (data)
303 netdev->features |= NETIF_F_HW_CSUM;
304 else
305 netdev->features &= ~NETIF_F_HW_CSUM;
306
307 return 0;
308}
309
Joe Perches64798842008-07-11 15:17:02 -0700310static int e1000_set_tso(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700312 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700313 struct e1000_hw *hw = &adapter->hw;
314
315 if ((hw->mac_type < e1000_82544) ||
316 (hw->mac_type == e1000_82547))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 return data ? -EINVAL : 0;
318
319 if (data)
320 netdev->features |= NETIF_F_TSO;
321 else
322 netdev->features &= ~NETIF_F_TSO;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -0800323
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000324 netdev->features &= ~NETIF_F_TSO6;
Auke Kok87ca4e52006-11-01 08:47:36 -0800325
Jeff Kirsher7e6c9862006-03-02 18:19:30 -0800326 DPRINTK(PROBE, INFO, "TSO is %s\n", data ? "Enabled" : "Disabled");
Joe Perchesc3033b02008-03-21 11:06:25 -0700327 adapter->tso_force = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 return 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800329}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Joe Perches64798842008-07-11 15:17:02 -0700331static u32 e1000_get_msglevel(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700333 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 return adapter->msg_enable;
335}
336
Joe Perches64798842008-07-11 15:17:02 -0700337static void e1000_set_msglevel(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700339 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 adapter->msg_enable = data;
341}
342
Joe Perches64798842008-07-11 15:17:02 -0700343static int e1000_get_regs_len(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
345#define E1000_REGS_LEN 32
Joe Perches406874a2008-04-03 10:06:32 -0700346 return E1000_REGS_LEN * sizeof(u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347}
348
Joe Perches64798842008-07-11 15:17:02 -0700349static void e1000_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
350 void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700352 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700354 u32 *regs_buff = p;
355 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Joe Perches406874a2008-04-03 10:06:32 -0700357 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
359 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
360
Joe Perches1dc32912008-07-11 15:17:08 -0700361 regs_buff[0] = er32(CTRL);
362 regs_buff[1] = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Joe Perches1dc32912008-07-11 15:17:08 -0700364 regs_buff[2] = er32(RCTL);
365 regs_buff[3] = er32(RDLEN);
366 regs_buff[4] = er32(RDH);
367 regs_buff[5] = er32(RDT);
368 regs_buff[6] = er32(RDTR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Joe Perches1dc32912008-07-11 15:17:08 -0700370 regs_buff[7] = er32(TCTL);
371 regs_buff[8] = er32(TDLEN);
372 regs_buff[9] = er32(TDH);
373 regs_buff[10] = er32(TDT);
374 regs_buff[11] = er32(TIDV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Joe Perches1dc32912008-07-11 15:17:08 -0700376 regs_buff[12] = hw->phy_type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800377 if (hw->phy_type == e1000_phy_igp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
379 IGP01E1000_PHY_AGC_A);
380 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A &
381 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700382 regs_buff[13] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
384 IGP01E1000_PHY_AGC_B);
385 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B &
386 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700387 regs_buff[14] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
389 IGP01E1000_PHY_AGC_C);
390 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C &
391 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700392 regs_buff[15] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
394 IGP01E1000_PHY_AGC_D);
395 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D &
396 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700397 regs_buff[16] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 regs_buff[17] = 0; /* extended 10bt distance (not needed) */
399 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
400 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS &
401 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700402 regs_buff[18] = (u32)phy_data; /* cable polarity */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
404 IGP01E1000_PHY_PCS_INIT_REG);
405 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG &
406 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700407 regs_buff[19] = (u32)phy_data; /* cable polarity */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 regs_buff[20] = 0; /* polarity correction enabled (always) */
409 regs_buff[22] = 0; /* phy receive errors (unavailable) */
410 regs_buff[23] = regs_buff[18]; /* mdix mode */
411 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
412 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -0700413 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700414 regs_buff[13] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
416 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
417 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
Auke Kok8fc897b2006-08-28 14:56:16 -0700418 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700419 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 regs_buff[18] = regs_buff[13]; /* cable polarity */
421 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
422 regs_buff[20] = regs_buff[17]; /* polarity correction */
423 /* phy receive errors */
424 regs_buff[22] = adapter->phy_stats.receive_errors;
425 regs_buff[23] = regs_buff[13]; /* mdix mode */
426 }
427 regs_buff[21] = adapter->phy_stats.idle_errors; /* phy idle errors */
428 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700429 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800431 if (hw->mac_type >= e1000_82540 &&
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -0700432 hw->media_type == e1000_media_type_copper) {
Joe Perches1dc32912008-07-11 15:17:08 -0700433 regs_buff[26] = er32(MANC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 }
435}
436
Joe Perches64798842008-07-11 15:17:02 -0700437static int e1000_get_eeprom_len(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700439 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700440 struct e1000_hw *hw = &adapter->hw;
441
442 return hw->eeprom.word_size * 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443}
444
Joe Perches64798842008-07-11 15:17:02 -0700445static int e1000_get_eeprom(struct net_device *netdev,
446 struct ethtool_eeprom *eeprom, u8 *bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700448 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700450 u16 *eeprom_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 int first_word, last_word;
452 int ret_val = 0;
Joe Perches406874a2008-04-03 10:06:32 -0700453 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800455 if (eeprom->len == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 return -EINVAL;
457
458 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
459
460 first_word = eeprom->offset >> 1;
461 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
462
Joe Perches406874a2008-04-03 10:06:32 -0700463 eeprom_buff = kmalloc(sizeof(u16) *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 (last_word - first_word + 1), GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800465 if (!eeprom_buff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 return -ENOMEM;
467
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800468 if (hw->eeprom.type == e1000_eeprom_spi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 ret_val = e1000_read_eeprom(hw, first_word,
470 last_word - first_word + 1,
471 eeprom_buff);
472 else {
Joe Perchesc7be73b2008-07-11 15:17:28 -0700473 for (i = 0; i < last_word - first_word + 1; i++) {
474 ret_val = e1000_read_eeprom(hw, first_word + i, 1,
475 &eeprom_buff[i]);
476 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 break;
Joe Perchesc7be73b2008-07-11 15:17:28 -0700478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 }
480
481 /* Device's eeprom is always little-endian, word addressable */
482 for (i = 0; i < last_word - first_word + 1; i++)
483 le16_to_cpus(&eeprom_buff[i]);
484
Joe Perches406874a2008-04-03 10:06:32 -0700485 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 eeprom->len);
487 kfree(eeprom_buff);
488
489 return ret_val;
490}
491
Joe Perches64798842008-07-11 15:17:02 -0700492static int e1000_set_eeprom(struct net_device *netdev,
493 struct ethtool_eeprom *eeprom, u8 *bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700495 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700497 u16 *eeprom_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 void *ptr;
499 int max_len, first_word, last_word, ret_val = 0;
Joe Perches406874a2008-04-03 10:06:32 -0700500 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800502 if (eeprom->len == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 return -EOPNOTSUPP;
504
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800505 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 return -EFAULT;
507
508 max_len = hw->eeprom.word_size * 2;
509
510 first_word = eeprom->offset >> 1;
511 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
512 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800513 if (!eeprom_buff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 return -ENOMEM;
515
516 ptr = (void *)eeprom_buff;
517
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800518 if (eeprom->offset & 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 /* need read/modify/write of first changed EEPROM word */
520 /* only the second byte of the word is being modified */
521 ret_val = e1000_read_eeprom(hw, first_word, 1,
522 &eeprom_buff[0]);
523 ptr++;
524 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800525 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 /* need read/modify/write of last changed EEPROM word */
527 /* only the first byte of the word is being modified */
528 ret_val = e1000_read_eeprom(hw, last_word, 1,
529 &eeprom_buff[last_word - first_word]);
530 }
531
532 /* Device's eeprom is always little-endian, word addressable */
533 for (i = 0; i < last_word - first_word + 1; i++)
534 le16_to_cpus(&eeprom_buff[i]);
535
536 memcpy(ptr, bytes, eeprom->len);
537
538 for (i = 0; i < last_word - first_word + 1; i++)
539 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
540
541 ret_val = e1000_write_eeprom(hw, first_word,
542 last_word - first_word + 1, eeprom_buff);
543
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000544 /* Update the checksum over the first part of the EEPROM if needed */
545 if ((ret_val == 0) && (first_word <= EEPROM_CHECKSUM_REG))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 e1000_update_eeprom_checksum(hw);
547
548 kfree(eeprom_buff);
549 return ret_val;
550}
551
Joe Perches64798842008-07-11 15:17:02 -0700552static void e1000_get_drvinfo(struct net_device *netdev,
553 struct ethtool_drvinfo *drvinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700555 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirshera2917e22006-01-12 16:51:23 -0800556 char firmware_version[32];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
558 strncpy(drvinfo->driver, e1000_driver_name, 32);
559 strncpy(drvinfo->version, e1000_driver_version, 32);
Jeff Kirshera2917e22006-01-12 16:51:23 -0800560
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000561 sprintf(firmware_version, "N/A");
Jeff Kirshera2917e22006-01-12 16:51:23 -0800562 strncpy(drvinfo->fw_version, firmware_version, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 drvinfo->regdump_len = e1000_get_regs_len(netdev);
565 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
566}
567
Joe Perches64798842008-07-11 15:17:02 -0700568static void e1000_get_ringparam(struct net_device *netdev,
569 struct ethtool_ringparam *ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700571 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700572 struct e1000_hw *hw = &adapter->hw;
573 e1000_mac_type mac_type = hw->mac_type;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400574 struct e1000_tx_ring *txdr = adapter->tx_ring;
575 struct e1000_rx_ring *rxdr = adapter->rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577 ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
578 E1000_MAX_82544_RXD;
579 ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD :
580 E1000_MAX_82544_TXD;
581 ring->rx_mini_max_pending = 0;
582 ring->rx_jumbo_max_pending = 0;
583 ring->rx_pending = rxdr->count;
584 ring->tx_pending = txdr->count;
585 ring->rx_mini_pending = 0;
586 ring->rx_jumbo_pending = 0;
587}
588
Joe Perches64798842008-07-11 15:17:02 -0700589static int e1000_set_ringparam(struct net_device *netdev,
590 struct ethtool_ringparam *ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700592 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700593 struct e1000_hw *hw = &adapter->hw;
594 e1000_mac_type mac_type = hw->mac_type;
Vasily Averin793fab722006-09-27 12:54:14 -0700595 struct e1000_tx_ring *txdr, *tx_old;
596 struct e1000_rx_ring *rxdr, *rx_old;
Yan Burman1c7e5b12007-03-06 08:58:04 -0800597 int i, err;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400598
Jeff Kirsher0989aa42006-03-02 18:17:16 -0800599 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
600 return -EINVAL;
601
Auke Kok2db10a02006-06-27 09:06:28 -0700602 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
603 msleep(1);
604
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400605 if (netif_running(adapter->netdev))
606 e1000_down(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
608 tx_old = adapter->tx_ring;
609 rx_old = adapter->rx_ring;
610
Vasily Averin793fab722006-09-27 12:54:14 -0700611 err = -ENOMEM;
Yan Burman1c7e5b12007-03-06 08:58:04 -0800612 txdr = kcalloc(adapter->num_tx_queues, sizeof(struct e1000_tx_ring), GFP_KERNEL);
Vasily Averin793fab722006-09-27 12:54:14 -0700613 if (!txdr)
614 goto err_alloc_tx;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400615
Yan Burman1c7e5b12007-03-06 08:58:04 -0800616 rxdr = kcalloc(adapter->num_rx_queues, sizeof(struct e1000_rx_ring), GFP_KERNEL);
Vasily Averin793fab722006-09-27 12:54:14 -0700617 if (!rxdr)
618 goto err_alloc_rx;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400619
Vasily Averin793fab722006-09-27 12:54:14 -0700620 adapter->tx_ring = txdr;
621 adapter->rx_ring = rxdr;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400622
Joe Perches406874a2008-04-03 10:06:32 -0700623 rxdr->count = max(ring->rx_pending,(u32)E1000_MIN_RXD);
624 rxdr->count = min(rxdr->count,(u32)(mac_type < e1000_82544 ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 E1000_MAX_RXD : E1000_MAX_82544_RXD));
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700626 rxdr->count = ALIGN(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Joe Perches406874a2008-04-03 10:06:32 -0700628 txdr->count = max(ring->tx_pending,(u32)E1000_MIN_TXD);
629 txdr->count = min(txdr->count,(u32)(mac_type < e1000_82544 ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 E1000_MAX_TXD : E1000_MAX_82544_TXD));
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700631 txdr->count = ALIGN(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800633 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400634 txdr[i].count = txdr->count;
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800635 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400636 rxdr[i].count = rxdr->count;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400637
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800638 if (netif_running(adapter->netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 /* Try to get new resources before deleting old */
Joe Perchesc7be73b2008-07-11 15:17:28 -0700640 err = e1000_setup_all_rx_resources(adapter);
641 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 goto err_setup_rx;
Joe Perchesc7be73b2008-07-11 15:17:28 -0700643 err = e1000_setup_all_tx_resources(adapter);
644 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 goto err_setup_tx;
646
647 /* save the new, restore the old in order to free it,
648 * then restore the new back again */
649
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 adapter->rx_ring = rx_old;
651 adapter->tx_ring = tx_old;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400652 e1000_free_all_rx_resources(adapter);
653 e1000_free_all_tx_resources(adapter);
654 kfree(tx_old);
655 kfree(rx_old);
Vasily Averin793fab722006-09-27 12:54:14 -0700656 adapter->rx_ring = rxdr;
657 adapter->tx_ring = txdr;
Joe Perchesc7be73b2008-07-11 15:17:28 -0700658 err = e1000_up(adapter);
659 if (err)
Auke Kok2db10a02006-06-27 09:06:28 -0700660 goto err_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 }
662
Auke Kok2db10a02006-06-27 09:06:28 -0700663 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 return 0;
665err_setup_tx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400666 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667err_setup_rx:
668 adapter->rx_ring = rx_old;
669 adapter->tx_ring = tx_old;
Vasily Averin793fab722006-09-27 12:54:14 -0700670 kfree(rxdr);
671err_alloc_rx:
672 kfree(txdr);
673err_alloc_tx:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 e1000_up(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -0700675err_setup:
676 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 return err;
678}
679
Joe Perches64798842008-07-11 15:17:02 -0700680static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data, int reg,
681 u32 mask, u32 write)
Joe Perches7e643002007-11-13 20:52:05 -0800682{
Joe Perches1dc32912008-07-11 15:17:08 -0700683 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700684 static const u32 test[] =
Joe Perches7e643002007-11-13 20:52:05 -0800685 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Joe Perches1dc32912008-07-11 15:17:08 -0700686 u8 __iomem *address = hw->hw_addr + reg;
Joe Perches406874a2008-04-03 10:06:32 -0700687 u32 read;
Joe Perches7e643002007-11-13 20:52:05 -0800688 int i;
689
690 for (i = 0; i < ARRAY_SIZE(test); i++) {
691 writel(write & test[i], address);
692 read = readl(address);
693 if (read != (write & test[i] & mask)) {
694 DPRINTK(DRV, ERR, "pattern test reg %04X failed: "
695 "got 0x%08X expected 0x%08X\n",
Jeff Garzikcba05162007-11-23 21:50:34 -0500696 reg, read, (write & test[i] & mask));
Joe Perches7e643002007-11-13 20:52:05 -0800697 *data = reg;
698 return true;
699 }
700 }
701 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702}
703
Joe Perches64798842008-07-11 15:17:02 -0700704static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data, int reg,
705 u32 mask, u32 write)
Joe Perches7e643002007-11-13 20:52:05 -0800706{
Joe Perches1dc32912008-07-11 15:17:08 -0700707 struct e1000_hw *hw = &adapter->hw;
708 u8 __iomem *address = hw->hw_addr + reg;
Joe Perches406874a2008-04-03 10:06:32 -0700709 u32 read;
Joe Perches7e643002007-11-13 20:52:05 -0800710
711 writel(write & mask, address);
712 read = readl(address);
713 if ((read & mask) != (write & mask)) {
714 DPRINTK(DRV, ERR, "set/check reg %04X test failed: "
715 "got 0x%08X expected 0x%08X\n",
716 reg, (read & mask), (write & mask));
717 *data = reg;
718 return true;
719 }
720 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721}
722
Joe Perches7e643002007-11-13 20:52:05 -0800723#define REG_PATTERN_TEST(reg, mask, write) \
724 do { \
725 if (reg_pattern_test(adapter, data, \
Joe Perches1dc32912008-07-11 15:17:08 -0700726 (hw->mac_type >= e1000_82543) \
Joe Perches7e643002007-11-13 20:52:05 -0800727 ? E1000_##reg : E1000_82542_##reg, \
728 mask, write)) \
729 return 1; \
730 } while (0)
731
732#define REG_SET_AND_CHECK(reg, mask, write) \
733 do { \
734 if (reg_set_and_check(adapter, data, \
Joe Perches1dc32912008-07-11 15:17:08 -0700735 (hw->mac_type >= e1000_82543) \
Joe Perches7e643002007-11-13 20:52:05 -0800736 ? E1000_##reg : E1000_82542_##reg, \
737 mask, write)) \
738 return 1; \
739 } while (0)
740
Joe Perches64798842008-07-11 15:17:02 -0700741static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742{
Joe Perches406874a2008-04-03 10:06:32 -0700743 u32 value, before, after;
744 u32 i, toggle;
Joe Perches1dc32912008-07-11 15:17:08 -0700745 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
747 /* The status register is Read Only, so a write should fail.
748 * Some bits that get toggled are ignored.
749 */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000750
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400751 /* there are several bits on newer hardware that are r/w */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000752 toggle = 0xFFFFF833;
Malli Chilakalab01f6692005-06-17 17:42:29 -0700753
Joe Perches1dc32912008-07-11 15:17:08 -0700754 before = er32(STATUS);
755 value = (er32(STATUS) & toggle);
756 ew32(STATUS, toggle);
757 after = er32(STATUS) & toggle;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800758 if (value != after) {
Malli Chilakalab01f6692005-06-17 17:42:29 -0700759 DPRINTK(DRV, ERR, "failed STATUS register test got: "
760 "0x%08X expected: 0x%08X\n", after, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 *data = 1;
762 return 1;
763 }
Malli Chilakalab01f6692005-06-17 17:42:29 -0700764 /* restore previous status */
Joe Perches1dc32912008-07-11 15:17:08 -0700765 ew32(STATUS, before);
Auke Kok90fb5132006-11-01 08:47:30 -0800766
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000767 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
768 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
769 REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF);
770 REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF);
Auke Kok90fb5132006-11-01 08:47:30 -0800771
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF);
773 REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
774 REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF);
775 REG_PATTERN_TEST(RDH, 0x0000FFFF, 0x0000FFFF);
776 REG_PATTERN_TEST(RDT, 0x0000FFFF, 0x0000FFFF);
777 REG_PATTERN_TEST(FCRTH, 0x0000FFF8, 0x0000FFF8);
778 REG_PATTERN_TEST(FCTTV, 0x0000FFFF, 0x0000FFFF);
779 REG_PATTERN_TEST(TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
780 REG_PATTERN_TEST(TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
781 REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF);
782
783 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000);
Auke Kok90fb5132006-11-01 08:47:30 -0800784
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000785 before = 0x06DFB3FE;
Auke Kokcd94dd02006-06-27 09:08:22 -0700786 REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);
788
Joe Perches1dc32912008-07-11 15:17:08 -0700789 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
Auke Kokcd94dd02006-06-27 09:08:22 -0700791 REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000793 REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
795 REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000796 value = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -0700797 for (i = 0; i < value; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF,
Auke Kok90fb5132006-11-01 08:47:30 -0800799 0xFFFFFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 }
801
802 } else {
803
804 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF);
805 REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF);
806 REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF);
807 REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF);
808
809 }
810
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000811 value = E1000_MC_TBL_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -0700812 for (i = 0; i < value; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
814
815 *data = 0;
816 return 0;
817}
818
Joe Perches64798842008-07-11 15:17:02 -0700819static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
Joe Perches1dc32912008-07-11 15:17:08 -0700821 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700822 u16 temp;
823 u16 checksum = 0;
824 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 *data = 0;
827 /* Read and add up the contents of the EEPROM */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800828 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
Joe Perches1dc32912008-07-11 15:17:08 -0700829 if ((e1000_read_eeprom(hw, i, 1, &temp)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 *data = 1;
831 break;
832 }
833 checksum += temp;
834 }
835
836 /* If Checksum is not Correct return error else test passed */
Joe Perchese982f172008-07-11 15:17:18 -0700837 if ((checksum != (u16)EEPROM_SUM) && !(*data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 *data = 2;
839
840 return *data;
841}
842
Joe Perches64798842008-07-11 15:17:02 -0700843static irqreturn_t e1000_test_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844{
Joe Perchese982f172008-07-11 15:17:18 -0700845 struct net_device *netdev = (struct net_device *)data;
Malli Chilakala60490fe2005-06-17 17:41:45 -0700846 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700847 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
Joe Perches1dc32912008-07-11 15:17:08 -0700849 adapter->test_icr |= er32(ICR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 return IRQ_HANDLED;
852}
853
Joe Perches64798842008-07-11 15:17:02 -0700854static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855{
856 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -0700857 u32 mask, i = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -0700858 bool shared_int = true;
Joe Perches406874a2008-04-03 10:06:32 -0700859 u32 irq = adapter->pdev->irq;
Joe Perches1dc32912008-07-11 15:17:08 -0700860 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
862 *data = 0;
863
Auke Kok8fc897b2006-08-28 14:56:16 -0700864 /* NOTE: we don't test MSI interrupts here, yet */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 /* Hook up test interrupt handler just for this test */
Auke Kok90fb5132006-11-01 08:47:30 -0800866 if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
867 netdev))
Joe Perchesc3033b02008-03-21 11:06:25 -0700868 shared_int = false;
Auke Kok8fc897b2006-08-28 14:56:16 -0700869 else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED,
Auke Kok90fb5132006-11-01 08:47:30 -0800870 netdev->name, netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 *data = 1;
872 return -1;
873 }
Auke Kok8fc897b2006-08-28 14:56:16 -0700874 DPRINTK(HW, INFO, "testing %s interrupt\n",
Auke Kokb9b6e782006-06-08 09:28:38 -0700875 (shared_int ? "shared" : "unshared"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
877 /* Disable all the interrupts */
Joe Perches1dc32912008-07-11 15:17:08 -0700878 ew32(IMC, 0xFFFFFFFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400879 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
881 /* Test each interrupt */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800882 for (; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
884 /* Interrupt to test */
885 mask = 1 << i;
886
Auke Kok76c224b2006-05-23 13:36:06 -0700887 if (!shared_int) {
888 /* Disable the interrupt to be reported in
889 * the cause register and then force the same
890 * interrupt and see if one gets posted. If
891 * an interrupt was posted to the bus, the
892 * test failed.
893 */
894 adapter->test_icr = 0;
Joe Perches1dc32912008-07-11 15:17:08 -0700895 ew32(IMC, mask);
896 ew32(ICS, mask);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400897 msleep(10);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800898
Auke Kok76c224b2006-05-23 13:36:06 -0700899 if (adapter->test_icr & mask) {
900 *data = 3;
901 break;
902 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 }
904
905 /* Enable the interrupt to be reported in
906 * the cause register and then force the same
907 * interrupt and see if one gets posted. If
908 * an interrupt was not posted to the bus, the
909 * test failed.
910 */
911 adapter->test_icr = 0;
Joe Perches1dc32912008-07-11 15:17:08 -0700912 ew32(IMS, mask);
913 ew32(ICS, mask);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400914 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800916 if (!(adapter->test_icr & mask)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 *data = 4;
918 break;
919 }
920
Auke Kok76c224b2006-05-23 13:36:06 -0700921 if (!shared_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 /* Disable the other interrupts to be reported in
923 * the cause register and then force the other
924 * interrupts and see if any get posted. If
925 * an interrupt was posted to the bus, the
926 * test failed.
927 */
928 adapter->test_icr = 0;
Joe Perches1dc32912008-07-11 15:17:08 -0700929 ew32(IMC, ~mask & 0x00007FFF);
930 ew32(ICS, ~mask & 0x00007FFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400931 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800933 if (adapter->test_icr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 *data = 5;
935 break;
936 }
937 }
938 }
939
940 /* Disable all the interrupts */
Joe Perches1dc32912008-07-11 15:17:08 -0700941 ew32(IMC, 0xFFFFFFFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400942 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
944 /* Unhook test interrupt handler */
945 free_irq(irq, netdev);
946
947 return *data;
948}
949
Joe Perches64798842008-07-11 15:17:02 -0700950static void e1000_free_desc_rings(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400952 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
953 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 struct pci_dev *pdev = adapter->pdev;
955 int i;
956
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800957 if (txdr->desc && txdr->buffer_info) {
958 for (i = 0; i < txdr->count; i++) {
959 if (txdr->buffer_info[i].dma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 pci_unmap_single(pdev, txdr->buffer_info[i].dma,
961 txdr->buffer_info[i].length,
962 PCI_DMA_TODEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800963 if (txdr->buffer_info[i].skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 dev_kfree_skb(txdr->buffer_info[i].skb);
965 }
966 }
967
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800968 if (rxdr->desc && rxdr->buffer_info) {
969 for (i = 0; i < rxdr->count; i++) {
970 if (rxdr->buffer_info[i].dma)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 pci_unmap_single(pdev, rxdr->buffer_info[i].dma,
972 rxdr->buffer_info[i].length,
973 PCI_DMA_FROMDEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800974 if (rxdr->buffer_info[i].skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 dev_kfree_skb(rxdr->buffer_info[i].skb);
976 }
977 }
978
Jeff Kirsherf5645112006-01-12 16:51:01 -0800979 if (txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 pci_free_consistent(pdev, txdr->size, txdr->desc, txdr->dma);
John W. Linville6b27adb2005-11-08 15:59:30 -0500981 txdr->desc = NULL;
982 }
Jeff Kirsherf5645112006-01-12 16:51:01 -0800983 if (rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 pci_free_consistent(pdev, rxdr->size, rxdr->desc, rxdr->dma);
John W. Linville6b27adb2005-11-08 15:59:30 -0500985 rxdr->desc = NULL;
986 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
Jesper Juhlb4558ea2005-10-28 16:53:13 -0400988 kfree(txdr->buffer_info);
John W. Linville6b27adb2005-11-08 15:59:30 -0500989 txdr->buffer_info = NULL;
Jesper Juhlb4558ea2005-10-28 16:53:13 -0400990 kfree(rxdr->buffer_info);
John W. Linville6b27adb2005-11-08 15:59:30 -0500991 rxdr->buffer_info = NULL;
Jeff Kirsherf5645112006-01-12 16:51:01 -0800992
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 return;
994}
995
Joe Perches64798842008-07-11 15:17:02 -0700996static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997{
Joe Perches1dc32912008-07-11 15:17:08 -0700998 struct e1000_hw *hw = &adapter->hw;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400999 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1000 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 struct pci_dev *pdev = adapter->pdev;
Joe Perches406874a2008-04-03 10:06:32 -07001002 u32 rctl;
Yan Burman1c7e5b12007-03-06 08:58:04 -08001003 int i, ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
1005 /* Setup Tx descriptor ring and Tx buffers */
1006
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001007 if (!txdr->count)
1008 txdr->count = E1000_DEFAULT_TXD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
Joe Perchesc7be73b2008-07-11 15:17:28 -07001010 txdr->buffer_info = kcalloc(txdr->count, sizeof(struct e1000_buffer),
1011 GFP_KERNEL);
1012 if (!txdr->buffer_info) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 ret_val = 1;
1014 goto err_nomem;
1015 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
1017 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001018 txdr->size = ALIGN(txdr->size, 4096);
Joe Perchesc7be73b2008-07-11 15:17:28 -07001019 txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma);
1020 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 ret_val = 2;
1022 goto err_nomem;
1023 }
1024 memset(txdr->desc, 0, txdr->size);
1025 txdr->next_to_use = txdr->next_to_clean = 0;
1026
Joe Perchese982f172008-07-11 15:17:18 -07001027 ew32(TDBAL, ((u64)txdr->dma & 0x00000000FFFFFFFF));
1028 ew32(TDBAH, ((u64)txdr->dma >> 32));
Joe Perches1dc32912008-07-11 15:17:08 -07001029 ew32(TDLEN, txdr->count * sizeof(struct e1000_tx_desc));
1030 ew32(TDH, 0);
1031 ew32(TDT, 0);
1032 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN |
1033 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1034 E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001036 for (i = 0; i < txdr->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i);
1038 struct sk_buff *skb;
1039 unsigned int size = 1024;
1040
Joe Perchesc7be73b2008-07-11 15:17:28 -07001041 skb = alloc_skb(size, GFP_KERNEL);
1042 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 ret_val = 3;
1044 goto err_nomem;
1045 }
1046 skb_put(skb, size);
1047 txdr->buffer_info[i].skb = skb;
1048 txdr->buffer_info[i].length = skb->len;
1049 txdr->buffer_info[i].dma =
1050 pci_map_single(pdev, skb->data, skb->len,
1051 PCI_DMA_TODEVICE);
1052 tx_desc->buffer_addr = cpu_to_le64(txdr->buffer_info[i].dma);
1053 tx_desc->lower.data = cpu_to_le32(skb->len);
1054 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1055 E1000_TXD_CMD_IFCS |
1056 E1000_TXD_CMD_RPS);
1057 tx_desc->upper.data = 0;
1058 }
1059
1060 /* Setup Rx descriptor ring and Rx buffers */
1061
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001062 if (!rxdr->count)
1063 rxdr->count = E1000_DEFAULT_RXD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
Joe Perchesc7be73b2008-07-11 15:17:28 -07001065 rxdr->buffer_info = kcalloc(rxdr->count, sizeof(struct e1000_buffer),
1066 GFP_KERNEL);
1067 if (!rxdr->buffer_info) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 ret_val = 4;
1069 goto err_nomem;
1070 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
1072 rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
Joe Perchesc7be73b2008-07-11 15:17:28 -07001073 rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma);
1074 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 ret_val = 5;
1076 goto err_nomem;
1077 }
1078 memset(rxdr->desc, 0, rxdr->size);
1079 rxdr->next_to_use = rxdr->next_to_clean = 0;
1080
Joe Perches1dc32912008-07-11 15:17:08 -07001081 rctl = er32(RCTL);
1082 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Joe Perchese982f172008-07-11 15:17:18 -07001083 ew32(RDBAL, ((u64)rxdr->dma & 0xFFFFFFFF));
1084 ew32(RDBAH, ((u64)rxdr->dma >> 32));
Joe Perches1dc32912008-07-11 15:17:08 -07001085 ew32(RDLEN, rxdr->size);
1086 ew32(RDH, 0);
1087 ew32(RDT, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
1089 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
Joe Perches1dc32912008-07-11 15:17:08 -07001090 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
1091 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001093 for (i = 0; i < rxdr->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i);
1095 struct sk_buff *skb;
1096
Joe Perchesc7be73b2008-07-11 15:17:28 -07001097 skb = alloc_skb(E1000_RXBUFFER_2048 + NET_IP_ALIGN, GFP_KERNEL);
1098 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 ret_val = 6;
1100 goto err_nomem;
1101 }
1102 skb_reserve(skb, NET_IP_ALIGN);
1103 rxdr->buffer_info[i].skb = skb;
1104 rxdr->buffer_info[i].length = E1000_RXBUFFER_2048;
1105 rxdr->buffer_info[i].dma =
1106 pci_map_single(pdev, skb->data, E1000_RXBUFFER_2048,
1107 PCI_DMA_FROMDEVICE);
1108 rx_desc->buffer_addr = cpu_to_le64(rxdr->buffer_info[i].dma);
1109 memset(skb->data, 0x00, skb->len);
1110 }
1111
1112 return 0;
1113
1114err_nomem:
1115 e1000_free_desc_rings(adapter);
1116 return ret_val;
1117}
1118
Joe Perches64798842008-07-11 15:17:02 -07001119static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120{
Joe Perches1dc32912008-07-11 15:17:08 -07001121 struct e1000_hw *hw = &adapter->hw;
1122
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
Joe Perches1dc32912008-07-11 15:17:08 -07001124 e1000_write_phy_reg(hw, 29, 0x001F);
1125 e1000_write_phy_reg(hw, 30, 0x8FFC);
1126 e1000_write_phy_reg(hw, 29, 0x001A);
1127 e1000_write_phy_reg(hw, 30, 0x8FF0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128}
1129
Joe Perches64798842008-07-11 15:17:02 -07001130static void e1000_phy_reset_clk_and_crs(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131{
Joe Perches1dc32912008-07-11 15:17:08 -07001132 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001133 u16 phy_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
1135 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1136 * Extended PHY Specific Control Register to 25MHz clock. This
1137 * value defaults back to a 2.5MHz clock when the PHY is reset.
1138 */
Joe Perches1dc32912008-07-11 15:17:08 -07001139 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 phy_reg |= M88E1000_EPSCR_TX_CLK_25;
Joe Perches1dc32912008-07-11 15:17:08 -07001141 e1000_write_phy_reg(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 M88E1000_EXT_PHY_SPEC_CTRL, phy_reg);
1143
1144 /* In addition, because of the s/w reset above, we need to enable
1145 * CRS on TX. This must be set for both full and half duplex
1146 * operation.
1147 */
Joe Perches1dc32912008-07-11 15:17:08 -07001148 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 phy_reg |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Joe Perches1dc32912008-07-11 15:17:08 -07001150 e1000_write_phy_reg(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 M88E1000_PHY_SPEC_CTRL, phy_reg);
1152}
1153
Joe Perches64798842008-07-11 15:17:02 -07001154static int e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155{
Joe Perches1dc32912008-07-11 15:17:08 -07001156 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001157 u32 ctrl_reg;
1158 u16 phy_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
1160 /* Setup the Device Control Register for PHY loopback test. */
1161
Joe Perches1dc32912008-07-11 15:17:08 -07001162 ctrl_reg = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 ctrl_reg |= (E1000_CTRL_ILOS | /* Invert Loss-Of-Signal */
1164 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1165 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1166 E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */
1167 E1000_CTRL_FD); /* Force Duplex to FULL */
1168
Joe Perches1dc32912008-07-11 15:17:08 -07001169 ew32(CTRL, ctrl_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
1171 /* Read the PHY Specific Control Register (0x10) */
Joe Perches1dc32912008-07-11 15:17:08 -07001172 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
1174 /* Clear Auto-Crossover bits in PHY Specific Control Register
1175 * (bits 6:5).
1176 */
1177 phy_reg &= ~M88E1000_PSCR_AUTO_X_MODE;
Joe Perches1dc32912008-07-11 15:17:08 -07001178 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
1180 /* Perform software reset on the PHY */
Joe Perches1dc32912008-07-11 15:17:08 -07001181 e1000_phy_reset(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
1183 /* Have to setup TX_CLK and TX_CRS after software reset */
1184 e1000_phy_reset_clk_and_crs(adapter);
1185
Joe Perches1dc32912008-07-11 15:17:08 -07001186 e1000_write_phy_reg(hw, PHY_CTRL, 0x8100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
1188 /* Wait for reset to complete. */
1189 udelay(500);
1190
1191 /* Have to setup TX_CLK and TX_CRS after software reset */
1192 e1000_phy_reset_clk_and_crs(adapter);
1193
1194 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1195 e1000_phy_disable_receiver(adapter);
1196
1197 /* Set the loopback bit in the PHY control register. */
Joe Perches1dc32912008-07-11 15:17:08 -07001198 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 phy_reg |= MII_CR_LOOPBACK;
Joe Perches1dc32912008-07-11 15:17:08 -07001200 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
1202 /* Setup TX_CLK and TX_CRS one more time. */
1203 e1000_phy_reset_clk_and_crs(adapter);
1204
1205 /* Check Phy Configuration */
Joe Perches1dc32912008-07-11 15:17:08 -07001206 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001207 if (phy_reg != 0x4100)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 return 9;
1209
Joe Perches1dc32912008-07-11 15:17:08 -07001210 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001211 if (phy_reg != 0x0070)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 return 10;
1213
Joe Perches1dc32912008-07-11 15:17:08 -07001214 e1000_read_phy_reg(hw, 29, &phy_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001215 if (phy_reg != 0x001A)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 return 11;
1217
1218 return 0;
1219}
1220
Joe Perches64798842008-07-11 15:17:02 -07001221static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222{
Joe Perches1dc32912008-07-11 15:17:08 -07001223 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001224 u32 ctrl_reg = 0;
1225 u32 stat_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
Joe Perches1dc32912008-07-11 15:17:08 -07001227 hw->autoneg = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228
Joe Perches1dc32912008-07-11 15:17:08 -07001229 if (hw->phy_type == e1000_phy_m88) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 /* Auto-MDI/MDIX Off */
Joe Perches1dc32912008-07-11 15:17:08 -07001231 e1000_write_phy_reg(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 M88E1000_PHY_SPEC_CTRL, 0x0808);
1233 /* reset to update Auto-MDI/MDIX */
Joe Perches1dc32912008-07-11 15:17:08 -07001234 e1000_write_phy_reg(hw, PHY_CTRL, 0x9140);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 /* autoneg off */
Joe Perches1dc32912008-07-11 15:17:08 -07001236 e1000_write_phy_reg(hw, PHY_CTRL, 0x8140);
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001237 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238
Joe Perches1dc32912008-07-11 15:17:08 -07001239 ctrl_reg = er32(CTRL);
Auke Kokcd94dd02006-06-27 09:08:22 -07001240
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001241 /* force 1000, set loopback */
1242 e1000_write_phy_reg(hw, PHY_CTRL, 0x4140);
Auke Kokcd94dd02006-06-27 09:08:22 -07001243
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001244 /* Now set up the MAC to the same speed/duplex as the PHY. */
1245 ctrl_reg = er32(CTRL);
1246 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1247 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1248 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1249 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1250 E1000_CTRL_FD); /* Force Duplex to FULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Joe Perches1dc32912008-07-11 15:17:08 -07001252 if (hw->media_type == e1000_media_type_copper &&
1253 hw->phy_type == e1000_phy_m88)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
Auke Kok8fc897b2006-08-28 14:56:16 -07001255 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 /* Set the ILOS bit on the fiber Nic is half
1257 * duplex link is detected. */
Joe Perches1dc32912008-07-11 15:17:08 -07001258 stat_reg = er32(STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001259 if ((stat_reg & E1000_STATUS_FD) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1261 }
1262
Joe Perches1dc32912008-07-11 15:17:08 -07001263 ew32(CTRL, ctrl_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
1265 /* Disable the receiver on the PHY so when a cable is plugged in, the
1266 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1267 */
Joe Perches1dc32912008-07-11 15:17:08 -07001268 if (hw->phy_type == e1000_phy_m88)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 e1000_phy_disable_receiver(adapter);
1270
1271 udelay(500);
1272
1273 return 0;
1274}
1275
Joe Perches64798842008-07-11 15:17:02 -07001276static int e1000_set_phy_loopback(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277{
Joe Perches1dc32912008-07-11 15:17:08 -07001278 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001279 u16 phy_reg = 0;
1280 u16 count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Joe Perches1dc32912008-07-11 15:17:08 -07001282 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 case e1000_82543:
Joe Perches1dc32912008-07-11 15:17:08 -07001284 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 /* Attempt to setup Loopback mode on Non-integrated PHY.
1286 * Some PHY registers get corrupted at random, so
1287 * attempt this 10 times.
1288 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001289 while (e1000_nonintegrated_phy_loopback(adapter) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 count++ < 10);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001291 if (count < 11)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 return 0;
1293 }
1294 break;
1295
1296 case e1000_82544:
1297 case e1000_82540:
1298 case e1000_82545:
1299 case e1000_82545_rev_3:
1300 case e1000_82546:
1301 case e1000_82546_rev_3:
1302 case e1000_82541:
1303 case e1000_82541_rev_2:
1304 case e1000_82547:
1305 case e1000_82547_rev_2:
1306 return e1000_integrated_phy_loopback(adapter);
1307 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 default:
1309 /* Default PHY loopback work is to read the MII
1310 * control register and assert bit 14 (loopback mode).
1311 */
Joe Perches1dc32912008-07-11 15:17:08 -07001312 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 phy_reg |= MII_CR_LOOPBACK;
Joe Perches1dc32912008-07-11 15:17:08 -07001314 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 return 0;
1316 break;
1317 }
1318
1319 return 8;
1320}
1321
Joe Perches64798842008-07-11 15:17:02 -07001322static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323{
Jeff Kirsher49273162006-01-12 16:50:44 -08001324 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001325 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
Jeff Kirsher49273162006-01-12 16:50:44 -08001327 if (hw->media_type == e1000_media_type_fiber ||
1328 hw->media_type == e1000_media_type_internal_serdes) {
1329 switch (hw->mac_type) {
1330 case e1000_82545:
1331 case e1000_82546:
1332 case e1000_82545_rev_3:
1333 case e1000_82546_rev_3:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 return e1000_set_phy_loopback(adapter);
Jeff Kirsher49273162006-01-12 16:50:44 -08001335 break;
Jeff Kirsher49273162006-01-12 16:50:44 -08001336 default:
Joe Perches1dc32912008-07-11 15:17:08 -07001337 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 rctl |= E1000_RCTL_LBM_TCVR;
Joe Perches1dc32912008-07-11 15:17:08 -07001339 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 return 0;
1341 }
Jeff Kirsher49273162006-01-12 16:50:44 -08001342 } else if (hw->media_type == e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 return e1000_set_phy_loopback(adapter);
1344
1345 return 7;
1346}
1347
Joe Perches64798842008-07-11 15:17:02 -07001348static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349{
Jeff Kirsher49273162006-01-12 16:50:44 -08001350 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001351 u32 rctl;
1352 u16 phy_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353
Joe Perches1dc32912008-07-11 15:17:08 -07001354 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
Joe Perches1dc32912008-07-11 15:17:08 -07001356 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Jeff Kirsher49273162006-01-12 16:50:44 -08001358 switch (hw->mac_type) {
Jeff Kirsher49273162006-01-12 16:50:44 -08001359 case e1000_82545:
1360 case e1000_82546:
1361 case e1000_82545_rev_3:
1362 case e1000_82546_rev_3:
1363 default:
Joe Perchesc3033b02008-03-21 11:06:25 -07001364 hw->autoneg = true;
Jeff Kirsher49273162006-01-12 16:50:44 -08001365 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
1366 if (phy_reg & MII_CR_LOOPBACK) {
1367 phy_reg &= ~MII_CR_LOOPBACK;
1368 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
1369 e1000_phy_reset(hw);
1370 }
1371 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 }
1373}
1374
Joe Perches64798842008-07-11 15:17:02 -07001375static void e1000_create_lbtest_frame(struct sk_buff *skb,
1376 unsigned int frame_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377{
1378 memset(skb->data, 0xFF, frame_size);
Jeff Kirsherce7393b2006-01-12 16:51:12 -08001379 frame_size &= ~1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1381 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1382 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1383}
1384
Joe Perches64798842008-07-11 15:17:02 -07001385static int e1000_check_lbtest_frame(struct sk_buff *skb,
1386 unsigned int frame_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387{
Jeff Kirsherce7393b2006-01-12 16:51:12 -08001388 frame_size &= ~1;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001389 if (*(skb->data + 3) == 0xFF) {
1390 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
1392 return 0;
1393 }
1394 }
1395 return 13;
1396}
1397
Joe Perches64798842008-07-11 15:17:02 -07001398static int e1000_run_loopback_test(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399{
Joe Perches1dc32912008-07-11 15:17:08 -07001400 struct e1000_hw *hw = &adapter->hw;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001401 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1402 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 struct pci_dev *pdev = adapter->pdev;
Malli Chilakalae4eff722005-04-28 19:38:30 -07001404 int i, j, k, l, lc, good_cnt, ret_val=0;
1405 unsigned long time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
Joe Perches1dc32912008-07-11 15:17:08 -07001407 ew32(RDT, rxdr->count - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001409 /* Calculate the loop count based on the largest descriptor ring
Malli Chilakalae4eff722005-04-28 19:38:30 -07001410 * The idea is to wrap the largest ring a number of times using 64
1411 * send/receive pairs during each loop
1412 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001414 if (rxdr->count <= txdr->count)
Malli Chilakalae4eff722005-04-28 19:38:30 -07001415 lc = ((txdr->count / 64) * 2) + 1;
1416 else
1417 lc = ((rxdr->count / 64) * 2) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Malli Chilakalae4eff722005-04-28 19:38:30 -07001419 k = l = 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001420 for (j = 0; j <= lc; j++) { /* loop count loop */
1421 for (i = 0; i < 64; i++) { /* send the packets */
1422 e1000_create_lbtest_frame(txdr->buffer_info[i].skb,
Malli Chilakalae4eff722005-04-28 19:38:30 -07001423 1024);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001424 pci_dma_sync_single_for_device(pdev,
Malli Chilakalae4eff722005-04-28 19:38:30 -07001425 txdr->buffer_info[k].dma,
1426 txdr->buffer_info[k].length,
1427 PCI_DMA_TODEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001428 if (unlikely(++k == txdr->count)) k = 0;
Malli Chilakalae4eff722005-04-28 19:38:30 -07001429 }
Joe Perches1dc32912008-07-11 15:17:08 -07001430 ew32(TDT, k);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001431 msleep(200);
Malli Chilakalae4eff722005-04-28 19:38:30 -07001432 time = jiffies; /* set the start time for the receive */
1433 good_cnt = 0;
1434 do { /* receive the sent packets */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001435 pci_dma_sync_single_for_cpu(pdev,
Malli Chilakalae4eff722005-04-28 19:38:30 -07001436 rxdr->buffer_info[l].dma,
1437 rxdr->buffer_info[l].length,
1438 PCI_DMA_FROMDEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001439
Malli Chilakalae4eff722005-04-28 19:38:30 -07001440 ret_val = e1000_check_lbtest_frame(
1441 rxdr->buffer_info[l].skb,
1442 1024);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001443 if (!ret_val)
Malli Chilakalae4eff722005-04-28 19:38:30 -07001444 good_cnt++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001445 if (unlikely(++l == rxdr->count)) l = 0;
1446 /* time + 20 msecs (200 msecs on 2.4) is more than
1447 * enough time to complete the receives, if it's
Malli Chilakalae4eff722005-04-28 19:38:30 -07001448 * exceeded, break and error off
1449 */
1450 } while (good_cnt < 64 && jiffies < (time + 20));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001451 if (good_cnt != 64) {
Malli Chilakalae4eff722005-04-28 19:38:30 -07001452 ret_val = 13; /* ret_val is the same as mis-compare */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001453 break;
Malli Chilakalae4eff722005-04-28 19:38:30 -07001454 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001455 if (jiffies >= (time + 2)) {
Malli Chilakalae4eff722005-04-28 19:38:30 -07001456 ret_val = 14; /* error code for time out error */
1457 break;
1458 }
1459 } /* end loop count loop */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 return ret_val;
1461}
1462
Joe Perches64798842008-07-11 15:17:02 -07001463static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464{
Joe Perchesc7be73b2008-07-11 15:17:28 -07001465 *data = e1000_setup_desc_rings(adapter);
1466 if (*data)
Jeff Kirsher57128192006-01-12 16:50:28 -08001467 goto out;
Joe Perchesc7be73b2008-07-11 15:17:28 -07001468 *data = e1000_setup_loopback_test(adapter);
1469 if (*data)
Jeff Kirsher57128192006-01-12 16:50:28 -08001470 goto err_loopback;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 *data = e1000_run_loopback_test(adapter);
1472 e1000_loopback_cleanup(adapter);
Jeff Kirsher57128192006-01-12 16:50:28 -08001473
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474err_loopback:
Jeff Kirsher57128192006-01-12 16:50:28 -08001475 e1000_free_desc_rings(adapter);
1476out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 return *data;
1478}
1479
Joe Perches64798842008-07-11 15:17:02 -07001480static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481{
Joe Perches1dc32912008-07-11 15:17:08 -07001482 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 *data = 0;
Joe Perches1dc32912008-07-11 15:17:08 -07001484 if (hw->media_type == e1000_media_type_internal_serdes) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 int i = 0;
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00001486 hw->serdes_has_link = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
Malli Chilakala26483452005-04-28 19:44:46 -07001488 /* On some blade server designs, link establishment
1489 * could take as long as 2-3 minutes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 do {
Joe Perches1dc32912008-07-11 15:17:08 -07001491 e1000_check_for_link(hw);
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00001492 if (hw->serdes_has_link)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 return *data;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001494 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 } while (i++ < 3750);
1496
Malli Chilakala26483452005-04-28 19:44:46 -07001497 *data = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 } else {
Joe Perches1dc32912008-07-11 15:17:08 -07001499 e1000_check_for_link(hw);
1500 if (hw->autoneg) /* if auto_neg is set wait for it */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001501 msleep(4000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
Joe Perches1dc32912008-07-11 15:17:08 -07001503 if (!(er32(STATUS) & E1000_STATUS_LU)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 *data = 1;
1505 }
1506 }
1507 return *data;
1508}
1509
Joe Perches64798842008-07-11 15:17:02 -07001510static int e1000_get_sset_count(struct net_device *netdev, int sset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001512 switch (sset) {
1513 case ETH_SS_TEST:
1514 return E1000_TEST_LEN;
1515 case ETH_SS_STATS:
1516 return E1000_STATS_LEN;
1517 default:
1518 return -EOPNOTSUPP;
1519 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520}
1521
Joe Perches64798842008-07-11 15:17:02 -07001522static void e1000_diag_test(struct net_device *netdev,
1523 struct ethtool_test *eth_test, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001525 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001526 struct e1000_hw *hw = &adapter->hw;
Joe Perchesc3033b02008-03-21 11:06:25 -07001527 bool if_running = netif_running(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Auke Kok1314bbf2006-09-27 12:54:02 -07001529 set_bit(__E1000_TESTING, &adapter->flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001530 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 /* Offline tests */
1532
1533 /* save speed, duplex, autoneg settings */
Joe Perches1dc32912008-07-11 15:17:08 -07001534 u16 autoneg_advertised = hw->autoneg_advertised;
1535 u8 forced_speed_duplex = hw->forced_speed_duplex;
1536 u8 autoneg = hw->autoneg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
Jesse Brandeburgd6582662006-08-16 13:31:33 -07001538 DPRINTK(HW, INFO, "offline testing starting\n");
1539
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 /* Link test performed before hardware reset so autoneg doesn't
1541 * interfere with test result */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001542 if (e1000_link_test(adapter, &data[4]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 eth_test->flags |= ETH_TEST_FL_FAILED;
1544
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001545 if (if_running)
Auke Kok2db10a02006-06-27 09:06:28 -07001546 /* indicate we're in test mode */
1547 dev_close(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 else
1549 e1000_reset(adapter);
1550
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001551 if (e1000_reg_test(adapter, &data[0]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 eth_test->flags |= ETH_TEST_FL_FAILED;
1553
1554 e1000_reset(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001555 if (e1000_eeprom_test(adapter, &data[1]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 eth_test->flags |= ETH_TEST_FL_FAILED;
1557
1558 e1000_reset(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001559 if (e1000_intr_test(adapter, &data[2]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 eth_test->flags |= ETH_TEST_FL_FAILED;
1561
1562 e1000_reset(adapter);
Jesse Brandeburgd6582662006-08-16 13:31:33 -07001563 /* make sure the phy is powered up */
1564 e1000_power_up_phy(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001565 if (e1000_loopback_test(adapter, &data[3]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 eth_test->flags |= ETH_TEST_FL_FAILED;
1567
1568 /* restore speed, duplex, autoneg settings */
Joe Perches1dc32912008-07-11 15:17:08 -07001569 hw->autoneg_advertised = autoneg_advertised;
1570 hw->forced_speed_duplex = forced_speed_duplex;
1571 hw->autoneg = autoneg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
1573 e1000_reset(adapter);
Auke Kok1314bbf2006-09-27 12:54:02 -07001574 clear_bit(__E1000_TESTING, &adapter->flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001575 if (if_running)
Auke Kok2db10a02006-06-27 09:06:28 -07001576 dev_open(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 } else {
Jesse Brandeburgd6582662006-08-16 13:31:33 -07001578 DPRINTK(HW, INFO, "online testing starting\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 /* Online tests */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001580 if (e1000_link_test(adapter, &data[4]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 eth_test->flags |= ETH_TEST_FL_FAILED;
1582
Auke Kok90fb5132006-11-01 08:47:30 -08001583 /* Online tests aren't run; pass by default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 data[0] = 0;
1585 data[1] = 0;
1586 data[2] = 0;
1587 data[3] = 0;
Auke Kok2db10a02006-06-27 09:06:28 -07001588
Auke Kok1314bbf2006-09-27 12:54:02 -07001589 clear_bit(__E1000_TESTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 }
Mallikarjuna R Chilakala352c9f82005-10-04 07:07:24 -04001591 msleep_interruptible(4 * 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592}
1593
Joe Perches64798842008-07-11 15:17:02 -07001594static int e1000_wol_exclusion(struct e1000_adapter *adapter,
1595 struct ethtool_wolinfo *wol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001598 int retval = 1; /* fail by default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001600 switch (hw->device_id) {
Auke Kokdc1f71f2006-10-24 14:45:55 -07001601 case E1000_DEV_ID_82542:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 case E1000_DEV_ID_82543GC_FIBER:
1603 case E1000_DEV_ID_82543GC_COPPER:
1604 case E1000_DEV_ID_82544EI_FIBER:
1605 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1606 case E1000_DEV_ID_82545EM_FIBER:
1607 case E1000_DEV_ID_82545EM_COPPER:
Jeff Kirsher84916822006-03-02 18:18:48 -08001608 case E1000_DEV_ID_82546GB_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001609 case E1000_DEV_ID_82546GB_PCIE:
1610 /* these don't support WoL at all */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 wol->supported = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001612 break;
1613 case E1000_DEV_ID_82546EB_FIBER:
1614 case E1000_DEV_ID_82546GB_FIBER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001615 /* Wake events not supported on port B */
Joe Perches1dc32912008-07-11 15:17:08 -07001616 if (er32(STATUS) & E1000_STATUS_FUNC_1) {
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001617 wol->supported = 0;
1618 break;
1619 }
1620 /* return success for non excluded adapter ports */
1621 retval = 0;
1622 break;
1623 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1624 /* quad port adapters only support WoL on port A */
1625 if (!adapter->quad_port_a) {
1626 wol->supported = 0;
1627 break;
1628 }
1629 /* return success for non excluded adapter ports */
1630 retval = 0;
1631 break;
1632 default:
1633 /* dual port cards only support WoL on port A from now on
1634 * unless it was enabled in the eeprom for port B
1635 * so exclude FUNC_1 ports from having WoL enabled */
Joe Perches1dc32912008-07-11 15:17:08 -07001636 if (er32(STATUS) & E1000_STATUS_FUNC_1 &&
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001637 !adapter->eeprom_wol) {
1638 wol->supported = 0;
1639 break;
1640 }
1641
1642 retval = 0;
1643 }
1644
1645 return retval;
1646}
1647
Joe Perches64798842008-07-11 15:17:02 -07001648static void e1000_get_wol(struct net_device *netdev,
1649 struct ethtool_wolinfo *wol)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001650{
1651 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001652 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001653
1654 wol->supported = WAKE_UCAST | WAKE_MCAST |
1655 WAKE_BCAST | WAKE_MAGIC;
1656 wol->wolopts = 0;
1657
1658 /* this function will set ->supported = 0 and return 1 if wol is not
1659 * supported by this hardware */
\"Rafael J. Wysocki\de126482008-11-07 20:30:19 +00001660 if (e1000_wol_exclusion(adapter, wol) ||
1661 !device_can_wakeup(&adapter->pdev->dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 return;
1663
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001664 /* apply any specific unsupported masks here */
Joe Perches1dc32912008-07-11 15:17:08 -07001665 switch (hw->device_id) {
Jeff Kirsher84916822006-03-02 18:18:48 -08001666 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001667 /* KSP3 does not suppport UCAST wake-ups */
1668 wol->supported &= ~WAKE_UCAST;
Jeff Kirsher84916822006-03-02 18:18:48 -08001669
1670 if (adapter->wol & E1000_WUFC_EX)
1671 DPRINTK(DRV, ERR, "Interface does not support "
1672 "directed (unicast) frame wake-up packets\n");
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001673 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 default:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001675 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 }
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001677
1678 if (adapter->wol & E1000_WUFC_EX)
1679 wol->wolopts |= WAKE_UCAST;
1680 if (adapter->wol & E1000_WUFC_MC)
1681 wol->wolopts |= WAKE_MCAST;
1682 if (adapter->wol & E1000_WUFC_BC)
1683 wol->wolopts |= WAKE_BCAST;
1684 if (adapter->wol & E1000_WUFC_MAG)
1685 wol->wolopts |= WAKE_MAGIC;
1686
1687 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688}
1689
Joe Perches64798842008-07-11 15:17:02 -07001690static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001692 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 struct e1000_hw *hw = &adapter->hw;
1694
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001695 if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
1696 return -EOPNOTSUPP;
1697
\"Rafael J. Wysocki\de126482008-11-07 20:30:19 +00001698 if (e1000_wol_exclusion(adapter, wol) ||
1699 !device_can_wakeup(&adapter->pdev->dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 return wol->wolopts ? -EOPNOTSUPP : 0;
1701
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001702 switch (hw->device_id) {
Jeff Kirsher84916822006-03-02 18:18:48 -08001703 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jeff Kirsher84916822006-03-02 18:18:48 -08001704 if (wol->wolopts & WAKE_UCAST) {
1705 DPRINTK(DRV, ERR, "Interface does not support "
1706 "directed (unicast) frame wake-up packets\n");
1707 return -EOPNOTSUPP;
1708 }
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001709 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 default:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001711 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 }
1713
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001714 /* these settings will always override what we currently have */
1715 adapter->wol = 0;
1716
1717 if (wol->wolopts & WAKE_UCAST)
1718 adapter->wol |= E1000_WUFC_EX;
1719 if (wol->wolopts & WAKE_MCAST)
1720 adapter->wol |= E1000_WUFC_MC;
1721 if (wol->wolopts & WAKE_BCAST)
1722 adapter->wol |= E1000_WUFC_BC;
1723 if (wol->wolopts & WAKE_MAGIC)
1724 adapter->wol |= E1000_WUFC_MAG;
1725
\"Rafael J. Wysocki\de126482008-11-07 20:30:19 +00001726 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1727
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 return 0;
1729}
1730
1731/* toggle LED 4 times per second = 2 "blinks" per second */
1732#define E1000_ID_INTERVAL (HZ/4)
1733
1734/* bit defines for adapter->led_status */
1735#define E1000_LED_ON 0
1736
Joe Perches64798842008-07-11 15:17:02 -07001737static void e1000_led_blink_callback(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738{
1739 struct e1000_adapter *adapter = (struct e1000_adapter *) data;
Joe Perches1dc32912008-07-11 15:17:08 -07001740 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001742 if (test_and_change_bit(E1000_LED_ON, &adapter->led_status))
Joe Perches1dc32912008-07-11 15:17:08 -07001743 e1000_led_off(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 else
Joe Perches1dc32912008-07-11 15:17:08 -07001745 e1000_led_on(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746
1747 mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL);
1748}
1749
Joe Perches64798842008-07-11 15:17:02 -07001750static int e1000_phys_id(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001752 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001753 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
Stephen Hemmingerabec42a2007-10-29 10:46:19 -07001755 if (!data)
1756 data = INT_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001758 if (!adapter->blink_timer.function) {
1759 init_timer(&adapter->blink_timer);
1760 adapter->blink_timer.function = e1000_led_blink_callback;
1761 adapter->blink_timer.data = (unsigned long)adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 }
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001763 e1000_setup_led(hw);
1764 mod_timer(&adapter->blink_timer, jiffies);
1765 msleep_interruptible(data * 1000);
1766 del_timer_sync(&adapter->blink_timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767
Joe Perches1dc32912008-07-11 15:17:08 -07001768 e1000_led_off(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 clear_bit(E1000_LED_ON, &adapter->led_status);
Joe Perches1dc32912008-07-11 15:17:08 -07001770 e1000_cleanup_led(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
1772 return 0;
1773}
1774
Jesse Brandeburg94c9e5a2009-07-06 10:44:20 +00001775static int e1000_get_coalesce(struct net_device *netdev,
1776 struct ethtool_coalesce *ec)
1777{
1778 struct e1000_adapter *adapter = netdev_priv(netdev);
1779
1780 if (adapter->hw.mac_type < e1000_82545)
1781 return -EOPNOTSUPP;
1782
1783 if (adapter->itr_setting <= 3)
1784 ec->rx_coalesce_usecs = adapter->itr_setting;
1785 else
1786 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1787
1788 return 0;
1789}
1790
1791static int e1000_set_coalesce(struct net_device *netdev,
1792 struct ethtool_coalesce *ec)
1793{
1794 struct e1000_adapter *adapter = netdev_priv(netdev);
1795 struct e1000_hw *hw = &adapter->hw;
1796
1797 if (hw->mac_type < e1000_82545)
1798 return -EOPNOTSUPP;
1799
1800 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
1801 ((ec->rx_coalesce_usecs > 3) &&
1802 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1803 (ec->rx_coalesce_usecs == 2))
1804 return -EINVAL;
1805
1806 if (ec->rx_coalesce_usecs <= 3) {
1807 adapter->itr = 20000;
1808 adapter->itr_setting = ec->rx_coalesce_usecs;
1809 } else {
1810 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1811 adapter->itr_setting = adapter->itr & ~3;
1812 }
1813
1814 if (adapter->itr_setting != 0)
1815 ew32(ITR, 1000000000 / (adapter->itr * 256));
1816 else
1817 ew32(ITR, 0);
1818
1819 return 0;
1820}
1821
Joe Perches64798842008-07-11 15:17:02 -07001822static int e1000_nway_reset(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001824 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kok2db10a02006-06-27 09:06:28 -07001825 if (netif_running(netdev))
1826 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 return 0;
1828}
1829
Joe Perches64798842008-07-11 15:17:02 -07001830static void e1000_get_ethtool_stats(struct net_device *netdev,
1831 struct ethtool_stats *stats, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001833 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 int i;
1835
1836 e1000_update_stats(adapter);
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001837 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1838 char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset;
1839 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
Joe Perches406874a2008-04-03 10:06:32 -07001840 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001842/* BUG_ON(i != E1000_STATS_LEN); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843}
1844
Joe Perches64798842008-07-11 15:17:02 -07001845static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1846 u8 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847{
Joe Perches406874a2008-04-03 10:06:32 -07001848 u8 *p = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 int i;
1850
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001851 switch (stringset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 case ETH_SS_TEST:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001853 memcpy(data, *e1000_gstrings_test,
Roel Kluinc32bc6e2007-12-05 11:57:30 -08001854 sizeof(e1000_gstrings_test));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 break;
1856 case ETH_SS_STATS:
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001857 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1858 memcpy(p, e1000_gstrings_stats[i].stat_string,
1859 ETH_GSTRING_LEN);
1860 p += ETH_GSTRING_LEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001862/* BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 break;
1864 }
1865}
1866
Jeff Garzik7282d492006-09-13 14:30:00 -04001867static const struct ethtool_ops e1000_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 .get_settings = e1000_get_settings,
1869 .set_settings = e1000_set_settings,
1870 .get_drvinfo = e1000_get_drvinfo,
1871 .get_regs_len = e1000_get_regs_len,
1872 .get_regs = e1000_get_regs,
1873 .get_wol = e1000_get_wol,
1874 .set_wol = e1000_set_wol,
Auke Kok8fc897b2006-08-28 14:56:16 -07001875 .get_msglevel = e1000_get_msglevel,
1876 .set_msglevel = e1000_set_msglevel,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 .nway_reset = e1000_nway_reset,
1878 .get_link = ethtool_op_get_link,
1879 .get_eeprom_len = e1000_get_eeprom_len,
1880 .get_eeprom = e1000_get_eeprom,
1881 .set_eeprom = e1000_set_eeprom,
1882 .get_ringparam = e1000_get_ringparam,
1883 .set_ringparam = e1000_set_ringparam,
Auke Kok8fc897b2006-08-28 14:56:16 -07001884 .get_pauseparam = e1000_get_pauseparam,
1885 .set_pauseparam = e1000_set_pauseparam,
1886 .get_rx_csum = e1000_get_rx_csum,
1887 .set_rx_csum = e1000_set_rx_csum,
1888 .get_tx_csum = e1000_get_tx_csum,
1889 .set_tx_csum = e1000_set_tx_csum,
Auke Kok8fc897b2006-08-28 14:56:16 -07001890 .set_sg = ethtool_op_set_sg,
Auke Kok8fc897b2006-08-28 14:56:16 -07001891 .set_tso = e1000_set_tso,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 .self_test = e1000_diag_test,
1893 .get_strings = e1000_get_strings,
1894 .phys_id = e1000_phys_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 .get_ethtool_stats = e1000_get_ethtool_stats,
Jesse Brandeburg94c9e5a2009-07-06 10:44:20 +00001896 .get_sset_count = e1000_get_sset_count,
1897 .get_coalesce = e1000_get_coalesce,
1898 .set_coalesce = e1000_set_coalesce,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899};
1900
1901void e1000_set_ethtool_ops(struct net_device *netdev)
1902{
1903 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
1904}