blob: a127688e83e64c244e0c381e5e11f4748d2d4d42 [file] [log] [blame]
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00001/*******************************************************************************
2
3 Intel(R) 82576 Virtual Function Linux driver
Mitch A Williams2a06ed92012-01-17 04:09:05 +00004 Copyright(c) 2009 - 2012 Intel Corporation.
Alexander Duyckd4e0fe02009-04-07 14:37:34 +00005
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 Kirsher03405012015-01-21 09:57:50 +000016 this program; if not, see <http://www.gnu.org/licenses/>.
Alexander Duyckd4e0fe02009-04-07 14:37:34 +000017
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 Duyckd4e0fe02009-04-07 14:37:34 +000038struct 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
50static 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
68static 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
Philippe Reynes1120ecd2017-02-05 23:55:19 +010074static int igbvf_get_link_ksettings(struct net_device *netdev,
75 struct ethtool_link_ksettings *cmd)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +000076{
77 struct igbvf_adapter *adapter = netdev_priv(netdev);
78 struct e1000_hw *hw = &adapter->hw;
79 u32 status;
80
Philippe Reynes1120ecd2017-02-05 23:55:19 +010081 ethtool_link_ksettings_zero_link_mode(cmd, supported);
82 ethtool_link_ksettings_add_link_mode(cmd, supported, 1000baseT_Full);
83 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
84 ethtool_link_ksettings_add_link_mode(cmd, advertising, 1000baseT_Full);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +000085
Philippe Reynes1120ecd2017-02-05 23:55:19 +010086 cmd->base.port = -1;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +000087
88 status = er32(STATUS);
89 if (status & E1000_STATUS_LU) {
90 if (status & E1000_STATUS_SPEED_1000)
Philippe Reynes1120ecd2017-02-05 23:55:19 +010091 cmd->base.speed = SPEED_1000;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +000092 else if (status & E1000_STATUS_SPEED_100)
Philippe Reynes1120ecd2017-02-05 23:55:19 +010093 cmd->base.speed = SPEED_100;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +000094 else
Philippe Reynes1120ecd2017-02-05 23:55:19 +010095 cmd->base.speed = SPEED_10;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +000096
97 if (status & E1000_STATUS_FD)
Philippe Reynes1120ecd2017-02-05 23:55:19 +010098 cmd->base.duplex = DUPLEX_FULL;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +000099 else
Philippe Reynes1120ecd2017-02-05 23:55:19 +0100100 cmd->base.duplex = DUPLEX_HALF;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000101 } else {
Philippe Reynes1120ecd2017-02-05 23:55:19 +0100102 cmd->base.speed = SPEED_UNKNOWN;
103 cmd->base.duplex = DUPLEX_UNKNOWN;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000104 }
105
Philippe Reynes1120ecd2017-02-05 23:55:19 +0100106 cmd->base.autoneg = AUTONEG_DISABLE;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000107
108 return 0;
109}
110
Philippe Reynes1120ecd2017-02-05 23:55:19 +0100111static int igbvf_set_link_ksettings(struct net_device *netdev,
112 const struct ethtool_link_ksettings *cmd)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000113{
114 return -EOPNOTSUPP;
115}
116
117static void igbvf_get_pauseparam(struct net_device *netdev,
Jeff Kirsher03405012015-01-21 09:57:50 +0000118 struct ethtool_pauseparam *pause)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000119{
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000120}
121
122static int igbvf_set_pauseparam(struct net_device *netdev,
Jeff Kirsher03405012015-01-21 09:57:50 +0000123 struct ethtool_pauseparam *pause)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000124{
125 return -EOPNOTSUPP;
126}
127
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000128static u32 igbvf_get_msglevel(struct net_device *netdev)
129{
130 struct igbvf_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher03405012015-01-21 09:57:50 +0000131
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000132 return adapter->msg_enable;
133}
134
135static void igbvf_set_msglevel(struct net_device *netdev, u32 data)
136{
137 struct igbvf_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher03405012015-01-21 09:57:50 +0000138
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000139 adapter->msg_enable = data;
140}
141
142static 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
148static void igbvf_get_regs(struct net_device *netdev,
Jeff Kirsher03405012015-01-21 09:57:50 +0000149 struct ethtool_regs *regs, void *p)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000150{
151 struct igbvf_adapter *adapter = netdev_priv(netdev);
152 struct e1000_hw *hw = &adapter->hw;
153 u32 *regs_buff = p;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000154
155 memset(p, 0, IGBVF_REGS_LEN * sizeof(u32));
156
Jacob Keller0ed2dbf2016-04-13 16:08:31 -0700157 regs->version = (1u << 24) |
158 (adapter->pdev->revision << 16) |
Sergei Shtylyovff938e42011-02-28 11:57:33 -0800159 adapter->pdev->device;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000160
161 regs_buff[0] = er32(CTRL);
162 regs_buff[1] = er32(STATUS);
163
164 regs_buff[2] = er32(RDLEN(0));
165 regs_buff[3] = er32(RDH(0));
166 regs_buff[4] = er32(RDT(0));
167
168 regs_buff[5] = er32(TDLEN(0));
169 regs_buff[6] = er32(TDH(0));
170 regs_buff[7] = er32(TDT(0));
171}
172
173static int igbvf_get_eeprom_len(struct net_device *netdev)
174{
175 return 0;
176}
177
178static int igbvf_get_eeprom(struct net_device *netdev,
Jeff Kirsher03405012015-01-21 09:57:50 +0000179 struct ethtool_eeprom *eeprom, u8 *bytes)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000180{
181 return -EOPNOTSUPP;
182}
183
184static int igbvf_set_eeprom(struct net_device *netdev,
Jeff Kirsher03405012015-01-21 09:57:50 +0000185 struct ethtool_eeprom *eeprom, u8 *bytes)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000186{
187 return -EOPNOTSUPP;
188}
189
190static void igbvf_get_drvinfo(struct net_device *netdev,
Jeff Kirsher03405012015-01-21 09:57:50 +0000191 struct ethtool_drvinfo *drvinfo)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000192{
193 struct igbvf_adapter *adapter = netdev_priv(netdev);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000194
Rick Jones612a94d2011-11-14 08:13:25 +0000195 strlcpy(drvinfo->driver, igbvf_driver_name, sizeof(drvinfo->driver));
196 strlcpy(drvinfo->version, igbvf_driver_version,
197 sizeof(drvinfo->version));
Rick Jones612a94d2011-11-14 08:13:25 +0000198 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
199 sizeof(drvinfo->bus_info));
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000200}
201
202static void igbvf_get_ringparam(struct net_device *netdev,
Jeff Kirsher03405012015-01-21 09:57:50 +0000203 struct ethtool_ringparam *ring)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000204{
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;
208
209 ring->rx_max_pending = IGBVF_MAX_RXD;
210 ring->tx_max_pending = IGBVF_MAX_TXD;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000211 ring->rx_pending = rx_ring->count;
212 ring->tx_pending = tx_ring->count;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000213}
214
215static int igbvf_set_ringparam(struct net_device *netdev,
Jeff Kirsher03405012015-01-21 09:57:50 +0000216 struct ethtool_ringparam *ring)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000217{
218 struct igbvf_adapter *adapter = netdev_priv(netdev);
219 struct igbvf_ring *temp_ring;
Alexander Duyck39305962009-10-26 11:32:25 +0000220 int err = 0;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000221 u32 new_rx_count, new_tx_count;
222
223 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
224 return -EINVAL;
225
Jeff Kirsher5beef762015-02-20 20:55:56 -0800226 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);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000228 new_rx_count = ALIGN(new_rx_count, REQ_RX_DESCRIPTOR_MULTIPLE);
229
Jeff Kirsher5beef762015-02-20 20:55:56 -0800230 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);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000232 new_tx_count = ALIGN(new_tx_count, REQ_TX_DESCRIPTOR_MULTIPLE);
233
234 if ((new_tx_count == adapter->tx_ring->count) &&
235 (new_rx_count == adapter->rx_ring->count)) {
236 /* nothing to do */
237 return 0;
238 }
239
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000240 while (test_and_set_bit(__IGBVF_RESETTING, &adapter->state))
Jeff Kirsher5beef762015-02-20 20:55:56 -0800241 usleep_range(1000, 2000);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000242
Alexander Duyck39305962009-10-26 11:32:25 +0000243 if (!netif_running(adapter->netdev)) {
244 adapter->tx_ring->count = new_tx_count;
245 adapter->rx_ring->count = new_rx_count;
246 goto clear_reset;
247 }
248
249 temp_ring = vmalloc(sizeof(struct igbvf_ring));
250 if (!temp_ring) {
251 err = -ENOMEM;
252 goto clear_reset;
253 }
254
255 igbvf_down(adapter);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000256
Jeff Kirsher03405012015-01-21 09:57:50 +0000257 /* We can't just free everything and then setup again,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000258 * because the ISRs in MSI-X mode get passed pointers
Jeff Kirsher03405012015-01-21 09:57:50 +0000259 * to the Tx and Rx ring structs.
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000260 */
261 if (new_tx_count != adapter->tx_ring->count) {
262 memcpy(temp_ring, adapter->tx_ring, sizeof(struct igbvf_ring));
263
264 temp_ring->count = new_tx_count;
265 err = igbvf_setup_tx_resources(adapter, temp_ring);
266 if (err)
267 goto err_setup;
268
269 igbvf_free_tx_resources(adapter->tx_ring);
270
271 memcpy(adapter->tx_ring, temp_ring, sizeof(struct igbvf_ring));
272 }
273
274 if (new_rx_count != adapter->rx_ring->count) {
275 memcpy(temp_ring, adapter->rx_ring, sizeof(struct igbvf_ring));
276
277 temp_ring->count = new_rx_count;
278 err = igbvf_setup_rx_resources(adapter, temp_ring);
279 if (err)
280 goto err_setup;
281
282 igbvf_free_rx_resources(adapter->rx_ring);
283
Jeff Kirsher03405012015-01-21 09:57:50 +0000284 memcpy(adapter->rx_ring, temp_ring, sizeof(struct igbvf_ring));
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000285 }
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000286err_setup:
Alexander Duyck39305962009-10-26 11:32:25 +0000287 igbvf_up(adapter);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000288 vfree(temp_ring);
Alexander Duyck39305962009-10-26 11:32:25 +0000289clear_reset:
290 clear_bit(__IGBVF_RESETTING, &adapter->state);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000291 return err;
292}
293
294static int igbvf_link_test(struct igbvf_adapter *adapter, u64 *data)
295{
296 struct e1000_hw *hw = &adapter->hw;
297 *data = 0;
298
Greg Edwards32652c22017-07-20 10:00:57 -0600299 spin_lock_bh(&hw->mbx_lock);
300
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000301 hw->mac.ops.check_for_link(hw);
302
Greg Edwards32652c22017-07-20 10:00:57 -0600303 spin_unlock_bh(&hw->mbx_lock);
304
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000305 if (!(er32(STATUS) & E1000_STATUS_LU))
306 *data = 1;
307
308 return *data;
309}
310
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000311static void igbvf_diag_test(struct net_device *netdev,
Jeff Kirsher03405012015-01-21 09:57:50 +0000312 struct ethtool_test *eth_test, u64 *data)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000313{
314 struct igbvf_adapter *adapter = netdev_priv(netdev);
315
316 set_bit(__IGBVF_TESTING, &adapter->state);
317
Jeff Kirsher03405012015-01-21 09:57:50 +0000318 /* Link test performed before hardware reset so autoneg doesn't
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000319 * interfere with test result
320 */
321 if (igbvf_link_test(adapter, &data[0]))
322 eth_test->flags |= ETH_TEST_FL_FAILED;
323
324 clear_bit(__IGBVF_TESTING, &adapter->state);
325 msleep_interruptible(4 * 1000);
326}
327
328static void igbvf_get_wol(struct net_device *netdev,
Jeff Kirsher03405012015-01-21 09:57:50 +0000329 struct ethtool_wolinfo *wol)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000330{
331 wol->supported = 0;
332 wol->wolopts = 0;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000333}
334
335static int igbvf_set_wol(struct net_device *netdev,
Jeff Kirsher03405012015-01-21 09:57:50 +0000336 struct ethtool_wolinfo *wol)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000337{
338 return -EOPNOTSUPP;
339}
340
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000341static int igbvf_get_coalesce(struct net_device *netdev,
Jeff Kirsher03405012015-01-21 09:57:50 +0000342 struct ethtool_coalesce *ec)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000343{
344 struct igbvf_adapter *adapter = netdev_priv(netdev);
345
Mitch A Williamsab50a2a2012-01-14 08:10:50 +0000346 if (adapter->requested_itr <= 3)
347 ec->rx_coalesce_usecs = adapter->requested_itr;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000348 else
Mitch A Williamsab50a2a2012-01-14 08:10:50 +0000349 ec->rx_coalesce_usecs = adapter->current_itr >> 2;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000350
351 return 0;
352}
353
354static int igbvf_set_coalesce(struct net_device *netdev,
Jeff Kirsher03405012015-01-21 09:57:50 +0000355 struct ethtool_coalesce *ec)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000356{
357 struct igbvf_adapter *adapter = netdev_priv(netdev);
358 struct e1000_hw *hw = &adapter->hw;
359
Mitch A Williams0e90b492012-06-30 00:23:19 +0000360 if ((ec->rx_coalesce_usecs >= IGBVF_MIN_ITR_USECS) &&
Jeff Kirsher03405012015-01-21 09:57:50 +0000361 (ec->rx_coalesce_usecs <= IGBVF_MAX_ITR_USECS)) {
Mitch A Williamsab50a2a2012-01-14 08:10:50 +0000362 adapter->current_itr = ec->rx_coalesce_usecs << 2;
363 adapter->requested_itr = 1000000000 /
364 (adapter->current_itr * 256);
Mitch A Williams0e90b492012-06-30 00:23:19 +0000365 } else if ((ec->rx_coalesce_usecs == 3) ||
366 (ec->rx_coalesce_usecs == 2)) {
367 adapter->current_itr = IGBVF_START_ITR;
368 adapter->requested_itr = ec->rx_coalesce_usecs;
369 } else if (ec->rx_coalesce_usecs == 0) {
Jeff Kirsher03405012015-01-21 09:57:50 +0000370 /* The user's desire is to turn off interrupt throttling
Mitch A Williams0e90b492012-06-30 00:23:19 +0000371 * altogether, but due to HW limitations, we can't do that.
372 * Instead we set a very small value in EITR, which would
373 * allow ~967k interrupts per second, but allow the adapter's
374 * internal clocking to still function properly.
375 */
376 adapter->current_itr = 4;
377 adapter->requested_itr = 1000000000 /
378 (adapter->current_itr * 256);
Jeff Kirsher03405012015-01-21 09:57:50 +0000379 } else {
Mitch A Williams0e90b492012-06-30 00:23:19 +0000380 return -EINVAL;
Jeff Kirsher03405012015-01-21 09:57:50 +0000381 }
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000382
Mitch A Williamsab50a2a2012-01-14 08:10:50 +0000383 writel(adapter->current_itr,
384 hw->hw_addr + adapter->rx_ring->itr_register);
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000385
386 return 0;
387}
388
389static int igbvf_nway_reset(struct net_device *netdev)
390{
391 struct igbvf_adapter *adapter = netdev_priv(netdev);
Jeff Kirsher03405012015-01-21 09:57:50 +0000392
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000393 if (netif_running(netdev))
394 igbvf_reinit_locked(adapter);
395 return 0;
396}
397
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000398static void igbvf_get_ethtool_stats(struct net_device *netdev,
Jeff Kirsher03405012015-01-21 09:57:50 +0000399 struct ethtool_stats *stats,
400 u64 *data)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000401{
402 struct igbvf_adapter *adapter = netdev_priv(netdev);
403 int i;
404
405 igbvf_update_stats(adapter);
406 for (i = 0; i < IGBVF_GLOBAL_STATS_LEN; i++) {
407 char *p = (char *)adapter +
Jeff Kirsher03405012015-01-21 09:57:50 +0000408 igbvf_gstrings_stats[i].stat_offset;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000409 char *b = (char *)adapter +
Jeff Kirsher03405012015-01-21 09:57:50 +0000410 igbvf_gstrings_stats[i].base_stat_offset;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000411 data[i] = ((igbvf_gstrings_stats[i].sizeof_stat ==
Jeff Kirsher03405012015-01-21 09:57:50 +0000412 sizeof(u64)) ? (*(u64 *)p - *(u64 *)b) :
413 (*(u32 *)p - *(u32 *)b));
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000414 }
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000415}
416
Ben Hutchings15f0a392009-10-01 11:58:24 +0000417static int igbvf_get_sset_count(struct net_device *dev, int stringset)
418{
Jeff Kirsher03405012015-01-21 09:57:50 +0000419 switch (stringset) {
Ben Hutchings15f0a392009-10-01 11:58:24 +0000420 case ETH_SS_TEST:
421 return IGBVF_TEST_LEN;
422 case ETH_SS_STATS:
423 return IGBVF_GLOBAL_STATS_LEN;
424 default:
425 return -EINVAL;
426 }
427}
428
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000429static void igbvf_get_strings(struct net_device *netdev, u32 stringset,
Jeff Kirsher03405012015-01-21 09:57:50 +0000430 u8 *data)
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000431{
432 u8 *p = data;
433 int i;
434
435 switch (stringset) {
436 case ETH_SS_TEST:
437 memcpy(data, *igbvf_gstrings_test, sizeof(igbvf_gstrings_test));
438 break;
439 case ETH_SS_STATS:
440 for (i = 0; i < IGBVF_GLOBAL_STATS_LEN; i++) {
441 memcpy(p, igbvf_gstrings_stats[i].stat_string,
442 ETH_GSTRING_LEN);
443 p += ETH_GSTRING_LEN;
444 }
445 break;
446 }
447}
448
449static const struct ethtool_ops igbvf_ethtool_ops = {
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000450 .get_drvinfo = igbvf_get_drvinfo,
451 .get_regs_len = igbvf_get_regs_len,
452 .get_regs = igbvf_get_regs,
453 .get_wol = igbvf_get_wol,
454 .set_wol = igbvf_set_wol,
455 .get_msglevel = igbvf_get_msglevel,
456 .set_msglevel = igbvf_set_msglevel,
457 .nway_reset = igbvf_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +0000458 .get_link = ethtool_op_get_link,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000459 .get_eeprom_len = igbvf_get_eeprom_len,
460 .get_eeprom = igbvf_get_eeprom,
461 .set_eeprom = igbvf_set_eeprom,
462 .get_ringparam = igbvf_get_ringparam,
463 .set_ringparam = igbvf_set_ringparam,
464 .get_pauseparam = igbvf_get_pauseparam,
465 .set_pauseparam = igbvf_set_pauseparam,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000466 .self_test = igbvf_diag_test,
Ben Hutchings15f0a392009-10-01 11:58:24 +0000467 .get_sset_count = igbvf_get_sset_count,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000468 .get_strings = igbvf_get_strings,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000469 .get_ethtool_stats = igbvf_get_ethtool_stats,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000470 .get_coalesce = igbvf_get_coalesce,
471 .set_coalesce = igbvf_set_coalesce,
Philippe Reynes1120ecd2017-02-05 23:55:19 +0100472 .get_link_ksettings = igbvf_get_link_ksettings,
473 .set_link_ksettings = igbvf_set_link_ksettings,
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000474};
475
476void igbvf_set_ethtool_ops(struct net_device *netdev)
477{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +0000478 netdev->ethtool_ops = &igbvf_ethtool_ops;
Alexander Duyckd4e0fe02009-04-07 14:37:34 +0000479}