blob: ec0fa426cce2313f037bff909bff303596c28faf [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
Ajit Khaparde8328c382009-10-13 01:45:48 +000034enum {NETDEV_STATS, E1000_STATS};
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036struct e1000_stats {
37 char stat_string[ETH_GSTRING_LEN];
Ajit Khaparde8328c382009-10-13 01:45:48 +000038 int type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 int sizeof_stat;
40 int stat_offset;
41};
42
Ajit Khaparde8328c382009-10-13 01:45:48 +000043#define E1000_STAT(m) E1000_STATS, \
44 sizeof(((struct e1000_adapter *)0)->m), \
45 offsetof(struct e1000_adapter, m)
46#define E1000_NETDEV_STAT(m) NETDEV_STATS, \
47 sizeof(((struct net_device *)0)->m), \
48 offsetof(struct net_device, m)
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050static const struct e1000_stats e1000_gstrings_stats[] = {
Mitch Williams49559852006-09-27 12:53:37 -070051 { "rx_packets", E1000_STAT(stats.gprc) },
52 { "tx_packets", E1000_STAT(stats.gptc) },
53 { "rx_bytes", E1000_STAT(stats.gorcl) },
54 { "tx_bytes", E1000_STAT(stats.gotcl) },
55 { "rx_broadcast", E1000_STAT(stats.bprc) },
56 { "tx_broadcast", E1000_STAT(stats.bptc) },
57 { "rx_multicast", E1000_STAT(stats.mprc) },
58 { "tx_multicast", E1000_STAT(stats.mptc) },
59 { "rx_errors", E1000_STAT(stats.rxerrc) },
60 { "tx_errors", E1000_STAT(stats.txerrc) },
Ajit Khaparde5fe31de2009-10-07 02:42:23 +000061 { "tx_dropped", E1000_NETDEV_STAT(stats.tx_dropped) },
Mitch Williams49559852006-09-27 12:53:37 -070062 { "multicast", E1000_STAT(stats.mprc) },
63 { "collisions", E1000_STAT(stats.colc) },
64 { "rx_length_errors", E1000_STAT(stats.rlerrc) },
Ajit Khaparde5fe31de2009-10-07 02:42:23 +000065 { "rx_over_errors", E1000_NETDEV_STAT(stats.rx_over_errors) },
Mitch Williams49559852006-09-27 12:53:37 -070066 { "rx_crc_errors", E1000_STAT(stats.crcerrs) },
Ajit Khaparde5fe31de2009-10-07 02:42:23 +000067 { "rx_frame_errors", E1000_NETDEV_STAT(stats.rx_frame_errors) },
Malli Chilakala26483452005-04-28 19:44:46 -070068 { "rx_no_buffer_count", E1000_STAT(stats.rnbc) },
Mitch Williams49559852006-09-27 12:53:37 -070069 { "rx_missed_errors", E1000_STAT(stats.mpc) },
70 { "tx_aborted_errors", E1000_STAT(stats.ecol) },
71 { "tx_carrier_errors", E1000_STAT(stats.tncrs) },
Ajit Khaparde5fe31de2009-10-07 02:42:23 +000072 { "tx_fifo_errors", E1000_NETDEV_STAT(stats.tx_fifo_errors) },
73 { "tx_heartbeat_errors", E1000_NETDEV_STAT(stats.tx_heartbeat_errors) },
Mitch Williams49559852006-09-27 12:53:37 -070074 { "tx_window_errors", E1000_STAT(stats.latecol) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 { "tx_abort_late_coll", E1000_STAT(stats.latecol) },
76 { "tx_deferred_ok", E1000_STAT(stats.dc) },
77 { "tx_single_coll_ok", E1000_STAT(stats.scc) },
78 { "tx_multi_coll_ok", E1000_STAT(stats.mcc) },
Jeff Kirsher6b7660c2006-01-12 16:50:35 -080079 { "tx_timeout_count", E1000_STAT(tx_timeout_count) },
Jesse Brandeburgfcfb1222006-11-01 08:47:59 -080080 { "tx_restart_queue", E1000_STAT(restart_queue) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 { "rx_long_length_errors", E1000_STAT(stats.roc) },
82 { "rx_short_length_errors", E1000_STAT(stats.ruc) },
83 { "rx_align_errors", E1000_STAT(stats.algnerrc) },
84 { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) },
85 { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) },
86 { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) },
87 { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) },
88 { "tx_flow_control_xon", E1000_STAT(stats.xontxc) },
89 { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) },
90 { "rx_long_byte_count", E1000_STAT(stats.gorcl) },
91 { "rx_csum_offload_good", E1000_STAT(hw_csum_good) },
Mallikarjuna R Chilakalae4c811c2005-10-04 07:05:44 -040092 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
Jeff Kirsher6b7660c2006-01-12 16:50:35 -080093 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
Jeff Garzik15e376b2006-12-15 11:16:33 -050094 { "tx_smbus", E1000_STAT(stats.mgptc) },
95 { "rx_smbus", E1000_STAT(stats.mgprc) },
96 { "dropped_smbus", E1000_STAT(stats.mgpdc) },
Linus Torvalds1da177e2005-04-16 15:20:36 -070097};
Jeff Kirsher7bfa4812006-01-12 16:50:41 -080098
Jeff Kirsher7bfa4812006-01-12 16:50:41 -080099#define E1000_QUEUE_STATS_LEN 0
Denis Chengff8ac602007-09-02 18:30:18 +0800100#define E1000_GLOBAL_STATS_LEN ARRAY_SIZE(e1000_gstrings_stats)
Jeff Kirsher7bfa4812006-01-12 16:50:41 -0800101#define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN + E1000_QUEUE_STATS_LEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = {
103 "Register test (offline)", "Eeprom test (offline)",
104 "Interrupt test (offline)", "Loopback test (offline)",
105 "Link test (on/offline)"
106};
Alejandro Martinez Ruiz4c3616c2007-10-18 10:00:15 +0200107#define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Joe Perches64798842008-07-11 15:17:02 -0700109static int e1000_get_settings(struct net_device *netdev,
110 struct ethtool_cmd *ecmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700112 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 struct e1000_hw *hw = &adapter->hw;
114
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800115 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 ecmd->supported = (SUPPORTED_10baseT_Half |
118 SUPPORTED_10baseT_Full |
119 SUPPORTED_100baseT_Half |
120 SUPPORTED_100baseT_Full |
121 SUPPORTED_1000baseT_Full|
122 SUPPORTED_Autoneg |
123 SUPPORTED_TP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 ecmd->advertising = ADVERTISED_TP;
125
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800126 if (hw->autoneg == 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 ecmd->advertising |= ADVERTISED_Autoneg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 /* the e1000 autoneg seems to match ethtool nicely */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 ecmd->advertising |= hw->autoneg_advertised;
130 }
131
132 ecmd->port = PORT_TP;
133 ecmd->phy_address = hw->phy_addr;
134
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800135 if (hw->mac_type == e1000_82543)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 ecmd->transceiver = XCVR_EXTERNAL;
137 else
138 ecmd->transceiver = XCVR_INTERNAL;
139
140 } else {
141 ecmd->supported = (SUPPORTED_1000baseT_Full |
142 SUPPORTED_FIBRE |
143 SUPPORTED_Autoneg);
144
Malli Chilakala012609a2005-06-17 17:43:06 -0700145 ecmd->advertising = (ADVERTISED_1000baseT_Full |
146 ADVERTISED_FIBRE |
147 ADVERTISED_Autoneg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 ecmd->port = PORT_FIBRE;
150
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800151 if (hw->mac_type >= e1000_82545)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 ecmd->transceiver = XCVR_INTERNAL;
153 else
154 ecmd->transceiver = XCVR_EXTERNAL;
155 }
156
Joe Perches1dc32912008-07-11 15:17:08 -0700157 if (er32(STATUS) & E1000_STATUS_LU) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159 e1000_get_speed_and_duplex(hw, &adapter->link_speed,
160 &adapter->link_duplex);
David Decotigny70739492011-04-27 18:32:40 +0000161 ethtool_cmd_speed_set(ecmd, adapter->link_speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300163 /* unfortunately FULL_DUPLEX != DUPLEX_FULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 * and HALF_DUPLEX != DUPLEX_HALF */
165
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800166 if (adapter->link_duplex == FULL_DUPLEX)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 ecmd->duplex = DUPLEX_FULL;
168 else
169 ecmd->duplex = DUPLEX_HALF;
170 } else {
David Decotigny70739492011-04-27 18:32:40 +0000171 ethtool_cmd_speed_set(ecmd, -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 ecmd->duplex = -1;
173 }
174
175 ecmd->autoneg = ((hw->media_type == e1000_media_type_fiber) ||
176 hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE;
177 return 0;
178}
179
Joe Perches64798842008-07-11 15:17:02 -0700180static int e1000_set_settings(struct net_device *netdev,
181 struct ethtool_cmd *ecmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700183 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 struct e1000_hw *hw = &adapter->hw;
185
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700186 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
187 msleep(1);
188
Jeff Kirsher57128192006-01-12 16:50:28 -0800189 if (ecmd->autoneg == AUTONEG_ENABLE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 hw->autoneg = 1;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800191 if (hw->media_type == e1000_media_type_fiber)
Malli Chilakala012609a2005-06-17 17:43:06 -0700192 hw->autoneg_advertised = ADVERTISED_1000baseT_Full |
193 ADVERTISED_FIBRE |
194 ADVERTISED_Autoneg;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800195 else
Jeff Kirsher2f2ca262006-09-27 12:53:40 -0700196 hw->autoneg_advertised = ecmd->advertising |
197 ADVERTISED_TP |
198 ADVERTISED_Autoneg;
Malli Chilakala012609a2005-06-17 17:43:06 -0700199 ecmd->advertising = hw->autoneg_advertised;
David Decotigny25db0332011-04-27 18:32:39 +0000200 } else {
201 u32 speed = ethtool_cmd_speed(ecmd);
David Decotigny14ad2512011-04-27 18:32:43 +0000202 if (e1000_set_spd_dplx(adapter, speed, ecmd->duplex)) {
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700203 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 return -EINVAL;
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700205 }
David Decotigny25db0332011-04-27 18:32:39 +0000206 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 /* reset the link */
209
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700210 if (netif_running(adapter->netdev)) {
211 e1000_down(adapter);
212 e1000_up(adapter);
213 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 e1000_reset(adapter);
215
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700216 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 return 0;
218}
219
Nick Nunleyb5481922010-02-03 14:49:28 +0000220static u32 e1000_get_link(struct net_device *netdev)
221{
222 struct e1000_adapter *adapter = netdev_priv(netdev);
223
224 /*
225 * If the link is not reported up to netdev, interrupts are disabled,
226 * and so the physical link state may have changed since we last
227 * looked. Set get_link_status to make sure that the true link
228 * state is interrogated, rather than pulling a cached and possibly
229 * stale link state from the driver.
230 */
231 if (!netif_carrier_ok(netdev))
232 adapter->hw.get_link_status = 1;
233
234 return e1000_has_link(adapter);
235}
236
Joe Perches64798842008-07-11 15:17:02 -0700237static void e1000_get_pauseparam(struct net_device *netdev,
238 struct ethtool_pauseparam *pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700240 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 struct e1000_hw *hw = &adapter->hw;
242
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800243 pause->autoneg =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800245
Jeff Kirsher11241b12006-09-27 12:53:28 -0700246 if (hw->fc == E1000_FC_RX_PAUSE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 pause->rx_pause = 1;
Jeff Kirsher11241b12006-09-27 12:53:28 -0700248 else if (hw->fc == E1000_FC_TX_PAUSE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 pause->tx_pause = 1;
Jeff Kirsher11241b12006-09-27 12:53:28 -0700250 else if (hw->fc == E1000_FC_FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 pause->rx_pause = 1;
252 pause->tx_pause = 1;
253 }
254}
255
Joe Perches64798842008-07-11 15:17:02 -0700256static int e1000_set_pauseparam(struct net_device *netdev,
257 struct ethtool_pauseparam *pause)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700259 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700261 int retval = 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 adapter->fc_autoneg = pause->autoneg;
264
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700265 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
266 msleep(1);
267
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800268 if (pause->rx_pause && pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700269 hw->fc = E1000_FC_FULL;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800270 else if (pause->rx_pause && !pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700271 hw->fc = E1000_FC_RX_PAUSE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800272 else if (!pause->rx_pause && pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700273 hw->fc = E1000_FC_TX_PAUSE;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800274 else if (!pause->rx_pause && !pause->tx_pause)
Jeff Kirsher11241b12006-09-27 12:53:28 -0700275 hw->fc = E1000_FC_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277 hw->original_fc = hw->fc;
278
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800279 if (adapter->fc_autoneg == AUTONEG_ENABLE) {
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700280 if (netif_running(adapter->netdev)) {
281 e1000_down(adapter);
282 e1000_up(adapter);
283 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 e1000_reset(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800285 } else
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700286 retval = ((hw->media_type == e1000_media_type_fiber) ?
Auke Kok90fb5132006-11-01 08:47:30 -0800287 e1000_setup_link(hw) : e1000_force_mac_fc(hw));
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800288
Jesse Brandeburg1a821ca2006-08-16 13:38:46 -0700289 clear_bit(__E1000_RESETTING, &adapter->flags);
290 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291}
292
Joe Perches64798842008-07-11 15:17:02 -0700293static u32 e1000_get_rx_csum(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700295 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 return adapter->rx_csum;
297}
298
Joe Perches64798842008-07-11 15:17:02 -0700299static int e1000_set_rx_csum(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700301 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 adapter->rx_csum = data;
303
Auke Kok2db10a02006-06-27 09:06:28 -0700304 if (netif_running(netdev))
305 e1000_reinit_locked(adapter);
306 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 e1000_reset(adapter);
308 return 0;
309}
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800310
Joe Perches64798842008-07-11 15:17:02 -0700311static u32 e1000_get_tx_csum(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
313 return (netdev->features & NETIF_F_HW_CSUM) != 0;
314}
315
Joe Perches64798842008-07-11 15:17:02 -0700316static int e1000_set_tx_csum(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700318 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700319 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Joe Perches1dc32912008-07-11 15:17:08 -0700321 if (hw->mac_type < e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 if (!data)
323 return -EINVAL;
324 return 0;
325 }
326
327 if (data)
328 netdev->features |= NETIF_F_HW_CSUM;
329 else
330 netdev->features &= ~NETIF_F_HW_CSUM;
331
332 return 0;
333}
334
Joe Perches64798842008-07-11 15:17:02 -0700335static int e1000_set_tso(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700337 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700338 struct e1000_hw *hw = &adapter->hw;
339
340 if ((hw->mac_type < e1000_82544) ||
341 (hw->mac_type == e1000_82547))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 return data ? -EINVAL : 0;
343
344 if (data)
345 netdev->features |= NETIF_F_TSO;
346 else
347 netdev->features &= ~NETIF_F_TSO;
Jeff Kirsher7e6c9862006-03-02 18:19:30 -0800348
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000349 netdev->features &= ~NETIF_F_TSO6;
Auke Kok87ca4e52006-11-01 08:47:36 -0800350
Emil Tantilovfeb8f472010-07-26 23:37:21 -0700351 e_info(probe, "TSO is %s\n", data ? "Enabled" : "Disabled");
Joe Perchesc3033b02008-03-21 11:06:25 -0700352 adapter->tso_force = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 return 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800354}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Joe Perches64798842008-07-11 15:17:02 -0700356static u32 e1000_get_msglevel(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700358 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 return adapter->msg_enable;
360}
361
Joe Perches64798842008-07-11 15:17:02 -0700362static void e1000_set_msglevel(struct net_device *netdev, u32 data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700364 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 adapter->msg_enable = data;
366}
367
Joe Perches64798842008-07-11 15:17:02 -0700368static int e1000_get_regs_len(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
370#define E1000_REGS_LEN 32
Joe Perches406874a2008-04-03 10:06:32 -0700371 return E1000_REGS_LEN * sizeof(u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372}
373
Joe Perches64798842008-07-11 15:17:02 -0700374static void e1000_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
375 void *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700377 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700379 u32 *regs_buff = p;
380 u16 phy_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Joe Perches406874a2008-04-03 10:06:32 -0700382 memset(p, 0, E1000_REGS_LEN * sizeof(u32));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
385
Joe Perches1dc32912008-07-11 15:17:08 -0700386 regs_buff[0] = er32(CTRL);
387 regs_buff[1] = er32(STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Joe Perches1dc32912008-07-11 15:17:08 -0700389 regs_buff[2] = er32(RCTL);
390 regs_buff[3] = er32(RDLEN);
391 regs_buff[4] = er32(RDH);
392 regs_buff[5] = er32(RDT);
393 regs_buff[6] = er32(RDTR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Joe Perches1dc32912008-07-11 15:17:08 -0700395 regs_buff[7] = er32(TCTL);
396 regs_buff[8] = er32(TDLEN);
397 regs_buff[9] = er32(TDH);
398 regs_buff[10] = er32(TDT);
399 regs_buff[11] = er32(TIDV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Joe Perches1dc32912008-07-11 15:17:08 -0700401 regs_buff[12] = hw->phy_type; /* PHY type (IGP=1, M88=0) */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800402 if (hw->phy_type == e1000_phy_igp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
404 IGP01E1000_PHY_AGC_A);
405 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A &
406 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700407 regs_buff[13] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
409 IGP01E1000_PHY_AGC_B);
410 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B &
411 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700412 regs_buff[14] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
414 IGP01E1000_PHY_AGC_C);
415 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C &
416 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700417 regs_buff[15] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
419 IGP01E1000_PHY_AGC_D);
420 e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D &
421 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700422 regs_buff[16] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 regs_buff[17] = 0; /* extended 10bt distance (not needed) */
424 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
425 e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS &
426 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700427 regs_buff[18] = (u32)phy_data; /* cable polarity */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT,
429 IGP01E1000_PHY_PCS_INIT_REG);
430 e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG &
431 IGP01E1000_PHY_PAGE_SELECT, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700432 regs_buff[19] = (u32)phy_data; /* cable polarity */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 regs_buff[20] = 0; /* polarity correction enabled (always) */
434 regs_buff[22] = 0; /* phy receive errors (unavailable) */
435 regs_buff[23] = regs_buff[18]; /* mdix mode */
436 e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0);
437 } else {
Auke Kok8fc897b2006-08-28 14:56:16 -0700438 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700439 regs_buff[13] = (u32)phy_data; /* cable length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */
441 regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */
442 regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */
Auke Kok8fc897b2006-08-28 14:56:16 -0700443 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700444 regs_buff[17] = (u32)phy_data; /* extended 10bt distance */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 regs_buff[18] = regs_buff[13]; /* cable polarity */
446 regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */
447 regs_buff[20] = regs_buff[17]; /* polarity correction */
448 /* phy receive errors */
449 regs_buff[22] = adapter->phy_stats.receive_errors;
450 regs_buff[23] = regs_buff[13]; /* mdix mode */
451 }
452 regs_buff[21] = adapter->phy_stats.idle_errors; /* phy idle errors */
453 e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
Joe Perches406874a2008-04-03 10:06:32 -0700454 regs_buff[24] = (u32)phy_data; /* phy local receiver status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 regs_buff[25] = regs_buff[24]; /* phy remote receiver status */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800456 if (hw->mac_type >= e1000_82540 &&
Jesse Brandeburg4ccc12a2006-10-24 14:45:53 -0700457 hw->media_type == e1000_media_type_copper) {
Joe Perches1dc32912008-07-11 15:17:08 -0700458 regs_buff[26] = er32(MANC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 }
460}
461
Joe Perches64798842008-07-11 15:17:02 -0700462static int e1000_get_eeprom_len(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700464 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700465 struct e1000_hw *hw = &adapter->hw;
466
467 return hw->eeprom.word_size * 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468}
469
Joe Perches64798842008-07-11 15:17:02 -0700470static int e1000_get_eeprom(struct net_device *netdev,
471 struct ethtool_eeprom *eeprom, u8 *bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700473 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700475 u16 *eeprom_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 int first_word, last_word;
477 int ret_val = 0;
Joe Perches406874a2008-04-03 10:06:32 -0700478 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800480 if (eeprom->len == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 return -EINVAL;
482
483 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
484
485 first_word = eeprom->offset >> 1;
486 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
487
Joe Perches406874a2008-04-03 10:06:32 -0700488 eeprom_buff = kmalloc(sizeof(u16) *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 (last_word - first_word + 1), GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800490 if (!eeprom_buff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 return -ENOMEM;
492
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800493 if (hw->eeprom.type == e1000_eeprom_spi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 ret_val = e1000_read_eeprom(hw, first_word,
495 last_word - first_word + 1,
496 eeprom_buff);
497 else {
Joe Perchesc7be73b2008-07-11 15:17:28 -0700498 for (i = 0; i < last_word - first_word + 1; i++) {
499 ret_val = e1000_read_eeprom(hw, first_word + i, 1,
500 &eeprom_buff[i]);
501 if (ret_val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 break;
Joe Perchesc7be73b2008-07-11 15:17:28 -0700503 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 }
505
506 /* Device's eeprom is always little-endian, word addressable */
507 for (i = 0; i < last_word - first_word + 1; i++)
508 le16_to_cpus(&eeprom_buff[i]);
509
Joe Perches406874a2008-04-03 10:06:32 -0700510 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 eeprom->len);
512 kfree(eeprom_buff);
513
514 return ret_val;
515}
516
Joe Perches64798842008-07-11 15:17:02 -0700517static int e1000_set_eeprom(struct net_device *netdev,
518 struct ethtool_eeprom *eeprom, u8 *bytes)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700520 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700522 u16 *eeprom_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 void *ptr;
524 int max_len, first_word, last_word, ret_val = 0;
Joe Perches406874a2008-04-03 10:06:32 -0700525 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800527 if (eeprom->len == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 return -EOPNOTSUPP;
529
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800530 if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 return -EFAULT;
532
533 max_len = hw->eeprom.word_size * 2;
534
535 first_word = eeprom->offset >> 1;
536 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
537 eeprom_buff = kmalloc(max_len, GFP_KERNEL);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800538 if (!eeprom_buff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 return -ENOMEM;
540
541 ptr = (void *)eeprom_buff;
542
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800543 if (eeprom->offset & 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 /* need read/modify/write of first changed EEPROM word */
545 /* only the second byte of the word is being modified */
546 ret_val = e1000_read_eeprom(hw, first_word, 1,
547 &eeprom_buff[0]);
548 ptr++;
549 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800550 if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 /* need read/modify/write of last changed EEPROM word */
552 /* only the first byte of the word is being modified */
553 ret_val = e1000_read_eeprom(hw, last_word, 1,
554 &eeprom_buff[last_word - first_word]);
555 }
556
557 /* Device's eeprom is always little-endian, word addressable */
558 for (i = 0; i < last_word - first_word + 1; i++)
559 le16_to_cpus(&eeprom_buff[i]);
560
561 memcpy(ptr, bytes, eeprom->len);
562
563 for (i = 0; i < last_word - first_word + 1; i++)
564 eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]);
565
566 ret_val = e1000_write_eeprom(hw, first_word,
567 last_word - first_word + 1, eeprom_buff);
568
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000569 /* Update the checksum over the first part of the EEPROM if needed */
570 if ((ret_val == 0) && (first_word <= EEPROM_CHECKSUM_REG))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 e1000_update_eeprom_checksum(hw);
572
573 kfree(eeprom_buff);
574 return ret_val;
575}
576
Joe Perches64798842008-07-11 15:17:02 -0700577static void e1000_get_drvinfo(struct net_device *netdev,
578 struct ethtool_drvinfo *drvinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700580 struct e1000_adapter *adapter = netdev_priv(netdev);
Jeff Kirshera2917e22006-01-12 16:51:23 -0800581 char firmware_version[32];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583 strncpy(drvinfo->driver, e1000_driver_name, 32);
584 strncpy(drvinfo->version, e1000_driver_version, 32);
Jeff Kirshera2917e22006-01-12 16:51:23 -0800585
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000586 sprintf(firmware_version, "N/A");
Jeff Kirshera2917e22006-01-12 16:51:23 -0800587 strncpy(drvinfo->fw_version, firmware_version, 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 drvinfo->regdump_len = e1000_get_regs_len(netdev);
590 drvinfo->eedump_len = e1000_get_eeprom_len(netdev);
591}
592
Joe Perches64798842008-07-11 15:17:02 -0700593static void e1000_get_ringparam(struct net_device *netdev,
594 struct ethtool_ringparam *ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700596 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700597 struct e1000_hw *hw = &adapter->hw;
598 e1000_mac_type mac_type = hw->mac_type;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400599 struct e1000_tx_ring *txdr = adapter->tx_ring;
600 struct e1000_rx_ring *rxdr = adapter->rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
602 ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD :
603 E1000_MAX_82544_RXD;
604 ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD :
605 E1000_MAX_82544_TXD;
606 ring->rx_mini_max_pending = 0;
607 ring->rx_jumbo_max_pending = 0;
608 ring->rx_pending = rxdr->count;
609 ring->tx_pending = txdr->count;
610 ring->rx_mini_pending = 0;
611 ring->rx_jumbo_pending = 0;
612}
613
Joe Perches64798842008-07-11 15:17:02 -0700614static int e1000_set_ringparam(struct net_device *netdev,
615 struct ethtool_ringparam *ring)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616{
Malli Chilakala60490fe2005-06-17 17:41:45 -0700617 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700618 struct e1000_hw *hw = &adapter->hw;
619 e1000_mac_type mac_type = hw->mac_type;
Vasily Averin793fab72006-09-27 12:54:14 -0700620 struct e1000_tx_ring *txdr, *tx_old;
621 struct e1000_rx_ring *rxdr, *rx_old;
Yan Burman1c7e5b12007-03-06 08:58:04 -0800622 int i, err;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400623
Jeff Kirsher0989aa42006-03-02 18:17:16 -0800624 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
625 return -EINVAL;
626
Auke Kok2db10a02006-06-27 09:06:28 -0700627 while (test_and_set_bit(__E1000_RESETTING, &adapter->flags))
628 msleep(1);
629
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400630 if (netif_running(adapter->netdev))
631 e1000_down(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
633 tx_old = adapter->tx_ring;
634 rx_old = adapter->rx_ring;
635
Vasily Averin793fab72006-09-27 12:54:14 -0700636 err = -ENOMEM;
Yan Burman1c7e5b12007-03-06 08:58:04 -0800637 txdr = kcalloc(adapter->num_tx_queues, sizeof(struct e1000_tx_ring), GFP_KERNEL);
Vasily Averin793fab72006-09-27 12:54:14 -0700638 if (!txdr)
639 goto err_alloc_tx;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400640
Yan Burman1c7e5b12007-03-06 08:58:04 -0800641 rxdr = kcalloc(adapter->num_rx_queues, sizeof(struct e1000_rx_ring), GFP_KERNEL);
Vasily Averin793fab72006-09-27 12:54:14 -0700642 if (!rxdr)
643 goto err_alloc_rx;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400644
Vasily Averin793fab72006-09-27 12:54:14 -0700645 adapter->tx_ring = txdr;
646 adapter->rx_ring = rxdr;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400647
Joe Perches406874a2008-04-03 10:06:32 -0700648 rxdr->count = max(ring->rx_pending,(u32)E1000_MIN_RXD);
649 rxdr->count = min(rxdr->count,(u32)(mac_type < e1000_82544 ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 E1000_MAX_RXD : E1000_MAX_82544_RXD));
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700651 rxdr->count = ALIGN(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Joe Perches406874a2008-04-03 10:06:32 -0700653 txdr->count = max(ring->tx_pending,(u32)E1000_MIN_TXD);
654 txdr->count = min(txdr->count,(u32)(mac_type < e1000_82544 ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 E1000_MAX_TXD : E1000_MAX_82544_TXD));
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -0700656 txdr->count = ALIGN(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800658 for (i = 0; i < adapter->num_tx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400659 txdr[i].count = txdr->count;
Jeff Kirsherf56799e2006-01-12 16:50:39 -0800660 for (i = 0; i < adapter->num_rx_queues; i++)
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400661 rxdr[i].count = rxdr->count;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400662
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800663 if (netif_running(adapter->netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 /* Try to get new resources before deleting old */
Joe Perchesc7be73b2008-07-11 15:17:28 -0700665 err = e1000_setup_all_rx_resources(adapter);
666 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 goto err_setup_rx;
Joe Perchesc7be73b2008-07-11 15:17:28 -0700668 err = e1000_setup_all_tx_resources(adapter);
669 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 goto err_setup_tx;
671
672 /* save the new, restore the old in order to free it,
673 * then restore the new back again */
674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 adapter->rx_ring = rx_old;
676 adapter->tx_ring = tx_old;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400677 e1000_free_all_rx_resources(adapter);
678 e1000_free_all_tx_resources(adapter);
679 kfree(tx_old);
680 kfree(rx_old);
Vasily Averin793fab72006-09-27 12:54:14 -0700681 adapter->rx_ring = rxdr;
682 adapter->tx_ring = txdr;
Joe Perchesc7be73b2008-07-11 15:17:28 -0700683 err = e1000_up(adapter);
684 if (err)
Auke Kok2db10a02006-06-27 09:06:28 -0700685 goto err_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 }
687
Auke Kok2db10a02006-06-27 09:06:28 -0700688 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 return 0;
690err_setup_tx:
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400691 e1000_free_all_rx_resources(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692err_setup_rx:
693 adapter->rx_ring = rx_old;
694 adapter->tx_ring = tx_old;
Vasily Averin793fab72006-09-27 12:54:14 -0700695 kfree(rxdr);
696err_alloc_rx:
697 kfree(txdr);
698err_alloc_tx:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 e1000_up(adapter);
Auke Kok2db10a02006-06-27 09:06:28 -0700700err_setup:
701 clear_bit(__E1000_RESETTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 return err;
703}
704
Joe Perches64798842008-07-11 15:17:02 -0700705static bool reg_pattern_test(struct e1000_adapter *adapter, u64 *data, int reg,
706 u32 mask, u32 write)
Joe Perches7e643002007-11-13 20:52:05 -0800707{
Joe Perches1dc32912008-07-11 15:17:08 -0700708 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700709 static const u32 test[] =
Joe Perches7e643002007-11-13 20:52:05 -0800710 {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF};
Joe Perches1dc32912008-07-11 15:17:08 -0700711 u8 __iomem *address = hw->hw_addr + reg;
Joe Perches406874a2008-04-03 10:06:32 -0700712 u32 read;
Joe Perches7e643002007-11-13 20:52:05 -0800713 int i;
714
715 for (i = 0; i < ARRAY_SIZE(test); i++) {
716 writel(write & test[i], address);
717 read = readl(address);
718 if (read != (write & test[i] & mask)) {
Emil Tantilovfeb8f472010-07-26 23:37:21 -0700719 e_err(drv, "pattern test reg %04X failed: "
720 "got 0x%08X expected 0x%08X\n",
721 reg, read, (write & test[i] & mask));
Joe Perches7e643002007-11-13 20:52:05 -0800722 *data = reg;
723 return true;
724 }
725 }
726 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727}
728
Joe Perches64798842008-07-11 15:17:02 -0700729static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data, int reg,
730 u32 mask, u32 write)
Joe Perches7e643002007-11-13 20:52:05 -0800731{
Joe Perches1dc32912008-07-11 15:17:08 -0700732 struct e1000_hw *hw = &adapter->hw;
733 u8 __iomem *address = hw->hw_addr + reg;
Joe Perches406874a2008-04-03 10:06:32 -0700734 u32 read;
Joe Perches7e643002007-11-13 20:52:05 -0800735
736 writel(write & mask, address);
737 read = readl(address);
738 if ((read & mask) != (write & mask)) {
Emil Tantilovfeb8f472010-07-26 23:37:21 -0700739 e_err(drv, "set/check reg %04X test failed: "
Emil Tantilov675ad472010-04-27 14:02:58 +0000740 "got 0x%08X expected 0x%08X\n",
741 reg, (read & mask), (write & mask));
Joe Perches7e643002007-11-13 20:52:05 -0800742 *data = reg;
743 return true;
744 }
745 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746}
747
Joe Perches7e643002007-11-13 20:52:05 -0800748#define REG_PATTERN_TEST(reg, mask, write) \
749 do { \
750 if (reg_pattern_test(adapter, data, \
Joe Perches1dc32912008-07-11 15:17:08 -0700751 (hw->mac_type >= e1000_82543) \
Joe Perches7e643002007-11-13 20:52:05 -0800752 ? E1000_##reg : E1000_82542_##reg, \
753 mask, write)) \
754 return 1; \
755 } while (0)
756
757#define REG_SET_AND_CHECK(reg, mask, write) \
758 do { \
759 if (reg_set_and_check(adapter, data, \
Joe Perches1dc32912008-07-11 15:17:08 -0700760 (hw->mac_type >= e1000_82543) \
Joe Perches7e643002007-11-13 20:52:05 -0800761 ? E1000_##reg : E1000_82542_##reg, \
762 mask, write)) \
763 return 1; \
764 } while (0)
765
Joe Perches64798842008-07-11 15:17:02 -0700766static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767{
Joe Perches406874a2008-04-03 10:06:32 -0700768 u32 value, before, after;
769 u32 i, toggle;
Joe Perches1dc32912008-07-11 15:17:08 -0700770 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
772 /* The status register is Read Only, so a write should fail.
773 * Some bits that get toggled are ignored.
774 */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000775
Mallikarjuna R Chilakala868d5302005-10-04 06:58:59 -0400776 /* there are several bits on newer hardware that are r/w */
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000777 toggle = 0xFFFFF833;
Malli Chilakalab01f6692005-06-17 17:42:29 -0700778
Joe Perches1dc32912008-07-11 15:17:08 -0700779 before = er32(STATUS);
780 value = (er32(STATUS) & toggle);
781 ew32(STATUS, toggle);
782 after = er32(STATUS) & toggle;
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800783 if (value != after) {
Emil Tantilovfeb8f472010-07-26 23:37:21 -0700784 e_err(drv, "failed STATUS register test got: "
Emil Tantilov675ad472010-04-27 14:02:58 +0000785 "0x%08X expected: 0x%08X\n", after, value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 *data = 1;
787 return 1;
788 }
Malli Chilakalab01f6692005-06-17 17:42:29 -0700789 /* restore previous status */
Joe Perches1dc32912008-07-11 15:17:08 -0700790 ew32(STATUS, before);
Auke Kok90fb5132006-11-01 08:47:30 -0800791
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000792 REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF);
793 REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF);
794 REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF);
795 REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF);
Auke Kok90fb5132006-11-01 08:47:30 -0800796
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF);
798 REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
799 REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF);
800 REG_PATTERN_TEST(RDH, 0x0000FFFF, 0x0000FFFF);
801 REG_PATTERN_TEST(RDT, 0x0000FFFF, 0x0000FFFF);
802 REG_PATTERN_TEST(FCRTH, 0x0000FFF8, 0x0000FFF8);
803 REG_PATTERN_TEST(FCTTV, 0x0000FFFF, 0x0000FFFF);
804 REG_PATTERN_TEST(TIPG, 0x3FFFFFFF, 0x3FFFFFFF);
805 REG_PATTERN_TEST(TDBAH, 0xFFFFFFFF, 0xFFFFFFFF);
806 REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF);
807
808 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000);
Auke Kok90fb5132006-11-01 08:47:30 -0800809
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000810 before = 0x06DFB3FE;
Auke Kokcd94dd02006-06-27 09:08:22 -0700811 REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000);
813
Joe Perches1dc32912008-07-11 15:17:08 -0700814 if (hw->mac_type >= e1000_82543) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
Auke Kokcd94dd02006-06-27 09:08:22 -0700816 REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000818 REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF);
820 REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF);
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000821 value = E1000_RAR_ENTRIES;
Auke Kokcd94dd02006-06-27 09:08:22 -0700822 for (i = 0; i < value; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF,
Auke Kok90fb5132006-11-01 08:47:30 -0800824 0xFFFFFFFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 }
826
827 } else {
828
829 REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF);
830 REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF);
831 REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF);
832 REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF);
833
834 }
835
Jesse Brandeburg1532ece2009-09-25 12:16:14 +0000836 value = E1000_MC_TBL_SIZE;
Auke Kokcd94dd02006-06-27 09:08:22 -0700837 for (i = 0; i < value; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF);
839
840 *data = 0;
841 return 0;
842}
843
Joe Perches64798842008-07-11 15:17:02 -0700844static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845{
Joe Perches1dc32912008-07-11 15:17:08 -0700846 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -0700847 u16 temp;
848 u16 checksum = 0;
849 u16 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 *data = 0;
852 /* Read and add up the contents of the EEPROM */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800853 for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
Joe Perches1dc32912008-07-11 15:17:08 -0700854 if ((e1000_read_eeprom(hw, i, 1, &temp)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 *data = 1;
856 break;
857 }
858 checksum += temp;
859 }
860
861 /* If Checksum is not Correct return error else test passed */
Joe Perchese982f172008-07-11 15:17:18 -0700862 if ((checksum != (u16)EEPROM_SUM) && !(*data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 *data = 2;
864
865 return *data;
866}
867
Joe Perches64798842008-07-11 15:17:02 -0700868static irqreturn_t e1000_test_intr(int irq, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869{
Joe Perchese982f172008-07-11 15:17:18 -0700870 struct net_device *netdev = (struct net_device *)data;
Malli Chilakala60490fe2005-06-17 17:41:45 -0700871 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -0700872 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
Joe Perches1dc32912008-07-11 15:17:08 -0700874 adapter->test_icr |= er32(ICR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
876 return IRQ_HANDLED;
877}
878
Joe Perches64798842008-07-11 15:17:02 -0700879static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880{
881 struct net_device *netdev = adapter->netdev;
Joe Perches406874a2008-04-03 10:06:32 -0700882 u32 mask, i = 0;
Joe Perchesc3033b02008-03-21 11:06:25 -0700883 bool shared_int = true;
Joe Perches406874a2008-04-03 10:06:32 -0700884 u32 irq = adapter->pdev->irq;
Joe Perches1dc32912008-07-11 15:17:08 -0700885 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887 *data = 0;
888
Auke Kok8fc897b2006-08-28 14:56:16 -0700889 /* NOTE: we don't test MSI interrupts here, yet */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 /* Hook up test interrupt handler just for this test */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800891 if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name,
Auke Kok90fb5132006-11-01 08:47:30 -0800892 netdev))
Joe Perchesc3033b02008-03-21 11:06:25 -0700893 shared_int = false;
Joe Perchesa0607fd2009-11-18 23:29:17 -0800894 else if (request_irq(irq, e1000_test_intr, IRQF_SHARED,
Auke Kok90fb5132006-11-01 08:47:30 -0800895 netdev->name, netdev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 *data = 1;
897 return -1;
898 }
Emil Tantilovfeb8f472010-07-26 23:37:21 -0700899 e_info(hw, "testing %s interrupt\n", (shared_int ?
900 "shared" : "unshared"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
902 /* Disable all the interrupts */
Joe Perches1dc32912008-07-11 15:17:08 -0700903 ew32(IMC, 0xFFFFFFFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400904 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
906 /* Test each interrupt */
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800907 for (; i < 10; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
909 /* Interrupt to test */
910 mask = 1 << i;
911
Auke Kok76c224b2006-05-23 13:36:06 -0700912 if (!shared_int) {
913 /* Disable the interrupt to be reported in
914 * the cause register and then force the same
915 * interrupt and see if one gets posted. If
916 * an interrupt was posted to the bus, the
917 * test failed.
918 */
919 adapter->test_icr = 0;
Joe Perches1dc32912008-07-11 15:17:08 -0700920 ew32(IMC, mask);
921 ew32(ICS, mask);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400922 msleep(10);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800923
Auke Kok76c224b2006-05-23 13:36:06 -0700924 if (adapter->test_icr & mask) {
925 *data = 3;
926 break;
927 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 }
929
930 /* Enable the interrupt to be reported in
931 * the cause register and then force the same
932 * interrupt and see if one gets posted. If
933 * an interrupt was not posted to the bus, the
934 * test failed.
935 */
936 adapter->test_icr = 0;
Joe Perches1dc32912008-07-11 15:17:08 -0700937 ew32(IMS, mask);
938 ew32(ICS, mask);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400939 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800941 if (!(adapter->test_icr & mask)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 *data = 4;
943 break;
944 }
945
Auke Kok76c224b2006-05-23 13:36:06 -0700946 if (!shared_int) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 /* Disable the other interrupts to be reported in
948 * the cause register and then force the other
949 * interrupts and see if any get posted. If
950 * an interrupt was posted to the bus, the
951 * test failed.
952 */
953 adapter->test_icr = 0;
Joe Perches1dc32912008-07-11 15:17:08 -0700954 ew32(IMC, ~mask & 0x00007FFF);
955 ew32(ICS, ~mask & 0x00007FFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400956 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800958 if (adapter->test_icr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 *data = 5;
960 break;
961 }
962 }
963 }
964
965 /* Disable all the interrupts */
Joe Perches1dc32912008-07-11 15:17:08 -0700966 ew32(IMC, 0xFFFFFFFF);
Jeff Garzikf8ec4732006-09-19 15:27:07 -0400967 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
969 /* Unhook test interrupt handler */
970 free_irq(irq, netdev);
971
972 return *data;
973}
974
Joe Perches64798842008-07-11 15:17:02 -0700975static void e1000_free_desc_rings(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976{
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -0400977 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
978 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 struct pci_dev *pdev = adapter->pdev;
980 int i;
981
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800982 if (txdr->desc && txdr->buffer_info) {
983 for (i = 0; i < txdr->count; i++) {
984 if (txdr->buffer_info[i].dma)
Nick Nunleyb16f53b2010-04-27 13:08:45 +0000985 dma_unmap_single(&pdev->dev,
986 txdr->buffer_info[i].dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 txdr->buffer_info[i].length,
Nick Nunleyb16f53b2010-04-27 13:08:45 +0000988 DMA_TO_DEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800989 if (txdr->buffer_info[i].skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 dev_kfree_skb(txdr->buffer_info[i].skb);
991 }
992 }
993
Jesse Brandeburg96838a42006-01-18 13:01:39 -0800994 if (rxdr->desc && rxdr->buffer_info) {
995 for (i = 0; i < rxdr->count; i++) {
996 if (rxdr->buffer_info[i].dma)
Nick Nunleyb16f53b2010-04-27 13:08:45 +0000997 dma_unmap_single(&pdev->dev,
998 rxdr->buffer_info[i].dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 rxdr->buffer_info[i].length,
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001000 DMA_FROM_DEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001001 if (rxdr->buffer_info[i].skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 dev_kfree_skb(rxdr->buffer_info[i].skb);
1003 }
1004 }
1005
Jeff Kirsherf5645112006-01-12 16:51:01 -08001006 if (txdr->desc) {
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001007 dma_free_coherent(&pdev->dev, txdr->size, txdr->desc,
1008 txdr->dma);
John W. Linville6b27adb2005-11-08 15:59:30 -05001009 txdr->desc = NULL;
1010 }
Jeff Kirsherf5645112006-01-12 16:51:01 -08001011 if (rxdr->desc) {
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001012 dma_free_coherent(&pdev->dev, rxdr->size, rxdr->desc,
1013 rxdr->dma);
John W. Linville6b27adb2005-11-08 15:59:30 -05001014 rxdr->desc = NULL;
1015 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
Jesper Juhlb4558ea2005-10-28 16:53:13 -04001017 kfree(txdr->buffer_info);
John W. Linville6b27adb2005-11-08 15:59:30 -05001018 txdr->buffer_info = NULL;
Jesper Juhlb4558ea2005-10-28 16:53:13 -04001019 kfree(rxdr->buffer_info);
John W. Linville6b27adb2005-11-08 15:59:30 -05001020 rxdr->buffer_info = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021}
1022
Joe Perches64798842008-07-11 15:17:02 -07001023static int e1000_setup_desc_rings(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024{
Joe Perches1dc32912008-07-11 15:17:08 -07001025 struct e1000_hw *hw = &adapter->hw;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001026 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1027 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 struct pci_dev *pdev = adapter->pdev;
Joe Perches406874a2008-04-03 10:06:32 -07001029 u32 rctl;
Yan Burman1c7e5b12007-03-06 08:58:04 -08001030 int i, ret_val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
1032 /* Setup Tx descriptor ring and Tx buffers */
1033
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001034 if (!txdr->count)
1035 txdr->count = E1000_DEFAULT_TXD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
Joe Perchesc7be73b2008-07-11 15:17:28 -07001037 txdr->buffer_info = kcalloc(txdr->count, sizeof(struct e1000_buffer),
1038 GFP_KERNEL);
1039 if (!txdr->buffer_info) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 ret_val = 1;
1041 goto err_nomem;
1042 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
1044 txdr->size = txdr->count * sizeof(struct e1000_tx_desc);
Milind Arun Choudhary9099cfb2007-04-27 13:55:29 -07001045 txdr->size = ALIGN(txdr->size, 4096);
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001046 txdr->desc = dma_alloc_coherent(&pdev->dev, txdr->size, &txdr->dma,
1047 GFP_KERNEL);
Joe Perchesc7be73b2008-07-11 15:17:28 -07001048 if (!txdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 ret_val = 2;
1050 goto err_nomem;
1051 }
1052 memset(txdr->desc, 0, txdr->size);
1053 txdr->next_to_use = txdr->next_to_clean = 0;
1054
Joe Perchese982f172008-07-11 15:17:18 -07001055 ew32(TDBAL, ((u64)txdr->dma & 0x00000000FFFFFFFF));
1056 ew32(TDBAH, ((u64)txdr->dma >> 32));
Joe Perches1dc32912008-07-11 15:17:08 -07001057 ew32(TDLEN, txdr->count * sizeof(struct e1000_tx_desc));
1058 ew32(TDH, 0);
1059 ew32(TDT, 0);
1060 ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN |
1061 E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT |
1062 E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001064 for (i = 0; i < txdr->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i);
1066 struct sk_buff *skb;
1067 unsigned int size = 1024;
1068
Joe Perchesc7be73b2008-07-11 15:17:28 -07001069 skb = alloc_skb(size, GFP_KERNEL);
1070 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 ret_val = 3;
1072 goto err_nomem;
1073 }
1074 skb_put(skb, size);
1075 txdr->buffer_info[i].skb = skb;
1076 txdr->buffer_info[i].length = skb->len;
1077 txdr->buffer_info[i].dma =
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001078 dma_map_single(&pdev->dev, skb->data, skb->len,
1079 DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 tx_desc->buffer_addr = cpu_to_le64(txdr->buffer_info[i].dma);
1081 tx_desc->lower.data = cpu_to_le32(skb->len);
1082 tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP |
1083 E1000_TXD_CMD_IFCS |
1084 E1000_TXD_CMD_RPS);
1085 tx_desc->upper.data = 0;
1086 }
1087
1088 /* Setup Rx descriptor ring and Rx buffers */
1089
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001090 if (!rxdr->count)
1091 rxdr->count = E1000_DEFAULT_RXD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
Joe Perchesc7be73b2008-07-11 15:17:28 -07001093 rxdr->buffer_info = kcalloc(rxdr->count, sizeof(struct e1000_buffer),
1094 GFP_KERNEL);
1095 if (!rxdr->buffer_info) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 ret_val = 4;
1097 goto err_nomem;
1098 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
1100 rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc);
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001101 rxdr->desc = dma_alloc_coherent(&pdev->dev, rxdr->size, &rxdr->dma,
1102 GFP_KERNEL);
Joe Perchesc7be73b2008-07-11 15:17:28 -07001103 if (!rxdr->desc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 ret_val = 5;
1105 goto err_nomem;
1106 }
1107 memset(rxdr->desc, 0, rxdr->size);
1108 rxdr->next_to_use = rxdr->next_to_clean = 0;
1109
Joe Perches1dc32912008-07-11 15:17:08 -07001110 rctl = er32(RCTL);
1111 ew32(RCTL, rctl & ~E1000_RCTL_EN);
Joe Perchese982f172008-07-11 15:17:18 -07001112 ew32(RDBAL, ((u64)rxdr->dma & 0xFFFFFFFF));
1113 ew32(RDBAH, ((u64)rxdr->dma >> 32));
Joe Perches1dc32912008-07-11 15:17:08 -07001114 ew32(RDLEN, rxdr->size);
1115 ew32(RDH, 0);
1116 ew32(RDT, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 |
1118 E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
Joe Perches1dc32912008-07-11 15:17:08 -07001119 (hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
1120 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001122 for (i = 0; i < rxdr->count; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i);
1124 struct sk_buff *skb;
1125
Joe Perchesc7be73b2008-07-11 15:17:28 -07001126 skb = alloc_skb(E1000_RXBUFFER_2048 + NET_IP_ALIGN, GFP_KERNEL);
1127 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 ret_val = 6;
1129 goto err_nomem;
1130 }
1131 skb_reserve(skb, NET_IP_ALIGN);
1132 rxdr->buffer_info[i].skb = skb;
1133 rxdr->buffer_info[i].length = E1000_RXBUFFER_2048;
1134 rxdr->buffer_info[i].dma =
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001135 dma_map_single(&pdev->dev, skb->data,
1136 E1000_RXBUFFER_2048, DMA_FROM_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 rx_desc->buffer_addr = cpu_to_le64(rxdr->buffer_info[i].dma);
1138 memset(skb->data, 0x00, skb->len);
1139 }
1140
1141 return 0;
1142
1143err_nomem:
1144 e1000_free_desc_rings(adapter);
1145 return ret_val;
1146}
1147
Joe Perches64798842008-07-11 15:17:02 -07001148static void e1000_phy_disable_receiver(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149{
Joe Perches1dc32912008-07-11 15:17:08 -07001150 struct e1000_hw *hw = &adapter->hw;
1151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
Joe Perches1dc32912008-07-11 15:17:08 -07001153 e1000_write_phy_reg(hw, 29, 0x001F);
1154 e1000_write_phy_reg(hw, 30, 0x8FFC);
1155 e1000_write_phy_reg(hw, 29, 0x001A);
1156 e1000_write_phy_reg(hw, 30, 0x8FF0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157}
1158
Joe Perches64798842008-07-11 15:17:02 -07001159static void e1000_phy_reset_clk_and_crs(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160{
Joe Perches1dc32912008-07-11 15:17:08 -07001161 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001162 u16 phy_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
1164 /* Because we reset the PHY above, we need to re-force TX_CLK in the
1165 * Extended PHY Specific Control Register to 25MHz clock. This
1166 * value defaults back to a 2.5MHz clock when the PHY is reset.
1167 */
Joe Perches1dc32912008-07-11 15:17:08 -07001168 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 phy_reg |= M88E1000_EPSCR_TX_CLK_25;
Joe Perches1dc32912008-07-11 15:17:08 -07001170 e1000_write_phy_reg(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 M88E1000_EXT_PHY_SPEC_CTRL, phy_reg);
1172
1173 /* In addition, because of the s/w reset above, we need to enable
1174 * CRS on TX. This must be set for both full and half duplex
1175 * operation.
1176 */
Joe Perches1dc32912008-07-11 15:17:08 -07001177 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 phy_reg |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Joe Perches1dc32912008-07-11 15:17:08 -07001179 e1000_write_phy_reg(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 M88E1000_PHY_SPEC_CTRL, phy_reg);
1181}
1182
Joe Perches64798842008-07-11 15:17:02 -07001183static int e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184{
Joe Perches1dc32912008-07-11 15:17:08 -07001185 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001186 u32 ctrl_reg;
1187 u16 phy_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
1189 /* Setup the Device Control Register for PHY loopback test. */
1190
Joe Perches1dc32912008-07-11 15:17:08 -07001191 ctrl_reg = er32(CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 ctrl_reg |= (E1000_CTRL_ILOS | /* Invert Loss-Of-Signal */
1193 E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1194 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1195 E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */
1196 E1000_CTRL_FD); /* Force Duplex to FULL */
1197
Joe Perches1dc32912008-07-11 15:17:08 -07001198 ew32(CTRL, ctrl_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
1200 /* Read the PHY Specific Control Register (0x10) */
Joe Perches1dc32912008-07-11 15:17:08 -07001201 e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
1203 /* Clear Auto-Crossover bits in PHY Specific Control Register
1204 * (bits 6:5).
1205 */
1206 phy_reg &= ~M88E1000_PSCR_AUTO_X_MODE;
Joe Perches1dc32912008-07-11 15:17:08 -07001207 e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
1209 /* Perform software reset on the PHY */
Joe Perches1dc32912008-07-11 15:17:08 -07001210 e1000_phy_reset(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212 /* Have to setup TX_CLK and TX_CRS after software reset */
1213 e1000_phy_reset_clk_and_crs(adapter);
1214
Joe Perches1dc32912008-07-11 15:17:08 -07001215 e1000_write_phy_reg(hw, PHY_CTRL, 0x8100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
1217 /* Wait for reset to complete. */
1218 udelay(500);
1219
1220 /* Have to setup TX_CLK and TX_CRS after software reset */
1221 e1000_phy_reset_clk_and_crs(adapter);
1222
1223 /* Write out to PHY registers 29 and 30 to disable the Receiver. */
1224 e1000_phy_disable_receiver(adapter);
1225
1226 /* Set the loopback bit in the PHY control register. */
Joe Perches1dc32912008-07-11 15:17:08 -07001227 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 phy_reg |= MII_CR_LOOPBACK;
Joe Perches1dc32912008-07-11 15:17:08 -07001229 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
1231 /* Setup TX_CLK and TX_CRS one more time. */
1232 e1000_phy_reset_clk_and_crs(adapter);
1233
1234 /* Check Phy Configuration */
Joe Perches1dc32912008-07-11 15:17:08 -07001235 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001236 if (phy_reg != 0x4100)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 return 9;
1238
Joe Perches1dc32912008-07-11 15:17:08 -07001239 e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001240 if (phy_reg != 0x0070)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 return 10;
1242
Joe Perches1dc32912008-07-11 15:17:08 -07001243 e1000_read_phy_reg(hw, 29, &phy_reg);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001244 if (phy_reg != 0x001A)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 return 11;
1246
1247 return 0;
1248}
1249
Joe Perches64798842008-07-11 15:17:02 -07001250static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251{
Joe Perches1dc32912008-07-11 15:17:08 -07001252 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001253 u32 ctrl_reg = 0;
1254 u32 stat_reg = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
Joe Perches1dc32912008-07-11 15:17:08 -07001256 hw->autoneg = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
Joe Perches1dc32912008-07-11 15:17:08 -07001258 if (hw->phy_type == e1000_phy_m88) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 /* Auto-MDI/MDIX Off */
Joe Perches1dc32912008-07-11 15:17:08 -07001260 e1000_write_phy_reg(hw,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 M88E1000_PHY_SPEC_CTRL, 0x0808);
1262 /* reset to update Auto-MDI/MDIX */
Joe Perches1dc32912008-07-11 15:17:08 -07001263 e1000_write_phy_reg(hw, PHY_CTRL, 0x9140);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 /* autoneg off */
Joe Perches1dc32912008-07-11 15:17:08 -07001265 e1000_write_phy_reg(hw, PHY_CTRL, 0x8140);
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
Joe Perches1dc32912008-07-11 15:17:08 -07001268 ctrl_reg = er32(CTRL);
Auke Kokcd94dd02006-06-27 09:08:22 -07001269
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001270 /* force 1000, set loopback */
1271 e1000_write_phy_reg(hw, PHY_CTRL, 0x4140);
Auke Kokcd94dd02006-06-27 09:08:22 -07001272
Jesse Brandeburg1532ece2009-09-25 12:16:14 +00001273 /* Now set up the MAC to the same speed/duplex as the PHY. */
1274 ctrl_reg = er32(CTRL);
1275 ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */
1276 ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */
1277 E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */
1278 E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */
1279 E1000_CTRL_FD); /* Force Duplex to FULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
Joe Perches1dc32912008-07-11 15:17:08 -07001281 if (hw->media_type == e1000_media_type_copper &&
1282 hw->phy_type == e1000_phy_m88)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */
Auke Kok8fc897b2006-08-28 14:56:16 -07001284 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 /* Set the ILOS bit on the fiber Nic is half
1286 * duplex link is detected. */
Joe Perches1dc32912008-07-11 15:17:08 -07001287 stat_reg = er32(STATUS);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001288 if ((stat_reg & E1000_STATUS_FD) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU);
1290 }
1291
Joe Perches1dc32912008-07-11 15:17:08 -07001292 ew32(CTRL, ctrl_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
1294 /* Disable the receiver on the PHY so when a cable is plugged in, the
1295 * PHY does not begin to autoneg when a cable is reconnected to the NIC.
1296 */
Joe Perches1dc32912008-07-11 15:17:08 -07001297 if (hw->phy_type == e1000_phy_m88)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 e1000_phy_disable_receiver(adapter);
1299
1300 udelay(500);
1301
1302 return 0;
1303}
1304
Joe Perches64798842008-07-11 15:17:02 -07001305static int e1000_set_phy_loopback(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306{
Joe Perches1dc32912008-07-11 15:17:08 -07001307 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001308 u16 phy_reg = 0;
1309 u16 count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310
Joe Perches1dc32912008-07-11 15:17:08 -07001311 switch (hw->mac_type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 case e1000_82543:
Joe Perches1dc32912008-07-11 15:17:08 -07001313 if (hw->media_type == e1000_media_type_copper) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 /* Attempt to setup Loopback mode on Non-integrated PHY.
1315 * Some PHY registers get corrupted at random, so
1316 * attempt this 10 times.
1317 */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001318 while (e1000_nonintegrated_phy_loopback(adapter) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 count++ < 10);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001320 if (count < 11)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 return 0;
1322 }
1323 break;
1324
1325 case e1000_82544:
1326 case e1000_82540:
1327 case e1000_82545:
1328 case e1000_82545_rev_3:
1329 case e1000_82546:
1330 case e1000_82546_rev_3:
1331 case e1000_82541:
1332 case e1000_82541_rev_2:
1333 case e1000_82547:
1334 case e1000_82547_rev_2:
1335 return e1000_integrated_phy_loopback(adapter);
1336 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 default:
1338 /* Default PHY loopback work is to read the MII
1339 * control register and assert bit 14 (loopback mode).
1340 */
Joe Perches1dc32912008-07-11 15:17:08 -07001341 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 phy_reg |= MII_CR_LOOPBACK;
Joe Perches1dc32912008-07-11 15:17:08 -07001343 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 return 0;
1345 break;
1346 }
1347
1348 return 8;
1349}
1350
Joe Perches64798842008-07-11 15:17:02 -07001351static int e1000_setup_loopback_test(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352{
Jeff Kirsher49273162006-01-12 16:50:44 -08001353 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001354 u32 rctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
Jeff Kirsher49273162006-01-12 16:50:44 -08001356 if (hw->media_type == e1000_media_type_fiber ||
1357 hw->media_type == e1000_media_type_internal_serdes) {
1358 switch (hw->mac_type) {
1359 case e1000_82545:
1360 case e1000_82546:
1361 case e1000_82545_rev_3:
1362 case e1000_82546_rev_3:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 return e1000_set_phy_loopback(adapter);
Jeff Kirsher49273162006-01-12 16:50:44 -08001364 break;
Jeff Kirsher49273162006-01-12 16:50:44 -08001365 default:
Joe Perches1dc32912008-07-11 15:17:08 -07001366 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 rctl |= E1000_RCTL_LBM_TCVR;
Joe Perches1dc32912008-07-11 15:17:08 -07001368 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 return 0;
1370 }
Jeff Kirsher49273162006-01-12 16:50:44 -08001371 } else if (hw->media_type == e1000_media_type_copper)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 return e1000_set_phy_loopback(adapter);
1373
1374 return 7;
1375}
1376
Joe Perches64798842008-07-11 15:17:02 -07001377static void e1000_loopback_cleanup(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378{
Jeff Kirsher49273162006-01-12 16:50:44 -08001379 struct e1000_hw *hw = &adapter->hw;
Joe Perches406874a2008-04-03 10:06:32 -07001380 u32 rctl;
1381 u16 phy_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
Joe Perches1dc32912008-07-11 15:17:08 -07001383 rctl = er32(RCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
Joe Perches1dc32912008-07-11 15:17:08 -07001385 ew32(RCTL, rctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
Jeff Kirsher49273162006-01-12 16:50:44 -08001387 switch (hw->mac_type) {
Jeff Kirsher49273162006-01-12 16:50:44 -08001388 case e1000_82545:
1389 case e1000_82546:
1390 case e1000_82545_rev_3:
1391 case e1000_82546_rev_3:
1392 default:
Joe Perchesc3033b02008-03-21 11:06:25 -07001393 hw->autoneg = true;
Jeff Kirsher49273162006-01-12 16:50:44 -08001394 e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg);
1395 if (phy_reg & MII_CR_LOOPBACK) {
1396 phy_reg &= ~MII_CR_LOOPBACK;
1397 e1000_write_phy_reg(hw, PHY_CTRL, phy_reg);
1398 e1000_phy_reset(hw);
1399 }
1400 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 }
1402}
1403
Joe Perches64798842008-07-11 15:17:02 -07001404static void e1000_create_lbtest_frame(struct sk_buff *skb,
1405 unsigned int frame_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406{
1407 memset(skb->data, 0xFF, frame_size);
Jeff Kirsherce7393b2006-01-12 16:51:12 -08001408 frame_size &= ~1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
1410 memset(&skb->data[frame_size / 2 + 10], 0xBE, 1);
1411 memset(&skb->data[frame_size / 2 + 12], 0xAF, 1);
1412}
1413
Joe Perches64798842008-07-11 15:17:02 -07001414static int e1000_check_lbtest_frame(struct sk_buff *skb,
1415 unsigned int frame_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416{
Jeff Kirsherce7393b2006-01-12 16:51:12 -08001417 frame_size &= ~1;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001418 if (*(skb->data + 3) == 0xFF) {
1419 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 (*(skb->data + frame_size / 2 + 12) == 0xAF)) {
1421 return 0;
1422 }
1423 }
1424 return 13;
1425}
1426
Joe Perches64798842008-07-11 15:17:02 -07001427static int e1000_run_loopback_test(struct e1000_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428{
Joe Perches1dc32912008-07-11 15:17:08 -07001429 struct e1000_hw *hw = &adapter->hw;
Mallikarjuna R Chilakala581d7082005-10-04 07:01:55 -04001430 struct e1000_tx_ring *txdr = &adapter->test_tx_ring;
1431 struct e1000_rx_ring *rxdr = &adapter->test_rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 struct pci_dev *pdev = adapter->pdev;
Malli Chilakalae4eff722005-04-28 19:38:30 -07001433 int i, j, k, l, lc, good_cnt, ret_val=0;
1434 unsigned long time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Joe Perches1dc32912008-07-11 15:17:08 -07001436 ew32(RDT, rxdr->count - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001438 /* Calculate the loop count based on the largest descriptor ring
Malli Chilakalae4eff722005-04-28 19:38:30 -07001439 * The idea is to wrap the largest ring a number of times using 64
1440 * send/receive pairs during each loop
1441 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001443 if (rxdr->count <= txdr->count)
Malli Chilakalae4eff722005-04-28 19:38:30 -07001444 lc = ((txdr->count / 64) * 2) + 1;
1445 else
1446 lc = ((rxdr->count / 64) * 2) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
Malli Chilakalae4eff722005-04-28 19:38:30 -07001448 k = l = 0;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001449 for (j = 0; j <= lc; j++) { /* loop count loop */
1450 for (i = 0; i < 64; i++) { /* send the packets */
1451 e1000_create_lbtest_frame(txdr->buffer_info[i].skb,
Malli Chilakalae4eff722005-04-28 19:38:30 -07001452 1024);
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001453 dma_sync_single_for_device(&pdev->dev,
1454 txdr->buffer_info[k].dma,
1455 txdr->buffer_info[k].length,
1456 DMA_TO_DEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001457 if (unlikely(++k == txdr->count)) k = 0;
Malli Chilakalae4eff722005-04-28 19:38:30 -07001458 }
Joe Perches1dc32912008-07-11 15:17:08 -07001459 ew32(TDT, k);
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001460 msleep(200);
Malli Chilakalae4eff722005-04-28 19:38:30 -07001461 time = jiffies; /* set the start time for the receive */
1462 good_cnt = 0;
1463 do { /* receive the sent packets */
Nick Nunleyb16f53b2010-04-27 13:08:45 +00001464 dma_sync_single_for_cpu(&pdev->dev,
1465 rxdr->buffer_info[l].dma,
1466 rxdr->buffer_info[l].length,
1467 DMA_FROM_DEVICE);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001468
Malli Chilakalae4eff722005-04-28 19:38:30 -07001469 ret_val = e1000_check_lbtest_frame(
1470 rxdr->buffer_info[l].skb,
1471 1024);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001472 if (!ret_val)
Malli Chilakalae4eff722005-04-28 19:38:30 -07001473 good_cnt++;
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001474 if (unlikely(++l == rxdr->count)) l = 0;
1475 /* time + 20 msecs (200 msecs on 2.4) is more than
1476 * enough time to complete the receives, if it's
Malli Chilakalae4eff722005-04-28 19:38:30 -07001477 * exceeded, break and error off
1478 */
1479 } while (good_cnt < 64 && jiffies < (time + 20));
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001480 if (good_cnt != 64) {
Malli Chilakalae4eff722005-04-28 19:38:30 -07001481 ret_val = 13; /* ret_val is the same as mis-compare */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001482 break;
Malli Chilakalae4eff722005-04-28 19:38:30 -07001483 }
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001484 if (jiffies >= (time + 2)) {
Malli Chilakalae4eff722005-04-28 19:38:30 -07001485 ret_val = 14; /* error code for time out error */
1486 break;
1487 }
1488 } /* end loop count loop */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 return ret_val;
1490}
1491
Joe Perches64798842008-07-11 15:17:02 -07001492static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493{
Joe Perchesc7be73b2008-07-11 15:17:28 -07001494 *data = e1000_setup_desc_rings(adapter);
1495 if (*data)
Jeff Kirsher57128192006-01-12 16:50:28 -08001496 goto out;
Joe Perchesc7be73b2008-07-11 15:17:28 -07001497 *data = e1000_setup_loopback_test(adapter);
1498 if (*data)
Jeff Kirsher57128192006-01-12 16:50:28 -08001499 goto err_loopback;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 *data = e1000_run_loopback_test(adapter);
1501 e1000_loopback_cleanup(adapter);
Jeff Kirsher57128192006-01-12 16:50:28 -08001502
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503err_loopback:
Jeff Kirsher57128192006-01-12 16:50:28 -08001504 e1000_free_desc_rings(adapter);
1505out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 return *data;
1507}
1508
Joe Perches64798842008-07-11 15:17:02 -07001509static int e1000_link_test(struct e1000_adapter *adapter, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510{
Joe Perches1dc32912008-07-11 15:17:08 -07001511 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 *data = 0;
Joe Perches1dc32912008-07-11 15:17:08 -07001513 if (hw->media_type == e1000_media_type_internal_serdes) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 int i = 0;
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00001515 hw->serdes_has_link = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Malli Chilakala26483452005-04-28 19:44:46 -07001517 /* On some blade server designs, link establishment
1518 * could take as long as 2-3 minutes */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 do {
Joe Perches1dc32912008-07-11 15:17:08 -07001520 e1000_check_for_link(hw);
Jesse Brandeburgbe0f0712009-09-25 12:17:44 +00001521 if (hw->serdes_has_link)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 return *data;
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001523 msleep(20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 } while (i++ < 3750);
1525
Malli Chilakala26483452005-04-28 19:44:46 -07001526 *data = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 } else {
Joe Perches1dc32912008-07-11 15:17:08 -07001528 e1000_check_for_link(hw);
1529 if (hw->autoneg) /* if auto_neg is set wait for it */
Jeff Garzikf8ec4732006-09-19 15:27:07 -04001530 msleep(4000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
Joe Perches1dc32912008-07-11 15:17:08 -07001532 if (!(er32(STATUS) & E1000_STATUS_LU)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 *data = 1;
1534 }
1535 }
1536 return *data;
1537}
1538
Joe Perches64798842008-07-11 15:17:02 -07001539static int e1000_get_sset_count(struct net_device *netdev, int sset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540{
Jeff Garzikb9f2c042007-10-03 18:07:32 -07001541 switch (sset) {
1542 case ETH_SS_TEST:
1543 return E1000_TEST_LEN;
1544 case ETH_SS_STATS:
1545 return E1000_STATS_LEN;
1546 default:
1547 return -EOPNOTSUPP;
1548 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549}
1550
Joe Perches64798842008-07-11 15:17:02 -07001551static void e1000_diag_test(struct net_device *netdev,
1552 struct ethtool_test *eth_test, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001554 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001555 struct e1000_hw *hw = &adapter->hw;
Joe Perchesc3033b02008-03-21 11:06:25 -07001556 bool if_running = netif_running(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
Auke Kok1314bbf2006-09-27 12:54:02 -07001558 set_bit(__E1000_TESTING, &adapter->flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001559 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 /* Offline tests */
1561
1562 /* save speed, duplex, autoneg settings */
Joe Perches1dc32912008-07-11 15:17:08 -07001563 u16 autoneg_advertised = hw->autoneg_advertised;
1564 u8 forced_speed_duplex = hw->forced_speed_duplex;
1565 u8 autoneg = hw->autoneg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001567 e_info(hw, "offline testing starting\n");
Jesse Brandeburgd6582662006-08-16 13:31:33 -07001568
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 /* Link test performed before hardware reset so autoneg doesn't
1570 * interfere with test result */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001571 if (e1000_link_test(adapter, &data[4]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 eth_test->flags |= ETH_TEST_FL_FAILED;
1573
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001574 if (if_running)
Auke Kok2db10a02006-06-27 09:06:28 -07001575 /* indicate we're in test mode */
1576 dev_close(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 else
1578 e1000_reset(adapter);
1579
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001580 if (e1000_reg_test(adapter, &data[0]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 eth_test->flags |= ETH_TEST_FL_FAILED;
1582
1583 e1000_reset(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001584 if (e1000_eeprom_test(adapter, &data[1]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 eth_test->flags |= ETH_TEST_FL_FAILED;
1586
1587 e1000_reset(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001588 if (e1000_intr_test(adapter, &data[2]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 eth_test->flags |= ETH_TEST_FL_FAILED;
1590
1591 e1000_reset(adapter);
Jesse Brandeburgd6582662006-08-16 13:31:33 -07001592 /* make sure the phy is powered up */
1593 e1000_power_up_phy(adapter);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001594 if (e1000_loopback_test(adapter, &data[3]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 eth_test->flags |= ETH_TEST_FL_FAILED;
1596
1597 /* restore speed, duplex, autoneg settings */
Joe Perches1dc32912008-07-11 15:17:08 -07001598 hw->autoneg_advertised = autoneg_advertised;
1599 hw->forced_speed_duplex = forced_speed_duplex;
1600 hw->autoneg = autoneg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
1602 e1000_reset(adapter);
Auke Kok1314bbf2006-09-27 12:54:02 -07001603 clear_bit(__E1000_TESTING, &adapter->flags);
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001604 if (if_running)
Auke Kok2db10a02006-06-27 09:06:28 -07001605 dev_open(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 } else {
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001607 e_info(hw, "online testing starting\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 /* Online tests */
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001609 if (e1000_link_test(adapter, &data[4]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 eth_test->flags |= ETH_TEST_FL_FAILED;
1611
Auke Kok90fb5132006-11-01 08:47:30 -08001612 /* Online tests aren't run; pass by default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 data[0] = 0;
1614 data[1] = 0;
1615 data[2] = 0;
1616 data[3] = 0;
Auke Kok2db10a02006-06-27 09:06:28 -07001617
Auke Kok1314bbf2006-09-27 12:54:02 -07001618 clear_bit(__E1000_TESTING, &adapter->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 }
Mallikarjuna R Chilakala352c9f82005-10-04 07:07:24 -04001620 msleep_interruptible(4 * 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621}
1622
Joe Perches64798842008-07-11 15:17:02 -07001623static int e1000_wol_exclusion(struct e1000_adapter *adapter,
1624 struct ethtool_wolinfo *wol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001627 int retval = 1; /* fail by default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001629 switch (hw->device_id) {
Auke Kokdc1f71f2006-10-24 14:45:55 -07001630 case E1000_DEV_ID_82542:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 case E1000_DEV_ID_82543GC_FIBER:
1632 case E1000_DEV_ID_82543GC_COPPER:
1633 case E1000_DEV_ID_82544EI_FIBER:
1634 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1635 case E1000_DEV_ID_82545EM_FIBER:
1636 case E1000_DEV_ID_82545EM_COPPER:
Jeff Kirsher84916822006-03-02 18:18:48 -08001637 case E1000_DEV_ID_82546GB_QUAD_COPPER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001638 case E1000_DEV_ID_82546GB_PCIE:
1639 /* these don't support WoL at all */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 wol->supported = 0;
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001641 break;
1642 case E1000_DEV_ID_82546EB_FIBER:
1643 case E1000_DEV_ID_82546GB_FIBER:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001644 /* Wake events not supported on port B */
Joe Perches1dc32912008-07-11 15:17:08 -07001645 if (er32(STATUS) & E1000_STATUS_FUNC_1) {
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001646 wol->supported = 0;
1647 break;
1648 }
1649 /* return success for non excluded adapter ports */
1650 retval = 0;
1651 break;
1652 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1653 /* quad port adapters only support WoL on port A */
1654 if (!adapter->quad_port_a) {
1655 wol->supported = 0;
1656 break;
1657 }
1658 /* return success for non excluded adapter ports */
1659 retval = 0;
1660 break;
1661 default:
1662 /* dual port cards only support WoL on port A from now on
1663 * unless it was enabled in the eeprom for port B
1664 * so exclude FUNC_1 ports from having WoL enabled */
Joe Perches1dc32912008-07-11 15:17:08 -07001665 if (er32(STATUS) & E1000_STATUS_FUNC_1 &&
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001666 !adapter->eeprom_wol) {
1667 wol->supported = 0;
1668 break;
1669 }
1670
1671 retval = 0;
1672 }
1673
1674 return retval;
1675}
1676
Joe Perches64798842008-07-11 15:17:02 -07001677static void e1000_get_wol(struct net_device *netdev,
1678 struct ethtool_wolinfo *wol)
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001679{
1680 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001681 struct e1000_hw *hw = &adapter->hw;
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001682
1683 wol->supported = WAKE_UCAST | WAKE_MCAST |
1684 WAKE_BCAST | WAKE_MAGIC;
1685 wol->wolopts = 0;
1686
1687 /* this function will set ->supported = 0 and return 1 if wol is not
1688 * supported by this hardware */
\"Rafael J. Wysocki\de126482008-11-07 20:30:19 +00001689 if (e1000_wol_exclusion(adapter, wol) ||
1690 !device_can_wakeup(&adapter->pdev->dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 return;
1692
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001693 /* apply any specific unsupported masks here */
Joe Perches1dc32912008-07-11 15:17:08 -07001694 switch (hw->device_id) {
Jeff Kirsher84916822006-03-02 18:18:48 -08001695 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001696 /* KSP3 does not suppport UCAST wake-ups */
1697 wol->supported &= ~WAKE_UCAST;
Jeff Kirsher84916822006-03-02 18:18:48 -08001698
1699 if (adapter->wol & E1000_WUFC_EX)
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001700 e_err(drv, "Interface does not support directed "
1701 "(unicast) frame wake-up packets\n");
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001702 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 default:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001704 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 }
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001706
1707 if (adapter->wol & E1000_WUFC_EX)
1708 wol->wolopts |= WAKE_UCAST;
1709 if (adapter->wol & E1000_WUFC_MC)
1710 wol->wolopts |= WAKE_MCAST;
1711 if (adapter->wol & E1000_WUFC_BC)
1712 wol->wolopts |= WAKE_BCAST;
1713 if (adapter->wol & E1000_WUFC_MAG)
1714 wol->wolopts |= WAKE_MAGIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715}
1716
Joe Perches64798842008-07-11 15:17:02 -07001717static int e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001719 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 struct e1000_hw *hw = &adapter->hw;
1721
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001722 if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))
1723 return -EOPNOTSUPP;
1724
\"Rafael J. Wysocki\de126482008-11-07 20:30:19 +00001725 if (e1000_wol_exclusion(adapter, wol) ||
1726 !device_can_wakeup(&adapter->pdev->dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 return wol->wolopts ? -EOPNOTSUPP : 0;
1728
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001729 switch (hw->device_id) {
Jeff Kirsher84916822006-03-02 18:18:48 -08001730 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
Jeff Kirsher84916822006-03-02 18:18:48 -08001731 if (wol->wolopts & WAKE_UCAST) {
Emil Tantilovfeb8f472010-07-26 23:37:21 -07001732 e_err(drv, "Interface does not support directed "
1733 "(unicast) frame wake-up packets\n");
Jeff Kirsher84916822006-03-02 18:18:48 -08001734 return -EOPNOTSUPP;
1735 }
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001736 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 default:
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001738 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 }
1740
Jesse Brandeburg120cd572006-08-31 14:27:46 -07001741 /* these settings will always override what we currently have */
1742 adapter->wol = 0;
1743
1744 if (wol->wolopts & WAKE_UCAST)
1745 adapter->wol |= E1000_WUFC_EX;
1746 if (wol->wolopts & WAKE_MCAST)
1747 adapter->wol |= E1000_WUFC_MC;
1748 if (wol->wolopts & WAKE_BCAST)
1749 adapter->wol |= E1000_WUFC_BC;
1750 if (wol->wolopts & WAKE_MAGIC)
1751 adapter->wol |= E1000_WUFC_MAG;
1752
\"Rafael J. Wysocki\de126482008-11-07 20:30:19 +00001753 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
1754
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 return 0;
1756}
1757
Jeff Kirsher64359092011-05-03 05:26:13 +00001758static int e1000_set_phys_id(struct net_device *netdev,
1759 enum ethtool_phys_id_state state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001761 struct e1000_adapter *adapter = netdev_priv(netdev);
Joe Perches1dc32912008-07-11 15:17:08 -07001762 struct e1000_hw *hw = &adapter->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
Jeff Kirsher64359092011-05-03 05:26:13 +00001764 switch (state) {
1765 case ETHTOOL_ID_ACTIVE:
1766 e1000_setup_led(hw);
1767 return 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768
Jeff Kirsher64359092011-05-03 05:26:13 +00001769 case ETHTOOL_ID_ON:
1770 e1000_led_on(hw);
1771 break;
1772
1773 case ETHTOOL_ID_OFF:
1774 e1000_led_off(hw);
1775 break;
1776
1777 case ETHTOOL_ID_INACTIVE:
1778 e1000_cleanup_led(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780
1781 return 0;
1782}
1783
Jesse Brandeburg94c9e5a2009-07-06 10:44:20 +00001784static int e1000_get_coalesce(struct net_device *netdev,
1785 struct ethtool_coalesce *ec)
1786{
1787 struct e1000_adapter *adapter = netdev_priv(netdev);
1788
1789 if (adapter->hw.mac_type < e1000_82545)
1790 return -EOPNOTSUPP;
1791
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001792 if (adapter->itr_setting <= 4)
Jesse Brandeburg94c9e5a2009-07-06 10:44:20 +00001793 ec->rx_coalesce_usecs = adapter->itr_setting;
1794 else
1795 ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting;
1796
1797 return 0;
1798}
1799
1800static int e1000_set_coalesce(struct net_device *netdev,
1801 struct ethtool_coalesce *ec)
1802{
1803 struct e1000_adapter *adapter = netdev_priv(netdev);
1804 struct e1000_hw *hw = &adapter->hw;
1805
1806 if (hw->mac_type < e1000_82545)
1807 return -EOPNOTSUPP;
1808
1809 if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) ||
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001810 ((ec->rx_coalesce_usecs > 4) &&
Jesse Brandeburg94c9e5a2009-07-06 10:44:20 +00001811 (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) ||
1812 (ec->rx_coalesce_usecs == 2))
1813 return -EINVAL;
1814
Jesse Brandeburgeab2abf2010-05-04 22:26:03 +00001815 if (ec->rx_coalesce_usecs == 4) {
1816 adapter->itr = adapter->itr_setting = 4;
1817 } else if (ec->rx_coalesce_usecs <= 3) {
Jesse Brandeburg94c9e5a2009-07-06 10:44:20 +00001818 adapter->itr = 20000;
1819 adapter->itr_setting = ec->rx_coalesce_usecs;
1820 } else {
1821 adapter->itr = (1000000 / ec->rx_coalesce_usecs);
1822 adapter->itr_setting = adapter->itr & ~3;
1823 }
1824
1825 if (adapter->itr_setting != 0)
1826 ew32(ITR, 1000000000 / (adapter->itr * 256));
1827 else
1828 ew32(ITR, 0);
1829
1830 return 0;
1831}
1832
Joe Perches64798842008-07-11 15:17:02 -07001833static int e1000_nway_reset(struct net_device *netdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001835 struct e1000_adapter *adapter = netdev_priv(netdev);
Auke Kok2db10a02006-06-27 09:06:28 -07001836 if (netif_running(netdev))
1837 e1000_reinit_locked(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 return 0;
1839}
1840
Joe Perches64798842008-07-11 15:17:02 -07001841static void e1000_get_ethtool_stats(struct net_device *netdev,
1842 struct ethtool_stats *stats, u64 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843{
Malli Chilakala60490fe2005-06-17 17:41:45 -07001844 struct e1000_adapter *adapter = netdev_priv(netdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 int i;
Ajit Khaparde8328c382009-10-13 01:45:48 +00001846 char *p = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
1848 e1000_update_stats(adapter);
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001849 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
Ajit Khaparde8328c382009-10-13 01:45:48 +00001850 switch (e1000_gstrings_stats[i].type) {
1851 case NETDEV_STATS:
1852 p = (char *) netdev +
1853 e1000_gstrings_stats[i].stat_offset;
1854 break;
1855 case E1000_STATS:
1856 p = (char *) adapter +
1857 e1000_gstrings_stats[i].stat_offset;
1858 break;
1859 }
1860
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001861 data[i] = (e1000_gstrings_stats[i].sizeof_stat ==
Joe Perches406874a2008-04-03 10:06:32 -07001862 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001864/* BUG_ON(i != E1000_STATS_LEN); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865}
1866
Joe Perches64798842008-07-11 15:17:02 -07001867static void e1000_get_strings(struct net_device *netdev, u32 stringset,
1868 u8 *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869{
Joe Perches406874a2008-04-03 10:06:32 -07001870 u8 *p = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 int i;
1872
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001873 switch (stringset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 case ETH_SS_TEST:
Jesse Brandeburg96838a42006-01-18 13:01:39 -08001875 memcpy(data, *e1000_gstrings_test,
Roel Kluinc32bc6e2007-12-05 11:57:30 -08001876 sizeof(e1000_gstrings_test));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 break;
1878 case ETH_SS_STATS:
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001879 for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
1880 memcpy(p, e1000_gstrings_stats[i].stat_string,
1881 ETH_GSTRING_LEN);
1882 p += ETH_GSTRING_LEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 }
Jeff Kirsher7bfa4812006-01-12 16:50:41 -08001884/* BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 break;
1886 }
1887}
1888
Jeff Garzik7282d492006-09-13 14:30:00 -04001889static const struct ethtool_ops e1000_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 .get_settings = e1000_get_settings,
1891 .set_settings = e1000_set_settings,
1892 .get_drvinfo = e1000_get_drvinfo,
1893 .get_regs_len = e1000_get_regs_len,
1894 .get_regs = e1000_get_regs,
1895 .get_wol = e1000_get_wol,
1896 .set_wol = e1000_set_wol,
Auke Kok8fc897b2006-08-28 14:56:16 -07001897 .get_msglevel = e1000_get_msglevel,
1898 .set_msglevel = e1000_set_msglevel,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 .nway_reset = e1000_nway_reset,
Nick Nunleyb5481922010-02-03 14:49:28 +00001900 .get_link = e1000_get_link,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 .get_eeprom_len = e1000_get_eeprom_len,
1902 .get_eeprom = e1000_get_eeprom,
1903 .set_eeprom = e1000_set_eeprom,
1904 .get_ringparam = e1000_get_ringparam,
1905 .set_ringparam = e1000_set_ringparam,
Auke Kok8fc897b2006-08-28 14:56:16 -07001906 .get_pauseparam = e1000_get_pauseparam,
1907 .set_pauseparam = e1000_set_pauseparam,
1908 .get_rx_csum = e1000_get_rx_csum,
1909 .set_rx_csum = e1000_set_rx_csum,
1910 .get_tx_csum = e1000_get_tx_csum,
1911 .set_tx_csum = e1000_set_tx_csum,
Auke Kok8fc897b2006-08-28 14:56:16 -07001912 .set_sg = ethtool_op_set_sg,
Auke Kok8fc897b2006-08-28 14:56:16 -07001913 .set_tso = e1000_set_tso,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 .self_test = e1000_diag_test,
1915 .get_strings = e1000_get_strings,
Jeff Kirsher64359092011-05-03 05:26:13 +00001916 .set_phys_id = e1000_set_phys_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 .get_ethtool_stats = e1000_get_ethtool_stats,
Jesse Brandeburg94c9e5a2009-07-06 10:44:20 +00001918 .get_sset_count = e1000_get_sset_count,
1919 .get_coalesce = e1000_get_coalesce,
1920 .set_coalesce = e1000_set_coalesce,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921};
1922
1923void e1000_set_ethtool_ops(struct net_device *netdev)
1924{
1925 SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops);
1926}