can: bfin_can: auto-calculate accessor sizes
[deliverable/linux.git] / drivers / net / vmxnet3 / vmxnet3_ethtool.c
CommitLineData
d1a890fa
SB
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
d1a890fa
SB
36/* per tq stats maintained by the device */
37static const struct vmxnet3_stat_desc
38vmxnet3_tq_dev_stats[] = {
39 /* description, offset */
76d39dae
SB
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) },
d1a890fa
SB
51};
52
53/* per tq stats maintained by the driver */
54static const struct vmxnet3_stat_desc
55vmxnet3_tq_driver_stats[] = {
56 /* description, offset */
76d39dae
SB
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) },
d1a890fa
SB
75};
76
77/* per rq stats maintained by the device */
78static const struct vmxnet3_stat_desc
79vmxnet3_rq_dev_stats[] = {
76d39dae
SB
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) },
d1a890fa
SB
91};
92
93/* per rq stats maintained by the driver */
94static const struct vmxnet3_stat_desc
95vmxnet3_rq_driver_stats[] = {
96 /* description, offset */
76d39dae
SB
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) },
d1a890fa
SB
105};
106
107/* gloabl stats maintained by the driver */
108static const struct vmxnet3_stat_desc
109vmxnet3_global_stats[] = {
110 /* description, offset */
76d39dae 111 { "tx timeout count", offsetof(struct vmxnet3_adapter,
d1a890fa
SB
112 tx_timeout_count) }
113};
114
115
95305f6c 116struct rtnl_link_stats64 *
117vmxnet3_get_stats64(struct net_device *netdev,
118 struct rtnl_link_stats64 *stats)
d1a890fa
SB
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;
83d0feff 125 unsigned long flags;
09c5088e 126 int i;
d1a890fa
SB
127
128 adapter = netdev_priv(netdev);
129
130 /* Collect the dev stats into the shared area */
83d0feff 131 spin_lock_irqsave(&adapter->cmd_lock, flags);
d1a890fa 132 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
83d0feff 133 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
d1a890fa 134
09c5088e
SB
135 for (i = 0; i < adapter->num_tx_queues; i++) {
136 devTxStats = &adapter->tqd_start[i].stats;
137 drvTxStats = &adapter->tx_queue[i].stats;
95305f6c 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;
09c5088e 146 }
d1a890fa 147
09c5088e
SB
148 for (i = 0; i < adapter->num_rx_queues; i++) {
149 devRxStats = &adapter->rqd_start[i].stats;
150 drvRxStats = &adapter->rx_queue[i].stats;
95305f6c 151 stats->rx_packets += devRxStats->ucastPktsRxOK +
152 devRxStats->mcastPktsRxOK +
153 devRxStats->bcastPktsRxOK;
d1a890fa 154
95305f6c 155 stats->rx_bytes += devRxStats->ucastBytesRxOK +
156 devRxStats->mcastBytesRxOK +
157 devRxStats->bcastBytesRxOK;
d1a890fa 158
95305f6c 159 stats->rx_errors += devRxStats->pktsRxError;
160 stats->rx_dropped += drvRxStats->drop_total;
161 stats->multicast += devRxStats->mcastPktsRxOK;
09c5088e 162 }
95305f6c 163
164 return stats;
d1a890fa
SB
165}
166
167static int
168vmxnet3_get_sset_count(struct net_device *netdev, int sset)
169{
76d39dae 170 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
d1a890fa
SB
171 switch (sset) {
172 case ETH_SS_STATS:
76d39dae
SB
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 +
d1a890fa
SB
179 ARRAY_SIZE(vmxnet3_global_stats);
180 default:
181 return -EOPNOTSUPP;
182 }
183}
184
185
76d39dae
SB
186/* Should be multiple of 4 */
187#define NUM_TX_REGS 8
188#define NUM_RX_REGS 12
189
d1a890fa
SB
190static int
191vmxnet3_get_regs_len(struct net_device *netdev)
192{
76d39dae
SB
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));
d1a890fa
SB
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 drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
206
207 strlcpy(drvinfo->version, VMXNET3_DRIVER_VERSION_REPORT,
208 sizeof(drvinfo->version));
209 drvinfo->driver[sizeof(drvinfo->version) - 1] = '\0';
210
211 strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
212 drvinfo->fw_version[sizeof(drvinfo->fw_version) - 1] = '\0';
213
214 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
215 ETHTOOL_BUSINFO_LEN);
216 drvinfo->n_stats = vmxnet3_get_sset_count(netdev, ETH_SS_STATS);
217 drvinfo->testinfo_len = 0;
218 drvinfo->eedump_len = 0;
219 drvinfo->regdump_len = vmxnet3_get_regs_len(netdev);
220}
221
222
223static void
224vmxnet3_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
225{
76d39dae 226 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
d1a890fa 227 if (stringset == ETH_SS_STATS) {
76d39dae
SB
228 int i, j;
229 for (j = 0; j < adapter->num_tx_queues; j++) {
230 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++) {
231 memcpy(buf, vmxnet3_tq_dev_stats[i].desc,
232 ETH_GSTRING_LEN);
233 buf += ETH_GSTRING_LEN;
234 }
235 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats);
236 i++) {
237 memcpy(buf, vmxnet3_tq_driver_stats[i].desc,
238 ETH_GSTRING_LEN);
239 buf += ETH_GSTRING_LEN;
240 }
d1a890fa 241 }
76d39dae
SB
242
243 for (j = 0; j < adapter->num_rx_queues; j++) {
244 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++) {
245 memcpy(buf, vmxnet3_rq_dev_stats[i].desc,
246 ETH_GSTRING_LEN);
247 buf += ETH_GSTRING_LEN;
248 }
249 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats);
250 i++) {
251 memcpy(buf, vmxnet3_rq_driver_stats[i].desc,
252 ETH_GSTRING_LEN);
253 buf += ETH_GSTRING_LEN;
254 }
d1a890fa 255 }
76d39dae 256
d1a890fa
SB
257 for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++) {
258 memcpy(buf, vmxnet3_global_stats[i].desc,
259 ETH_GSTRING_LEN);
260 buf += ETH_GSTRING_LEN;
261 }
262 }
263}
264
a0d2730c 265int vmxnet3_set_features(struct net_device *netdev, u32 features)
d92be4b1 266{
d1a890fa 267 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
83d0feff 268 unsigned long flags;
a0d2730c 269 u32 changed = features ^ netdev->features;
d1a890fa 270
a0d2730c
MM
271 if (changed & (NETIF_F_RXCSUM|NETIF_F_LRO)) {
272 if (features & NETIF_F_RXCSUM)
273 adapter->shared->devRead.misc.uptFeatures |=
274 UPT1_F_RXCSUM;
275 else
276 adapter->shared->devRead.misc.uptFeatures &=
277 ~UPT1_F_RXCSUM;
d1a890fa
SB
278
279 /* update harware LRO capability accordingly */
a0d2730c 280 if (features & NETIF_F_LRO)
ca802447 281 adapter->shared->devRead.misc.uptFeatures |=
3843e515 282 UPT1_F_LRO;
d1a890fa
SB
283 else
284 adapter->shared->devRead.misc.uptFeatures &=
3843e515 285 ~UPT1_F_LRO;
a0d2730c 286
83d0feff 287 spin_lock_irqsave(&adapter->cmd_lock, flags);
d1a890fa
SB
288 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
289 VMXNET3_CMD_UPDATE_FEATURE);
83d0feff 290 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
d1a890fa
SB
291 }
292 return 0;
293}
294
295static void
296vmxnet3_get_ethtool_stats(struct net_device *netdev,
297 struct ethtool_stats *stats, u64 *buf)
298{
299 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
83d0feff 300 unsigned long flags;
d1a890fa
SB
301 u8 *base;
302 int i;
09c5088e 303 int j = 0;
d1a890fa 304
83d0feff 305 spin_lock_irqsave(&adapter->cmd_lock, flags);
d1a890fa 306 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
83d0feff 307 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
d1a890fa
SB
308
309 /* this does assume each counter is 64-bit wide */
76d39dae
SB
310 for (j = 0; j < adapter->num_tx_queues; j++) {
311 base = (u8 *)&adapter->tqd_start[j].stats;
312 *buf++ = (u64)j;
313 for (i = 1; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++)
314 *buf++ = *(u64 *)(base +
315 vmxnet3_tq_dev_stats[i].offset);
316
317 base = (u8 *)&adapter->tx_queue[j].stats;
318 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++)
319 *buf++ = *(u64 *)(base +
320 vmxnet3_tq_driver_stats[i].offset);
321 }
d1a890fa 322
76d39dae
SB
323 for (j = 0; j < adapter->num_tx_queues; j++) {
324 base = (u8 *)&adapter->rqd_start[j].stats;
325 *buf++ = (u64) j;
326 for (i = 1; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++)
327 *buf++ = *(u64 *)(base +
328 vmxnet3_rq_dev_stats[i].offset);
329
330 base = (u8 *)&adapter->rx_queue[j].stats;
331 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++)
332 *buf++ = *(u64 *)(base +
333 vmxnet3_rq_driver_stats[i].offset);
334 }
d1a890fa
SB
335
336 base = (u8 *)adapter;
337 for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++)
338 *buf++ = *(u64 *)(base + vmxnet3_global_stats[i].offset);
339}
340
341
342static void
343vmxnet3_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
344{
345 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
346 u32 *buf = p;
76d39dae 347 int i = 0, j = 0;
d1a890fa
SB
348
349 memset(p, 0, vmxnet3_get_regs_len(netdev));
350
351 regs->version = 1;
352
353 /* Update vmxnet3_get_regs_len if we want to dump more registers */
354
355 /* make each ring use multiple of 16 bytes */
76d39dae
SB
356 for (i = 0; i < adapter->num_tx_queues; i++) {
357 buf[j++] = adapter->tx_queue[i].tx_ring.next2fill;
358 buf[j++] = adapter->tx_queue[i].tx_ring.next2comp;
359 buf[j++] = adapter->tx_queue[i].tx_ring.gen;
360 buf[j++] = 0;
361
362 buf[j++] = adapter->tx_queue[i].comp_ring.next2proc;
363 buf[j++] = adapter->tx_queue[i].comp_ring.gen;
364 buf[j++] = adapter->tx_queue[i].stopped;
365 buf[j++] = 0;
366 }
367
368 for (i = 0; i < adapter->num_rx_queues; i++) {
369 buf[j++] = adapter->rx_queue[i].rx_ring[0].next2fill;
370 buf[j++] = adapter->rx_queue[i].rx_ring[0].next2comp;
371 buf[j++] = adapter->rx_queue[i].rx_ring[0].gen;
372 buf[j++] = 0;
373
374 buf[j++] = adapter->rx_queue[i].rx_ring[1].next2fill;
375 buf[j++] = adapter->rx_queue[i].rx_ring[1].next2comp;
376 buf[j++] = adapter->rx_queue[i].rx_ring[1].gen;
377 buf[j++] = 0;
378
379 buf[j++] = adapter->rx_queue[i].comp_ring.next2proc;
380 buf[j++] = adapter->rx_queue[i].comp_ring.gen;
381 buf[j++] = 0;
382 buf[j++] = 0;
383 }
384
d1a890fa
SB
385}
386
387
388static void
389vmxnet3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
390{
391 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
392
393 wol->supported = WAKE_UCAST | WAKE_ARP | WAKE_MAGIC;
394 wol->wolopts = adapter->wol;
395}
396
397
398static int
399vmxnet3_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
400{
401 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
402
403 if (wol->wolopts & (WAKE_PHY | WAKE_MCAST | WAKE_BCAST |
404 WAKE_MAGICSECURE)) {
405 return -EOPNOTSUPP;
406 }
407
408 adapter->wol = wol->wolopts;
409
410 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
411
412 return 0;
413}
414
415
416static int
417vmxnet3_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
418{
419 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
420
421 ecmd->supported = SUPPORTED_10000baseT_Full | SUPPORTED_1000baseT_Full |
422 SUPPORTED_TP;
423 ecmd->advertising = ADVERTISED_TP;
424 ecmd->port = PORT_TP;
425 ecmd->transceiver = XCVR_INTERNAL;
426
427 if (adapter->link_speed) {
70739497 428 ethtool_cmd_speed_set(ecmd, adapter->link_speed);
d1a890fa
SB
429 ecmd->duplex = DUPLEX_FULL;
430 } else {
70739497 431 ethtool_cmd_speed_set(ecmd, -1);
d1a890fa
SB
432 ecmd->duplex = -1;
433 }
434 return 0;
435}
436
437
438static void
439vmxnet3_get_ringparam(struct net_device *netdev,
440 struct ethtool_ringparam *param)
441{
442 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
443
444 param->rx_max_pending = VMXNET3_RX_RING_MAX_SIZE;
445 param->tx_max_pending = VMXNET3_TX_RING_MAX_SIZE;
446 param->rx_mini_max_pending = 0;
447 param->rx_jumbo_max_pending = 0;
448
09c5088e
SB
449 param->rx_pending = adapter->rx_queue[0].rx_ring[0].size *
450 adapter->num_rx_queues;
451 param->tx_pending = adapter->tx_queue[0].tx_ring.size *
452 adapter->num_tx_queues;
d1a890fa
SB
453 param->rx_mini_pending = 0;
454 param->rx_jumbo_pending = 0;
455}
456
457
458static int
459vmxnet3_set_ringparam(struct net_device *netdev,
460 struct ethtool_ringparam *param)
461{
462 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
463 u32 new_tx_ring_size, new_rx_ring_size;
464 u32 sz;
465 int err = 0;
466
467 if (param->tx_pending == 0 || param->tx_pending >
468 VMXNET3_TX_RING_MAX_SIZE)
469 return -EINVAL;
470
471 if (param->rx_pending == 0 || param->rx_pending >
472 VMXNET3_RX_RING_MAX_SIZE)
473 return -EINVAL;
474
475
476 /* round it up to a multiple of VMXNET3_RING_SIZE_ALIGN */
477 new_tx_ring_size = (param->tx_pending + VMXNET3_RING_SIZE_MASK) &
478 ~VMXNET3_RING_SIZE_MASK;
479 new_tx_ring_size = min_t(u32, new_tx_ring_size,
480 VMXNET3_TX_RING_MAX_SIZE);
481 if (new_tx_ring_size > VMXNET3_TX_RING_MAX_SIZE || (new_tx_ring_size %
482 VMXNET3_RING_SIZE_ALIGN) != 0)
483 return -EINVAL;
484
485 /* ring0 has to be a multiple of
486 * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN
487 */
488 sz = adapter->rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN;
489 new_rx_ring_size = (param->rx_pending + sz - 1) / sz * sz;
490 new_rx_ring_size = min_t(u32, new_rx_ring_size,
491 VMXNET3_RX_RING_MAX_SIZE / sz * sz);
492 if (new_rx_ring_size > VMXNET3_RX_RING_MAX_SIZE || (new_rx_ring_size %
493 sz) != 0)
494 return -EINVAL;
495
09c5088e
SB
496 if (new_tx_ring_size == adapter->tx_queue[0].tx_ring.size &&
497 new_rx_ring_size == adapter->rx_queue[0].rx_ring[0].size) {
d1a890fa
SB
498 return 0;
499 }
500
501 /*
502 * Reset_work may be in the middle of resetting the device, wait for its
503 * completion.
504 */
505 while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
506 msleep(1);
507
508 if (netif_running(netdev)) {
509 vmxnet3_quiesce_dev(adapter);
510 vmxnet3_reset_dev(adapter);
511
512 /* recreate the rx queue and the tx queue based on the
513 * new sizes */
09c5088e
SB
514 vmxnet3_tq_destroy_all(adapter);
515 vmxnet3_rq_destroy_all(adapter);
d1a890fa
SB
516
517 err = vmxnet3_create_queues(adapter, new_tx_ring_size,
518 new_rx_ring_size, VMXNET3_DEF_RX_RING_SIZE);
09c5088e 519
d1a890fa
SB
520 if (err) {
521 /* failed, most likely because of OOM, try default
522 * size */
523 printk(KERN_ERR "%s: failed to apply new sizes, try the"
524 " default ones\n", netdev->name);
525 err = vmxnet3_create_queues(adapter,
526 VMXNET3_DEF_TX_RING_SIZE,
527 VMXNET3_DEF_RX_RING_SIZE,
528 VMXNET3_DEF_RX_RING_SIZE);
529 if (err) {
530 printk(KERN_ERR "%s: failed to create queues "
531 "with default sizes. Closing it\n",
532 netdev->name);
533 goto out;
534 }
535 }
536
537 err = vmxnet3_activate_dev(adapter);
538 if (err)
539 printk(KERN_ERR "%s: failed to re-activate, error %d."
540 " Closing it\n", netdev->name, err);
541 }
542
543out:
544 clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
545 if (err)
546 vmxnet3_force_close(adapter);
547
548 return err;
549}
550
551
09c5088e
SB
552static int
553vmxnet3_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info,
554 void *rules)
555{
556 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
557 switch (info->cmd) {
558 case ETHTOOL_GRXRINGS:
559 info->data = adapter->num_rx_queues;
560 return 0;
561 }
562 return -EOPNOTSUPP;
563}
564
e9248fbd 565#ifdef VMXNET3_RSS
09c5088e
SB
566static int
567vmxnet3_get_rss_indir(struct net_device *netdev,
568 struct ethtool_rxfh_indir *p)
569{
570 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
571 struct UPT1_RSSConf *rssConf = adapter->rss_conf;
572 unsigned int n = min_t(unsigned int, p->size, rssConf->indTableSize);
573
574 p->size = rssConf->indTableSize;
575 while (n--)
576 p->ring_index[n] = rssConf->indTable[n];
577 return 0;
578
579}
580
581static int
582vmxnet3_set_rss_indir(struct net_device *netdev,
583 const struct ethtool_rxfh_indir *p)
584{
585 unsigned int i;
83d0feff 586 unsigned long flags;
09c5088e
SB
587 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
588 struct UPT1_RSSConf *rssConf = adapter->rss_conf;
589
590 if (p->size != rssConf->indTableSize)
591 return -EINVAL;
592 for (i = 0; i < rssConf->indTableSize; i++) {
593 /*
594 * Return with error code if any of the queue indices
595 * is out of range
596 */
597 if (p->ring_index[i] < 0 ||
598 p->ring_index[i] >= adapter->num_rx_queues)
599 return -EINVAL;
600 }
601
602 for (i = 0; i < rssConf->indTableSize; i++)
603 rssConf->indTable[i] = p->ring_index[i];
604
83d0feff 605 spin_lock_irqsave(&adapter->cmd_lock, flags);
09c5088e
SB
606 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
607 VMXNET3_CMD_UPDATE_RSSIDT);
83d0feff 608 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
09c5088e
SB
609
610 return 0;
611
612}
e9248fbd 613#endif
09c5088e 614
d1a890fa
SB
615static struct ethtool_ops vmxnet3_ethtool_ops = {
616 .get_settings = vmxnet3_get_settings,
617 .get_drvinfo = vmxnet3_get_drvinfo,
618 .get_regs_len = vmxnet3_get_regs_len,
619 .get_regs = vmxnet3_get_regs,
620 .get_wol = vmxnet3_get_wol,
621 .set_wol = vmxnet3_set_wol,
622 .get_link = ethtool_op_get_link,
d1a890fa 623 .get_strings = vmxnet3_get_strings,
d1a890fa
SB
624 .get_sset_count = vmxnet3_get_sset_count,
625 .get_ethtool_stats = vmxnet3_get_ethtool_stats,
626 .get_ringparam = vmxnet3_get_ringparam,
627 .set_ringparam = vmxnet3_set_ringparam,
09c5088e 628 .get_rxnfc = vmxnet3_get_rxnfc,
e9248fbd 629#ifdef VMXNET3_RSS
09c5088e
SB
630 .get_rxfh_indir = vmxnet3_get_rss_indir,
631 .set_rxfh_indir = vmxnet3_set_rss_indir,
e9248fbd 632#endif
d1a890fa
SB
633};
634
635void vmxnet3_set_ethtool_ops(struct net_device *netdev)
636{
637 SET_ETHTOOL_OPS(netdev, &vmxnet3_ethtool_ops);
638}
This page took 0.235645 seconds and 5 git commands to generate.