Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 3 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | more details. |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | You should have received a copy of the GNU General Public License along with |
Auke Kok | 0abb6eb | 2006-09-27 12:53:14 -0700 | [diff] [blame] | 16 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | Contact Information: |
| 23 | Linux NICS <linux.nics@intel.com> |
Auke Kok | 3d41e30 | 2006-04-14 19:05:31 -0700 | [diff] [blame] | 24 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 26 | |
| 27 | *******************************************************************************/ |
| 28 | |
| 29 | /* ethtool support for e1000 */ |
| 30 | |
| 31 | #include "e1000.h" |
| 32 | |
| 33 | #include <asm/uaccess.h> |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | struct e1000_stats { |
| 36 | char stat_string[ETH_GSTRING_LEN]; |
| 37 | int sizeof_stat; |
| 38 | int stat_offset; |
| 39 | }; |
| 40 | |
| 41 | #define E1000_STAT(m) sizeof(((struct e1000_adapter *)0)->m), \ |
| 42 | offsetof(struct e1000_adapter, m) |
| 43 | static const struct e1000_stats e1000_gstrings_stats[] = { |
| 44 | { "rx_packets", E1000_STAT(net_stats.rx_packets) }, |
| 45 | { "tx_packets", E1000_STAT(net_stats.tx_packets) }, |
| 46 | { "rx_bytes", E1000_STAT(net_stats.rx_bytes) }, |
| 47 | { "tx_bytes", E1000_STAT(net_stats.tx_bytes) }, |
| 48 | { "rx_errors", E1000_STAT(net_stats.rx_errors) }, |
| 49 | { "tx_errors", E1000_STAT(net_stats.tx_errors) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { "tx_dropped", E1000_STAT(net_stats.tx_dropped) }, |
| 51 | { "multicast", E1000_STAT(net_stats.multicast) }, |
| 52 | { "collisions", E1000_STAT(net_stats.collisions) }, |
| 53 | { "rx_length_errors", E1000_STAT(net_stats.rx_length_errors) }, |
| 54 | { "rx_over_errors", E1000_STAT(net_stats.rx_over_errors) }, |
| 55 | { "rx_crc_errors", E1000_STAT(net_stats.rx_crc_errors) }, |
| 56 | { "rx_frame_errors", E1000_STAT(net_stats.rx_frame_errors) }, |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 57 | { "rx_no_buffer_count", E1000_STAT(stats.rnbc) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { "rx_missed_errors", E1000_STAT(net_stats.rx_missed_errors) }, |
| 59 | { "tx_aborted_errors", E1000_STAT(net_stats.tx_aborted_errors) }, |
| 60 | { "tx_carrier_errors", E1000_STAT(net_stats.tx_carrier_errors) }, |
| 61 | { "tx_fifo_errors", E1000_STAT(net_stats.tx_fifo_errors) }, |
| 62 | { "tx_heartbeat_errors", E1000_STAT(net_stats.tx_heartbeat_errors) }, |
| 63 | { "tx_window_errors", E1000_STAT(net_stats.tx_window_errors) }, |
| 64 | { "tx_abort_late_coll", E1000_STAT(stats.latecol) }, |
| 65 | { "tx_deferred_ok", E1000_STAT(stats.dc) }, |
| 66 | { "tx_single_coll_ok", E1000_STAT(stats.scc) }, |
| 67 | { "tx_multi_coll_ok", E1000_STAT(stats.mcc) }, |
Jeff Kirsher | 6b7660c | 2006-01-12 16:50:35 -0800 | [diff] [blame] | 68 | { "tx_timeout_count", E1000_STAT(tx_timeout_count) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { "rx_long_length_errors", E1000_STAT(stats.roc) }, |
| 70 | { "rx_short_length_errors", E1000_STAT(stats.ruc) }, |
| 71 | { "rx_align_errors", E1000_STAT(stats.algnerrc) }, |
| 72 | { "tx_tcp_seg_good", E1000_STAT(stats.tsctc) }, |
| 73 | { "tx_tcp_seg_failed", E1000_STAT(stats.tsctfc) }, |
| 74 | { "rx_flow_control_xon", E1000_STAT(stats.xonrxc) }, |
| 75 | { "rx_flow_control_xoff", E1000_STAT(stats.xoffrxc) }, |
| 76 | { "tx_flow_control_xon", E1000_STAT(stats.xontxc) }, |
| 77 | { "tx_flow_control_xoff", E1000_STAT(stats.xofftxc) }, |
| 78 | { "rx_long_byte_count", E1000_STAT(stats.gorcl) }, |
| 79 | { "rx_csum_offload_good", E1000_STAT(hw_csum_good) }, |
Mallikarjuna R Chilakala | e4c811c | 2005-10-04 07:05:44 -0400 | [diff] [blame] | 80 | { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) }, |
| 81 | { "rx_header_split", E1000_STAT(rx_hdr_split) }, |
Jeff Kirsher | 6b7660c | 2006-01-12 16:50:35 -0800 | [diff] [blame] | 82 | { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | }; |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 84 | |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 85 | #define E1000_QUEUE_STATS_LEN 0 |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 86 | #define E1000_GLOBAL_STATS_LEN \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | sizeof(e1000_gstrings_stats) / sizeof(struct e1000_stats) |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 88 | #define E1000_STATS_LEN (E1000_GLOBAL_STATS_LEN + E1000_QUEUE_STATS_LEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | static const char e1000_gstrings_test[][ETH_GSTRING_LEN] = { |
| 90 | "Register test (offline)", "Eeprom test (offline)", |
| 91 | "Interrupt test (offline)", "Loopback test (offline)", |
| 92 | "Link test (on/offline)" |
| 93 | }; |
| 94 | #define E1000_TEST_LEN sizeof(e1000_gstrings_test) / ETH_GSTRING_LEN |
| 95 | |
| 96 | static int |
| 97 | e1000_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) |
| 98 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 99 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | struct e1000_hw *hw = &adapter->hw; |
| 101 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 102 | if (hw->media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | ecmd->supported = (SUPPORTED_10baseT_Half | |
| 105 | SUPPORTED_10baseT_Full | |
| 106 | SUPPORTED_100baseT_Half | |
| 107 | SUPPORTED_100baseT_Full | |
| 108 | SUPPORTED_1000baseT_Full| |
| 109 | SUPPORTED_Autoneg | |
| 110 | SUPPORTED_TP); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 111 | if (hw->phy_type == e1000_phy_ife) |
| 112 | ecmd->supported &= ~SUPPORTED_1000baseT_Full; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | ecmd->advertising = ADVERTISED_TP; |
| 114 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 115 | if (hw->autoneg == 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | ecmd->advertising |= ADVERTISED_Autoneg; |
| 117 | |
| 118 | /* the e1000 autoneg seems to match ethtool nicely */ |
| 119 | |
| 120 | ecmd->advertising |= hw->autoneg_advertised; |
| 121 | } |
| 122 | |
| 123 | ecmd->port = PORT_TP; |
| 124 | ecmd->phy_address = hw->phy_addr; |
| 125 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 126 | if (hw->mac_type == e1000_82543) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | ecmd->transceiver = XCVR_EXTERNAL; |
| 128 | else |
| 129 | ecmd->transceiver = XCVR_INTERNAL; |
| 130 | |
| 131 | } else { |
| 132 | ecmd->supported = (SUPPORTED_1000baseT_Full | |
| 133 | SUPPORTED_FIBRE | |
| 134 | SUPPORTED_Autoneg); |
| 135 | |
Malli Chilakala | 012609a | 2005-06-17 17:43:06 -0700 | [diff] [blame] | 136 | ecmd->advertising = (ADVERTISED_1000baseT_Full | |
| 137 | ADVERTISED_FIBRE | |
| 138 | ADVERTISED_Autoneg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | ecmd->port = PORT_FIBRE; |
| 141 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 142 | if (hw->mac_type >= e1000_82545) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | ecmd->transceiver = XCVR_INTERNAL; |
| 144 | else |
| 145 | ecmd->transceiver = XCVR_EXTERNAL; |
| 146 | } |
| 147 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 148 | if (netif_carrier_ok(adapter->netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | e1000_get_speed_and_duplex(hw, &adapter->link_speed, |
| 151 | &adapter->link_duplex); |
| 152 | ecmd->speed = adapter->link_speed; |
| 153 | |
| 154 | /* unfortunatly FULL_DUPLEX != DUPLEX_FULL |
| 155 | * and HALF_DUPLEX != DUPLEX_HALF */ |
| 156 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 157 | if (adapter->link_duplex == FULL_DUPLEX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | ecmd->duplex = DUPLEX_FULL; |
| 159 | else |
| 160 | ecmd->duplex = DUPLEX_HALF; |
| 161 | } else { |
| 162 | ecmd->speed = -1; |
| 163 | ecmd->duplex = -1; |
| 164 | } |
| 165 | |
| 166 | ecmd->autoneg = ((hw->media_type == e1000_media_type_fiber) || |
| 167 | hw->autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE; |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | static int |
| 172 | e1000_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) |
| 173 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 174 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | struct e1000_hw *hw = &adapter->hw; |
| 176 | |
Jeff Kirsher | 5712819 | 2006-01-12 16:50:28 -0800 | [diff] [blame] | 177 | /* When SoL/IDER sessions are active, autoneg/speed/duplex |
| 178 | * cannot be changed */ |
| 179 | if (e1000_check_phy_reset_block(hw)) { |
| 180 | DPRINTK(DRV, ERR, "Cannot change link characteristics " |
| 181 | "when SoL/IDER is active.\n"); |
| 182 | return -EINVAL; |
| 183 | } |
| 184 | |
Jesse Brandeburg | 1a821ca | 2006-08-16 13:38:46 -0700 | [diff] [blame] | 185 | while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) |
| 186 | msleep(1); |
| 187 | |
Jeff Kirsher | 5712819 | 2006-01-12 16:50:28 -0800 | [diff] [blame] | 188 | if (ecmd->autoneg == AUTONEG_ENABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | hw->autoneg = 1; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 190 | if (hw->media_type == e1000_media_type_fiber) |
Malli Chilakala | 012609a | 2005-06-17 17:43:06 -0700 | [diff] [blame] | 191 | hw->autoneg_advertised = ADVERTISED_1000baseT_Full | |
| 192 | ADVERTISED_FIBRE | |
| 193 | ADVERTISED_Autoneg; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 194 | else |
Malli Chilakala | 012609a | 2005-06-17 17:43:06 -0700 | [diff] [blame] | 195 | hw->autoneg_advertised = ADVERTISED_10baseT_Half | |
| 196 | ADVERTISED_10baseT_Full | |
| 197 | ADVERTISED_100baseT_Half | |
| 198 | ADVERTISED_100baseT_Full | |
| 199 | ADVERTISED_1000baseT_Full| |
| 200 | ADVERTISED_Autoneg | |
| 201 | ADVERTISED_TP; |
| 202 | ecmd->advertising = hw->autoneg_advertised; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } else |
Jesse Brandeburg | 1a821ca | 2006-08-16 13:38:46 -0700 | [diff] [blame] | 204 | if (e1000_set_spd_dplx(adapter, ecmd->speed + ecmd->duplex)) { |
| 205 | clear_bit(__E1000_RESETTING, &adapter->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | return -EINVAL; |
Jesse Brandeburg | 1a821ca | 2006-08-16 13:38:46 -0700 | [diff] [blame] | 207 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | /* reset the link */ |
| 210 | |
Jesse Brandeburg | 1a821ca | 2006-08-16 13:38:46 -0700 | [diff] [blame] | 211 | if (netif_running(adapter->netdev)) { |
| 212 | e1000_down(adapter); |
| 213 | e1000_up(adapter); |
| 214 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | e1000_reset(adapter); |
| 216 | |
Jesse Brandeburg | 1a821ca | 2006-08-16 13:38:46 -0700 | [diff] [blame] | 217 | clear_bit(__E1000_RESETTING, &adapter->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | static void |
| 222 | e1000_get_pauseparam(struct net_device *netdev, |
| 223 | struct ethtool_pauseparam *pause) |
| 224 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 225 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | struct e1000_hw *hw = &adapter->hw; |
| 227 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 228 | pause->autoneg = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | (adapter->fc_autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 230 | |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame^] | 231 | if (hw->fc == E1000_FC_RX_PAUSE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | pause->rx_pause = 1; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame^] | 233 | else if (hw->fc == E1000_FC_TX_PAUSE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | pause->tx_pause = 1; |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame^] | 235 | else if (hw->fc == E1000_FC_FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | pause->rx_pause = 1; |
| 237 | pause->tx_pause = 1; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | static int |
| 242 | e1000_set_pauseparam(struct net_device *netdev, |
| 243 | struct ethtool_pauseparam *pause) |
| 244 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 245 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | struct e1000_hw *hw = &adapter->hw; |
Jesse Brandeburg | 1a821ca | 2006-08-16 13:38:46 -0700 | [diff] [blame] | 247 | int retval = 0; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | adapter->fc_autoneg = pause->autoneg; |
| 250 | |
Jesse Brandeburg | 1a821ca | 2006-08-16 13:38:46 -0700 | [diff] [blame] | 251 | while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) |
| 252 | msleep(1); |
| 253 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 254 | if (pause->rx_pause && pause->tx_pause) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame^] | 255 | hw->fc = E1000_FC_FULL; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 256 | else if (pause->rx_pause && !pause->tx_pause) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame^] | 257 | hw->fc = E1000_FC_RX_PAUSE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 258 | else if (!pause->rx_pause && pause->tx_pause) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame^] | 259 | hw->fc = E1000_FC_TX_PAUSE; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 260 | else if (!pause->rx_pause && !pause->tx_pause) |
Jeff Kirsher | 11241b1 | 2006-09-27 12:53:28 -0700 | [diff] [blame^] | 261 | hw->fc = E1000_FC_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
| 263 | hw->original_fc = hw->fc; |
| 264 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 265 | if (adapter->fc_autoneg == AUTONEG_ENABLE) { |
Jesse Brandeburg | 1a821ca | 2006-08-16 13:38:46 -0700 | [diff] [blame] | 266 | if (netif_running(adapter->netdev)) { |
| 267 | e1000_down(adapter); |
| 268 | e1000_up(adapter); |
| 269 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | e1000_reset(adapter); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 271 | } else |
Jesse Brandeburg | 1a821ca | 2006-08-16 13:38:46 -0700 | [diff] [blame] | 272 | retval = ((hw->media_type == e1000_media_type_fiber) ? |
| 273 | e1000_setup_link(hw) : e1000_force_mac_fc(hw)); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 274 | |
Jesse Brandeburg | 1a821ca | 2006-08-16 13:38:46 -0700 | [diff] [blame] | 275 | clear_bit(__E1000_RESETTING, &adapter->flags); |
| 276 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | static uint32_t |
| 280 | e1000_get_rx_csum(struct net_device *netdev) |
| 281 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 282 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | return adapter->rx_csum; |
| 284 | } |
| 285 | |
| 286 | static int |
| 287 | e1000_set_rx_csum(struct net_device *netdev, uint32_t data) |
| 288 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 289 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | adapter->rx_csum = data; |
| 291 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 292 | if (netif_running(netdev)) |
| 293 | e1000_reinit_locked(adapter); |
| 294 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | e1000_reset(adapter); |
| 296 | return 0; |
| 297 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | static uint32_t |
| 300 | e1000_get_tx_csum(struct net_device *netdev) |
| 301 | { |
| 302 | return (netdev->features & NETIF_F_HW_CSUM) != 0; |
| 303 | } |
| 304 | |
| 305 | static int |
| 306 | e1000_set_tx_csum(struct net_device *netdev, uint32_t data) |
| 307 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 308 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 310 | if (adapter->hw.mac_type < e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | if (!data) |
| 312 | return -EINVAL; |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | if (data) |
| 317 | netdev->features |= NETIF_F_HW_CSUM; |
| 318 | else |
| 319 | netdev->features &= ~NETIF_F_HW_CSUM; |
| 320 | |
| 321 | return 0; |
| 322 | } |
| 323 | |
| 324 | #ifdef NETIF_F_TSO |
| 325 | static int |
| 326 | e1000_set_tso(struct net_device *netdev, uint32_t data) |
| 327 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 328 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 329 | if ((adapter->hw.mac_type < e1000_82544) || |
| 330 | (adapter->hw.mac_type == e1000_82547)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | return data ? -EINVAL : 0; |
| 332 | |
| 333 | if (data) |
| 334 | netdev->features |= NETIF_F_TSO; |
| 335 | else |
| 336 | netdev->features &= ~NETIF_F_TSO; |
Jeff Kirsher | 7e6c986 | 2006-03-02 18:19:30 -0800 | [diff] [blame] | 337 | |
| 338 | DPRINTK(PROBE, INFO, "TSO is %s\n", data ? "Enabled" : "Disabled"); |
| 339 | adapter->tso_force = TRUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | return 0; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 341 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | #endif /* NETIF_F_TSO */ |
| 343 | |
| 344 | static uint32_t |
| 345 | e1000_get_msglevel(struct net_device *netdev) |
| 346 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 347 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | return adapter->msg_enable; |
| 349 | } |
| 350 | |
| 351 | static void |
| 352 | e1000_set_msglevel(struct net_device *netdev, uint32_t data) |
| 353 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 354 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | adapter->msg_enable = data; |
| 356 | } |
| 357 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 358 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | e1000_get_regs_len(struct net_device *netdev) |
| 360 | { |
| 361 | #define E1000_REGS_LEN 32 |
| 362 | return E1000_REGS_LEN * sizeof(uint32_t); |
| 363 | } |
| 364 | |
| 365 | static void |
| 366 | e1000_get_regs(struct net_device *netdev, |
| 367 | struct ethtool_regs *regs, void *p) |
| 368 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 369 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | struct e1000_hw *hw = &adapter->hw; |
| 371 | uint32_t *regs_buff = p; |
| 372 | uint16_t phy_data; |
| 373 | |
| 374 | memset(p, 0, E1000_REGS_LEN * sizeof(uint32_t)); |
| 375 | |
| 376 | regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id; |
| 377 | |
| 378 | regs_buff[0] = E1000_READ_REG(hw, CTRL); |
| 379 | regs_buff[1] = E1000_READ_REG(hw, STATUS); |
| 380 | |
| 381 | regs_buff[2] = E1000_READ_REG(hw, RCTL); |
| 382 | regs_buff[3] = E1000_READ_REG(hw, RDLEN); |
| 383 | regs_buff[4] = E1000_READ_REG(hw, RDH); |
| 384 | regs_buff[5] = E1000_READ_REG(hw, RDT); |
| 385 | regs_buff[6] = E1000_READ_REG(hw, RDTR); |
| 386 | |
| 387 | regs_buff[7] = E1000_READ_REG(hw, TCTL); |
| 388 | regs_buff[8] = E1000_READ_REG(hw, TDLEN); |
| 389 | regs_buff[9] = E1000_READ_REG(hw, TDH); |
| 390 | regs_buff[10] = E1000_READ_REG(hw, TDT); |
| 391 | regs_buff[11] = E1000_READ_REG(hw, TIDV); |
| 392 | |
| 393 | regs_buff[12] = adapter->hw.phy_type; /* PHY type (IGP=1, M88=0) */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 394 | if (hw->phy_type == e1000_phy_igp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 396 | IGP01E1000_PHY_AGC_A); |
| 397 | e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_A & |
| 398 | IGP01E1000_PHY_PAGE_SELECT, &phy_data); |
| 399 | regs_buff[13] = (uint32_t)phy_data; /* cable length */ |
| 400 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 401 | IGP01E1000_PHY_AGC_B); |
| 402 | e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_B & |
| 403 | IGP01E1000_PHY_PAGE_SELECT, &phy_data); |
| 404 | regs_buff[14] = (uint32_t)phy_data; /* cable length */ |
| 405 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 406 | IGP01E1000_PHY_AGC_C); |
| 407 | e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_C & |
| 408 | IGP01E1000_PHY_PAGE_SELECT, &phy_data); |
| 409 | regs_buff[15] = (uint32_t)phy_data; /* cable length */ |
| 410 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 411 | IGP01E1000_PHY_AGC_D); |
| 412 | e1000_read_phy_reg(hw, IGP01E1000_PHY_AGC_D & |
| 413 | IGP01E1000_PHY_PAGE_SELECT, &phy_data); |
| 414 | regs_buff[16] = (uint32_t)phy_data; /* cable length */ |
| 415 | regs_buff[17] = 0; /* extended 10bt distance (not needed) */ |
| 416 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0); |
| 417 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS & |
| 418 | IGP01E1000_PHY_PAGE_SELECT, &phy_data); |
| 419 | regs_buff[18] = (uint32_t)phy_data; /* cable polarity */ |
| 420 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, |
| 421 | IGP01E1000_PHY_PCS_INIT_REG); |
| 422 | e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG & |
| 423 | IGP01E1000_PHY_PAGE_SELECT, &phy_data); |
| 424 | regs_buff[19] = (uint32_t)phy_data; /* cable polarity */ |
| 425 | regs_buff[20] = 0; /* polarity correction enabled (always) */ |
| 426 | regs_buff[22] = 0; /* phy receive errors (unavailable) */ |
| 427 | regs_buff[23] = regs_buff[18]; /* mdix mode */ |
| 428 | e1000_write_phy_reg(hw, IGP01E1000_PHY_PAGE_SELECT, 0x0); |
| 429 | } else { |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 430 | e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | regs_buff[13] = (uint32_t)phy_data; /* cable length */ |
| 432 | regs_buff[14] = 0; /* Dummy (to align w/ IGP phy reg dump) */ |
| 433 | regs_buff[15] = 0; /* Dummy (to align w/ IGP phy reg dump) */ |
| 434 | regs_buff[16] = 0; /* Dummy (to align w/ IGP phy reg dump) */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 435 | e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | regs_buff[17] = (uint32_t)phy_data; /* extended 10bt distance */ |
| 437 | regs_buff[18] = regs_buff[13]; /* cable polarity */ |
| 438 | regs_buff[19] = 0; /* Dummy (to align w/ IGP phy reg dump) */ |
| 439 | regs_buff[20] = regs_buff[17]; /* polarity correction */ |
| 440 | /* phy receive errors */ |
| 441 | regs_buff[22] = adapter->phy_stats.receive_errors; |
| 442 | regs_buff[23] = regs_buff[13]; /* mdix mode */ |
| 443 | } |
| 444 | regs_buff[21] = adapter->phy_stats.idle_errors; /* phy idle errors */ |
| 445 | e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data); |
| 446 | regs_buff[24] = (uint32_t)phy_data; /* phy local receiver status */ |
| 447 | regs_buff[25] = regs_buff[24]; /* phy remote receiver status */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 448 | if (hw->mac_type >= e1000_82540 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | hw->media_type == e1000_media_type_copper) { |
| 450 | regs_buff[26] = E1000_READ_REG(hw, MANC); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | static int |
| 455 | e1000_get_eeprom_len(struct net_device *netdev) |
| 456 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 457 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | return adapter->hw.eeprom.word_size * 2; |
| 459 | } |
| 460 | |
| 461 | static int |
| 462 | e1000_get_eeprom(struct net_device *netdev, |
| 463 | struct ethtool_eeprom *eeprom, uint8_t *bytes) |
| 464 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 465 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | struct e1000_hw *hw = &adapter->hw; |
| 467 | uint16_t *eeprom_buff; |
| 468 | int first_word, last_word; |
| 469 | int ret_val = 0; |
| 470 | uint16_t i; |
| 471 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 472 | if (eeprom->len == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | return -EINVAL; |
| 474 | |
| 475 | eeprom->magic = hw->vendor_id | (hw->device_id << 16); |
| 476 | |
| 477 | first_word = eeprom->offset >> 1; |
| 478 | last_word = (eeprom->offset + eeprom->len - 1) >> 1; |
| 479 | |
| 480 | eeprom_buff = kmalloc(sizeof(uint16_t) * |
| 481 | (last_word - first_word + 1), GFP_KERNEL); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 482 | if (!eeprom_buff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | return -ENOMEM; |
| 484 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 485 | if (hw->eeprom.type == e1000_eeprom_spi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | ret_val = e1000_read_eeprom(hw, first_word, |
| 487 | last_word - first_word + 1, |
| 488 | eeprom_buff); |
| 489 | else { |
| 490 | for (i = 0; i < last_word - first_word + 1; i++) |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 491 | if ((ret_val = e1000_read_eeprom(hw, first_word + i, 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | &eeprom_buff[i]))) |
| 493 | break; |
| 494 | } |
| 495 | |
| 496 | /* Device's eeprom is always little-endian, word addressable */ |
| 497 | for (i = 0; i < last_word - first_word + 1; i++) |
| 498 | le16_to_cpus(&eeprom_buff[i]); |
| 499 | |
| 500 | memcpy(bytes, (uint8_t *)eeprom_buff + (eeprom->offset & 1), |
| 501 | eeprom->len); |
| 502 | kfree(eeprom_buff); |
| 503 | |
| 504 | return ret_val; |
| 505 | } |
| 506 | |
| 507 | static int |
| 508 | e1000_set_eeprom(struct net_device *netdev, |
| 509 | struct ethtool_eeprom *eeprom, uint8_t *bytes) |
| 510 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 511 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | struct e1000_hw *hw = &adapter->hw; |
| 513 | uint16_t *eeprom_buff; |
| 514 | void *ptr; |
| 515 | int max_len, first_word, last_word, ret_val = 0; |
| 516 | uint16_t i; |
| 517 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 518 | if (eeprom->len == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | return -EOPNOTSUPP; |
| 520 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 521 | if (eeprom->magic != (hw->vendor_id | (hw->device_id << 16))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | return -EFAULT; |
| 523 | |
| 524 | max_len = hw->eeprom.word_size * 2; |
| 525 | |
| 526 | first_word = eeprom->offset >> 1; |
| 527 | last_word = (eeprom->offset + eeprom->len - 1) >> 1; |
| 528 | eeprom_buff = kmalloc(max_len, GFP_KERNEL); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 529 | if (!eeprom_buff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | return -ENOMEM; |
| 531 | |
| 532 | ptr = (void *)eeprom_buff; |
| 533 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 534 | if (eeprom->offset & 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | /* need read/modify/write of first changed EEPROM word */ |
| 536 | /* only the second byte of the word is being modified */ |
| 537 | ret_val = e1000_read_eeprom(hw, first_word, 1, |
| 538 | &eeprom_buff[0]); |
| 539 | ptr++; |
| 540 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 541 | if (((eeprom->offset + eeprom->len) & 1) && (ret_val == 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | /* need read/modify/write of last changed EEPROM word */ |
| 543 | /* only the first byte of the word is being modified */ |
| 544 | ret_val = e1000_read_eeprom(hw, last_word, 1, |
| 545 | &eeprom_buff[last_word - first_word]); |
| 546 | } |
| 547 | |
| 548 | /* Device's eeprom is always little-endian, word addressable */ |
| 549 | for (i = 0; i < last_word - first_word + 1; i++) |
| 550 | le16_to_cpus(&eeprom_buff[i]); |
| 551 | |
| 552 | memcpy(ptr, bytes, eeprom->len); |
| 553 | |
| 554 | for (i = 0; i < last_word - first_word + 1; i++) |
| 555 | eeprom_buff[i] = cpu_to_le16(eeprom_buff[i]); |
| 556 | |
| 557 | ret_val = e1000_write_eeprom(hw, first_word, |
| 558 | last_word - first_word + 1, eeprom_buff); |
| 559 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 560 | /* Update the checksum over the first part of the EEPROM if needed |
Mallikarjuna R Chilakala | a7990ba | 2005-10-04 07:08:19 -0400 | [diff] [blame] | 561 | * and flush shadow RAM for 82573 conrollers */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 562 | if ((ret_val == 0) && ((first_word <= EEPROM_CHECKSUM_REG) || |
Mallikarjuna R Chilakala | a7990ba | 2005-10-04 07:08:19 -0400 | [diff] [blame] | 563 | (hw->mac_type == e1000_82573))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | e1000_update_eeprom_checksum(hw); |
| 565 | |
| 566 | kfree(eeprom_buff); |
| 567 | return ret_val; |
| 568 | } |
| 569 | |
| 570 | static void |
| 571 | e1000_get_drvinfo(struct net_device *netdev, |
| 572 | struct ethtool_drvinfo *drvinfo) |
| 573 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 574 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Jeff Kirsher | a2917e2 | 2006-01-12 16:51:23 -0800 | [diff] [blame] | 575 | char firmware_version[32]; |
| 576 | uint16_t eeprom_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
| 578 | strncpy(drvinfo->driver, e1000_driver_name, 32); |
| 579 | strncpy(drvinfo->version, e1000_driver_version, 32); |
Jeff Kirsher | a2917e2 | 2006-01-12 16:51:23 -0800 | [diff] [blame] | 580 | |
| 581 | /* EEPROM image version # is reported as firmware version # for |
| 582 | * 8257{1|2|3} controllers */ |
| 583 | e1000_read_eeprom(&adapter->hw, 5, 1, &eeprom_data); |
| 584 | switch (adapter->hw.mac_type) { |
| 585 | case e1000_82571: |
| 586 | case e1000_82572: |
| 587 | case e1000_82573: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 588 | case e1000_80003es2lan: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 589 | case e1000_ich8lan: |
Jeff Kirsher | a2917e2 | 2006-01-12 16:51:23 -0800 | [diff] [blame] | 590 | sprintf(firmware_version, "%d.%d-%d", |
| 591 | (eeprom_data & 0xF000) >> 12, |
| 592 | (eeprom_data & 0x0FF0) >> 4, |
| 593 | eeprom_data & 0x000F); |
| 594 | break; |
| 595 | default: |
| 596 | sprintf(firmware_version, "N/A"); |
| 597 | } |
| 598 | |
| 599 | strncpy(drvinfo->fw_version, firmware_version, 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32); |
| 601 | drvinfo->n_stats = E1000_STATS_LEN; |
| 602 | drvinfo->testinfo_len = E1000_TEST_LEN; |
| 603 | drvinfo->regdump_len = e1000_get_regs_len(netdev); |
| 604 | drvinfo->eedump_len = e1000_get_eeprom_len(netdev); |
| 605 | } |
| 606 | |
| 607 | static void |
| 608 | e1000_get_ringparam(struct net_device *netdev, |
| 609 | struct ethtool_ringparam *ring) |
| 610 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 611 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | e1000_mac_type mac_type = adapter->hw.mac_type; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 613 | struct e1000_tx_ring *txdr = adapter->tx_ring; |
| 614 | struct e1000_rx_ring *rxdr = adapter->rx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
| 616 | ring->rx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_RXD : |
| 617 | E1000_MAX_82544_RXD; |
| 618 | ring->tx_max_pending = (mac_type < e1000_82544) ? E1000_MAX_TXD : |
| 619 | E1000_MAX_82544_TXD; |
| 620 | ring->rx_mini_max_pending = 0; |
| 621 | ring->rx_jumbo_max_pending = 0; |
| 622 | ring->rx_pending = rxdr->count; |
| 623 | ring->tx_pending = txdr->count; |
| 624 | ring->rx_mini_pending = 0; |
| 625 | ring->rx_jumbo_pending = 0; |
| 626 | } |
| 627 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 628 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | e1000_set_ringparam(struct net_device *netdev, |
| 630 | struct ethtool_ringparam *ring) |
| 631 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 632 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | e1000_mac_type mac_type = adapter->hw.mac_type; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 634 | struct e1000_tx_ring *txdr, *tx_old, *tx_new; |
| 635 | struct e1000_rx_ring *rxdr, *rx_old, *rx_new; |
| 636 | int i, err, tx_ring_size, rx_ring_size; |
| 637 | |
Jeff Kirsher | 0989aa4 | 2006-03-02 18:17:16 -0800 | [diff] [blame] | 638 | if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) |
| 639 | return -EINVAL; |
| 640 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 641 | tx_ring_size = sizeof(struct e1000_tx_ring) * adapter->num_tx_queues; |
| 642 | rx_ring_size = sizeof(struct e1000_rx_ring) * adapter->num_rx_queues; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 643 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 644 | while (test_and_set_bit(__E1000_RESETTING, &adapter->flags)) |
| 645 | msleep(1); |
| 646 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 647 | if (netif_running(adapter->netdev)) |
| 648 | e1000_down(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
| 650 | tx_old = adapter->tx_ring; |
| 651 | rx_old = adapter->rx_ring; |
| 652 | |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 653 | adapter->tx_ring = kmalloc(tx_ring_size, GFP_KERNEL); |
| 654 | if (!adapter->tx_ring) { |
| 655 | err = -ENOMEM; |
| 656 | goto err_setup_rx; |
| 657 | } |
| 658 | memset(adapter->tx_ring, 0, tx_ring_size); |
| 659 | |
| 660 | adapter->rx_ring = kmalloc(rx_ring_size, GFP_KERNEL); |
| 661 | if (!adapter->rx_ring) { |
| 662 | kfree(adapter->tx_ring); |
| 663 | err = -ENOMEM; |
| 664 | goto err_setup_rx; |
| 665 | } |
| 666 | memset(adapter->rx_ring, 0, rx_ring_size); |
| 667 | |
| 668 | txdr = adapter->tx_ring; |
| 669 | rxdr = adapter->rx_ring; |
| 670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | rxdr->count = max(ring->rx_pending,(uint32_t)E1000_MIN_RXD); |
| 672 | rxdr->count = min(rxdr->count,(uint32_t)(mac_type < e1000_82544 ? |
| 673 | E1000_MAX_RXD : E1000_MAX_82544_RXD)); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 674 | E1000_ROUNDUP(rxdr->count, REQ_RX_DESCRIPTOR_MULTIPLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | |
| 676 | txdr->count = max(ring->tx_pending,(uint32_t)E1000_MIN_TXD); |
| 677 | txdr->count = min(txdr->count,(uint32_t)(mac_type < e1000_82544 ? |
| 678 | E1000_MAX_TXD : E1000_MAX_82544_TXD)); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 679 | E1000_ROUNDUP(txdr->count, REQ_TX_DESCRIPTOR_MULTIPLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 681 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 682 | txdr[i].count = txdr->count; |
Jeff Kirsher | f56799e | 2006-01-12 16:50:39 -0800 | [diff] [blame] | 683 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 684 | rxdr[i].count = rxdr->count; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 685 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 686 | if (netif_running(adapter->netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | /* Try to get new resources before deleting old */ |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 688 | if ((err = e1000_setup_all_rx_resources(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | goto err_setup_rx; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 690 | if ((err = e1000_setup_all_tx_resources(adapter))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | goto err_setup_tx; |
| 692 | |
| 693 | /* save the new, restore the old in order to free it, |
| 694 | * then restore the new back again */ |
| 695 | |
| 696 | rx_new = adapter->rx_ring; |
| 697 | tx_new = adapter->tx_ring; |
| 698 | adapter->rx_ring = rx_old; |
| 699 | adapter->tx_ring = tx_old; |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 700 | e1000_free_all_rx_resources(adapter); |
| 701 | e1000_free_all_tx_resources(adapter); |
| 702 | kfree(tx_old); |
| 703 | kfree(rx_old); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | adapter->rx_ring = rx_new; |
| 705 | adapter->tx_ring = tx_new; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 706 | if ((err = e1000_up(adapter))) |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 707 | goto err_setup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 710 | clear_bit(__E1000_RESETTING, &adapter->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | return 0; |
| 712 | err_setup_tx: |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 713 | e1000_free_all_rx_resources(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | err_setup_rx: |
| 715 | adapter->rx_ring = rx_old; |
| 716 | adapter->tx_ring = tx_old; |
| 717 | e1000_up(adapter); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 718 | err_setup: |
| 719 | clear_bit(__E1000_RESETTING, &adapter->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | return err; |
| 721 | } |
| 722 | |
| 723 | #define REG_PATTERN_TEST(R, M, W) \ |
| 724 | { \ |
| 725 | uint32_t pat, value; \ |
| 726 | uint32_t test[] = \ |
| 727 | {0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF}; \ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 728 | for (pat = 0; pat < sizeof(test)/sizeof(test[0]); pat++) { \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | E1000_WRITE_REG(&adapter->hw, R, (test[pat] & W)); \ |
| 730 | value = E1000_READ_REG(&adapter->hw, R); \ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 731 | if (value != (test[pat] & W & M)) { \ |
Malli Chilakala | b01f669 | 2005-06-17 17:42:29 -0700 | [diff] [blame] | 732 | DPRINTK(DRV, ERR, "pattern test reg %04X failed: got " \ |
| 733 | "0x%08X expected 0x%08X\n", \ |
| 734 | E1000_##R, value, (test[pat] & W & M)); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | *data = (adapter->hw.mac_type < e1000_82543) ? \ |
| 736 | E1000_82542_##R : E1000_##R; \ |
| 737 | return 1; \ |
| 738 | } \ |
| 739 | } \ |
| 740 | } |
| 741 | |
| 742 | #define REG_SET_AND_CHECK(R, M, W) \ |
| 743 | { \ |
| 744 | uint32_t value; \ |
| 745 | E1000_WRITE_REG(&adapter->hw, R, W & M); \ |
| 746 | value = E1000_READ_REG(&adapter->hw, R); \ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 747 | if ((W & M) != (value & M)) { \ |
Malli Chilakala | b01f669 | 2005-06-17 17:42:29 -0700 | [diff] [blame] | 748 | DPRINTK(DRV, ERR, "set/check reg %04X test failed: got 0x%08X "\ |
| 749 | "expected 0x%08X\n", E1000_##R, (value & M), (W & M)); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | *data = (adapter->hw.mac_type < e1000_82543) ? \ |
| 751 | E1000_82542_##R : E1000_##R; \ |
| 752 | return 1; \ |
| 753 | } \ |
| 754 | } |
| 755 | |
| 756 | static int |
| 757 | e1000_reg_test(struct e1000_adapter *adapter, uint64_t *data) |
| 758 | { |
Malli Chilakala | b01f669 | 2005-06-17 17:42:29 -0700 | [diff] [blame] | 759 | uint32_t value, before, after; |
| 760 | uint32_t i, toggle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
| 762 | /* The status register is Read Only, so a write should fail. |
| 763 | * Some bits that get toggled are ignored. |
| 764 | */ |
Malli Chilakala | b01f669 | 2005-06-17 17:42:29 -0700 | [diff] [blame] | 765 | switch (adapter->hw.mac_type) { |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 766 | /* there are several bits on newer hardware that are r/w */ |
| 767 | case e1000_82571: |
| 768 | case e1000_82572: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 769 | case e1000_80003es2lan: |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 770 | toggle = 0x7FFFF3FF; |
| 771 | break; |
Malli Chilakala | b01f669 | 2005-06-17 17:42:29 -0700 | [diff] [blame] | 772 | case e1000_82573: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 773 | case e1000_ich8lan: |
Malli Chilakala | b01f669 | 2005-06-17 17:42:29 -0700 | [diff] [blame] | 774 | toggle = 0x7FFFF033; |
| 775 | break; |
| 776 | default: |
| 777 | toggle = 0xFFFFF833; |
| 778 | break; |
| 779 | } |
| 780 | |
| 781 | before = E1000_READ_REG(&adapter->hw, STATUS); |
| 782 | value = (E1000_READ_REG(&adapter->hw, STATUS) & toggle); |
| 783 | E1000_WRITE_REG(&adapter->hw, STATUS, toggle); |
| 784 | after = E1000_READ_REG(&adapter->hw, STATUS) & toggle; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 785 | if (value != after) { |
Malli Chilakala | b01f669 | 2005-06-17 17:42:29 -0700 | [diff] [blame] | 786 | DPRINTK(DRV, ERR, "failed STATUS register test got: " |
| 787 | "0x%08X expected: 0x%08X\n", after, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | *data = 1; |
| 789 | return 1; |
| 790 | } |
Malli Chilakala | b01f669 | 2005-06-17 17:42:29 -0700 | [diff] [blame] | 791 | /* restore previous status */ |
| 792 | E1000_WRITE_REG(&adapter->hw, STATUS, before); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 793 | if (adapter->hw.mac_type != e1000_ich8lan) { |
| 794 | REG_PATTERN_TEST(FCAL, 0xFFFFFFFF, 0xFFFFFFFF); |
| 795 | REG_PATTERN_TEST(FCAH, 0x0000FFFF, 0xFFFFFFFF); |
| 796 | REG_PATTERN_TEST(FCT, 0x0000FFFF, 0xFFFFFFFF); |
| 797 | REG_PATTERN_TEST(VET, 0x0000FFFF, 0xFFFFFFFF); |
| 798 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | REG_PATTERN_TEST(RDTR, 0x0000FFFF, 0xFFFFFFFF); |
| 800 | REG_PATTERN_TEST(RDBAH, 0xFFFFFFFF, 0xFFFFFFFF); |
| 801 | REG_PATTERN_TEST(RDLEN, 0x000FFF80, 0x000FFFFF); |
| 802 | REG_PATTERN_TEST(RDH, 0x0000FFFF, 0x0000FFFF); |
| 803 | REG_PATTERN_TEST(RDT, 0x0000FFFF, 0x0000FFFF); |
| 804 | REG_PATTERN_TEST(FCRTH, 0x0000FFF8, 0x0000FFF8); |
| 805 | REG_PATTERN_TEST(FCTTV, 0x0000FFFF, 0x0000FFFF); |
| 806 | REG_PATTERN_TEST(TIPG, 0x3FFFFFFF, 0x3FFFFFFF); |
| 807 | REG_PATTERN_TEST(TDBAH, 0xFFFFFFFF, 0xFFFFFFFF); |
| 808 | REG_PATTERN_TEST(TDLEN, 0x000FFF80, 0x000FFFFF); |
| 809 | |
| 810 | REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x00000000); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 811 | before = (adapter->hw.mac_type == e1000_ich8lan ? |
| 812 | 0x06C3B33E : 0x06DFB3FE); |
| 813 | REG_SET_AND_CHECK(RCTL, before, 0x003FFFFB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | REG_SET_AND_CHECK(TCTL, 0xFFFFFFFF, 0x00000000); |
| 815 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 816 | if (adapter->hw.mac_type >= e1000_82543) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 818 | REG_SET_AND_CHECK(RCTL, before, 0xFFFFFFFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | REG_PATTERN_TEST(RDBAL, 0xFFFFFFF0, 0xFFFFFFFF); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 820 | if (adapter->hw.mac_type != e1000_ich8lan) |
| 821 | REG_PATTERN_TEST(TXCW, 0xC000FFFF, 0x0000FFFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | REG_PATTERN_TEST(TDBAL, 0xFFFFFFF0, 0xFFFFFFFF); |
| 823 | REG_PATTERN_TEST(TIDV, 0x0000FFFF, 0x0000FFFF); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 824 | value = (adapter->hw.mac_type == e1000_ich8lan ? |
| 825 | E1000_RAR_ENTRIES_ICH8LAN : E1000_RAR_ENTRIES); |
| 826 | for (i = 0; i < value; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | REG_PATTERN_TEST(RA + (((i << 1) + 1) << 2), 0x8003FFFF, |
| 828 | 0xFFFFFFFF); |
| 829 | } |
| 830 | |
| 831 | } else { |
| 832 | |
| 833 | REG_SET_AND_CHECK(RCTL, 0xFFFFFFFF, 0x01FFFFFF); |
| 834 | REG_PATTERN_TEST(RDBAL, 0xFFFFF000, 0xFFFFFFFF); |
| 835 | REG_PATTERN_TEST(TXCW, 0x0000FFFF, 0x0000FFFF); |
| 836 | REG_PATTERN_TEST(TDBAL, 0xFFFFF000, 0xFFFFFFFF); |
| 837 | |
| 838 | } |
| 839 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 840 | value = (adapter->hw.mac_type == e1000_ich8lan ? |
| 841 | E1000_MC_TBL_SIZE_ICH8LAN : E1000_MC_TBL_SIZE); |
| 842 | for (i = 0; i < value; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | REG_PATTERN_TEST(MTA + (i << 2), 0xFFFFFFFF, 0xFFFFFFFF); |
| 844 | |
| 845 | *data = 0; |
| 846 | return 0; |
| 847 | } |
| 848 | |
| 849 | static int |
| 850 | e1000_eeprom_test(struct e1000_adapter *adapter, uint64_t *data) |
| 851 | { |
| 852 | uint16_t temp; |
| 853 | uint16_t checksum = 0; |
| 854 | uint16_t i; |
| 855 | |
| 856 | *data = 0; |
| 857 | /* Read and add up the contents of the EEPROM */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 858 | for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) { |
| 859 | if ((e1000_read_eeprom(&adapter->hw, i, 1, &temp)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | *data = 1; |
| 861 | break; |
| 862 | } |
| 863 | checksum += temp; |
| 864 | } |
| 865 | |
| 866 | /* If Checksum is not Correct return error else test passed */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 867 | if ((checksum != (uint16_t) EEPROM_SUM) && !(*data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | *data = 2; |
| 869 | |
| 870 | return *data; |
| 871 | } |
| 872 | |
| 873 | static irqreturn_t |
| 874 | e1000_test_intr(int irq, |
| 875 | void *data, |
| 876 | struct pt_regs *regs) |
| 877 | { |
| 878 | struct net_device *netdev = (struct net_device *) data; |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 879 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
| 881 | adapter->test_icr |= E1000_READ_REG(&adapter->hw, ICR); |
| 882 | |
| 883 | return IRQ_HANDLED; |
| 884 | } |
| 885 | |
| 886 | static int |
| 887 | e1000_intr_test(struct e1000_adapter *adapter, uint64_t *data) |
| 888 | { |
| 889 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 890 | uint32_t mask, i=0, shared_int = TRUE; |
| 891 | uint32_t irq = adapter->pdev->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | |
| 893 | *data = 0; |
| 894 | |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 895 | /* NOTE: we don't test MSI interrupts here, yet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | /* Hook up test interrupt handler just for this test */ |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 897 | if (!request_irq(irq, &e1000_test_intr, IRQF_PROBE_SHARED, |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 898 | netdev->name, netdev)) |
| 899 | shared_int = FALSE; |
| 900 | else if (request_irq(irq, &e1000_test_intr, IRQF_SHARED, |
| 901 | netdev->name, netdev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | *data = 1; |
| 903 | return -1; |
| 904 | } |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 905 | DPRINTK(HW, INFO, "testing %s interrupt\n", |
Auke Kok | b9b6e78 | 2006-06-08 09:28:38 -0700 | [diff] [blame] | 906 | (shared_int ? "shared" : "unshared")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | |
| 908 | /* Disable all the interrupts */ |
| 909 | E1000_WRITE_REG(&adapter->hw, IMC, 0xFFFFFFFF); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 910 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | |
| 912 | /* Test each interrupt */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 913 | for (; i < 10; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 915 | if (adapter->hw.mac_type == e1000_ich8lan && i == 8) |
| 916 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | /* Interrupt to test */ |
| 918 | mask = 1 << i; |
| 919 | |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 920 | if (!shared_int) { |
| 921 | /* Disable the interrupt to be reported in |
| 922 | * the cause register and then force the same |
| 923 | * interrupt and see if one gets posted. If |
| 924 | * an interrupt was posted to the bus, the |
| 925 | * test failed. |
| 926 | */ |
| 927 | adapter->test_icr = 0; |
| 928 | E1000_WRITE_REG(&adapter->hw, IMC, mask); |
| 929 | E1000_WRITE_REG(&adapter->hw, ICS, mask); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 930 | msleep(10); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 931 | |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 932 | if (adapter->test_icr & mask) { |
| 933 | *data = 3; |
| 934 | break; |
| 935 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | /* Enable the interrupt to be reported in |
| 939 | * the cause register and then force the same |
| 940 | * interrupt and see if one gets posted. If |
| 941 | * an interrupt was not posted to the bus, the |
| 942 | * test failed. |
| 943 | */ |
| 944 | adapter->test_icr = 0; |
| 945 | E1000_WRITE_REG(&adapter->hw, IMS, mask); |
| 946 | E1000_WRITE_REG(&adapter->hw, ICS, mask); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 947 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 949 | if (!(adapter->test_icr & mask)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | *data = 4; |
| 951 | break; |
| 952 | } |
| 953 | |
Auke Kok | 76c224b | 2006-05-23 13:36:06 -0700 | [diff] [blame] | 954 | if (!shared_int) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | /* Disable the other interrupts to be reported in |
| 956 | * the cause register and then force the other |
| 957 | * interrupts and see if any get posted. If |
| 958 | * an interrupt was posted to the bus, the |
| 959 | * test failed. |
| 960 | */ |
| 961 | adapter->test_icr = 0; |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 962 | E1000_WRITE_REG(&adapter->hw, IMC, ~mask & 0x00007FFF); |
| 963 | E1000_WRITE_REG(&adapter->hw, ICS, ~mask & 0x00007FFF); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 964 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 966 | if (adapter->test_icr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | *data = 5; |
| 968 | break; |
| 969 | } |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | /* Disable all the interrupts */ |
| 974 | E1000_WRITE_REG(&adapter->hw, IMC, 0xFFFFFFFF); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 975 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | |
| 977 | /* Unhook test interrupt handler */ |
| 978 | free_irq(irq, netdev); |
| 979 | |
| 980 | return *data; |
| 981 | } |
| 982 | |
| 983 | static void |
| 984 | e1000_free_desc_rings(struct e1000_adapter *adapter) |
| 985 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 986 | struct e1000_tx_ring *txdr = &adapter->test_tx_ring; |
| 987 | struct e1000_rx_ring *rxdr = &adapter->test_rx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | struct pci_dev *pdev = adapter->pdev; |
| 989 | int i; |
| 990 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 991 | if (txdr->desc && txdr->buffer_info) { |
| 992 | for (i = 0; i < txdr->count; i++) { |
| 993 | if (txdr->buffer_info[i].dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | pci_unmap_single(pdev, txdr->buffer_info[i].dma, |
| 995 | txdr->buffer_info[i].length, |
| 996 | PCI_DMA_TODEVICE); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 997 | if (txdr->buffer_info[i].skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | dev_kfree_skb(txdr->buffer_info[i].skb); |
| 999 | } |
| 1000 | } |
| 1001 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1002 | if (rxdr->desc && rxdr->buffer_info) { |
| 1003 | for (i = 0; i < rxdr->count; i++) { |
| 1004 | if (rxdr->buffer_info[i].dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | pci_unmap_single(pdev, rxdr->buffer_info[i].dma, |
| 1006 | rxdr->buffer_info[i].length, |
| 1007 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1008 | if (rxdr->buffer_info[i].skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | dev_kfree_skb(rxdr->buffer_info[i].skb); |
| 1010 | } |
| 1011 | } |
| 1012 | |
Jeff Kirsher | f564511 | 2006-01-12 16:51:01 -0800 | [diff] [blame] | 1013 | if (txdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | pci_free_consistent(pdev, txdr->size, txdr->desc, txdr->dma); |
John W. Linville | 6b27adb | 2005-11-08 15:59:30 -0500 | [diff] [blame] | 1015 | txdr->desc = NULL; |
| 1016 | } |
Jeff Kirsher | f564511 | 2006-01-12 16:51:01 -0800 | [diff] [blame] | 1017 | if (rxdr->desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | pci_free_consistent(pdev, rxdr->size, rxdr->desc, rxdr->dma); |
John W. Linville | 6b27adb | 2005-11-08 15:59:30 -0500 | [diff] [blame] | 1019 | rxdr->desc = NULL; |
| 1020 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | |
Jesper Juhl | b4558ea | 2005-10-28 16:53:13 -0400 | [diff] [blame] | 1022 | kfree(txdr->buffer_info); |
John W. Linville | 6b27adb | 2005-11-08 15:59:30 -0500 | [diff] [blame] | 1023 | txdr->buffer_info = NULL; |
Jesper Juhl | b4558ea | 2005-10-28 16:53:13 -0400 | [diff] [blame] | 1024 | kfree(rxdr->buffer_info); |
John W. Linville | 6b27adb | 2005-11-08 15:59:30 -0500 | [diff] [blame] | 1025 | rxdr->buffer_info = NULL; |
Jeff Kirsher | f564511 | 2006-01-12 16:51:01 -0800 | [diff] [blame] | 1026 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | return; |
| 1028 | } |
| 1029 | |
| 1030 | static int |
| 1031 | e1000_setup_desc_rings(struct e1000_adapter *adapter) |
| 1032 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1033 | struct e1000_tx_ring *txdr = &adapter->test_tx_ring; |
| 1034 | struct e1000_rx_ring *rxdr = &adapter->test_rx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | struct pci_dev *pdev = adapter->pdev; |
| 1036 | uint32_t rctl; |
| 1037 | int size, i, ret_val; |
| 1038 | |
| 1039 | /* Setup Tx descriptor ring and Tx buffers */ |
| 1040 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1041 | if (!txdr->count) |
| 1042 | txdr->count = E1000_DEFAULT_TXD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | |
| 1044 | size = txdr->count * sizeof(struct e1000_buffer); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1045 | if (!(txdr->buffer_info = kmalloc(size, GFP_KERNEL))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | ret_val = 1; |
| 1047 | goto err_nomem; |
| 1048 | } |
| 1049 | memset(txdr->buffer_info, 0, size); |
| 1050 | |
| 1051 | txdr->size = txdr->count * sizeof(struct e1000_tx_desc); |
| 1052 | E1000_ROUNDUP(txdr->size, 4096); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1053 | if (!(txdr->desc = pci_alloc_consistent(pdev, txdr->size, &txdr->dma))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | ret_val = 2; |
| 1055 | goto err_nomem; |
| 1056 | } |
| 1057 | memset(txdr->desc, 0, txdr->size); |
| 1058 | txdr->next_to_use = txdr->next_to_clean = 0; |
| 1059 | |
| 1060 | E1000_WRITE_REG(&adapter->hw, TDBAL, |
| 1061 | ((uint64_t) txdr->dma & 0x00000000FFFFFFFF)); |
| 1062 | E1000_WRITE_REG(&adapter->hw, TDBAH, ((uint64_t) txdr->dma >> 32)); |
| 1063 | E1000_WRITE_REG(&adapter->hw, TDLEN, |
| 1064 | txdr->count * sizeof(struct e1000_tx_desc)); |
| 1065 | E1000_WRITE_REG(&adapter->hw, TDH, 0); |
| 1066 | E1000_WRITE_REG(&adapter->hw, TDT, 0); |
| 1067 | E1000_WRITE_REG(&adapter->hw, TCTL, |
| 1068 | E1000_TCTL_PSP | E1000_TCTL_EN | |
| 1069 | E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT | |
| 1070 | E1000_FDX_COLLISION_DISTANCE << E1000_COLD_SHIFT); |
| 1071 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1072 | for (i = 0; i < txdr->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*txdr, i); |
| 1074 | struct sk_buff *skb; |
| 1075 | unsigned int size = 1024; |
| 1076 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1077 | if (!(skb = alloc_skb(size, GFP_KERNEL))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | ret_val = 3; |
| 1079 | goto err_nomem; |
| 1080 | } |
| 1081 | skb_put(skb, size); |
| 1082 | txdr->buffer_info[i].skb = skb; |
| 1083 | txdr->buffer_info[i].length = skb->len; |
| 1084 | txdr->buffer_info[i].dma = |
| 1085 | pci_map_single(pdev, skb->data, skb->len, |
| 1086 | PCI_DMA_TODEVICE); |
| 1087 | tx_desc->buffer_addr = cpu_to_le64(txdr->buffer_info[i].dma); |
| 1088 | tx_desc->lower.data = cpu_to_le32(skb->len); |
| 1089 | tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP | |
| 1090 | E1000_TXD_CMD_IFCS | |
| 1091 | E1000_TXD_CMD_RPS); |
| 1092 | tx_desc->upper.data = 0; |
| 1093 | } |
| 1094 | |
| 1095 | /* Setup Rx descriptor ring and Rx buffers */ |
| 1096 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1097 | if (!rxdr->count) |
| 1098 | rxdr->count = E1000_DEFAULT_RXD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | |
| 1100 | size = rxdr->count * sizeof(struct e1000_buffer); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1101 | if (!(rxdr->buffer_info = kmalloc(size, GFP_KERNEL))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | ret_val = 4; |
| 1103 | goto err_nomem; |
| 1104 | } |
| 1105 | memset(rxdr->buffer_info, 0, size); |
| 1106 | |
| 1107 | rxdr->size = rxdr->count * sizeof(struct e1000_rx_desc); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1108 | if (!(rxdr->desc = pci_alloc_consistent(pdev, rxdr->size, &rxdr->dma))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | ret_val = 5; |
| 1110 | goto err_nomem; |
| 1111 | } |
| 1112 | memset(rxdr->desc, 0, rxdr->size); |
| 1113 | rxdr->next_to_use = rxdr->next_to_clean = 0; |
| 1114 | |
| 1115 | rctl = E1000_READ_REG(&adapter->hw, RCTL); |
| 1116 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl & ~E1000_RCTL_EN); |
| 1117 | E1000_WRITE_REG(&adapter->hw, RDBAL, |
| 1118 | ((uint64_t) rxdr->dma & 0xFFFFFFFF)); |
| 1119 | E1000_WRITE_REG(&adapter->hw, RDBAH, ((uint64_t) rxdr->dma >> 32)); |
| 1120 | E1000_WRITE_REG(&adapter->hw, RDLEN, rxdr->size); |
| 1121 | E1000_WRITE_REG(&adapter->hw, RDH, 0); |
| 1122 | E1000_WRITE_REG(&adapter->hw, RDT, 0); |
| 1123 | rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 | |
| 1124 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 1125 | (adapter->hw.mc_filter_type << E1000_RCTL_MO_SHIFT); |
| 1126 | E1000_WRITE_REG(&adapter->hw, RCTL, rctl); |
| 1127 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1128 | for (i = 0; i < rxdr->count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | struct e1000_rx_desc *rx_desc = E1000_RX_DESC(*rxdr, i); |
| 1130 | struct sk_buff *skb; |
| 1131 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1132 | if (!(skb = alloc_skb(E1000_RXBUFFER_2048 + NET_IP_ALIGN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | GFP_KERNEL))) { |
| 1134 | ret_val = 6; |
| 1135 | goto err_nomem; |
| 1136 | } |
| 1137 | skb_reserve(skb, NET_IP_ALIGN); |
| 1138 | rxdr->buffer_info[i].skb = skb; |
| 1139 | rxdr->buffer_info[i].length = E1000_RXBUFFER_2048; |
| 1140 | rxdr->buffer_info[i].dma = |
| 1141 | pci_map_single(pdev, skb->data, E1000_RXBUFFER_2048, |
| 1142 | PCI_DMA_FROMDEVICE); |
| 1143 | rx_desc->buffer_addr = cpu_to_le64(rxdr->buffer_info[i].dma); |
| 1144 | memset(skb->data, 0x00, skb->len); |
| 1145 | } |
| 1146 | |
| 1147 | return 0; |
| 1148 | |
| 1149 | err_nomem: |
| 1150 | e1000_free_desc_rings(adapter); |
| 1151 | return ret_val; |
| 1152 | } |
| 1153 | |
| 1154 | static void |
| 1155 | e1000_phy_disable_receiver(struct e1000_adapter *adapter) |
| 1156 | { |
| 1157 | /* Write out to PHY registers 29 and 30 to disable the Receiver. */ |
| 1158 | e1000_write_phy_reg(&adapter->hw, 29, 0x001F); |
| 1159 | e1000_write_phy_reg(&adapter->hw, 30, 0x8FFC); |
| 1160 | e1000_write_phy_reg(&adapter->hw, 29, 0x001A); |
| 1161 | e1000_write_phy_reg(&adapter->hw, 30, 0x8FF0); |
| 1162 | } |
| 1163 | |
| 1164 | static void |
| 1165 | e1000_phy_reset_clk_and_crs(struct e1000_adapter *adapter) |
| 1166 | { |
| 1167 | uint16_t phy_reg; |
| 1168 | |
| 1169 | /* Because we reset the PHY above, we need to re-force TX_CLK in the |
| 1170 | * Extended PHY Specific Control Register to 25MHz clock. This |
| 1171 | * value defaults back to a 2.5MHz clock when the PHY is reset. |
| 1172 | */ |
| 1173 | e1000_read_phy_reg(&adapter->hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg); |
| 1174 | phy_reg |= M88E1000_EPSCR_TX_CLK_25; |
| 1175 | e1000_write_phy_reg(&adapter->hw, |
| 1176 | M88E1000_EXT_PHY_SPEC_CTRL, phy_reg); |
| 1177 | |
| 1178 | /* In addition, because of the s/w reset above, we need to enable |
| 1179 | * CRS on TX. This must be set for both full and half duplex |
| 1180 | * operation. |
| 1181 | */ |
| 1182 | e1000_read_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, &phy_reg); |
| 1183 | phy_reg |= M88E1000_PSCR_ASSERT_CRS_ON_TX; |
| 1184 | e1000_write_phy_reg(&adapter->hw, |
| 1185 | M88E1000_PHY_SPEC_CTRL, phy_reg); |
| 1186 | } |
| 1187 | |
| 1188 | static int |
| 1189 | e1000_nonintegrated_phy_loopback(struct e1000_adapter *adapter) |
| 1190 | { |
| 1191 | uint32_t ctrl_reg; |
| 1192 | uint16_t phy_reg; |
| 1193 | |
| 1194 | /* Setup the Device Control Register for PHY loopback test. */ |
| 1195 | |
| 1196 | ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL); |
| 1197 | ctrl_reg |= (E1000_CTRL_ILOS | /* Invert Loss-Of-Signal */ |
| 1198 | E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ |
| 1199 | E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ |
| 1200 | E1000_CTRL_SPD_1000 | /* Force Speed to 1000 */ |
| 1201 | E1000_CTRL_FD); /* Force Duplex to FULL */ |
| 1202 | |
| 1203 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl_reg); |
| 1204 | |
| 1205 | /* Read the PHY Specific Control Register (0x10) */ |
| 1206 | e1000_read_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, &phy_reg); |
| 1207 | |
| 1208 | /* Clear Auto-Crossover bits in PHY Specific Control Register |
| 1209 | * (bits 6:5). |
| 1210 | */ |
| 1211 | phy_reg &= ~M88E1000_PSCR_AUTO_X_MODE; |
| 1212 | e1000_write_phy_reg(&adapter->hw, M88E1000_PHY_SPEC_CTRL, phy_reg); |
| 1213 | |
| 1214 | /* Perform software reset on the PHY */ |
| 1215 | e1000_phy_reset(&adapter->hw); |
| 1216 | |
| 1217 | /* Have to setup TX_CLK and TX_CRS after software reset */ |
| 1218 | e1000_phy_reset_clk_and_crs(adapter); |
| 1219 | |
| 1220 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x8100); |
| 1221 | |
| 1222 | /* Wait for reset to complete. */ |
| 1223 | udelay(500); |
| 1224 | |
| 1225 | /* Have to setup TX_CLK and TX_CRS after software reset */ |
| 1226 | e1000_phy_reset_clk_and_crs(adapter); |
| 1227 | |
| 1228 | /* Write out to PHY registers 29 and 30 to disable the Receiver. */ |
| 1229 | e1000_phy_disable_receiver(adapter); |
| 1230 | |
| 1231 | /* Set the loopback bit in the PHY control register. */ |
| 1232 | e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg); |
| 1233 | phy_reg |= MII_CR_LOOPBACK; |
| 1234 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg); |
| 1235 | |
| 1236 | /* Setup TX_CLK and TX_CRS one more time. */ |
| 1237 | e1000_phy_reset_clk_and_crs(adapter); |
| 1238 | |
| 1239 | /* Check Phy Configuration */ |
| 1240 | e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1241 | if (phy_reg != 0x4100) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | return 9; |
| 1243 | |
| 1244 | e1000_read_phy_reg(&adapter->hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_reg); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1245 | if (phy_reg != 0x0070) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | return 10; |
| 1247 | |
| 1248 | e1000_read_phy_reg(&adapter->hw, 29, &phy_reg); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1249 | if (phy_reg != 0x001A) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | return 11; |
| 1251 | |
| 1252 | return 0; |
| 1253 | } |
| 1254 | |
| 1255 | static int |
| 1256 | e1000_integrated_phy_loopback(struct e1000_adapter *adapter) |
| 1257 | { |
| 1258 | uint32_t ctrl_reg = 0; |
| 1259 | uint32_t stat_reg = 0; |
| 1260 | |
| 1261 | adapter->hw.autoneg = FALSE; |
| 1262 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1263 | if (adapter->hw.phy_type == e1000_phy_m88) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | /* Auto-MDI/MDIX Off */ |
| 1265 | e1000_write_phy_reg(&adapter->hw, |
| 1266 | M88E1000_PHY_SPEC_CTRL, 0x0808); |
| 1267 | /* reset to update Auto-MDI/MDIX */ |
| 1268 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x9140); |
| 1269 | /* autoneg off */ |
| 1270 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x8140); |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1271 | } else if (adapter->hw.phy_type == e1000_phy_gg82563) |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1272 | e1000_write_phy_reg(&adapter->hw, |
| 1273 | GG82563_PHY_KMRN_MODE_CTRL, |
Auke Kok | acfbc9f | 2006-06-27 09:06:24 -0700 | [diff] [blame] | 1274 | 0x1CC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1277 | |
| 1278 | if (adapter->hw.phy_type == e1000_phy_ife) { |
| 1279 | /* force 100, set loopback */ |
| 1280 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x6100); |
| 1281 | |
| 1282 | /* Now set up the MAC to the same speed/duplex as the PHY. */ |
| 1283 | ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ |
| 1284 | ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ |
| 1285 | E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ |
| 1286 | E1000_CTRL_SPD_100 |/* Force Speed to 100 */ |
| 1287 | E1000_CTRL_FD); /* Force Duplex to FULL */ |
| 1288 | } else { |
| 1289 | /* force 1000, set loopback */ |
| 1290 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, 0x4140); |
| 1291 | |
| 1292 | /* Now set up the MAC to the same speed/duplex as the PHY. */ |
| 1293 | ctrl_reg = E1000_READ_REG(&adapter->hw, CTRL); |
| 1294 | ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ |
| 1295 | ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ |
| 1296 | E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ |
| 1297 | E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */ |
| 1298 | E1000_CTRL_FD); /* Force Duplex to FULL */ |
| 1299 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1301 | if (adapter->hw.media_type == e1000_media_type_copper && |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1302 | adapter->hw.phy_type == e1000_phy_m88) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */ |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1304 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | /* Set the ILOS bit on the fiber Nic is half |
| 1306 | * duplex link is detected. */ |
| 1307 | stat_reg = E1000_READ_REG(&adapter->hw, STATUS); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1308 | if ((stat_reg & E1000_STATUS_FD) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU); |
| 1310 | } |
| 1311 | |
| 1312 | E1000_WRITE_REG(&adapter->hw, CTRL, ctrl_reg); |
| 1313 | |
| 1314 | /* Disable the receiver on the PHY so when a cable is plugged in, the |
| 1315 | * PHY does not begin to autoneg when a cable is reconnected to the NIC. |
| 1316 | */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1317 | if (adapter->hw.phy_type == e1000_phy_m88) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | e1000_phy_disable_receiver(adapter); |
| 1319 | |
| 1320 | udelay(500); |
| 1321 | |
| 1322 | return 0; |
| 1323 | } |
| 1324 | |
| 1325 | static int |
| 1326 | e1000_set_phy_loopback(struct e1000_adapter *adapter) |
| 1327 | { |
| 1328 | uint16_t phy_reg = 0; |
| 1329 | uint16_t count = 0; |
| 1330 | |
| 1331 | switch (adapter->hw.mac_type) { |
| 1332 | case e1000_82543: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1333 | if (adapter->hw.media_type == e1000_media_type_copper) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | /* Attempt to setup Loopback mode on Non-integrated PHY. |
| 1335 | * Some PHY registers get corrupted at random, so |
| 1336 | * attempt this 10 times. |
| 1337 | */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1338 | while (e1000_nonintegrated_phy_loopback(adapter) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | count++ < 10); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1340 | if (count < 11) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | return 0; |
| 1342 | } |
| 1343 | break; |
| 1344 | |
| 1345 | case e1000_82544: |
| 1346 | case e1000_82540: |
| 1347 | case e1000_82545: |
| 1348 | case e1000_82545_rev_3: |
| 1349 | case e1000_82546: |
| 1350 | case e1000_82546_rev_3: |
| 1351 | case e1000_82541: |
| 1352 | case e1000_82541_rev_2: |
| 1353 | case e1000_82547: |
| 1354 | case e1000_82547_rev_2: |
Mallikarjuna R Chilakala | 868d530 | 2005-10-04 06:58:59 -0400 | [diff] [blame] | 1355 | case e1000_82571: |
| 1356 | case e1000_82572: |
Malli Chilakala | 4564327 | 2005-06-17 17:42:42 -0700 | [diff] [blame] | 1357 | case e1000_82573: |
Jeff Kirsher | 6418ecc | 2006-03-02 18:21:10 -0800 | [diff] [blame] | 1358 | case e1000_80003es2lan: |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1359 | case e1000_ich8lan: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | return e1000_integrated_phy_loopback(adapter); |
| 1361 | break; |
| 1362 | |
| 1363 | default: |
| 1364 | /* Default PHY loopback work is to read the MII |
| 1365 | * control register and assert bit 14 (loopback mode). |
| 1366 | */ |
| 1367 | e1000_read_phy_reg(&adapter->hw, PHY_CTRL, &phy_reg); |
| 1368 | phy_reg |= MII_CR_LOOPBACK; |
| 1369 | e1000_write_phy_reg(&adapter->hw, PHY_CTRL, phy_reg); |
| 1370 | return 0; |
| 1371 | break; |
| 1372 | } |
| 1373 | |
| 1374 | return 8; |
| 1375 | } |
| 1376 | |
| 1377 | static int |
| 1378 | e1000_setup_loopback_test(struct e1000_adapter *adapter) |
| 1379 | { |
Jeff Kirsher | 4927316 | 2006-01-12 16:50:44 -0800 | [diff] [blame] | 1380 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | uint32_t rctl; |
| 1382 | |
Jeff Kirsher | 4927316 | 2006-01-12 16:50:44 -0800 | [diff] [blame] | 1383 | if (hw->media_type == e1000_media_type_fiber || |
| 1384 | hw->media_type == e1000_media_type_internal_serdes) { |
| 1385 | switch (hw->mac_type) { |
| 1386 | case e1000_82545: |
| 1387 | case e1000_82546: |
| 1388 | case e1000_82545_rev_3: |
| 1389 | case e1000_82546_rev_3: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | return e1000_set_phy_loopback(adapter); |
Jeff Kirsher | 4927316 | 2006-01-12 16:50:44 -0800 | [diff] [blame] | 1391 | break; |
| 1392 | case e1000_82571: |
| 1393 | case e1000_82572: |
| 1394 | #define E1000_SERDES_LB_ON 0x410 |
| 1395 | e1000_set_phy_loopback(adapter); |
| 1396 | E1000_WRITE_REG(hw, SCTL, E1000_SERDES_LB_ON); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1397 | msleep(10); |
Jeff Kirsher | 4927316 | 2006-01-12 16:50:44 -0800 | [diff] [blame] | 1398 | return 0; |
| 1399 | break; |
| 1400 | default: |
| 1401 | rctl = E1000_READ_REG(hw, RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | rctl |= E1000_RCTL_LBM_TCVR; |
Jeff Kirsher | 4927316 | 2006-01-12 16:50:44 -0800 | [diff] [blame] | 1403 | E1000_WRITE_REG(hw, RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | return 0; |
| 1405 | } |
Jeff Kirsher | 4927316 | 2006-01-12 16:50:44 -0800 | [diff] [blame] | 1406 | } else if (hw->media_type == e1000_media_type_copper) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | return e1000_set_phy_loopback(adapter); |
| 1408 | |
| 1409 | return 7; |
| 1410 | } |
| 1411 | |
| 1412 | static void |
| 1413 | e1000_loopback_cleanup(struct e1000_adapter *adapter) |
| 1414 | { |
Jeff Kirsher | 4927316 | 2006-01-12 16:50:44 -0800 | [diff] [blame] | 1415 | struct e1000_hw *hw = &adapter->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | uint32_t rctl; |
| 1417 | uint16_t phy_reg; |
| 1418 | |
Jeff Kirsher | 4927316 | 2006-01-12 16:50:44 -0800 | [diff] [blame] | 1419 | rctl = E1000_READ_REG(hw, RCTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC); |
Jeff Kirsher | 4927316 | 2006-01-12 16:50:44 -0800 | [diff] [blame] | 1421 | E1000_WRITE_REG(hw, RCTL, rctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | |
Jeff Kirsher | 4927316 | 2006-01-12 16:50:44 -0800 | [diff] [blame] | 1423 | switch (hw->mac_type) { |
| 1424 | case e1000_82571: |
| 1425 | case e1000_82572: |
| 1426 | if (hw->media_type == e1000_media_type_fiber || |
| 1427 | hw->media_type == e1000_media_type_internal_serdes) { |
| 1428 | #define E1000_SERDES_LB_OFF 0x400 |
| 1429 | E1000_WRITE_REG(hw, SCTL, E1000_SERDES_LB_OFF); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1430 | msleep(10); |
Jeff Kirsher | 4927316 | 2006-01-12 16:50:44 -0800 | [diff] [blame] | 1431 | break; |
Jeff Kirsher | fd80324 | 2005-12-13 00:06:22 -0500 | [diff] [blame] | 1432 | } |
Jeff Kirsher | 4927316 | 2006-01-12 16:50:44 -0800 | [diff] [blame] | 1433 | /* Fall Through */ |
| 1434 | case e1000_82545: |
| 1435 | case e1000_82546: |
| 1436 | case e1000_82545_rev_3: |
| 1437 | case e1000_82546_rev_3: |
| 1438 | default: |
| 1439 | hw->autoneg = TRUE; |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1440 | if (hw->phy_type == e1000_phy_gg82563) |
Jeff Kirsher | 8704163 | 2006-03-02 18:21:24 -0800 | [diff] [blame] | 1441 | e1000_write_phy_reg(hw, |
| 1442 | GG82563_PHY_KMRN_MODE_CTRL, |
| 1443 | 0x180); |
Jeff Kirsher | 4927316 | 2006-01-12 16:50:44 -0800 | [diff] [blame] | 1444 | e1000_read_phy_reg(hw, PHY_CTRL, &phy_reg); |
| 1445 | if (phy_reg & MII_CR_LOOPBACK) { |
| 1446 | phy_reg &= ~MII_CR_LOOPBACK; |
| 1447 | e1000_write_phy_reg(hw, PHY_CTRL, phy_reg); |
| 1448 | e1000_phy_reset(hw); |
| 1449 | } |
| 1450 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | static void |
| 1455 | e1000_create_lbtest_frame(struct sk_buff *skb, unsigned int frame_size) |
| 1456 | { |
| 1457 | memset(skb->data, 0xFF, frame_size); |
Jeff Kirsher | ce7393b | 2006-01-12 16:51:12 -0800 | [diff] [blame] | 1458 | frame_size &= ~1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1); |
| 1460 | memset(&skb->data[frame_size / 2 + 10], 0xBE, 1); |
| 1461 | memset(&skb->data[frame_size / 2 + 12], 0xAF, 1); |
| 1462 | } |
| 1463 | |
| 1464 | static int |
| 1465 | e1000_check_lbtest_frame(struct sk_buff *skb, unsigned int frame_size) |
| 1466 | { |
Jeff Kirsher | ce7393b | 2006-01-12 16:51:12 -0800 | [diff] [blame] | 1467 | frame_size &= ~1; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1468 | if (*(skb->data + 3) == 0xFF) { |
| 1469 | if ((*(skb->data + frame_size / 2 + 10) == 0xBE) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | (*(skb->data + frame_size / 2 + 12) == 0xAF)) { |
| 1471 | return 0; |
| 1472 | } |
| 1473 | } |
| 1474 | return 13; |
| 1475 | } |
| 1476 | |
| 1477 | static int |
| 1478 | e1000_run_loopback_test(struct e1000_adapter *adapter) |
| 1479 | { |
Mallikarjuna R Chilakala | 581d708 | 2005-10-04 07:01:55 -0400 | [diff] [blame] | 1480 | struct e1000_tx_ring *txdr = &adapter->test_tx_ring; |
| 1481 | struct e1000_rx_ring *rxdr = &adapter->test_rx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | struct pci_dev *pdev = adapter->pdev; |
Malli Chilakala | e4eff72 | 2005-04-28 19:38:30 -0700 | [diff] [blame] | 1483 | int i, j, k, l, lc, good_cnt, ret_val=0; |
| 1484 | unsigned long time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | |
| 1486 | E1000_WRITE_REG(&adapter->hw, RDT, rxdr->count - 1); |
| 1487 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1488 | /* Calculate the loop count based on the largest descriptor ring |
Malli Chilakala | e4eff72 | 2005-04-28 19:38:30 -0700 | [diff] [blame] | 1489 | * The idea is to wrap the largest ring a number of times using 64 |
| 1490 | * send/receive pairs during each loop |
| 1491 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1493 | if (rxdr->count <= txdr->count) |
Malli Chilakala | e4eff72 | 2005-04-28 19:38:30 -0700 | [diff] [blame] | 1494 | lc = ((txdr->count / 64) * 2) + 1; |
| 1495 | else |
| 1496 | lc = ((rxdr->count / 64) * 2) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | |
Malli Chilakala | e4eff72 | 2005-04-28 19:38:30 -0700 | [diff] [blame] | 1498 | k = l = 0; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1499 | for (j = 0; j <= lc; j++) { /* loop count loop */ |
| 1500 | for (i = 0; i < 64; i++) { /* send the packets */ |
| 1501 | e1000_create_lbtest_frame(txdr->buffer_info[i].skb, |
Malli Chilakala | e4eff72 | 2005-04-28 19:38:30 -0700 | [diff] [blame] | 1502 | 1024); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1503 | pci_dma_sync_single_for_device(pdev, |
Malli Chilakala | e4eff72 | 2005-04-28 19:38:30 -0700 | [diff] [blame] | 1504 | txdr->buffer_info[k].dma, |
| 1505 | txdr->buffer_info[k].length, |
| 1506 | PCI_DMA_TODEVICE); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1507 | if (unlikely(++k == txdr->count)) k = 0; |
Malli Chilakala | e4eff72 | 2005-04-28 19:38:30 -0700 | [diff] [blame] | 1508 | } |
| 1509 | E1000_WRITE_REG(&adapter->hw, TDT, k); |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1510 | msleep(200); |
Malli Chilakala | e4eff72 | 2005-04-28 19:38:30 -0700 | [diff] [blame] | 1511 | time = jiffies; /* set the start time for the receive */ |
| 1512 | good_cnt = 0; |
| 1513 | do { /* receive the sent packets */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1514 | pci_dma_sync_single_for_cpu(pdev, |
Malli Chilakala | e4eff72 | 2005-04-28 19:38:30 -0700 | [diff] [blame] | 1515 | rxdr->buffer_info[l].dma, |
| 1516 | rxdr->buffer_info[l].length, |
| 1517 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1518 | |
Malli Chilakala | e4eff72 | 2005-04-28 19:38:30 -0700 | [diff] [blame] | 1519 | ret_val = e1000_check_lbtest_frame( |
| 1520 | rxdr->buffer_info[l].skb, |
| 1521 | 1024); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1522 | if (!ret_val) |
Malli Chilakala | e4eff72 | 2005-04-28 19:38:30 -0700 | [diff] [blame] | 1523 | good_cnt++; |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1524 | if (unlikely(++l == rxdr->count)) l = 0; |
| 1525 | /* time + 20 msecs (200 msecs on 2.4) is more than |
| 1526 | * enough time to complete the receives, if it's |
Malli Chilakala | e4eff72 | 2005-04-28 19:38:30 -0700 | [diff] [blame] | 1527 | * exceeded, break and error off |
| 1528 | */ |
| 1529 | } while (good_cnt < 64 && jiffies < (time + 20)); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1530 | if (good_cnt != 64) { |
Malli Chilakala | e4eff72 | 2005-04-28 19:38:30 -0700 | [diff] [blame] | 1531 | ret_val = 13; /* ret_val is the same as mis-compare */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1532 | break; |
Malli Chilakala | e4eff72 | 2005-04-28 19:38:30 -0700 | [diff] [blame] | 1533 | } |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1534 | if (jiffies >= (time + 2)) { |
Malli Chilakala | e4eff72 | 2005-04-28 19:38:30 -0700 | [diff] [blame] | 1535 | ret_val = 14; /* error code for time out error */ |
| 1536 | break; |
| 1537 | } |
| 1538 | } /* end loop count loop */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | return ret_val; |
| 1540 | } |
| 1541 | |
| 1542 | static int |
| 1543 | e1000_loopback_test(struct e1000_adapter *adapter, uint64_t *data) |
| 1544 | { |
Jeff Kirsher | 5712819 | 2006-01-12 16:50:28 -0800 | [diff] [blame] | 1545 | /* PHY loopback cannot be performed if SoL/IDER |
| 1546 | * sessions are active */ |
| 1547 | if (e1000_check_phy_reset_block(&adapter->hw)) { |
| 1548 | DPRINTK(DRV, ERR, "Cannot do PHY loopback test " |
| 1549 | "when SoL/IDER is active.\n"); |
| 1550 | *data = 0; |
| 1551 | goto out; |
| 1552 | } |
| 1553 | |
| 1554 | if ((*data = e1000_setup_desc_rings(adapter))) |
| 1555 | goto out; |
| 1556 | if ((*data = e1000_setup_loopback_test(adapter))) |
| 1557 | goto err_loopback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | *data = e1000_run_loopback_test(adapter); |
| 1559 | e1000_loopback_cleanup(adapter); |
Jeff Kirsher | 5712819 | 2006-01-12 16:50:28 -0800 | [diff] [blame] | 1560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | err_loopback: |
Jeff Kirsher | 5712819 | 2006-01-12 16:50:28 -0800 | [diff] [blame] | 1562 | e1000_free_desc_rings(adapter); |
| 1563 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | return *data; |
| 1565 | } |
| 1566 | |
| 1567 | static int |
| 1568 | e1000_link_test(struct e1000_adapter *adapter, uint64_t *data) |
| 1569 | { |
| 1570 | *data = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | if (adapter->hw.media_type == e1000_media_type_internal_serdes) { |
| 1572 | int i = 0; |
| 1573 | adapter->hw.serdes_link_down = TRUE; |
| 1574 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1575 | /* On some blade server designs, link establishment |
| 1576 | * could take as long as 2-3 minutes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | do { |
| 1578 | e1000_check_for_link(&adapter->hw); |
| 1579 | if (adapter->hw.serdes_link_down == FALSE) |
| 1580 | return *data; |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1581 | msleep(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | } while (i++ < 3750); |
| 1583 | |
Malli Chilakala | 2648345 | 2005-04-28 19:44:46 -0700 | [diff] [blame] | 1584 | *data = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | } else { |
| 1586 | e1000_check_for_link(&adapter->hw); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1587 | if (adapter->hw.autoneg) /* if auto_neg is set wait for it */ |
Jeff Garzik | f8ec473 | 2006-09-19 15:27:07 -0400 | [diff] [blame] | 1588 | msleep(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1590 | if (!(E1000_READ_REG(&adapter->hw, STATUS) & E1000_STATUS_LU)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | *data = 1; |
| 1592 | } |
| 1593 | } |
| 1594 | return *data; |
| 1595 | } |
| 1596 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1597 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | e1000_diag_test_count(struct net_device *netdev) |
| 1599 | { |
| 1600 | return E1000_TEST_LEN; |
| 1601 | } |
| 1602 | |
Jesse Brandeburg | d658266 | 2006-08-16 13:31:33 -0700 | [diff] [blame] | 1603 | extern void e1000_power_up_phy(struct e1000_adapter *); |
| 1604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | static void |
| 1606 | e1000_diag_test(struct net_device *netdev, |
| 1607 | struct ethtool_test *eth_test, uint64_t *data) |
| 1608 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1609 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | boolean_t if_running = netif_running(netdev); |
| 1611 | |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1612 | set_bit(__E1000_DRIVER_TESTING, &adapter->flags); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1613 | if (eth_test->flags == ETH_TEST_FL_OFFLINE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | /* Offline tests */ |
| 1615 | |
| 1616 | /* save speed, duplex, autoneg settings */ |
| 1617 | uint16_t autoneg_advertised = adapter->hw.autoneg_advertised; |
| 1618 | uint8_t forced_speed_duplex = adapter->hw.forced_speed_duplex; |
| 1619 | uint8_t autoneg = adapter->hw.autoneg; |
| 1620 | |
Jesse Brandeburg | d658266 | 2006-08-16 13:31:33 -0700 | [diff] [blame] | 1621 | DPRINTK(HW, INFO, "offline testing starting\n"); |
| 1622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | /* Link test performed before hardware reset so autoneg doesn't |
| 1624 | * interfere with test result */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1625 | if (e1000_link_test(adapter, &data[4])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1627 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1628 | if (if_running) |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1629 | /* indicate we're in test mode */ |
| 1630 | dev_close(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | else |
| 1632 | e1000_reset(adapter); |
| 1633 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1634 | if (e1000_reg_test(adapter, &data[0])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1636 | |
| 1637 | e1000_reset(adapter); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1638 | if (e1000_eeprom_test(adapter, &data[1])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1640 | |
| 1641 | e1000_reset(adapter); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1642 | if (e1000_intr_test(adapter, &data[2])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1644 | |
| 1645 | e1000_reset(adapter); |
Jesse Brandeburg | d658266 | 2006-08-16 13:31:33 -0700 | [diff] [blame] | 1646 | /* make sure the phy is powered up */ |
| 1647 | e1000_power_up_phy(adapter); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1648 | if (e1000_loopback_test(adapter, &data[3])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1650 | |
| 1651 | /* restore speed, duplex, autoneg settings */ |
| 1652 | adapter->hw.autoneg_advertised = autoneg_advertised; |
| 1653 | adapter->hw.forced_speed_duplex = forced_speed_duplex; |
| 1654 | adapter->hw.autoneg = autoneg; |
| 1655 | |
| 1656 | e1000_reset(adapter); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1657 | clear_bit(__E1000_DRIVER_TESTING, &adapter->flags); |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1658 | if (if_running) |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1659 | dev_open(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | } else { |
Jesse Brandeburg | d658266 | 2006-08-16 13:31:33 -0700 | [diff] [blame] | 1661 | DPRINTK(HW, INFO, "online testing starting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | /* Online tests */ |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1663 | if (e1000_link_test(adapter, &data[4])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1665 | |
| 1666 | /* Offline tests aren't run; pass by default */ |
| 1667 | data[0] = 0; |
| 1668 | data[1] = 0; |
| 1669 | data[2] = 0; |
| 1670 | data[3] = 0; |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1671 | |
| 1672 | clear_bit(__E1000_DRIVER_TESTING, &adapter->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | } |
Mallikarjuna R Chilakala | 352c9f8 | 2005-10-04 07:07:24 -0400 | [diff] [blame] | 1674 | msleep_interruptible(4 * 1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1677 | static int e1000_wol_exclusion(struct e1000_adapter *adapter, struct ethtool_wolinfo *wol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | struct e1000_hw *hw = &adapter->hw; |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1680 | int retval = 1; /* fail by default */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1682 | switch (hw->device_id) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | case E1000_DEV_ID_82543GC_FIBER: |
| 1684 | case E1000_DEV_ID_82543GC_COPPER: |
| 1685 | case E1000_DEV_ID_82544EI_FIBER: |
| 1686 | case E1000_DEV_ID_82546EB_QUAD_COPPER: |
| 1687 | case E1000_DEV_ID_82545EM_FIBER: |
| 1688 | case E1000_DEV_ID_82545EM_COPPER: |
Jeff Kirsher | 8491682 | 2006-03-02 18:18:48 -0800 | [diff] [blame] | 1689 | case E1000_DEV_ID_82546GB_QUAD_COPPER: |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1690 | case E1000_DEV_ID_82546GB_PCIE: |
| 1691 | /* these don't support WoL at all */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | wol->supported = 0; |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1693 | break; |
| 1694 | case E1000_DEV_ID_82546EB_FIBER: |
| 1695 | case E1000_DEV_ID_82546GB_FIBER: |
| 1696 | case E1000_DEV_ID_82571EB_FIBER: |
| 1697 | case E1000_DEV_ID_82571EB_SERDES: |
| 1698 | case E1000_DEV_ID_82571EB_COPPER: |
| 1699 | /* Wake events not supported on port B */ |
| 1700 | if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1) { |
| 1701 | wol->supported = 0; |
| 1702 | break; |
| 1703 | } |
| 1704 | /* return success for non excluded adapter ports */ |
| 1705 | retval = 0; |
| 1706 | break; |
Jesse Brandeburg | 5881cde | 2006-08-31 14:27:47 -0700 | [diff] [blame] | 1707 | case E1000_DEV_ID_82571EB_QUAD_COPPER: |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1708 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
| 1709 | /* quad port adapters only support WoL on port A */ |
| 1710 | if (!adapter->quad_port_a) { |
| 1711 | wol->supported = 0; |
| 1712 | break; |
| 1713 | } |
| 1714 | /* return success for non excluded adapter ports */ |
| 1715 | retval = 0; |
| 1716 | break; |
| 1717 | default: |
| 1718 | /* dual port cards only support WoL on port A from now on |
| 1719 | * unless it was enabled in the eeprom for port B |
| 1720 | * so exclude FUNC_1 ports from having WoL enabled */ |
| 1721 | if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1 && |
| 1722 | !adapter->eeprom_wol) { |
| 1723 | wol->supported = 0; |
| 1724 | break; |
| 1725 | } |
| 1726 | |
| 1727 | retval = 0; |
| 1728 | } |
| 1729 | |
| 1730 | return retval; |
| 1731 | } |
| 1732 | |
| 1733 | static void |
| 1734 | e1000_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 1735 | { |
| 1736 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1737 | |
| 1738 | wol->supported = WAKE_UCAST | WAKE_MCAST | |
| 1739 | WAKE_BCAST | WAKE_MAGIC; |
| 1740 | wol->wolopts = 0; |
| 1741 | |
| 1742 | /* this function will set ->supported = 0 and return 1 if wol is not |
| 1743 | * supported by this hardware */ |
| 1744 | if (e1000_wol_exclusion(adapter, wol)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | return; |
| 1746 | |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1747 | /* apply any specific unsupported masks here */ |
| 1748 | switch (adapter->hw.device_id) { |
Jeff Kirsher | 8491682 | 2006-03-02 18:18:48 -0800 | [diff] [blame] | 1749 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1750 | /* KSP3 does not suppport UCAST wake-ups */ |
| 1751 | wol->supported &= ~WAKE_UCAST; |
Jeff Kirsher | 8491682 | 2006-03-02 18:18:48 -0800 | [diff] [blame] | 1752 | |
| 1753 | if (adapter->wol & E1000_WUFC_EX) |
| 1754 | DPRINTK(DRV, ERR, "Interface does not support " |
| 1755 | "directed (unicast) frame wake-up packets\n"); |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1756 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | default: |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1758 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | } |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1760 | |
| 1761 | if (adapter->wol & E1000_WUFC_EX) |
| 1762 | wol->wolopts |= WAKE_UCAST; |
| 1763 | if (adapter->wol & E1000_WUFC_MC) |
| 1764 | wol->wolopts |= WAKE_MCAST; |
| 1765 | if (adapter->wol & E1000_WUFC_BC) |
| 1766 | wol->wolopts |= WAKE_BCAST; |
| 1767 | if (adapter->wol & E1000_WUFC_MAG) |
| 1768 | wol->wolopts |= WAKE_MAGIC; |
| 1769 | |
| 1770 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | static int |
| 1774 | e1000_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 1775 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1776 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | struct e1000_hw *hw = &adapter->hw; |
| 1778 | |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1779 | if (wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE)) |
| 1780 | return -EOPNOTSUPP; |
| 1781 | |
| 1782 | if (e1000_wol_exclusion(adapter, wol)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | return wol->wolopts ? -EOPNOTSUPP : 0; |
| 1784 | |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1785 | switch (hw->device_id) { |
Jeff Kirsher | 8491682 | 2006-03-02 18:18:48 -0800 | [diff] [blame] | 1786 | case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: |
Jeff Kirsher | 8491682 | 2006-03-02 18:18:48 -0800 | [diff] [blame] | 1787 | if (wol->wolopts & WAKE_UCAST) { |
| 1788 | DPRINTK(DRV, ERR, "Interface does not support " |
| 1789 | "directed (unicast) frame wake-up packets\n"); |
| 1790 | return -EOPNOTSUPP; |
| 1791 | } |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1792 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | default: |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1794 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
Jesse Brandeburg | 120cd57 | 2006-08-31 14:27:46 -0700 | [diff] [blame] | 1797 | /* these settings will always override what we currently have */ |
| 1798 | adapter->wol = 0; |
| 1799 | |
| 1800 | if (wol->wolopts & WAKE_UCAST) |
| 1801 | adapter->wol |= E1000_WUFC_EX; |
| 1802 | if (wol->wolopts & WAKE_MCAST) |
| 1803 | adapter->wol |= E1000_WUFC_MC; |
| 1804 | if (wol->wolopts & WAKE_BCAST) |
| 1805 | adapter->wol |= E1000_WUFC_BC; |
| 1806 | if (wol->wolopts & WAKE_MAGIC) |
| 1807 | adapter->wol |= E1000_WUFC_MAG; |
| 1808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | return 0; |
| 1810 | } |
| 1811 | |
| 1812 | /* toggle LED 4 times per second = 2 "blinks" per second */ |
| 1813 | #define E1000_ID_INTERVAL (HZ/4) |
| 1814 | |
| 1815 | /* bit defines for adapter->led_status */ |
| 1816 | #define E1000_LED_ON 0 |
| 1817 | |
| 1818 | static void |
| 1819 | e1000_led_blink_callback(unsigned long data) |
| 1820 | { |
| 1821 | struct e1000_adapter *adapter = (struct e1000_adapter *) data; |
| 1822 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1823 | if (test_and_change_bit(E1000_LED_ON, &adapter->led_status)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | e1000_led_off(&adapter->hw); |
| 1825 | else |
| 1826 | e1000_led_on(&adapter->hw); |
| 1827 | |
| 1828 | mod_timer(&adapter->blink_timer, jiffies + E1000_ID_INTERVAL); |
| 1829 | } |
| 1830 | |
| 1831 | static int |
| 1832 | e1000_phys_id(struct net_device *netdev, uint32_t data) |
| 1833 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1834 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1836 | if (!data || data > (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | data = (uint32_t)(MAX_SCHEDULE_TIMEOUT / HZ); |
| 1838 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1839 | if (adapter->hw.mac_type < e1000_82571) { |
| 1840 | if (!adapter->blink_timer.function) { |
Malli Chilakala | d439d4b | 2005-06-17 17:43:56 -0700 | [diff] [blame] | 1841 | init_timer(&adapter->blink_timer); |
| 1842 | adapter->blink_timer.function = e1000_led_blink_callback; |
| 1843 | adapter->blink_timer.data = (unsigned long) adapter; |
| 1844 | } |
| 1845 | e1000_setup_led(&adapter->hw); |
| 1846 | mod_timer(&adapter->blink_timer, jiffies); |
| 1847 | msleep_interruptible(data * 1000); |
| 1848 | del_timer_sync(&adapter->blink_timer); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1849 | } else if (adapter->hw.phy_type == e1000_phy_ife) { |
| 1850 | if (!adapter->blink_timer.function) { |
| 1851 | init_timer(&adapter->blink_timer); |
| 1852 | adapter->blink_timer.function = e1000_led_blink_callback; |
| 1853 | adapter->blink_timer.data = (unsigned long) adapter; |
| 1854 | } |
| 1855 | mod_timer(&adapter->blink_timer, jiffies); |
Jeff Kirsher | d8c2bd3 | 2006-01-12 16:50:37 -0800 | [diff] [blame] | 1856 | msleep_interruptible(data * 1000); |
Auke Kok | cd94dd0 | 2006-06-27 09:08:22 -0700 | [diff] [blame] | 1857 | del_timer_sync(&adapter->blink_timer); |
| 1858 | e1000_write_phy_reg(&(adapter->hw), IFE_PHY_SPECIAL_CONTROL_LED, 0); |
Jeff Kirsher | d8c2bd3 | 2006-01-12 16:50:37 -0800 | [diff] [blame] | 1859 | } else { |
Auke Kok | f1b3a85 | 2006-06-27 09:07:56 -0700 | [diff] [blame] | 1860 | e1000_blink_led_start(&adapter->hw); |
Malli Chilakala | d439d4b | 2005-06-17 17:43:56 -0700 | [diff] [blame] | 1861 | msleep_interruptible(data * 1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | } |
| 1863 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | e1000_led_off(&adapter->hw); |
| 1865 | clear_bit(E1000_LED_ON, &adapter->led_status); |
| 1866 | e1000_cleanup_led(&adapter->hw); |
| 1867 | |
| 1868 | return 0; |
| 1869 | } |
| 1870 | |
| 1871 | static int |
| 1872 | e1000_nway_reset(struct net_device *netdev) |
| 1873 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1874 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 2db10a0 | 2006-06-27 09:06:28 -0700 | [diff] [blame] | 1875 | if (netif_running(netdev)) |
| 1876 | e1000_reinit_locked(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | return 0; |
| 1878 | } |
| 1879 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1880 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | e1000_get_stats_count(struct net_device *netdev) |
| 1882 | { |
| 1883 | return E1000_STATS_LEN; |
| 1884 | } |
| 1885 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1886 | static void |
| 1887 | e1000_get_ethtool_stats(struct net_device *netdev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | struct ethtool_stats *stats, uint64_t *data) |
| 1889 | { |
Malli Chilakala | 60490fe | 2005-06-17 17:41:45 -0700 | [diff] [blame] | 1890 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | int i; |
| 1892 | |
| 1893 | e1000_update_stats(adapter); |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 1894 | for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) { |
| 1895 | char *p = (char *)adapter+e1000_gstrings_stats[i].stat_offset; |
| 1896 | data[i] = (e1000_gstrings_stats[i].sizeof_stat == |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p; |
| 1898 | } |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 1899 | /* BUG_ON(i != E1000_STATS_LEN); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | } |
| 1901 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1902 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | e1000_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data) |
| 1904 | { |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 1905 | uint8_t *p = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | int i; |
| 1907 | |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1908 | switch (stringset) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | case ETH_SS_TEST: |
Jesse Brandeburg | 96838a4 | 2006-01-18 13:01:39 -0800 | [diff] [blame] | 1910 | memcpy(data, *e1000_gstrings_test, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | E1000_TEST_LEN*ETH_GSTRING_LEN); |
| 1912 | break; |
| 1913 | case ETH_SS_STATS: |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 1914 | for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) { |
| 1915 | memcpy(p, e1000_gstrings_stats[i].stat_string, |
| 1916 | ETH_GSTRING_LEN); |
| 1917 | p += ETH_GSTRING_LEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | } |
Jeff Kirsher | 7bfa481 | 2006-01-12 16:50:41 -0800 | [diff] [blame] | 1919 | /* BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | break; |
| 1921 | } |
| 1922 | } |
| 1923 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 1924 | static const struct ethtool_ops e1000_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | .get_settings = e1000_get_settings, |
| 1926 | .set_settings = e1000_set_settings, |
| 1927 | .get_drvinfo = e1000_get_drvinfo, |
| 1928 | .get_regs_len = e1000_get_regs_len, |
| 1929 | .get_regs = e1000_get_regs, |
| 1930 | .get_wol = e1000_get_wol, |
| 1931 | .set_wol = e1000_set_wol, |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1932 | .get_msglevel = e1000_get_msglevel, |
| 1933 | .set_msglevel = e1000_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | .nway_reset = e1000_nway_reset, |
| 1935 | .get_link = ethtool_op_get_link, |
| 1936 | .get_eeprom_len = e1000_get_eeprom_len, |
| 1937 | .get_eeprom = e1000_get_eeprom, |
| 1938 | .set_eeprom = e1000_set_eeprom, |
| 1939 | .get_ringparam = e1000_get_ringparam, |
| 1940 | .set_ringparam = e1000_set_ringparam, |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1941 | .get_pauseparam = e1000_get_pauseparam, |
| 1942 | .set_pauseparam = e1000_set_pauseparam, |
| 1943 | .get_rx_csum = e1000_get_rx_csum, |
| 1944 | .set_rx_csum = e1000_set_rx_csum, |
| 1945 | .get_tx_csum = e1000_get_tx_csum, |
| 1946 | .set_tx_csum = e1000_set_tx_csum, |
| 1947 | .get_sg = ethtool_op_get_sg, |
| 1948 | .set_sg = ethtool_op_set_sg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | #ifdef NETIF_F_TSO |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1950 | .get_tso = ethtool_op_get_tso, |
| 1951 | .set_tso = e1000_set_tso, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | #endif |
| 1953 | .self_test_count = e1000_diag_test_count, |
| 1954 | .self_test = e1000_diag_test, |
| 1955 | .get_strings = e1000_get_strings, |
| 1956 | .phys_id = e1000_phys_id, |
| 1957 | .get_stats_count = e1000_get_stats_count, |
| 1958 | .get_ethtool_stats = e1000_get_ethtool_stats, |
Auke Kok | 8fc897b | 2006-08-28 14:56:16 -0700 | [diff] [blame] | 1959 | .get_perm_addr = ethtool_op_get_perm_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | }; |
| 1961 | |
| 1962 | void e1000_set_ethtool_ops(struct net_device *netdev) |
| 1963 | { |
| 1964 | SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops); |
| 1965 | } |