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