Linux Audio

Check our new training course

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