1/*
2 * Linux driver for VMware's vmxnet3 ethernet NIC.
3 *
4 * Copyright (C) 2008-2009, VMware, Inc. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; version 2 of the License and no later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT.  See the GNU General Public License for more
14 * details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * The full GNU General Public License is included in this distribution in
21 * the file called "COPYING".
22 *
23 * Maintained by: Shreyas Bhatewara <pv-drivers@vmware.com>
24 *
25 */
26
27
28#include "vmxnet3_int.h"
29
30struct vmxnet3_stat_desc {
31	char desc[ETH_GSTRING_LEN];
32	int  offset;
33};
34
35
36/* per tq stats maintained by the device */
37static const struct vmxnet3_stat_desc
38vmxnet3_tq_dev_stats[] = {
39	/* description,         offset */
40	{ "Tx Queue#",        0 },
41	{ "  TSO pkts tx",	offsetof(struct UPT1_TxStats, TSOPktsTxOK) },
42	{ "  TSO bytes tx",	offsetof(struct UPT1_TxStats, TSOBytesTxOK) },
43	{ "  ucast pkts tx",	offsetof(struct UPT1_TxStats, ucastPktsTxOK) },
44	{ "  ucast bytes tx",	offsetof(struct UPT1_TxStats, ucastBytesTxOK) },
45	{ "  mcast pkts tx",	offsetof(struct UPT1_TxStats, mcastPktsTxOK) },
46	{ "  mcast bytes tx",	offsetof(struct UPT1_TxStats, mcastBytesTxOK) },
47	{ "  bcast pkts tx",	offsetof(struct UPT1_TxStats, bcastPktsTxOK) },
48	{ "  bcast bytes tx",	offsetof(struct UPT1_TxStats, bcastBytesTxOK) },
49	{ "  pkts tx err",	offsetof(struct UPT1_TxStats, pktsTxError) },
50	{ "  pkts tx discard",	offsetof(struct UPT1_TxStats, pktsTxDiscard) },
51};
52
53/* per tq stats maintained by the driver */
54static const struct vmxnet3_stat_desc
55vmxnet3_tq_driver_stats[] = {
56	/* description,         offset */
57	{"  drv dropped tx total",	offsetof(struct vmxnet3_tq_driver_stats,
58						 drop_total) },
59	{ "     too many frags", offsetof(struct vmxnet3_tq_driver_stats,
60					  drop_too_many_frags) },
61	{ "     giant hdr",	offsetof(struct vmxnet3_tq_driver_stats,
62					 drop_oversized_hdr) },
63	{ "     hdr err",	offsetof(struct vmxnet3_tq_driver_stats,
64					 drop_hdr_inspect_err) },
65	{ "     tso",		offsetof(struct vmxnet3_tq_driver_stats,
66					 drop_tso) },
67	{ "  ring full",	offsetof(struct vmxnet3_tq_driver_stats,
68					 tx_ring_full) },
69	{ "  pkts linearized",	offsetof(struct vmxnet3_tq_driver_stats,
70					 linearized) },
71	{ "  hdr cloned",	offsetof(struct vmxnet3_tq_driver_stats,
72					 copy_skb_header) },
73	{ "  giant hdr",	offsetof(struct vmxnet3_tq_driver_stats,
74					 oversized_hdr) },
75};
76
77/* per rq stats maintained by the device */
78static const struct vmxnet3_stat_desc
79vmxnet3_rq_dev_stats[] = {
80	{ "Rx Queue#",        0 },
81	{ "  LRO pkts rx",	offsetof(struct UPT1_RxStats, LROPktsRxOK) },
82	{ "  LRO byte rx",	offsetof(struct UPT1_RxStats, LROBytesRxOK) },
83	{ "  ucast pkts rx",	offsetof(struct UPT1_RxStats, ucastPktsRxOK) },
84	{ "  ucast bytes rx",	offsetof(struct UPT1_RxStats, ucastBytesRxOK) },
85	{ "  mcast pkts rx",	offsetof(struct UPT1_RxStats, mcastPktsRxOK) },
86	{ "  mcast bytes rx",	offsetof(struct UPT1_RxStats, mcastBytesRxOK) },
87	{ "  bcast pkts rx",	offsetof(struct UPT1_RxStats, bcastPktsRxOK) },
88	{ "  bcast bytes rx",	offsetof(struct UPT1_RxStats, bcastBytesRxOK) },
89	{ "  pkts rx OOB",	offsetof(struct UPT1_RxStats, pktsRxOutOfBuf) },
90	{ "  pkts rx err",	offsetof(struct UPT1_RxStats, pktsRxError) },
91};
92
93/* per rq stats maintained by the driver */
94static const struct vmxnet3_stat_desc
95vmxnet3_rq_driver_stats[] = {
96	/* description,         offset */
97	{ "  drv dropped rx total", offsetof(struct vmxnet3_rq_driver_stats,
98					     drop_total) },
99	{ "     err",		offsetof(struct vmxnet3_rq_driver_stats,
100					 drop_err) },
101	{ "     fcs",		offsetof(struct vmxnet3_rq_driver_stats,
102					 drop_fcs) },
103	{ "  rx buf alloc fail", offsetof(struct vmxnet3_rq_driver_stats,
104					  rx_buf_alloc_failure) },
105};
106
107/* global stats maintained by the driver */
108static const struct vmxnet3_stat_desc
109vmxnet3_global_stats[] = {
110	/* description,         offset */
111	{ "tx timeout count",	offsetof(struct vmxnet3_adapter,
112					 tx_timeout_count) }
113};
114
115
116struct rtnl_link_stats64 *
117vmxnet3_get_stats64(struct net_device *netdev,
118		   struct rtnl_link_stats64 *stats)
119{
120	struct vmxnet3_adapter *adapter;
121	struct vmxnet3_tq_driver_stats *drvTxStats;
122	struct vmxnet3_rq_driver_stats *drvRxStats;
123	struct UPT1_TxStats *devTxStats;
124	struct UPT1_RxStats *devRxStats;
125	unsigned long flags;
126	int i;
127
128	adapter = netdev_priv(netdev);
129
130	/* Collect the dev stats into the shared area */
131	spin_lock_irqsave(&adapter->cmd_lock, flags);
132	VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
133	spin_unlock_irqrestore(&adapter->cmd_lock, flags);
134
135	for (i = 0; i < adapter->num_tx_queues; i++) {
136		devTxStats = &adapter->tqd_start[i].stats;
137		drvTxStats = &adapter->tx_queue[i].stats;
138		stats->tx_packets += devTxStats->ucastPktsTxOK +
139				     devTxStats->mcastPktsTxOK +
140				     devTxStats->bcastPktsTxOK;
141		stats->tx_bytes += devTxStats->ucastBytesTxOK +
142				   devTxStats->mcastBytesTxOK +
143				   devTxStats->bcastBytesTxOK;
144		stats->tx_errors += devTxStats->pktsTxError;
145		stats->tx_dropped += drvTxStats->drop_total;
146	}
147
148	for (i = 0; i < adapter->num_rx_queues; i++) {
149		devRxStats = &adapter->rqd_start[i].stats;
150		drvRxStats = &adapter->rx_queue[i].stats;
151		stats->rx_packets += devRxStats->ucastPktsRxOK +
152				     devRxStats->mcastPktsRxOK +
153				     devRxStats->bcastPktsRxOK;
154
155		stats->rx_bytes += devRxStats->ucastBytesRxOK +
156				   devRxStats->mcastBytesRxOK +
157				   devRxStats->bcastBytesRxOK;
158
159		stats->rx_errors += devRxStats->pktsRxError;
160		stats->rx_dropped += drvRxStats->drop_total;
161		stats->multicast +=  devRxStats->mcastPktsRxOK;
162	}
163
164	return stats;
165}
166
167static int
168vmxnet3_get_sset_count(struct net_device *netdev, int sset)
169{
170	struct vmxnet3_adapter *adapter = netdev_priv(netdev);
171	switch (sset) {
172	case ETH_SS_STATS:
173		return (ARRAY_SIZE(vmxnet3_tq_dev_stats) +
174			ARRAY_SIZE(vmxnet3_tq_driver_stats)) *
175		       adapter->num_tx_queues +
176		       (ARRAY_SIZE(vmxnet3_rq_dev_stats) +
177			ARRAY_SIZE(vmxnet3_rq_driver_stats)) *
178		       adapter->num_rx_queues +
179			ARRAY_SIZE(vmxnet3_global_stats);
180	default:
181		return -EOPNOTSUPP;
182	}
183}
184
185
186/* Should be multiple of 4 */
187#define NUM_TX_REGS	8
188#define NUM_RX_REGS	12
189
190static int
191vmxnet3_get_regs_len(struct net_device *netdev)
192{
193	struct vmxnet3_adapter *adapter = netdev_priv(netdev);
194	return (adapter->num_tx_queues * NUM_TX_REGS * sizeof(u32) +
195		adapter->num_rx_queues * NUM_RX_REGS * sizeof(u32));
196}
197
198
199static void
200vmxnet3_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
201{
202	struct vmxnet3_adapter *adapter = netdev_priv(netdev);
203
204	strlcpy(drvinfo->driver, vmxnet3_driver_name, sizeof(drvinfo->driver));
205
206	strlcpy(drvinfo->version, VMXNET3_DRIVER_VERSION_REPORT,
207		sizeof(drvinfo->version));
208
209	strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
210		sizeof(drvinfo->bus_info));
211	drvinfo->n_stats = vmxnet3_get_sset_count(netdev, ETH_SS_STATS);
212	drvinfo->testinfo_len = 0;
213	drvinfo->eedump_len   = 0;
214	drvinfo->regdump_len  = vmxnet3_get_regs_len(netdev);
215}
216
217
218static void
219vmxnet3_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
220{
221	 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
222	if (stringset == ETH_SS_STATS) {
223		int i, j;
224		for (j = 0; j < adapter->num_tx_queues; j++) {
225			for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++) {
226				memcpy(buf, vmxnet3_tq_dev_stats[i].desc,
227				       ETH_GSTRING_LEN);
228				buf += ETH_GSTRING_LEN;
229			}
230			for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats);
231			     i++) {
232				memcpy(buf, vmxnet3_tq_driver_stats[i].desc,
233				       ETH_GSTRING_LEN);
234				buf += ETH_GSTRING_LEN;
235			}
236		}
237
238		for (j = 0; j < adapter->num_rx_queues; j++) {
239			for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++) {
240				memcpy(buf, vmxnet3_rq_dev_stats[i].desc,
241				       ETH_GSTRING_LEN);
242				buf += ETH_GSTRING_LEN;
243			}
244			for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats);
245			     i++) {
246				memcpy(buf, vmxnet3_rq_driver_stats[i].desc,
247				       ETH_GSTRING_LEN);
248				buf += ETH_GSTRING_LEN;
249			}
250		}
251
252		for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++) {
253			memcpy(buf, vmxnet3_global_stats[i].desc,
254				ETH_GSTRING_LEN);
255			buf += ETH_GSTRING_LEN;
256		}
257	}
258}
259
260int vmxnet3_set_features(struct net_device *netdev, netdev_features_t features)
261{
262	struct vmxnet3_adapter *adapter = netdev_priv(netdev);
263	unsigned long flags;
264	netdev_features_t changed = features ^ netdev->features;
265
266	if (changed & (NETIF_F_RXCSUM | NETIF_F_LRO |
267		       NETIF_F_HW_VLAN_CTAG_RX)) {
268		if (features & NETIF_F_RXCSUM)
269			adapter->shared->devRead.misc.uptFeatures |=
270			UPT1_F_RXCSUM;
271		else
272			adapter->shared->devRead.misc.uptFeatures &=
273			~UPT1_F_RXCSUM;
274
275		/* update hardware LRO capability accordingly */
276		if (features & NETIF_F_LRO)
277			adapter->shared->devRead.misc.uptFeatures |=
278							UPT1_F_LRO;
279		else
280			adapter->shared->devRead.misc.uptFeatures &=
281							~UPT1_F_LRO;
282
283		if (features & NETIF_F_HW_VLAN_CTAG_RX)
284			adapter->shared->devRead.misc.uptFeatures |=
285			UPT1_F_RXVLAN;
286		else
287			adapter->shared->devRead.misc.uptFeatures &=
288			~UPT1_F_RXVLAN;
289
290		spin_lock_irqsave(&adapter->cmd_lock, flags);
291		VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
292				       VMXNET3_CMD_UPDATE_FEATURE);
293		spin_unlock_irqrestore(&adapter->cmd_lock, flags);
294	}
295	return 0;
296}
297
298static void
299vmxnet3_get_ethtool_stats(struct net_device *netdev,
300			  struct ethtool_stats *stats, u64  *buf)
301{
302	struct vmxnet3_adapter *adapter = netdev_priv(netdev);
303	unsigned long flags;
304	u8 *base;
305	int i;
306	int j = 0;
307
308	spin_lock_irqsave(&adapter->cmd_lock, flags);
309	VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
310	spin_unlock_irqrestore(&adapter->cmd_lock, flags);
311
312	/* this does assume each counter is 64-bit wide */
313	for (j = 0; j < adapter->num_tx_queues; j++) {
314		base = (u8 *)&adapter->tqd_start[j].stats;
315		*buf++ = (u64)j;
316		for (i = 1; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++)
317			*buf++ = *(u64 *)(base +
318					  vmxnet3_tq_dev_stats[i].offset);
319
320		base = (u8 *)&adapter->tx_queue[j].stats;
321		for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++)
322			*buf++ = *(u64 *)(base +
323					  vmxnet3_tq_driver_stats[i].offset);
324	}
325
326	for (j = 0; j < adapter->num_rx_queues; j++) {
327		base = (u8 *)&adapter->rqd_start[j].stats;
328		*buf++ = (u64) j;
329		for (i = 1; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++)
330			*buf++ = *(u64 *)(base +
331					  vmxnet3_rq_dev_stats[i].offset);
332
333		base = (u8 *)&adapter->rx_queue[j].stats;
334		for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++)
335			*buf++ = *(u64 *)(base +
336					  vmxnet3_rq_driver_stats[i].offset);
337	}
338
339	base = (u8 *)adapter;
340	for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++)
341		*buf++ = *(u64 *)(base + vmxnet3_global_stats[i].offset);
342}
343
344
345static void
346vmxnet3_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
347{
348	struct vmxnet3_adapter *adapter = netdev_priv(netdev);
349	u32 *buf = p;
350	int i = 0, j = 0;
351
352	memset(p, 0, vmxnet3_get_regs_len(netdev));
353
354	regs->version = 1;
355
356	/* Update vmxnet3_get_regs_len if we want to dump more registers */
357
358	/* make each ring use multiple of 16 bytes */
359	for (i = 0; i < adapter->num_tx_queues; i++) {
360		buf[j++] = adapter->tx_queue[i].tx_ring.next2fill;
361		buf[j++] = adapter->tx_queue[i].tx_ring.next2comp;
362		buf[j++] = adapter->tx_queue[i].tx_ring.gen;
363		buf[j++] = 0;
364
365		buf[j++] = adapter->tx_queue[i].comp_ring.next2proc;
366		buf[j++] = adapter->tx_queue[i].comp_ring.gen;
367		buf[j++] = adapter->tx_queue[i].stopped;
368		buf[j++] = 0;
369	}
370
371	for (i = 0; i < adapter->num_rx_queues; i++) {
372		buf[j++] = adapter->rx_queue[i].rx_ring[0].next2fill;
373		buf[j++] = adapter->rx_queue[i].rx_ring[0].next2comp;
374		buf[j++] = adapter->rx_queue[i].rx_ring[0].gen;
375		buf[j++] = 0;
376
377		buf[j++] = adapter->rx_queue[i].rx_ring[1].next2fill;
378		buf[j++] = adapter->rx_queue[i].rx_ring[1].next2comp;
379		buf[j++] = adapter->rx_queue[i].rx_ring[1].gen;
380		buf[j++] = 0;
381
382		buf[j++] = adapter->rx_queue[i].comp_ring.next2proc;
383		buf[j++] = adapter->rx_queue[i].comp_ring.gen;
384		buf[j++] = 0;
385		buf[j++] = 0;
386	}
387
388}
389
390
391static void
392vmxnet3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
393{
394	struct vmxnet3_adapter *adapter = netdev_priv(netdev);
395
396	wol->supported = WAKE_UCAST | WAKE_ARP | WAKE_MAGIC;
397	wol->wolopts = adapter->wol;
398}
399
400
401static int
402vmxnet3_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
403{
404	struct vmxnet3_adapter *adapter = netdev_priv(netdev);
405
406	if (wol->wolopts & (WAKE_PHY | WAKE_MCAST | WAKE_BCAST |
407			    WAKE_MAGICSECURE)) {
408		return -EOPNOTSUPP;
409	}
410
411	adapter->wol = wol->wolopts;
412
413	device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
414
415	return 0;
416}
417
418
419static int
420vmxnet3_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
421{
422	struct vmxnet3_adapter *adapter = netdev_priv(netdev);
423
424	ecmd->supported = SUPPORTED_10000baseT_Full | SUPPORTED_1000baseT_Full |
425			  SUPPORTED_TP;
426	ecmd->advertising = ADVERTISED_TP;
427	ecmd->port = PORT_TP;
428	ecmd->transceiver = XCVR_INTERNAL;
429
430	if (adapter->link_speed) {
431		ethtool_cmd_speed_set(ecmd, adapter->link_speed);
432		ecmd->duplex = DUPLEX_FULL;
433	} else {
434		ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
435		ecmd->duplex = DUPLEX_UNKNOWN;
436	}
437	return 0;
438}
439
440
441static void
442vmxnet3_get_ringparam(struct net_device *netdev,
443		      struct ethtool_ringparam *param)
444{
445	struct vmxnet3_adapter *adapter = netdev_priv(netdev);
446
447	param->rx_max_pending = VMXNET3_RX_RING_MAX_SIZE;
448	param->tx_max_pending = VMXNET3_TX_RING_MAX_SIZE;
449	param->rx_mini_max_pending = 0;
450	param->rx_jumbo_max_pending = VMXNET3_RX_RING2_MAX_SIZE;
451
452	param->rx_pending = adapter->rx_ring_size;
453	param->tx_pending = adapter->tx_ring_size;
454	param->rx_mini_pending = 0;
455	param->rx_jumbo_pending = adapter->rx_ring2_size;
456}
457
458
459static int
460vmxnet3_set_ringparam(struct net_device *netdev,
461		      struct ethtool_ringparam *param)
462{
463	struct vmxnet3_adapter *adapter = netdev_priv(netdev);
464	u32 new_tx_ring_size, new_rx_ring_size, new_rx_ring2_size;
465	u32 sz;
466	int err = 0;
467
468	if (param->tx_pending == 0 || param->tx_pending >
469						VMXNET3_TX_RING_MAX_SIZE)
470		return -EINVAL;
471
472	if (param->rx_pending == 0 || param->rx_pending >
473						VMXNET3_RX_RING_MAX_SIZE)
474		return -EINVAL;
475
476	if (param->rx_jumbo_pending == 0 ||
477	    param->rx_jumbo_pending > VMXNET3_RX_RING2_MAX_SIZE)
478		return -EINVAL;
479
480	/* if adapter not yet initialized, do nothing */
481	if (adapter->rx_buf_per_pkt == 0) {
482		netdev_err(netdev, "adapter not completely initialized, "
483			   "ring size cannot be changed yet\n");
484		return -EOPNOTSUPP;
485	}
486
487	/* round it up to a multiple of VMXNET3_RING_SIZE_ALIGN */
488	new_tx_ring_size = (param->tx_pending + VMXNET3_RING_SIZE_MASK) &
489							~VMXNET3_RING_SIZE_MASK;
490	new_tx_ring_size = min_t(u32, new_tx_ring_size,
491				 VMXNET3_TX_RING_MAX_SIZE);
492	if (new_tx_ring_size > VMXNET3_TX_RING_MAX_SIZE || (new_tx_ring_size %
493						VMXNET3_RING_SIZE_ALIGN) != 0)
494		return -EINVAL;
495
496	/* ring0 has to be a multiple of
497	 * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN
498	 */
499	sz = adapter->rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN;
500	new_rx_ring_size = (param->rx_pending + sz - 1) / sz * sz;
501	new_rx_ring_size = min_t(u32, new_rx_ring_size,
502				 VMXNET3_RX_RING_MAX_SIZE / sz * sz);
503	if (new_rx_ring_size > VMXNET3_RX_RING_MAX_SIZE || (new_rx_ring_size %
504							   sz) != 0)
505		return -EINVAL;
506
507	/* ring2 has to be a multiple of VMXNET3_RING_SIZE_ALIGN */
508	new_rx_ring2_size = (param->rx_jumbo_pending + VMXNET3_RING_SIZE_MASK) &
509				~VMXNET3_RING_SIZE_MASK;
510	new_rx_ring2_size = min_t(u32, new_rx_ring2_size,
511				  VMXNET3_RX_RING2_MAX_SIZE);
512
513	if (new_tx_ring_size == adapter->tx_ring_size &&
514	    new_rx_ring_size == adapter->rx_ring_size &&
515	    new_rx_ring2_size == adapter->rx_ring2_size) {
516		return 0;
517	}
518
519	/*
520	 * Reset_work may be in the middle of resetting the device, wait for its
521	 * completion.
522	 */
523	while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
524		msleep(1);
525
526	if (netif_running(netdev)) {
527		vmxnet3_quiesce_dev(adapter);
528		vmxnet3_reset_dev(adapter);
529
530		/* recreate the rx queue and the tx queue based on the
531		 * new sizes */
532		vmxnet3_tq_destroy_all(adapter);
533		vmxnet3_rq_destroy_all(adapter);
534
535		err = vmxnet3_create_queues(adapter, new_tx_ring_size,
536			new_rx_ring_size, new_rx_ring2_size);
537
538		if (err) {
539			/* failed, most likely because of OOM, try default
540			 * size */
541			netdev_err(netdev, "failed to apply new sizes, "
542				   "try the default ones\n");
543			new_rx_ring_size = VMXNET3_DEF_RX_RING_SIZE;
544			new_rx_ring2_size = VMXNET3_DEF_RX_RING2_SIZE;
545			new_tx_ring_size = VMXNET3_DEF_TX_RING_SIZE;
546			err = vmxnet3_create_queues(adapter,
547						    new_tx_ring_size,
548						    new_rx_ring_size,
549						    new_rx_ring2_size);
550			if (err) {
551				netdev_err(netdev, "failed to create queues "
552					   "with default sizes. Closing it\n");
553				goto out;
554			}
555		}
556
557		err = vmxnet3_activate_dev(adapter);
558		if (err)
559			netdev_err(netdev, "failed to re-activate, error %d."
560				   " Closing it\n", err);
561	}
562	adapter->tx_ring_size = new_tx_ring_size;
563	adapter->rx_ring_size = new_rx_ring_size;
564	adapter->rx_ring2_size = new_rx_ring2_size;
565
566out:
567	clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
568	if (err)
569		vmxnet3_force_close(adapter);
570
571	return err;
572}
573
574
575static int
576vmxnet3_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info,
577		  u32 *rules)
578{
579	struct vmxnet3_adapter *adapter = netdev_priv(netdev);
580	switch (info->cmd) {
581	case ETHTOOL_GRXRINGS:
582		info->data = adapter->num_rx_queues;
583		return 0;
584	}
585	return -EOPNOTSUPP;
586}
587
588#ifdef VMXNET3_RSS
589static u32
590vmxnet3_get_rss_indir_size(struct net_device *netdev)
591{
592	struct vmxnet3_adapter *adapter = netdev_priv(netdev);
593	struct UPT1_RSSConf *rssConf = adapter->rss_conf;
594
595	return rssConf->indTableSize;
596}
597
598static int
599vmxnet3_get_rss(struct net_device *netdev, u32 *p, u8 *key, u8 *hfunc)
600{
601	struct vmxnet3_adapter *adapter = netdev_priv(netdev);
602	struct UPT1_RSSConf *rssConf = adapter->rss_conf;
603	unsigned int n = rssConf->indTableSize;
604
605	if (hfunc)
606		*hfunc = ETH_RSS_HASH_TOP;
607	if (!p)
608		return 0;
609	while (n--)
610		p[n] = rssConf->indTable[n];
611	return 0;
612
613}
614
615static int
616vmxnet3_set_rss(struct net_device *netdev, const u32 *p, const u8 *key,
617		const u8 hfunc)
618{
619	unsigned int i;
620	unsigned long flags;
621	struct vmxnet3_adapter *adapter = netdev_priv(netdev);
622	struct UPT1_RSSConf *rssConf = adapter->rss_conf;
623
624	/* We do not allow change in unsupported parameters */
625	if (key ||
626	    (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
627		return -EOPNOTSUPP;
628	if (!p)
629		return 0;
630	for (i = 0; i < rssConf->indTableSize; i++)
631		rssConf->indTable[i] = p[i];
632
633	spin_lock_irqsave(&adapter->cmd_lock, flags);
634	VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
635			       VMXNET3_CMD_UPDATE_RSSIDT);
636	spin_unlock_irqrestore(&adapter->cmd_lock, flags);
637
638	return 0;
639
640}
641#endif
642
643static const struct ethtool_ops vmxnet3_ethtool_ops = {
644	.get_settings      = vmxnet3_get_settings,
645	.get_drvinfo       = vmxnet3_get_drvinfo,
646	.get_regs_len      = vmxnet3_get_regs_len,
647	.get_regs          = vmxnet3_get_regs,
648	.get_wol           = vmxnet3_get_wol,
649	.set_wol           = vmxnet3_set_wol,
650	.get_link          = ethtool_op_get_link,
651	.get_strings       = vmxnet3_get_strings,
652	.get_sset_count	   = vmxnet3_get_sset_count,
653	.get_ethtool_stats = vmxnet3_get_ethtool_stats,
654	.get_ringparam     = vmxnet3_get_ringparam,
655	.set_ringparam     = vmxnet3_set_ringparam,
656	.get_rxnfc         = vmxnet3_get_rxnfc,
657#ifdef VMXNET3_RSS
658	.get_rxfh_indir_size = vmxnet3_get_rss_indir_size,
659	.get_rxfh          = vmxnet3_get_rss,
660	.set_rxfh          = vmxnet3_set_rss,
661#endif
662};
663
664void vmxnet3_set_ethtool_ops(struct net_device *netdev)
665{
666	netdev->ethtool_ops = &vmxnet3_ethtool_ops;
667}
668