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