enic: Add new firmware devcmds
[linux/fpc-iii.git] / drivers / net / vmxnet3 / vmxnet3_ethtool.c
blob7e4b5a89165a5804dcb68dd78d225163ea71efd7
1 /*
2 * Linux driver for VMware's vmxnet3 ethernet NIC.
4 * Copyright (C) 2008-2009, VMware, Inc. All Rights Reserved.
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.
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.
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.
20 * The full GNU General Public License is included in this distribution in
21 * the file called "COPYING".
23 * Maintained by: Shreyas Bhatewara <pv-drivers@vmware.com>
28 #include "vmxnet3_int.h"
30 struct vmxnet3_stat_desc {
31 char desc[ETH_GSTRING_LEN];
32 int offset;
36 static u32
37 vmxnet3_get_rx_csum(struct net_device *netdev)
39 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
40 return adapter->rxcsum;
44 static int
45 vmxnet3_set_rx_csum(struct net_device *netdev, u32 val)
47 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
49 if (adapter->rxcsum != val) {
50 adapter->rxcsum = val;
51 if (netif_running(netdev)) {
52 if (val)
53 set_flag_le64(
54 &adapter->shared->devRead.misc.uptFeatures,
55 UPT1_F_RXCSUM);
56 else
57 reset_flag_le64(
58 &adapter->shared->devRead.misc.uptFeatures,
59 UPT1_F_RXCSUM);
61 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
62 VMXNET3_CMD_UPDATE_FEATURE);
65 return 0;
69 /* per tq stats maintained by the device */
70 static const struct vmxnet3_stat_desc
71 vmxnet3_tq_dev_stats[] = {
72 /* description, offset */
73 { "TSO pkts tx", offsetof(struct UPT1_TxStats, TSOPktsTxOK) },
74 { "TSO bytes tx", offsetof(struct UPT1_TxStats, TSOBytesTxOK) },
75 { "ucast pkts tx", offsetof(struct UPT1_TxStats, ucastPktsTxOK) },
76 { "ucast bytes tx", offsetof(struct UPT1_TxStats, ucastBytesTxOK) },
77 { "mcast pkts tx", offsetof(struct UPT1_TxStats, mcastPktsTxOK) },
78 { "mcast bytes tx", offsetof(struct UPT1_TxStats, mcastBytesTxOK) },
79 { "bcast pkts tx", offsetof(struct UPT1_TxStats, bcastPktsTxOK) },
80 { "bcast bytes tx", offsetof(struct UPT1_TxStats, bcastBytesTxOK) },
81 { "pkts tx err", offsetof(struct UPT1_TxStats, pktsTxError) },
82 { "pkts tx discard", offsetof(struct UPT1_TxStats, pktsTxDiscard) },
85 /* per tq stats maintained by the driver */
86 static const struct vmxnet3_stat_desc
87 vmxnet3_tq_driver_stats[] = {
88 /* description, offset */
89 {"drv dropped tx total", offsetof(struct vmxnet3_tq_driver_stats,
90 drop_total) },
91 { " too many frags", offsetof(struct vmxnet3_tq_driver_stats,
92 drop_too_many_frags) },
93 { " giant hdr", offsetof(struct vmxnet3_tq_driver_stats,
94 drop_oversized_hdr) },
95 { " hdr err", offsetof(struct vmxnet3_tq_driver_stats,
96 drop_hdr_inspect_err) },
97 { " tso", offsetof(struct vmxnet3_tq_driver_stats,
98 drop_tso) },
99 { "ring full", offsetof(struct vmxnet3_tq_driver_stats,
100 tx_ring_full) },
101 { "pkts linearized", offsetof(struct vmxnet3_tq_driver_stats,
102 linearized) },
103 { "hdr cloned", offsetof(struct vmxnet3_tq_driver_stats,
104 copy_skb_header) },
105 { "giant hdr", offsetof(struct vmxnet3_tq_driver_stats,
106 oversized_hdr) },
109 /* per rq stats maintained by the device */
110 static const struct vmxnet3_stat_desc
111 vmxnet3_rq_dev_stats[] = {
112 { "LRO pkts rx", offsetof(struct UPT1_RxStats, LROPktsRxOK) },
113 { "LRO byte rx", offsetof(struct UPT1_RxStats, LROBytesRxOK) },
114 { "ucast pkts rx", offsetof(struct UPT1_RxStats, ucastPktsRxOK) },
115 { "ucast bytes rx", offsetof(struct UPT1_RxStats, ucastBytesRxOK) },
116 { "mcast pkts rx", offsetof(struct UPT1_RxStats, mcastPktsRxOK) },
117 { "mcast bytes rx", offsetof(struct UPT1_RxStats, mcastBytesRxOK) },
118 { "bcast pkts rx", offsetof(struct UPT1_RxStats, bcastPktsRxOK) },
119 { "bcast bytes rx", offsetof(struct UPT1_RxStats, bcastBytesRxOK) },
120 { "pkts rx out of buf", offsetof(struct UPT1_RxStats, pktsRxOutOfBuf) },
121 { "pkts rx err", offsetof(struct UPT1_RxStats, pktsRxError) },
124 /* per rq stats maintained by the driver */
125 static const struct vmxnet3_stat_desc
126 vmxnet3_rq_driver_stats[] = {
127 /* description, offset */
128 { "drv dropped rx total", offsetof(struct vmxnet3_rq_driver_stats,
129 drop_total) },
130 { " err", offsetof(struct vmxnet3_rq_driver_stats,
131 drop_err) },
132 { " fcs", offsetof(struct vmxnet3_rq_driver_stats,
133 drop_fcs) },
134 { "rx buf alloc fail", offsetof(struct vmxnet3_rq_driver_stats,
135 rx_buf_alloc_failure) },
138 /* gloabl stats maintained by the driver */
139 static const struct vmxnet3_stat_desc
140 vmxnet3_global_stats[] = {
141 /* description, offset */
142 { "tx timeout count", offsetof(struct vmxnet3_adapter,
143 tx_timeout_count) }
147 struct net_device_stats *
148 vmxnet3_get_stats(struct net_device *netdev)
150 struct vmxnet3_adapter *adapter;
151 struct vmxnet3_tq_driver_stats *drvTxStats;
152 struct vmxnet3_rq_driver_stats *drvRxStats;
153 struct UPT1_TxStats *devTxStats;
154 struct UPT1_RxStats *devRxStats;
155 struct net_device_stats *net_stats = &netdev->stats;
157 adapter = netdev_priv(netdev);
159 /* Collect the dev stats into the shared area */
160 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
162 /* Assuming that we have a single queue device */
163 devTxStats = &adapter->tqd_start->stats;
164 devRxStats = &adapter->rqd_start->stats;
166 /* Get access to the driver stats per queue */
167 drvTxStats = &adapter->tx_queue.stats;
168 drvRxStats = &adapter->rx_queue.stats;
170 memset(net_stats, 0, sizeof(*net_stats));
172 net_stats->rx_packets = devRxStats->ucastPktsRxOK +
173 devRxStats->mcastPktsRxOK +
174 devRxStats->bcastPktsRxOK;
176 net_stats->tx_packets = devTxStats->ucastPktsTxOK +
177 devTxStats->mcastPktsTxOK +
178 devTxStats->bcastPktsTxOK;
180 net_stats->rx_bytes = devRxStats->ucastBytesRxOK +
181 devRxStats->mcastBytesRxOK +
182 devRxStats->bcastBytesRxOK;
184 net_stats->tx_bytes = devTxStats->ucastBytesTxOK +
185 devTxStats->mcastBytesTxOK +
186 devTxStats->bcastBytesTxOK;
188 net_stats->rx_errors = devRxStats->pktsRxError;
189 net_stats->tx_errors = devTxStats->pktsTxError;
190 net_stats->rx_dropped = drvRxStats->drop_total;
191 net_stats->tx_dropped = drvTxStats->drop_total;
192 net_stats->multicast = devRxStats->mcastPktsRxOK;
194 return net_stats;
197 static int
198 vmxnet3_get_sset_count(struct net_device *netdev, int sset)
200 switch (sset) {
201 case ETH_SS_STATS:
202 return ARRAY_SIZE(vmxnet3_tq_dev_stats) +
203 ARRAY_SIZE(vmxnet3_tq_driver_stats) +
204 ARRAY_SIZE(vmxnet3_rq_dev_stats) +
205 ARRAY_SIZE(vmxnet3_rq_driver_stats) +
206 ARRAY_SIZE(vmxnet3_global_stats);
207 default:
208 return -EOPNOTSUPP;
213 static int
214 vmxnet3_get_regs_len(struct net_device *netdev)
216 return 20 * sizeof(u32);
220 static void
221 vmxnet3_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
223 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
225 strlcpy(drvinfo->driver, vmxnet3_driver_name, sizeof(drvinfo->driver));
226 drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
228 strlcpy(drvinfo->version, VMXNET3_DRIVER_VERSION_REPORT,
229 sizeof(drvinfo->version));
230 drvinfo->driver[sizeof(drvinfo->version) - 1] = '\0';
232 strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
233 drvinfo->fw_version[sizeof(drvinfo->fw_version) - 1] = '\0';
235 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
236 ETHTOOL_BUSINFO_LEN);
237 drvinfo->n_stats = vmxnet3_get_sset_count(netdev, ETH_SS_STATS);
238 drvinfo->testinfo_len = 0;
239 drvinfo->eedump_len = 0;
240 drvinfo->regdump_len = vmxnet3_get_regs_len(netdev);
244 static void
245 vmxnet3_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
247 if (stringset == ETH_SS_STATS) {
248 int i;
250 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++) {
251 memcpy(buf, vmxnet3_tq_dev_stats[i].desc,
252 ETH_GSTRING_LEN);
253 buf += ETH_GSTRING_LEN;
255 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++) {
256 memcpy(buf, vmxnet3_tq_driver_stats[i].desc,
257 ETH_GSTRING_LEN);
258 buf += ETH_GSTRING_LEN;
260 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++) {
261 memcpy(buf, vmxnet3_rq_dev_stats[i].desc,
262 ETH_GSTRING_LEN);
263 buf += ETH_GSTRING_LEN;
265 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++) {
266 memcpy(buf, vmxnet3_rq_driver_stats[i].desc,
267 ETH_GSTRING_LEN);
268 buf += ETH_GSTRING_LEN;
270 for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++) {
271 memcpy(buf, vmxnet3_global_stats[i].desc,
272 ETH_GSTRING_LEN);
273 buf += ETH_GSTRING_LEN;
278 static int
279 vmxnet3_set_flags(struct net_device *netdev, u32 data)
281 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
282 u8 lro_requested = (data & ETH_FLAG_LRO) == 0 ? 0 : 1;
283 u8 lro_present = (netdev->features & NETIF_F_LRO) == 0 ? 0 : 1;
285 if (data & ~ETH_FLAG_LRO)
286 return -EOPNOTSUPP;
288 if (lro_requested ^ lro_present) {
289 /* toggle the LRO feature*/
290 netdev->features ^= NETIF_F_LRO;
292 /* update harware LRO capability accordingly */
293 if (lro_requested)
294 adapter->shared->devRead.misc.uptFeatures |=
295 cpu_to_le64(UPT1_F_LRO);
296 else
297 adapter->shared->devRead.misc.uptFeatures &=
298 cpu_to_le64(~UPT1_F_LRO);
299 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
300 VMXNET3_CMD_UPDATE_FEATURE);
302 return 0;
305 static void
306 vmxnet3_get_ethtool_stats(struct net_device *netdev,
307 struct ethtool_stats *stats, u64 *buf)
309 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
310 u8 *base;
311 int i;
313 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
315 /* this does assume each counter is 64-bit wide */
317 base = (u8 *)&adapter->tqd_start->stats;
318 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++)
319 *buf++ = *(u64 *)(base + vmxnet3_tq_dev_stats[i].offset);
321 base = (u8 *)&adapter->tx_queue.stats;
322 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++)
323 *buf++ = *(u64 *)(base + vmxnet3_tq_driver_stats[i].offset);
325 base = (u8 *)&adapter->rqd_start->stats;
326 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++)
327 *buf++ = *(u64 *)(base + vmxnet3_rq_dev_stats[i].offset);
329 base = (u8 *)&adapter->rx_queue.stats;
330 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++)
331 *buf++ = *(u64 *)(base + vmxnet3_rq_driver_stats[i].offset);
333 base = (u8 *)adapter;
334 for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++)
335 *buf++ = *(u64 *)(base + vmxnet3_global_stats[i].offset);
339 static void
340 vmxnet3_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
342 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
343 u32 *buf = p;
345 memset(p, 0, vmxnet3_get_regs_len(netdev));
347 regs->version = 1;
349 /* Update vmxnet3_get_regs_len if we want to dump more registers */
351 /* make each ring use multiple of 16 bytes */
352 buf[0] = adapter->tx_queue.tx_ring.next2fill;
353 buf[1] = adapter->tx_queue.tx_ring.next2comp;
354 buf[2] = adapter->tx_queue.tx_ring.gen;
355 buf[3] = 0;
357 buf[4] = adapter->tx_queue.comp_ring.next2proc;
358 buf[5] = adapter->tx_queue.comp_ring.gen;
359 buf[6] = adapter->tx_queue.stopped;
360 buf[7] = 0;
362 buf[8] = adapter->rx_queue.rx_ring[0].next2fill;
363 buf[9] = adapter->rx_queue.rx_ring[0].next2comp;
364 buf[10] = adapter->rx_queue.rx_ring[0].gen;
365 buf[11] = 0;
367 buf[12] = adapter->rx_queue.rx_ring[1].next2fill;
368 buf[13] = adapter->rx_queue.rx_ring[1].next2comp;
369 buf[14] = adapter->rx_queue.rx_ring[1].gen;
370 buf[15] = 0;
372 buf[16] = adapter->rx_queue.comp_ring.next2proc;
373 buf[17] = adapter->rx_queue.comp_ring.gen;
374 buf[18] = 0;
375 buf[19] = 0;
379 static void
380 vmxnet3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
382 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
384 wol->supported = WAKE_UCAST | WAKE_ARP | WAKE_MAGIC;
385 wol->wolopts = adapter->wol;
389 static int
390 vmxnet3_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
392 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
394 if (wol->wolopts & (WAKE_PHY | WAKE_MCAST | WAKE_BCAST |
395 WAKE_MAGICSECURE)) {
396 return -EOPNOTSUPP;
399 adapter->wol = wol->wolopts;
401 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
403 return 0;
407 static int
408 vmxnet3_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
410 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
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;
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;
425 return 0;
429 static void
430 vmxnet3_get_ringparam(struct net_device *netdev,
431 struct ethtool_ringparam *param)
433 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
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;
440 param->rx_pending = adapter->rx_queue.rx_ring[0].size;
441 param->tx_pending = adapter->tx_queue.tx_ring.size;
442 param->rx_mini_pending = 0;
443 param->rx_jumbo_pending = 0;
447 static int
448 vmxnet3_set_ringparam(struct net_device *netdev,
449 struct ethtool_ringparam *param)
451 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
452 u32 new_tx_ring_size, new_rx_ring_size;
453 u32 sz;
454 int err = 0;
456 if (param->tx_pending == 0 || param->tx_pending >
457 VMXNET3_TX_RING_MAX_SIZE)
458 return -EINVAL;
460 if (param->rx_pending == 0 || param->rx_pending >
461 VMXNET3_RX_RING_MAX_SIZE)
462 return -EINVAL;
465 /* round it up to a multiple of VMXNET3_RING_SIZE_ALIGN */
466 new_tx_ring_size = (param->tx_pending + VMXNET3_RING_SIZE_MASK) &
467 ~VMXNET3_RING_SIZE_MASK;
468 new_tx_ring_size = min_t(u32, new_tx_ring_size,
469 VMXNET3_TX_RING_MAX_SIZE);
470 if (new_tx_ring_size > VMXNET3_TX_RING_MAX_SIZE || (new_tx_ring_size %
471 VMXNET3_RING_SIZE_ALIGN) != 0)
472 return -EINVAL;
474 /* ring0 has to be a multiple of
475 * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN
477 sz = adapter->rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN;
478 new_rx_ring_size = (param->rx_pending + sz - 1) / sz * sz;
479 new_rx_ring_size = min_t(u32, new_rx_ring_size,
480 VMXNET3_RX_RING_MAX_SIZE / sz * sz);
481 if (new_rx_ring_size > VMXNET3_RX_RING_MAX_SIZE || (new_rx_ring_size %
482 sz) != 0)
483 return -EINVAL;
485 if (new_tx_ring_size == adapter->tx_queue.tx_ring.size &&
486 new_rx_ring_size == adapter->rx_queue.rx_ring[0].size) {
487 return 0;
491 * Reset_work may be in the middle of resetting the device, wait for its
492 * completion.
494 while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
495 msleep(1);
497 if (netif_running(netdev)) {
498 vmxnet3_quiesce_dev(adapter);
499 vmxnet3_reset_dev(adapter);
501 /* recreate the rx queue and the tx queue based on the
502 * new sizes */
503 vmxnet3_tq_destroy(&adapter->tx_queue, adapter);
504 vmxnet3_rq_destroy(&adapter->rx_queue, adapter);
506 err = vmxnet3_create_queues(adapter, new_tx_ring_size,
507 new_rx_ring_size, VMXNET3_DEF_RX_RING_SIZE);
508 if (err) {
509 /* failed, most likely because of OOM, try default
510 * size */
511 printk(KERN_ERR "%s: failed to apply new sizes, try the"
512 " default ones\n", netdev->name);
513 err = vmxnet3_create_queues(adapter,
514 VMXNET3_DEF_TX_RING_SIZE,
515 VMXNET3_DEF_RX_RING_SIZE,
516 VMXNET3_DEF_RX_RING_SIZE);
517 if (err) {
518 printk(KERN_ERR "%s: failed to create queues "
519 "with default sizes. Closing it\n",
520 netdev->name);
521 goto out;
525 err = vmxnet3_activate_dev(adapter);
526 if (err)
527 printk(KERN_ERR "%s: failed to re-activate, error %d."
528 " Closing it\n", netdev->name, err);
531 out:
532 clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
533 if (err)
534 vmxnet3_force_close(adapter);
536 return err;
540 static struct ethtool_ops vmxnet3_ethtool_ops = {
541 .get_settings = vmxnet3_get_settings,
542 .get_drvinfo = vmxnet3_get_drvinfo,
543 .get_regs_len = vmxnet3_get_regs_len,
544 .get_regs = vmxnet3_get_regs,
545 .get_wol = vmxnet3_get_wol,
546 .set_wol = vmxnet3_set_wol,
547 .get_link = ethtool_op_get_link,
548 .get_rx_csum = vmxnet3_get_rx_csum,
549 .set_rx_csum = vmxnet3_set_rx_csum,
550 .get_tx_csum = ethtool_op_get_tx_csum,
551 .set_tx_csum = ethtool_op_set_tx_hw_csum,
552 .get_sg = ethtool_op_get_sg,
553 .set_sg = ethtool_op_set_sg,
554 .get_tso = ethtool_op_get_tso,
555 .set_tso = ethtool_op_set_tso,
556 .get_strings = vmxnet3_get_strings,
557 .get_flags = ethtool_op_get_flags,
558 .set_flags = vmxnet3_set_flags,
559 .get_sset_count = vmxnet3_get_sset_count,
560 .get_ethtool_stats = vmxnet3_get_ethtool_stats,
561 .get_ringparam = vmxnet3_get_ringparam,
562 .set_ringparam = vmxnet3_set_ringparam,
565 void vmxnet3_set_ethtool_ops(struct net_device *netdev)
567 SET_ETHTOOL_OPS(netdev, &vmxnet3_ethtool_ops);