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