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