2 * Linux driver for VMware's vmxnet3 ethernet NIC.
4 * Copyright (C) 2008-2024, 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"
29 #include <net/vxlan.h>
30 #include <net/geneve.h>
31 #include "vmxnet3_xdp.h"
33 #define VXLAN_UDP_PORT 8472
35 struct vmxnet3_stat_desc
{
36 char desc
[ETH_GSTRING_LEN
];
41 /* per tq stats maintained by the device */
42 static const struct vmxnet3_stat_desc
43 vmxnet3_tq_dev_stats
[] = {
44 /* description, offset */
46 { " TSO pkts tx", offsetof(struct UPT1_TxStats
, TSOPktsTxOK
) },
47 { " TSO bytes tx", offsetof(struct UPT1_TxStats
, TSOBytesTxOK
) },
48 { " ucast pkts tx", offsetof(struct UPT1_TxStats
, ucastPktsTxOK
) },
49 { " ucast bytes tx", offsetof(struct UPT1_TxStats
, ucastBytesTxOK
) },
50 { " mcast pkts tx", offsetof(struct UPT1_TxStats
, mcastPktsTxOK
) },
51 { " mcast bytes tx", offsetof(struct UPT1_TxStats
, mcastBytesTxOK
) },
52 { " bcast pkts tx", offsetof(struct UPT1_TxStats
, bcastPktsTxOK
) },
53 { " bcast bytes tx", offsetof(struct UPT1_TxStats
, bcastBytesTxOK
) },
54 { " pkts tx err", offsetof(struct UPT1_TxStats
, pktsTxError
) },
55 { " pkts tx discard", offsetof(struct UPT1_TxStats
, pktsTxDiscard
) },
58 /* per tq stats maintained by the driver */
59 static const struct vmxnet3_stat_desc
60 vmxnet3_tq_driver_stats
[] = {
61 /* description, offset */
62 {" drv dropped tx total", offsetof(struct vmxnet3_tq_driver_stats
,
64 { " too many frags", offsetof(struct vmxnet3_tq_driver_stats
,
65 drop_too_many_frags
) },
66 { " giant hdr", offsetof(struct vmxnet3_tq_driver_stats
,
67 drop_oversized_hdr
) },
68 { " hdr err", offsetof(struct vmxnet3_tq_driver_stats
,
69 drop_hdr_inspect_err
) },
70 { " tso", offsetof(struct vmxnet3_tq_driver_stats
,
72 { " ring full", offsetof(struct vmxnet3_tq_driver_stats
,
74 { " pkts linearized", offsetof(struct vmxnet3_tq_driver_stats
,
76 { " hdr cloned", offsetof(struct vmxnet3_tq_driver_stats
,
78 { " giant hdr", offsetof(struct vmxnet3_tq_driver_stats
,
80 { " xdp xmit", offsetof(struct vmxnet3_tq_driver_stats
,
82 { " xdp xmit err", offsetof(struct vmxnet3_tq_driver_stats
,
86 /* per rq stats maintained by the device */
87 static const struct vmxnet3_stat_desc
88 vmxnet3_rq_dev_stats
[] = {
90 { " LRO pkts rx", offsetof(struct UPT1_RxStats
, LROPktsRxOK
) },
91 { " LRO byte rx", offsetof(struct UPT1_RxStats
, LROBytesRxOK
) },
92 { " ucast pkts rx", offsetof(struct UPT1_RxStats
, ucastPktsRxOK
) },
93 { " ucast bytes rx", offsetof(struct UPT1_RxStats
, ucastBytesRxOK
) },
94 { " mcast pkts rx", offsetof(struct UPT1_RxStats
, mcastPktsRxOK
) },
95 { " mcast bytes rx", offsetof(struct UPT1_RxStats
, mcastBytesRxOK
) },
96 { " bcast pkts rx", offsetof(struct UPT1_RxStats
, bcastPktsRxOK
) },
97 { " bcast bytes rx", offsetof(struct UPT1_RxStats
, bcastBytesRxOK
) },
98 { " pkts rx OOB", offsetof(struct UPT1_RxStats
, pktsRxOutOfBuf
) },
99 { " pkts rx err", offsetof(struct UPT1_RxStats
, pktsRxError
) },
102 /* per rq stats maintained by the driver */
103 static const struct vmxnet3_stat_desc
104 vmxnet3_rq_driver_stats
[] = {
105 /* description, offset */
106 { " drv dropped rx total", offsetof(struct vmxnet3_rq_driver_stats
,
108 { " err", offsetof(struct vmxnet3_rq_driver_stats
,
110 { " fcs", offsetof(struct vmxnet3_rq_driver_stats
,
112 { " rx buf alloc fail", offsetof(struct vmxnet3_rq_driver_stats
,
113 rx_buf_alloc_failure
) },
114 { " xdp packets", offsetof(struct vmxnet3_rq_driver_stats
,
116 { " xdp tx", offsetof(struct vmxnet3_rq_driver_stats
,
118 { " xdp redirects", offsetof(struct vmxnet3_rq_driver_stats
,
120 { " xdp drops", offsetof(struct vmxnet3_rq_driver_stats
,
122 { " xdp aborted", offsetof(struct vmxnet3_rq_driver_stats
,
126 /* global stats maintained by the driver */
127 static const struct vmxnet3_stat_desc
128 vmxnet3_global_stats
[] = {
129 /* description, offset */
130 { "tx timeout count", offsetof(struct vmxnet3_adapter
,
136 vmxnet3_get_stats64(struct net_device
*netdev
,
137 struct rtnl_link_stats64
*stats
)
139 struct vmxnet3_adapter
*adapter
;
140 struct vmxnet3_tq_driver_stats
*drvTxStats
;
141 struct vmxnet3_rq_driver_stats
*drvRxStats
;
142 struct UPT1_TxStats
*devTxStats
;
143 struct UPT1_RxStats
*devRxStats
;
147 adapter
= netdev_priv(netdev
);
149 /* Collect the dev stats into the shared area */
150 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
151 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
, VMXNET3_CMD_GET_STATS
);
152 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
154 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
155 devTxStats
= &adapter
->tqd_start
[i
].stats
;
156 drvTxStats
= &adapter
->tx_queue
[i
].stats
;
157 stats
->tx_packets
+= devTxStats
->ucastPktsTxOK
+
158 devTxStats
->mcastPktsTxOK
+
159 devTxStats
->bcastPktsTxOK
;
160 stats
->tx_bytes
+= devTxStats
->ucastBytesTxOK
+
161 devTxStats
->mcastBytesTxOK
+
162 devTxStats
->bcastBytesTxOK
;
163 stats
->tx_errors
+= devTxStats
->pktsTxError
;
164 stats
->tx_dropped
+= drvTxStats
->drop_total
;
167 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
168 devRxStats
= &adapter
->rqd_start
[i
].stats
;
169 drvRxStats
= &adapter
->rx_queue
[i
].stats
;
170 stats
->rx_packets
+= devRxStats
->ucastPktsRxOK
+
171 devRxStats
->mcastPktsRxOK
+
172 devRxStats
->bcastPktsRxOK
;
174 stats
->rx_bytes
+= devRxStats
->ucastBytesRxOK
+
175 devRxStats
->mcastBytesRxOK
+
176 devRxStats
->bcastBytesRxOK
;
178 stats
->rx_errors
+= devRxStats
->pktsRxError
;
179 stats
->rx_dropped
+= drvRxStats
->drop_total
;
180 stats
->multicast
+= devRxStats
->mcastPktsRxOK
;
185 vmxnet3_get_sset_count(struct net_device
*netdev
, int sset
)
187 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
190 return (ARRAY_SIZE(vmxnet3_tq_dev_stats
) +
191 ARRAY_SIZE(vmxnet3_tq_driver_stats
)) *
192 adapter
->num_tx_queues
+
193 (ARRAY_SIZE(vmxnet3_rq_dev_stats
) +
194 ARRAY_SIZE(vmxnet3_rq_driver_stats
)) *
195 adapter
->num_rx_queues
+
196 ARRAY_SIZE(vmxnet3_global_stats
);
203 /* This is a version 2 of the vmxnet3 ethtool_regs which goes hand in hand with
204 * the version 2 of the vmxnet3 support for ethtool(8) --register-dump.
205 * Therefore, if any registers are added, removed or modified, then a version
206 * bump and a corresponding change in the vmxnet3 support for ethtool(8)
207 * --register-dump would be required.
210 vmxnet3_get_regs_len(struct net_device
*netdev
)
212 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
214 return ((9 /* BAR1 registers */ +
215 (1 + adapter
->intr
.num_intrs
) +
216 (1 + adapter
->num_tx_queues
* 17 /* Tx queue registers */) +
217 (1 + adapter
->num_rx_queues
* 23 /* Rx queue registers */)) *
223 vmxnet3_get_drvinfo(struct net_device
*netdev
, struct ethtool_drvinfo
*drvinfo
)
225 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
227 strscpy(drvinfo
->driver
, vmxnet3_driver_name
, sizeof(drvinfo
->driver
));
229 strscpy(drvinfo
->version
, VMXNET3_DRIVER_VERSION_REPORT
,
230 sizeof(drvinfo
->version
));
232 strscpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
),
233 sizeof(drvinfo
->bus_info
));
238 vmxnet3_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*buf
)
240 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
243 if (stringset
!= ETH_SS_STATS
)
246 for (j
= 0; j
< adapter
->num_tx_queues
; j
++) {
247 for (i
= 0; i
< ARRAY_SIZE(vmxnet3_tq_dev_stats
); i
++)
248 ethtool_puts(&buf
, vmxnet3_tq_dev_stats
[i
].desc
);
249 for (i
= 0; i
< ARRAY_SIZE(vmxnet3_tq_driver_stats
); i
++)
250 ethtool_puts(&buf
, vmxnet3_tq_driver_stats
[i
].desc
);
253 for (j
= 0; j
< adapter
->num_rx_queues
; j
++) {
254 for (i
= 0; i
< ARRAY_SIZE(vmxnet3_rq_dev_stats
); i
++)
255 ethtool_puts(&buf
, vmxnet3_rq_dev_stats
[i
].desc
);
256 for (i
= 0; i
< ARRAY_SIZE(vmxnet3_rq_driver_stats
); i
++)
257 ethtool_puts(&buf
, vmxnet3_rq_driver_stats
[i
].desc
);
260 for (i
= 0; i
< ARRAY_SIZE(vmxnet3_global_stats
); i
++)
261 ethtool_puts(&buf
, vmxnet3_global_stats
[i
].desc
);
264 netdev_features_t
vmxnet3_fix_features(struct net_device
*netdev
,
265 netdev_features_t features
)
267 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
269 /* If Rx checksum is disabled, then LRO should also be disabled */
270 if (!(features
& NETIF_F_RXCSUM
))
271 features
&= ~NETIF_F_LRO
;
273 /* If XDP is enabled, then LRO should not be enabled */
274 if (vmxnet3_xdp_enabled(adapter
) && (features
& NETIF_F_LRO
)) {
275 netdev_err(netdev
, "LRO is not supported with XDP");
276 features
&= ~NETIF_F_LRO
;
282 netdev_features_t
vmxnet3_features_check(struct sk_buff
*skb
,
283 struct net_device
*netdev
,
284 netdev_features_t features
)
286 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
288 /* Validate if the tunneled packet is being offloaded by the device */
289 if (VMXNET3_VERSION_GE_4(adapter
) &&
290 skb
->encapsulation
&& skb
->ip_summed
== CHECKSUM_PARTIAL
) {
295 switch (vlan_get_protocol(skb
)) {
296 case htons(ETH_P_IP
):
297 l4_proto
= ip_hdr(skb
)->protocol
;
299 case htons(ETH_P_IPV6
):
300 l4_proto
= ipv6_hdr(skb
)->nexthdr
;
303 return features
& ~(NETIF_F_CSUM_MASK
| NETIF_F_GSO_MASK
);
309 port
= be16_to_cpu(udph
->dest
);
310 /* Check if offloaded port is supported */
311 if (port
!= GENEVE_UDP_PORT
&&
312 port
!= IANA_VXLAN_UDP_PORT
&&
313 port
!= VXLAN_UDP_PORT
) {
314 return features
& ~(NETIF_F_CSUM_MASK
| NETIF_F_GSO_MASK
);
318 return features
& ~(NETIF_F_CSUM_MASK
| NETIF_F_GSO_MASK
);
324 static void vmxnet3_enable_encap_offloads(struct net_device
*netdev
, netdev_features_t features
)
326 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
328 if (VMXNET3_VERSION_GE_4(adapter
)) {
329 netdev
->hw_enc_features
|= NETIF_F_SG
| NETIF_F_RXCSUM
|
330 NETIF_F_HW_CSUM
| NETIF_F_HW_VLAN_CTAG_TX
|
331 NETIF_F_HW_VLAN_CTAG_RX
| NETIF_F_TSO
| NETIF_F_TSO6
|
333 if (features
& NETIF_F_GSO_UDP_TUNNEL
)
334 netdev
->hw_enc_features
|= NETIF_F_GSO_UDP_TUNNEL
;
335 if (features
& NETIF_F_GSO_UDP_TUNNEL_CSUM
)
336 netdev
->hw_enc_features
|= NETIF_F_GSO_UDP_TUNNEL_CSUM
;
338 if (VMXNET3_VERSION_GE_7(adapter
)) {
341 if (vmxnet3_check_ptcapability(adapter
->ptcap_supported
[0],
342 VMXNET3_CAP_GENEVE_CHECKSUM_OFFLOAD
)) {
343 adapter
->dev_caps
[0] |= 1UL << VMXNET3_CAP_GENEVE_CHECKSUM_OFFLOAD
;
345 if (vmxnet3_check_ptcapability(adapter
->ptcap_supported
[0],
346 VMXNET3_CAP_VXLAN_CHECKSUM_OFFLOAD
)) {
347 adapter
->dev_caps
[0] |= 1UL << VMXNET3_CAP_VXLAN_CHECKSUM_OFFLOAD
;
349 if (vmxnet3_check_ptcapability(adapter
->ptcap_supported
[0],
350 VMXNET3_CAP_GENEVE_TSO
)) {
351 adapter
->dev_caps
[0] |= 1UL << VMXNET3_CAP_GENEVE_TSO
;
353 if (vmxnet3_check_ptcapability(adapter
->ptcap_supported
[0],
354 VMXNET3_CAP_VXLAN_TSO
)) {
355 adapter
->dev_caps
[0] |= 1UL << VMXNET3_CAP_VXLAN_TSO
;
357 if (vmxnet3_check_ptcapability(adapter
->ptcap_supported
[0],
358 VMXNET3_CAP_GENEVE_OUTER_CHECKSUM_OFFLOAD
)) {
359 adapter
->dev_caps
[0] |= 1UL << VMXNET3_CAP_GENEVE_OUTER_CHECKSUM_OFFLOAD
;
361 if (vmxnet3_check_ptcapability(adapter
->ptcap_supported
[0],
362 VMXNET3_CAP_VXLAN_OUTER_CHECKSUM_OFFLOAD
)) {
363 adapter
->dev_caps
[0] |= 1UL << VMXNET3_CAP_VXLAN_OUTER_CHECKSUM_OFFLOAD
;
366 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_DCR
, adapter
->dev_caps
[0]);
367 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
368 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
, VMXNET3_CMD_GET_DCR0_REG
);
369 adapter
->dev_caps
[0] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_CMD
);
370 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
372 if (!(adapter
->dev_caps
[0] & (1UL << VMXNET3_CAP_GENEVE_CHECKSUM_OFFLOAD
)) &&
373 !(adapter
->dev_caps
[0] & (1UL << VMXNET3_CAP_VXLAN_CHECKSUM_OFFLOAD
)) &&
374 !(adapter
->dev_caps
[0] & (1UL << VMXNET3_CAP_GENEVE_TSO
)) &&
375 !(adapter
->dev_caps
[0] & (1UL << VMXNET3_CAP_VXLAN_TSO
))) {
376 netdev
->hw_enc_features
&= ~NETIF_F_GSO_UDP_TUNNEL
;
378 if (!(adapter
->dev_caps
[0] & (1UL << VMXNET3_CAP_GENEVE_OUTER_CHECKSUM_OFFLOAD
)) &&
379 !(adapter
->dev_caps
[0] & (1UL << VMXNET3_CAP_VXLAN_OUTER_CHECKSUM_OFFLOAD
))) {
380 netdev
->hw_enc_features
&= ~NETIF_F_GSO_UDP_TUNNEL_CSUM
;
385 static void vmxnet3_disable_encap_offloads(struct net_device
*netdev
)
387 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
389 if (VMXNET3_VERSION_GE_4(adapter
)) {
390 netdev
->hw_enc_features
&= ~(NETIF_F_SG
| NETIF_F_RXCSUM
|
391 NETIF_F_HW_CSUM
| NETIF_F_HW_VLAN_CTAG_TX
|
392 NETIF_F_HW_VLAN_CTAG_RX
| NETIF_F_TSO
| NETIF_F_TSO6
|
393 NETIF_F_LRO
| NETIF_F_GSO_UDP_TUNNEL
|
394 NETIF_F_GSO_UDP_TUNNEL_CSUM
);
396 if (VMXNET3_VERSION_GE_7(adapter
)) {
399 adapter
->dev_caps
[0] &= ~(1UL << VMXNET3_CAP_GENEVE_CHECKSUM_OFFLOAD
|
400 1UL << VMXNET3_CAP_VXLAN_CHECKSUM_OFFLOAD
|
401 1UL << VMXNET3_CAP_GENEVE_TSO
|
402 1UL << VMXNET3_CAP_VXLAN_TSO
|
403 1UL << VMXNET3_CAP_GENEVE_OUTER_CHECKSUM_OFFLOAD
|
404 1UL << VMXNET3_CAP_VXLAN_OUTER_CHECKSUM_OFFLOAD
);
406 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_DCR
, adapter
->dev_caps
[0]);
407 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
408 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
, VMXNET3_CMD_GET_DCR0_REG
);
409 adapter
->dev_caps
[0] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_CMD
);
410 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
414 int vmxnet3_set_features(struct net_device
*netdev
, netdev_features_t features
)
416 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
418 netdev_features_t changed
= features
^ netdev
->features
;
419 netdev_features_t tun_offload_mask
= NETIF_F_GSO_UDP_TUNNEL
|
420 NETIF_F_GSO_UDP_TUNNEL_CSUM
;
421 u8 udp_tun_enabled
= (netdev
->features
& tun_offload_mask
) != 0;
423 if (changed
& (NETIF_F_RXCSUM
| NETIF_F_LRO
|
424 NETIF_F_HW_VLAN_CTAG_RX
| tun_offload_mask
)) {
425 if (features
& NETIF_F_RXCSUM
)
426 adapter
->shared
->devRead
.misc
.uptFeatures
|=
429 adapter
->shared
->devRead
.misc
.uptFeatures
&=
432 /* update hardware LRO capability accordingly */
433 if (features
& NETIF_F_LRO
)
434 adapter
->shared
->devRead
.misc
.uptFeatures
|=
437 adapter
->shared
->devRead
.misc
.uptFeatures
&=
440 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
441 adapter
->shared
->devRead
.misc
.uptFeatures
|=
444 adapter
->shared
->devRead
.misc
.uptFeatures
&=
447 if ((features
& tun_offload_mask
) != 0) {
448 vmxnet3_enable_encap_offloads(netdev
, features
);
449 adapter
->shared
->devRead
.misc
.uptFeatures
|=
451 } else if ((features
& tun_offload_mask
) == 0 &&
453 vmxnet3_disable_encap_offloads(netdev
);
454 adapter
->shared
->devRead
.misc
.uptFeatures
&=
458 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
459 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
460 VMXNET3_CMD_UPDATE_FEATURE
);
461 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
467 vmxnet3_get_ethtool_stats(struct net_device
*netdev
,
468 struct ethtool_stats
*stats
, u64
*buf
)
470 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
476 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
477 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
, VMXNET3_CMD_GET_STATS
);
478 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
480 /* this does assume each counter is 64-bit wide */
481 for (j
= 0; j
< adapter
->num_tx_queues
; j
++) {
482 base
= (u8
*)&adapter
->tqd_start
[j
].stats
;
484 for (i
= 1; i
< ARRAY_SIZE(vmxnet3_tq_dev_stats
); i
++)
485 *buf
++ = *(u64
*)(base
+
486 vmxnet3_tq_dev_stats
[i
].offset
);
488 base
= (u8
*)&adapter
->tx_queue
[j
].stats
;
489 for (i
= 0; i
< ARRAY_SIZE(vmxnet3_tq_driver_stats
); i
++)
490 *buf
++ = *(u64
*)(base
+
491 vmxnet3_tq_driver_stats
[i
].offset
);
494 for (j
= 0; j
< adapter
->num_rx_queues
; j
++) {
495 base
= (u8
*)&adapter
->rqd_start
[j
].stats
;
497 for (i
= 1; i
< ARRAY_SIZE(vmxnet3_rq_dev_stats
); i
++)
498 *buf
++ = *(u64
*)(base
+
499 vmxnet3_rq_dev_stats
[i
].offset
);
501 base
= (u8
*)&adapter
->rx_queue
[j
].stats
;
502 for (i
= 0; i
< ARRAY_SIZE(vmxnet3_rq_driver_stats
); i
++)
503 *buf
++ = *(u64
*)(base
+
504 vmxnet3_rq_driver_stats
[i
].offset
);
507 base
= (u8
*)adapter
;
508 for (i
= 0; i
< ARRAY_SIZE(vmxnet3_global_stats
); i
++)
509 *buf
++ = *(u64
*)(base
+ vmxnet3_global_stats
[i
].offset
);
513 /* This is a version 2 of the vmxnet3 ethtool_regs which goes hand in hand with
514 * the version 2 of the vmxnet3 support for ethtool(8) --register-dump.
515 * Therefore, if any registers are added, removed or modified, then a version
516 * bump and a corresponding change in the vmxnet3 support for ethtool(8)
517 * --register-dump would be required.
520 vmxnet3_get_regs(struct net_device
*netdev
, struct ethtool_regs
*regs
, void *p
)
522 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
526 memset(p
, 0, vmxnet3_get_regs_len(netdev
));
530 /* Update vmxnet3_get_regs_len if we want to dump more registers */
532 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_VRRS
);
533 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_UVRS
);
534 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_DSAL
);
535 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_DSAH
);
536 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_CMD
);
537 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_MACL
);
538 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_MACH
);
539 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_ICR
);
540 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_ECR
);
542 buf
[j
++] = adapter
->intr
.num_intrs
;
543 for (i
= 0; i
< adapter
->intr
.num_intrs
; i
++) {
544 buf
[j
++] = VMXNET3_READ_BAR0_REG(adapter
, VMXNET3_REG_IMR
545 + i
* VMXNET3_REG_ALIGN
);
548 buf
[j
++] = adapter
->num_tx_queues
;
549 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
550 struct vmxnet3_tx_queue
*tq
= &adapter
->tx_queue
[i
];
552 buf
[j
++] = VMXNET3_READ_BAR0_REG(adapter
, adapter
->tx_prod_offset
+
553 i
* VMXNET3_REG_ALIGN
);
555 buf
[j
++] = VMXNET3_GET_ADDR_LO(tq
->tx_ring
.basePA
);
556 buf
[j
++] = VMXNET3_GET_ADDR_HI(tq
->tx_ring
.basePA
);
557 buf
[j
++] = tq
->tx_ring
.size
;
558 buf
[j
++] = tq
->tx_ring
.next2fill
;
559 buf
[j
++] = tq
->tx_ring
.next2comp
;
560 buf
[j
++] = tq
->tx_ring
.gen
;
562 buf
[j
++] = VMXNET3_GET_ADDR_LO(tq
->data_ring
.basePA
);
563 buf
[j
++] = VMXNET3_GET_ADDR_HI(tq
->data_ring
.basePA
);
564 buf
[j
++] = tq
->data_ring
.size
;
565 buf
[j
++] = tq
->txdata_desc_size
;
567 buf
[j
++] = VMXNET3_GET_ADDR_LO(tq
->comp_ring
.basePA
);
568 buf
[j
++] = VMXNET3_GET_ADDR_HI(tq
->comp_ring
.basePA
);
569 buf
[j
++] = tq
->comp_ring
.size
;
570 buf
[j
++] = tq
->comp_ring
.next2proc
;
571 buf
[j
++] = tq
->comp_ring
.gen
;
573 buf
[j
++] = tq
->stopped
;
576 buf
[j
++] = adapter
->num_rx_queues
;
577 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
578 struct vmxnet3_rx_queue
*rq
= &adapter
->rx_queue
[i
];
580 buf
[j
++] = VMXNET3_READ_BAR0_REG(adapter
, adapter
->rx_prod_offset
+
581 i
* VMXNET3_REG_ALIGN
);
582 buf
[j
++] = VMXNET3_READ_BAR0_REG(adapter
, adapter
->rx_prod2_offset
+
583 i
* VMXNET3_REG_ALIGN
);
585 buf
[j
++] = VMXNET3_GET_ADDR_LO(rq
->rx_ring
[0].basePA
);
586 buf
[j
++] = VMXNET3_GET_ADDR_HI(rq
->rx_ring
[0].basePA
);
587 buf
[j
++] = rq
->rx_ring
[0].size
;
588 buf
[j
++] = rq
->rx_ring
[0].next2fill
;
589 buf
[j
++] = rq
->rx_ring
[0].next2comp
;
590 buf
[j
++] = rq
->rx_ring
[0].gen
;
592 buf
[j
++] = VMXNET3_GET_ADDR_LO(rq
->rx_ring
[1].basePA
);
593 buf
[j
++] = VMXNET3_GET_ADDR_HI(rq
->rx_ring
[1].basePA
);
594 buf
[j
++] = rq
->rx_ring
[1].size
;
595 buf
[j
++] = rq
->rx_ring
[1].next2fill
;
596 buf
[j
++] = rq
->rx_ring
[1].next2comp
;
597 buf
[j
++] = rq
->rx_ring
[1].gen
;
599 buf
[j
++] = VMXNET3_GET_ADDR_LO(rq
->data_ring
.basePA
);
600 buf
[j
++] = VMXNET3_GET_ADDR_HI(rq
->data_ring
.basePA
);
601 buf
[j
++] = rq
->rx_ring
[0].size
;
602 buf
[j
++] = rq
->data_ring
.desc_size
;
604 buf
[j
++] = VMXNET3_GET_ADDR_LO(rq
->comp_ring
.basePA
);
605 buf
[j
++] = VMXNET3_GET_ADDR_HI(rq
->comp_ring
.basePA
);
606 buf
[j
++] = rq
->comp_ring
.size
;
607 buf
[j
++] = rq
->comp_ring
.next2proc
;
608 buf
[j
++] = rq
->comp_ring
.gen
;
614 vmxnet3_get_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
616 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
618 wol
->supported
= WAKE_UCAST
| WAKE_ARP
| WAKE_MAGIC
;
619 wol
->wolopts
= adapter
->wol
;
624 vmxnet3_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
626 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
628 if (wol
->wolopts
& (WAKE_PHY
| WAKE_MCAST
| WAKE_BCAST
|
633 adapter
->wol
= wol
->wolopts
;
635 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
642 vmxnet3_get_link_ksettings(struct net_device
*netdev
,
643 struct ethtool_link_ksettings
*ecmd
)
645 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
647 ethtool_link_ksettings_zero_link_mode(ecmd
, supported
);
648 ethtool_link_ksettings_add_link_mode(ecmd
, supported
, 10000baseT_Full
);
649 ethtool_link_ksettings_add_link_mode(ecmd
, supported
, 1000baseT_Full
);
650 ethtool_link_ksettings_add_link_mode(ecmd
, supported
, TP
);
651 ethtool_link_ksettings_zero_link_mode(ecmd
, advertising
);
652 ethtool_link_ksettings_add_link_mode(ecmd
, advertising
, TP
);
653 ecmd
->base
.port
= PORT_TP
;
655 if (adapter
->link_speed
) {
656 ecmd
->base
.speed
= adapter
->link_speed
;
657 ecmd
->base
.duplex
= DUPLEX_FULL
;
659 ecmd
->base
.speed
= SPEED_UNKNOWN
;
660 ecmd
->base
.duplex
= DUPLEX_UNKNOWN
;
666 vmxnet3_get_ringparam(struct net_device
*netdev
,
667 struct ethtool_ringparam
*param
,
668 struct kernel_ethtool_ringparam
*kernel_param
,
669 struct netlink_ext_ack
*extack
)
671 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
673 param
->rx_max_pending
= VMXNET3_RX_RING_MAX_SIZE
;
674 param
->tx_max_pending
= VMXNET3_TX_RING_MAX_SIZE
;
675 param
->rx_mini_max_pending
= VMXNET3_VERSION_GE_3(adapter
) ?
676 VMXNET3_RXDATA_DESC_MAX_SIZE
: 0;
677 param
->rx_jumbo_max_pending
= VMXNET3_RX_RING2_MAX_SIZE
;
679 param
->rx_pending
= adapter
->rx_ring_size
;
680 param
->tx_pending
= adapter
->tx_ring_size
;
681 param
->rx_mini_pending
= VMXNET3_VERSION_GE_3(adapter
) ?
682 adapter
->rxdata_desc_size
: 0;
683 param
->rx_jumbo_pending
= adapter
->rx_ring2_size
;
687 vmxnet3_set_ringparam(struct net_device
*netdev
,
688 struct ethtool_ringparam
*param
,
689 struct kernel_ethtool_ringparam
*kernel_param
,
690 struct netlink_ext_ack
*extack
)
692 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
693 u32 new_tx_ring_size
, new_rx_ring_size
, new_rx_ring2_size
;
694 u16 new_rxdata_desc_size
;
698 if (param
->tx_pending
== 0 || param
->tx_pending
>
699 VMXNET3_TX_RING_MAX_SIZE
)
702 if (param
->rx_pending
== 0 || param
->rx_pending
>
703 VMXNET3_RX_RING_MAX_SIZE
)
706 if (param
->rx_jumbo_pending
== 0 ||
707 param
->rx_jumbo_pending
> VMXNET3_RX_RING2_MAX_SIZE
)
710 /* if adapter not yet initialized, do nothing */
711 if (adapter
->rx_buf_per_pkt
== 0) {
712 netdev_err(netdev
, "adapter not completely initialized, "
713 "ring size cannot be changed yet\n");
717 if (VMXNET3_VERSION_GE_3(adapter
)) {
718 if (param
->rx_mini_pending
> VMXNET3_RXDATA_DESC_MAX_SIZE
)
720 } else if (param
->rx_mini_pending
!= 0) {
724 /* round it up to a multiple of VMXNET3_RING_SIZE_ALIGN */
725 new_tx_ring_size
= (param
->tx_pending
+ VMXNET3_RING_SIZE_MASK
) &
726 ~VMXNET3_RING_SIZE_MASK
;
727 new_tx_ring_size
= min_t(u32
, new_tx_ring_size
,
728 VMXNET3_TX_RING_MAX_SIZE
);
729 if (new_tx_ring_size
> VMXNET3_TX_RING_MAX_SIZE
|| (new_tx_ring_size
%
730 VMXNET3_RING_SIZE_ALIGN
) != 0)
733 /* ring0 has to be a multiple of
734 * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN
736 sz
= adapter
->rx_buf_per_pkt
* VMXNET3_RING_SIZE_ALIGN
;
737 new_rx_ring_size
= (param
->rx_pending
+ sz
- 1) / sz
* sz
;
738 new_rx_ring_size
= min_t(u32
, new_rx_ring_size
,
739 VMXNET3_RX_RING_MAX_SIZE
/ sz
* sz
);
740 if (new_rx_ring_size
> VMXNET3_RX_RING_MAX_SIZE
|| (new_rx_ring_size
%
744 /* ring2 has to be a multiple of VMXNET3_RING_SIZE_ALIGN */
745 new_rx_ring2_size
= (param
->rx_jumbo_pending
+ VMXNET3_RING_SIZE_MASK
) &
746 ~VMXNET3_RING_SIZE_MASK
;
747 new_rx_ring2_size
= min_t(u32
, new_rx_ring2_size
,
748 VMXNET3_RX_RING2_MAX_SIZE
);
750 /* For v7 and later, keep ring size power of 2 for UPT */
751 if (VMXNET3_VERSION_GE_7(adapter
)) {
752 new_tx_ring_size
= rounddown_pow_of_two(new_tx_ring_size
);
753 new_rx_ring_size
= rounddown_pow_of_two(new_rx_ring_size
);
754 new_rx_ring2_size
= rounddown_pow_of_two(new_rx_ring2_size
);
757 /* rx data ring buffer size has to be a multiple of
758 * VMXNET3_RXDATA_DESC_SIZE_ALIGN
760 new_rxdata_desc_size
=
761 (param
->rx_mini_pending
+ VMXNET3_RXDATA_DESC_SIZE_MASK
) &
762 ~VMXNET3_RXDATA_DESC_SIZE_MASK
;
763 new_rxdata_desc_size
= min_t(u16
, new_rxdata_desc_size
,
764 VMXNET3_RXDATA_DESC_MAX_SIZE
);
766 if (new_tx_ring_size
== adapter
->tx_ring_size
&&
767 new_rx_ring_size
== adapter
->rx_ring_size
&&
768 new_rx_ring2_size
== adapter
->rx_ring2_size
&&
769 new_rxdata_desc_size
== adapter
->rxdata_desc_size
) {
774 * Reset_work may be in the middle of resetting the device, wait for its
777 while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING
, &adapter
->state
))
778 usleep_range(1000, 2000);
780 if (netif_running(netdev
)) {
781 vmxnet3_quiesce_dev(adapter
);
782 vmxnet3_reset_dev(adapter
);
784 /* recreate the rx queue and the tx queue based on the
786 vmxnet3_tq_destroy_all(adapter
);
787 vmxnet3_rq_destroy_all(adapter
);
789 err
= vmxnet3_create_queues(adapter
, new_tx_ring_size
,
790 new_rx_ring_size
, new_rx_ring2_size
,
791 adapter
->txdata_desc_size
,
792 new_rxdata_desc_size
);
794 /* failed, most likely because of OOM, try default
796 netdev_err(netdev
, "failed to apply new sizes, "
797 "try the default ones\n");
798 new_rx_ring_size
= VMXNET3_DEF_RX_RING_SIZE
;
799 new_rx_ring2_size
= VMXNET3_DEF_RX_RING2_SIZE
;
800 new_tx_ring_size
= VMXNET3_DEF_TX_RING_SIZE
;
801 new_rxdata_desc_size
= VMXNET3_VERSION_GE_3(adapter
) ?
802 VMXNET3_DEF_RXDATA_DESC_SIZE
: 0;
804 err
= vmxnet3_create_queues(adapter
,
808 adapter
->txdata_desc_size
,
809 new_rxdata_desc_size
);
811 netdev_err(netdev
, "failed to create queues "
812 "with default sizes. Closing it\n");
817 err
= vmxnet3_activate_dev(adapter
);
819 netdev_err(netdev
, "failed to re-activate, error %d."
820 " Closing it\n", err
);
822 adapter
->tx_ring_size
= new_tx_ring_size
;
823 adapter
->rx_ring_size
= new_rx_ring_size
;
824 adapter
->rx_ring2_size
= new_rx_ring2_size
;
825 adapter
->rxdata_desc_size
= new_rxdata_desc_size
;
828 clear_bit(VMXNET3_STATE_BIT_RESETTING
, &adapter
->state
);
830 vmxnet3_force_close(adapter
);
836 vmxnet3_get_rss_hash_opts(struct vmxnet3_adapter
*adapter
,
837 struct ethtool_rxnfc
*info
)
839 enum Vmxnet3_RSSField rss_fields
;
841 if (netif_running(adapter
->netdev
)) {
844 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
846 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
847 VMXNET3_CMD_GET_RSS_FIELDS
);
848 rss_fields
= VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_CMD
);
849 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
851 rss_fields
= adapter
->rss_fields
;
856 /* Report default options for RSS on vmxnet3 */
857 switch (info
->flow_type
) {
860 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
|
861 RXH_IP_SRC
| RXH_IP_DST
;
864 if (rss_fields
& VMXNET3_RSS_FIELDS_UDPIP4
)
865 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
866 info
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
871 if (rss_fields
& VMXNET3_RSS_FIELDS_ESPIP4
)
872 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
876 info
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
879 if (rss_fields
& VMXNET3_RSS_FIELDS_UDPIP6
)
880 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
881 info
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
886 if (VMXNET3_VERSION_GE_6(adapter
) &&
887 (rss_fields
& VMXNET3_RSS_FIELDS_ESPIP6
))
888 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
892 info
->data
|= RXH_IP_SRC
| RXH_IP_DST
;
902 vmxnet3_set_rss_hash_opt(struct net_device
*netdev
,
903 struct vmxnet3_adapter
*adapter
,
904 struct ethtool_rxnfc
*nfc
)
906 enum Vmxnet3_RSSField rss_fields
= adapter
->rss_fields
;
908 /* RSS does not support anything other than hashing
909 * to queues on src and dst IPs and ports
911 if (nfc
->data
& ~(RXH_IP_SRC
| RXH_IP_DST
|
912 RXH_L4_B_0_1
| RXH_L4_B_2_3
))
915 switch (nfc
->flow_type
) {
918 if (!(nfc
->data
& RXH_IP_SRC
) ||
919 !(nfc
->data
& RXH_IP_DST
) ||
920 !(nfc
->data
& RXH_L4_B_0_1
) ||
921 !(nfc
->data
& RXH_L4_B_2_3
))
925 if (!(nfc
->data
& RXH_IP_SRC
) ||
926 !(nfc
->data
& RXH_IP_DST
))
928 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
930 rss_fields
&= ~VMXNET3_RSS_FIELDS_UDPIP4
;
932 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
933 rss_fields
|= VMXNET3_RSS_FIELDS_UDPIP4
;
940 if (!(nfc
->data
& RXH_IP_SRC
) ||
941 !(nfc
->data
& RXH_IP_DST
))
943 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
945 rss_fields
&= ~VMXNET3_RSS_FIELDS_UDPIP6
;
947 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
948 rss_fields
|= VMXNET3_RSS_FIELDS_UDPIP6
;
957 if (!(nfc
->data
& RXH_IP_SRC
) ||
958 !(nfc
->data
& RXH_IP_DST
))
960 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
962 rss_fields
&= ~VMXNET3_RSS_FIELDS_ESPIP4
;
964 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
965 rss_fields
|= VMXNET3_RSS_FIELDS_ESPIP4
;
974 if (!VMXNET3_VERSION_GE_6(adapter
))
976 if (!(nfc
->data
& RXH_IP_SRC
) ||
977 !(nfc
->data
& RXH_IP_DST
))
979 switch (nfc
->data
& (RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
981 rss_fields
&= ~VMXNET3_RSS_FIELDS_ESPIP6
;
983 case (RXH_L4_B_0_1
| RXH_L4_B_2_3
):
984 rss_fields
|= VMXNET3_RSS_FIELDS_ESPIP6
;
992 if (!(nfc
->data
& RXH_IP_SRC
) ||
993 !(nfc
->data
& RXH_IP_DST
) ||
994 (nfc
->data
& RXH_L4_B_0_1
) ||
995 (nfc
->data
& RXH_L4_B_2_3
))
1002 /* if we changed something we need to update flags */
1003 if (rss_fields
!= adapter
->rss_fields
) {
1004 adapter
->default_rss_fields
= false;
1005 if (netif_running(netdev
)) {
1006 struct Vmxnet3_DriverShared
*shared
= adapter
->shared
;
1007 union Vmxnet3_CmdInfo
*cmdInfo
= &shared
->cu
.cmdInfo
;
1008 unsigned long flags
;
1010 if (VMXNET3_VERSION_GE_7(adapter
)) {
1011 if ((rss_fields
& VMXNET3_RSS_FIELDS_UDPIP4
||
1012 rss_fields
& VMXNET3_RSS_FIELDS_UDPIP6
) &&
1013 vmxnet3_check_ptcapability(adapter
->ptcap_supported
[0],
1014 VMXNET3_CAP_UDP_RSS
)) {
1015 adapter
->dev_caps
[0] |= 1UL << VMXNET3_CAP_UDP_RSS
;
1017 adapter
->dev_caps
[0] &= ~(1UL << VMXNET3_CAP_UDP_RSS
);
1019 if ((rss_fields
& VMXNET3_RSS_FIELDS_ESPIP4
) &&
1020 vmxnet3_check_ptcapability(adapter
->ptcap_supported
[0],
1021 VMXNET3_CAP_ESP_RSS_IPV4
)) {
1022 adapter
->dev_caps
[0] |= 1UL << VMXNET3_CAP_ESP_RSS_IPV4
;
1024 adapter
->dev_caps
[0] &= ~(1UL << VMXNET3_CAP_ESP_RSS_IPV4
);
1026 if ((rss_fields
& VMXNET3_RSS_FIELDS_ESPIP6
) &&
1027 vmxnet3_check_ptcapability(adapter
->ptcap_supported
[0],
1028 VMXNET3_CAP_ESP_RSS_IPV6
)) {
1029 adapter
->dev_caps
[0] |= 1UL << VMXNET3_CAP_ESP_RSS_IPV6
;
1031 adapter
->dev_caps
[0] &= ~(1UL << VMXNET3_CAP_ESP_RSS_IPV6
);
1034 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_DCR
,
1035 adapter
->dev_caps
[0]);
1036 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
1037 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
1038 VMXNET3_CMD_GET_DCR0_REG
);
1039 adapter
->dev_caps
[0] = VMXNET3_READ_BAR1_REG(adapter
,
1041 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
1043 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
1044 cmdInfo
->setRssFields
= rss_fields
;
1045 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
1046 VMXNET3_CMD_SET_RSS_FIELDS
);
1048 /* Not all requested RSS may get applied, so get and
1049 * cache what was actually applied.
1051 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
1052 VMXNET3_CMD_GET_RSS_FIELDS
);
1053 adapter
->rss_fields
=
1054 VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_CMD
);
1055 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
1057 /* When the device is activated, we will try to apply
1058 * these rules and cache the applied value later.
1060 adapter
->rss_fields
= rss_fields
;
1067 vmxnet3_get_rxnfc(struct net_device
*netdev
, struct ethtool_rxnfc
*info
,
1070 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
1073 switch (info
->cmd
) {
1074 case ETHTOOL_GRXRINGS
:
1075 info
->data
= adapter
->num_rx_queues
;
1078 if (!VMXNET3_VERSION_GE_4(adapter
)) {
1083 if (!adapter
->rss
) {
1088 err
= vmxnet3_get_rss_hash_opts(adapter
, info
);
1099 vmxnet3_set_rxnfc(struct net_device
*netdev
, struct ethtool_rxnfc
*info
)
1101 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
1104 if (!VMXNET3_VERSION_GE_4(adapter
)) {
1109 if (!adapter
->rss
) {
1115 switch (info
->cmd
) {
1117 err
= vmxnet3_set_rss_hash_opt(netdev
, adapter
, info
);
1130 vmxnet3_get_rss_indir_size(struct net_device
*netdev
)
1132 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
1133 struct UPT1_RSSConf
*rssConf
= adapter
->rss_conf
;
1135 return rssConf
->indTableSize
;
1139 vmxnet3_get_rss(struct net_device
*netdev
, struct ethtool_rxfh_param
*rxfh
)
1141 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
1142 struct UPT1_RSSConf
*rssConf
= adapter
->rss_conf
;
1143 unsigned int n
= rssConf
->indTableSize
;
1145 rxfh
->hfunc
= ETH_RSS_HASH_TOP
;
1148 if (n
> UPT1_RSS_MAX_IND_TABLE_SIZE
)
1151 rxfh
->indir
[n
] = rssConf
->indTable
[n
];
1157 vmxnet3_set_rss(struct net_device
*netdev
, struct ethtool_rxfh_param
*rxfh
,
1158 struct netlink_ext_ack
*extack
)
1161 unsigned long flags
;
1162 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
1163 struct UPT1_RSSConf
*rssConf
= adapter
->rss_conf
;
1165 /* We do not allow change in unsupported parameters */
1167 (rxfh
->hfunc
!= ETH_RSS_HASH_NO_CHANGE
&&
1168 rxfh
->hfunc
!= ETH_RSS_HASH_TOP
))
1172 for (i
= 0; i
< rssConf
->indTableSize
; i
++)
1173 rssConf
->indTable
[i
] = rxfh
->indir
[i
];
1175 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
1176 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
1177 VMXNET3_CMD_UPDATE_RSSIDT
);
1178 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
1185 static int vmxnet3_get_coalesce(struct net_device
*netdev
,
1186 struct ethtool_coalesce
*ec
,
1187 struct kernel_ethtool_coalesce
*kernel_coal
,
1188 struct netlink_ext_ack
*extack
)
1190 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
1192 if (!VMXNET3_VERSION_GE_3(adapter
))
1195 switch (adapter
->coal_conf
->coalMode
) {
1196 case VMXNET3_COALESCE_DISABLED
:
1197 /* struct ethtool_coalesce is already initialized to 0 */
1199 case VMXNET3_COALESCE_ADAPT
:
1200 ec
->use_adaptive_rx_coalesce
= true;
1202 case VMXNET3_COALESCE_STATIC
:
1203 ec
->tx_max_coalesced_frames
=
1204 adapter
->coal_conf
->coalPara
.coalStatic
.tx_comp_depth
;
1205 ec
->rx_max_coalesced_frames
=
1206 adapter
->coal_conf
->coalPara
.coalStatic
.rx_depth
;
1208 case VMXNET3_COALESCE_RBC
: {
1211 rbc_rate
= adapter
->coal_conf
->coalPara
.coalRbc
.rbc_rate
;
1212 ec
->rx_coalesce_usecs
= VMXNET3_COAL_RBC_USECS(rbc_rate
);
1222 static int vmxnet3_set_coalesce(struct net_device
*netdev
,
1223 struct ethtool_coalesce
*ec
,
1224 struct kernel_ethtool_coalesce
*kernel_coal
,
1225 struct netlink_ext_ack
*extack
)
1227 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
1228 struct Vmxnet3_DriverShared
*shared
= adapter
->shared
;
1229 union Vmxnet3_CmdInfo
*cmdInfo
= &shared
->cu
.cmdInfo
;
1230 unsigned long flags
;
1232 if (!VMXNET3_VERSION_GE_3(adapter
))
1235 if ((ec
->rx_coalesce_usecs
== 0) &&
1236 (ec
->use_adaptive_rx_coalesce
== 0) &&
1237 (ec
->tx_max_coalesced_frames
== 0) &&
1238 (ec
->rx_max_coalesced_frames
== 0)) {
1239 memset(adapter
->coal_conf
, 0, sizeof(*adapter
->coal_conf
));
1240 adapter
->coal_conf
->coalMode
= VMXNET3_COALESCE_DISABLED
;
1244 if (ec
->rx_coalesce_usecs
!= 0) {
1247 if ((ec
->use_adaptive_rx_coalesce
!= 0) ||
1248 (ec
->tx_max_coalesced_frames
!= 0) ||
1249 (ec
->rx_max_coalesced_frames
!= 0)) {
1253 rbc_rate
= VMXNET3_COAL_RBC_RATE(ec
->rx_coalesce_usecs
);
1254 if (rbc_rate
< VMXNET3_COAL_RBC_MIN_RATE
||
1255 rbc_rate
> VMXNET3_COAL_RBC_MAX_RATE
) {
1259 memset(adapter
->coal_conf
, 0, sizeof(*adapter
->coal_conf
));
1260 adapter
->coal_conf
->coalMode
= VMXNET3_COALESCE_RBC
;
1261 adapter
->coal_conf
->coalPara
.coalRbc
.rbc_rate
= rbc_rate
;
1265 if (ec
->use_adaptive_rx_coalesce
!= 0) {
1266 if (ec
->tx_max_coalesced_frames
!= 0 ||
1267 ec
->rx_max_coalesced_frames
!= 0) {
1270 memset(adapter
->coal_conf
, 0, sizeof(*adapter
->coal_conf
));
1271 adapter
->coal_conf
->coalMode
= VMXNET3_COALESCE_ADAPT
;
1275 if ((ec
->tx_max_coalesced_frames
!= 0) ||
1276 (ec
->rx_max_coalesced_frames
!= 0)) {
1277 if ((ec
->tx_max_coalesced_frames
>
1278 VMXNET3_COAL_STATIC_MAX_DEPTH
) ||
1279 (ec
->rx_max_coalesced_frames
>
1280 VMXNET3_COAL_STATIC_MAX_DEPTH
)) {
1284 memset(adapter
->coal_conf
, 0, sizeof(*adapter
->coal_conf
));
1285 adapter
->coal_conf
->coalMode
= VMXNET3_COALESCE_STATIC
;
1287 adapter
->coal_conf
->coalPara
.coalStatic
.tx_comp_depth
=
1288 (ec
->tx_max_coalesced_frames
?
1289 ec
->tx_max_coalesced_frames
:
1290 VMXNET3_COAL_STATIC_DEFAULT_DEPTH
);
1292 adapter
->coal_conf
->coalPara
.coalStatic
.rx_depth
=
1293 (ec
->rx_max_coalesced_frames
?
1294 ec
->rx_max_coalesced_frames
:
1295 VMXNET3_COAL_STATIC_DEFAULT_DEPTH
);
1297 adapter
->coal_conf
->coalPara
.coalStatic
.tx_depth
=
1298 VMXNET3_COAL_STATIC_DEFAULT_DEPTH
;
1303 adapter
->default_coal_mode
= false;
1304 if (netif_running(netdev
)) {
1305 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
1306 cmdInfo
->varConf
.confVer
= 1;
1307 cmdInfo
->varConf
.confLen
=
1308 cpu_to_le32(sizeof(*adapter
->coal_conf
));
1309 cmdInfo
->varConf
.confPA
= cpu_to_le64(adapter
->coal_conf_pa
);
1310 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
1311 VMXNET3_CMD_SET_COALESCE
);
1312 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
1318 static void vmxnet3_get_channels(struct net_device
*netdev
,
1319 struct ethtool_channels
*ec
)
1321 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
1323 if (IS_ENABLED(CONFIG_PCI_MSI
) && adapter
->intr
.type
== VMXNET3_IT_MSIX
) {
1324 if (adapter
->share_intr
== VMXNET3_INTR_BUDDYSHARE
) {
1325 ec
->combined_count
= adapter
->num_tx_queues
;
1327 ec
->rx_count
= adapter
->num_rx_queues
;
1329 adapter
->share_intr
== VMXNET3_INTR_TXSHARE
?
1330 1 : adapter
->num_tx_queues
;
1333 ec
->combined_count
= 1;
1336 ec
->other_count
= 1;
1338 /* Number of interrupts cannot be changed on the fly */
1339 /* Just set maximums to actual values */
1340 ec
->max_rx
= ec
->rx_count
;
1341 ec
->max_tx
= ec
->tx_count
;
1342 ec
->max_combined
= ec
->combined_count
;
1343 ec
->max_other
= ec
->other_count
;
1346 static const struct ethtool_ops vmxnet3_ethtool_ops
= {
1347 .supported_coalesce_params
= ETHTOOL_COALESCE_RX_USECS
|
1348 ETHTOOL_COALESCE_MAX_FRAMES
|
1349 ETHTOOL_COALESCE_USE_ADAPTIVE_RX
,
1350 .get_drvinfo
= vmxnet3_get_drvinfo
,
1351 .get_regs_len
= vmxnet3_get_regs_len
,
1352 .get_regs
= vmxnet3_get_regs
,
1353 .get_wol
= vmxnet3_get_wol
,
1354 .set_wol
= vmxnet3_set_wol
,
1355 .get_link
= ethtool_op_get_link
,
1356 .get_coalesce
= vmxnet3_get_coalesce
,
1357 .set_coalesce
= vmxnet3_set_coalesce
,
1358 .get_strings
= vmxnet3_get_strings
,
1359 .get_sset_count
= vmxnet3_get_sset_count
,
1360 .get_ethtool_stats
= vmxnet3_get_ethtool_stats
,
1361 .get_ringparam
= vmxnet3_get_ringparam
,
1362 .set_ringparam
= vmxnet3_set_ringparam
,
1363 .get_rxnfc
= vmxnet3_get_rxnfc
,
1364 .set_rxnfc
= vmxnet3_set_rxnfc
,
1366 .get_rxfh_indir_size
= vmxnet3_get_rss_indir_size
,
1367 .get_rxfh
= vmxnet3_get_rss
,
1368 .set_rxfh
= vmxnet3_set_rss
,
1370 .get_link_ksettings
= vmxnet3_get_link_ksettings
,
1371 .get_channels
= vmxnet3_get_channels
,
1374 void vmxnet3_set_ethtool_ops(struct net_device
*netdev
)
1376 netdev
->ethtool_ops
= &vmxnet3_ethtool_ops
;