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