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> |
Bruce Allan | 203e415 | 2012-12-05 08:40:59 +0000 | [diff] [blame] | 38 | #include <linux/mdio.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 | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 123 | #define E1000_TEST_LEN ARRAY_SIZE(e1000_gstrings_test) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 124 | |
| 125 | static int e1000_get_settings(struct net_device *netdev, |
| 126 | struct ethtool_cmd *ecmd) |
| 127 | { |
| 128 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 129 | struct e1000_hw *hw = &adapter->hw; |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 130 | u32 speed; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 131 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 132 | if (hw->phy.media_type == e1000_media_type_copper) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 133 | ecmd->supported = (SUPPORTED_10baseT_Half | |
| 134 | SUPPORTED_10baseT_Full | |
| 135 | SUPPORTED_100baseT_Half | |
| 136 | SUPPORTED_100baseT_Full | |
| 137 | SUPPORTED_1000baseT_Full | |
| 138 | SUPPORTED_Autoneg | |
| 139 | SUPPORTED_TP); |
| 140 | if (hw->phy.type == e1000_phy_ife) |
| 141 | ecmd->supported &= ~SUPPORTED_1000baseT_Full; |
| 142 | ecmd->advertising = ADVERTISED_TP; |
| 143 | |
| 144 | if (hw->mac.autoneg == 1) { |
| 145 | ecmd->advertising |= ADVERTISED_Autoneg; |
| 146 | /* the e1000 autoneg seems to match ethtool nicely */ |
| 147 | ecmd->advertising |= hw->phy.autoneg_advertised; |
| 148 | } |
| 149 | |
| 150 | ecmd->port = PORT_TP; |
| 151 | ecmd->phy_address = hw->phy.addr; |
| 152 | ecmd->transceiver = XCVR_INTERNAL; |
| 153 | |
| 154 | } else { |
| 155 | ecmd->supported = (SUPPORTED_1000baseT_Full | |
| 156 | SUPPORTED_FIBRE | |
| 157 | SUPPORTED_Autoneg); |
| 158 | |
| 159 | ecmd->advertising = (ADVERTISED_1000baseT_Full | |
| 160 | ADVERTISED_FIBRE | |
| 161 | ADVERTISED_Autoneg); |
| 162 | |
| 163 | ecmd->port = PORT_FIBRE; |
| 164 | ecmd->transceiver = XCVR_EXTERNAL; |
| 165 | } |
| 166 | |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 167 | speed = -1; |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 168 | ecmd->duplex = -1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 169 | |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 170 | if (netif_running(netdev)) { |
| 171 | if (netif_carrier_ok(netdev)) { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 172 | speed = adapter->link_speed; |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 173 | ecmd->duplex = adapter->link_duplex - 1; |
| 174 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 175 | } else { |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 176 | u32 status = er32(STATUS); |
| 177 | if (status & E1000_STATUS_LU) { |
| 178 | if (status & E1000_STATUS_SPEED_1000) |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 179 | speed = SPEED_1000; |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 180 | else if (status & E1000_STATUS_SPEED_100) |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 181 | speed = SPEED_100; |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 182 | else |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 183 | speed = SPEED_10; |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 184 | |
| 185 | if (status & E1000_STATUS_FD) |
| 186 | ecmd->duplex = DUPLEX_FULL; |
| 187 | else |
| 188 | ecmd->duplex = DUPLEX_HALF; |
| 189 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 190 | } |
| 191 | |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 192 | ethtool_cmd_speed_set(ecmd, speed); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 193 | ecmd->autoneg = ((hw->phy.media_type == e1000_media_type_fiber) || |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 194 | hw->mac.autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE; |
Chaitanya Lala | 18760f1 | 2009-06-08 14:28:54 +0000 | [diff] [blame] | 195 | |
| 196 | /* MDI-X => 2; MDI =>1; Invalid =>0 */ |
| 197 | if ((hw->phy.media_type == e1000_media_type_copper) && |
Bruce Allan | 0c6bdb3 | 2010-06-17 18:58:43 +0000 | [diff] [blame] | 198 | netif_carrier_ok(netdev)) |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 199 | 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] | 200 | else |
| 201 | ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID; |
| 202 | |
Jesse Brandeburg | 4e8186b | 2012-07-26 02:31:14 +0000 | [diff] [blame] | 203 | if (hw->phy.mdix == AUTO_ALL_MODES) |
| 204 | ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO; |
| 205 | else |
| 206 | ecmd->eth_tp_mdix_ctrl = hw->phy.mdix; |
| 207 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 208 | return 0; |
| 209 | } |
| 210 | |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame] | 211 | 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] | 212 | { |
| 213 | struct e1000_mac_info *mac = &adapter->hw.mac; |
| 214 | |
| 215 | mac->autoneg = 0; |
| 216 | |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame] | 217 | /* 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] | 218 | * for the switch() below to work |
| 219 | */ |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame] | 220 | if ((spd & 1) || (dplx & ~1)) |
| 221 | goto err_inval; |
| 222 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 223 | /* Fiber NICs only allow 1000 gbps Full duplex */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 224 | if ((adapter->hw.phy.media_type == e1000_media_type_fiber) && |
David Decotigny | 14ad251 | 2011-04-27 18:32:43 +0000 | [diff] [blame] | 225 | spd != SPEED_1000 && |
| 226 | dplx != DUPLEX_FULL) { |
| 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; |
| 247 | case SPEED_1000 + DUPLEX_HALF: /* not supported */ |
| 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 | { |
| 419 | #define E1000_REGS_LEN 32 /* overestimate */ |
| 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 | |
| 436 | regs_buff[0] = er32(CTRL); |
| 437 | regs_buff[1] = er32(STATUS); |
| 438 | |
| 439 | regs_buff[2] = er32(RCTL); |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 440 | regs_buff[3] = er32(RDLEN(0)); |
| 441 | regs_buff[4] = er32(RDH(0)); |
| 442 | regs_buff[5] = er32(RDT(0)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 443 | regs_buff[6] = er32(RDTR); |
| 444 | |
| 445 | regs_buff[7] = er32(TCTL); |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 446 | regs_buff[8] = er32(TDLEN(0)); |
| 447 | regs_buff[9] = er32(TDH(0)); |
| 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 | |
| 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 | |
| 502 | eeprom_buff = kmalloc(sizeof(u16) * |
| 503 | (last_word - first_word + 1), GFP_KERNEL); |
| 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, |
| 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 | |
| 552 | if (eeprom->magic != (adapter->pdev->vendor | (adapter->pdev->device << 16))) |
| 553 | return -EFAULT; |
| 554 | |
Bruce Allan | 4a77035 | 2008-10-01 17:18:35 -0700 | [diff] [blame] | 555 | if (adapter->flags & FLAG_READ_ONLY_NVM) |
| 556 | return -EINVAL; |
| 557 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 558 | max_len = hw->nvm.word_size * 2; |
| 559 | |
| 560 | first_word = eeprom->offset >> 1; |
| 561 | last_word = (eeprom->offset + eeprom->len - 1) >> 1; |
| 562 | eeprom_buff = kmalloc(max_len, GFP_KERNEL); |
| 563 | if (!eeprom_buff) |
| 564 | return -ENOMEM; |
| 565 | |
| 566 | ptr = (void *)eeprom_buff; |
| 567 | |
| 568 | if (eeprom->offset & 1) { |
| 569 | /* need read/modify/write of first changed EEPROM word */ |
| 570 | /* only the second byte of the word is being modified */ |
| 571 | ret_val = e1000_read_nvm(hw, first_word, 1, &eeprom_buff[0]); |
| 572 | ptr++; |
| 573 | } |
Bruce Allan | 9e2d765 | 2012-01-31 06:37:27 +0000 | [diff] [blame] | 574 | if (((eeprom->offset + eeprom->len) & 1) && (!ret_val)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 575 | /* need read/modify/write of last changed EEPROM word */ |
| 576 | /* only the first byte of the word is being modified */ |
| 577 | ret_val = e1000_read_nvm(hw, last_word, 1, |
| 578 | &eeprom_buff[last_word - first_word]); |
| 579 | |
Bruce Allan | e243455 | 2008-11-21 17:02:41 -0800 | [diff] [blame] | 580 | if (ret_val) |
| 581 | goto out; |
| 582 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 583 | /* Device's eeprom is always little-endian, word addressable */ |
| 584 | for (i = 0; i < last_word - first_word + 1; i++) |
| 585 | le16_to_cpus(&eeprom_buff[i]); |
| 586 | |
| 587 | memcpy(ptr, bytes, eeprom->len); |
| 588 | |
| 589 | for (i = 0; i < last_word - first_word + 1; i++) |
Bruce Allan | e885d76 | 2012-01-31 06:37:32 +0000 | [diff] [blame] | 590 | cpu_to_le16s(&eeprom_buff[i]); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 591 | |
| 592 | ret_val = e1000_write_nvm(hw, first_word, |
| 593 | last_word - first_word + 1, eeprom_buff); |
| 594 | |
Bruce Allan | e243455 | 2008-11-21 17:02:41 -0800 | [diff] [blame] | 595 | if (ret_val) |
| 596 | goto out; |
| 597 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 598 | /* Update the checksum over the first part of the EEPROM if needed |
Bruce Allan | e243455 | 2008-11-21 17:02:41 -0800 | [diff] [blame] | 599 | * and flush shadow RAM for applicable controllers |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 600 | */ |
Bruce Allan | e243455 | 2008-11-21 17:02:41 -0800 | [diff] [blame] | 601 | if ((first_word <= NVM_CHECKSUM_REG) || |
Bruce Allan | f89271dd | 2009-11-20 23:22:20 +0000 | [diff] [blame] | 602 | (hw->mac.type == e1000_82583) || |
| 603 | (hw->mac.type == e1000_82574) || |
| 604 | (hw->mac.type == e1000_82573)) |
Bruce Allan | e243455 | 2008-11-21 17:02:41 -0800 | [diff] [blame] | 605 | ret_val = e1000e_update_nvm_checksum(hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 606 | |
Bruce Allan | e243455 | 2008-11-21 17:02:41 -0800 | [diff] [blame] | 607 | out: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 608 | kfree(eeprom_buff); |
| 609 | return ret_val; |
| 610 | } |
| 611 | |
| 612 | static void e1000_get_drvinfo(struct net_device *netdev, |
| 613 | struct ethtool_drvinfo *drvinfo) |
| 614 | { |
| 615 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 616 | |
Rick Jones | 612a94d | 2011-11-14 08:13:25 +0000 | [diff] [blame] | 617 | strlcpy(drvinfo->driver, e1000e_driver_name, |
| 618 | 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), |
| 626 | "%d.%d-%d", |
Bruce Allan | 8452759 | 2008-11-21 17:00:22 -0800 | [diff] [blame] | 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[] = { |
| 755 | 0x5A5A5A5A, 0xA5A5A5A5, 0x00000000, 0xFFFFFFFF}; |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 756 | for (pat = 0; pat < ARRAY_SIZE(test); pat++) { |
Joe Perches | 2a88719 | 2007-11-13 20:53:51 -0800 | [diff] [blame] | 757 | E1000_WRITE_REG_ARRAY(&adapter->hw, reg, offset, |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 758 | (test[pat] & write)); |
| 759 | val = E1000_READ_REG_ARRAY(&adapter->hw, reg, offset); |
| 760 | if (val != (test[pat] & write & mask)) { |
Bruce Allan | a8fc189 | 2012-12-05 06:25:36 +0000 | [diff] [blame] | 761 | e_err("pattern test failed (reg 0x%05X): got 0x%08X expected 0x%08X\n", |
| 762 | reg + (offset << 2), val, |
| 763 | (test[pat] & write & mask)); |
Joe Perches | 2a88719 | 2007-11-13 20:53:51 -0800 | [diff] [blame] | 764 | *data = reg; |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 765 | return 1; |
Joe Perches | 2a88719 | 2007-11-13 20:53:51 -0800 | [diff] [blame] | 766 | } |
| 767 | } |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 768 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Joe Perches | 2a88719 | 2007-11-13 20:53:51 -0800 | [diff] [blame] | 771 | static bool reg_set_and_check(struct e1000_adapter *adapter, u64 *data, |
| 772 | int reg, u32 mask, u32 write) |
| 773 | { |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 774 | u32 val; |
Joe Perches | 2a88719 | 2007-11-13 20:53:51 -0800 | [diff] [blame] | 775 | __ew32(&adapter->hw, reg, write & mask); |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 776 | val = __er32(&adapter->hw, reg); |
| 777 | if ((write & mask) != (val & mask)) { |
Bruce Allan | a8fc189 | 2012-12-05 06:25:36 +0000 | [diff] [blame] | 778 | 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] | 779 | reg, (val & mask), (write & mask)); |
Joe Perches | 2a88719 | 2007-11-13 20:53:51 -0800 | [diff] [blame] | 780 | *data = reg; |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 781 | return 1; |
Joe Perches | 2a88719 | 2007-11-13 20:53:51 -0800 | [diff] [blame] | 782 | } |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 783 | return 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 784 | } |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 785 | #define REG_PATTERN_TEST_ARRAY(reg, offset, mask, write) \ |
| 786 | do { \ |
| 787 | if (reg_pattern_test(adapter, data, reg, offset, mask, write)) \ |
| 788 | return 1; \ |
Joe Perches | 2a88719 | 2007-11-13 20:53:51 -0800 | [diff] [blame] | 789 | } while (0) |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 790 | #define REG_PATTERN_TEST(reg, mask, write) \ |
| 791 | REG_PATTERN_TEST_ARRAY(reg, 0, mask, write) |
Joe Perches | 2a88719 | 2007-11-13 20:53:51 -0800 | [diff] [blame] | 792 | |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 793 | #define REG_SET_AND_CHECK(reg, mask, write) \ |
| 794 | do { \ |
| 795 | if (reg_set_and_check(adapter, data, reg, mask, write)) \ |
| 796 | return 1; \ |
Joe Perches | 2a88719 | 2007-11-13 20:53:51 -0800 | [diff] [blame] | 797 | } while (0) |
| 798 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 799 | static int e1000_reg_test(struct e1000_adapter *adapter, u64 *data) |
| 800 | { |
| 801 | struct e1000_hw *hw = &adapter->hw; |
| 802 | struct e1000_mac_info *mac = &adapter->hw.mac; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 803 | u32 value; |
| 804 | u32 before; |
| 805 | u32 after; |
| 806 | u32 i; |
| 807 | u32 toggle; |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 808 | u32 mask; |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 809 | u32 wlock_mac = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 810 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 811 | /* The status register is Read Only, so a write should fail. |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 812 | * Some bits that get toggled are ignored. |
| 813 | */ |
| 814 | switch (mac->type) { |
| 815 | /* there are several bits on newer hardware that are r/w */ |
| 816 | case e1000_82571: |
| 817 | case e1000_82572: |
| 818 | case e1000_80003es2lan: |
| 819 | toggle = 0x7FFFF3FF; |
| 820 | break; |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 821 | default: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 822 | toggle = 0x7FFFF033; |
| 823 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | before = er32(STATUS); |
| 827 | value = (er32(STATUS) & toggle); |
| 828 | ew32(STATUS, toggle); |
| 829 | after = er32(STATUS) & toggle; |
| 830 | if (value != after) { |
Bruce Allan | 6ad6514 | 2012-04-12 05:47:09 +0000 | [diff] [blame] | 831 | e_err("failed STATUS register test got: 0x%08X expected: 0x%08X\n", |
| 832 | after, value); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 833 | *data = 1; |
| 834 | return 1; |
| 835 | } |
| 836 | /* restore previous status */ |
| 837 | ew32(STATUS, before); |
| 838 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 839 | if (!(adapter->flags & FLAG_IS_ICH)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 840 | REG_PATTERN_TEST(E1000_FCAL, 0xFFFFFFFF, 0xFFFFFFFF); |
| 841 | REG_PATTERN_TEST(E1000_FCAH, 0x0000FFFF, 0xFFFFFFFF); |
| 842 | REG_PATTERN_TEST(E1000_FCT, 0x0000FFFF, 0xFFFFFFFF); |
| 843 | REG_PATTERN_TEST(E1000_VET, 0x0000FFFF, 0xFFFFFFFF); |
| 844 | } |
| 845 | |
| 846 | REG_PATTERN_TEST(E1000_RDTR, 0x0000FFFF, 0xFFFFFFFF); |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 847 | REG_PATTERN_TEST(E1000_RDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF); |
| 848 | REG_PATTERN_TEST(E1000_RDLEN(0), 0x000FFF80, 0x000FFFFF); |
| 849 | REG_PATTERN_TEST(E1000_RDH(0), 0x0000FFFF, 0x0000FFFF); |
| 850 | REG_PATTERN_TEST(E1000_RDT(0), 0x0000FFFF, 0x0000FFFF); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 851 | REG_PATTERN_TEST(E1000_FCRTH, 0x0000FFF8, 0x0000FFF8); |
| 852 | REG_PATTERN_TEST(E1000_FCTTV, 0x0000FFFF, 0x0000FFFF); |
| 853 | REG_PATTERN_TEST(E1000_TIPG, 0x3FFFFFFF, 0x3FFFFFFF); |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 854 | REG_PATTERN_TEST(E1000_TDBAH(0), 0xFFFFFFFF, 0xFFFFFFFF); |
| 855 | REG_PATTERN_TEST(E1000_TDLEN(0), 0x000FFF80, 0x000FFFFF); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 856 | |
| 857 | REG_SET_AND_CHECK(E1000_RCTL, 0xFFFFFFFF, 0x00000000); |
| 858 | |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 859 | before = ((adapter->flags & FLAG_IS_ICH) ? 0x06C3B33E : 0x06DFB3FE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 860 | REG_SET_AND_CHECK(E1000_RCTL, before, 0x003FFFFB); |
| 861 | REG_SET_AND_CHECK(E1000_TCTL, 0xFFFFFFFF, 0x00000000); |
| 862 | |
Auke Kok | 8658251 | 2007-10-04 15:00:08 -0700 | [diff] [blame] | 863 | REG_SET_AND_CHECK(E1000_RCTL, before, 0xFFFFFFFF); |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 864 | REG_PATTERN_TEST(E1000_RDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 865 | if (!(adapter->flags & FLAG_IS_ICH)) |
Auke Kok | 8658251 | 2007-10-04 15:00:08 -0700 | [diff] [blame] | 866 | REG_PATTERN_TEST(E1000_TXCW, 0xC000FFFF, 0x0000FFFF); |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 867 | REG_PATTERN_TEST(E1000_TDBAL(0), 0xFFFFFFF0, 0xFFFFFFFF); |
Auke Kok | 8658251 | 2007-10-04 15:00:08 -0700 | [diff] [blame] | 868 | REG_PATTERN_TEST(E1000_TIDV, 0x0000FFFF, 0x0000FFFF); |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 869 | mask = 0x8003FFFF; |
| 870 | switch (mac->type) { |
| 871 | case e1000_ich10lan: |
| 872 | case e1000_pchlan: |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 873 | case e1000_pch2lan: |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 874 | case e1000_pch_lpt: |
Bruce Allan | a4f58f5 | 2009-06-02 11:29:18 +0000 | [diff] [blame] | 875 | mask |= (1 << 18); |
| 876 | break; |
| 877 | default: |
| 878 | break; |
| 879 | } |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 880 | |
| 881 | if (mac->type == e1000_pch_lpt) |
| 882 | wlock_mac = (er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK) >> |
| 883 | E1000_FWSM_WLOCK_MAC_SHIFT; |
| 884 | |
| 885 | for (i = 0; i < mac->rar_entry_count; i++) { |
Bruce Allan | a8fc189 | 2012-12-05 06:25:36 +0000 | [diff] [blame] | 886 | if (mac->type == e1000_pch_lpt) { |
| 887 | /* Cannot test write-protected SHRAL[n] registers */ |
| 888 | if ((wlock_mac == 1) || (wlock_mac && (i > wlock_mac))) |
| 889 | continue; |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 890 | |
Bruce Allan | a8fc189 | 2012-12-05 06:25:36 +0000 | [diff] [blame] | 891 | /* SHRAH[9] different than the others */ |
| 892 | if (i == 10) |
| 893 | mask |= (1 << 30); |
| 894 | else |
| 895 | mask &= ~(1 << 30); |
| 896 | } |
| 897 | |
| 898 | REG_PATTERN_TEST_ARRAY(E1000_RA, ((i << 1) + 1), mask, |
| 899 | 0xFFFFFFFF); |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 900 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 901 | |
| 902 | for (i = 0; i < mac->mta_reg_count; i++) |
| 903 | REG_PATTERN_TEST_ARRAY(E1000_MTA, i, 0xFFFFFFFF, 0xFFFFFFFF); |
| 904 | |
| 905 | *data = 0; |
Bruce Allan | 2fbe452 | 2012-04-19 03:21:47 +0000 | [diff] [blame] | 906 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 907 | return 0; |
| 908 | } |
| 909 | |
| 910 | static int e1000_eeprom_test(struct e1000_adapter *adapter, u64 *data) |
| 911 | { |
| 912 | u16 temp; |
| 913 | u16 checksum = 0; |
| 914 | u16 i; |
| 915 | |
| 916 | *data = 0; |
| 917 | /* Read and add up the contents of the EEPROM */ |
| 918 | for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) { |
| 919 | if ((e1000_read_nvm(&adapter->hw, i, 1, &temp)) < 0) { |
| 920 | *data = 1; |
Bruce Allan | e243455 | 2008-11-21 17:02:41 -0800 | [diff] [blame] | 921 | return *data; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 922 | } |
| 923 | checksum += temp; |
| 924 | } |
| 925 | |
| 926 | /* If Checksum is not Correct return error else test passed */ |
| 927 | if ((checksum != (u16) NVM_SUM) && !(*data)) |
| 928 | *data = 2; |
| 929 | |
| 930 | return *data; |
| 931 | } |
| 932 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 933 | static irqreturn_t e1000_test_intr(int __always_unused irq, void *data) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 934 | { |
| 935 | struct net_device *netdev = (struct net_device *) data; |
| 936 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 937 | struct e1000_hw *hw = &adapter->hw; |
| 938 | |
| 939 | adapter->test_icr |= er32(ICR); |
| 940 | |
| 941 | return IRQ_HANDLED; |
| 942 | } |
| 943 | |
| 944 | static int e1000_intr_test(struct e1000_adapter *adapter, u64 *data) |
| 945 | { |
| 946 | struct net_device *netdev = adapter->netdev; |
| 947 | struct e1000_hw *hw = &adapter->hw; |
| 948 | u32 mask; |
| 949 | u32 shared_int = 1; |
| 950 | u32 irq = adapter->pdev->irq; |
| 951 | int i; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 952 | int ret_val = 0; |
| 953 | int int_mode = E1000E_INT_MODE_LEGACY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 954 | |
| 955 | *data = 0; |
| 956 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 957 | /* NOTE: we don't test MSI/MSI-X interrupts here, yet */ |
| 958 | if (adapter->int_mode == E1000E_INT_MODE_MSIX) { |
| 959 | int_mode = adapter->int_mode; |
| 960 | e1000e_reset_interrupt_capability(adapter); |
| 961 | adapter->int_mode = E1000E_INT_MODE_LEGACY; |
| 962 | e1000e_set_interrupt_capability(adapter); |
| 963 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 964 | /* Hook up test interrupt handler just for this test */ |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 965 | if (!request_irq(irq, e1000_test_intr, IRQF_PROBE_SHARED, netdev->name, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 966 | netdev)) { |
| 967 | shared_int = 0; |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 968 | } else if (request_irq(irq, e1000_test_intr, IRQF_SHARED, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 969 | netdev->name, netdev)) { |
| 970 | *data = 1; |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 971 | ret_val = -1; |
| 972 | goto out; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 973 | } |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 974 | e_info("testing %s interrupt\n", (shared_int ? "shared" : "unshared")); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 975 | |
| 976 | /* Disable all the interrupts */ |
| 977 | ew32(IMC, 0xFFFFFFFF); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 978 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 979 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 980 | |
| 981 | /* Test each interrupt */ |
| 982 | for (i = 0; i < 10; i++) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 983 | /* Interrupt to test */ |
| 984 | mask = 1 << i; |
| 985 | |
Bruce Allan | f4187b5 | 2008-08-26 18:36:50 -0700 | [diff] [blame] | 986 | if (adapter->flags & FLAG_IS_ICH) { |
| 987 | switch (mask) { |
| 988 | case E1000_ICR_RXSEQ: |
| 989 | continue; |
| 990 | case 0x00000100: |
| 991 | if (adapter->hw.mac.type == e1000_ich8lan || |
| 992 | adapter->hw.mac.type == e1000_ich9lan) |
| 993 | continue; |
| 994 | break; |
| 995 | default: |
| 996 | break; |
| 997 | } |
| 998 | } |
| 999 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1000 | if (!shared_int) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1001 | /* Disable the interrupt to be reported in |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1002 | * the cause register and then force the same |
| 1003 | * interrupt and see if one gets posted. If |
| 1004 | * an interrupt was posted to the bus, the |
| 1005 | * test failed. |
| 1006 | */ |
| 1007 | adapter->test_icr = 0; |
| 1008 | ew32(IMC, mask); |
| 1009 | ew32(ICS, mask); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 1010 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 1011 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1012 | |
| 1013 | if (adapter->test_icr & mask) { |
| 1014 | *data = 3; |
| 1015 | break; |
| 1016 | } |
| 1017 | } |
| 1018 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1019 | /* Enable the interrupt to be reported in |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1020 | * the cause register and then force the same |
| 1021 | * interrupt and see if one gets posted. If |
| 1022 | * an interrupt was not posted to the bus, the |
| 1023 | * test failed. |
| 1024 | */ |
| 1025 | adapter->test_icr = 0; |
| 1026 | ew32(IMS, mask); |
| 1027 | ew32(ICS, mask); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 1028 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 1029 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1030 | |
| 1031 | if (!(adapter->test_icr & mask)) { |
| 1032 | *data = 4; |
| 1033 | break; |
| 1034 | } |
| 1035 | |
| 1036 | if (!shared_int) { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1037 | /* Disable the other interrupts to be reported in |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1038 | * the cause register and then force the other |
| 1039 | * interrupts and see if any get posted. If |
| 1040 | * an interrupt was posted to the bus, the |
| 1041 | * test failed. |
| 1042 | */ |
| 1043 | adapter->test_icr = 0; |
| 1044 | ew32(IMC, ~mask & 0x00007FFF); |
| 1045 | ew32(ICS, ~mask & 0x00007FFF); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 1046 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 1047 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1048 | |
| 1049 | if (adapter->test_icr) { |
| 1050 | *data = 5; |
| 1051 | break; |
| 1052 | } |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | /* Disable all the interrupts */ |
| 1057 | ew32(IMC, 0xFFFFFFFF); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 1058 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 1059 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1060 | |
| 1061 | /* Unhook test interrupt handler */ |
| 1062 | free_irq(irq, netdev); |
| 1063 | |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1064 | out: |
| 1065 | if (int_mode == E1000E_INT_MODE_MSIX) { |
| 1066 | e1000e_reset_interrupt_capability(adapter); |
| 1067 | adapter->int_mode = int_mode; |
| 1068 | e1000e_set_interrupt_capability(adapter); |
| 1069 | } |
| 1070 | |
| 1071 | return ret_val; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | static void e1000_free_desc_rings(struct e1000_adapter *adapter) |
| 1075 | { |
| 1076 | struct e1000_ring *tx_ring = &adapter->test_tx_ring; |
| 1077 | struct e1000_ring *rx_ring = &adapter->test_rx_ring; |
| 1078 | struct pci_dev *pdev = adapter->pdev; |
| 1079 | int i; |
| 1080 | |
| 1081 | if (tx_ring->desc && tx_ring->buffer_info) { |
| 1082 | for (i = 0; i < tx_ring->count; i++) { |
| 1083 | if (tx_ring->buffer_info[i].dma) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1084 | dma_unmap_single(&pdev->dev, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1085 | tx_ring->buffer_info[i].dma, |
| 1086 | tx_ring->buffer_info[i].length, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1087 | DMA_TO_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1088 | if (tx_ring->buffer_info[i].skb) |
| 1089 | dev_kfree_skb(tx_ring->buffer_info[i].skb); |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | if (rx_ring->desc && rx_ring->buffer_info) { |
| 1094 | for (i = 0; i < rx_ring->count; i++) { |
| 1095 | if (rx_ring->buffer_info[i].dma) |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1096 | dma_unmap_single(&pdev->dev, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1097 | rx_ring->buffer_info[i].dma, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1098 | 2048, DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1099 | if (rx_ring->buffer_info[i].skb) |
| 1100 | dev_kfree_skb(rx_ring->buffer_info[i].skb); |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | if (tx_ring->desc) { |
| 1105 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, |
| 1106 | tx_ring->dma); |
| 1107 | tx_ring->desc = NULL; |
| 1108 | } |
| 1109 | if (rx_ring->desc) { |
| 1110 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, |
| 1111 | rx_ring->dma); |
| 1112 | rx_ring->desc = NULL; |
| 1113 | } |
| 1114 | |
| 1115 | kfree(tx_ring->buffer_info); |
| 1116 | tx_ring->buffer_info = NULL; |
| 1117 | kfree(rx_ring->buffer_info); |
| 1118 | rx_ring->buffer_info = NULL; |
| 1119 | } |
| 1120 | |
| 1121 | static int e1000_setup_desc_rings(struct e1000_adapter *adapter) |
| 1122 | { |
| 1123 | struct e1000_ring *tx_ring = &adapter->test_tx_ring; |
| 1124 | struct e1000_ring *rx_ring = &adapter->test_rx_ring; |
| 1125 | struct pci_dev *pdev = adapter->pdev; |
| 1126 | struct e1000_hw *hw = &adapter->hw; |
| 1127 | u32 rctl; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1128 | int i; |
| 1129 | int ret_val; |
| 1130 | |
| 1131 | /* Setup Tx descriptor ring and Tx buffers */ |
| 1132 | |
| 1133 | if (!tx_ring->count) |
| 1134 | tx_ring->count = E1000_DEFAULT_TXD; |
| 1135 | |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 1136 | tx_ring->buffer_info = kcalloc(tx_ring->count, |
| 1137 | sizeof(struct e1000_buffer), |
| 1138 | GFP_KERNEL); |
Bruce Allan | 668018d | 2012-01-31 07:02:56 +0000 | [diff] [blame] | 1139 | if (!tx_ring->buffer_info) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1140 | ret_val = 1; |
| 1141 | goto err_nomem; |
| 1142 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1143 | |
| 1144 | tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc); |
| 1145 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 1146 | tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size, |
| 1147 | &tx_ring->dma, GFP_KERNEL); |
| 1148 | if (!tx_ring->desc) { |
| 1149 | ret_val = 2; |
| 1150 | goto err_nomem; |
| 1151 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1152 | tx_ring->next_to_use = 0; |
| 1153 | tx_ring->next_to_clean = 0; |
| 1154 | |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 1155 | ew32(TDBAL(0), ((u64) tx_ring->dma & 0x00000000FFFFFFFF)); |
| 1156 | ew32(TDBAH(0), ((u64) tx_ring->dma >> 32)); |
| 1157 | ew32(TDLEN(0), tx_ring->count * sizeof(struct e1000_tx_desc)); |
| 1158 | ew32(TDH(0), 0); |
| 1159 | ew32(TDT(0), 0); |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 1160 | ew32(TCTL, E1000_TCTL_PSP | E1000_TCTL_EN | E1000_TCTL_MULR | |
| 1161 | E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT | |
| 1162 | E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1163 | |
| 1164 | for (i = 0; i < tx_ring->count; i++) { |
| 1165 | struct e1000_tx_desc *tx_desc = E1000_TX_DESC(*tx_ring, i); |
| 1166 | struct sk_buff *skb; |
| 1167 | unsigned int skb_size = 1024; |
| 1168 | |
| 1169 | skb = alloc_skb(skb_size, GFP_KERNEL); |
| 1170 | if (!skb) { |
| 1171 | ret_val = 3; |
| 1172 | goto err_nomem; |
| 1173 | } |
| 1174 | skb_put(skb, skb_size); |
| 1175 | tx_ring->buffer_info[i].skb = skb; |
| 1176 | tx_ring->buffer_info[i].length = skb->len; |
| 1177 | tx_ring->buffer_info[i].dma = |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1178 | dma_map_single(&pdev->dev, skb->data, skb->len, |
| 1179 | DMA_TO_DEVICE); |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1180 | if (dma_mapping_error(&pdev->dev, |
| 1181 | tx_ring->buffer_info[i].dma)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1182 | ret_val = 4; |
| 1183 | goto err_nomem; |
| 1184 | } |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 1185 | 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] | 1186 | tx_desc->lower.data = cpu_to_le32(skb->len); |
| 1187 | tx_desc->lower.data |= cpu_to_le32(E1000_TXD_CMD_EOP | |
| 1188 | E1000_TXD_CMD_IFCS | |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 1189 | E1000_TXD_CMD_RS); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1190 | tx_desc->upper.data = 0; |
| 1191 | } |
| 1192 | |
| 1193 | /* Setup Rx descriptor ring and Rx buffers */ |
| 1194 | |
| 1195 | if (!rx_ring->count) |
| 1196 | rx_ring->count = E1000_DEFAULT_RXD; |
| 1197 | |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 1198 | rx_ring->buffer_info = kcalloc(rx_ring->count, |
| 1199 | sizeof(struct e1000_buffer), |
| 1200 | GFP_KERNEL); |
Bruce Allan | 668018d | 2012-01-31 07:02:56 +0000 | [diff] [blame] | 1201 | if (!rx_ring->buffer_info) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1202 | ret_val = 5; |
| 1203 | goto err_nomem; |
| 1204 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1205 | |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1206 | rx_ring->size = rx_ring->count * sizeof(union e1000_rx_desc_extended); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1207 | rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size, |
| 1208 | &rx_ring->dma, GFP_KERNEL); |
| 1209 | if (!rx_ring->desc) { |
| 1210 | ret_val = 6; |
| 1211 | goto err_nomem; |
| 1212 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1213 | rx_ring->next_to_use = 0; |
| 1214 | rx_ring->next_to_clean = 0; |
| 1215 | |
| 1216 | rctl = er32(RCTL); |
Bruce Allan | 7f99ae6 | 2011-07-22 06:21:35 +0000 | [diff] [blame] | 1217 | if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX)) |
| 1218 | ew32(RCTL, rctl & ~E1000_RCTL_EN); |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 1219 | ew32(RDBAL(0), ((u64) rx_ring->dma & 0xFFFFFFFF)); |
| 1220 | ew32(RDBAH(0), ((u64) rx_ring->dma >> 32)); |
| 1221 | ew32(RDLEN(0), rx_ring->size); |
| 1222 | ew32(RDH(0), 0); |
| 1223 | ew32(RDT(0), 0); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1224 | rctl = E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_SZ_2048 | |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1225 | E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_LPE | |
| 1226 | E1000_RCTL_SBP | E1000_RCTL_SECRC | |
| 1227 | E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF | |
| 1228 | (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1229 | ew32(RCTL, rctl); |
| 1230 | |
| 1231 | for (i = 0; i < rx_ring->count; i++) { |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1232 | union e1000_rx_desc_extended *rx_desc; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1233 | struct sk_buff *skb; |
| 1234 | |
| 1235 | skb = alloc_skb(2048 + NET_IP_ALIGN, GFP_KERNEL); |
| 1236 | if (!skb) { |
| 1237 | ret_val = 7; |
| 1238 | goto err_nomem; |
| 1239 | } |
| 1240 | skb_reserve(skb, NET_IP_ALIGN); |
| 1241 | rx_ring->buffer_info[i].skb = skb; |
| 1242 | rx_ring->buffer_info[i].dma = |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1243 | dma_map_single(&pdev->dev, skb->data, 2048, |
| 1244 | DMA_FROM_DEVICE); |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1245 | if (dma_mapping_error(&pdev->dev, |
| 1246 | rx_ring->buffer_info[i].dma)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1247 | ret_val = 8; |
| 1248 | goto err_nomem; |
| 1249 | } |
Bruce Allan | 5f45021 | 2011-07-22 06:21:46 +0000 | [diff] [blame] | 1250 | rx_desc = E1000_RX_DESC_EXT(*rx_ring, i); |
| 1251 | rx_desc->read.buffer_addr = |
| 1252 | cpu_to_le64(rx_ring->buffer_info[i].dma); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1253 | memset(skb->data, 0x00, skb->len); |
| 1254 | } |
| 1255 | |
| 1256 | return 0; |
| 1257 | |
| 1258 | err_nomem: |
| 1259 | e1000_free_desc_rings(adapter); |
| 1260 | return ret_val; |
| 1261 | } |
| 1262 | |
| 1263 | static void e1000_phy_disable_receiver(struct e1000_adapter *adapter) |
| 1264 | { |
| 1265 | /* Write out to PHY registers 29 and 30 to disable the Receiver. */ |
| 1266 | e1e_wphy(&adapter->hw, 29, 0x001F); |
| 1267 | e1e_wphy(&adapter->hw, 30, 0x8FFC); |
| 1268 | e1e_wphy(&adapter->hw, 29, 0x001A); |
| 1269 | e1e_wphy(&adapter->hw, 30, 0x8FF0); |
| 1270 | } |
| 1271 | |
| 1272 | static int e1000_integrated_phy_loopback(struct e1000_adapter *adapter) |
| 1273 | { |
| 1274 | struct e1000_hw *hw = &adapter->hw; |
| 1275 | u32 ctrl_reg = 0; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1276 | u16 phy_reg = 0; |
Bruce Allan | cbd006c | 2010-11-24 06:01:30 +0000 | [diff] [blame] | 1277 | s32 ret_val = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1278 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1279 | hw->mac.autoneg = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1280 | |
Bruce Allan | 3af5048 | 2010-06-16 13:25:55 +0000 | [diff] [blame] | 1281 | if (hw->phy.type == e1000_phy_ife) { |
| 1282 | /* force 100, set loopback */ |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 1283 | e1e_wphy(hw, MII_BMCR, 0x6100); |
Bruce Allan | bb436b2 | 2009-11-20 23:24:11 +0000 | [diff] [blame] | 1284 | |
Bruce Allan | 3af5048 | 2010-06-16 13:25:55 +0000 | [diff] [blame] | 1285 | /* Now set up the MAC to the same speed/duplex as the PHY. */ |
| 1286 | ctrl_reg = er32(CTRL); |
| 1287 | ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ |
| 1288 | ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ |
| 1289 | E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ |
| 1290 | E1000_CTRL_SPD_100 |/* Force Speed to 100 */ |
| 1291 | E1000_CTRL_FD); /* Force Duplex to FULL */ |
| 1292 | |
| 1293 | ew32(CTRL, ctrl_reg); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 1294 | e1e_flush(); |
Bruce Allan | 3af5048 | 2010-06-16 13:25:55 +0000 | [diff] [blame] | 1295 | udelay(500); |
| 1296 | |
| 1297 | return 0; |
| 1298 | } |
| 1299 | |
| 1300 | /* Specific PHY configuration for loopback */ |
| 1301 | switch (hw->phy.type) { |
| 1302 | case e1000_phy_m88: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1303 | /* Auto-MDI/MDIX Off */ |
| 1304 | e1e_wphy(hw, M88E1000_PHY_SPEC_CTRL, 0x0808); |
| 1305 | /* reset to update Auto-MDI/MDIX */ |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 1306 | e1e_wphy(hw, MII_BMCR, 0x9140); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1307 | /* autoneg off */ |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 1308 | e1e_wphy(hw, MII_BMCR, 0x8140); |
Bruce Allan | 3af5048 | 2010-06-16 13:25:55 +0000 | [diff] [blame] | 1309 | break; |
| 1310 | case e1000_phy_gg82563: |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1311 | e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x1CC); |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 1312 | break; |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1313 | case e1000_phy_bm: |
| 1314 | /* Set Default MAC Interface speed to 1GB */ |
| 1315 | e1e_rphy(hw, PHY_REG(2, 21), &phy_reg); |
| 1316 | phy_reg &= ~0x0007; |
| 1317 | phy_reg |= 0x006; |
| 1318 | e1e_wphy(hw, PHY_REG(2, 21), phy_reg); |
| 1319 | /* Assert SW reset for above settings to take effect */ |
Bruce Allan | 6b598e1 | 2013-01-23 06:50:05 +0000 | [diff] [blame] | 1320 | hw->phy.ops.commit(hw); |
Bruce Allan | 97ac8ca | 2008-04-29 09:16:05 -0700 | [diff] [blame] | 1321 | mdelay(1); |
| 1322 | /* Force Full Duplex */ |
| 1323 | e1e_rphy(hw, PHY_REG(769, 16), &phy_reg); |
| 1324 | e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x000C); |
| 1325 | /* Set Link Up (in force link) */ |
| 1326 | e1e_rphy(hw, PHY_REG(776, 16), &phy_reg); |
| 1327 | e1e_wphy(hw, PHY_REG(776, 16), phy_reg | 0x0040); |
| 1328 | /* Force Link */ |
| 1329 | e1e_rphy(hw, PHY_REG(769, 16), &phy_reg); |
| 1330 | e1e_wphy(hw, PHY_REG(769, 16), phy_reg | 0x0040); |
| 1331 | /* Set Early Link Enable */ |
| 1332 | e1e_rphy(hw, PHY_REG(769, 20), &phy_reg); |
| 1333 | e1e_wphy(hw, PHY_REG(769, 20), phy_reg | 0x0400); |
Bruce Allan | 3af5048 | 2010-06-16 13:25:55 +0000 | [diff] [blame] | 1334 | break; |
| 1335 | case e1000_phy_82577: |
| 1336 | case e1000_phy_82578: |
| 1337 | /* Workaround: K1 must be disabled for stable 1Gbps operation */ |
Bruce Allan | cbd006c | 2010-11-24 06:01:30 +0000 | [diff] [blame] | 1338 | ret_val = hw->phy.ops.acquire(hw); |
| 1339 | if (ret_val) { |
| 1340 | e_err("Cannot setup 1Gbps loopback.\n"); |
| 1341 | return ret_val; |
| 1342 | } |
Bruce Allan | 3af5048 | 2010-06-16 13:25:55 +0000 | [diff] [blame] | 1343 | e1000_configure_k1_ich8lan(hw, false); |
Bruce Allan | cbd006c | 2010-11-24 06:01:30 +0000 | [diff] [blame] | 1344 | hw->phy.ops.release(hw); |
Bruce Allan | 3af5048 | 2010-06-16 13:25:55 +0000 | [diff] [blame] | 1345 | break; |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 1346 | case e1000_phy_82579: |
| 1347 | /* Disable PHY energy detect power down */ |
| 1348 | e1e_rphy(hw, PHY_REG(0, 21), &phy_reg); |
| 1349 | e1e_wphy(hw, PHY_REG(0, 21), phy_reg & ~(1 << 3)); |
| 1350 | /* Disable full chip energy detect */ |
| 1351 | e1e_rphy(hw, PHY_REG(776, 18), &phy_reg); |
| 1352 | e1e_wphy(hw, PHY_REG(776, 18), phy_reg | 1); |
| 1353 | /* Enable loopback on the PHY */ |
Bruce Allan | d3738bb | 2010-06-16 13:27:28 +0000 | [diff] [blame] | 1354 | e1e_wphy(hw, I82577_PHY_LBK_CTRL, 0x8001); |
| 1355 | break; |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 1356 | default: |
Bruce Allan | 3af5048 | 2010-06-16 13:25:55 +0000 | [diff] [blame] | 1357 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1358 | } |
| 1359 | |
Bruce Allan | 3af5048 | 2010-06-16 13:25:55 +0000 | [diff] [blame] | 1360 | /* force 1000, set loopback */ |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 1361 | e1e_wphy(hw, MII_BMCR, 0x4140); |
Bruce Allan | 3af5048 | 2010-06-16 13:25:55 +0000 | [diff] [blame] | 1362 | mdelay(250); |
| 1363 | |
| 1364 | /* Now set up the MAC to the same speed/duplex as the PHY. */ |
| 1365 | ctrl_reg = er32(CTRL); |
| 1366 | ctrl_reg &= ~E1000_CTRL_SPD_SEL; /* Clear the speed sel bits */ |
| 1367 | ctrl_reg |= (E1000_CTRL_FRCSPD | /* Set the Force Speed Bit */ |
| 1368 | E1000_CTRL_FRCDPX | /* Set the Force Duplex Bit */ |
| 1369 | E1000_CTRL_SPD_1000 |/* Force Speed to 1000 */ |
| 1370 | E1000_CTRL_FD); /* Force Duplex to FULL */ |
| 1371 | |
| 1372 | if (adapter->flags & FLAG_IS_ICH) |
| 1373 | ctrl_reg |= E1000_CTRL_SLU; /* Set Link Up */ |
| 1374 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1375 | if (hw->phy.media_type == e1000_media_type_copper && |
| 1376 | hw->phy.type == e1000_phy_m88) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1377 | ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */ |
| 1378 | } else { |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1379 | /* 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] | 1380 | * detected. |
| 1381 | */ |
Bruce Allan | 90da066 | 2011-01-06 07:02:53 +0000 | [diff] [blame] | 1382 | if ((er32(STATUS) & E1000_STATUS_FD) == 0) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1383 | ctrl_reg |= (E1000_CTRL_ILOS | E1000_CTRL_SLU); |
| 1384 | } |
| 1385 | |
| 1386 | ew32(CTRL, ctrl_reg); |
| 1387 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1388 | /* 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] | 1389 | * PHY does not begin to autoneg when a cable is reconnected to the NIC. |
| 1390 | */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1391 | if (hw->phy.type == e1000_phy_m88) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1392 | e1000_phy_disable_receiver(adapter); |
| 1393 | |
| 1394 | udelay(500); |
| 1395 | |
| 1396 | return 0; |
| 1397 | } |
| 1398 | |
| 1399 | static int e1000_set_82571_fiber_loopback(struct e1000_adapter *adapter) |
| 1400 | { |
| 1401 | struct e1000_hw *hw = &adapter->hw; |
| 1402 | u32 ctrl = er32(CTRL); |
Bruce Allan | 70806a7 | 2013-01-05 05:08:37 +0000 | [diff] [blame] | 1403 | int link; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1404 | |
| 1405 | /* special requirements for 82571/82572 fiber adapters */ |
| 1406 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1407 | /* jump through hoops to make sure link is up because serdes |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1408 | * link is hardwired up |
| 1409 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1410 | ctrl |= E1000_CTRL_SLU; |
| 1411 | ew32(CTRL, ctrl); |
| 1412 | |
| 1413 | /* disable autoneg */ |
| 1414 | ctrl = er32(TXCW); |
| 1415 | ctrl &= ~(1 << 31); |
| 1416 | ew32(TXCW, ctrl); |
| 1417 | |
| 1418 | link = (er32(STATUS) & E1000_STATUS_LU); |
| 1419 | |
| 1420 | if (!link) { |
| 1421 | /* set invert loss of signal */ |
| 1422 | ctrl = er32(CTRL); |
| 1423 | ctrl |= E1000_CTRL_ILOS; |
| 1424 | ew32(CTRL, ctrl); |
| 1425 | } |
| 1426 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1427 | /* special write to serdes control register to enable SerDes analog |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1428 | * loopback |
| 1429 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1430 | #define E1000_SERDES_LB_ON 0x410 |
| 1431 | ew32(SCTL, E1000_SERDES_LB_ON); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 1432 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 1433 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1434 | |
| 1435 | return 0; |
| 1436 | } |
| 1437 | |
| 1438 | /* only call this for fiber/serdes connections to es2lan */ |
| 1439 | static int e1000_set_es2lan_mac_loopback(struct e1000_adapter *adapter) |
| 1440 | { |
| 1441 | struct e1000_hw *hw = &adapter->hw; |
| 1442 | u32 ctrlext = er32(CTRL_EXT); |
| 1443 | u32 ctrl = er32(CTRL); |
| 1444 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1445 | /* save CTRL_EXT to restore later, reuse an empty variable (unused |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1446 | * on mac_type 80003es2lan) |
| 1447 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1448 | adapter->tx_fifo_head = ctrlext; |
| 1449 | |
| 1450 | /* clear the serdes mode bits, putting the device into mac loopback */ |
| 1451 | ctrlext &= ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES; |
| 1452 | ew32(CTRL_EXT, ctrlext); |
| 1453 | |
| 1454 | /* force speed to 1000/FD, link up */ |
| 1455 | ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100); |
| 1456 | ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | |
| 1457 | E1000_CTRL_SPD_1000 | E1000_CTRL_FD); |
| 1458 | ew32(CTRL, ctrl); |
| 1459 | |
| 1460 | /* set mac loopback */ |
| 1461 | ctrl = er32(RCTL); |
| 1462 | ctrl |= E1000_RCTL_LBM_MAC; |
| 1463 | ew32(RCTL, ctrl); |
| 1464 | |
| 1465 | /* set testing mode parameters (no need to reset later) */ |
| 1466 | #define KMRNCTRLSTA_OPMODE (0x1F << 16) |
| 1467 | #define KMRNCTRLSTA_OPMODE_1GB_FD_GMII 0x0582 |
| 1468 | ew32(KMRNCTRLSTA, |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 1469 | (KMRNCTRLSTA_OPMODE | KMRNCTRLSTA_OPMODE_1GB_FD_GMII)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1470 | |
| 1471 | return 0; |
| 1472 | } |
| 1473 | |
| 1474 | static int e1000_setup_loopback_test(struct e1000_adapter *adapter) |
| 1475 | { |
| 1476 | struct e1000_hw *hw = &adapter->hw; |
| 1477 | u32 rctl; |
| 1478 | |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1479 | if (hw->phy.media_type == e1000_media_type_fiber || |
| 1480 | hw->phy.media_type == e1000_media_type_internal_serdes) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1481 | switch (hw->mac.type) { |
| 1482 | case e1000_80003es2lan: |
| 1483 | return e1000_set_es2lan_mac_loopback(adapter); |
| 1484 | break; |
| 1485 | case e1000_82571: |
| 1486 | case e1000_82572: |
| 1487 | return e1000_set_82571_fiber_loopback(adapter); |
| 1488 | break; |
| 1489 | default: |
| 1490 | rctl = er32(RCTL); |
| 1491 | rctl |= E1000_RCTL_LBM_TCVR; |
| 1492 | ew32(RCTL, rctl); |
| 1493 | return 0; |
| 1494 | } |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1495 | } else if (hw->phy.media_type == e1000_media_type_copper) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1496 | return e1000_integrated_phy_loopback(adapter); |
| 1497 | } |
| 1498 | |
| 1499 | return 7; |
| 1500 | } |
| 1501 | |
| 1502 | static void e1000_loopback_cleanup(struct e1000_adapter *adapter) |
| 1503 | { |
| 1504 | struct e1000_hw *hw = &adapter->hw; |
| 1505 | u32 rctl; |
| 1506 | u16 phy_reg; |
| 1507 | |
| 1508 | rctl = er32(RCTL); |
| 1509 | rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC); |
| 1510 | ew32(RCTL, rctl); |
| 1511 | |
| 1512 | switch (hw->mac.type) { |
| 1513 | case e1000_80003es2lan: |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1514 | if (hw->phy.media_type == e1000_media_type_fiber || |
| 1515 | hw->phy.media_type == e1000_media_type_internal_serdes) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1516 | /* restore CTRL_EXT, stealing space from tx_fifo_head */ |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1517 | ew32(CTRL_EXT, adapter->tx_fifo_head); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1518 | adapter->tx_fifo_head = 0; |
| 1519 | } |
| 1520 | /* fall through */ |
| 1521 | case e1000_82571: |
| 1522 | case e1000_82572: |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1523 | if (hw->phy.media_type == e1000_media_type_fiber || |
| 1524 | hw->phy.media_type == e1000_media_type_internal_serdes) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1525 | #define E1000_SERDES_LB_OFF 0x400 |
| 1526 | ew32(SCTL, E1000_SERDES_LB_OFF); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 1527 | e1e_flush(); |
Bruce Allan | 1bba438 | 2011-03-19 00:27:20 +0000 | [diff] [blame] | 1528 | usleep_range(10000, 20000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1529 | break; |
| 1530 | } |
| 1531 | /* Fall Through */ |
| 1532 | default: |
| 1533 | hw->mac.autoneg = 1; |
| 1534 | if (hw->phy.type == e1000_phy_gg82563) |
| 1535 | e1e_wphy(hw, GG82563_PHY_KMRN_MODE_CTRL, 0x180); |
Bruce Allan | c2ade1a | 2013-01-16 08:54:35 +0000 | [diff] [blame] | 1536 | e1e_rphy(hw, MII_BMCR, &phy_reg); |
| 1537 | if (phy_reg & BMCR_LOOPBACK) { |
| 1538 | phy_reg &= ~BMCR_LOOPBACK; |
| 1539 | e1e_wphy(hw, MII_BMCR, phy_reg); |
Bruce Allan | 6b598e1 | 2013-01-23 06:50:05 +0000 | [diff] [blame] | 1540 | if (hw->phy.ops.commit) |
| 1541 | hw->phy.ops.commit(hw); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1542 | } |
| 1543 | break; |
| 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | static void e1000_create_lbtest_frame(struct sk_buff *skb, |
| 1548 | unsigned int frame_size) |
| 1549 | { |
| 1550 | memset(skb->data, 0xFF, frame_size); |
| 1551 | frame_size &= ~1; |
| 1552 | memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1); |
| 1553 | memset(&skb->data[frame_size / 2 + 10], 0xBE, 1); |
| 1554 | memset(&skb->data[frame_size / 2 + 12], 0xAF, 1); |
| 1555 | } |
| 1556 | |
| 1557 | static int e1000_check_lbtest_frame(struct sk_buff *skb, |
| 1558 | unsigned int frame_size) |
| 1559 | { |
| 1560 | frame_size &= ~1; |
| 1561 | if (*(skb->data + 3) == 0xFF) |
| 1562 | if ((*(skb->data + frame_size / 2 + 10) == 0xBE) && |
| 1563 | (*(skb->data + frame_size / 2 + 12) == 0xAF)) |
| 1564 | return 0; |
| 1565 | return 13; |
| 1566 | } |
| 1567 | |
| 1568 | static int e1000_run_loopback_test(struct e1000_adapter *adapter) |
| 1569 | { |
| 1570 | struct e1000_ring *tx_ring = &adapter->test_tx_ring; |
| 1571 | struct e1000_ring *rx_ring = &adapter->test_rx_ring; |
| 1572 | struct pci_dev *pdev = adapter->pdev; |
| 1573 | struct e1000_hw *hw = &adapter->hw; |
| 1574 | int i, j, k, l; |
| 1575 | int lc; |
| 1576 | int good_cnt; |
| 1577 | int ret_val = 0; |
| 1578 | unsigned long time; |
| 1579 | |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 1580 | ew32(RDT(0), rx_ring->count - 1); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1581 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1582 | /* Calculate the loop count based on the largest descriptor ring |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1583 | * The idea is to wrap the largest ring a number of times using 64 |
| 1584 | * send/receive pairs during each loop |
| 1585 | */ |
| 1586 | |
| 1587 | if (rx_ring->count <= tx_ring->count) |
| 1588 | lc = ((tx_ring->count / 64) * 2) + 1; |
| 1589 | else |
| 1590 | lc = ((rx_ring->count / 64) * 2) + 1; |
| 1591 | |
| 1592 | k = 0; |
| 1593 | l = 0; |
| 1594 | for (j = 0; j <= lc; j++) { /* loop count loop */ |
| 1595 | for (i = 0; i < 64; i++) { /* send the packets */ |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 1596 | e1000_create_lbtest_frame(tx_ring->buffer_info[k].skb, |
| 1597 | 1024); |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1598 | dma_sync_single_for_device(&pdev->dev, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1599 | tx_ring->buffer_info[k].dma, |
| 1600 | tx_ring->buffer_info[k].length, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1601 | DMA_TO_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1602 | k++; |
| 1603 | if (k == tx_ring->count) |
| 1604 | k = 0; |
| 1605 | } |
Bruce Allan | 1e36052 | 2012-03-20 03:48:13 +0000 | [diff] [blame] | 1606 | ew32(TDT(0), k); |
Jesse Brandeburg | 945a515 | 2011-07-20 00:56:21 +0000 | [diff] [blame] | 1607 | e1e_flush(); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1608 | msleep(200); |
| 1609 | time = jiffies; /* set the start time for the receive */ |
| 1610 | good_cnt = 0; |
| 1611 | do { /* receive the sent packets */ |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1612 | dma_sync_single_for_cpu(&pdev->dev, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1613 | rx_ring->buffer_info[l].dma, 2048, |
Nick Nunley | 0be3f55 | 2010-04-27 13:09:05 +0000 | [diff] [blame] | 1614 | DMA_FROM_DEVICE); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1615 | |
| 1616 | ret_val = e1000_check_lbtest_frame( |
| 1617 | rx_ring->buffer_info[l].skb, 1024); |
| 1618 | if (!ret_val) |
| 1619 | good_cnt++; |
| 1620 | l++; |
| 1621 | if (l == rx_ring->count) |
| 1622 | l = 0; |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1623 | /* time + 20 msecs (200 msecs on 2.4) is more than |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1624 | * enough time to complete the receives, if it's |
| 1625 | * exceeded, break and error off |
| 1626 | */ |
| 1627 | } while ((good_cnt < 64) && !time_after(jiffies, time + 20)); |
| 1628 | if (good_cnt != 64) { |
| 1629 | ret_val = 13; /* ret_val is the same as mis-compare */ |
| 1630 | break; |
| 1631 | } |
Bruce Allan | cef8c79 | 2008-04-02 13:48:23 -0700 | [diff] [blame] | 1632 | if (jiffies >= (time + 20)) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1633 | ret_val = 14; /* error code for time out error */ |
| 1634 | break; |
| 1635 | } |
| 1636 | } /* end loop count loop */ |
| 1637 | return ret_val; |
| 1638 | } |
| 1639 | |
| 1640 | static int e1000_loopback_test(struct e1000_adapter *adapter, u64 *data) |
| 1641 | { |
Bruce Allan | 44abd5c | 2012-02-22 09:02:37 +0000 | [diff] [blame] | 1642 | struct e1000_hw *hw = &adapter->hw; |
| 1643 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1644 | /* PHY loopback cannot be performed if SoL/IDER sessions are active */ |
Bruce Allan | 470a542 | 2012-05-26 06:08:48 +0000 | [diff] [blame] | 1645 | if (hw->phy.ops.check_reset_block && |
| 1646 | hw->phy.ops.check_reset_block(hw)) { |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1647 | 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] | 1648 | *data = 0; |
| 1649 | goto out; |
| 1650 | } |
| 1651 | |
| 1652 | *data = e1000_setup_desc_rings(adapter); |
Adrian Bunk | e265522 | 2007-10-15 14:02:21 -0700 | [diff] [blame] | 1653 | if (*data) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1654 | goto out; |
| 1655 | |
| 1656 | *data = e1000_setup_loopback_test(adapter); |
Adrian Bunk | e265522 | 2007-10-15 14:02:21 -0700 | [diff] [blame] | 1657 | if (*data) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1658 | goto err_loopback; |
| 1659 | |
| 1660 | *data = e1000_run_loopback_test(adapter); |
| 1661 | e1000_loopback_cleanup(adapter); |
| 1662 | |
| 1663 | err_loopback: |
| 1664 | e1000_free_desc_rings(adapter); |
| 1665 | out: |
| 1666 | return *data; |
| 1667 | } |
| 1668 | |
| 1669 | static int e1000_link_test(struct e1000_adapter *adapter, u64 *data) |
| 1670 | { |
| 1671 | struct e1000_hw *hw = &adapter->hw; |
| 1672 | |
| 1673 | *data = 0; |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1674 | if (hw->phy.media_type == e1000_media_type_internal_serdes) { |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1675 | int i = 0; |
Alex Chiang | 612e244 | 2009-02-05 23:55:45 -0800 | [diff] [blame] | 1676 | hw->mac.serdes_has_link = false; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1677 | |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1678 | /* On some blade server designs, link establishment |
Bruce Allan | ad68076 | 2008-03-28 09:15:03 -0700 | [diff] [blame] | 1679 | * could take as long as 2-3 minutes |
| 1680 | */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1681 | do { |
| 1682 | hw->mac.ops.check_for_link(hw); |
| 1683 | if (hw->mac.serdes_has_link) |
| 1684 | return *data; |
| 1685 | msleep(20); |
| 1686 | } while (i++ < 3750); |
| 1687 | |
| 1688 | *data = 1; |
| 1689 | } else { |
| 1690 | hw->mac.ops.check_for_link(hw); |
| 1691 | if (hw->mac.autoneg) |
Bruce Allan | e921eb1 | 2012-11-28 09:28:37 +0000 | [diff] [blame] | 1692 | /* On some Phy/switch combinations, link establishment |
Bruce Allan | 5661aeb | 2011-02-25 06:36:25 +0000 | [diff] [blame] | 1693 | * can take a few seconds more than expected. |
| 1694 | */ |
| 1695 | msleep(5000); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1696 | |
Bruce Allan | 5661aeb | 2011-02-25 06:36:25 +0000 | [diff] [blame] | 1697 | if (!(er32(STATUS) & E1000_STATUS_LU)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1698 | *data = 1; |
| 1699 | } |
| 1700 | return *data; |
| 1701 | } |
| 1702 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1703 | static int e1000e_get_sset_count(struct net_device __always_unused *netdev, |
| 1704 | int sset) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1705 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1706 | switch (sset) { |
| 1707 | case ETH_SS_TEST: |
| 1708 | return E1000_TEST_LEN; |
| 1709 | case ETH_SS_STATS: |
| 1710 | return E1000_STATS_LEN; |
| 1711 | default: |
| 1712 | return -EOPNOTSUPP; |
| 1713 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | static void e1000_diag_test(struct net_device *netdev, |
| 1717 | struct ethtool_test *eth_test, u64 *data) |
| 1718 | { |
| 1719 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1720 | u16 autoneg_advertised; |
| 1721 | u8 forced_speed_duplex; |
| 1722 | u8 autoneg; |
| 1723 | bool if_running = netif_running(netdev); |
| 1724 | |
| 1725 | set_bit(__E1000_TESTING, &adapter->state); |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 1726 | |
| 1727 | if (!if_running) { |
| 1728 | /* Get control of and reset hardware */ |
| 1729 | if (adapter->flags & FLAG_HAS_AMT) |
| 1730 | e1000e_get_hw_control(adapter); |
| 1731 | |
| 1732 | e1000e_power_up_phy(adapter); |
| 1733 | |
| 1734 | adapter->hw.phy.autoneg_wait_to_complete = 1; |
| 1735 | e1000e_reset(adapter); |
| 1736 | adapter->hw.phy.autoneg_wait_to_complete = 0; |
| 1737 | } |
| 1738 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1739 | if (eth_test->flags == ETH_TEST_FL_OFFLINE) { |
| 1740 | /* Offline tests */ |
| 1741 | |
| 1742 | /* save speed, duplex, autoneg settings */ |
| 1743 | autoneg_advertised = adapter->hw.phy.autoneg_advertised; |
| 1744 | forced_speed_duplex = adapter->hw.mac.forced_speed_duplex; |
| 1745 | autoneg = adapter->hw.mac.autoneg; |
| 1746 | |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1747 | e_info("offline testing starting\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1748 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1749 | if (if_running) |
| 1750 | /* indicate we're in test mode */ |
| 1751 | dev_close(netdev); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1752 | |
| 1753 | if (e1000_reg_test(adapter, &data[0])) |
| 1754 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1755 | |
| 1756 | e1000e_reset(adapter); |
| 1757 | if (e1000_eeprom_test(adapter, &data[1])) |
| 1758 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1759 | |
| 1760 | e1000e_reset(adapter); |
| 1761 | if (e1000_intr_test(adapter, &data[2])) |
| 1762 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1763 | |
| 1764 | e1000e_reset(adapter); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1765 | if (e1000_loopback_test(adapter, &data[3])) |
| 1766 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1767 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1768 | /* force this routine to wait until autoneg complete/timeout */ |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1769 | adapter->hw.phy.autoneg_wait_to_complete = 1; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1770 | e1000e_reset(adapter); |
Jeff Kirsher | 318a94d | 2008-03-28 09:15:16 -0700 | [diff] [blame] | 1771 | adapter->hw.phy.autoneg_wait_to_complete = 0; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1772 | |
Carolyn Wyborny | c6ce385 | 2010-10-15 17:35:31 +0000 | [diff] [blame] | 1773 | if (e1000_link_test(adapter, &data[4])) |
| 1774 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1775 | |
| 1776 | /* restore speed, duplex, autoneg settings */ |
| 1777 | adapter->hw.phy.autoneg_advertised = autoneg_advertised; |
| 1778 | adapter->hw.mac.forced_speed_duplex = forced_speed_duplex; |
| 1779 | adapter->hw.mac.autoneg = autoneg; |
| 1780 | e1000e_reset(adapter); |
| 1781 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1782 | clear_bit(__E1000_TESTING, &adapter->state); |
| 1783 | if (if_running) |
| 1784 | dev_open(netdev); |
| 1785 | } else { |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 1786 | /* Online tests */ |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 1787 | |
Jeff Kirsher | 44defeb | 2008-08-04 17:20:41 -0700 | [diff] [blame] | 1788 | e_info("online testing starting\n"); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1789 | |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 1790 | /* register, eeprom, intr and loopback tests not run online */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1791 | data[0] = 0; |
| 1792 | data[1] = 0; |
| 1793 | data[2] = 0; |
| 1794 | data[3] = 0; |
| 1795 | |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 1796 | if (e1000_link_test(adapter, &data[4])) |
| 1797 | eth_test->flags |= ETH_TEST_FL_FAILED; |
Bruce Allan | 11b08be | 2010-05-10 14:59:31 +0000 | [diff] [blame] | 1798 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1799 | clear_bit(__E1000_TESTING, &adapter->state); |
| 1800 | } |
Bruce Allan | 31dbe5b | 2011-01-06 14:29:52 +0000 | [diff] [blame] | 1801 | |
| 1802 | if (!if_running) { |
| 1803 | e1000e_reset(adapter); |
| 1804 | |
| 1805 | if (adapter->flags & FLAG_HAS_AMT) |
| 1806 | e1000e_release_hw_control(adapter); |
| 1807 | } |
| 1808 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1809 | msleep_interruptible(4 * 1000); |
| 1810 | } |
| 1811 | |
| 1812 | static void e1000_get_wol(struct net_device *netdev, |
| 1813 | struct ethtool_wolinfo *wol) |
| 1814 | { |
| 1815 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1816 | |
| 1817 | wol->supported = 0; |
| 1818 | wol->wolopts = 0; |
| 1819 | |
\"Rafael J. Wysocki\ | 6ff6802 | 2008-11-12 09:52:32 +0000 | [diff] [blame] | 1820 | if (!(adapter->flags & FLAG_HAS_WOL) || |
| 1821 | !device_can_wakeup(&adapter->pdev->dev)) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1822 | return; |
| 1823 | |
| 1824 | wol->supported = WAKE_UCAST | WAKE_MCAST | |
Bruce Allan | 4a29e15 | 2011-03-04 09:07:01 +0000 | [diff] [blame] | 1825 | WAKE_BCAST | WAKE_MAGIC | WAKE_PHY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1826 | |
| 1827 | /* apply any specific unsupported masks here */ |
| 1828 | if (adapter->flags & FLAG_NO_WAKE_UCAST) { |
| 1829 | wol->supported &= ~WAKE_UCAST; |
| 1830 | |
| 1831 | if (adapter->wol & E1000_WUFC_EX) |
Bruce Allan | 6ad6514 | 2012-04-12 05:47:09 +0000 | [diff] [blame] | 1832 | 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] | 1833 | } |
| 1834 | |
| 1835 | if (adapter->wol & E1000_WUFC_EX) |
| 1836 | wol->wolopts |= WAKE_UCAST; |
| 1837 | if (adapter->wol & E1000_WUFC_MC) |
| 1838 | wol->wolopts |= WAKE_MCAST; |
| 1839 | if (adapter->wol & E1000_WUFC_BC) |
| 1840 | wol->wolopts |= WAKE_BCAST; |
| 1841 | if (adapter->wol & E1000_WUFC_MAG) |
| 1842 | wol->wolopts |= WAKE_MAGIC; |
Mitch Williams | efb90e4 | 2008-01-29 12:43:02 -0800 | [diff] [blame] | 1843 | if (adapter->wol & E1000_WUFC_LNKC) |
| 1844 | wol->wolopts |= WAKE_PHY; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1845 | } |
| 1846 | |
Bruce Allan | 4a29e15 | 2011-03-04 09:07:01 +0000 | [diff] [blame] | 1847 | 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] | 1848 | { |
| 1849 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1850 | |
\"Rafael J. Wysocki\ | 6ff6802 | 2008-11-12 09:52:32 +0000 | [diff] [blame] | 1851 | if (!(adapter->flags & FLAG_HAS_WOL) || |
Bruce Allan | 1fbfca3 | 2009-11-20 23:22:01 +0000 | [diff] [blame] | 1852 | !device_can_wakeup(&adapter->pdev->dev) || |
| 1853 | (wol->wolopts & ~(WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | |
Bruce Allan | 4a29e15 | 2011-03-04 09:07:01 +0000 | [diff] [blame] | 1854 | WAKE_MAGIC | WAKE_PHY))) |
Bruce Allan | 1fbfca3 | 2009-11-20 23:22:01 +0000 | [diff] [blame] | 1855 | return -EOPNOTSUPP; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1856 | |
| 1857 | /* these settings will always override what we currently have */ |
| 1858 | adapter->wol = 0; |
| 1859 | |
| 1860 | if (wol->wolopts & WAKE_UCAST) |
| 1861 | adapter->wol |= E1000_WUFC_EX; |
| 1862 | if (wol->wolopts & WAKE_MCAST) |
| 1863 | adapter->wol |= E1000_WUFC_MC; |
| 1864 | if (wol->wolopts & WAKE_BCAST) |
| 1865 | adapter->wol |= E1000_WUFC_BC; |
| 1866 | if (wol->wolopts & WAKE_MAGIC) |
| 1867 | adapter->wol |= E1000_WUFC_MAG; |
Mitch Williams | efb90e4 | 2008-01-29 12:43:02 -0800 | [diff] [blame] | 1868 | if (wol->wolopts & WAKE_PHY) |
| 1869 | adapter->wol |= E1000_WUFC_LNKC; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1870 | |
\"Rafael J. Wysocki\ | 6ff6802 | 2008-11-12 09:52:32 +0000 | [diff] [blame] | 1871 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 1872 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1873 | return 0; |
| 1874 | } |
| 1875 | |
Bruce Allan | dbf80dc | 2011-04-16 00:34:40 +0000 | [diff] [blame] | 1876 | static int e1000_set_phys_id(struct net_device *netdev, |
| 1877 | enum ethtool_phys_id_state state) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1878 | { |
| 1879 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1880 | struct e1000_hw *hw = &adapter->hw; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1881 | |
Bruce Allan | dbf80dc | 2011-04-16 00:34:40 +0000 | [diff] [blame] | 1882 | switch (state) { |
| 1883 | case ETHTOOL_ID_ACTIVE: |
| 1884 | if (!hw->mac.ops.blink_led) |
| 1885 | return 2; /* cycle on/off twice per second */ |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1886 | |
Bruce Allan | dbf80dc | 2011-04-16 00:34:40 +0000 | [diff] [blame] | 1887 | hw->mac.ops.blink_led(hw); |
| 1888 | break; |
| 1889 | |
| 1890 | case ETHTOOL_ID_INACTIVE: |
Bruce Allan | 4662e82 | 2008-08-26 18:37:06 -0700 | [diff] [blame] | 1891 | if (hw->phy.type == e1000_phy_ife) |
| 1892 | e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0); |
Bruce Allan | dbf80dc | 2011-04-16 00:34:40 +0000 | [diff] [blame] | 1893 | hw->mac.ops.led_off(hw); |
| 1894 | hw->mac.ops.cleanup_led(hw); |
| 1895 | break; |
| 1896 | |
| 1897 | case ETHTOOL_ID_ON: |
Bruce Allan | f23efdf | 2012-01-31 06:37:38 +0000 | [diff] [blame] | 1898 | hw->mac.ops.led_on(hw); |
Bruce Allan | dbf80dc | 2011-04-16 00:34:40 +0000 | [diff] [blame] | 1899 | break; |
| 1900 | |
| 1901 | case ETHTOOL_ID_OFF: |
Bruce Allan | f23efdf | 2012-01-31 06:37:38 +0000 | [diff] [blame] | 1902 | hw->mac.ops.led_off(hw); |
Bruce Allan | dbf80dc | 2011-04-16 00:34:40 +0000 | [diff] [blame] | 1903 | break; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1904 | } |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1905 | return 0; |
| 1906 | } |
| 1907 | |
Auke Kok | de5b307 | 2008-04-23 11:09:08 -0700 | [diff] [blame] | 1908 | static int e1000_get_coalesce(struct net_device *netdev, |
| 1909 | struct ethtool_coalesce *ec) |
| 1910 | { |
| 1911 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 1912 | |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 1913 | if (adapter->itr_setting <= 4) |
Auke Kok | de5b307 | 2008-04-23 11:09:08 -0700 | [diff] [blame] | 1914 | ec->rx_coalesce_usecs = adapter->itr_setting; |
| 1915 | else |
| 1916 | ec->rx_coalesce_usecs = 1000000 / adapter->itr_setting; |
| 1917 | |
| 1918 | return 0; |
| 1919 | } |
| 1920 | |
| 1921 | static int e1000_set_coalesce(struct net_device *netdev, |
| 1922 | struct ethtool_coalesce *ec) |
| 1923 | { |
| 1924 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Auke Kok | de5b307 | 2008-04-23 11:09:08 -0700 | [diff] [blame] | 1925 | |
| 1926 | if ((ec->rx_coalesce_usecs > E1000_MAX_ITR_USECS) || |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 1927 | ((ec->rx_coalesce_usecs > 4) && |
Auke Kok | de5b307 | 2008-04-23 11:09:08 -0700 | [diff] [blame] | 1928 | (ec->rx_coalesce_usecs < E1000_MIN_ITR_USECS)) || |
| 1929 | (ec->rx_coalesce_usecs == 2)) |
| 1930 | return -EINVAL; |
| 1931 | |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 1932 | if (ec->rx_coalesce_usecs == 4) { |
Bruce Allan | 06a402e | 2012-08-17 06:17:57 +0000 | [diff] [blame] | 1933 | adapter->itr_setting = 4; |
| 1934 | adapter->itr = adapter->itr_setting; |
Jesse Brandeburg | eab2abf | 2010-05-04 22:26:03 +0000 | [diff] [blame] | 1935 | } else if (ec->rx_coalesce_usecs <= 3) { |
Auke Kok | de5b307 | 2008-04-23 11:09:08 -0700 | [diff] [blame] | 1936 | adapter->itr = 20000; |
| 1937 | adapter->itr_setting = ec->rx_coalesce_usecs; |
| 1938 | } else { |
| 1939 | adapter->itr = (1000000 / ec->rx_coalesce_usecs); |
| 1940 | adapter->itr_setting = adapter->itr & ~3; |
| 1941 | } |
| 1942 | |
| 1943 | if (adapter->itr_setting != 0) |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 1944 | e1000e_write_itr(adapter, adapter->itr); |
Auke Kok | de5b307 | 2008-04-23 11:09:08 -0700 | [diff] [blame] | 1945 | else |
Matthew Vick | 22a4cca | 2012-07-12 00:02:42 +0000 | [diff] [blame] | 1946 | e1000e_write_itr(adapter, 0); |
Auke Kok | de5b307 | 2008-04-23 11:09:08 -0700 | [diff] [blame] | 1947 | |
| 1948 | return 0; |
| 1949 | } |
| 1950 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1951 | static int e1000_nway_reset(struct net_device *netdev) |
| 1952 | { |
| 1953 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Bruce Allan | 5962bc2 | 2011-01-20 06:58:07 +0000 | [diff] [blame] | 1954 | |
| 1955 | if (!netif_running(netdev)) |
| 1956 | return -EAGAIN; |
| 1957 | |
| 1958 | if (!adapter->hw.mac.autoneg) |
| 1959 | return -EINVAL; |
| 1960 | |
| 1961 | e1000e_reinit_locked(adapter); |
| 1962 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1963 | return 0; |
| 1964 | } |
| 1965 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1966 | static void e1000_get_ethtool_stats(struct net_device *netdev, |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1967 | struct ethtool_stats __always_unused *stats, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1968 | u64 *data) |
| 1969 | { |
| 1970 | struct e1000_adapter *adapter = netdev_priv(netdev); |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 1971 | struct rtnl_link_stats64 net_stats; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1972 | int i; |
Ajit Khaparde | e0f36a9 | 2009-10-13 01:45:09 +0000 | [diff] [blame] | 1973 | char *p = NULL; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1974 | |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 1975 | e1000e_get_stats64(netdev, &net_stats); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1976 | for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) { |
Ajit Khaparde | e0f36a9 | 2009-10-13 01:45:09 +0000 | [diff] [blame] | 1977 | switch (e1000_gstrings_stats[i].type) { |
| 1978 | case NETDEV_STATS: |
Jeff Kirsher | 67fd4fc | 2011-01-07 05:12:09 +0000 | [diff] [blame] | 1979 | p = (char *) &net_stats + |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1980 | e1000_gstrings_stats[i].stat_offset; |
Ajit Khaparde | e0f36a9 | 2009-10-13 01:45:09 +0000 | [diff] [blame] | 1981 | break; |
| 1982 | case E1000_STATS: |
| 1983 | p = (char *) adapter + |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1984 | e1000_gstrings_stats[i].stat_offset; |
Ajit Khaparde | e0f36a9 | 2009-10-13 01:45:09 +0000 | [diff] [blame] | 1985 | break; |
Bruce Allan | 61c7581 | 2010-12-09 23:04:25 +0000 | [diff] [blame] | 1986 | default: |
| 1987 | data[i] = 0; |
| 1988 | continue; |
Ajit Khaparde | e0f36a9 | 2009-10-13 01:45:09 +0000 | [diff] [blame] | 1989 | } |
| 1990 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1991 | data[i] = (e1000_gstrings_stats[i].sizeof_stat == |
Bruce Allan | f0ff439 | 2013-02-20 04:05:39 +0000 | [diff] [blame] | 1992 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1993 | } |
| 1994 | } |
| 1995 | |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 1996 | static void e1000_get_strings(struct net_device __always_unused *netdev, |
| 1997 | u32 stringset, u8 *data) |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 1998 | { |
| 1999 | u8 *p = data; |
| 2000 | int i; |
| 2001 | |
| 2002 | switch (stringset) { |
| 2003 | case ETH_SS_TEST: |
Bruce Allan | 5c1bda0 | 2011-01-19 04:23:39 +0000 | [diff] [blame] | 2004 | memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test)); |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2005 | break; |
| 2006 | case ETH_SS_STATS: |
| 2007 | for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) { |
| 2008 | memcpy(p, e1000_gstrings_stats[i].stat_string, |
| 2009 | ETH_GSTRING_LEN); |
| 2010 | p += ETH_GSTRING_LEN; |
| 2011 | } |
| 2012 | break; |
| 2013 | } |
| 2014 | } |
| 2015 | |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 2016 | static int e1000_get_rxnfc(struct net_device *netdev, |
Bruce Allan | 8bb6286 | 2013-01-16 08:46:49 +0000 | [diff] [blame] | 2017 | struct ethtool_rxnfc *info, |
| 2018 | u32 __always_unused *rule_locs) |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 2019 | { |
| 2020 | info->data = 0; |
| 2021 | |
| 2022 | switch (info->cmd) { |
| 2023 | case ETHTOOL_GRXFH: { |
| 2024 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2025 | struct e1000_hw *hw = &adapter->hw; |
| 2026 | u32 mrqc = er32(MRQC); |
| 2027 | |
| 2028 | if (!(mrqc & E1000_MRQC_RSS_FIELD_MASK)) |
| 2029 | return 0; |
| 2030 | |
| 2031 | switch (info->flow_type) { |
| 2032 | case TCP_V4_FLOW: |
| 2033 | if (mrqc & E1000_MRQC_RSS_FIELD_IPV4_TCP) |
| 2034 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 2035 | /* fall through */ |
| 2036 | case UDP_V4_FLOW: |
| 2037 | case SCTP_V4_FLOW: |
| 2038 | case AH_ESP_V4_FLOW: |
| 2039 | case IPV4_FLOW: |
| 2040 | if (mrqc & E1000_MRQC_RSS_FIELD_IPV4) |
| 2041 | info->data |= RXH_IP_SRC | RXH_IP_DST; |
| 2042 | break; |
| 2043 | case TCP_V6_FLOW: |
| 2044 | if (mrqc & E1000_MRQC_RSS_FIELD_IPV6_TCP) |
| 2045 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 2046 | /* fall through */ |
| 2047 | case UDP_V6_FLOW: |
| 2048 | case SCTP_V6_FLOW: |
| 2049 | case AH_ESP_V6_FLOW: |
| 2050 | case IPV6_FLOW: |
| 2051 | if (mrqc & E1000_MRQC_RSS_FIELD_IPV6) |
| 2052 | info->data |= RXH_IP_SRC | RXH_IP_DST; |
| 2053 | break; |
| 2054 | default: |
| 2055 | break; |
| 2056 | } |
| 2057 | return 0; |
| 2058 | } |
| 2059 | default: |
| 2060 | return -EOPNOTSUPP; |
| 2061 | } |
| 2062 | } |
| 2063 | |
Bruce Allan | 203e415 | 2012-12-05 08:40:59 +0000 | [diff] [blame] | 2064 | static int e1000e_get_eee(struct net_device *netdev, struct ethtool_eee *edata) |
| 2065 | { |
| 2066 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2067 | struct e1000_hw *hw = &adapter->hw; |
| 2068 | u16 cap_addr, adv_addr, lpa_addr, pcs_stat_addr, phy_data, lpi_ctrl; |
| 2069 | u32 status, ret_val; |
| 2070 | |
| 2071 | if (!(adapter->flags & FLAG_IS_ICH) || |
| 2072 | !(adapter->flags2 & FLAG2_HAS_EEE)) |
| 2073 | return -EOPNOTSUPP; |
| 2074 | |
| 2075 | switch (hw->phy.type) { |
| 2076 | case e1000_phy_82579: |
| 2077 | cap_addr = I82579_EEE_CAPABILITY; |
| 2078 | adv_addr = I82579_EEE_ADVERTISEMENT; |
| 2079 | lpa_addr = I82579_EEE_LP_ABILITY; |
| 2080 | pcs_stat_addr = I82579_EEE_PCS_STATUS; |
| 2081 | break; |
| 2082 | case e1000_phy_i217: |
| 2083 | cap_addr = I217_EEE_CAPABILITY; |
| 2084 | adv_addr = I217_EEE_ADVERTISEMENT; |
| 2085 | lpa_addr = I217_EEE_LP_ABILITY; |
| 2086 | pcs_stat_addr = I217_EEE_PCS_STATUS; |
| 2087 | break; |
| 2088 | default: |
| 2089 | return -EOPNOTSUPP; |
| 2090 | } |
| 2091 | |
| 2092 | ret_val = hw->phy.ops.acquire(hw); |
| 2093 | if (ret_val) |
| 2094 | return -EBUSY; |
| 2095 | |
| 2096 | /* EEE Capability */ |
| 2097 | ret_val = e1000_read_emi_reg_locked(hw, cap_addr, &phy_data); |
| 2098 | if (ret_val) |
| 2099 | goto release; |
| 2100 | edata->supported = mmd_eee_cap_to_ethtool_sup_t(phy_data); |
| 2101 | |
| 2102 | /* EEE Advertised */ |
| 2103 | ret_val = e1000_read_emi_reg_locked(hw, adv_addr, &phy_data); |
| 2104 | if (ret_val) |
| 2105 | goto release; |
| 2106 | edata->advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data); |
| 2107 | |
| 2108 | /* EEE Link Partner Advertised */ |
| 2109 | ret_val = e1000_read_emi_reg_locked(hw, lpa_addr, &phy_data); |
| 2110 | if (ret_val) |
| 2111 | goto release; |
| 2112 | edata->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(phy_data); |
| 2113 | |
| 2114 | /* EEE PCS Status */ |
| 2115 | ret_val = e1000_read_emi_reg_locked(hw, pcs_stat_addr, &phy_data); |
| 2116 | if (hw->phy.type == e1000_phy_82579) |
| 2117 | phy_data <<= 8; |
| 2118 | |
| 2119 | release: |
| 2120 | hw->phy.ops.release(hw); |
| 2121 | if (ret_val) |
| 2122 | return -ENODATA; |
| 2123 | |
| 2124 | e1e_rphy(hw, I82579_LPI_CTRL, &lpi_ctrl); |
| 2125 | status = er32(STATUS); |
| 2126 | |
| 2127 | /* Result of the EEE auto negotiation - there is no register that |
| 2128 | * has the status of the EEE negotiation so do a best-guess based |
| 2129 | * on whether both Tx and Rx LPI indications have been received or |
| 2130 | * base it on the link speed, the EEE advertised speeds on both ends |
| 2131 | * and the speeds on which EEE is enabled locally. |
| 2132 | */ |
| 2133 | if (((phy_data & E1000_EEE_TX_LPI_RCVD) && |
| 2134 | (phy_data & E1000_EEE_RX_LPI_RCVD)) || |
| 2135 | ((status & E1000_STATUS_SPEED_100) && |
| 2136 | (edata->advertised & ADVERTISED_100baseT_Full) && |
| 2137 | (edata->lp_advertised & ADVERTISED_100baseT_Full) && |
| 2138 | (lpi_ctrl & I82579_LPI_CTRL_100_ENABLE)) || |
| 2139 | ((status & E1000_STATUS_SPEED_1000) && |
| 2140 | (edata->advertised & ADVERTISED_1000baseT_Full) && |
| 2141 | (edata->lp_advertised & ADVERTISED_1000baseT_Full) && |
| 2142 | (lpi_ctrl & I82579_LPI_CTRL_1000_ENABLE))) |
| 2143 | edata->eee_active = true; |
| 2144 | |
| 2145 | edata->eee_enabled = !hw->dev_spec.ich8lan.eee_disable; |
| 2146 | edata->tx_lpi_enabled = true; |
| 2147 | edata->tx_lpi_timer = er32(LPIC) >> E1000_LPIC_LPIET_SHIFT; |
| 2148 | |
| 2149 | return 0; |
| 2150 | } |
| 2151 | |
| 2152 | static int e1000e_set_eee(struct net_device *netdev, struct ethtool_eee *edata) |
| 2153 | { |
| 2154 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2155 | struct e1000_hw *hw = &adapter->hw; |
| 2156 | struct ethtool_eee eee_curr; |
| 2157 | s32 ret_val; |
| 2158 | |
| 2159 | if (!(adapter->flags & FLAG_IS_ICH) || |
| 2160 | !(adapter->flags2 & FLAG2_HAS_EEE)) |
| 2161 | return -EOPNOTSUPP; |
| 2162 | |
| 2163 | ret_val = e1000e_get_eee(netdev, &eee_curr); |
| 2164 | if (ret_val) |
| 2165 | return ret_val; |
| 2166 | |
| 2167 | if (eee_curr.advertised != edata->advertised) { |
| 2168 | e_err("Setting EEE advertisement is not supported\n"); |
| 2169 | return -EINVAL; |
| 2170 | } |
| 2171 | |
| 2172 | if (eee_curr.tx_lpi_enabled != edata->tx_lpi_enabled) { |
| 2173 | e_err("Setting EEE tx-lpi is not supported\n"); |
| 2174 | return -EINVAL; |
| 2175 | } |
| 2176 | |
| 2177 | if (eee_curr.tx_lpi_timer != edata->tx_lpi_timer) { |
| 2178 | e_err("Setting EEE Tx LPI timer is not supported\n"); |
| 2179 | return -EINVAL; |
| 2180 | } |
| 2181 | |
| 2182 | if (hw->dev_spec.ich8lan.eee_disable != !edata->eee_enabled) { |
| 2183 | hw->dev_spec.ich8lan.eee_disable = !edata->eee_enabled; |
| 2184 | |
| 2185 | /* reset the link */ |
| 2186 | if (netif_running(netdev)) |
| 2187 | e1000e_reinit_locked(adapter); |
| 2188 | else |
| 2189 | e1000e_reset(adapter); |
| 2190 | } |
| 2191 | |
| 2192 | return 0; |
| 2193 | } |
| 2194 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 2195 | static int e1000e_get_ts_info(struct net_device *netdev, |
| 2196 | struct ethtool_ts_info *info) |
| 2197 | { |
| 2198 | struct e1000_adapter *adapter = netdev_priv(netdev); |
| 2199 | |
| 2200 | ethtool_op_get_ts_info(netdev, info); |
| 2201 | |
| 2202 | if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP)) |
| 2203 | return 0; |
| 2204 | |
| 2205 | info->so_timestamping |= (SOF_TIMESTAMPING_TX_HARDWARE | |
| 2206 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 2207 | SOF_TIMESTAMPING_RAW_HARDWARE); |
| 2208 | |
| 2209 | info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON); |
| 2210 | |
| 2211 | info->rx_filters = ((1 << HWTSTAMP_FILTER_NONE) | |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 2212 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | |
| 2213 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | |
| 2214 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) | |
| 2215 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) | |
| 2216 | (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) | |
| 2217 | (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) | |
| 2218 | (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) | |
| 2219 | (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) | |
| 2220 | (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 2221 | (1 << HWTSTAMP_FILTER_ALL)); |
| 2222 | |
Bruce Allan | d89777b | 2013-01-19 01:09:58 +0000 | [diff] [blame] | 2223 | if (adapter->ptp_clock) |
| 2224 | info->phc_index = ptp_clock_index(adapter->ptp_clock); |
| 2225 | |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 2226 | return 0; |
| 2227 | } |
| 2228 | |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2229 | static const struct ethtool_ops e1000_ethtool_ops = { |
| 2230 | .get_settings = e1000_get_settings, |
| 2231 | .set_settings = e1000_set_settings, |
| 2232 | .get_drvinfo = e1000_get_drvinfo, |
| 2233 | .get_regs_len = e1000_get_regs_len, |
| 2234 | .get_regs = e1000_get_regs, |
| 2235 | .get_wol = e1000_get_wol, |
| 2236 | .set_wol = e1000_set_wol, |
| 2237 | .get_msglevel = e1000_get_msglevel, |
| 2238 | .set_msglevel = e1000_set_msglevel, |
| 2239 | .nway_reset = e1000_nway_reset, |
Ben Hutchings | ed4ba4b | 2010-12-09 12:10:25 +0000 | [diff] [blame] | 2240 | .get_link = ethtool_op_get_link, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2241 | .get_eeprom_len = e1000_get_eeprom_len, |
| 2242 | .get_eeprom = e1000_get_eeprom, |
| 2243 | .set_eeprom = e1000_set_eeprom, |
| 2244 | .get_ringparam = e1000_get_ringparam, |
| 2245 | .set_ringparam = e1000_set_ringparam, |
| 2246 | .get_pauseparam = e1000_get_pauseparam, |
| 2247 | .set_pauseparam = e1000_set_pauseparam, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2248 | .self_test = e1000_diag_test, |
| 2249 | .get_strings = e1000_get_strings, |
Bruce Allan | dbf80dc | 2011-04-16 00:34:40 +0000 | [diff] [blame] | 2250 | .set_phys_id = e1000_set_phys_id, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2251 | .get_ethtool_stats = e1000_get_ethtool_stats, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2252 | .get_sset_count = e1000e_get_sset_count, |
Auke Kok | de5b307 | 2008-04-23 11:09:08 -0700 | [diff] [blame] | 2253 | .get_coalesce = e1000_get_coalesce, |
| 2254 | .set_coalesce = e1000_set_coalesce, |
Bruce Allan | 70495a5 | 2012-01-11 01:26:50 +0000 | [diff] [blame] | 2255 | .get_rxnfc = e1000_get_rxnfc, |
Bruce Allan | b67e191 | 2012-12-27 08:32:33 +0000 | [diff] [blame] | 2256 | .get_ts_info = e1000e_get_ts_info, |
Bruce Allan | 203e415 | 2012-12-05 08:40:59 +0000 | [diff] [blame] | 2257 | .get_eee = e1000e_get_eee, |
| 2258 | .set_eee = e1000e_set_eee, |
Auke Kok | bc7f75f | 2007-09-17 12:30:59 -0700 | [diff] [blame] | 2259 | }; |
| 2260 | |
| 2261 | void e1000e_set_ethtool_ops(struct net_device *netdev) |
| 2262 | { |
| 2263 | SET_ETHTOOL_OPS(netdev, &e1000_ethtool_ops); |
| 2264 | } |