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);
224 if (stringset != ETH_SS_STATS)
227 for (j = 0; j < adapter->num_tx_queues; j++) {
228 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++)
229 ethtool_sprintf(&buf, vmxnet3_tq_dev_stats[i].desc);
230 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++)
231 ethtool_sprintf(&buf, vmxnet3_tq_driver_stats[i].desc);
234 for (j = 0; j < adapter->num_rx_queues; j++) {
235 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++)
236 ethtool_sprintf(&buf, vmxnet3_rq_dev_stats[i].desc);
237 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++)
238 ethtool_sprintf(&buf, vmxnet3_rq_driver_stats[i].desc);
241 for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++)
242 ethtool_sprintf(&buf, vmxnet3_global_stats[i].desc);
245 netdev_features_t vmxnet3_fix_features(struct net_device *netdev,
246 netdev_features_t features)
248 /* If Rx checksum is disabled, then LRO should also be disabled */
249 if (!(features & NETIF_F_RXCSUM))
250 features &= ~NETIF_F_LRO;
255 netdev_features_t vmxnet3_features_check(struct sk_buff *skb,
256 struct net_device *netdev,
257 netdev_features_t features)
259 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
261 /* Validate if the tunneled packet is being offloaded by the device */
262 if (VMXNET3_VERSION_GE_4(adapter) &&
263 skb->encapsulation && skb->ip_summed == CHECKSUM_PARTIAL) {
266 switch (vlan_get_protocol(skb)) {
267 case htons(ETH_P_IP):
268 l4_proto = ip_hdr(skb)->protocol;
270 case htons(ETH_P_IPV6):
271 l4_proto = ipv6_hdr(skb)->nexthdr;
274 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
277 if (l4_proto != IPPROTO_UDP)
278 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
283 static void vmxnet3_enable_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 static void vmxnet3_disable_encap_offloads(struct net_device *netdev)
298 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
300 if (VMXNET3_VERSION_GE_4(adapter)) {
301 netdev->hw_enc_features &= ~(NETIF_F_SG | NETIF_F_RXCSUM |
302 NETIF_F_HW_CSUM | NETIF_F_HW_VLAN_CTAG_TX |
303 NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_TSO | NETIF_F_TSO6 |
304 NETIF_F_LRO | NETIF_F_GSO_UDP_TUNNEL |
305 NETIF_F_GSO_UDP_TUNNEL_CSUM);
309 int vmxnet3_set_features(struct net_device *netdev, netdev_features_t features)
311 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
313 netdev_features_t changed = features ^ netdev->features;
314 netdev_features_t tun_offload_mask = NETIF_F_GSO_UDP_TUNNEL |
315 NETIF_F_GSO_UDP_TUNNEL_CSUM;
316 u8 udp_tun_enabled = (netdev->features & tun_offload_mask) != 0;
318 if (changed & (NETIF_F_RXCSUM | NETIF_F_LRO |
319 NETIF_F_HW_VLAN_CTAG_RX | tun_offload_mask)) {
320 if (features & NETIF_F_RXCSUM)
321 adapter->shared->devRead.misc.uptFeatures |=
324 adapter->shared->devRead.misc.uptFeatures &=
327 /* update hardware LRO capability accordingly */
328 if (features & NETIF_F_LRO)
329 adapter->shared->devRead.misc.uptFeatures |=
332 adapter->shared->devRead.misc.uptFeatures &=
335 if (features & NETIF_F_HW_VLAN_CTAG_RX)
336 adapter->shared->devRead.misc.uptFeatures |=
339 adapter->shared->devRead.misc.uptFeatures &=
342 if ((features & tun_offload_mask) != 0 && !udp_tun_enabled) {
343 vmxnet3_enable_encap_offloads(netdev);
344 adapter->shared->devRead.misc.uptFeatures |=
346 } else if ((features & tun_offload_mask) == 0 &&
348 vmxnet3_disable_encap_offloads(netdev);
349 adapter->shared->devRead.misc.uptFeatures &=
353 spin_lock_irqsave(&adapter->cmd_lock, flags);
354 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
355 VMXNET3_CMD_UPDATE_FEATURE);
356 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
362 vmxnet3_get_ethtool_stats(struct net_device *netdev,
363 struct ethtool_stats *stats, u64 *buf)
365 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
371 spin_lock_irqsave(&adapter->cmd_lock, flags);
372 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD, VMXNET3_CMD_GET_STATS);
373 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
375 /* this does assume each counter is 64-bit wide */
376 for (j = 0; j < adapter->num_tx_queues; j++) {
377 base = (u8 *)&adapter->tqd_start[j].stats;
379 for (i = 1; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++)
380 *buf++ = *(u64 *)(base +
381 vmxnet3_tq_dev_stats[i].offset);
383 base = (u8 *)&adapter->tx_queue[j].stats;
384 for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++)
385 *buf++ = *(u64 *)(base +
386 vmxnet3_tq_driver_stats[i].offset);
389 for (j = 0; j < adapter->num_rx_queues; j++) {
390 base = (u8 *)&adapter->rqd_start[j].stats;
392 for (i = 1; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++)
393 *buf++ = *(u64 *)(base +
394 vmxnet3_rq_dev_stats[i].offset);
396 base = (u8 *)&adapter->rx_queue[j].stats;
397 for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++)
398 *buf++ = *(u64 *)(base +
399 vmxnet3_rq_driver_stats[i].offset);
402 base = (u8 *)adapter;
403 for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++)
404 *buf++ = *(u64 *)(base + vmxnet3_global_stats[i].offset);
408 /* This is a version 2 of the vmxnet3 ethtool_regs which goes hand in hand with
409 * the version 2 of the vmxnet3 support for ethtool(8) --register-dump.
410 * Therefore, if any registers are added, removed or modified, then a version
411 * bump and a corresponding change in the vmxnet3 support for ethtool(8)
412 * --register-dump would be required.
415 vmxnet3_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
417 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
421 memset(p, 0, vmxnet3_get_regs_len(netdev));
425 /* Update vmxnet3_get_regs_len if we want to dump more registers */
427 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_VRRS);
428 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_UVRS);
429 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_DSAL);
430 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_DSAH);
431 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_CMD);
432 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_MACL);
433 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_MACH);
434 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_ICR);
435 buf[j++] = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_ECR);
437 buf[j++] = adapter->intr.num_intrs;
438 for (i = 0; i < adapter->intr.num_intrs; i++) {
439 buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_IMR
440 + i * VMXNET3_REG_ALIGN);
443 buf[j++] = adapter->num_tx_queues;
444 for (i = 0; i < adapter->num_tx_queues; i++) {
445 struct vmxnet3_tx_queue *tq = &adapter->tx_queue[i];
447 buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_TXPROD +
448 i * VMXNET3_REG_ALIGN);
450 buf[j++] = VMXNET3_GET_ADDR_LO(tq->tx_ring.basePA);
451 buf[j++] = VMXNET3_GET_ADDR_HI(tq->tx_ring.basePA);
452 buf[j++] = tq->tx_ring.size;
453 buf[j++] = tq->tx_ring.next2fill;
454 buf[j++] = tq->tx_ring.next2comp;
455 buf[j++] = tq->tx_ring.gen;
457 buf[j++] = VMXNET3_GET_ADDR_LO(tq->data_ring.basePA);
458 buf[j++] = VMXNET3_GET_ADDR_HI(tq->data_ring.basePA);
459 buf[j++] = tq->data_ring.size;
460 buf[j++] = tq->txdata_desc_size;
462 buf[j++] = VMXNET3_GET_ADDR_LO(tq->comp_ring.basePA);
463 buf[j++] = VMXNET3_GET_ADDR_HI(tq->comp_ring.basePA);
464 buf[j++] = tq->comp_ring.size;
465 buf[j++] = tq->comp_ring.next2proc;
466 buf[j++] = tq->comp_ring.gen;
468 buf[j++] = tq->stopped;
471 buf[j++] = adapter->num_rx_queues;
472 for (i = 0; i < adapter->num_rx_queues; i++) {
473 struct vmxnet3_rx_queue *rq = &adapter->rx_queue[i];
475 buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_RXPROD +
476 i * VMXNET3_REG_ALIGN);
477 buf[j++] = VMXNET3_READ_BAR0_REG(adapter, VMXNET3_REG_RXPROD2 +
478 i * VMXNET3_REG_ALIGN);
480 buf[j++] = VMXNET3_GET_ADDR_LO(rq->rx_ring[0].basePA);
481 buf[j++] = VMXNET3_GET_ADDR_HI(rq->rx_ring[0].basePA);
482 buf[j++] = rq->rx_ring[0].size;
483 buf[j++] = rq->rx_ring[0].next2fill;
484 buf[j++] = rq->rx_ring[0].next2comp;
485 buf[j++] = rq->rx_ring[0].gen;
487 buf[j++] = VMXNET3_GET_ADDR_LO(rq->rx_ring[1].basePA);
488 buf[j++] = VMXNET3_GET_ADDR_HI(rq->rx_ring[1].basePA);
489 buf[j++] = rq->rx_ring[1].size;
490 buf[j++] = rq->rx_ring[1].next2fill;
491 buf[j++] = rq->rx_ring[1].next2comp;
492 buf[j++] = rq->rx_ring[1].gen;
494 buf[j++] = VMXNET3_GET_ADDR_LO(rq->data_ring.basePA);
495 buf[j++] = VMXNET3_GET_ADDR_HI(rq->data_ring.basePA);
496 buf[j++] = rq->rx_ring[0].size;
497 buf[j++] = rq->data_ring.desc_size;
499 buf[j++] = VMXNET3_GET_ADDR_LO(rq->comp_ring.basePA);
500 buf[j++] = VMXNET3_GET_ADDR_HI(rq->comp_ring.basePA);
501 buf[j++] = rq->comp_ring.size;
502 buf[j++] = rq->comp_ring.next2proc;
503 buf[j++] = rq->comp_ring.gen;
509 vmxnet3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
511 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
513 wol->supported = WAKE_UCAST | WAKE_ARP | WAKE_MAGIC;
514 wol->wolopts = adapter->wol;
519 vmxnet3_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
521 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
523 if (wol->wolopts & (WAKE_PHY | WAKE_MCAST | WAKE_BCAST |
528 adapter->wol = wol->wolopts;
530 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
537 vmxnet3_get_link_ksettings(struct net_device *netdev,
538 struct ethtool_link_ksettings *ecmd)
540 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
542 ethtool_link_ksettings_zero_link_mode(ecmd, supported);
543 ethtool_link_ksettings_add_link_mode(ecmd, supported, 10000baseT_Full);
544 ethtool_link_ksettings_add_link_mode(ecmd, supported, 1000baseT_Full);
545 ethtool_link_ksettings_add_link_mode(ecmd, supported, TP);
546 ethtool_link_ksettings_zero_link_mode(ecmd, advertising);
547 ethtool_link_ksettings_add_link_mode(ecmd, advertising, TP);
548 ecmd->base.port = PORT_TP;
550 if (adapter->link_speed) {
551 ecmd->base.speed = adapter->link_speed;
552 ecmd->base.duplex = DUPLEX_FULL;
554 ecmd->base.speed = SPEED_UNKNOWN;
555 ecmd->base.duplex = DUPLEX_UNKNOWN;
562 vmxnet3_get_ringparam(struct net_device *netdev,
563 struct ethtool_ringparam *param)
565 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
567 param->rx_max_pending = VMXNET3_RX_RING_MAX_SIZE;
568 param->tx_max_pending = VMXNET3_TX_RING_MAX_SIZE;
569 param->rx_mini_max_pending = VMXNET3_VERSION_GE_3(adapter) ?
570 VMXNET3_RXDATA_DESC_MAX_SIZE : 0;
571 param->rx_jumbo_max_pending = VMXNET3_RX_RING2_MAX_SIZE;
573 param->rx_pending = adapter->rx_ring_size;
574 param->tx_pending = adapter->tx_ring_size;
575 param->rx_mini_pending = VMXNET3_VERSION_GE_3(adapter) ?
576 adapter->rxdata_desc_size : 0;
577 param->rx_jumbo_pending = adapter->rx_ring2_size;
582 vmxnet3_set_ringparam(struct net_device *netdev,
583 struct ethtool_ringparam *param)
585 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
586 u32 new_tx_ring_size, new_rx_ring_size, new_rx_ring2_size;
587 u16 new_rxdata_desc_size;
591 if (param->tx_pending == 0 || param->tx_pending >
592 VMXNET3_TX_RING_MAX_SIZE)
595 if (param->rx_pending == 0 || param->rx_pending >
596 VMXNET3_RX_RING_MAX_SIZE)
599 if (param->rx_jumbo_pending == 0 ||
600 param->rx_jumbo_pending > VMXNET3_RX_RING2_MAX_SIZE)
603 /* if adapter not yet initialized, do nothing */
604 if (adapter->rx_buf_per_pkt == 0) {
605 netdev_err(netdev, "adapter not completely initialized, "
606 "ring size cannot be changed yet\n");
610 if (VMXNET3_VERSION_GE_3(adapter)) {
611 if (param->rx_mini_pending > VMXNET3_RXDATA_DESC_MAX_SIZE)
613 } else if (param->rx_mini_pending != 0) {
617 /* round it up to a multiple of VMXNET3_RING_SIZE_ALIGN */
618 new_tx_ring_size = (param->tx_pending + VMXNET3_RING_SIZE_MASK) &
619 ~VMXNET3_RING_SIZE_MASK;
620 new_tx_ring_size = min_t(u32, new_tx_ring_size,
621 VMXNET3_TX_RING_MAX_SIZE);
622 if (new_tx_ring_size > VMXNET3_TX_RING_MAX_SIZE || (new_tx_ring_size %
623 VMXNET3_RING_SIZE_ALIGN) != 0)
626 /* ring0 has to be a multiple of
627 * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN
629 sz = adapter->rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN;
630 new_rx_ring_size = (param->rx_pending + sz - 1) / sz * sz;
631 new_rx_ring_size = min_t(u32, new_rx_ring_size,
632 VMXNET3_RX_RING_MAX_SIZE / sz * sz);
633 if (new_rx_ring_size > VMXNET3_RX_RING_MAX_SIZE || (new_rx_ring_size %
637 /* ring2 has to be a multiple of VMXNET3_RING_SIZE_ALIGN */
638 new_rx_ring2_size = (param->rx_jumbo_pending + VMXNET3_RING_SIZE_MASK) &
639 ~VMXNET3_RING_SIZE_MASK;
640 new_rx_ring2_size = min_t(u32, new_rx_ring2_size,
641 VMXNET3_RX_RING2_MAX_SIZE);
643 /* rx data ring buffer size has to be a multiple of
644 * VMXNET3_RXDATA_DESC_SIZE_ALIGN
646 new_rxdata_desc_size =
647 (param->rx_mini_pending + VMXNET3_RXDATA_DESC_SIZE_MASK) &
648 ~VMXNET3_RXDATA_DESC_SIZE_MASK;
649 new_rxdata_desc_size = min_t(u16, new_rxdata_desc_size,
650 VMXNET3_RXDATA_DESC_MAX_SIZE);
652 if (new_tx_ring_size == adapter->tx_ring_size &&
653 new_rx_ring_size == adapter->rx_ring_size &&
654 new_rx_ring2_size == adapter->rx_ring2_size &&
655 new_rxdata_desc_size == adapter->rxdata_desc_size) {
660 * Reset_work may be in the middle of resetting the device, wait for its
663 while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state))
664 usleep_range(1000, 2000);
666 if (netif_running(netdev)) {
667 vmxnet3_quiesce_dev(adapter);
668 vmxnet3_reset_dev(adapter);
670 /* recreate the rx queue and the tx queue based on the
672 vmxnet3_tq_destroy_all(adapter);
673 vmxnet3_rq_destroy_all(adapter);
675 err = vmxnet3_create_queues(adapter, new_tx_ring_size,
676 new_rx_ring_size, new_rx_ring2_size,
677 adapter->txdata_desc_size,
678 new_rxdata_desc_size);
680 /* failed, most likely because of OOM, try default
682 netdev_err(netdev, "failed to apply new sizes, "
683 "try the default ones\n");
684 new_rx_ring_size = VMXNET3_DEF_RX_RING_SIZE;
685 new_rx_ring2_size = VMXNET3_DEF_RX_RING2_SIZE;
686 new_tx_ring_size = VMXNET3_DEF_TX_RING_SIZE;
687 new_rxdata_desc_size = VMXNET3_VERSION_GE_3(adapter) ?
688 VMXNET3_DEF_RXDATA_DESC_SIZE : 0;
690 err = vmxnet3_create_queues(adapter,
694 adapter->txdata_desc_size,
695 new_rxdata_desc_size);
697 netdev_err(netdev, "failed to create queues "
698 "with default sizes. Closing it\n");
703 err = vmxnet3_activate_dev(adapter);
705 netdev_err(netdev, "failed to re-activate, error %d."
706 " Closing it\n", err);
708 adapter->tx_ring_size = new_tx_ring_size;
709 adapter->rx_ring_size = new_rx_ring_size;
710 adapter->rx_ring2_size = new_rx_ring2_size;
711 adapter->rxdata_desc_size = new_rxdata_desc_size;
714 clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
716 vmxnet3_force_close(adapter);
722 vmxnet3_get_rss_hash_opts(struct vmxnet3_adapter *adapter,
723 struct ethtool_rxnfc *info)
725 enum Vmxnet3_RSSField rss_fields;
727 if (netif_running(adapter->netdev)) {
730 spin_lock_irqsave(&adapter->cmd_lock, flags);
732 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
733 VMXNET3_CMD_GET_RSS_FIELDS);
734 rss_fields = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_CMD);
735 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
737 rss_fields = adapter->rss_fields;
742 /* Report default options for RSS on vmxnet3 */
743 switch (info->flow_type) {
746 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3 |
747 RXH_IP_SRC | RXH_IP_DST;
750 if (rss_fields & VMXNET3_RSS_FIELDS_UDPIP4)
751 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
752 info->data |= RXH_IP_SRC | RXH_IP_DST;
757 if (rss_fields & VMXNET3_RSS_FIELDS_ESPIP4)
758 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
762 info->data |= RXH_IP_SRC | RXH_IP_DST;
765 if (rss_fields & VMXNET3_RSS_FIELDS_UDPIP6)
766 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
767 info->data |= RXH_IP_SRC | RXH_IP_DST;
774 info->data |= RXH_IP_SRC | RXH_IP_DST;
784 vmxnet3_set_rss_hash_opt(struct net_device *netdev,
785 struct vmxnet3_adapter *adapter,
786 struct ethtool_rxnfc *nfc)
788 enum Vmxnet3_RSSField rss_fields = adapter->rss_fields;
790 /* RSS does not support anything other than hashing
791 * to queues on src and dst IPs and ports
793 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
794 RXH_L4_B_0_1 | RXH_L4_B_2_3))
797 switch (nfc->flow_type) {
800 if (!(nfc->data & RXH_IP_SRC) ||
801 !(nfc->data & RXH_IP_DST) ||
802 !(nfc->data & RXH_L4_B_0_1) ||
803 !(nfc->data & RXH_L4_B_2_3))
807 if (!(nfc->data & RXH_IP_SRC) ||
808 !(nfc->data & RXH_IP_DST))
810 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
812 rss_fields &= ~VMXNET3_RSS_FIELDS_UDPIP4;
814 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
815 rss_fields |= VMXNET3_RSS_FIELDS_UDPIP4;
822 if (!(nfc->data & RXH_IP_SRC) ||
823 !(nfc->data & RXH_IP_DST))
825 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
827 rss_fields &= ~VMXNET3_RSS_FIELDS_UDPIP6;
829 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
830 rss_fields |= VMXNET3_RSS_FIELDS_UDPIP6;
839 if (!(nfc->data & RXH_IP_SRC) ||
840 !(nfc->data & RXH_IP_DST))
842 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
844 rss_fields &= ~VMXNET3_RSS_FIELDS_ESPIP4;
846 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
847 rss_fields |= VMXNET3_RSS_FIELDS_ESPIP4;
858 if (!(nfc->data & RXH_IP_SRC) ||
859 !(nfc->data & RXH_IP_DST) ||
860 (nfc->data & RXH_L4_B_0_1) ||
861 (nfc->data & RXH_L4_B_2_3))
868 /* if we changed something we need to update flags */
869 if (rss_fields != adapter->rss_fields) {
870 adapter->default_rss_fields = false;
871 if (netif_running(netdev)) {
872 struct Vmxnet3_DriverShared *shared = adapter->shared;
873 union Vmxnet3_CmdInfo *cmdInfo = &shared->cu.cmdInfo;
876 spin_lock_irqsave(&adapter->cmd_lock, flags);
877 cmdInfo->setRssFields = rss_fields;
878 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
879 VMXNET3_CMD_SET_RSS_FIELDS);
881 /* Not all requested RSS may get applied, so get and
882 * cache what was actually applied.
884 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
885 VMXNET3_CMD_GET_RSS_FIELDS);
886 adapter->rss_fields =
887 VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_CMD);
888 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
890 /* When the device is activated, we will try to apply
891 * these rules and cache the applied value later.
893 adapter->rss_fields = rss_fields;
900 vmxnet3_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info,
903 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
907 case ETHTOOL_GRXRINGS:
908 info->data = adapter->num_rx_queues;
911 if (!VMXNET3_VERSION_GE_4(adapter)) {
921 err = vmxnet3_get_rss_hash_opts(adapter, info);
932 vmxnet3_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info)
934 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
937 if (!VMXNET3_VERSION_GE_4(adapter)) {
950 err = vmxnet3_set_rss_hash_opt(netdev, adapter, info);
963 vmxnet3_get_rss_indir_size(struct net_device *netdev)
965 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
966 struct UPT1_RSSConf *rssConf = adapter->rss_conf;
968 return rssConf->indTableSize;
972 vmxnet3_get_rss(struct net_device *netdev, u32 *p, u8 *key, u8 *hfunc)
974 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
975 struct UPT1_RSSConf *rssConf = adapter->rss_conf;
976 unsigned int n = rssConf->indTableSize;
979 *hfunc = ETH_RSS_HASH_TOP;
982 if (n > UPT1_RSS_MAX_IND_TABLE_SIZE)
985 p[n] = rssConf->indTable[n];
991 vmxnet3_set_rss(struct net_device *netdev, const u32 *p, const u8 *key,
996 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
997 struct UPT1_RSSConf *rssConf = adapter->rss_conf;
999 /* We do not allow change in unsupported parameters */
1001 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
1005 for (i = 0; i < rssConf->indTableSize; i++)
1006 rssConf->indTable[i] = p[i];
1008 spin_lock_irqsave(&adapter->cmd_lock, flags);
1009 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
1010 VMXNET3_CMD_UPDATE_RSSIDT);
1011 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
1019 vmxnet3_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
1021 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
1023 if (!VMXNET3_VERSION_GE_3(adapter))
1026 switch (adapter->coal_conf->coalMode) {
1027 case VMXNET3_COALESCE_DISABLED:
1028 /* struct ethtool_coalesce is already initialized to 0 */
1030 case VMXNET3_COALESCE_ADAPT:
1031 ec->use_adaptive_rx_coalesce = true;
1033 case VMXNET3_COALESCE_STATIC:
1034 ec->tx_max_coalesced_frames =
1035 adapter->coal_conf->coalPara.coalStatic.tx_comp_depth;
1036 ec->rx_max_coalesced_frames =
1037 adapter->coal_conf->coalPara.coalStatic.rx_depth;
1039 case VMXNET3_COALESCE_RBC: {
1042 rbc_rate = adapter->coal_conf->coalPara.coalRbc.rbc_rate;
1043 ec->rx_coalesce_usecs = VMXNET3_COAL_RBC_USECS(rbc_rate);
1054 vmxnet3_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
1056 struct vmxnet3_adapter *adapter = netdev_priv(netdev);
1057 struct Vmxnet3_DriverShared *shared = adapter->shared;
1058 union Vmxnet3_CmdInfo *cmdInfo = &shared->cu.cmdInfo;
1059 unsigned long flags;
1061 if (!VMXNET3_VERSION_GE_3(adapter))
1064 if ((ec->rx_coalesce_usecs == 0) &&
1065 (ec->use_adaptive_rx_coalesce == 0) &&
1066 (ec->tx_max_coalesced_frames == 0) &&
1067 (ec->rx_max_coalesced_frames == 0)) {
1068 memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
1069 adapter->coal_conf->coalMode = VMXNET3_COALESCE_DISABLED;
1073 if (ec->rx_coalesce_usecs != 0) {
1076 if ((ec->use_adaptive_rx_coalesce != 0) ||
1077 (ec->tx_max_coalesced_frames != 0) ||
1078 (ec->rx_max_coalesced_frames != 0)) {
1082 rbc_rate = VMXNET3_COAL_RBC_RATE(ec->rx_coalesce_usecs);
1083 if (rbc_rate < VMXNET3_COAL_RBC_MIN_RATE ||
1084 rbc_rate > VMXNET3_COAL_RBC_MAX_RATE) {
1088 memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
1089 adapter->coal_conf->coalMode = VMXNET3_COALESCE_RBC;
1090 adapter->coal_conf->coalPara.coalRbc.rbc_rate = rbc_rate;
1094 if (ec->use_adaptive_rx_coalesce != 0) {
1095 if ((ec->rx_coalesce_usecs != 0) ||
1096 (ec->tx_max_coalesced_frames != 0) ||
1097 (ec->rx_max_coalesced_frames != 0)) {
1100 memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
1101 adapter->coal_conf->coalMode = VMXNET3_COALESCE_ADAPT;
1105 if ((ec->tx_max_coalesced_frames != 0) ||
1106 (ec->rx_max_coalesced_frames != 0)) {
1107 if ((ec->rx_coalesce_usecs != 0) ||
1108 (ec->use_adaptive_rx_coalesce != 0)) {
1112 if ((ec->tx_max_coalesced_frames >
1113 VMXNET3_COAL_STATIC_MAX_DEPTH) ||
1114 (ec->rx_max_coalesced_frames >
1115 VMXNET3_COAL_STATIC_MAX_DEPTH)) {
1119 memset(adapter->coal_conf, 0, sizeof(*adapter->coal_conf));
1120 adapter->coal_conf->coalMode = VMXNET3_COALESCE_STATIC;
1122 adapter->coal_conf->coalPara.coalStatic.tx_comp_depth =
1123 (ec->tx_max_coalesced_frames ?
1124 ec->tx_max_coalesced_frames :
1125 VMXNET3_COAL_STATIC_DEFAULT_DEPTH);
1127 adapter->coal_conf->coalPara.coalStatic.rx_depth =
1128 (ec->rx_max_coalesced_frames ?
1129 ec->rx_max_coalesced_frames :
1130 VMXNET3_COAL_STATIC_DEFAULT_DEPTH);
1132 adapter->coal_conf->coalPara.coalStatic.tx_depth =
1133 VMXNET3_COAL_STATIC_DEFAULT_DEPTH;
1138 adapter->default_coal_mode = false;
1139 if (netif_running(netdev)) {
1140 spin_lock_irqsave(&adapter->cmd_lock, flags);
1141 cmdInfo->varConf.confVer = 1;
1142 cmdInfo->varConf.confLen =
1143 cpu_to_le32(sizeof(*adapter->coal_conf));
1144 cmdInfo->varConf.confPA = cpu_to_le64(adapter->coal_conf_pa);
1145 VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
1146 VMXNET3_CMD_SET_COALESCE);
1147 spin_unlock_irqrestore(&adapter->cmd_lock, flags);
1153 static const struct ethtool_ops vmxnet3_ethtool_ops = {
1154 .supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS |
1155 ETHTOOL_COALESCE_MAX_FRAMES |
1156 ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
1157 .get_drvinfo = vmxnet3_get_drvinfo,
1158 .get_regs_len = vmxnet3_get_regs_len,
1159 .get_regs = vmxnet3_get_regs,
1160 .get_wol = vmxnet3_get_wol,
1161 .set_wol = vmxnet3_set_wol,
1162 .get_link = ethtool_op_get_link,
1163 .get_coalesce = vmxnet3_get_coalesce,
1164 .set_coalesce = vmxnet3_set_coalesce,
1165 .get_strings = vmxnet3_get_strings,
1166 .get_sset_count = vmxnet3_get_sset_count,
1167 .get_ethtool_stats = vmxnet3_get_ethtool_stats,
1168 .get_ringparam = vmxnet3_get_ringparam,
1169 .set_ringparam = vmxnet3_set_ringparam,
1170 .get_rxnfc = vmxnet3_get_rxnfc,
1171 .set_rxnfc = vmxnet3_set_rxnfc,
1173 .get_rxfh_indir_size = vmxnet3_get_rss_indir_size,
1174 .get_rxfh = vmxnet3_get_rss,
1175 .set_rxfh = vmxnet3_set_rss,
1177 .get_link_ksettings = vmxnet3_get_link_ksettings,
1180 void vmxnet3_set_ethtool_ops(struct net_device *netdev)
1182 netdev->ethtool_ops = &vmxnet3_ethtool_ops;