2 * Linux driver for VMware's vmxnet3 ethernet NIC.
4 * Copyright (C) 2008-2009, VMware, Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; version 2 of the License and no later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 * The full GNU General Public License is included in this distribution in
21 * the file called "COPYING".
23 * Maintained by: Shreyas Bhatewara <pv-drivers@vmware.com>
28 #include "vmxnet3_int.h"
30 struct vmxnet3_stat_desc
{
31 char desc
[ETH_GSTRING_LEN
];
36 /* per tq stats maintained by the device */
37 static const struct vmxnet3_stat_desc
38 vmxnet3_tq_dev_stats
[] = {
39 /* description, offset */
41 { " TSO pkts tx", offsetof(struct UPT1_TxStats
, TSOPktsTxOK
) },
42 { " TSO bytes tx", offsetof(struct UPT1_TxStats
, TSOBytesTxOK
) },
43 { " ucast pkts tx", offsetof(struct UPT1_TxStats
, ucastPktsTxOK
) },
44 { " ucast bytes tx", offsetof(struct UPT1_TxStats
, ucastBytesTxOK
) },
45 { " mcast pkts tx", offsetof(struct UPT1_TxStats
, mcastPktsTxOK
) },
46 { " mcast bytes tx", offsetof(struct UPT1_TxStats
, mcastBytesTxOK
) },
47 { " bcast pkts tx", offsetof(struct UPT1_TxStats
, bcastPktsTxOK
) },
48 { " bcast bytes tx", offsetof(struct UPT1_TxStats
, bcastBytesTxOK
) },
49 { " pkts tx err", offsetof(struct UPT1_TxStats
, pktsTxError
) },
50 { " pkts tx discard", offsetof(struct UPT1_TxStats
, pktsTxDiscard
) },
53 /* per tq stats maintained by the driver */
54 static const struct vmxnet3_stat_desc
55 vmxnet3_tq_driver_stats
[] = {
56 /* description, offset */
57 {" drv dropped tx total", offsetof(struct vmxnet3_tq_driver_stats
,
59 { " too many frags", offsetof(struct vmxnet3_tq_driver_stats
,
60 drop_too_many_frags
) },
61 { " giant hdr", offsetof(struct vmxnet3_tq_driver_stats
,
62 drop_oversized_hdr
) },
63 { " hdr err", offsetof(struct vmxnet3_tq_driver_stats
,
64 drop_hdr_inspect_err
) },
65 { " tso", offsetof(struct vmxnet3_tq_driver_stats
,
67 { " ring full", offsetof(struct vmxnet3_tq_driver_stats
,
69 { " pkts linearized", offsetof(struct vmxnet3_tq_driver_stats
,
71 { " hdr cloned", offsetof(struct vmxnet3_tq_driver_stats
,
73 { " giant hdr", offsetof(struct vmxnet3_tq_driver_stats
,
77 /* per rq stats maintained by the device */
78 static const struct vmxnet3_stat_desc
79 vmxnet3_rq_dev_stats
[] = {
81 { " LRO pkts rx", offsetof(struct UPT1_RxStats
, LROPktsRxOK
) },
82 { " LRO byte rx", offsetof(struct UPT1_RxStats
, LROBytesRxOK
) },
83 { " ucast pkts rx", offsetof(struct UPT1_RxStats
, ucastPktsRxOK
) },
84 { " ucast bytes rx", offsetof(struct UPT1_RxStats
, ucastBytesRxOK
) },
85 { " mcast pkts rx", offsetof(struct UPT1_RxStats
, mcastPktsRxOK
) },
86 { " mcast bytes rx", offsetof(struct UPT1_RxStats
, mcastBytesRxOK
) },
87 { " bcast pkts rx", offsetof(struct UPT1_RxStats
, bcastPktsRxOK
) },
88 { " bcast bytes rx", offsetof(struct UPT1_RxStats
, bcastBytesRxOK
) },
89 { " pkts rx OOB", offsetof(struct UPT1_RxStats
, pktsRxOutOfBuf
) },
90 { " pkts rx err", offsetof(struct UPT1_RxStats
, pktsRxError
) },
93 /* per rq stats maintained by the driver */
94 static const struct vmxnet3_stat_desc
95 vmxnet3_rq_driver_stats
[] = {
96 /* description, offset */
97 { " drv dropped rx total", offsetof(struct vmxnet3_rq_driver_stats
,
99 { " err", offsetof(struct vmxnet3_rq_driver_stats
,
101 { " fcs", offsetof(struct vmxnet3_rq_driver_stats
,
103 { " rx buf alloc fail", offsetof(struct vmxnet3_rq_driver_stats
,
104 rx_buf_alloc_failure
) },
107 /* global stats maintained by the driver */
108 static const struct vmxnet3_stat_desc
109 vmxnet3_global_stats
[] = {
110 /* description, offset */
111 { "tx timeout count", offsetof(struct vmxnet3_adapter
,
116 struct rtnl_link_stats64
*
117 vmxnet3_get_stats64(struct net_device
*netdev
,
118 struct rtnl_link_stats64
*stats
)
120 struct vmxnet3_adapter
*adapter
;
121 struct vmxnet3_tq_driver_stats
*drvTxStats
;
122 struct vmxnet3_rq_driver_stats
*drvRxStats
;
123 struct UPT1_TxStats
*devTxStats
;
124 struct UPT1_RxStats
*devRxStats
;
128 adapter
= netdev_priv(netdev
);
130 /* Collect the dev stats into the shared area */
131 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
132 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
, VMXNET3_CMD_GET_STATS
);
133 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
135 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
136 devTxStats
= &adapter
->tqd_start
[i
].stats
;
137 drvTxStats
= &adapter
->tx_queue
[i
].stats
;
138 stats
->tx_packets
+= devTxStats
->ucastPktsTxOK
+
139 devTxStats
->mcastPktsTxOK
+
140 devTxStats
->bcastPktsTxOK
;
141 stats
->tx_bytes
+= devTxStats
->ucastBytesTxOK
+
142 devTxStats
->mcastBytesTxOK
+
143 devTxStats
->bcastBytesTxOK
;
144 stats
->tx_errors
+= devTxStats
->pktsTxError
;
145 stats
->tx_dropped
+= drvTxStats
->drop_total
;
148 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
149 devRxStats
= &adapter
->rqd_start
[i
].stats
;
150 drvRxStats
= &adapter
->rx_queue
[i
].stats
;
151 stats
->rx_packets
+= devRxStats
->ucastPktsRxOK
+
152 devRxStats
->mcastPktsRxOK
+
153 devRxStats
->bcastPktsRxOK
;
155 stats
->rx_bytes
+= devRxStats
->ucastBytesRxOK
+
156 devRxStats
->mcastBytesRxOK
+
157 devRxStats
->bcastBytesRxOK
;
159 stats
->rx_errors
+= devRxStats
->pktsRxError
;
160 stats
->rx_dropped
+= drvRxStats
->drop_total
;
161 stats
->multicast
+= devRxStats
->mcastPktsRxOK
;
168 vmxnet3_get_sset_count(struct net_device
*netdev
, int sset
)
170 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
173 return (ARRAY_SIZE(vmxnet3_tq_dev_stats
) +
174 ARRAY_SIZE(vmxnet3_tq_driver_stats
)) *
175 adapter
->num_tx_queues
+
176 (ARRAY_SIZE(vmxnet3_rq_dev_stats
) +
177 ARRAY_SIZE(vmxnet3_rq_driver_stats
)) *
178 adapter
->num_rx_queues
+
179 ARRAY_SIZE(vmxnet3_global_stats
);
186 /* This is a version 2 of the vmxnet3 ethtool_regs which goes hand in hand with
187 * the version 2 of the vmxnet3 support for ethtool(8) --register-dump.
188 * Therefore, if any registers are added, removed or modified, then a version
189 * bump and a corresponding change in the vmxnet3 support for ethtool(8)
190 * --register-dump would be required.
193 vmxnet3_get_regs_len(struct net_device
*netdev
)
195 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
197 return ((9 /* BAR1 registers */ +
198 (1 + adapter
->intr
.num_intrs
) +
199 (1 + adapter
->num_tx_queues
* 17 /* Tx queue registers */) +
200 (1 + adapter
->num_rx_queues
* 23 /* Rx queue registers */)) *
206 vmxnet3_get_drvinfo(struct net_device
*netdev
, struct ethtool_drvinfo
*drvinfo
)
208 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
210 strlcpy(drvinfo
->driver
, vmxnet3_driver_name
, sizeof(drvinfo
->driver
));
212 strlcpy(drvinfo
->version
, VMXNET3_DRIVER_VERSION_REPORT
,
213 sizeof(drvinfo
->version
));
215 strlcpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
),
216 sizeof(drvinfo
->bus_info
));
221 vmxnet3_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*buf
)
223 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
224 if (stringset
== ETH_SS_STATS
) {
226 for (j
= 0; j
< adapter
->num_tx_queues
; j
++) {
227 for (i
= 0; i
< ARRAY_SIZE(vmxnet3_tq_dev_stats
); i
++) {
228 memcpy(buf
, vmxnet3_tq_dev_stats
[i
].desc
,
230 buf
+= ETH_GSTRING_LEN
;
232 for (i
= 0; i
< ARRAY_SIZE(vmxnet3_tq_driver_stats
);
234 memcpy(buf
, vmxnet3_tq_driver_stats
[i
].desc
,
236 buf
+= ETH_GSTRING_LEN
;
240 for (j
= 0; j
< adapter
->num_rx_queues
; j
++) {
241 for (i
= 0; i
< ARRAY_SIZE(vmxnet3_rq_dev_stats
); i
++) {
242 memcpy(buf
, vmxnet3_rq_dev_stats
[i
].desc
,
244 buf
+= ETH_GSTRING_LEN
;
246 for (i
= 0; i
< ARRAY_SIZE(vmxnet3_rq_driver_stats
);
248 memcpy(buf
, vmxnet3_rq_driver_stats
[i
].desc
,
250 buf
+= ETH_GSTRING_LEN
;
254 for (i
= 0; i
< ARRAY_SIZE(vmxnet3_global_stats
); i
++) {
255 memcpy(buf
, vmxnet3_global_stats
[i
].desc
,
257 buf
+= ETH_GSTRING_LEN
;
262 int vmxnet3_set_features(struct net_device
*netdev
, netdev_features_t features
)
264 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
266 netdev_features_t changed
= features
^ netdev
->features
;
268 if (changed
& (NETIF_F_RXCSUM
| NETIF_F_LRO
|
269 NETIF_F_HW_VLAN_CTAG_RX
)) {
270 if (features
& NETIF_F_RXCSUM
)
271 adapter
->shared
->devRead
.misc
.uptFeatures
|=
274 adapter
->shared
->devRead
.misc
.uptFeatures
&=
277 /* update hardware LRO capability accordingly */
278 if (features
& NETIF_F_LRO
)
279 adapter
->shared
->devRead
.misc
.uptFeatures
|=
282 adapter
->shared
->devRead
.misc
.uptFeatures
&=
285 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
286 adapter
->shared
->devRead
.misc
.uptFeatures
|=
289 adapter
->shared
->devRead
.misc
.uptFeatures
&=
292 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
293 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
294 VMXNET3_CMD_UPDATE_FEATURE
);
295 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
301 vmxnet3_get_ethtool_stats(struct net_device
*netdev
,
302 struct ethtool_stats
*stats
, u64
*buf
)
304 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
310 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
311 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
, VMXNET3_CMD_GET_STATS
);
312 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
314 /* this does assume each counter is 64-bit wide */
315 for (j
= 0; j
< adapter
->num_tx_queues
; j
++) {
316 base
= (u8
*)&adapter
->tqd_start
[j
].stats
;
318 for (i
= 1; i
< ARRAY_SIZE(vmxnet3_tq_dev_stats
); i
++)
319 *buf
++ = *(u64
*)(base
+
320 vmxnet3_tq_dev_stats
[i
].offset
);
322 base
= (u8
*)&adapter
->tx_queue
[j
].stats
;
323 for (i
= 0; i
< ARRAY_SIZE(vmxnet3_tq_driver_stats
); i
++)
324 *buf
++ = *(u64
*)(base
+
325 vmxnet3_tq_driver_stats
[i
].offset
);
328 for (j
= 0; j
< adapter
->num_rx_queues
; j
++) {
329 base
= (u8
*)&adapter
->rqd_start
[j
].stats
;
331 for (i
= 1; i
< ARRAY_SIZE(vmxnet3_rq_dev_stats
); i
++)
332 *buf
++ = *(u64
*)(base
+
333 vmxnet3_rq_dev_stats
[i
].offset
);
335 base
= (u8
*)&adapter
->rx_queue
[j
].stats
;
336 for (i
= 0; i
< ARRAY_SIZE(vmxnet3_rq_driver_stats
); i
++)
337 *buf
++ = *(u64
*)(base
+
338 vmxnet3_rq_driver_stats
[i
].offset
);
341 base
= (u8
*)adapter
;
342 for (i
= 0; i
< ARRAY_SIZE(vmxnet3_global_stats
); i
++)
343 *buf
++ = *(u64
*)(base
+ vmxnet3_global_stats
[i
].offset
);
347 /* This is a version 2 of the vmxnet3 ethtool_regs which goes hand in hand with
348 * the version 2 of the vmxnet3 support for ethtool(8) --register-dump.
349 * Therefore, if any registers are added, removed or modified, then a version
350 * bump and a corresponding change in the vmxnet3 support for ethtool(8)
351 * --register-dump would be required.
354 vmxnet3_get_regs(struct net_device
*netdev
, struct ethtool_regs
*regs
, void *p
)
356 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
360 memset(p
, 0, vmxnet3_get_regs_len(netdev
));
364 /* Update vmxnet3_get_regs_len if we want to dump more registers */
366 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_VRRS
);
367 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_UVRS
);
368 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_DSAL
);
369 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_DSAH
);
370 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_CMD
);
371 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_MACL
);
372 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_MACH
);
373 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_ICR
);
374 buf
[j
++] = VMXNET3_READ_BAR1_REG(adapter
, VMXNET3_REG_ECR
);
376 buf
[j
++] = adapter
->intr
.num_intrs
;
377 for (i
= 0; i
< adapter
->intr
.num_intrs
; i
++) {
378 buf
[j
++] = VMXNET3_READ_BAR0_REG(adapter
, VMXNET3_REG_IMR
379 + i
* VMXNET3_REG_ALIGN
);
382 buf
[j
++] = adapter
->num_tx_queues
;
383 for (i
= 0; i
< adapter
->num_tx_queues
; i
++) {
384 struct vmxnet3_tx_queue
*tq
= &adapter
->tx_queue
[i
];
386 buf
[j
++] = VMXNET3_READ_BAR0_REG(adapter
, VMXNET3_REG_TXPROD
+
387 i
* VMXNET3_REG_ALIGN
);
389 buf
[j
++] = VMXNET3_GET_ADDR_LO(tq
->tx_ring
.basePA
);
390 buf
[j
++] = VMXNET3_GET_ADDR_HI(tq
->tx_ring
.basePA
);
391 buf
[j
++] = tq
->tx_ring
.size
;
392 buf
[j
++] = tq
->tx_ring
.next2fill
;
393 buf
[j
++] = tq
->tx_ring
.next2comp
;
394 buf
[j
++] = tq
->tx_ring
.gen
;
396 buf
[j
++] = VMXNET3_GET_ADDR_LO(tq
->data_ring
.basePA
);
397 buf
[j
++] = VMXNET3_GET_ADDR_HI(tq
->data_ring
.basePA
);
398 buf
[j
++] = tq
->data_ring
.size
;
399 /* transmit data ring buffer size */
400 buf
[j
++] = VMXNET3_HDR_COPY_SIZE
;
402 buf
[j
++] = VMXNET3_GET_ADDR_LO(tq
->comp_ring
.basePA
);
403 buf
[j
++] = VMXNET3_GET_ADDR_HI(tq
->comp_ring
.basePA
);
404 buf
[j
++] = tq
->comp_ring
.size
;
405 buf
[j
++] = tq
->comp_ring
.next2proc
;
406 buf
[j
++] = tq
->comp_ring
.gen
;
408 buf
[j
++] = tq
->stopped
;
411 buf
[j
++] = adapter
->num_rx_queues
;
412 for (i
= 0; i
< adapter
->num_rx_queues
; i
++) {
413 struct vmxnet3_rx_queue
*rq
= &adapter
->rx_queue
[i
];
415 buf
[j
++] = VMXNET3_READ_BAR0_REG(adapter
, VMXNET3_REG_RXPROD
+
416 i
* VMXNET3_REG_ALIGN
);
417 buf
[j
++] = VMXNET3_READ_BAR0_REG(adapter
, VMXNET3_REG_RXPROD2
+
418 i
* VMXNET3_REG_ALIGN
);
420 buf
[j
++] = VMXNET3_GET_ADDR_LO(rq
->rx_ring
[0].basePA
);
421 buf
[j
++] = VMXNET3_GET_ADDR_HI(rq
->rx_ring
[0].basePA
);
422 buf
[j
++] = rq
->rx_ring
[0].size
;
423 buf
[j
++] = rq
->rx_ring
[0].next2fill
;
424 buf
[j
++] = rq
->rx_ring
[0].next2comp
;
425 buf
[j
++] = rq
->rx_ring
[0].gen
;
427 buf
[j
++] = VMXNET3_GET_ADDR_LO(rq
->rx_ring
[1].basePA
);
428 buf
[j
++] = VMXNET3_GET_ADDR_HI(rq
->rx_ring
[1].basePA
);
429 buf
[j
++] = rq
->rx_ring
[1].size
;
430 buf
[j
++] = rq
->rx_ring
[1].next2fill
;
431 buf
[j
++] = rq
->rx_ring
[1].next2comp
;
432 buf
[j
++] = rq
->rx_ring
[1].gen
;
434 /* receive data ring */
440 buf
[j
++] = VMXNET3_GET_ADDR_LO(rq
->comp_ring
.basePA
);
441 buf
[j
++] = VMXNET3_GET_ADDR_HI(rq
->comp_ring
.basePA
);
442 buf
[j
++] = rq
->comp_ring
.size
;
443 buf
[j
++] = rq
->comp_ring
.next2proc
;
444 buf
[j
++] = rq
->comp_ring
.gen
;
450 vmxnet3_get_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
452 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
454 wol
->supported
= WAKE_UCAST
| WAKE_ARP
| WAKE_MAGIC
;
455 wol
->wolopts
= adapter
->wol
;
460 vmxnet3_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
462 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
464 if (wol
->wolopts
& (WAKE_PHY
| WAKE_MCAST
| WAKE_BCAST
|
469 adapter
->wol
= wol
->wolopts
;
471 device_set_wakeup_enable(&adapter
->pdev
->dev
, adapter
->wol
);
478 vmxnet3_get_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
480 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
482 ecmd
->supported
= SUPPORTED_10000baseT_Full
| SUPPORTED_1000baseT_Full
|
484 ecmd
->advertising
= ADVERTISED_TP
;
485 ecmd
->port
= PORT_TP
;
486 ecmd
->transceiver
= XCVR_INTERNAL
;
488 if (adapter
->link_speed
) {
489 ethtool_cmd_speed_set(ecmd
, adapter
->link_speed
);
490 ecmd
->duplex
= DUPLEX_FULL
;
492 ethtool_cmd_speed_set(ecmd
, SPEED_UNKNOWN
);
493 ecmd
->duplex
= DUPLEX_UNKNOWN
;
500 vmxnet3_get_ringparam(struct net_device
*netdev
,
501 struct ethtool_ringparam
*param
)
503 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
505 param
->rx_max_pending
= VMXNET3_RX_RING_MAX_SIZE
;
506 param
->tx_max_pending
= VMXNET3_TX_RING_MAX_SIZE
;
507 param
->rx_mini_max_pending
= 0;
508 param
->rx_jumbo_max_pending
= VMXNET3_RX_RING2_MAX_SIZE
;
510 param
->rx_pending
= adapter
->rx_ring_size
;
511 param
->tx_pending
= adapter
->tx_ring_size
;
512 param
->rx_mini_pending
= 0;
513 param
->rx_jumbo_pending
= adapter
->rx_ring2_size
;
518 vmxnet3_set_ringparam(struct net_device
*netdev
,
519 struct ethtool_ringparam
*param
)
521 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
522 u32 new_tx_ring_size
, new_rx_ring_size
, new_rx_ring2_size
;
526 if (param
->tx_pending
== 0 || param
->tx_pending
>
527 VMXNET3_TX_RING_MAX_SIZE
)
530 if (param
->rx_pending
== 0 || param
->rx_pending
>
531 VMXNET3_RX_RING_MAX_SIZE
)
534 if (param
->rx_jumbo_pending
== 0 ||
535 param
->rx_jumbo_pending
> VMXNET3_RX_RING2_MAX_SIZE
)
538 /* if adapter not yet initialized, do nothing */
539 if (adapter
->rx_buf_per_pkt
== 0) {
540 netdev_err(netdev
, "adapter not completely initialized, "
541 "ring size cannot be changed yet\n");
545 /* round it up to a multiple of VMXNET3_RING_SIZE_ALIGN */
546 new_tx_ring_size
= (param
->tx_pending
+ VMXNET3_RING_SIZE_MASK
) &
547 ~VMXNET3_RING_SIZE_MASK
;
548 new_tx_ring_size
= min_t(u32
, new_tx_ring_size
,
549 VMXNET3_TX_RING_MAX_SIZE
);
550 if (new_tx_ring_size
> VMXNET3_TX_RING_MAX_SIZE
|| (new_tx_ring_size
%
551 VMXNET3_RING_SIZE_ALIGN
) != 0)
554 /* ring0 has to be a multiple of
555 * rx_buf_per_pkt * VMXNET3_RING_SIZE_ALIGN
557 sz
= adapter
->rx_buf_per_pkt
* VMXNET3_RING_SIZE_ALIGN
;
558 new_rx_ring_size
= (param
->rx_pending
+ sz
- 1) / sz
* sz
;
559 new_rx_ring_size
= min_t(u32
, new_rx_ring_size
,
560 VMXNET3_RX_RING_MAX_SIZE
/ sz
* sz
);
561 if (new_rx_ring_size
> VMXNET3_RX_RING_MAX_SIZE
|| (new_rx_ring_size
%
565 /* ring2 has to be a multiple of VMXNET3_RING_SIZE_ALIGN */
566 new_rx_ring2_size
= (param
->rx_jumbo_pending
+ VMXNET3_RING_SIZE_MASK
) &
567 ~VMXNET3_RING_SIZE_MASK
;
568 new_rx_ring2_size
= min_t(u32
, new_rx_ring2_size
,
569 VMXNET3_RX_RING2_MAX_SIZE
);
571 if (new_tx_ring_size
== adapter
->tx_ring_size
&&
572 new_rx_ring_size
== adapter
->rx_ring_size
&&
573 new_rx_ring2_size
== adapter
->rx_ring2_size
) {
578 * Reset_work may be in the middle of resetting the device, wait for its
581 while (test_and_set_bit(VMXNET3_STATE_BIT_RESETTING
, &adapter
->state
))
584 if (netif_running(netdev
)) {
585 vmxnet3_quiesce_dev(adapter
);
586 vmxnet3_reset_dev(adapter
);
588 /* recreate the rx queue and the tx queue based on the
590 vmxnet3_tq_destroy_all(adapter
);
591 vmxnet3_rq_destroy_all(adapter
);
593 err
= vmxnet3_create_queues(adapter
, new_tx_ring_size
,
594 new_rx_ring_size
, new_rx_ring2_size
);
597 /* failed, most likely because of OOM, try default
599 netdev_err(netdev
, "failed to apply new sizes, "
600 "try the default ones\n");
601 new_rx_ring_size
= VMXNET3_DEF_RX_RING_SIZE
;
602 new_rx_ring2_size
= VMXNET3_DEF_RX_RING2_SIZE
;
603 new_tx_ring_size
= VMXNET3_DEF_TX_RING_SIZE
;
604 err
= vmxnet3_create_queues(adapter
,
609 netdev_err(netdev
, "failed to create queues "
610 "with default sizes. Closing it\n");
615 err
= vmxnet3_activate_dev(adapter
);
617 netdev_err(netdev
, "failed to re-activate, error %d."
618 " Closing it\n", err
);
620 adapter
->tx_ring_size
= new_tx_ring_size
;
621 adapter
->rx_ring_size
= new_rx_ring_size
;
622 adapter
->rx_ring2_size
= new_rx_ring2_size
;
625 clear_bit(VMXNET3_STATE_BIT_RESETTING
, &adapter
->state
);
627 vmxnet3_force_close(adapter
);
634 vmxnet3_get_rxnfc(struct net_device
*netdev
, struct ethtool_rxnfc
*info
,
637 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
639 case ETHTOOL_GRXRINGS
:
640 info
->data
= adapter
->num_rx_queues
;
648 vmxnet3_get_rss_indir_size(struct net_device
*netdev
)
650 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
651 struct UPT1_RSSConf
*rssConf
= adapter
->rss_conf
;
653 return rssConf
->indTableSize
;
657 vmxnet3_get_rss(struct net_device
*netdev
, u32
*p
, u8
*key
, u8
*hfunc
)
659 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
660 struct UPT1_RSSConf
*rssConf
= adapter
->rss_conf
;
661 unsigned int n
= rssConf
->indTableSize
;
664 *hfunc
= ETH_RSS_HASH_TOP
;
668 p
[n
] = rssConf
->indTable
[n
];
674 vmxnet3_set_rss(struct net_device
*netdev
, const u32
*p
, const u8
*key
,
679 struct vmxnet3_adapter
*adapter
= netdev_priv(netdev
);
680 struct UPT1_RSSConf
*rssConf
= adapter
->rss_conf
;
682 /* We do not allow change in unsupported parameters */
684 (hfunc
!= ETH_RSS_HASH_NO_CHANGE
&& hfunc
!= ETH_RSS_HASH_TOP
))
688 for (i
= 0; i
< rssConf
->indTableSize
; i
++)
689 rssConf
->indTable
[i
] = p
[i
];
691 spin_lock_irqsave(&adapter
->cmd_lock
, flags
);
692 VMXNET3_WRITE_BAR1_REG(adapter
, VMXNET3_REG_CMD
,
693 VMXNET3_CMD_UPDATE_RSSIDT
);
694 spin_unlock_irqrestore(&adapter
->cmd_lock
, flags
);
701 static const struct ethtool_ops vmxnet3_ethtool_ops
= {
702 .get_settings
= vmxnet3_get_settings
,
703 .get_drvinfo
= vmxnet3_get_drvinfo
,
704 .get_regs_len
= vmxnet3_get_regs_len
,
705 .get_regs
= vmxnet3_get_regs
,
706 .get_wol
= vmxnet3_get_wol
,
707 .set_wol
= vmxnet3_set_wol
,
708 .get_link
= ethtool_op_get_link
,
709 .get_strings
= vmxnet3_get_strings
,
710 .get_sset_count
= vmxnet3_get_sset_count
,
711 .get_ethtool_stats
= vmxnet3_get_ethtool_stats
,
712 .get_ringparam
= vmxnet3_get_ringparam
,
713 .set_ringparam
= vmxnet3_set_ringparam
,
714 .get_rxnfc
= vmxnet3_get_rxnfc
,
716 .get_rxfh_indir_size
= vmxnet3_get_rss_indir_size
,
717 .get_rxfh
= vmxnet3_get_rss
,
718 .set_rxfh
= vmxnet3_set_rss
,
722 void vmxnet3_set_ethtool_ops(struct net_device
*netdev
)
724 netdev
->ethtool_ops
= &vmxnet3_ethtool_ops
;