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