2 * Linux driver for VMware's vmxnet3 ethernet NIC.
4 * Copyright (C) 2008-2016, 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
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: pv-drivers@vmware.com
28 #include "vmxnet3_int.h"
30 struct vmxnet3_stat_desc {
31 char desc[ETH_GSTRING_LEN];
36 /* per tq stats maintained by the device */
37 static const struct vmxnet3_stat_desc
38 vmxnet3_tq_dev_stats[] = {
39 /* description, offset */
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) },
53 /* per tq stats maintained by the driver */
54 static const struct vmxnet3_stat_desc
55 vmxnet3_tq_driver_stats[] = {
56 /* description, offset */
57 {" drv dropped tx total", offsetof(struct vmxnet3_tq_driver_stats,
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,
67 { " ring full", offsetof(struct vmxnet3_tq_driver_stats,
69 { " pkts linearized", offsetof(struct vmxnet3_tq_driver_stats,
71 { " hdr cloned", offsetof(struct vmxnet3_tq_driver_stats,
73 { " giant hdr", offsetof(struct vmxnet3_tq_driver_stats,
77 /* per rq stats maintained by the device */
78 static const struct vmxnet3_stat_desc
79 vmxnet3_rq_dev_stats[] = {
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) },
93 /* per rq stats maintained by the driver */
94 static const struct vmxnet3_stat_desc
95 vmxnet3_rq_driver_stats[] = {
96 /* description, offset */
97 { " drv dropped rx total", offsetof(struct vmxnet3_rq_driver_stats,
99 { " err", offsetof(struct vmxnet3_rq_driver_stats,
101 { " fcs", offsetof(struct vmxnet3_rq_driver_stats,
103 { " rx buf alloc fail", offsetof(struct vmxnet3_rq_driver_stats,
104 rx_buf_alloc_failure) },
107 /* global stats maintained by the driver */
108 static const struct vmxnet3_stat_desc
109 vmxnet3_global_stats[] = {
110 /* description, offset */
111 { "tx timeout count", offsetof(struct vmxnet3_adapter,
116 struct rtnl_link_stats64 *
117 vmxnet3_get_stats64(struct net_device *netdev,
118 struct rtnl_link_stats64 *stats)
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;
128 adapter = netdev_priv(netdev);
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);
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;
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;
155 stats->rx_bytes += devRxStats->ucastBytesRxOK +
156 devRxStats->mcastBytesRxOK +
157 devRxStats->bcastBytesRxOK;
159 stats->rx_errors += devRxStats->pktsRxError;
160 stats->rx_dropped += drvRxStats->drop_total;
161 stats->multicast += devRxStats->mcastPktsRxOK;
168 vmxnet3_get_sset_count(struct net_device *netdev, int sset)
170 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
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);
186 /* This is a version 2 of the vmxnet3 ethtool_regs which goes hand in hand with
187 * the version 2 of the vmxnet3 support for ethtool(8) --register-dump.
188 * Therefore, if any registers are added, removed or modified, then a version
189 * bump and a corresponding change in the vmxnet3 support for ethtool(8)
190 * --register-dump would be required.
193 vmxnet3_get_regs_len(struct net_device *netdev)
195 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
197 return ((9 /* BAR1 registers */ +
198 (1 + adapter->intr.num_intrs) +
199 (1 + adapter->num_tx_queues * 17 /* Tx queue registers */) +
200 (1 + adapter->num_rx_queues * 23 /* Rx queue registers */)) *
206 vmxnet3_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
208 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
210 strlcpy(drvinfo->driver, vmxnet3_driver_name, sizeof(drvinfo->driver));
212 strlcpy(drvinfo->version, VMXNET3_DRIVER_VERSION_REPORT,
213 sizeof(drvinfo->version));
215 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
216 sizeof(drvinfo->bus_info));
221 vmxnet3_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
223 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
224 if (stringset == ETH_SS_STATS) {
226 for (j = 0; j < adapter->num_tx_queues; j++) {
227 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++) {
228 memcpy(buf, vmxnet3_tq_dev_stats[i].desc,
230 buf += ETH_GSTRING_LEN;
232 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats);
234 memcpy(buf, vmxnet3_tq_driver_stats[i].desc,
236 buf += ETH_GSTRING_LEN;
240 for (j = 0; j < adapter->num_rx_queues; j++) {
241 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++) {
242 memcpy(buf, vmxnet3_rq_dev_stats[i].desc,
244 buf += ETH_GSTRING_LEN;
246 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats);
248 memcpy(buf, vmxnet3_rq_driver_stats[i].desc,
250 buf += ETH_GSTRING_LEN;
254 for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++) {
255 memcpy(buf, vmxnet3_global_stats[i].desc,
257 buf += ETH_GSTRING_LEN;
262 int vmxnet3_set_features(struct net_device *netdev, netdev_features_t features)
264 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
266 netdev_features_t changed = features ^ netdev->features;
268 if (changed & (NETIF_F_RXCSUM | NETIF_F_LRO |
269 NETIF_F_HW_VLAN_CTAG_RX)) {
270 if (features & NETIF_F_RXCSUM)
271 adapter->shared->devRead.misc.uptFeatures |=
274 adapter->shared->devRead.misc.uptFeatures &=
277 /* update hardware LRO capability accordingly */
278 if (features & NETIF_F_LRO)
279 adapter->shared->devRead.misc.uptFeatures |=
282 adapter->shared->devRead.misc.uptFeatures &=
285 if (features & NETIF_F_HW_VLAN_CTAG_RX)
286 adapter->shared->devRead.misc.uptFeatures |=
289 adapter->shared->devRead.misc.uptFeatures &=
292 spin_lock_irqsave(&adapter->cmd_lock, flags);
293 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
294 VMXNET3_CMD_UPDATE_FEATURE);
295 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
301 vmxnet3_get_ethtool_stats(struct net_device *netdev,
302 struct ethtool_stats *stats, u64 *buf)
304 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
310 spin_lock_irqsave(&adapter->cmd_lock, flags);
311 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
312 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
314 /* this does assume each counter is 64-bit wide */
315 for (j = 0; j < adapter->num_tx_queues; j++) {
316 base = (u8 *)&adapter->tqd_start[j].stats;
318 for (i = 1; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++)
319 *buf++ = *(u64 *)(base +
320 vmxnet3_tq_dev_stats[i].offset);
322 base = (u8 *)&adapter->tx_queue[j].stats;
323 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++)
324 *buf++ = *(u64 *)(base +
325 vmxnet3_tq_driver_stats[i].offset);
328 for (j = 0; j < adapter->num_rx_queues; j++) {
329 base = (u8 *)&adapter->rqd_start[j].stats;
331 for (i = 1; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++)
332 *buf++ = *(u64 *)(base +
333 vmxnet3_rq_dev_stats[i].offset);
335 base = (u8 *)&adapter->rx_queue[j].stats;
336 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++)
337 *buf++ = *(u64 *)(base +
338 vmxnet3_rq_driver_stats[i].offset);
341 base = (u8 *)adapter;
342 for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++)
343 *buf++ = *(u64 *)(base + vmxnet3_global_stats[i].offset);
347 /* This is a version 2 of the vmxnet3 ethtool_regs which goes hand in hand with
348 * the version 2 of the vmxnet3 support for ethtool(8) --register-dump.
349 * Therefore, if any registers are added, removed or modified, then a version
350 * bump and a corresponding change in the vmxnet3 support for ethtool(8)
351 * --register-dump would be required.
354 vmxnet3_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
356 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
360 memset(p, 0, vmxnet3_get_regs_len(netdev));
364 /* Update vmxnet3_get_regs_len if we want to dump more registers */
366 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_VRRS);
367 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_UVRS);
368 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_DSAL);
369 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_DSAH);
370 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_CMD);
371 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_MACL);
372 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_MACH);
373 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_ICR);
374 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_ECR);
376 buf[j++] = adapter->intr.num_intrs;
377 for (i = 0; i < adapter->intr.num_intrs; i++) {
378 buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_IMR
379 + i * VMXNET3_REG_ALIGN);
382 buf[j++] = adapter->num_tx_queues;
383 for (i = 0; i < adapter->num_tx_queues; i++) {
384 struct vmxnet3_tx_queue *tq = &adapter->tx_queue[i];
386 buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_TXPROD +
387 i * VMXNET3_REG_ALIGN);
389 buf[j++] = VMXNET3_GET_ADDR_LO(tq->tx_ring.basePA);
390 buf[j++] = VMXNET3_GET_ADDR_HI(tq->tx_ring.basePA);
391 buf[j++] = tq->tx_ring.size;
392 buf[j++] = tq->tx_ring.next2fill;
393 buf[j++] = tq->tx_ring.next2comp;
394 buf[j++] = tq->tx_ring.gen;
396 buf[j++] = VMXNET3_GET_ADDR_LO(tq->data_ring.basePA);
397 buf[j++] = VMXNET3_GET_ADDR_HI(tq->data_ring.basePA);
398 buf[j++] = tq->data_ring.size;
399 buf[j++] = tq->txdata_desc_size;
401 buf[j++] = VMXNET3_GET_ADDR_LO(tq->comp_ring.basePA);
402 buf[j++] = VMXNET3_GET_ADDR_HI(tq->comp_ring.basePA);
403 buf[j++] = tq->comp_ring.size;
404 buf[j++] = tq->comp_ring.next2proc;
405 buf[j++] = tq->comp_ring.gen;
407 buf[j++] = tq->stopped;
410 buf[j++] = adapter->num_rx_queues;
411 for (i = 0; i < adapter->num_rx_queues; i++) {
412 struct vmxnet3_rx_queue *rq = &adapter->rx_queue[i];
414 buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_RXPROD +
415 i * VMXNET3_REG_ALIGN);
416 buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_RXPROD2 +
417 i * VMXNET3_REG_ALIGN);
419 buf[j++] = VMXNET3_GET_ADDR_LO(rq->rx_ring[0].basePA);
420 buf[j++] = VMXNET3_GET_ADDR_HI(rq->rx_ring[0].basePA);
421 buf[j++] = rq->rx_ring[0].size;
422 buf[j++] = rq->rx_ring[0].next2fill;
423 buf[j++] = rq->rx_ring[0].next2comp;
424 buf[j++] = rq->rx_ring[0].gen;
426 buf[j++] = VMXNET3_GET_ADDR_LO(rq->rx_ring[1].basePA);
427 buf[j++] = VMXNET3_GET_ADDR_HI(rq->rx_ring[1].basePA);
428 buf[j++] = rq->rx_ring[1].size;
429 buf[j++] = rq->rx_ring[1].next2fill;
430 buf[j++] = rq->rx_ring[1].next2comp;
431 buf[j++] = rq->rx_ring[1].gen;
433 buf[j++] = VMXNET3_GET_ADDR_LO(rq->data_ring.basePA);
434 buf[j++] = VMXNET3_GET_ADDR_HI(rq->data_ring.basePA);
435 buf[j++] = rq->rx_ring[0].size;
436 buf[j++] = rq->data_ring.desc_size;
438 buf[j++] = VMXNET3_GET_ADDR_LO(rq->comp_ring.basePA);
439 buf[j++] = VMXNET3_GET_ADDR_HI(rq->comp_ring.basePA);
440 buf[j++] = rq->comp_ring.size;
441 buf[j++] = rq->comp_ring.next2proc;
442 buf[j++] = rq->comp_ring.gen;
448 vmxnet3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
450 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
452 wol->supported = WAKE_UCAST | WAKE_ARP | WAKE_MAGIC;
453 wol->wolopts = adapter->wol;
458 vmxnet3_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
460 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
462 if (wol->wolopts & (WAKE_PHY | WAKE_MCAST | WAKE_BCAST |
467 adapter->wol = wol->wolopts;
469 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
476 vmxnet3_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
478 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
480 ecmd->supported = SUPPORTED_10000baseT_Full | SUPPORTED_1000baseT_Full |
482 ecmd->advertising = ADVERTISED_TP;
483 ecmd->port = PORT_TP;
484 ecmd->transceiver = XCVR_INTERNAL;
486 if (adapter->link_speed) {
487 ethtool_cmd_speed_set(ecmd, adapter->link_speed);
488 ecmd->duplex = DUPLEX_FULL;
490 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
491 ecmd->duplex = DUPLEX_UNKNOWN;
498 vmxnet3_get_ringparam(struct net_device *netdev,
499 struct ethtool_ringparam *param)
501 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
503 param->rx_max_pending = VMXNET3_RX_RING_MAX_SIZE;
504 param->tx_max_pending = VMXNET3_TX_RING_MAX_SIZE;
505 param->rx_mini_max_pending = VMXNET3_VERSION_GE_3(adapter) ?
506 VMXNET3_RXDATA_DESC_MAX_SIZE : 0;
507 param->rx_jumbo_max_pending = VMXNET3_RX_RING2_MAX_SIZE;
509 param->rx_pending = adapter->rx_ring_size;
510 param->tx_pending = adapter->tx_ring_size;
511 param->rx_mini_pending = VMXNET3_VERSION_GE_3(adapter) ?
512 adapter->rxdata_desc_size : 0;
513 param->rx_jumbo_pending = adapter->rx_ring2_size;
518 vmxnet3_set_ringparam(struct net_device *netdev,
519 struct ethtool_ringparam *param)
521 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
522 u32 new_tx_ring_size, new_rx_ring_size, new_rx_ring2_size;
523 u16 new_rxdata_desc_size;
527 if (param->tx_pending == 0 || param->tx_pending >
528 VMXNET3_TX_RING_MAX_SIZE)
531 if (param->rx_pending == 0 || param->rx_pending >
532 VMXNET3_RX_RING_MAX_SIZE)
535 if (param->rx_jumbo_pending == 0 ||
536 param->rx_jumbo_pending > VMXNET3_RX_RING2_MAX_SIZE)
539 /* if adapter not yet initialized, do nothing */
540 if (adapter->rx_buf_per_pkt == 0) {
541 netdev_err(netdev, "adapter not completely initialized, "
542 "ring size cannot be changed yet\n");
546 if (VMXNET3_VERSION_GE_3(adapter)) {
547 if (param->rx_mini_pending < 0 ||
548 param->rx_mini_pending > VMXNET3_RXDATA_DESC_MAX_SIZE) {
551 } else if (param->rx_mini_pending != 0) {
555 /* round it up to a multiple of VMXNET3_RING_SIZE_ALIGN */
556 new_tx_ring_size = (param->tx_pending + VMXNET3_RING_SIZE_MASK) &
557 ~VMXNET3_RING_SIZE_MASK;
558 new_tx_ring_size = min_t(u32, new_tx_ring_size,
559 VMXNET3_TX_RING_MAX_SIZE);
560 if (new_tx_ring_size > VMXNET3_TX_RING_MAX_SIZE || (new_tx_ring_size %
561 VMXNET3_RING_SIZE_ALIGN) != 0)
564 /* ring0 has to be a multiple of
565 * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN
567 sz = adapter->rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN;
568 new_rx_ring_size = (param->rx_pending + sz - 1) / sz * sz;
569 new_rx_ring_size = min_t(u32, new_rx_ring_size,
570 VMXNET3_RX_RING_MAX_SIZE / sz * sz);
571 if (new_rx_ring_size > VMXNET3_RX_RING_MAX_SIZE || (new_rx_ring_size %
575 /* ring2 has to be a multiple of VMXNET3_RING_SIZE_ALIGN */
576 new_rx_ring2_size = (param->rx_jumbo_pending + VMXNET3_RING_SIZE_MASK) &
577 ~VMXNET3_RING_SIZE_MASK;
578 new_rx_ring2_size = min_t(u32, new_rx_ring2_size,
579 VMXNET3_RX_RING2_MAX_SIZE);
581 /* rx data ring buffer size has to be a multiple of
582 * VMXNET3_RXDATA_DESC_SIZE_ALIGN
584 new_rxdata_desc_size =
585 (param->rx_mini_pending + VMXNET3_RXDATA_DESC_SIZE_MASK) &
586 ~VMXNET3_RXDATA_DESC_SIZE_MASK;
587 new_rxdata_desc_size = min_t(u16, new_rxdata_desc_size,
588 VMXNET3_RXDATA_DESC_MAX_SIZE);
590 if (new_tx_ring_size == adapter->tx_ring_size &&
591 new_rx_ring_size == adapter->rx_ring_size &&
592 new_rx_ring2_size == adapter->rx_ring2_size &&
593 new_rxdata_desc_size == adapter->rxdata_desc_size) {
598 * Reset_work may be in the middle of resetting the device, wait for its
601 while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
604 if (netif_running(netdev)) {
605 vmxnet3_quiesce_dev(adapter);
606 vmxnet3_reset_dev(adapter);
608 /* recreate the rx queue and the tx queue based on the
610 vmxnet3_tq_destroy_all(adapter);
611 vmxnet3_rq_destroy_all(adapter);
613 err = vmxnet3_create_queues(adapter, new_tx_ring_size,
614 new_rx_ring_size, new_rx_ring2_size,
615 adapter->txdata_desc_size,
616 new_rxdata_desc_size);
618 /* failed, most likely because of OOM, try default
620 netdev_err(netdev, "failed to apply new sizes, "
621 "try the default ones\n");
622 new_rx_ring_size = VMXNET3_DEF_RX_RING_SIZE;
623 new_rx_ring2_size = VMXNET3_DEF_RX_RING2_SIZE;
624 new_tx_ring_size = VMXNET3_DEF_TX_RING_SIZE;
625 new_rxdata_desc_size = VMXNET3_VERSION_GE_3(adapter) ?
626 VMXNET3_DEF_RXDATA_DESC_SIZE : 0;
628 err = vmxnet3_create_queues(adapter,
632 adapter->txdata_desc_size,
633 new_rxdata_desc_size);
635 netdev_err(netdev, "failed to create queues "
636 "with default sizes. Closing it\n");
641 err = vmxnet3_activate_dev(adapter);
643 netdev_err(netdev, "failed to re-activate, error %d."
644 " Closing it\n", err);
646 adapter->tx_ring_size = new_tx_ring_size;
647 adapter->rx_ring_size = new_rx_ring_size;
648 adapter->rx_ring2_size = new_rx_ring2_size;
649 adapter->rxdata_desc_size = new_rxdata_desc_size;
652 clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
654 vmxnet3_force_close(adapter);
661 vmxnet3_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info,
664 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
666 case ETHTOOL_GRXRINGS:
667 info->data = adapter->num_rx_queues;
675 vmxnet3_get_rss_indir_size(struct net_device *netdev)
677 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
678 struct UPT1_RSSConf *rssConf = adapter->rss_conf;
680 return rssConf->indTableSize;
684 vmxnet3_get_rss(struct net_device *netdev, u32 *p, u8 *key, u8 *hfunc)
686 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
687 struct UPT1_RSSConf *rssConf = adapter->rss_conf;
688 unsigned int n = rssConf->indTableSize;
691 *hfunc = ETH_RSS_HASH_TOP;
694 if (n > UPT1_RSS_MAX_IND_TABLE_SIZE)
697 p[n] = rssConf->indTable[n];
703 vmxnet3_set_rss(struct net_device *netdev, const u32 *p, const u8 *key,
708 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
709 struct UPT1_RSSConf *rssConf = adapter->rss_conf;
711 /* We do not allow change in unsupported parameters */
713 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
717 for (i = 0; i < rssConf->indTableSize; i++)
718 rssConf->indTable[i] = p[i];
720 spin_lock_irqsave(&adapter->cmd_lock, flags);
721 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
722 VMXNET3_CMD_UPDATE_RSSIDT);
723 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
731 vmxnet3_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
733 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
735 if (!VMXNET3_VERSION_GE_3(adapter))
738 switch (adapter->coal_conf->coalMode) {
739 case VMXNET3_COALESCE_DISABLED:
740 /* struct ethtool_coalesce is already initialized to 0 */
742 case VMXNET3_COALESCE_ADAPT:
743 ec->use_adaptive_rx_coalesce = true;
745 case VMXNET3_COALESCE_STATIC:
746 ec->tx_max_coalesced_frames =
747 adapter->coal_conf->coalPara.coalStatic.tx_comp_depth;
748 ec->rx_max_coalesced_frames =
749 adapter->coal_conf->coalPara.coalStatic.rx_depth;
751 case VMXNET3_COALESCE_RBC: {
754 rbc_rate = adapter->coal_conf->coalPara.coalRbc.rbc_rate;
755 ec->rx_coalesce_usecs = VMXNET3_COAL_RBC_USECS(rbc_rate);
766 vmxnet3_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
768 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
769 struct Vmxnet3_DriverShared *shared = adapter->shared;
770 union Vmxnet3_CmdInfo *cmdInfo = &shared->cu.cmdInfo;
773 if (!VMXNET3_VERSION_GE_3(adapter))
776 if (ec->rx_coalesce_usecs_irq ||
777 ec->rx_max_coalesced_frames_irq ||
778 ec->tx_coalesce_usecs ||
779 ec->tx_coalesce_usecs_irq ||
780 ec->tx_max_coalesced_frames_irq ||
781 ec->stats_block_coalesce_usecs ||
782 ec->use_adaptive_tx_coalesce ||
784 ec->rx_coalesce_usecs_low ||
785 ec->rx_max_coalesced_frames_low ||
786 ec->tx_coalesce_usecs_low ||
787 ec->tx_max_coalesced_frames_low ||
789 ec->rx_coalesce_usecs_high ||
790 ec->rx_max_coalesced_frames_high ||
791 ec->tx_coalesce_usecs_high ||
792 ec->tx_max_coalesced_frames_high ||
793 ec->rate_sample_interval) {
797 if ((ec->rx_coalesce_usecs == 0) &&
798 (ec->use_adaptive_rx_coalesce == 0) &&
799 (ec->tx_max_coalesced_frames == 0) &&
800 (ec->rx_max_coalesced_frames == 0)) {
801 memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
802 adapter->coal_conf->coalMode = VMXNET3_COALESCE_DISABLED;
806 if (ec->rx_coalesce_usecs != 0) {
809 if ((ec->use_adaptive_rx_coalesce != 0) ||
810 (ec->tx_max_coalesced_frames != 0) ||
811 (ec->rx_max_coalesced_frames != 0)) {
815 rbc_rate = VMXNET3_COAL_RBC_RATE(ec->rx_coalesce_usecs);
816 if (rbc_rate < VMXNET3_COAL_RBC_MIN_RATE ||
817 rbc_rate > VMXNET3_COAL_RBC_MAX_RATE) {
821 memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
822 adapter->coal_conf->coalMode = VMXNET3_COALESCE_RBC;
823 adapter->coal_conf->coalPara.coalRbc.rbc_rate = rbc_rate;
827 if (ec->use_adaptive_rx_coalesce != 0) {
828 if ((ec->rx_coalesce_usecs != 0) ||
829 (ec->tx_max_coalesced_frames != 0) ||
830 (ec->rx_max_coalesced_frames != 0)) {
833 memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
834 adapter->coal_conf->coalMode = VMXNET3_COALESCE_ADAPT;
838 if ((ec->tx_max_coalesced_frames != 0) ||
839 (ec->rx_max_coalesced_frames != 0)) {
840 if ((ec->rx_coalesce_usecs != 0) ||
841 (ec->use_adaptive_rx_coalesce != 0)) {
845 if ((ec->tx_max_coalesced_frames >
846 VMXNET3_COAL_STATIC_MAX_DEPTH) ||
847 (ec->rx_max_coalesced_frames >
848 VMXNET3_COAL_STATIC_MAX_DEPTH)) {
852 memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
853 adapter->coal_conf->coalMode = VMXNET3_COALESCE_STATIC;
855 adapter->coal_conf->coalPara.coalStatic.tx_comp_depth =
856 (ec->tx_max_coalesced_frames ?
857 ec->tx_max_coalesced_frames :
858 VMXNET3_COAL_STATIC_DEFAULT_DEPTH);
860 adapter->coal_conf->coalPara.coalStatic.rx_depth =
861 (ec->rx_max_coalesced_frames ?
862 ec->rx_max_coalesced_frames :
863 VMXNET3_COAL_STATIC_DEFAULT_DEPTH);
865 adapter->coal_conf->coalPara.coalStatic.tx_depth =
866 VMXNET3_COAL_STATIC_DEFAULT_DEPTH;
871 adapter->default_coal_mode = false;
872 if (netif_running(netdev)) {
873 spin_lock_irqsave(&adapter->cmd_lock, flags);
874 cmdInfo->varConf.confVer = 1;
875 cmdInfo->varConf.confLen =
876 cpu_to_le32(sizeof(*adapter->coal_conf));
877 cmdInfo->varConf.confPA = cpu_to_le64(adapter->coal_conf_pa);
878 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
879 VMXNET3_CMD_SET_COALESCE);
880 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
886 static const struct ethtool_ops vmxnet3_ethtool_ops = {
887 .get_settings = vmxnet3_get_settings,
888 .get_drvinfo = vmxnet3_get_drvinfo,
889 .get_regs_len = vmxnet3_get_regs_len,
890 .get_regs = vmxnet3_get_regs,
891 .get_wol = vmxnet3_get_wol,
892 .set_wol = vmxnet3_set_wol,
893 .get_link = ethtool_op_get_link,
894 .get_coalesce = vmxnet3_get_coalesce,
895 .set_coalesce = vmxnet3_set_coalesce,
896 .get_strings = vmxnet3_get_strings,
897 .get_sset_count = vmxnet3_get_sset_count,
898 .get_ethtool_stats = vmxnet3_get_ethtool_stats,
899 .get_ringparam = vmxnet3_get_ringparam,
900 .set_ringparam = vmxnet3_set_ringparam,
901 .get_rxnfc = vmxnet3_get_rxnfc,
903 .get_rxfh_indir_size = vmxnet3_get_rss_indir_size,
904 .get_rxfh = vmxnet3_get_rss,
905 .set_rxfh = vmxnet3_set_rss,
909 void vmxnet3_set_ethtool_ops(struct net_device *netdev)
911 netdev->ethtool_ops = &vmxnet3_ethtool_ops;