2 * Linux driver for VMware's vmxnet3 ethernet NIC.
4 * Copyright (C) 2008-2020, 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,
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;
166 vmxnet3_get_sset_count(struct net_device *netdev, int sset)
168 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
171 return (ARRAY_SIZE(vmxnet3_tq_dev_stats) +
172 ARRAY_SIZE(vmxnet3_tq_driver_stats)) *
173 adapter->num_tx_queues +
174 (ARRAY_SIZE(vmxnet3_rq_dev_stats) +
175 ARRAY_SIZE(vmxnet3_rq_driver_stats)) *
176 adapter->num_rx_queues +
177 ARRAY_SIZE(vmxnet3_global_stats);
184 /* This is a version 2 of the vmxnet3 ethtool_regs which goes hand in hand with
185 * the version 2 of the vmxnet3 support for ethtool(8) --register-dump.
186 * Therefore, if any registers are added, removed or modified, then a version
187 * bump and a corresponding change in the vmxnet3 support for ethtool(8)
188 * --register-dump would be required.
191 vmxnet3_get_regs_len(struct net_device *netdev)
193 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
195 return ((9 /* BAR1 registers */ +
196 (1 + adapter->intr.num_intrs) +
197 (1 + adapter->num_tx_queues * 17 /* Tx queue registers */) +
198 (1 + adapter->num_rx_queues * 23 /* Rx queue registers */)) *
204 vmxnet3_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
206 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
208 strlcpy(drvinfo->driver, vmxnet3_driver_name, sizeof(drvinfo->driver));
210 strlcpy(drvinfo->version, VMXNET3_DRIVER_VERSION_REPORT,
211 sizeof(drvinfo->version));
213 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
214 sizeof(drvinfo->bus_info));
219 vmxnet3_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
221 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
222 if (stringset == ETH_SS_STATS) {
224 for (j = 0; j < adapter->num_tx_queues; j++) {
225 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++) {
226 memcpy(buf, vmxnet3_tq_dev_stats[i].desc,
228 buf += ETH_GSTRING_LEN;
230 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats);
232 memcpy(buf, vmxnet3_tq_driver_stats[i].desc,
234 buf += ETH_GSTRING_LEN;
238 for (j = 0; j < adapter->num_rx_queues; j++) {
239 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++) {
240 memcpy(buf, vmxnet3_rq_dev_stats[i].desc,
242 buf += ETH_GSTRING_LEN;
244 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats);
246 memcpy(buf, vmxnet3_rq_driver_stats[i].desc,
248 buf += ETH_GSTRING_LEN;
252 for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++) {
253 memcpy(buf, vmxnet3_global_stats[i].desc,
255 buf += ETH_GSTRING_LEN;
260 netdev_features_t vmxnet3_fix_features(struct net_device *netdev,
261 netdev_features_t features)
263 /* If Rx checksum is disabled, then LRO should also be disabled */
264 if (!(features & NETIF_F_RXCSUM))
265 features &= ~NETIF_F_LRO;
270 static void vmxnet3_enable_encap_offloads(struct net_device *netdev)
272 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
274 if (VMXNET3_VERSION_GE_4(adapter)) {
275 netdev->hw_enc_features |= NETIF_F_SG | NETIF_F_RXCSUM |
276 NETIF_F_HW_CSUM | NETIF_F_HW_VLAN_CTAG_TX |
277 NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_TSO | NETIF_F_TSO6 |
278 NETIF_F_LRO | NETIF_F_GSO_UDP_TUNNEL |
279 NETIF_F_GSO_UDP_TUNNEL_CSUM;
283 static void vmxnet3_disable_encap_offloads(struct net_device *netdev)
285 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
287 if (VMXNET3_VERSION_GE_4(adapter)) {
288 netdev->hw_enc_features &= ~(NETIF_F_SG | NETIF_F_RXCSUM |
289 NETIF_F_HW_CSUM | NETIF_F_HW_VLAN_CTAG_TX |
290 NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_TSO | NETIF_F_TSO6 |
291 NETIF_F_LRO | NETIF_F_GSO_UDP_TUNNEL |
292 NETIF_F_GSO_UDP_TUNNEL_CSUM);
296 int vmxnet3_set_features(struct net_device *netdev, netdev_features_t features)
298 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
300 netdev_features_t changed = features ^ netdev->features;
301 netdev_features_t tun_offload_mask = NETIF_F_GSO_UDP_TUNNEL |
302 NETIF_F_GSO_UDP_TUNNEL_CSUM;
303 u8 udp_tun_enabled = (netdev->features & tun_offload_mask) != 0;
305 if (changed & (NETIF_F_RXCSUM | NETIF_F_LRO |
306 NETIF_F_HW_VLAN_CTAG_RX | tun_offload_mask)) {
307 if (features & NETIF_F_RXCSUM)
308 adapter->shared->devRead.misc.uptFeatures |=
311 adapter->shared->devRead.misc.uptFeatures &=
314 /* update hardware LRO capability accordingly */
315 if (features & NETIF_F_LRO)
316 adapter->shared->devRead.misc.uptFeatures |=
319 adapter->shared->devRead.misc.uptFeatures &=
322 if (features & NETIF_F_HW_VLAN_CTAG_RX)
323 adapter->shared->devRead.misc.uptFeatures |=
326 adapter->shared->devRead.misc.uptFeatures &=
329 if ((features & tun_offload_mask) != 0 && !udp_tun_enabled) {
330 vmxnet3_enable_encap_offloads(netdev);
331 adapter->shared->devRead.misc.uptFeatures |=
333 } else if ((features & tun_offload_mask) == 0 &&
335 vmxnet3_disable_encap_offloads(netdev);
336 adapter->shared->devRead.misc.uptFeatures &=
340 spin_lock_irqsave(&adapter->cmd_lock, flags);
341 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
342 VMXNET3_CMD_UPDATE_FEATURE);
343 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
349 vmxnet3_get_ethtool_stats(struct net_device *netdev,
350 struct ethtool_stats *stats, u64 *buf)
352 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
358 spin_lock_irqsave(&adapter->cmd_lock, flags);
359 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
360 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
362 /* this does assume each counter is 64-bit wide */
363 for (j = 0; j < adapter->num_tx_queues; j++) {
364 base = (u8 *)&adapter->tqd_start[j].stats;
366 for (i = 1; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++)
367 *buf++ = *(u64 *)(base +
368 vmxnet3_tq_dev_stats[i].offset);
370 base = (u8 *)&adapter->tx_queue[j].stats;
371 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++)
372 *buf++ = *(u64 *)(base +
373 vmxnet3_tq_driver_stats[i].offset);
376 for (j = 0; j < adapter->num_rx_queues; j++) {
377 base = (u8 *)&adapter->rqd_start[j].stats;
379 for (i = 1; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++)
380 *buf++ = *(u64 *)(base +
381 vmxnet3_rq_dev_stats[i].offset);
383 base = (u8 *)&adapter->rx_queue[j].stats;
384 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++)
385 *buf++ = *(u64 *)(base +
386 vmxnet3_rq_driver_stats[i].offset);
389 base = (u8 *)adapter;
390 for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++)
391 *buf++ = *(u64 *)(base + vmxnet3_global_stats[i].offset);
395 /* This is a version 2 of the vmxnet3 ethtool_regs which goes hand in hand with
396 * the version 2 of the vmxnet3 support for ethtool(8) --register-dump.
397 * Therefore, if any registers are added, removed or modified, then a version
398 * bump and a corresponding change in the vmxnet3 support for ethtool(8)
399 * --register-dump would be required.
402 vmxnet3_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
404 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
408 memset(p, 0, vmxnet3_get_regs_len(netdev));
412 /* Update vmxnet3_get_regs_len if we want to dump more registers */
414 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_VRRS);
415 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_UVRS);
416 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_DSAL);
417 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_DSAH);
418 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_CMD);
419 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_MACL);
420 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_MACH);
421 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_ICR);
422 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_ECR);
424 buf[j++] = adapter->intr.num_intrs;
425 for (i = 0; i < adapter->intr.num_intrs; i++) {
426 buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_IMR
427 + i * VMXNET3_REG_ALIGN);
430 buf[j++] = adapter->num_tx_queues;
431 for (i = 0; i < adapter->num_tx_queues; i++) {
432 struct vmxnet3_tx_queue *tq = &adapter->tx_queue[i];
434 buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_TXPROD +
435 i * VMXNET3_REG_ALIGN);
437 buf[j++] = VMXNET3_GET_ADDR_LO(tq->tx_ring.basePA);
438 buf[j++] = VMXNET3_GET_ADDR_HI(tq->tx_ring.basePA);
439 buf[j++] = tq->tx_ring.size;
440 buf[j++] = tq->tx_ring.next2fill;
441 buf[j++] = tq->tx_ring.next2comp;
442 buf[j++] = tq->tx_ring.gen;
444 buf[j++] = VMXNET3_GET_ADDR_LO(tq->data_ring.basePA);
445 buf[j++] = VMXNET3_GET_ADDR_HI(tq->data_ring.basePA);
446 buf[j++] = tq->data_ring.size;
447 buf[j++] = tq->txdata_desc_size;
449 buf[j++] = VMXNET3_GET_ADDR_LO(tq->comp_ring.basePA);
450 buf[j++] = VMXNET3_GET_ADDR_HI(tq->comp_ring.basePA);
451 buf[j++] = tq->comp_ring.size;
452 buf[j++] = tq->comp_ring.next2proc;
453 buf[j++] = tq->comp_ring.gen;
455 buf[j++] = tq->stopped;
458 buf[j++] = adapter->num_rx_queues;
459 for (i = 0; i < adapter->num_rx_queues; i++) {
460 struct vmxnet3_rx_queue *rq = &adapter->rx_queue[i];
462 buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_RXPROD +
463 i * VMXNET3_REG_ALIGN);
464 buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_RXPROD2 +
465 i * VMXNET3_REG_ALIGN);
467 buf[j++] = VMXNET3_GET_ADDR_LO(rq->rx_ring[0].basePA);
468 buf[j++] = VMXNET3_GET_ADDR_HI(rq->rx_ring[0].basePA);
469 buf[j++] = rq->rx_ring[0].size;
470 buf[j++] = rq->rx_ring[0].next2fill;
471 buf[j++] = rq->rx_ring[0].next2comp;
472 buf[j++] = rq->rx_ring[0].gen;
474 buf[j++] = VMXNET3_GET_ADDR_LO(rq->rx_ring[1].basePA);
475 buf[j++] = VMXNET3_GET_ADDR_HI(rq->rx_ring[1].basePA);
476 buf[j++] = rq->rx_ring[1].size;
477 buf[j++] = rq->rx_ring[1].next2fill;
478 buf[j++] = rq->rx_ring[1].next2comp;
479 buf[j++] = rq->rx_ring[1].gen;
481 buf[j++] = VMXNET3_GET_ADDR_LO(rq->data_ring.basePA);
482 buf[j++] = VMXNET3_GET_ADDR_HI(rq->data_ring.basePA);
483 buf[j++] = rq->rx_ring[0].size;
484 buf[j++] = rq->data_ring.desc_size;
486 buf[j++] = VMXNET3_GET_ADDR_LO(rq->comp_ring.basePA);
487 buf[j++] = VMXNET3_GET_ADDR_HI(rq->comp_ring.basePA);
488 buf[j++] = rq->comp_ring.size;
489 buf[j++] = rq->comp_ring.next2proc;
490 buf[j++] = rq->comp_ring.gen;
496 vmxnet3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
498 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
500 wol->supported = WAKE_UCAST | WAKE_ARP | WAKE_MAGIC;
501 wol->wolopts = adapter->wol;
506 vmxnet3_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
508 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
510 if (wol->wolopts & (WAKE_PHY | WAKE_MCAST | WAKE_BCAST |
515 adapter->wol = wol->wolopts;
517 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
524 vmxnet3_get_link_ksettings(struct net_device *netdev,
525 struct ethtool_link_ksettings *ecmd)
527 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
529 ethtool_link_ksettings_zero_link_mode(ecmd, supported);
530 ethtool_link_ksettings_add_link_mode(ecmd, supported, 10000baseT_Full);
531 ethtool_link_ksettings_add_link_mode(ecmd, supported, 1000baseT_Full);
532 ethtool_link_ksettings_add_link_mode(ecmd, supported, TP);
533 ethtool_link_ksettings_zero_link_mode(ecmd, advertising);
534 ethtool_link_ksettings_add_link_mode(ecmd, advertising, TP);
535 ecmd->base.port = PORT_TP;
537 if (adapter->link_speed) {
538 ecmd->base.speed = adapter->link_speed;
539 ecmd->base.duplex = DUPLEX_FULL;
541 ecmd->base.speed = SPEED_UNKNOWN;
542 ecmd->base.duplex = DUPLEX_UNKNOWN;
549 vmxnet3_get_ringparam(struct net_device *netdev,
550 struct ethtool_ringparam *param)
552 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
554 param->rx_max_pending = VMXNET3_RX_RING_MAX_SIZE;
555 param->tx_max_pending = VMXNET3_TX_RING_MAX_SIZE;
556 param->rx_mini_max_pending = VMXNET3_VERSION_GE_3(adapter) ?
557 VMXNET3_RXDATA_DESC_MAX_SIZE : 0;
558 param->rx_jumbo_max_pending = VMXNET3_RX_RING2_MAX_SIZE;
560 param->rx_pending = adapter->rx_ring_size;
561 param->tx_pending = adapter->tx_ring_size;
562 param->rx_mini_pending = VMXNET3_VERSION_GE_3(adapter) ?
563 adapter->rxdata_desc_size : 0;
564 param->rx_jumbo_pending = adapter->rx_ring2_size;
569 vmxnet3_set_ringparam(struct net_device *netdev,
570 struct ethtool_ringparam *param)
572 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
573 u32 new_tx_ring_size, new_rx_ring_size, new_rx_ring2_size;
574 u16 new_rxdata_desc_size;
578 if (param->tx_pending == 0 || param->tx_pending >
579 VMXNET3_TX_RING_MAX_SIZE)
582 if (param->rx_pending == 0 || param->rx_pending >
583 VMXNET3_RX_RING_MAX_SIZE)
586 if (param->rx_jumbo_pending == 0 ||
587 param->rx_jumbo_pending > VMXNET3_RX_RING2_MAX_SIZE)
590 /* if adapter not yet initialized, do nothing */
591 if (adapter->rx_buf_per_pkt == 0) {
592 netdev_err(netdev, "adapter not completely initialized, "
593 "ring size cannot be changed yet\n");
597 if (VMXNET3_VERSION_GE_3(adapter)) {
598 if (param->rx_mini_pending > VMXNET3_RXDATA_DESC_MAX_SIZE)
600 } else if (param->rx_mini_pending != 0) {
604 /* round it up to a multiple of VMXNET3_RING_SIZE_ALIGN */
605 new_tx_ring_size = (param->tx_pending + VMXNET3_RING_SIZE_MASK) &
606 ~VMXNET3_RING_SIZE_MASK;
607 new_tx_ring_size = min_t(u32, new_tx_ring_size,
608 VMXNET3_TX_RING_MAX_SIZE);
609 if (new_tx_ring_size > VMXNET3_TX_RING_MAX_SIZE || (new_tx_ring_size %
610 VMXNET3_RING_SIZE_ALIGN) != 0)
613 /* ring0 has to be a multiple of
614 * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN
616 sz = adapter->rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN;
617 new_rx_ring_size = (param->rx_pending + sz - 1) / sz * sz;
618 new_rx_ring_size = min_t(u32, new_rx_ring_size,
619 VMXNET3_RX_RING_MAX_SIZE / sz * sz);
620 if (new_rx_ring_size > VMXNET3_RX_RING_MAX_SIZE || (new_rx_ring_size %
624 /* ring2 has to be a multiple of VMXNET3_RING_SIZE_ALIGN */
625 new_rx_ring2_size = (param->rx_jumbo_pending + VMXNET3_RING_SIZE_MASK) &
626 ~VMXNET3_RING_SIZE_MASK;
627 new_rx_ring2_size = min_t(u32, new_rx_ring2_size,
628 VMXNET3_RX_RING2_MAX_SIZE);
630 /* rx data ring buffer size has to be a multiple of
631 * VMXNET3_RXDATA_DESC_SIZE_ALIGN
633 new_rxdata_desc_size =
634 (param->rx_mini_pending + VMXNET3_RXDATA_DESC_SIZE_MASK) &
635 ~VMXNET3_RXDATA_DESC_SIZE_MASK;
636 new_rxdata_desc_size = min_t(u16, new_rxdata_desc_size,
637 VMXNET3_RXDATA_DESC_MAX_SIZE);
639 if (new_tx_ring_size == adapter->tx_ring_size &&
640 new_rx_ring_size == adapter->rx_ring_size &&
641 new_rx_ring2_size == adapter->rx_ring2_size &&
642 new_rxdata_desc_size == adapter->rxdata_desc_size) {
647 * Reset_work may be in the middle of resetting the device, wait for its
650 while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
651 usleep_range(1000, 2000);
653 if (netif_running(netdev)) {
654 vmxnet3_quiesce_dev(adapter);
655 vmxnet3_reset_dev(adapter);
657 /* recreate the rx queue and the tx queue based on the
659 vmxnet3_tq_destroy_all(adapter);
660 vmxnet3_rq_destroy_all(adapter);
662 err = vmxnet3_create_queues(adapter, new_tx_ring_size,
663 new_rx_ring_size, new_rx_ring2_size,
664 adapter->txdata_desc_size,
665 new_rxdata_desc_size);
667 /* failed, most likely because of OOM, try default
669 netdev_err(netdev, "failed to apply new sizes, "
670 "try the default ones\n");
671 new_rx_ring_size = VMXNET3_DEF_RX_RING_SIZE;
672 new_rx_ring2_size = VMXNET3_DEF_RX_RING2_SIZE;
673 new_tx_ring_size = VMXNET3_DEF_TX_RING_SIZE;
674 new_rxdata_desc_size = VMXNET3_VERSION_GE_3(adapter) ?
675 VMXNET3_DEF_RXDATA_DESC_SIZE : 0;
677 err = vmxnet3_create_queues(adapter,
681 adapter->txdata_desc_size,
682 new_rxdata_desc_size);
684 netdev_err(netdev, "failed to create queues "
685 "with default sizes. Closing it\n");
690 err = vmxnet3_activate_dev(adapter);
692 netdev_err(netdev, "failed to re-activate, error %d."
693 " Closing it\n", err);
695 adapter->tx_ring_size = new_tx_ring_size;
696 adapter->rx_ring_size = new_rx_ring_size;
697 adapter->rx_ring2_size = new_rx_ring2_size;
698 adapter->rxdata_desc_size = new_rxdata_desc_size;
701 clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
703 vmxnet3_force_close(adapter);
709 vmxnet3_get_rss_hash_opts(struct vmxnet3_adapter *adapter,
710 struct ethtool_rxnfc *info)
712 enum Vmxnet3_RSSField rss_fields;
714 if (netif_running(adapter->netdev)) {
717 spin_lock_irqsave(&adapter->cmd_lock, flags);
719 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
720 VMXNET3_CMD_GET_RSS_FIELDS);
721 rss_fields = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_CMD);
722 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
724 rss_fields = adapter->rss_fields;
729 /* Report default options for RSS on vmxnet3 */
730 switch (info->flow_type) {
733 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3 |
734 RXH_IP_SRC | RXH_IP_DST;
737 if (rss_fields & VMXNET3_RSS_FIELDS_UDPIP4)
738 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
739 info->data |= RXH_IP_SRC | RXH_IP_DST;
744 if (rss_fields & VMXNET3_RSS_FIELDS_ESPIP4)
745 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
749 info->data |= RXH_IP_SRC | RXH_IP_DST;
752 if (rss_fields & VMXNET3_RSS_FIELDS_UDPIP6)
753 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
754 info->data |= RXH_IP_SRC | RXH_IP_DST;
761 info->data |= RXH_IP_SRC | RXH_IP_DST;
771 vmxnet3_set_rss_hash_opt(struct net_device *netdev,
772 struct vmxnet3_adapter *adapter,
773 struct ethtool_rxnfc *nfc)
775 enum Vmxnet3_RSSField rss_fields = adapter->rss_fields;
777 /* RSS does not support anything other than hashing
778 * to queues on src and dst IPs and ports
780 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
781 RXH_L4_B_0_1 | RXH_L4_B_2_3))
784 switch (nfc->flow_type) {
787 if (!(nfc->data & RXH_IP_SRC) ||
788 !(nfc->data & RXH_IP_DST) ||
789 !(nfc->data & RXH_L4_B_0_1) ||
790 !(nfc->data & RXH_L4_B_2_3))
794 if (!(nfc->data & RXH_IP_SRC) ||
795 !(nfc->data & RXH_IP_DST))
797 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
799 rss_fields &= ~VMXNET3_RSS_FIELDS_UDPIP4;
801 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
802 rss_fields |= VMXNET3_RSS_FIELDS_UDPIP4;
809 if (!(nfc->data & RXH_IP_SRC) ||
810 !(nfc->data & RXH_IP_DST))
812 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
814 rss_fields &= ~VMXNET3_RSS_FIELDS_UDPIP6;
816 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
817 rss_fields |= VMXNET3_RSS_FIELDS_UDPIP6;
826 if (!(nfc->data & RXH_IP_SRC) ||
827 !(nfc->data & RXH_IP_DST))
829 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
831 rss_fields &= ~VMXNET3_RSS_FIELDS_ESPIP4;
833 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
834 rss_fields |= VMXNET3_RSS_FIELDS_ESPIP4;
845 if (!(nfc->data & RXH_IP_SRC) ||
846 !(nfc->data & RXH_IP_DST) ||
847 (nfc->data & RXH_L4_B_0_1) ||
848 (nfc->data & RXH_L4_B_2_3))
855 /* if we changed something we need to update flags */
856 if (rss_fields != adapter->rss_fields) {
857 adapter->default_rss_fields = false;
858 if (netif_running(netdev)) {
859 struct Vmxnet3_DriverShared *shared = adapter->shared;
860 union Vmxnet3_CmdInfo *cmdInfo = &shared->cu.cmdInfo;
863 spin_lock_irqsave(&adapter->cmd_lock, flags);
864 cmdInfo->setRssFields = rss_fields;
865 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
866 VMXNET3_CMD_SET_RSS_FIELDS);
868 /* Not all requested RSS may get applied, so get and
869 * cache what was actually applied.
871 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
872 VMXNET3_CMD_GET_RSS_FIELDS);
873 adapter->rss_fields =
874 VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_CMD);
875 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
877 /* When the device is activated, we will try to apply
878 * these rules and cache the applied value later.
880 adapter->rss_fields = rss_fields;
887 vmxnet3_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info,
890 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
894 case ETHTOOL_GRXRINGS:
895 info->data = adapter->num_rx_queues;
898 if (!VMXNET3_VERSION_GE_4(adapter)) {
908 err = vmxnet3_get_rss_hash_opts(adapter, info);
919 vmxnet3_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info)
921 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
924 if (!VMXNET3_VERSION_GE_4(adapter)) {
937 err = vmxnet3_set_rss_hash_opt(netdev, adapter, info);
950 vmxnet3_get_rss_indir_size(struct net_device *netdev)
952 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
953 struct UPT1_RSSConf *rssConf = adapter->rss_conf;
955 return rssConf->indTableSize;
959 vmxnet3_get_rss(struct net_device *netdev, u32 *p, u8 *key, u8 *hfunc)
961 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
962 struct UPT1_RSSConf *rssConf = adapter->rss_conf;
963 unsigned int n = rssConf->indTableSize;
966 *hfunc = ETH_RSS_HASH_TOP;
969 if (n > UPT1_RSS_MAX_IND_TABLE_SIZE)
972 p[n] = rssConf->indTable[n];
978 vmxnet3_set_rss(struct net_device *netdev, const u32 *p, const u8 *key,
983 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
984 struct UPT1_RSSConf *rssConf = adapter->rss_conf;
986 /* We do not allow change in unsupported parameters */
988 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
992 for (i = 0; i < rssConf->indTableSize; i++)
993 rssConf->indTable[i] = p[i];
995 spin_lock_irqsave(&adapter->cmd_lock, flags);
996 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
997 VMXNET3_CMD_UPDATE_RSSIDT);
998 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
1006 vmxnet3_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
1008 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
1010 if (!VMXNET3_VERSION_GE_3(adapter))
1013 switch (adapter->coal_conf->coalMode) {
1014 case VMXNET3_COALESCE_DISABLED:
1015 /* struct ethtool_coalesce is already initialized to 0 */
1017 case VMXNET3_COALESCE_ADAPT:
1018 ec->use_adaptive_rx_coalesce = true;
1020 case VMXNET3_COALESCE_STATIC:
1021 ec->tx_max_coalesced_frames =
1022 adapter->coal_conf->coalPara.coalStatic.tx_comp_depth;
1023 ec->rx_max_coalesced_frames =
1024 adapter->coal_conf->coalPara.coalStatic.rx_depth;
1026 case VMXNET3_COALESCE_RBC: {
1029 rbc_rate = adapter->coal_conf->coalPara.coalRbc.rbc_rate;
1030 ec->rx_coalesce_usecs = VMXNET3_COAL_RBC_USECS(rbc_rate);
1041 vmxnet3_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
1043 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
1044 struct Vmxnet3_DriverShared *shared = adapter->shared;
1045 union Vmxnet3_CmdInfo *cmdInfo = &shared->cu.cmdInfo;
1046 unsigned long flags;
1048 if (!VMXNET3_VERSION_GE_3(adapter))
1051 if ((ec->rx_coalesce_usecs == 0) &&
1052 (ec->use_adaptive_rx_coalesce == 0) &&
1053 (ec->tx_max_coalesced_frames == 0) &&
1054 (ec->rx_max_coalesced_frames == 0)) {
1055 memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
1056 adapter->coal_conf->coalMode = VMXNET3_COALESCE_DISABLED;
1060 if (ec->rx_coalesce_usecs != 0) {
1063 if ((ec->use_adaptive_rx_coalesce != 0) ||
1064 (ec->tx_max_coalesced_frames != 0) ||
1065 (ec->rx_max_coalesced_frames != 0)) {
1069 rbc_rate = VMXNET3_COAL_RBC_RATE(ec->rx_coalesce_usecs);
1070 if (rbc_rate < VMXNET3_COAL_RBC_MIN_RATE ||
1071 rbc_rate > VMXNET3_COAL_RBC_MAX_RATE) {
1075 memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
1076 adapter->coal_conf->coalMode = VMXNET3_COALESCE_RBC;
1077 adapter->coal_conf->coalPara.coalRbc.rbc_rate = rbc_rate;
1081 if (ec->use_adaptive_rx_coalesce != 0) {
1082 if ((ec->rx_coalesce_usecs != 0) ||
1083 (ec->tx_max_coalesced_frames != 0) ||
1084 (ec->rx_max_coalesced_frames != 0)) {
1087 memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
1088 adapter->coal_conf->coalMode = VMXNET3_COALESCE_ADAPT;
1092 if ((ec->tx_max_coalesced_frames != 0) ||
1093 (ec->rx_max_coalesced_frames != 0)) {
1094 if ((ec->rx_coalesce_usecs != 0) ||
1095 (ec->use_adaptive_rx_coalesce != 0)) {
1099 if ((ec->tx_max_coalesced_frames >
1100 VMXNET3_COAL_STATIC_MAX_DEPTH) ||
1101 (ec->rx_max_coalesced_frames >
1102 VMXNET3_COAL_STATIC_MAX_DEPTH)) {
1106 memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
1107 adapter->coal_conf->coalMode = VMXNET3_COALESCE_STATIC;
1109 adapter->coal_conf->coalPara.coalStatic.tx_comp_depth =
1110 (ec->tx_max_coalesced_frames ?
1111 ec->tx_max_coalesced_frames :
1112 VMXNET3_COAL_STATIC_DEFAULT_DEPTH);
1114 adapter->coal_conf->coalPara.coalStatic.rx_depth =
1115 (ec->rx_max_coalesced_frames ?
1116 ec->rx_max_coalesced_frames :
1117 VMXNET3_COAL_STATIC_DEFAULT_DEPTH);
1119 adapter->coal_conf->coalPara.coalStatic.tx_depth =
1120 VMXNET3_COAL_STATIC_DEFAULT_DEPTH;
1125 adapter->default_coal_mode = false;
1126 if (netif_running(netdev)) {
1127 spin_lock_irqsave(&adapter->cmd_lock, flags);
1128 cmdInfo->varConf.confVer = 1;
1129 cmdInfo->varConf.confLen =
1130 cpu_to_le32(sizeof(*adapter->coal_conf));
1131 cmdInfo->varConf.confPA = cpu_to_le64(adapter->coal_conf_pa);
1132 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
1133 VMXNET3_CMD_SET_COALESCE);
1134 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
1140 static const struct ethtool_ops vmxnet3_ethtool_ops = {
1141 .supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS |
1142 ETHTOOL_COALESCE_MAX_FRAMES |
1143 ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
1144 .get_drvinfo = vmxnet3_get_drvinfo,
1145 .get_regs_len = vmxnet3_get_regs_len,
1146 .get_regs = vmxnet3_get_regs,
1147 .get_wol = vmxnet3_get_wol,
1148 .set_wol = vmxnet3_set_wol,
1149 .get_link = ethtool_op_get_link,
1150 .get_coalesce = vmxnet3_get_coalesce,
1151 .set_coalesce = vmxnet3_set_coalesce,
1152 .get_strings = vmxnet3_get_strings,
1153 .get_sset_count = vmxnet3_get_sset_count,
1154 .get_ethtool_stats = vmxnet3_get_ethtool_stats,
1155 .get_ringparam = vmxnet3_get_ringparam,
1156 .set_ringparam = vmxnet3_set_ringparam,
1157 .get_rxnfc = vmxnet3_get_rxnfc,
1158 .set_rxnfc = vmxnet3_set_rxnfc,
1160 .get_rxfh_indir_size = vmxnet3_get_rss_indir_size,
1161 .get_rxfh = vmxnet3_get_rss,
1162 .set_rxfh = vmxnet3_set_rss,
1164 .get_link_ksettings = vmxnet3_get_link_ksettings,
1167 void vmxnet3_set_ethtool_ops(struct net_device *netdev)
1169 netdev->ethtool_ops = &vmxnet3_ethtool_ops;