1 /*******************************************************************************
3 Intel(R) 82576 Virtual Function Linux driver
4 Copyright(c) 2009 - 2012 Intel Corporation.
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.
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
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, see <http://www.gnu.org/licenses/>.
18 The full GNU General Public License is included in this distribution in
19 the file called "COPYING".
22 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *******************************************************************************/
27 /* ethtool support for igbvf */
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>
36 #include <linux/if_vlan.h>
39 char stat_string[ETH_GSTRING_LEN];
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)
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) },
66 #define IGBVF_GLOBAL_STATS_LEN ARRAY_SIZE(igbvf_gstrings_stats)
68 static const char igbvf_gstrings_test[][ETH_GSTRING_LEN] = {
69 "Link test (on/offline)"
72 #define IGBVF_TEST_LEN ARRAY_SIZE(igbvf_gstrings_test)
74 static int igbvf_get_settings(struct net_device *netdev,
75 struct ethtool_cmd *ecmd)
77 struct igbvf_adapter *adapter = netdev_priv(netdev);
78 struct e1000_hw *hw = &adapter->hw;
81 ecmd->supported = SUPPORTED_1000baseT_Full;
83 ecmd->advertising = ADVERTISED_1000baseT_Full;
86 ecmd->transceiver = XCVR_DUMMY1;
88 status = er32(STATUS);
89 if (status & E1000_STATUS_LU) {
90 if (status & E1000_STATUS_SPEED_1000)
91 ethtool_cmd_speed_set(ecmd, SPEED_1000);
92 else if (status & E1000_STATUS_SPEED_100)
93 ethtool_cmd_speed_set(ecmd, SPEED_100);
95 ethtool_cmd_speed_set(ecmd, SPEED_10);
97 if (status & E1000_STATUS_FD)
98 ecmd->duplex = DUPLEX_FULL;
100 ecmd->duplex = DUPLEX_HALF;
102 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
103 ecmd->duplex = DUPLEX_UNKNOWN;
106 ecmd->autoneg = AUTONEG_DISABLE;
111 static int igbvf_set_settings(struct net_device *netdev,
112 struct ethtool_cmd *ecmd)
117 static void igbvf_get_pauseparam(struct net_device *netdev,
118 struct ethtool_pauseparam *pause)
122 static int igbvf_set_pauseparam(struct net_device *netdev,
123 struct ethtool_pauseparam *pause)
128 static u32 igbvf_get_msglevel(struct net_device *netdev)
130 struct igbvf_adapter *adapter = netdev_priv(netdev);
132 return adapter->msg_enable;
135 static void igbvf_set_msglevel(struct net_device *netdev, u32 data)
137 struct igbvf_adapter *adapter = netdev_priv(netdev);
139 adapter->msg_enable = data;
142 static int igbvf_get_regs_len(struct net_device *netdev)
144 #define IGBVF_REGS_LEN 8
145 return IGBVF_REGS_LEN * sizeof(u32);
148 static void igbvf_get_regs(struct net_device *netdev,
149 struct ethtool_regs *regs, void *p)
151 struct igbvf_adapter *adapter = netdev_priv(netdev);
152 struct e1000_hw *hw = &adapter->hw;
155 memset(p, 0, IGBVF_REGS_LEN * sizeof(u32));
157 regs->version = (1u << 24) |
158 (adapter->pdev->revision << 16) |
159 adapter->pdev->device;
161 regs_buff[0] = er32(CTRL);
162 regs_buff[1] = er32(STATUS);
164 regs_buff[2] = er32(RDLEN(0));
165 regs_buff[3] = er32(RDH(0));
166 regs_buff[4] = er32(RDT(0));
168 regs_buff[5] = er32(TDLEN(0));
169 regs_buff[6] = er32(TDH(0));
170 regs_buff[7] = er32(TDT(0));
173 static int igbvf_get_eeprom_len(struct net_device *netdev)
178 static int igbvf_get_eeprom(struct net_device *netdev,
179 struct ethtool_eeprom *eeprom, u8 *bytes)
184 static int igbvf_set_eeprom(struct net_device *netdev,
185 struct ethtool_eeprom *eeprom, u8 *bytes)
190 static void igbvf_get_drvinfo(struct net_device *netdev,
191 struct ethtool_drvinfo *drvinfo)
193 struct igbvf_adapter *adapter = netdev_priv(netdev);
195 strlcpy(drvinfo->driver, igbvf_driver_name, sizeof(drvinfo->driver));
196 strlcpy(drvinfo->version, igbvf_driver_version,
197 sizeof(drvinfo->version));
198 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
199 sizeof(drvinfo->bus_info));
202 static void igbvf_get_ringparam(struct net_device *netdev,
203 struct ethtool_ringparam *ring)
205 struct igbvf_adapter *adapter = netdev_priv(netdev);
206 struct igbvf_ring *tx_ring = adapter->tx_ring;
207 struct igbvf_ring *rx_ring = adapter->rx_ring;
209 ring->rx_max_pending = IGBVF_MAX_RXD;
210 ring->tx_max_pending = IGBVF_MAX_TXD;
211 ring->rx_pending = rx_ring->count;
212 ring->tx_pending = tx_ring->count;
215 static int igbvf_set_ringparam(struct net_device *netdev,
216 struct ethtool_ringparam *ring)
218 struct igbvf_adapter *adapter = netdev_priv(netdev);
219 struct igbvf_ring *temp_ring;
221 u32 new_rx_count, new_tx_count;
223 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
226 new_rx_count = max_t(u32, ring->rx_pending, IGBVF_MIN_RXD);
227 new_rx_count = min_t(u32, new_rx_count, IGBVF_MAX_RXD);
228 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
230 new_tx_count = max_t(u32, ring->tx_pending, IGBVF_MIN_TXD);
231 new_tx_count = min_t(u32, new_tx_count, IGBVF_MAX_TXD);
232 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
234 if ((new_tx_count == adapter->tx_ring->count) &&
235 (new_rx_count == adapter->rx_ring->count)) {
240 while (test_and_set_bit(__IGBVF_RESETTING, &adapter->state))
241 usleep_range(1000, 2000);
243 if (!netif_running(adapter->netdev)) {
244 adapter->tx_ring->count = new_tx_count;
245 adapter->rx_ring->count = new_rx_count;
249 temp_ring = vmalloc(sizeof(struct igbvf_ring));
257 /* We can't just free everything and then setup again,
258 * because the ISRs in MSI-X mode get passed pointers
259 * to the Tx and Rx ring structs.
261 if (new_tx_count != adapter->tx_ring->count) {
262 memcpy(temp_ring, adapter->tx_ring, sizeof(struct igbvf_ring));
264 temp_ring->count = new_tx_count;
265 err = igbvf_setup_tx_resources(adapter, temp_ring);
269 igbvf_free_tx_resources(adapter->tx_ring);
271 memcpy(adapter->tx_ring, temp_ring, sizeof(struct igbvf_ring));
274 if (new_rx_count != adapter->rx_ring->count) {
275 memcpy(temp_ring, adapter->rx_ring, sizeof(struct igbvf_ring));
277 temp_ring->count = new_rx_count;
278 err = igbvf_setup_rx_resources(adapter, temp_ring);
282 igbvf_free_rx_resources(adapter->rx_ring);
284 memcpy(adapter->rx_ring, temp_ring, sizeof(struct igbvf_ring));
290 clear_bit(__IGBVF_RESETTING, &adapter->state);
294 static int igbvf_link_test(struct igbvf_adapter *adapter, u64 *data)
296 struct e1000_hw *hw = &adapter->hw;
299 hw->mac.ops.check_for_link(hw);
301 if (!(er32(STATUS) & E1000_STATUS_LU))
307 static void igbvf_diag_test(struct net_device *netdev,
308 struct ethtool_test *eth_test, u64 *data)
310 struct igbvf_adapter *adapter = netdev_priv(netdev);
312 set_bit(__IGBVF_TESTING, &adapter->state);
314 /* Link test performed before hardware reset so autoneg doesn't
315 * interfere with test result
317 if (igbvf_link_test(adapter, &data[0]))
318 eth_test->flags |= ETH_TEST_FL_FAILED;
320 clear_bit(__IGBVF_TESTING, &adapter->state);
321 msleep_interruptible(4 * 1000);
324 static void igbvf_get_wol(struct net_device *netdev,
325 struct ethtool_wolinfo *wol)
331 static int igbvf_set_wol(struct net_device *netdev,
332 struct ethtool_wolinfo *wol)
337 static int igbvf_get_coalesce(struct net_device *netdev,
338 struct ethtool_coalesce *ec)
340 struct igbvf_adapter *adapter = netdev_priv(netdev);
342 if (adapter->requested_itr <= 3)
343 ec->rx_coalesce_usecs = adapter->requested_itr;
345 ec->rx_coalesce_usecs = adapter->current_itr >> 2;
350 static int igbvf_set_coalesce(struct net_device *netdev,
351 struct ethtool_coalesce *ec)
353 struct igbvf_adapter *adapter = netdev_priv(netdev);
354 struct e1000_hw *hw = &adapter->hw;
356 if ((ec->rx_coalesce_usecs >= IGBVF_MIN_ITR_USECS) &&
357 (ec->rx_coalesce_usecs <= IGBVF_MAX_ITR_USECS)) {
358 adapter->current_itr = ec->rx_coalesce_usecs << 2;
359 adapter->requested_itr = 1000000000 /
360 (adapter->current_itr * 256);
361 } else if ((ec->rx_coalesce_usecs == 3) ||
362 (ec->rx_coalesce_usecs == 2)) {
363 adapter->current_itr = IGBVF_START_ITR;
364 adapter->requested_itr = ec->rx_coalesce_usecs;
365 } else if (ec->rx_coalesce_usecs == 0) {
366 /* The user's desire is to turn off interrupt throttling
367 * altogether, but due to HW limitations, we can't do that.
368 * Instead we set a very small value in EITR, which would
369 * allow ~967k interrupts per second, but allow the adapter's
370 * internal clocking to still function properly.
372 adapter->current_itr = 4;
373 adapter->requested_itr = 1000000000 /
374 (adapter->current_itr * 256);
379 writel(adapter->current_itr,
380 hw->hw_addr + adapter->rx_ring->itr_register);
385 static int igbvf_nway_reset(struct net_device *netdev)
387 struct igbvf_adapter *adapter = netdev_priv(netdev);
389 if (netif_running(netdev))
390 igbvf_reinit_locked(adapter);
394 static void igbvf_get_ethtool_stats(struct net_device *netdev,
395 struct ethtool_stats *stats,
398 struct igbvf_adapter *adapter = netdev_priv(netdev);
401 igbvf_update_stats(adapter);
402 for (i = 0; i < IGBVF_GLOBAL_STATS_LEN; i++) {
403 char *p = (char *)adapter +
404 igbvf_gstrings_stats[i].stat_offset;
405 char *b = (char *)adapter +
406 igbvf_gstrings_stats[i].base_stat_offset;
407 data[i] = ((igbvf_gstrings_stats[i].sizeof_stat ==
408 sizeof(u64)) ? (*(u64 *)p - *(u64 *)b) :
409 (*(u32 *)p - *(u32 *)b));
413 static int igbvf_get_sset_count(struct net_device *dev, int stringset)
417 return IGBVF_TEST_LEN;
419 return IGBVF_GLOBAL_STATS_LEN;
425 static void igbvf_get_strings(struct net_device *netdev, u32 stringset,
433 memcpy(data, *igbvf_gstrings_test, sizeof(igbvf_gstrings_test));
436 for (i = 0; i < IGBVF_GLOBAL_STATS_LEN; i++) {
437 memcpy(p, igbvf_gstrings_stats[i].stat_string,
439 p += ETH_GSTRING_LEN;
445 static const struct ethtool_ops igbvf_ethtool_ops = {
446 .get_settings = igbvf_get_settings,
447 .set_settings = igbvf_set_settings,
448 .get_drvinfo = igbvf_get_drvinfo,
449 .get_regs_len = igbvf_get_regs_len,
450 .get_regs = igbvf_get_regs,
451 .get_wol = igbvf_get_wol,
452 .set_wol = igbvf_set_wol,
453 .get_msglevel = igbvf_get_msglevel,
454 .set_msglevel = igbvf_set_msglevel,
455 .nway_reset = igbvf_nway_reset,
456 .get_link = ethtool_op_get_link,
457 .get_eeprom_len = igbvf_get_eeprom_len,
458 .get_eeprom = igbvf_get_eeprom,
459 .set_eeprom = igbvf_set_eeprom,
460 .get_ringparam = igbvf_get_ringparam,
461 .set_ringparam = igbvf_set_ringparam,
462 .get_pauseparam = igbvf_get_pauseparam,
463 .set_pauseparam = igbvf_set_pauseparam,
464 .self_test = igbvf_diag_test,
465 .get_sset_count = igbvf_get_sset_count,
466 .get_strings = igbvf_get_strings,
467 .get_ethtool_stats = igbvf_get_ethtool_stats,
468 .get_coalesce = igbvf_get_coalesce,
469 .set_coalesce = igbvf_set_coalesce,
472 void igbvf_set_ethtool_ops(struct net_device *netdev)
474 netdev->ethtool_ops = &igbvf_ethtool_ops;