Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel(R) 82576 Virtual Function Linux driver |
Mitch A Williams | 2a06ed9 | 2012-01-17 04:09:05 +0000 | [diff] [blame] | 4 | Copyright(c) 2009 - 2012 Intel Corporation. |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 16 | this program; if not, see <http://www.gnu.org/licenses/>. |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 17 | |
| 18 | The full GNU General Public License is included in this distribution in |
| 19 | the file called "COPYING". |
| 20 | |
| 21 | Contact Information: |
| 22 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 23 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | |
| 25 | *******************************************************************************/ |
| 26 | |
| 27 | /* ethtool support for igbvf */ |
| 28 | |
| 29 | #include <linux/netdevice.h> |
| 30 | #include <linux/ethtool.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <linux/vmalloc.h> |
| 33 | #include <linux/delay.h> |
| 34 | |
| 35 | #include "igbvf.h" |
| 36 | #include <linux/if_vlan.h> |
| 37 | |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 38 | struct igbvf_stats { |
| 39 | char stat_string[ETH_GSTRING_LEN]; |
| 40 | int sizeof_stat; |
| 41 | int stat_offset; |
| 42 | int base_stat_offset; |
| 43 | }; |
| 44 | |
| 45 | #define IGBVF_STAT(current, base) \ |
| 46 | sizeof(((struct igbvf_adapter *)0)->current), \ |
| 47 | offsetof(struct igbvf_adapter, current), \ |
| 48 | offsetof(struct igbvf_adapter, base) |
| 49 | |
| 50 | static const struct igbvf_stats igbvf_gstrings_stats[] = { |
| 51 | { "rx_packets", IGBVF_STAT(stats.gprc, stats.base_gprc) }, |
| 52 | { "tx_packets", IGBVF_STAT(stats.gptc, stats.base_gptc) }, |
| 53 | { "rx_bytes", IGBVF_STAT(stats.gorc, stats.base_gorc) }, |
| 54 | { "tx_bytes", IGBVF_STAT(stats.gotc, stats.base_gotc) }, |
| 55 | { "multicast", IGBVF_STAT(stats.mprc, stats.base_mprc) }, |
| 56 | { "lbrx_bytes", IGBVF_STAT(stats.gorlbc, stats.base_gorlbc) }, |
| 57 | { "lbrx_packets", IGBVF_STAT(stats.gprlbc, stats.base_gprlbc) }, |
| 58 | { "tx_restart_queue", IGBVF_STAT(restart_queue, zero_base) }, |
| 59 | { "rx_long_byte_count", IGBVF_STAT(stats.gorc, stats.base_gorc) }, |
| 60 | { "rx_csum_offload_good", IGBVF_STAT(hw_csum_good, zero_base) }, |
| 61 | { "rx_csum_offload_errors", IGBVF_STAT(hw_csum_err, zero_base) }, |
| 62 | { "rx_header_split", IGBVF_STAT(rx_hdr_split, zero_base) }, |
| 63 | { "alloc_rx_buff_failed", IGBVF_STAT(alloc_rx_buff_failed, zero_base) }, |
| 64 | }; |
| 65 | |
| 66 | #define IGBVF_GLOBAL_STATS_LEN ARRAY_SIZE(igbvf_gstrings_stats) |
| 67 | |
| 68 | static const char igbvf_gstrings_test[][ETH_GSTRING_LEN] = { |
| 69 | "Link test (on/offline)" |
| 70 | }; |
| 71 | |
| 72 | #define IGBVF_TEST_LEN ARRAY_SIZE(igbvf_gstrings_test) |
| 73 | |
| 74 | static int igbvf_get_settings(struct net_device *netdev, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 75 | struct ethtool_cmd *ecmd) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 76 | { |
| 77 | struct igbvf_adapter *adapter = netdev_priv(netdev); |
| 78 | struct e1000_hw *hw = &adapter->hw; |
| 79 | u32 status; |
| 80 | |
| 81 | ecmd->supported = SUPPORTED_1000baseT_Full; |
| 82 | |
| 83 | ecmd->advertising = ADVERTISED_1000baseT_Full; |
| 84 | |
| 85 | ecmd->port = -1; |
| 86 | ecmd->transceiver = XCVR_DUMMY1; |
| 87 | |
| 88 | status = er32(STATUS); |
| 89 | if (status & E1000_STATUS_LU) { |
| 90 | if (status & E1000_STATUS_SPEED_1000) |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 91 | ethtool_cmd_speed_set(ecmd, SPEED_1000); |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 92 | else if (status & E1000_STATUS_SPEED_100) |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 93 | ethtool_cmd_speed_set(ecmd, SPEED_100); |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 94 | else |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 95 | ethtool_cmd_speed_set(ecmd, SPEED_10); |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 96 | |
| 97 | if (status & E1000_STATUS_FD) |
| 98 | ecmd->duplex = DUPLEX_FULL; |
| 99 | else |
| 100 | ecmd->duplex = DUPLEX_HALF; |
| 101 | } else { |
Jiri Pirko | 537fae0 | 2014-06-06 14:17:00 +0200 | [diff] [blame] | 102 | ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN); |
| 103 | ecmd->duplex = DUPLEX_UNKNOWN; |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | ecmd->autoneg = AUTONEG_DISABLE; |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 111 | static int igbvf_set_settings(struct net_device *netdev, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 112 | struct ethtool_cmd *ecmd) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 113 | { |
| 114 | return -EOPNOTSUPP; |
| 115 | } |
| 116 | |
| 117 | static void igbvf_get_pauseparam(struct net_device *netdev, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 118 | struct ethtool_pauseparam *pause) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 119 | { |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | static int igbvf_set_pauseparam(struct net_device *netdev, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 123 | struct ethtool_pauseparam *pause) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 124 | { |
| 125 | return -EOPNOTSUPP; |
| 126 | } |
| 127 | |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 128 | static u32 igbvf_get_msglevel(struct net_device *netdev) |
| 129 | { |
| 130 | struct igbvf_adapter *adapter = netdev_priv(netdev); |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 131 | |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 132 | return adapter->msg_enable; |
| 133 | } |
| 134 | |
| 135 | static void igbvf_set_msglevel(struct net_device *netdev, u32 data) |
| 136 | { |
| 137 | struct igbvf_adapter *adapter = netdev_priv(netdev); |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 138 | |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 139 | adapter->msg_enable = data; |
| 140 | } |
| 141 | |
| 142 | static int igbvf_get_regs_len(struct net_device *netdev) |
| 143 | { |
| 144 | #define IGBVF_REGS_LEN 8 |
| 145 | return IGBVF_REGS_LEN * sizeof(u32); |
| 146 | } |
| 147 | |
| 148 | static void igbvf_get_regs(struct net_device *netdev, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 149 | struct ethtool_regs *regs, void *p) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 150 | { |
| 151 | struct igbvf_adapter *adapter = netdev_priv(netdev); |
| 152 | struct e1000_hw *hw = &adapter->hw; |
| 153 | u32 *regs_buff = p; |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 154 | |
| 155 | memset(p, 0, IGBVF_REGS_LEN * sizeof(u32)); |
| 156 | |
Sergei Shtylyov | ff938e4 | 2011-02-28 11:57:33 -0800 | [diff] [blame] | 157 | regs->version = (1 << 24) | (adapter->pdev->revision << 16) | |
| 158 | adapter->pdev->device; |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 159 | |
| 160 | regs_buff[0] = er32(CTRL); |
| 161 | regs_buff[1] = er32(STATUS); |
| 162 | |
| 163 | regs_buff[2] = er32(RDLEN(0)); |
| 164 | regs_buff[3] = er32(RDH(0)); |
| 165 | regs_buff[4] = er32(RDT(0)); |
| 166 | |
| 167 | regs_buff[5] = er32(TDLEN(0)); |
| 168 | regs_buff[6] = er32(TDH(0)); |
| 169 | regs_buff[7] = er32(TDT(0)); |
| 170 | } |
| 171 | |
| 172 | static int igbvf_get_eeprom_len(struct net_device *netdev) |
| 173 | { |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | static int igbvf_get_eeprom(struct net_device *netdev, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 178 | struct ethtool_eeprom *eeprom, u8 *bytes) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 179 | { |
| 180 | return -EOPNOTSUPP; |
| 181 | } |
| 182 | |
| 183 | static int igbvf_set_eeprom(struct net_device *netdev, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 184 | struct ethtool_eeprom *eeprom, u8 *bytes) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 185 | { |
| 186 | return -EOPNOTSUPP; |
| 187 | } |
| 188 | |
| 189 | static void igbvf_get_drvinfo(struct net_device *netdev, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 190 | struct ethtool_drvinfo *drvinfo) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 191 | { |
| 192 | struct igbvf_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 193 | |
Rick Jones | 612a94d | 2011-11-14 08:13:25 +0000 | [diff] [blame] | 194 | strlcpy(drvinfo->driver, igbvf_driver_name, sizeof(drvinfo->driver)); |
| 195 | strlcpy(drvinfo->version, igbvf_driver_version, |
| 196 | sizeof(drvinfo->version)); |
Rick Jones | 612a94d | 2011-11-14 08:13:25 +0000 | [diff] [blame] | 197 | strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), |
| 198 | sizeof(drvinfo->bus_info)); |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 199 | drvinfo->regdump_len = igbvf_get_regs_len(netdev); |
| 200 | drvinfo->eedump_len = igbvf_get_eeprom_len(netdev); |
| 201 | } |
| 202 | |
| 203 | static void igbvf_get_ringparam(struct net_device *netdev, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 204 | struct ethtool_ringparam *ring) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 205 | { |
| 206 | struct igbvf_adapter *adapter = netdev_priv(netdev); |
| 207 | struct igbvf_ring *tx_ring = adapter->tx_ring; |
| 208 | struct igbvf_ring *rx_ring = adapter->rx_ring; |
| 209 | |
| 210 | ring->rx_max_pending = IGBVF_MAX_RXD; |
| 211 | ring->tx_max_pending = IGBVF_MAX_TXD; |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 212 | ring->rx_pending = rx_ring->count; |
| 213 | ring->tx_pending = tx_ring->count; |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | static int igbvf_set_ringparam(struct net_device *netdev, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 217 | struct ethtool_ringparam *ring) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 218 | { |
| 219 | struct igbvf_adapter *adapter = netdev_priv(netdev); |
| 220 | struct igbvf_ring *temp_ring; |
Alexander Duyck | 3930596 | 2009-10-26 11:32:25 +0000 | [diff] [blame] | 221 | int err = 0; |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 222 | u32 new_rx_count, new_tx_count; |
| 223 | |
| 224 | if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) |
| 225 | return -EINVAL; |
| 226 | |
| 227 | new_rx_count = max(ring->rx_pending, (u32)IGBVF_MIN_RXD); |
| 228 | new_rx_count = min(new_rx_count, (u32)IGBVF_MAX_RXD); |
| 229 | new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE); |
| 230 | |
| 231 | new_tx_count = max(ring->tx_pending, (u32)IGBVF_MIN_TXD); |
| 232 | new_tx_count = min(new_tx_count, (u32)IGBVF_MAX_TXD); |
| 233 | new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE); |
| 234 | |
| 235 | if ((new_tx_count == adapter->tx_ring->count) && |
| 236 | (new_rx_count == adapter->rx_ring->count)) { |
| 237 | /* nothing to do */ |
| 238 | return 0; |
| 239 | } |
| 240 | |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 241 | while (test_and_set_bit(__IGBVF_RESETTING, &adapter->state)) |
| 242 | msleep(1); |
| 243 | |
Alexander Duyck | 3930596 | 2009-10-26 11:32:25 +0000 | [diff] [blame] | 244 | if (!netif_running(adapter->netdev)) { |
| 245 | adapter->tx_ring->count = new_tx_count; |
| 246 | adapter->rx_ring->count = new_rx_count; |
| 247 | goto clear_reset; |
| 248 | } |
| 249 | |
| 250 | temp_ring = vmalloc(sizeof(struct igbvf_ring)); |
| 251 | if (!temp_ring) { |
| 252 | err = -ENOMEM; |
| 253 | goto clear_reset; |
| 254 | } |
| 255 | |
| 256 | igbvf_down(adapter); |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 257 | |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 258 | /* We can't just free everything and then setup again, |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 259 | * because the ISRs in MSI-X mode get passed pointers |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 260 | * to the Tx and Rx ring structs. |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 261 | */ |
| 262 | if (new_tx_count != adapter->tx_ring->count) { |
| 263 | memcpy(temp_ring, adapter->tx_ring, sizeof(struct igbvf_ring)); |
| 264 | |
| 265 | temp_ring->count = new_tx_count; |
| 266 | err = igbvf_setup_tx_resources(adapter, temp_ring); |
| 267 | if (err) |
| 268 | goto err_setup; |
| 269 | |
| 270 | igbvf_free_tx_resources(adapter->tx_ring); |
| 271 | |
| 272 | memcpy(adapter->tx_ring, temp_ring, sizeof(struct igbvf_ring)); |
| 273 | } |
| 274 | |
| 275 | if (new_rx_count != adapter->rx_ring->count) { |
| 276 | memcpy(temp_ring, adapter->rx_ring, sizeof(struct igbvf_ring)); |
| 277 | |
| 278 | temp_ring->count = new_rx_count; |
| 279 | err = igbvf_setup_rx_resources(adapter, temp_ring); |
| 280 | if (err) |
| 281 | goto err_setup; |
| 282 | |
| 283 | igbvf_free_rx_resources(adapter->rx_ring); |
| 284 | |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 285 | memcpy(adapter->rx_ring, temp_ring, sizeof(struct igbvf_ring)); |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 286 | } |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 287 | err_setup: |
Alexander Duyck | 3930596 | 2009-10-26 11:32:25 +0000 | [diff] [blame] | 288 | igbvf_up(adapter); |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 289 | vfree(temp_ring); |
Alexander Duyck | 3930596 | 2009-10-26 11:32:25 +0000 | [diff] [blame] | 290 | clear_reset: |
| 291 | clear_bit(__IGBVF_RESETTING, &adapter->state); |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 292 | return err; |
| 293 | } |
| 294 | |
| 295 | static int igbvf_link_test(struct igbvf_adapter *adapter, u64 *data) |
| 296 | { |
| 297 | struct e1000_hw *hw = &adapter->hw; |
| 298 | *data = 0; |
| 299 | |
| 300 | hw->mac.ops.check_for_link(hw); |
| 301 | |
| 302 | if (!(er32(STATUS) & E1000_STATUS_LU)) |
| 303 | *data = 1; |
| 304 | |
| 305 | return *data; |
| 306 | } |
| 307 | |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 308 | static void igbvf_diag_test(struct net_device *netdev, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 309 | struct ethtool_test *eth_test, u64 *data) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 310 | { |
| 311 | struct igbvf_adapter *adapter = netdev_priv(netdev); |
| 312 | |
| 313 | set_bit(__IGBVF_TESTING, &adapter->state); |
| 314 | |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 315 | /* Link test performed before hardware reset so autoneg doesn't |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 316 | * interfere with test result |
| 317 | */ |
| 318 | if (igbvf_link_test(adapter, &data[0])) |
| 319 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 320 | |
| 321 | clear_bit(__IGBVF_TESTING, &adapter->state); |
| 322 | msleep_interruptible(4 * 1000); |
| 323 | } |
| 324 | |
| 325 | static void igbvf_get_wol(struct net_device *netdev, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 326 | struct ethtool_wolinfo *wol) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 327 | { |
| 328 | wol->supported = 0; |
| 329 | wol->wolopts = 0; |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | static int igbvf_set_wol(struct net_device *netdev, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 333 | struct ethtool_wolinfo *wol) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 334 | { |
| 335 | return -EOPNOTSUPP; |
| 336 | } |
| 337 | |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 338 | static int igbvf_get_coalesce(struct net_device *netdev, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 339 | struct ethtool_coalesce *ec) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 340 | { |
| 341 | struct igbvf_adapter *adapter = netdev_priv(netdev); |
| 342 | |
Mitch A Williams | ab50a2a | 2012-01-14 08:10:50 +0000 | [diff] [blame] | 343 | if (adapter->requested_itr <= 3) |
| 344 | ec->rx_coalesce_usecs = adapter->requested_itr; |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 345 | else |
Mitch A Williams | ab50a2a | 2012-01-14 08:10:50 +0000 | [diff] [blame] | 346 | ec->rx_coalesce_usecs = adapter->current_itr >> 2; |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 347 | |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | static int igbvf_set_coalesce(struct net_device *netdev, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 352 | struct ethtool_coalesce *ec) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 353 | { |
| 354 | struct igbvf_adapter *adapter = netdev_priv(netdev); |
| 355 | struct e1000_hw *hw = &adapter->hw; |
| 356 | |
Mitch A Williams | 0e90b49 | 2012-06-30 00:23:19 +0000 | [diff] [blame] | 357 | if ((ec->rx_coalesce_usecs >= IGBVF_MIN_ITR_USECS) && |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 358 | (ec->rx_coalesce_usecs <= IGBVF_MAX_ITR_USECS)) { |
Mitch A Williams | ab50a2a | 2012-01-14 08:10:50 +0000 | [diff] [blame] | 359 | adapter->current_itr = ec->rx_coalesce_usecs << 2; |
| 360 | adapter->requested_itr = 1000000000 / |
| 361 | (adapter->current_itr * 256); |
Mitch A Williams | 0e90b49 | 2012-06-30 00:23:19 +0000 | [diff] [blame] | 362 | } else if ((ec->rx_coalesce_usecs == 3) || |
| 363 | (ec->rx_coalesce_usecs == 2)) { |
| 364 | adapter->current_itr = IGBVF_START_ITR; |
| 365 | adapter->requested_itr = ec->rx_coalesce_usecs; |
| 366 | } else if (ec->rx_coalesce_usecs == 0) { |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 367 | /* The user's desire is to turn off interrupt throttling |
Mitch A Williams | 0e90b49 | 2012-06-30 00:23:19 +0000 | [diff] [blame] | 368 | * altogether, but due to HW limitations, we can't do that. |
| 369 | * Instead we set a very small value in EITR, which would |
| 370 | * allow ~967k interrupts per second, but allow the adapter's |
| 371 | * internal clocking to still function properly. |
| 372 | */ |
| 373 | adapter->current_itr = 4; |
| 374 | adapter->requested_itr = 1000000000 / |
| 375 | (adapter->current_itr * 256); |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 376 | } else { |
Mitch A Williams | 0e90b49 | 2012-06-30 00:23:19 +0000 | [diff] [blame] | 377 | return -EINVAL; |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 378 | } |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 379 | |
Mitch A Williams | ab50a2a | 2012-01-14 08:10:50 +0000 | [diff] [blame] | 380 | writel(adapter->current_itr, |
| 381 | hw->hw_addr + adapter->rx_ring->itr_register); |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | static int igbvf_nway_reset(struct net_device *netdev) |
| 387 | { |
| 388 | struct igbvf_adapter *adapter = netdev_priv(netdev); |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 389 | |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 390 | if (netif_running(netdev)) |
| 391 | igbvf_reinit_locked(adapter); |
| 392 | return 0; |
| 393 | } |
| 394 | |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 395 | static void igbvf_get_ethtool_stats(struct net_device *netdev, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 396 | struct ethtool_stats *stats, |
| 397 | u64 *data) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 398 | { |
| 399 | struct igbvf_adapter *adapter = netdev_priv(netdev); |
| 400 | int i; |
| 401 | |
| 402 | igbvf_update_stats(adapter); |
| 403 | for (i = 0; i < IGBVF_GLOBAL_STATS_LEN; i++) { |
| 404 | char *p = (char *)adapter + |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 405 | igbvf_gstrings_stats[i].stat_offset; |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 406 | char *b = (char *)adapter + |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 407 | igbvf_gstrings_stats[i].base_stat_offset; |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 408 | data[i] = ((igbvf_gstrings_stats[i].sizeof_stat == |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 409 | sizeof(u64)) ? (*(u64 *)p - *(u64 *)b) : |
| 410 | (*(u32 *)p - *(u32 *)b)); |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 411 | } |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 414 | static int igbvf_get_sset_count(struct net_device *dev, int stringset) |
| 415 | { |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 416 | switch (stringset) { |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 417 | case ETH_SS_TEST: |
| 418 | return IGBVF_TEST_LEN; |
| 419 | case ETH_SS_STATS: |
| 420 | return IGBVF_GLOBAL_STATS_LEN; |
| 421 | default: |
| 422 | return -EINVAL; |
| 423 | } |
| 424 | } |
| 425 | |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 426 | static void igbvf_get_strings(struct net_device *netdev, u32 stringset, |
Jeff Kirsher | 0340501 | 2015-01-21 09:57:50 +0000 | [diff] [blame^] | 427 | u8 *data) |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 428 | { |
| 429 | u8 *p = data; |
| 430 | int i; |
| 431 | |
| 432 | switch (stringset) { |
| 433 | case ETH_SS_TEST: |
| 434 | memcpy(data, *igbvf_gstrings_test, sizeof(igbvf_gstrings_test)); |
| 435 | break; |
| 436 | case ETH_SS_STATS: |
| 437 | for (i = 0; i < IGBVF_GLOBAL_STATS_LEN; i++) { |
| 438 | memcpy(p, igbvf_gstrings_stats[i].stat_string, |
| 439 | ETH_GSTRING_LEN); |
| 440 | p += ETH_GSTRING_LEN; |
| 441 | } |
| 442 | break; |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | static const struct ethtool_ops igbvf_ethtool_ops = { |
| 447 | .get_settings = igbvf_get_settings, |
| 448 | .set_settings = igbvf_set_settings, |
| 449 | .get_drvinfo = igbvf_get_drvinfo, |
| 450 | .get_regs_len = igbvf_get_regs_len, |
| 451 | .get_regs = igbvf_get_regs, |
| 452 | .get_wol = igbvf_get_wol, |
| 453 | .set_wol = igbvf_set_wol, |
| 454 | .get_msglevel = igbvf_get_msglevel, |
| 455 | .set_msglevel = igbvf_set_msglevel, |
| 456 | .nway_reset = igbvf_nway_reset, |
Ben Hutchings | ed4ba4b | 2010-12-09 12:10:25 +0000 | [diff] [blame] | 457 | .get_link = ethtool_op_get_link, |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 458 | .get_eeprom_len = igbvf_get_eeprom_len, |
| 459 | .get_eeprom = igbvf_get_eeprom, |
| 460 | .set_eeprom = igbvf_set_eeprom, |
| 461 | .get_ringparam = igbvf_get_ringparam, |
| 462 | .set_ringparam = igbvf_set_ringparam, |
| 463 | .get_pauseparam = igbvf_get_pauseparam, |
| 464 | .set_pauseparam = igbvf_set_pauseparam, |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 465 | .self_test = igbvf_diag_test, |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 466 | .get_sset_count = igbvf_get_sset_count, |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 467 | .get_strings = igbvf_get_strings, |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 468 | .get_ethtool_stats = igbvf_get_ethtool_stats, |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 469 | .get_coalesce = igbvf_get_coalesce, |
| 470 | .set_coalesce = igbvf_set_coalesce, |
| 471 | }; |
| 472 | |
| 473 | void igbvf_set_ethtool_ops(struct net_device *netdev) |
| 474 | { |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 475 | netdev->ethtool_ops = &igbvf_ethtool_ops; |
Alexander Duyck | d4e0fe0 | 2009-04-07 14:37:34 +0000 | [diff] [blame] | 476 | } |