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