2 * QEMU VMWARE VMXNET3 paravirtual NIC
4 * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
6 * Developed by Daynix Computing LTD (http://www.daynix.com)
9 * Dmitry Fleytman <dmitry@daynix.com>
10 * Tamir Shomer <tamirs@daynix.com>
11 * Yan Vugenfirer <yan@daynix.com>
13 * This work is licensed under the terms of the GNU GPL, version 2.
14 * See the COPYING file in the top-level directory.
18 #include "qemu/osdep.h"
20 #include "hw/pci/pci.h"
23 #include "net/checksum.h"
24 #include "sysemu/sysemu.h"
25 #include "qemu-common.h"
26 #include "qemu/bswap.h"
27 #include "hw/pci/msix.h"
28 #include "hw/pci/msi.h"
29 #include "migration/register.h"
32 #include "vmxnet_debug.h"
33 #include "vmware_utils.h"
34 #include "net_tx_pkt.h"
35 #include "net_rx_pkt.h"
37 #define PCI_DEVICE_ID_VMWARE_VMXNET3_REVISION 0x1
38 #define VMXNET3_MSIX_BAR_SIZE 0x2000
39 #define MIN_BUF_SIZE 60
41 /* Compatibility flags for migration */
42 #define VMXNET3_COMPAT_FLAG_OLD_MSI_OFFSETS_BIT 0
43 #define VMXNET3_COMPAT_FLAG_OLD_MSI_OFFSETS \
44 (1 << VMXNET3_COMPAT_FLAG_OLD_MSI_OFFSETS_BIT)
45 #define VMXNET3_COMPAT_FLAG_DISABLE_PCIE_BIT 1
46 #define VMXNET3_COMPAT_FLAG_DISABLE_PCIE \
47 (1 << VMXNET3_COMPAT_FLAG_DISABLE_PCIE_BIT)
49 #define VMXNET3_EXP_EP_OFFSET (0x48)
50 #define VMXNET3_MSI_OFFSET(s) \
51 ((s)->compat_flags & VMXNET3_COMPAT_FLAG_OLD_MSI_OFFSETS ? 0x50 : 0x84)
52 #define VMXNET3_MSIX_OFFSET(s) \
53 ((s)->compat_flags & VMXNET3_COMPAT_FLAG_OLD_MSI_OFFSETS ? 0 : 0x9c)
54 #define VMXNET3_DSN_OFFSET (0x100)
56 #define VMXNET3_BAR0_IDX (0)
57 #define VMXNET3_BAR1_IDX (1)
58 #define VMXNET3_MSIX_BAR_IDX (2)
60 #define VMXNET3_OFF_MSIX_TABLE (0x000)
61 #define VMXNET3_OFF_MSIX_PBA(s) \
62 ((s)->compat_flags & VMXNET3_COMPAT_FLAG_OLD_MSI_OFFSETS ? 0x800 : 0x1000)
64 /* Link speed in Mbps should be shifted by 16 */
65 #define VMXNET3_LINK_SPEED (1000 << 16)
67 /* Link status: 1 - up, 0 - down. */
68 #define VMXNET3_LINK_STATUS_UP 0x1
70 /* Least significant bit should be set for revision and version */
71 #define VMXNET3_UPT_REVISION 0x1
72 #define VMXNET3_DEVICE_REVISION 0x1
74 /* Number of interrupt vectors for non-MSIx modes */
75 #define VMXNET3_MAX_NMSIX_INTRS (1)
77 /* Macros for rings descriptors access */
78 #define VMXNET3_READ_TX_QUEUE_DESCR8(_d, dpa, field) \
79 (vmw_shmem_ld8(_d, dpa + offsetof(struct Vmxnet3_TxQueueDesc, field)))
81 #define VMXNET3_WRITE_TX_QUEUE_DESCR8(_d, dpa, field, value) \
82 (vmw_shmem_st8(_d, dpa + offsetof(struct Vmxnet3_TxQueueDesc, field, value)))
84 #define VMXNET3_READ_TX_QUEUE_DESCR32(_d, dpa, field) \
85 (vmw_shmem_ld32(_d, dpa + offsetof(struct Vmxnet3_TxQueueDesc, field)))
87 #define VMXNET3_WRITE_TX_QUEUE_DESCR32(_d, dpa, field, value) \
88 (vmw_shmem_st32(_d, dpa + offsetof(struct Vmxnet3_TxQueueDesc, field), value))
90 #define VMXNET3_READ_TX_QUEUE_DESCR64(_d, dpa, field) \
91 (vmw_shmem_ld64(_d, dpa + offsetof(struct Vmxnet3_TxQueueDesc, field)))
93 #define VMXNET3_WRITE_TX_QUEUE_DESCR64(_d, dpa, field, value) \
94 (vmw_shmem_st64(_d, dpa + offsetof(struct Vmxnet3_TxQueueDesc, field), value))
96 #define VMXNET3_READ_RX_QUEUE_DESCR64(_d, dpa, field) \
97 (vmw_shmem_ld64(_d, dpa + offsetof(struct Vmxnet3_RxQueueDesc, field)))
99 #define VMXNET3_READ_RX_QUEUE_DESCR32(_d, dpa, field) \
100 (vmw_shmem_ld32(_d, dpa + offsetof(struct Vmxnet3_RxQueueDesc, field)))
102 #define VMXNET3_WRITE_RX_QUEUE_DESCR64(_d, dpa, field, value) \
103 (vmw_shmem_st64(_d, dpa + offsetof(struct Vmxnet3_RxQueueDesc, field), value))
105 #define VMXNET3_WRITE_RX_QUEUE_DESCR8(_d, dpa, field, value) \
106 (vmw_shmem_st8(_d, dpa + offsetof(struct Vmxnet3_RxQueueDesc, field), value))
108 /* Macros for guest driver shared area access */
109 #define VMXNET3_READ_DRV_SHARED64(_d, shpa, field) \
110 (vmw_shmem_ld64(_d, shpa + offsetof(struct Vmxnet3_DriverShared, field)))
112 #define VMXNET3_READ_DRV_SHARED32(_d, shpa, field) \
113 (vmw_shmem_ld32(_d, shpa + offsetof(struct Vmxnet3_DriverShared, field)))
115 #define VMXNET3_WRITE_DRV_SHARED32(_d, shpa, field, val) \
116 (vmw_shmem_st32(_d, shpa + offsetof(struct Vmxnet3_DriverShared, field), val))
118 #define VMXNET3_READ_DRV_SHARED16(_d, shpa, field) \
119 (vmw_shmem_ld16(_d, shpa + offsetof(struct Vmxnet3_DriverShared, field)))
121 #define VMXNET3_READ_DRV_SHARED8(_d, shpa, field) \
122 (vmw_shmem_ld8(_d, shpa + offsetof(struct Vmxnet3_DriverShared, field)))
124 #define VMXNET3_READ_DRV_SHARED(_d, shpa, field, b, l) \
125 (vmw_shmem_read(_d, shpa + offsetof(struct Vmxnet3_DriverShared, field), b, l))
127 #define VMXNET_FLAG_IS_SET(field, flag) (((field) & (flag)) == (flag))
129 typedef struct VMXNET3Class
{
130 PCIDeviceClass parent_class
;
131 DeviceRealize parent_dc_realize
;
134 #define TYPE_VMXNET3 "vmxnet3"
135 #define VMXNET3(obj) OBJECT_CHECK(VMXNET3State, (obj), TYPE_VMXNET3)
137 #define VMXNET3_DEVICE_CLASS(klass) \
138 OBJECT_CLASS_CHECK(VMXNET3Class, (klass), TYPE_VMXNET3)
139 #define VMXNET3_DEVICE_GET_CLASS(obj) \
140 OBJECT_GET_CLASS(VMXNET3Class, (obj), TYPE_VMXNET3)
142 /* Cyclic ring abstraction */
151 static inline void vmxnet3_ring_init(PCIDevice
*d
,
160 ring
->cell_size
= cell_size
;
161 ring
->gen
= VMXNET3_INIT_GEN
;
165 vmw_shmem_set(d
, pa
, 0, size
* cell_size
);
169 #define VMXNET3_RING_DUMP(macro, ring_name, ridx, r) \
170 macro("%s#%d: base %" PRIx64 " size %u cell_size %u gen %d next %u", \
171 (ring_name), (ridx), \
172 (r)->pa, (r)->size, (r)->cell_size, (r)->gen, (r)->next)
174 static inline void vmxnet3_ring_inc(Vmxnet3Ring
*ring
)
176 if (++ring
->next
>= ring
->size
) {
182 static inline void vmxnet3_ring_dec(Vmxnet3Ring
*ring
)
184 if (ring
->next
-- == 0) {
185 ring
->next
= ring
->size
- 1;
190 static inline hwaddr
vmxnet3_ring_curr_cell_pa(Vmxnet3Ring
*ring
)
192 return ring
->pa
+ ring
->next
* ring
->cell_size
;
195 static inline void vmxnet3_ring_read_curr_cell(PCIDevice
*d
, Vmxnet3Ring
*ring
,
198 vmw_shmem_read(d
, vmxnet3_ring_curr_cell_pa(ring
), buff
, ring
->cell_size
);
201 static inline void vmxnet3_ring_write_curr_cell(PCIDevice
*d
, Vmxnet3Ring
*ring
,
204 vmw_shmem_write(d
, vmxnet3_ring_curr_cell_pa(ring
), buff
, ring
->cell_size
);
207 static inline size_t vmxnet3_ring_curr_cell_idx(Vmxnet3Ring
*ring
)
212 static inline uint8_t vmxnet3_ring_curr_gen(Vmxnet3Ring
*ring
)
217 /* Debug trace-related functions */
219 vmxnet3_dump_tx_descr(struct Vmxnet3_TxDesc
*descr
)
221 VMW_PKPRN("TX DESCR: "
222 "addr %" PRIx64
", len: %d, gen: %d, rsvd: %d, "
223 "dtype: %d, ext1: %d, msscof: %d, hlen: %d, om: %d, "
224 "eop: %d, cq: %d, ext2: %d, ti: %d, tci: %d",
225 descr
->addr
, descr
->len
, descr
->gen
, descr
->rsvd
,
226 descr
->dtype
, descr
->ext1
, descr
->msscof
, descr
->hlen
, descr
->om
,
227 descr
->eop
, descr
->cq
, descr
->ext2
, descr
->ti
, descr
->tci
);
231 vmxnet3_dump_virt_hdr(struct virtio_net_hdr
*vhdr
)
233 VMW_PKPRN("VHDR: flags 0x%x, gso_type: 0x%x, hdr_len: %d, gso_size: %d, "
234 "csum_start: %d, csum_offset: %d",
235 vhdr
->flags
, vhdr
->gso_type
, vhdr
->hdr_len
, vhdr
->gso_size
,
236 vhdr
->csum_start
, vhdr
->csum_offset
);
240 vmxnet3_dump_rx_descr(struct Vmxnet3_RxDesc
*descr
)
242 VMW_PKPRN("RX DESCR: addr %" PRIx64
", len: %d, gen: %d, rsvd: %d, "
243 "dtype: %d, ext1: %d, btype: %d",
244 descr
->addr
, descr
->len
, descr
->gen
,
245 descr
->rsvd
, descr
->dtype
, descr
->ext1
, descr
->btype
);
248 /* Device state and helper functions */
249 #define VMXNET3_RX_RINGS_PER_QUEUE (2)
253 Vmxnet3Ring comp_ring
;
257 struct UPT1_TxStats txq_stats
;
261 Vmxnet3Ring rx_ring
[VMXNET3_RX_RINGS_PER_QUEUE
];
262 Vmxnet3Ring comp_ring
;
265 struct UPT1_RxStats rxq_stats
;
275 PCIDevice parent_obj
;
280 MemoryRegion msix_bar
;
282 Vmxnet3RxqDescr rxq_descr
[VMXNET3_DEVICE_MAX_RX_QUEUES
];
283 Vmxnet3TxqDescr txq_descr
[VMXNET3_DEVICE_MAX_TX_QUEUES
];
285 /* Whether MSI-X support was installed successfully */
288 hwaddr temp_shared_guest_driver_memory
;
292 /* This boolean tells whether RX packet being indicated has to */
293 /* be split into head and body chunks from different RX rings */
294 bool rx_packets_compound
;
296 bool rx_vlan_stripping
;
304 /* Maximum number of fragments for indicated TX packets */
305 uint32_t max_tx_frags
;
307 /* Maximum number of fragments for indicated RX packets */
308 uint16_t max_rx_frags
;
310 /* Index for events interrupt */
311 uint8_t event_int_idx
;
313 /* Whether automatic interrupts masking enabled */
314 bool auto_int_masking
;
318 /* TX packets to QEMU interface */
319 struct NetTxPkt
*tx_pkt
;
320 uint32_t offload_mode
;
321 uint32_t cso_or_gso_size
;
325 struct NetRxPkt
*rx_pkt
;
328 bool skip_current_tx_pkt
;
330 uint32_t device_active
;
331 uint32_t last_command
;
333 uint32_t link_status_and_speed
;
335 Vmxnet3IntState interrupt_states
[VMXNET3_MAX_INTRS
];
337 uint32_t temp_mac
; /* To store the low part first */
340 uint32_t vlan_table
[VMXNET3_VFT_SIZE
];
343 uint32_t mcast_list_len
;
344 uint32_t mcast_list_buff_size
; /* needed for live migration. */
346 /* Compatibility flags for migration */
347 uint32_t compat_flags
;
350 /* Interrupt management */
353 * This function returns sign whether interrupt line is in asserted state
354 * This depends on the type of interrupt used. For INTX interrupt line will
355 * be asserted until explicit deassertion, for MSI(X) interrupt line will
356 * be deasserted automatically due to notification semantics of the MSI(X)
359 static bool _vmxnet3_assert_interrupt_line(VMXNET3State
*s
, uint32_t int_idx
)
361 PCIDevice
*d
= PCI_DEVICE(s
);
363 if (s
->msix_used
&& msix_enabled(d
)) {
364 VMW_IRPRN("Sending MSI-X notification for vector %u", int_idx
);
365 msix_notify(d
, int_idx
);
368 if (msi_enabled(d
)) {
369 VMW_IRPRN("Sending MSI notification for vector %u", int_idx
);
370 msi_notify(d
, int_idx
);
374 VMW_IRPRN("Asserting line for interrupt %u", int_idx
);
379 static void _vmxnet3_deassert_interrupt_line(VMXNET3State
*s
, int lidx
)
381 PCIDevice
*d
= PCI_DEVICE(s
);
384 * This function should never be called for MSI(X) interrupts
385 * because deassertion never required for message interrupts
387 assert(!s
->msix_used
|| !msix_enabled(d
));
389 * This function should never be called for MSI(X) interrupts
390 * because deassertion never required for message interrupts
392 assert(!msi_enabled(d
));
394 VMW_IRPRN("Deasserting line for interrupt %u", lidx
);
398 static void vmxnet3_update_interrupt_line_state(VMXNET3State
*s
, int lidx
)
400 if (!s
->interrupt_states
[lidx
].is_pending
&&
401 s
->interrupt_states
[lidx
].is_asserted
) {
402 VMW_IRPRN("New interrupt line state for index %d is DOWN", lidx
);
403 _vmxnet3_deassert_interrupt_line(s
, lidx
);
404 s
->interrupt_states
[lidx
].is_asserted
= false;
408 if (s
->interrupt_states
[lidx
].is_pending
&&
409 !s
->interrupt_states
[lidx
].is_masked
&&
410 !s
->interrupt_states
[lidx
].is_asserted
) {
411 VMW_IRPRN("New interrupt line state for index %d is UP", lidx
);
412 s
->interrupt_states
[lidx
].is_asserted
=
413 _vmxnet3_assert_interrupt_line(s
, lidx
);
414 s
->interrupt_states
[lidx
].is_pending
= false;
419 static void vmxnet3_trigger_interrupt(VMXNET3State
*s
, int lidx
)
421 PCIDevice
*d
= PCI_DEVICE(s
);
422 s
->interrupt_states
[lidx
].is_pending
= true;
423 vmxnet3_update_interrupt_line_state(s
, lidx
);
425 if (s
->msix_used
&& msix_enabled(d
) && s
->auto_int_masking
) {
429 if (msi_enabled(d
) && s
->auto_int_masking
) {
436 s
->interrupt_states
[lidx
].is_masked
= true;
437 vmxnet3_update_interrupt_line_state(s
, lidx
);
440 static bool vmxnet3_interrupt_asserted(VMXNET3State
*s
, int lidx
)
442 return s
->interrupt_states
[lidx
].is_asserted
;
445 static void vmxnet3_clear_interrupt(VMXNET3State
*s
, int int_idx
)
447 s
->interrupt_states
[int_idx
].is_pending
= false;
448 if (s
->auto_int_masking
) {
449 s
->interrupt_states
[int_idx
].is_masked
= true;
451 vmxnet3_update_interrupt_line_state(s
, int_idx
);
455 vmxnet3_on_interrupt_mask_changed(VMXNET3State
*s
, int lidx
, bool is_masked
)
457 s
->interrupt_states
[lidx
].is_masked
= is_masked
;
458 vmxnet3_update_interrupt_line_state(s
, lidx
);
461 static bool vmxnet3_verify_driver_magic(PCIDevice
*d
, hwaddr dshmem
)
463 return (VMXNET3_READ_DRV_SHARED32(d
, dshmem
, magic
) == VMXNET3_REV1_MAGIC
);
466 #define VMXNET3_GET_BYTE(x, byte_num) (((x) >> (byte_num)*8) & 0xFF)
467 #define VMXNET3_MAKE_BYTE(byte_num, val) \
468 (((uint32_t)((val) & 0xFF)) << (byte_num)*8)
470 static void vmxnet3_set_variable_mac(VMXNET3State
*s
, uint32_t h
, uint32_t l
)
472 s
->conf
.macaddr
.a
[0] = VMXNET3_GET_BYTE(l
, 0);
473 s
->conf
.macaddr
.a
[1] = VMXNET3_GET_BYTE(l
, 1);
474 s
->conf
.macaddr
.a
[2] = VMXNET3_GET_BYTE(l
, 2);
475 s
->conf
.macaddr
.a
[3] = VMXNET3_GET_BYTE(l
, 3);
476 s
->conf
.macaddr
.a
[4] = VMXNET3_GET_BYTE(h
, 0);
477 s
->conf
.macaddr
.a
[5] = VMXNET3_GET_BYTE(h
, 1);
479 VMW_CFPRN("Variable MAC: " MAC_FMT
, MAC_ARG(s
->conf
.macaddr
.a
));
481 qemu_format_nic_info_str(qemu_get_queue(s
->nic
), s
->conf
.macaddr
.a
);
484 static uint64_t vmxnet3_get_mac_low(MACAddr
*addr
)
486 return VMXNET3_MAKE_BYTE(0, addr
->a
[0]) |
487 VMXNET3_MAKE_BYTE(1, addr
->a
[1]) |
488 VMXNET3_MAKE_BYTE(2, addr
->a
[2]) |
489 VMXNET3_MAKE_BYTE(3, addr
->a
[3]);
492 static uint64_t vmxnet3_get_mac_high(MACAddr
*addr
)
494 return VMXNET3_MAKE_BYTE(0, addr
->a
[4]) |
495 VMXNET3_MAKE_BYTE(1, addr
->a
[5]);
499 vmxnet3_inc_tx_consumption_counter(VMXNET3State
*s
, int qidx
)
501 vmxnet3_ring_inc(&s
->txq_descr
[qidx
].tx_ring
);
505 vmxnet3_inc_rx_consumption_counter(VMXNET3State
*s
, int qidx
, int ridx
)
507 vmxnet3_ring_inc(&s
->rxq_descr
[qidx
].rx_ring
[ridx
]);
511 vmxnet3_inc_tx_completion_counter(VMXNET3State
*s
, int qidx
)
513 vmxnet3_ring_inc(&s
->txq_descr
[qidx
].comp_ring
);
517 vmxnet3_inc_rx_completion_counter(VMXNET3State
*s
, int qidx
)
519 vmxnet3_ring_inc(&s
->rxq_descr
[qidx
].comp_ring
);
523 vmxnet3_dec_rx_completion_counter(VMXNET3State
*s
, int qidx
)
525 vmxnet3_ring_dec(&s
->rxq_descr
[qidx
].comp_ring
);
528 static void vmxnet3_complete_packet(VMXNET3State
*s
, int qidx
, uint32_t tx_ridx
)
530 struct Vmxnet3_TxCompDesc txcq_descr
;
531 PCIDevice
*d
= PCI_DEVICE(s
);
533 VMXNET3_RING_DUMP(VMW_RIPRN
, "TXC", qidx
, &s
->txq_descr
[qidx
].comp_ring
);
535 memset(&txcq_descr
, 0, sizeof(txcq_descr
));
536 txcq_descr
.txdIdx
= tx_ridx
;
537 txcq_descr
.gen
= vmxnet3_ring_curr_gen(&s
->txq_descr
[qidx
].comp_ring
);
538 txcq_descr
.val1
= cpu_to_le32(txcq_descr
.val1
);
539 txcq_descr
.val2
= cpu_to_le32(txcq_descr
.val2
);
540 vmxnet3_ring_write_curr_cell(d
, &s
->txq_descr
[qidx
].comp_ring
, &txcq_descr
);
542 /* Flush changes in TX descriptor before changing the counter value */
545 vmxnet3_inc_tx_completion_counter(s
, qidx
);
546 vmxnet3_trigger_interrupt(s
, s
->txq_descr
[qidx
].intr_idx
);
550 vmxnet3_setup_tx_offloads(VMXNET3State
*s
)
552 switch (s
->offload_mode
) {
553 case VMXNET3_OM_NONE
:
554 net_tx_pkt_build_vheader(s
->tx_pkt
, false, false, 0);
557 case VMXNET3_OM_CSUM
:
558 net_tx_pkt_build_vheader(s
->tx_pkt
, false, true, 0);
559 VMW_PKPRN("L4 CSO requested\n");
563 net_tx_pkt_build_vheader(s
->tx_pkt
, true, true,
565 net_tx_pkt_update_ip_checksums(s
->tx_pkt
);
566 VMW_PKPRN("GSO offload requested.");
570 g_assert_not_reached();
578 vmxnet3_tx_retrieve_metadata(VMXNET3State
*s
,
579 const struct Vmxnet3_TxDesc
*txd
)
581 s
->offload_mode
= txd
->om
;
582 s
->cso_or_gso_size
= txd
->msscof
;
584 s
->needs_vlan
= txd
->ti
;
588 VMXNET3_PKT_STATUS_OK
,
589 VMXNET3_PKT_STATUS_ERROR
,
590 VMXNET3_PKT_STATUS_DISCARD
,/* only for tx */
591 VMXNET3_PKT_STATUS_OUT_OF_BUF
/* only for rx */
595 vmxnet3_on_tx_done_update_stats(VMXNET3State
*s
, int qidx
,
596 Vmxnet3PktStatus status
)
598 size_t tot_len
= net_tx_pkt_get_total_len(s
->tx_pkt
);
599 struct UPT1_TxStats
*stats
= &s
->txq_descr
[qidx
].txq_stats
;
602 case VMXNET3_PKT_STATUS_OK
:
603 switch (net_tx_pkt_get_packet_type(s
->tx_pkt
)) {
605 stats
->bcastPktsTxOK
++;
606 stats
->bcastBytesTxOK
+= tot_len
;
609 stats
->mcastPktsTxOK
++;
610 stats
->mcastBytesTxOK
+= tot_len
;
613 stats
->ucastPktsTxOK
++;
614 stats
->ucastBytesTxOK
+= tot_len
;
617 g_assert_not_reached();
620 if (s
->offload_mode
== VMXNET3_OM_TSO
) {
622 * According to VMWARE headers this statistic is a number
623 * of packets after segmentation but since we don't have
624 * this information in QEMU model, the best we can do is to
625 * provide number of non-segmented packets
627 stats
->TSOPktsTxOK
++;
628 stats
->TSOBytesTxOK
+= tot_len
;
632 case VMXNET3_PKT_STATUS_DISCARD
:
633 stats
->pktsTxDiscard
++;
636 case VMXNET3_PKT_STATUS_ERROR
:
637 stats
->pktsTxError
++;
641 g_assert_not_reached();
646 vmxnet3_on_rx_done_update_stats(VMXNET3State
*s
,
648 Vmxnet3PktStatus status
)
650 struct UPT1_RxStats
*stats
= &s
->rxq_descr
[qidx
].rxq_stats
;
651 size_t tot_len
= net_rx_pkt_get_total_len(s
->rx_pkt
);
654 case VMXNET3_PKT_STATUS_OUT_OF_BUF
:
655 stats
->pktsRxOutOfBuf
++;
658 case VMXNET3_PKT_STATUS_ERROR
:
659 stats
->pktsRxError
++;
661 case VMXNET3_PKT_STATUS_OK
:
662 switch (net_rx_pkt_get_packet_type(s
->rx_pkt
)) {
664 stats
->bcastPktsRxOK
++;
665 stats
->bcastBytesRxOK
+= tot_len
;
668 stats
->mcastPktsRxOK
++;
669 stats
->mcastBytesRxOK
+= tot_len
;
672 stats
->ucastPktsRxOK
++;
673 stats
->ucastBytesRxOK
+= tot_len
;
676 g_assert_not_reached();
679 if (tot_len
> s
->mtu
) {
680 stats
->LROPktsRxOK
++;
681 stats
->LROBytesRxOK
+= tot_len
;
685 g_assert_not_reached();
690 vmxnet3_ring_read_curr_txdesc(PCIDevice
*pcidev
, Vmxnet3Ring
*ring
,
691 struct Vmxnet3_TxDesc
*txd
)
693 vmxnet3_ring_read_curr_cell(pcidev
, ring
, txd
);
694 txd
->addr
= le64_to_cpu(txd
->addr
);
695 txd
->val1
= le32_to_cpu(txd
->val1
);
696 txd
->val2
= le32_to_cpu(txd
->val2
);
700 vmxnet3_pop_next_tx_descr(VMXNET3State
*s
,
702 struct Vmxnet3_TxDesc
*txd
,
705 Vmxnet3Ring
*ring
= &s
->txq_descr
[qidx
].tx_ring
;
706 PCIDevice
*d
= PCI_DEVICE(s
);
708 vmxnet3_ring_read_curr_txdesc(d
, ring
, txd
);
709 if (txd
->gen
== vmxnet3_ring_curr_gen(ring
)) {
710 /* Only read after generation field verification */
712 /* Re-read to be sure we got the latest version */
713 vmxnet3_ring_read_curr_txdesc(d
, ring
, txd
);
714 VMXNET3_RING_DUMP(VMW_RIPRN
, "TX", qidx
, ring
);
715 *descr_idx
= vmxnet3_ring_curr_cell_idx(ring
);
716 vmxnet3_inc_tx_consumption_counter(s
, qidx
);
724 vmxnet3_send_packet(VMXNET3State
*s
, uint32_t qidx
)
726 Vmxnet3PktStatus status
= VMXNET3_PKT_STATUS_OK
;
728 if (!vmxnet3_setup_tx_offloads(s
)) {
729 status
= VMXNET3_PKT_STATUS_ERROR
;
734 vmxnet3_dump_virt_hdr(net_tx_pkt_get_vhdr(s
->tx_pkt
));
735 net_tx_pkt_dump(s
->tx_pkt
);
737 if (!net_tx_pkt_send(s
->tx_pkt
, qemu_get_queue(s
->nic
))) {
738 status
= VMXNET3_PKT_STATUS_DISCARD
;
743 vmxnet3_on_tx_done_update_stats(s
, qidx
, status
);
744 return (status
== VMXNET3_PKT_STATUS_OK
);
747 static void vmxnet3_process_tx_queue(VMXNET3State
*s
, int qidx
)
749 struct Vmxnet3_TxDesc txd
;
755 if (!vmxnet3_pop_next_tx_descr(s
, qidx
, &txd
, &txd_idx
)) {
759 vmxnet3_dump_tx_descr(&txd
);
761 if (!s
->skip_current_tx_pkt
) {
762 data_len
= (txd
.len
> 0) ? txd
.len
: VMXNET3_MAX_TX_BUF_SIZE
;
765 if (!net_tx_pkt_add_raw_fragment(s
->tx_pkt
,
768 s
->skip_current_tx_pkt
= true;
773 vmxnet3_tx_retrieve_metadata(s
, &txd
);
778 if (!s
->skip_current_tx_pkt
&& net_tx_pkt_parse(s
->tx_pkt
)) {
780 net_tx_pkt_setup_vlan_header(s
->tx_pkt
, s
->tci
);
783 vmxnet3_send_packet(s
, qidx
);
785 vmxnet3_on_tx_done_update_stats(s
, qidx
,
786 VMXNET3_PKT_STATUS_ERROR
);
789 vmxnet3_complete_packet(s
, qidx
, txd_idx
);
791 s
->skip_current_tx_pkt
= false;
792 net_tx_pkt_reset(s
->tx_pkt
);
798 vmxnet3_read_next_rx_descr(VMXNET3State
*s
, int qidx
, int ridx
,
799 struct Vmxnet3_RxDesc
*dbuf
, uint32_t *didx
)
801 PCIDevice
*d
= PCI_DEVICE(s
);
803 Vmxnet3Ring
*ring
= &s
->rxq_descr
[qidx
].rx_ring
[ridx
];
804 *didx
= vmxnet3_ring_curr_cell_idx(ring
);
805 vmxnet3_ring_read_curr_cell(d
, ring
, dbuf
);
806 dbuf
->addr
= le64_to_cpu(dbuf
->addr
);
807 dbuf
->val1
= le32_to_cpu(dbuf
->val1
);
808 dbuf
->ext1
= le32_to_cpu(dbuf
->ext1
);
811 static inline uint8_t
812 vmxnet3_get_rx_ring_gen(VMXNET3State
*s
, int qidx
, int ridx
)
814 return s
->rxq_descr
[qidx
].rx_ring
[ridx
].gen
;
818 vmxnet3_pop_rxc_descr(VMXNET3State
*s
, int qidx
, uint32_t *descr_gen
)
821 struct Vmxnet3_RxCompDesc rxcd
;
824 vmxnet3_ring_curr_cell_pa(&s
->rxq_descr
[qidx
].comp_ring
);
826 pci_dma_read(PCI_DEVICE(s
),
827 daddr
, &rxcd
, sizeof(struct Vmxnet3_RxCompDesc
));
828 rxcd
.val1
= le32_to_cpu(rxcd
.val1
);
829 rxcd
.val2
= le32_to_cpu(rxcd
.val2
);
830 rxcd
.val3
= le32_to_cpu(rxcd
.val3
);
831 ring_gen
= vmxnet3_ring_curr_gen(&s
->rxq_descr
[qidx
].comp_ring
);
833 if (rxcd
.gen
!= ring_gen
) {
834 *descr_gen
= ring_gen
;
835 vmxnet3_inc_rx_completion_counter(s
, qidx
);
843 vmxnet3_revert_rxc_descr(VMXNET3State
*s
, int qidx
)
845 vmxnet3_dec_rx_completion_counter(s
, qidx
);
849 #define RX_HEAD_BODY_RING (0)
850 #define RX_BODY_ONLY_RING (1)
853 vmxnet3_get_next_head_rx_descr(VMXNET3State
*s
,
854 struct Vmxnet3_RxDesc
*descr_buf
,
860 vmxnet3_read_next_rx_descr(s
, RXQ_IDX
, RX_HEAD_BODY_RING
,
861 descr_buf
, descr_idx
);
863 /* If no more free descriptors - return */
864 ring_gen
= vmxnet3_get_rx_ring_gen(s
, RXQ_IDX
, RX_HEAD_BODY_RING
);
865 if (descr_buf
->gen
!= ring_gen
) {
869 /* Only read after generation field verification */
871 /* Re-read to be sure we got the latest version */
872 vmxnet3_read_next_rx_descr(s
, RXQ_IDX
, RX_HEAD_BODY_RING
,
873 descr_buf
, descr_idx
);
875 /* Mark current descriptor as used/skipped */
876 vmxnet3_inc_rx_consumption_counter(s
, RXQ_IDX
, RX_HEAD_BODY_RING
);
878 /* If this is what we are looking for - return */
879 if (descr_buf
->btype
== VMXNET3_RXD_BTYPE_HEAD
) {
880 *ridx
= RX_HEAD_BODY_RING
;
887 vmxnet3_get_next_body_rx_descr(VMXNET3State
*s
,
888 struct Vmxnet3_RxDesc
*d
,
892 vmxnet3_read_next_rx_descr(s
, RXQ_IDX
, RX_HEAD_BODY_RING
, d
, didx
);
894 /* Try to find corresponding descriptor in head/body ring */
895 if (d
->gen
== vmxnet3_get_rx_ring_gen(s
, RXQ_IDX
, RX_HEAD_BODY_RING
)) {
896 /* Only read after generation field verification */
898 /* Re-read to be sure we got the latest version */
899 vmxnet3_read_next_rx_descr(s
, RXQ_IDX
, RX_HEAD_BODY_RING
, d
, didx
);
900 if (d
->btype
== VMXNET3_RXD_BTYPE_BODY
) {
901 vmxnet3_inc_rx_consumption_counter(s
, RXQ_IDX
, RX_HEAD_BODY_RING
);
902 *ridx
= RX_HEAD_BODY_RING
;
908 * If there is no free descriptors on head/body ring or next free
909 * descriptor is a head descriptor switch to body only ring
911 vmxnet3_read_next_rx_descr(s
, RXQ_IDX
, RX_BODY_ONLY_RING
, d
, didx
);
913 /* If no more free descriptors - return */
914 if (d
->gen
== vmxnet3_get_rx_ring_gen(s
, RXQ_IDX
, RX_BODY_ONLY_RING
)) {
915 /* Only read after generation field verification */
917 /* Re-read to be sure we got the latest version */
918 vmxnet3_read_next_rx_descr(s
, RXQ_IDX
, RX_BODY_ONLY_RING
, d
, didx
);
919 assert(d
->btype
== VMXNET3_RXD_BTYPE_BODY
);
920 *ridx
= RX_BODY_ONLY_RING
;
921 vmxnet3_inc_rx_consumption_counter(s
, RXQ_IDX
, RX_BODY_ONLY_RING
);
929 vmxnet3_get_next_rx_descr(VMXNET3State
*s
, bool is_head
,
930 struct Vmxnet3_RxDesc
*descr_buf
,
934 if (is_head
|| !s
->rx_packets_compound
) {
935 return vmxnet3_get_next_head_rx_descr(s
, descr_buf
, descr_idx
, ridx
);
937 return vmxnet3_get_next_body_rx_descr(s
, descr_buf
, descr_idx
, ridx
);
941 /* In case packet was csum offloaded (either NEEDS_CSUM or DATA_VALID),
942 * the implementation always passes an RxCompDesc with a "Checksum
943 * calculated and found correct" to the OS (cnc=0 and tuc=1, see
944 * vmxnet3_rx_update_descr). This emulates the observed ESXi behavior.
946 * Therefore, if packet has the NEEDS_CSUM set, we must calculate
947 * and place a fully computed checksum into the tcp/udp header.
948 * Otherwise, the OS driver will receive a checksum-correct indication
949 * (CHECKSUM_UNNECESSARY), but with the actual tcp/udp checksum field
950 * having just the pseudo header csum value.
952 * While this is not a problem if packet is destined for local delivery,
953 * in the case the host OS performs forwarding, it will forward an
954 * incorrectly checksummed packet.
956 static void vmxnet3_rx_need_csum_calculate(struct NetRxPkt
*pkt
,
957 const void *pkt_data
,
960 struct virtio_net_hdr
*vhdr
;
961 bool isip4
, isip6
, istcp
, isudp
;
965 if (!net_rx_pkt_has_virt_hdr(pkt
)) {
969 vhdr
= net_rx_pkt_get_vhdr(pkt
);
970 if (!VMXNET_FLAG_IS_SET(vhdr
->flags
, VIRTIO_NET_HDR_F_NEEDS_CSUM
)) {
974 net_rx_pkt_get_protocols(pkt
, &isip4
, &isip6
, &isudp
, &istcp
);
975 if (!(isip4
|| isip6
) || !(istcp
|| isudp
)) {
979 vmxnet3_dump_virt_hdr(vhdr
);
981 /* Validate packet len: csum_start + scum_offset + length of csum field */
982 if (pkt_len
< (vhdr
->csum_start
+ vhdr
->csum_offset
+ 2)) {
983 VMW_PKPRN("packet len:%zu < csum_start(%d) + csum_offset(%d) + 2, "
984 "cannot calculate checksum",
985 pkt_len
, vhdr
->csum_start
, vhdr
->csum_offset
);
989 data
= (uint8_t *)pkt_data
+ vhdr
->csum_start
;
990 len
= pkt_len
- vhdr
->csum_start
;
991 /* Put the checksum obtained into the packet */
992 stw_be_p(data
+ vhdr
->csum_offset
,
993 net_checksum_finish_nozero(net_checksum_add(len
, data
)));
995 vhdr
->flags
&= ~VIRTIO_NET_HDR_F_NEEDS_CSUM
;
996 vhdr
->flags
|= VIRTIO_NET_HDR_F_DATA_VALID
;
999 static void vmxnet3_rx_update_descr(struct NetRxPkt
*pkt
,
1000 struct Vmxnet3_RxCompDesc
*rxcd
)
1002 int csum_ok
, is_gso
;
1003 bool isip4
, isip6
, istcp
, isudp
;
1004 struct virtio_net_hdr
*vhdr
;
1005 uint8_t offload_type
;
1007 if (net_rx_pkt_is_vlan_stripped(pkt
)) {
1009 rxcd
->tci
= net_rx_pkt_get_vlan_tag(pkt
);
1012 if (!net_rx_pkt_has_virt_hdr(pkt
)) {
1016 vhdr
= net_rx_pkt_get_vhdr(pkt
);
1018 * Checksum is valid when lower level tell so or when lower level
1019 * requires checksum offload telling that packet produced/bridged
1020 * locally and did travel over network after last checksum calculation
1023 csum_ok
= VMXNET_FLAG_IS_SET(vhdr
->flags
, VIRTIO_NET_HDR_F_DATA_VALID
) ||
1024 VMXNET_FLAG_IS_SET(vhdr
->flags
, VIRTIO_NET_HDR_F_NEEDS_CSUM
);
1026 offload_type
= vhdr
->gso_type
& ~VIRTIO_NET_HDR_GSO_ECN
;
1027 is_gso
= (offload_type
!= VIRTIO_NET_HDR_GSO_NONE
) ? 1 : 0;
1029 if (!csum_ok
&& !is_gso
) {
1033 net_rx_pkt_get_protocols(pkt
, &isip4
, &isip6
, &isudp
, &istcp
);
1034 if ((!istcp
&& !isudp
) || (!isip4
&& !isip6
)) {
1039 rxcd
->v4
= isip4
? 1 : 0;
1040 rxcd
->v6
= isip6
? 1 : 0;
1041 rxcd
->tcp
= istcp
? 1 : 0;
1042 rxcd
->udp
= isudp
? 1 : 0;
1043 rxcd
->fcs
= rxcd
->tuc
= rxcd
->ipc
= 1;
1052 vmxnet3_pci_dma_writev(PCIDevice
*pci_dev
,
1053 const struct iovec
*iov
,
1054 size_t start_iov_off
,
1056 size_t bytes_to_copy
)
1058 size_t curr_off
= 0;
1061 while (bytes_to_copy
) {
1062 if (start_iov_off
< (curr_off
+ iov
->iov_len
)) {
1064 MIN((curr_off
+ iov
->iov_len
) - start_iov_off
, bytes_to_copy
);
1066 pci_dma_write(pci_dev
, target_addr
+ copied
,
1067 iov
->iov_base
+ start_iov_off
- curr_off
,
1070 copied
+= chunk_len
;
1071 start_iov_off
+= chunk_len
;
1072 curr_off
= start_iov_off
;
1073 bytes_to_copy
-= chunk_len
;
1075 curr_off
+= iov
->iov_len
;
1082 vmxnet3_pci_dma_write_rxcd(PCIDevice
*pcidev
, dma_addr_t pa
,
1083 struct Vmxnet3_RxCompDesc
*rxcd
)
1085 rxcd
->val1
= cpu_to_le32(rxcd
->val1
);
1086 rxcd
->val2
= cpu_to_le32(rxcd
->val2
);
1087 rxcd
->val3
= cpu_to_le32(rxcd
->val3
);
1088 pci_dma_write(pcidev
, pa
, rxcd
, sizeof(*rxcd
));
1092 vmxnet3_indicate_packet(VMXNET3State
*s
)
1094 struct Vmxnet3_RxDesc rxd
;
1095 PCIDevice
*d
= PCI_DEVICE(s
);
1096 bool is_head
= true;
1098 uint32_t rx_ridx
= 0;
1100 struct Vmxnet3_RxCompDesc rxcd
;
1101 uint32_t new_rxcd_gen
= VMXNET3_INIT_GEN
;
1102 hwaddr new_rxcd_pa
= 0;
1103 hwaddr ready_rxcd_pa
= 0;
1104 struct iovec
*data
= net_rx_pkt_get_iovec(s
->rx_pkt
);
1105 size_t bytes_copied
= 0;
1106 size_t bytes_left
= net_rx_pkt_get_total_len(s
->rx_pkt
);
1107 uint16_t num_frags
= 0;
1110 net_rx_pkt_dump(s
->rx_pkt
);
1112 while (bytes_left
> 0) {
1114 /* cannot add more frags to packet */
1115 if (num_frags
== s
->max_rx_frags
) {
1119 new_rxcd_pa
= vmxnet3_pop_rxc_descr(s
, RXQ_IDX
, &new_rxcd_gen
);
1124 if (!vmxnet3_get_next_rx_descr(s
, is_head
, &rxd
, &rxd_idx
, &rx_ridx
)) {
1128 chunk_size
= MIN(bytes_left
, rxd
.len
);
1129 vmxnet3_pci_dma_writev(d
, data
, bytes_copied
, rxd
.addr
, chunk_size
);
1130 bytes_copied
+= chunk_size
;
1131 bytes_left
-= chunk_size
;
1133 vmxnet3_dump_rx_descr(&rxd
);
1135 if (ready_rxcd_pa
!= 0) {
1136 vmxnet3_pci_dma_write_rxcd(d
, ready_rxcd_pa
, &rxcd
);
1139 memset(&rxcd
, 0, sizeof(struct Vmxnet3_RxCompDesc
));
1140 rxcd
.rxdIdx
= rxd_idx
;
1141 rxcd
.len
= chunk_size
;
1143 rxcd
.gen
= new_rxcd_gen
;
1144 rxcd
.rqID
= RXQ_IDX
+ rx_ridx
* s
->rxq_num
;
1146 if (bytes_left
== 0) {
1147 vmxnet3_rx_update_descr(s
->rx_pkt
, &rxcd
);
1150 VMW_RIPRN("RX Completion descriptor: rxRing: %lu rxIdx %lu len %lu "
1151 "sop %d csum_correct %lu",
1152 (unsigned long) rx_ridx
,
1153 (unsigned long) rxcd
.rxdIdx
,
1154 (unsigned long) rxcd
.len
,
1156 (unsigned long) rxcd
.tuc
);
1159 ready_rxcd_pa
= new_rxcd_pa
;
1164 if (ready_rxcd_pa
!= 0) {
1166 rxcd
.err
= (bytes_left
!= 0);
1168 vmxnet3_pci_dma_write_rxcd(d
, ready_rxcd_pa
, &rxcd
);
1170 /* Flush RX descriptor changes */
1174 if (new_rxcd_pa
!= 0) {
1175 vmxnet3_revert_rxc_descr(s
, RXQ_IDX
);
1178 vmxnet3_trigger_interrupt(s
, s
->rxq_descr
[RXQ_IDX
].intr_idx
);
1180 if (bytes_left
== 0) {
1181 vmxnet3_on_rx_done_update_stats(s
, RXQ_IDX
, VMXNET3_PKT_STATUS_OK
);
1183 } else if (num_frags
== s
->max_rx_frags
) {
1184 vmxnet3_on_rx_done_update_stats(s
, RXQ_IDX
, VMXNET3_PKT_STATUS_ERROR
);
1187 vmxnet3_on_rx_done_update_stats(s
, RXQ_IDX
,
1188 VMXNET3_PKT_STATUS_OUT_OF_BUF
);
1194 vmxnet3_io_bar0_write(void *opaque
, hwaddr addr
,
1195 uint64_t val
, unsigned size
)
1197 VMXNET3State
*s
= opaque
;
1199 if (!s
->device_active
) {
1203 if (VMW_IS_MULTIREG_ADDR(addr
, VMXNET3_REG_TXPROD
,
1204 VMXNET3_DEVICE_MAX_TX_QUEUES
, VMXNET3_REG_ALIGN
)) {
1206 VMW_MULTIREG_IDX_BY_ADDR(addr
, VMXNET3_REG_TXPROD
,
1208 assert(tx_queue_idx
<= s
->txq_num
);
1209 vmxnet3_process_tx_queue(s
, tx_queue_idx
);
1213 if (VMW_IS_MULTIREG_ADDR(addr
, VMXNET3_REG_IMR
,
1214 VMXNET3_MAX_INTRS
, VMXNET3_REG_ALIGN
)) {
1215 int l
= VMW_MULTIREG_IDX_BY_ADDR(addr
, VMXNET3_REG_IMR
,
1218 VMW_CBPRN("Interrupt mask for line %d written: 0x%" PRIx64
, l
, val
);
1220 vmxnet3_on_interrupt_mask_changed(s
, l
, val
);
1224 if (VMW_IS_MULTIREG_ADDR(addr
, VMXNET3_REG_RXPROD
,
1225 VMXNET3_DEVICE_MAX_RX_QUEUES
, VMXNET3_REG_ALIGN
) ||
1226 VMW_IS_MULTIREG_ADDR(addr
, VMXNET3_REG_RXPROD2
,
1227 VMXNET3_DEVICE_MAX_RX_QUEUES
, VMXNET3_REG_ALIGN
)) {
1231 VMW_WRPRN("BAR0 unknown write [%" PRIx64
"] = %" PRIx64
", size %d",
1232 (uint64_t) addr
, val
, size
);
1236 vmxnet3_io_bar0_read(void *opaque
, hwaddr addr
, unsigned size
)
1238 VMXNET3State
*s
= opaque
;
1240 if (VMW_IS_MULTIREG_ADDR(addr
, VMXNET3_REG_IMR
,
1241 VMXNET3_MAX_INTRS
, VMXNET3_REG_ALIGN
)) {
1242 int l
= VMW_MULTIREG_IDX_BY_ADDR(addr
, VMXNET3_REG_IMR
,
1244 return s
->interrupt_states
[l
].is_masked
;
1247 VMW_CBPRN("BAR0 unknown read [%" PRIx64
"], size %d", addr
, size
);
1251 static void vmxnet3_reset_interrupt_states(VMXNET3State
*s
)
1254 for (i
= 0; i
< ARRAY_SIZE(s
->interrupt_states
); i
++) {
1255 s
->interrupt_states
[i
].is_asserted
= false;
1256 s
->interrupt_states
[i
].is_pending
= false;
1257 s
->interrupt_states
[i
].is_masked
= true;
1261 static void vmxnet3_reset_mac(VMXNET3State
*s
)
1263 memcpy(&s
->conf
.macaddr
.a
, &s
->perm_mac
.a
, sizeof(s
->perm_mac
.a
));
1264 VMW_CFPRN("MAC address set to: " MAC_FMT
, MAC_ARG(s
->conf
.macaddr
.a
));
1267 static void vmxnet3_deactivate_device(VMXNET3State
*s
)
1269 if (s
->device_active
) {
1270 VMW_CBPRN("Deactivating vmxnet3...");
1271 net_tx_pkt_reset(s
->tx_pkt
);
1272 net_tx_pkt_uninit(s
->tx_pkt
);
1273 net_rx_pkt_uninit(s
->rx_pkt
);
1274 s
->device_active
= false;
1278 static void vmxnet3_reset(VMXNET3State
*s
)
1280 VMW_CBPRN("Resetting vmxnet3...");
1282 vmxnet3_deactivate_device(s
);
1283 vmxnet3_reset_interrupt_states(s
);
1286 s
->skip_current_tx_pkt
= false;
1289 static void vmxnet3_update_rx_mode(VMXNET3State
*s
)
1291 PCIDevice
*d
= PCI_DEVICE(s
);
1293 s
->rx_mode
= VMXNET3_READ_DRV_SHARED32(d
, s
->drv_shmem
,
1294 devRead
.rxFilterConf
.rxMode
);
1295 VMW_CFPRN("RX mode: 0x%08X", s
->rx_mode
);
1298 static void vmxnet3_update_vlan_filters(VMXNET3State
*s
)
1301 PCIDevice
*d
= PCI_DEVICE(s
);
1303 /* Copy configuration from shared memory */
1304 VMXNET3_READ_DRV_SHARED(d
, s
->drv_shmem
,
1305 devRead
.rxFilterConf
.vfTable
,
1307 sizeof(s
->vlan_table
));
1309 /* Invert byte order when needed */
1310 for (i
= 0; i
< ARRAY_SIZE(s
->vlan_table
); i
++) {
1311 s
->vlan_table
[i
] = le32_to_cpu(s
->vlan_table
[i
]);
1314 /* Dump configuration for debugging purposes */
1315 VMW_CFPRN("Configured VLANs:");
1316 for (i
= 0; i
< sizeof(s
->vlan_table
) * 8; i
++) {
1317 if (VMXNET3_VFTABLE_ENTRY_IS_SET(s
->vlan_table
, i
)) {
1318 VMW_CFPRN("\tVLAN %d is present", i
);
1323 static void vmxnet3_update_mcast_filters(VMXNET3State
*s
)
1325 PCIDevice
*d
= PCI_DEVICE(s
);
1327 uint16_t list_bytes
=
1328 VMXNET3_READ_DRV_SHARED16(d
, s
->drv_shmem
,
1329 devRead
.rxFilterConf
.mfTableLen
);
1331 s
->mcast_list_len
= list_bytes
/ sizeof(s
->mcast_list
[0]);
1333 s
->mcast_list
= g_realloc(s
->mcast_list
, list_bytes
);
1334 if (!s
->mcast_list
) {
1335 if (s
->mcast_list_len
== 0) {
1336 VMW_CFPRN("Current multicast list is empty");
1338 VMW_ERPRN("Failed to allocate multicast list of %d elements",
1341 s
->mcast_list_len
= 0;
1344 hwaddr mcast_list_pa
=
1345 VMXNET3_READ_DRV_SHARED64(d
, s
->drv_shmem
,
1346 devRead
.rxFilterConf
.mfTablePA
);
1348 pci_dma_read(d
, mcast_list_pa
, s
->mcast_list
, list_bytes
);
1350 VMW_CFPRN("Current multicast list len is %d:", s
->mcast_list_len
);
1351 for (i
= 0; i
< s
->mcast_list_len
; i
++) {
1352 VMW_CFPRN("\t" MAC_FMT
, MAC_ARG(s
->mcast_list
[i
].a
));
1357 static void vmxnet3_setup_rx_filtering(VMXNET3State
*s
)
1359 vmxnet3_update_rx_mode(s
);
1360 vmxnet3_update_vlan_filters(s
);
1361 vmxnet3_update_mcast_filters(s
);
1364 static uint32_t vmxnet3_get_interrupt_config(VMXNET3State
*s
)
1366 uint32_t interrupt_mode
= VMXNET3_IT_AUTO
| (VMXNET3_IMM_AUTO
<< 2);
1367 VMW_CFPRN("Interrupt config is 0x%X", interrupt_mode
);
1368 return interrupt_mode
;
1371 static void vmxnet3_fill_stats(VMXNET3State
*s
)
1374 PCIDevice
*d
= PCI_DEVICE(s
);
1376 if (!s
->device_active
)
1379 for (i
= 0; i
< s
->txq_num
; i
++) {
1381 s
->txq_descr
[i
].tx_stats_pa
,
1382 &s
->txq_descr
[i
].txq_stats
,
1383 sizeof(s
->txq_descr
[i
].txq_stats
));
1386 for (i
= 0; i
< s
->rxq_num
; i
++) {
1388 s
->rxq_descr
[i
].rx_stats_pa
,
1389 &s
->rxq_descr
[i
].rxq_stats
,
1390 sizeof(s
->rxq_descr
[i
].rxq_stats
));
1394 static void vmxnet3_adjust_by_guest_type(VMXNET3State
*s
)
1396 struct Vmxnet3_GOSInfo gos
;
1397 PCIDevice
*d
= PCI_DEVICE(s
);
1399 VMXNET3_READ_DRV_SHARED(d
, s
->drv_shmem
, devRead
.misc
.driverInfo
.gos
,
1401 s
->rx_packets_compound
=
1402 (gos
.gosType
== VMXNET3_GOS_TYPE_WIN
) ? false : true;
1404 VMW_CFPRN("Guest type specifics: RXCOMPOUND: %d", s
->rx_packets_compound
);
1408 vmxnet3_dump_conf_descr(const char *name
,
1409 struct Vmxnet3_VariableLenConfDesc
*pm_descr
)
1411 VMW_CFPRN("%s descriptor dump: Version %u, Length %u",
1412 name
, pm_descr
->confVer
, pm_descr
->confLen
);
1416 static void vmxnet3_update_pm_state(VMXNET3State
*s
)
1418 struct Vmxnet3_VariableLenConfDesc pm_descr
;
1419 PCIDevice
*d
= PCI_DEVICE(s
);
1422 VMXNET3_READ_DRV_SHARED32(d
, s
->drv_shmem
, devRead
.pmConfDesc
.confLen
);
1424 VMXNET3_READ_DRV_SHARED32(d
, s
->drv_shmem
, devRead
.pmConfDesc
.confVer
);
1426 VMXNET3_READ_DRV_SHARED64(d
, s
->drv_shmem
, devRead
.pmConfDesc
.confPA
);
1428 vmxnet3_dump_conf_descr("PM State", &pm_descr
);
1431 static void vmxnet3_update_features(VMXNET3State
*s
)
1433 uint32_t guest_features
;
1434 int rxcso_supported
;
1435 PCIDevice
*d
= PCI_DEVICE(s
);
1437 guest_features
= VMXNET3_READ_DRV_SHARED32(d
, s
->drv_shmem
,
1438 devRead
.misc
.uptFeatures
);
1440 rxcso_supported
= VMXNET_FLAG_IS_SET(guest_features
, UPT1_F_RXCSUM
);
1441 s
->rx_vlan_stripping
= VMXNET_FLAG_IS_SET(guest_features
, UPT1_F_RXVLAN
);
1442 s
->lro_supported
= VMXNET_FLAG_IS_SET(guest_features
, UPT1_F_LRO
);
1444 VMW_CFPRN("Features configuration: LRO: %d, RXCSUM: %d, VLANSTRIP: %d",
1445 s
->lro_supported
, rxcso_supported
,
1446 s
->rx_vlan_stripping
);
1447 if (s
->peer_has_vhdr
) {
1448 qemu_set_offload(qemu_get_queue(s
->nic
)->peer
,
1457 static bool vmxnet3_verify_intx(VMXNET3State
*s
, int intx
)
1459 return s
->msix_used
|| msi_enabled(PCI_DEVICE(s
))
1460 || intx
== pci_get_byte(s
->parent_obj
.config
+ PCI_INTERRUPT_PIN
) - 1;
1463 static void vmxnet3_validate_interrupt_idx(bool is_msix
, int idx
)
1465 int max_ints
= is_msix
? VMXNET3_MAX_INTRS
: VMXNET3_MAX_NMSIX_INTRS
;
1466 if (idx
>= max_ints
) {
1467 hw_error("Bad interrupt index: %d\n", idx
);
1471 static void vmxnet3_validate_interrupts(VMXNET3State
*s
)
1475 VMW_CFPRN("Verifying event interrupt index (%d)", s
->event_int_idx
);
1476 vmxnet3_validate_interrupt_idx(s
->msix_used
, s
->event_int_idx
);
1478 for (i
= 0; i
< s
->txq_num
; i
++) {
1479 int idx
= s
->txq_descr
[i
].intr_idx
;
1480 VMW_CFPRN("Verifying TX queue %d interrupt index (%d)", i
, idx
);
1481 vmxnet3_validate_interrupt_idx(s
->msix_used
, idx
);
1484 for (i
= 0; i
< s
->rxq_num
; i
++) {
1485 int idx
= s
->rxq_descr
[i
].intr_idx
;
1486 VMW_CFPRN("Verifying RX queue %d interrupt index (%d)", i
, idx
);
1487 vmxnet3_validate_interrupt_idx(s
->msix_used
, idx
);
1491 static void vmxnet3_validate_queues(VMXNET3State
*s
)
1494 * txq_num and rxq_num are total number of queues
1495 * configured by guest. These numbers must not
1496 * exceed corresponding maximal values.
1499 if (s
->txq_num
> VMXNET3_DEVICE_MAX_TX_QUEUES
) {
1500 hw_error("Bad TX queues number: %d\n", s
->txq_num
);
1503 if (s
->rxq_num
> VMXNET3_DEVICE_MAX_RX_QUEUES
) {
1504 hw_error("Bad RX queues number: %d\n", s
->rxq_num
);
1508 static void vmxnet3_activate_device(VMXNET3State
*s
)
1511 static const uint32_t VMXNET3_DEF_TX_THRESHOLD
= 1;
1512 PCIDevice
*d
= PCI_DEVICE(s
);
1513 hwaddr qdescr_table_pa
;
1517 /* Verify configuration consistency */
1518 if (!vmxnet3_verify_driver_magic(d
, s
->drv_shmem
)) {
1519 VMW_ERPRN("Device configuration received from driver is invalid");
1523 /* Verify if device is active */
1524 if (s
->device_active
) {
1525 VMW_CFPRN("Vmxnet3 device is active");
1529 vmxnet3_adjust_by_guest_type(s
);
1530 vmxnet3_update_features(s
);
1531 vmxnet3_update_pm_state(s
);
1532 vmxnet3_setup_rx_filtering(s
);
1533 /* Cache fields from shared memory */
1534 s
->mtu
= VMXNET3_READ_DRV_SHARED32(d
, s
->drv_shmem
, devRead
.misc
.mtu
);
1535 VMW_CFPRN("MTU is %u", s
->mtu
);
1538 VMXNET3_READ_DRV_SHARED16(d
, s
->drv_shmem
, devRead
.misc
.maxNumRxSG
);
1540 if (s
->max_rx_frags
== 0) {
1541 s
->max_rx_frags
= 1;
1544 VMW_CFPRN("Max RX fragments is %u", s
->max_rx_frags
);
1547 VMXNET3_READ_DRV_SHARED8(d
, s
->drv_shmem
, devRead
.intrConf
.eventIntrIdx
);
1548 assert(vmxnet3_verify_intx(s
, s
->event_int_idx
));
1549 VMW_CFPRN("Events interrupt line is %u", s
->event_int_idx
);
1551 s
->auto_int_masking
=
1552 VMXNET3_READ_DRV_SHARED8(d
, s
->drv_shmem
, devRead
.intrConf
.autoMask
);
1553 VMW_CFPRN("Automatic interrupt masking is %d", (int)s
->auto_int_masking
);
1556 VMXNET3_READ_DRV_SHARED8(d
, s
->drv_shmem
, devRead
.misc
.numTxQueues
);
1558 VMXNET3_READ_DRV_SHARED8(d
, s
->drv_shmem
, devRead
.misc
.numRxQueues
);
1560 VMW_CFPRN("Number of TX/RX queues %u/%u", s
->txq_num
, s
->rxq_num
);
1561 vmxnet3_validate_queues(s
);
1564 VMXNET3_READ_DRV_SHARED64(d
, s
->drv_shmem
, devRead
.misc
.queueDescPA
);
1565 VMW_CFPRN("TX queues descriptors table is at 0x%" PRIx64
, qdescr_table_pa
);
1568 * Worst-case scenario is a packet that holds all TX rings space so
1569 * we calculate total size of all TX rings for max TX fragments number
1571 s
->max_tx_frags
= 0;
1574 for (i
= 0; i
< s
->txq_num
; i
++) {
1576 qdescr_table_pa
+ i
* sizeof(struct Vmxnet3_TxQueueDesc
);
1578 /* Read interrupt number for this TX queue */
1579 s
->txq_descr
[i
].intr_idx
=
1580 VMXNET3_READ_TX_QUEUE_DESCR8(d
, qdescr_pa
, conf
.intrIdx
);
1581 assert(vmxnet3_verify_intx(s
, s
->txq_descr
[i
].intr_idx
));
1583 VMW_CFPRN("TX Queue %d interrupt: %d", i
, s
->txq_descr
[i
].intr_idx
);
1585 /* Read rings memory locations for TX queues */
1586 pa
= VMXNET3_READ_TX_QUEUE_DESCR64(d
, qdescr_pa
, conf
.txRingBasePA
);
1587 size
= VMXNET3_READ_TX_QUEUE_DESCR32(d
, qdescr_pa
, conf
.txRingSize
);
1589 vmxnet3_ring_init(d
, &s
->txq_descr
[i
].tx_ring
, pa
, size
,
1590 sizeof(struct Vmxnet3_TxDesc
), false);
1591 VMXNET3_RING_DUMP(VMW_CFPRN
, "TX", i
, &s
->txq_descr
[i
].tx_ring
);
1593 s
->max_tx_frags
+= size
;
1596 pa
= VMXNET3_READ_TX_QUEUE_DESCR64(d
, qdescr_pa
, conf
.compRingBasePA
);
1597 size
= VMXNET3_READ_TX_QUEUE_DESCR32(d
, qdescr_pa
, conf
.compRingSize
);
1598 vmxnet3_ring_init(d
, &s
->txq_descr
[i
].comp_ring
, pa
, size
,
1599 sizeof(struct Vmxnet3_TxCompDesc
), true);
1600 VMXNET3_RING_DUMP(VMW_CFPRN
, "TXC", i
, &s
->txq_descr
[i
].comp_ring
);
1602 s
->txq_descr
[i
].tx_stats_pa
=
1603 qdescr_pa
+ offsetof(struct Vmxnet3_TxQueueDesc
, stats
);
1605 memset(&s
->txq_descr
[i
].txq_stats
, 0,
1606 sizeof(s
->txq_descr
[i
].txq_stats
));
1608 /* Fill device-managed parameters for queues */
1609 VMXNET3_WRITE_TX_QUEUE_DESCR32(d
, qdescr_pa
,
1611 VMXNET3_DEF_TX_THRESHOLD
);
1614 /* Preallocate TX packet wrapper */
1615 VMW_CFPRN("Max TX fragments is %u", s
->max_tx_frags
);
1616 net_tx_pkt_init(&s
->tx_pkt
, PCI_DEVICE(s
),
1617 s
->max_tx_frags
, s
->peer_has_vhdr
);
1618 net_rx_pkt_init(&s
->rx_pkt
, s
->peer_has_vhdr
);
1620 /* Read rings memory locations for RX queues */
1621 for (i
= 0; i
< s
->rxq_num
; i
++) {
1624 qdescr_table_pa
+ s
->txq_num
* sizeof(struct Vmxnet3_TxQueueDesc
) +
1625 i
* sizeof(struct Vmxnet3_RxQueueDesc
);
1627 /* Read interrupt number for this RX queue */
1628 s
->rxq_descr
[i
].intr_idx
=
1629 VMXNET3_READ_TX_QUEUE_DESCR8(d
, qd_pa
, conf
.intrIdx
);
1630 assert(vmxnet3_verify_intx(s
, s
->rxq_descr
[i
].intr_idx
));
1632 VMW_CFPRN("RX Queue %d interrupt: %d", i
, s
->rxq_descr
[i
].intr_idx
);
1634 /* Read rings memory locations */
1635 for (j
= 0; j
< VMXNET3_RX_RINGS_PER_QUEUE
; j
++) {
1637 pa
= VMXNET3_READ_RX_QUEUE_DESCR64(d
, qd_pa
, conf
.rxRingBasePA
[j
]);
1638 size
= VMXNET3_READ_RX_QUEUE_DESCR32(d
, qd_pa
, conf
.rxRingSize
[j
]);
1639 vmxnet3_ring_init(d
, &s
->rxq_descr
[i
].rx_ring
[j
], pa
, size
,
1640 sizeof(struct Vmxnet3_RxDesc
), false);
1641 VMW_CFPRN("RX queue %d:%d: Base: %" PRIx64
", Size: %d",
1646 pa
= VMXNET3_READ_RX_QUEUE_DESCR64(d
, qd_pa
, conf
.compRingBasePA
);
1647 size
= VMXNET3_READ_RX_QUEUE_DESCR32(d
, qd_pa
, conf
.compRingSize
);
1648 vmxnet3_ring_init(d
, &s
->rxq_descr
[i
].comp_ring
, pa
, size
,
1649 sizeof(struct Vmxnet3_RxCompDesc
), true);
1650 VMW_CFPRN("RXC queue %d: Base: %" PRIx64
", Size: %d", i
, pa
, size
);
1652 s
->rxq_descr
[i
].rx_stats_pa
=
1653 qd_pa
+ offsetof(struct Vmxnet3_RxQueueDesc
, stats
);
1654 memset(&s
->rxq_descr
[i
].rxq_stats
, 0,
1655 sizeof(s
->rxq_descr
[i
].rxq_stats
));
1658 vmxnet3_validate_interrupts(s
);
1660 /* Make sure everything is in place before device activation */
1663 vmxnet3_reset_mac(s
);
1665 s
->device_active
= true;
1668 static void vmxnet3_handle_command(VMXNET3State
*s
, uint64_t cmd
)
1670 s
->last_command
= cmd
;
1673 case VMXNET3_CMD_GET_PERM_MAC_HI
:
1674 VMW_CBPRN("Set: Get upper part of permanent MAC");
1677 case VMXNET3_CMD_GET_PERM_MAC_LO
:
1678 VMW_CBPRN("Set: Get lower part of permanent MAC");
1681 case VMXNET3_CMD_GET_STATS
:
1682 VMW_CBPRN("Set: Get device statistics");
1683 vmxnet3_fill_stats(s
);
1686 case VMXNET3_CMD_ACTIVATE_DEV
:
1687 VMW_CBPRN("Set: Activating vmxnet3 device");
1688 vmxnet3_activate_device(s
);
1691 case VMXNET3_CMD_UPDATE_RX_MODE
:
1692 VMW_CBPRN("Set: Update rx mode");
1693 vmxnet3_update_rx_mode(s
);
1696 case VMXNET3_CMD_UPDATE_VLAN_FILTERS
:
1697 VMW_CBPRN("Set: Update VLAN filters");
1698 vmxnet3_update_vlan_filters(s
);
1701 case VMXNET3_CMD_UPDATE_MAC_FILTERS
:
1702 VMW_CBPRN("Set: Update MAC filters");
1703 vmxnet3_update_mcast_filters(s
);
1706 case VMXNET3_CMD_UPDATE_FEATURE
:
1707 VMW_CBPRN("Set: Update features");
1708 vmxnet3_update_features(s
);
1711 case VMXNET3_CMD_UPDATE_PMCFG
:
1712 VMW_CBPRN("Set: Update power management config");
1713 vmxnet3_update_pm_state(s
);
1716 case VMXNET3_CMD_GET_LINK
:
1717 VMW_CBPRN("Set: Get link");
1720 case VMXNET3_CMD_RESET_DEV
:
1721 VMW_CBPRN("Set: Reset device");
1725 case VMXNET3_CMD_QUIESCE_DEV
:
1726 VMW_CBPRN("Set: VMXNET3_CMD_QUIESCE_DEV - deactivate the device");
1727 vmxnet3_deactivate_device(s
);
1730 case VMXNET3_CMD_GET_CONF_INTR
:
1731 VMW_CBPRN("Set: VMXNET3_CMD_GET_CONF_INTR - interrupt configuration");
1734 case VMXNET3_CMD_GET_ADAPTIVE_RING_INFO
:
1735 VMW_CBPRN("Set: VMXNET3_CMD_GET_ADAPTIVE_RING_INFO - "
1736 "adaptive ring info flags");
1739 case VMXNET3_CMD_GET_DID_LO
:
1740 VMW_CBPRN("Set: Get lower part of device ID");
1743 case VMXNET3_CMD_GET_DID_HI
:
1744 VMW_CBPRN("Set: Get upper part of device ID");
1747 case VMXNET3_CMD_GET_DEV_EXTRA_INFO
:
1748 VMW_CBPRN("Set: Get device extra info");
1752 VMW_CBPRN("Received unknown command: %" PRIx64
, cmd
);
1757 static uint64_t vmxnet3_get_command_status(VMXNET3State
*s
)
1761 switch (s
->last_command
) {
1762 case VMXNET3_CMD_ACTIVATE_DEV
:
1763 ret
= (s
->device_active
) ? 0 : 1;
1764 VMW_CFPRN("Device active: %" PRIx64
, ret
);
1767 case VMXNET3_CMD_RESET_DEV
:
1768 case VMXNET3_CMD_QUIESCE_DEV
:
1769 case VMXNET3_CMD_GET_QUEUE_STATUS
:
1770 case VMXNET3_CMD_GET_DEV_EXTRA_INFO
:
1774 case VMXNET3_CMD_GET_LINK
:
1775 ret
= s
->link_status_and_speed
;
1776 VMW_CFPRN("Link and speed: %" PRIx64
, ret
);
1779 case VMXNET3_CMD_GET_PERM_MAC_LO
:
1780 ret
= vmxnet3_get_mac_low(&s
->perm_mac
);
1783 case VMXNET3_CMD_GET_PERM_MAC_HI
:
1784 ret
= vmxnet3_get_mac_high(&s
->perm_mac
);
1787 case VMXNET3_CMD_GET_CONF_INTR
:
1788 ret
= vmxnet3_get_interrupt_config(s
);
1791 case VMXNET3_CMD_GET_ADAPTIVE_RING_INFO
:
1792 ret
= VMXNET3_DISABLE_ADAPTIVE_RING
;
1795 case VMXNET3_CMD_GET_DID_LO
:
1796 ret
= PCI_DEVICE_ID_VMWARE_VMXNET3
;
1799 case VMXNET3_CMD_GET_DID_HI
:
1800 ret
= VMXNET3_DEVICE_REVISION
;
1804 VMW_WRPRN("Received request for unknown command: %x", s
->last_command
);
1812 static void vmxnet3_set_events(VMXNET3State
*s
, uint32_t val
)
1815 PCIDevice
*d
= PCI_DEVICE(s
);
1817 VMW_CBPRN("Setting events: 0x%x", val
);
1818 events
= VMXNET3_READ_DRV_SHARED32(d
, s
->drv_shmem
, ecr
) | val
;
1819 VMXNET3_WRITE_DRV_SHARED32(d
, s
->drv_shmem
, ecr
, events
);
1822 static void vmxnet3_ack_events(VMXNET3State
*s
, uint32_t val
)
1824 PCIDevice
*d
= PCI_DEVICE(s
);
1827 VMW_CBPRN("Clearing events: 0x%x", val
);
1828 events
= VMXNET3_READ_DRV_SHARED32(d
, s
->drv_shmem
, ecr
) & ~val
;
1829 VMXNET3_WRITE_DRV_SHARED32(d
, s
->drv_shmem
, ecr
, events
);
1833 vmxnet3_io_bar1_write(void *opaque
,
1838 VMXNET3State
*s
= opaque
;
1841 /* Vmxnet3 Revision Report Selection */
1842 case VMXNET3_REG_VRRS
:
1843 VMW_CBPRN("Write BAR1 [VMXNET3_REG_VRRS] = %" PRIx64
", size %d",
1847 /* UPT Version Report Selection */
1848 case VMXNET3_REG_UVRS
:
1849 VMW_CBPRN("Write BAR1 [VMXNET3_REG_UVRS] = %" PRIx64
", size %d",
1853 /* Driver Shared Address Low */
1854 case VMXNET3_REG_DSAL
:
1855 VMW_CBPRN("Write BAR1 [VMXNET3_REG_DSAL] = %" PRIx64
", size %d",
1858 * Guest driver will first write the low part of the shared
1859 * memory address. We save it to temp variable and set the
1860 * shared address only after we get the high part
1863 vmxnet3_deactivate_device(s
);
1865 s
->temp_shared_guest_driver_memory
= val
;
1869 /* Driver Shared Address High */
1870 case VMXNET3_REG_DSAH
:
1871 VMW_CBPRN("Write BAR1 [VMXNET3_REG_DSAH] = %" PRIx64
", size %d",
1874 * Set the shared memory between guest driver and device.
1875 * We already should have low address part.
1877 s
->drv_shmem
= s
->temp_shared_guest_driver_memory
| (val
<< 32);
1881 case VMXNET3_REG_CMD
:
1882 VMW_CBPRN("Write BAR1 [VMXNET3_REG_CMD] = %" PRIx64
", size %d",
1884 vmxnet3_handle_command(s
, val
);
1887 /* MAC Address Low */
1888 case VMXNET3_REG_MACL
:
1889 VMW_CBPRN("Write BAR1 [VMXNET3_REG_MACL] = %" PRIx64
", size %d",
1894 /* MAC Address High */
1895 case VMXNET3_REG_MACH
:
1896 VMW_CBPRN("Write BAR1 [VMXNET3_REG_MACH] = %" PRIx64
", size %d",
1898 vmxnet3_set_variable_mac(s
, val
, s
->temp_mac
);
1901 /* Interrupt Cause Register */
1902 case VMXNET3_REG_ICR
:
1903 VMW_CBPRN("Write BAR1 [VMXNET3_REG_ICR] = %" PRIx64
", size %d",
1905 g_assert_not_reached();
1908 /* Event Cause Register */
1909 case VMXNET3_REG_ECR
:
1910 VMW_CBPRN("Write BAR1 [VMXNET3_REG_ECR] = %" PRIx64
", size %d",
1912 vmxnet3_ack_events(s
, val
);
1916 VMW_CBPRN("Unknown Write to BAR1 [%" PRIx64
"] = %" PRIx64
", size %d",
1923 vmxnet3_io_bar1_read(void *opaque
, hwaddr addr
, unsigned size
)
1925 VMXNET3State
*s
= opaque
;
1929 /* Vmxnet3 Revision Report Selection */
1930 case VMXNET3_REG_VRRS
:
1931 VMW_CBPRN("Read BAR1 [VMXNET3_REG_VRRS], size %d", size
);
1932 ret
= VMXNET3_DEVICE_REVISION
;
1935 /* UPT Version Report Selection */
1936 case VMXNET3_REG_UVRS
:
1937 VMW_CBPRN("Read BAR1 [VMXNET3_REG_UVRS], size %d", size
);
1938 ret
= VMXNET3_UPT_REVISION
;
1942 case VMXNET3_REG_CMD
:
1943 VMW_CBPRN("Read BAR1 [VMXNET3_REG_CMD], size %d", size
);
1944 ret
= vmxnet3_get_command_status(s
);
1947 /* MAC Address Low */
1948 case VMXNET3_REG_MACL
:
1949 VMW_CBPRN("Read BAR1 [VMXNET3_REG_MACL], size %d", size
);
1950 ret
= vmxnet3_get_mac_low(&s
->conf
.macaddr
);
1953 /* MAC Address High */
1954 case VMXNET3_REG_MACH
:
1955 VMW_CBPRN("Read BAR1 [VMXNET3_REG_MACH], size %d", size
);
1956 ret
= vmxnet3_get_mac_high(&s
->conf
.macaddr
);
1960 * Interrupt Cause Register
1961 * Used for legacy interrupts only so interrupt index always 0
1963 case VMXNET3_REG_ICR
:
1964 VMW_CBPRN("Read BAR1 [VMXNET3_REG_ICR], size %d", size
);
1965 if (vmxnet3_interrupt_asserted(s
, 0)) {
1966 vmxnet3_clear_interrupt(s
, 0);
1974 VMW_CBPRN("Unknow read BAR1[%" PRIx64
"], %d bytes", addr
, size
);
1982 vmxnet3_can_receive(NetClientState
*nc
)
1984 VMXNET3State
*s
= qemu_get_nic_opaque(nc
);
1985 return s
->device_active
&&
1986 VMXNET_FLAG_IS_SET(s
->link_status_and_speed
, VMXNET3_LINK_STATUS_UP
);
1990 vmxnet3_is_registered_vlan(VMXNET3State
*s
, const void *data
)
1992 uint16_t vlan_tag
= eth_get_pkt_tci(data
) & VLAN_VID_MASK
;
1993 if (IS_SPECIAL_VLAN_ID(vlan_tag
)) {
1997 return VMXNET3_VFTABLE_ENTRY_IS_SET(s
->vlan_table
, vlan_tag
);
2001 vmxnet3_is_allowed_mcast_group(VMXNET3State
*s
, const uint8_t *group_mac
)
2004 for (i
= 0; i
< s
->mcast_list_len
; i
++) {
2005 if (!memcmp(group_mac
, s
->mcast_list
[i
].a
, sizeof(s
->mcast_list
[i
]))) {
2013 vmxnet3_rx_filter_may_indicate(VMXNET3State
*s
, const void *data
,
2016 struct eth_header
*ehdr
= PKT_GET_ETH_HDR(data
);
2018 if (VMXNET_FLAG_IS_SET(s
->rx_mode
, VMXNET3_RXM_PROMISC
)) {
2022 if (!vmxnet3_is_registered_vlan(s
, data
)) {
2026 switch (net_rx_pkt_get_packet_type(s
->rx_pkt
)) {
2028 if (!VMXNET_FLAG_IS_SET(s
->rx_mode
, VMXNET3_RXM_UCAST
)) {
2031 if (memcmp(s
->conf
.macaddr
.a
, ehdr
->h_dest
, ETH_ALEN
)) {
2037 if (!VMXNET_FLAG_IS_SET(s
->rx_mode
, VMXNET3_RXM_BCAST
)) {
2043 if (VMXNET_FLAG_IS_SET(s
->rx_mode
, VMXNET3_RXM_ALL_MULTI
)) {
2046 if (!VMXNET_FLAG_IS_SET(s
->rx_mode
, VMXNET3_RXM_MCAST
)) {
2049 if (!vmxnet3_is_allowed_mcast_group(s
, ehdr
->h_dest
)) {
2055 g_assert_not_reached();
2062 vmxnet3_receive(NetClientState
*nc
, const uint8_t *buf
, size_t size
)
2064 VMXNET3State
*s
= qemu_get_nic_opaque(nc
);
2065 size_t bytes_indicated
;
2066 uint8_t min_buf
[MIN_BUF_SIZE
];
2068 if (!vmxnet3_can_receive(nc
)) {
2069 VMW_PKPRN("Cannot receive now");
2073 if (s
->peer_has_vhdr
) {
2074 net_rx_pkt_set_vhdr(s
->rx_pkt
, (struct virtio_net_hdr
*)buf
);
2075 buf
+= sizeof(struct virtio_net_hdr
);
2076 size
-= sizeof(struct virtio_net_hdr
);
2079 /* Pad to minimum Ethernet frame length */
2080 if (size
< sizeof(min_buf
)) {
2081 memcpy(min_buf
, buf
, size
);
2082 memset(&min_buf
[size
], 0, sizeof(min_buf
) - size
);
2084 size
= sizeof(min_buf
);
2087 net_rx_pkt_set_packet_type(s
->rx_pkt
,
2088 get_eth_packet_type(PKT_GET_ETH_HDR(buf
)));
2090 if (vmxnet3_rx_filter_may_indicate(s
, buf
, size
)) {
2091 net_rx_pkt_set_protocols(s
->rx_pkt
, buf
, size
);
2092 vmxnet3_rx_need_csum_calculate(s
->rx_pkt
, buf
, size
);
2093 net_rx_pkt_attach_data(s
->rx_pkt
, buf
, size
, s
->rx_vlan_stripping
);
2094 bytes_indicated
= vmxnet3_indicate_packet(s
) ? size
: -1;
2095 if (bytes_indicated
< size
) {
2096 VMW_PKPRN("RX: %zu of %zu bytes indicated", bytes_indicated
, size
);
2099 VMW_PKPRN("Packet dropped by RX filter");
2100 bytes_indicated
= size
;
2104 assert(bytes_indicated
!= 0);
2105 return bytes_indicated
;
2108 static void vmxnet3_set_link_status(NetClientState
*nc
)
2110 VMXNET3State
*s
= qemu_get_nic_opaque(nc
);
2112 if (nc
->link_down
) {
2113 s
->link_status_and_speed
&= ~VMXNET3_LINK_STATUS_UP
;
2115 s
->link_status_and_speed
|= VMXNET3_LINK_STATUS_UP
;
2118 vmxnet3_set_events(s
, VMXNET3_ECR_LINK
);
2119 vmxnet3_trigger_interrupt(s
, s
->event_int_idx
);
2122 static NetClientInfo net_vmxnet3_info
= {
2123 .type
= NET_CLIENT_DRIVER_NIC
,
2124 .size
= sizeof(NICState
),
2125 .receive
= vmxnet3_receive
,
2126 .link_status_changed
= vmxnet3_set_link_status
,
2129 static bool vmxnet3_peer_has_vnet_hdr(VMXNET3State
*s
)
2131 NetClientState
*nc
= qemu_get_queue(s
->nic
);
2133 if (qemu_has_vnet_hdr(nc
->peer
)) {
2140 static void vmxnet3_net_uninit(VMXNET3State
*s
)
2142 g_free(s
->mcast_list
);
2143 vmxnet3_deactivate_device(s
);
2144 qemu_del_nic(s
->nic
);
2147 static void vmxnet3_net_init(VMXNET3State
*s
)
2149 DeviceState
*d
= DEVICE(s
);
2151 VMW_CBPRN("vmxnet3_net_init called...");
2153 qemu_macaddr_default_if_unset(&s
->conf
.macaddr
);
2155 /* Windows guest will query the address that was set on init */
2156 memcpy(&s
->perm_mac
.a
, &s
->conf
.macaddr
.a
, sizeof(s
->perm_mac
.a
));
2158 s
->mcast_list
= NULL
;
2159 s
->mcast_list_len
= 0;
2161 s
->link_status_and_speed
= VMXNET3_LINK_SPEED
| VMXNET3_LINK_STATUS_UP
;
2163 VMW_CFPRN("Permanent MAC: " MAC_FMT
, MAC_ARG(s
->perm_mac
.a
));
2165 s
->nic
= qemu_new_nic(&net_vmxnet3_info
, &s
->conf
,
2166 object_get_typename(OBJECT(s
)),
2169 s
->peer_has_vhdr
= vmxnet3_peer_has_vnet_hdr(s
);
2171 s
->skip_current_tx_pkt
= false;
2174 s
->rx_vlan_stripping
= false;
2175 s
->lro_supported
= false;
2177 if (s
->peer_has_vhdr
) {
2178 qemu_set_vnet_hdr_len(qemu_get_queue(s
->nic
)->peer
,
2179 sizeof(struct virtio_net_hdr
));
2181 qemu_using_vnet_hdr(qemu_get_queue(s
->nic
)->peer
, 1);
2184 qemu_format_nic_info_str(qemu_get_queue(s
->nic
), s
->conf
.macaddr
.a
);
2188 vmxnet3_unuse_msix_vectors(VMXNET3State
*s
, int num_vectors
)
2190 PCIDevice
*d
= PCI_DEVICE(s
);
2192 for (i
= 0; i
< num_vectors
; i
++) {
2193 msix_vector_unuse(d
, i
);
2198 vmxnet3_use_msix_vectors(VMXNET3State
*s
, int num_vectors
)
2200 PCIDevice
*d
= PCI_DEVICE(s
);
2202 for (i
= 0; i
< num_vectors
; i
++) {
2203 int res
= msix_vector_use(d
, i
);
2205 VMW_WRPRN("Failed to use MSI-X vector %d, error %d", i
, res
);
2206 vmxnet3_unuse_msix_vectors(s
, i
);
2214 vmxnet3_init_msix(VMXNET3State
*s
)
2216 PCIDevice
*d
= PCI_DEVICE(s
);
2217 int res
= msix_init(d
, VMXNET3_MAX_INTRS
,
2219 VMXNET3_MSIX_BAR_IDX
, VMXNET3_OFF_MSIX_TABLE
,
2221 VMXNET3_MSIX_BAR_IDX
, VMXNET3_OFF_MSIX_PBA(s
),
2222 VMXNET3_MSIX_OFFSET(s
), NULL
);
2225 VMW_WRPRN("Failed to initialize MSI-X, error %d", res
);
2226 s
->msix_used
= false;
2228 if (!vmxnet3_use_msix_vectors(s
, VMXNET3_MAX_INTRS
)) {
2229 VMW_WRPRN("Failed to use MSI-X vectors, error %d", res
);
2230 msix_uninit(d
, &s
->msix_bar
, &s
->msix_bar
);
2231 s
->msix_used
= false;
2233 s
->msix_used
= true;
2236 return s
->msix_used
;
2240 vmxnet3_cleanup_msix(VMXNET3State
*s
)
2242 PCIDevice
*d
= PCI_DEVICE(s
);
2245 vmxnet3_unuse_msix_vectors(s
, VMXNET3_MAX_INTRS
);
2246 msix_uninit(d
, &s
->msix_bar
, &s
->msix_bar
);
2251 vmxnet3_cleanup_msi(VMXNET3State
*s
)
2253 PCIDevice
*d
= PCI_DEVICE(s
);
2259 vmxnet3_msix_save(QEMUFile
*f
, void *opaque
)
2261 PCIDevice
*d
= PCI_DEVICE(opaque
);
2266 vmxnet3_msix_load(QEMUFile
*f
, void *opaque
, int version_id
)
2268 PCIDevice
*d
= PCI_DEVICE(opaque
);
2273 static const MemoryRegionOps b0_ops
= {
2274 .read
= vmxnet3_io_bar0_read
,
2275 .write
= vmxnet3_io_bar0_write
,
2276 .endianness
= DEVICE_LITTLE_ENDIAN
,
2278 .min_access_size
= 4,
2279 .max_access_size
= 4,
2283 static const MemoryRegionOps b1_ops
= {
2284 .read
= vmxnet3_io_bar1_read
,
2285 .write
= vmxnet3_io_bar1_write
,
2286 .endianness
= DEVICE_LITTLE_ENDIAN
,
2288 .min_access_size
= 4,
2289 .max_access_size
= 4,
2293 static SaveVMHandlers savevm_vmxnet3_msix
= {
2294 .save_state
= vmxnet3_msix_save
,
2295 .load_state
= vmxnet3_msix_load
,
2298 static uint64_t vmxnet3_device_serial_num(VMXNET3State
*s
)
2300 uint64_t dsn_payload
;
2301 uint8_t *dsnp
= (uint8_t *)&dsn_payload
;
2304 dsnp
[1] = s
->conf
.macaddr
.a
[3];
2305 dsnp
[2] = s
->conf
.macaddr
.a
[4];
2306 dsnp
[3] = s
->conf
.macaddr
.a
[5];
2307 dsnp
[4] = s
->conf
.macaddr
.a
[0];
2308 dsnp
[5] = s
->conf
.macaddr
.a
[1];
2309 dsnp
[6] = s
->conf
.macaddr
.a
[2];
2315 #define VMXNET3_USE_64BIT (true)
2316 #define VMXNET3_PER_VECTOR_MASK (false)
2318 static void vmxnet3_pci_realize(PCIDevice
*pci_dev
, Error
**errp
)
2320 DeviceState
*dev
= DEVICE(pci_dev
);
2321 VMXNET3State
*s
= VMXNET3(pci_dev
);
2324 VMW_CBPRN("Starting init...");
2326 memory_region_init_io(&s
->bar0
, OBJECT(s
), &b0_ops
, s
,
2327 "vmxnet3-b0", VMXNET3_PT_REG_SIZE
);
2328 pci_register_bar(pci_dev
, VMXNET3_BAR0_IDX
,
2329 PCI_BASE_ADDRESS_SPACE_MEMORY
, &s
->bar0
);
2331 memory_region_init_io(&s
->bar1
, OBJECT(s
), &b1_ops
, s
,
2332 "vmxnet3-b1", VMXNET3_VD_REG_SIZE
);
2333 pci_register_bar(pci_dev
, VMXNET3_BAR1_IDX
,
2334 PCI_BASE_ADDRESS_SPACE_MEMORY
, &s
->bar1
);
2336 memory_region_init(&s
->msix_bar
, OBJECT(s
), "vmxnet3-msix-bar",
2337 VMXNET3_MSIX_BAR_SIZE
);
2338 pci_register_bar(pci_dev
, VMXNET3_MSIX_BAR_IDX
,
2339 PCI_BASE_ADDRESS_SPACE_MEMORY
, &s
->msix_bar
);
2341 vmxnet3_reset_interrupt_states(s
);
2343 /* Interrupt pin A */
2344 pci_dev
->config
[PCI_INTERRUPT_PIN
] = 0x01;
2346 ret
= msi_init(pci_dev
, VMXNET3_MSI_OFFSET(s
), VMXNET3_MAX_NMSIX_INTRS
,
2347 VMXNET3_USE_64BIT
, VMXNET3_PER_VECTOR_MASK
, NULL
);
2348 /* Any error other than -ENOTSUP(board's MSI support is broken)
2349 * is a programming error. Fall back to INTx silently on -ENOTSUP */
2350 assert(!ret
|| ret
== -ENOTSUP
);
2352 if (!vmxnet3_init_msix(s
)) {
2353 VMW_WRPRN("Failed to initialize MSI-X, configuration is inconsistent.");
2356 vmxnet3_net_init(s
);
2358 if (pci_is_express(pci_dev
)) {
2359 if (pci_bus_is_express(pci_get_bus(pci_dev
))) {
2360 pcie_endpoint_cap_init(pci_dev
, VMXNET3_EXP_EP_OFFSET
);
2363 pcie_dev_ser_num_init(pci_dev
, VMXNET3_DSN_OFFSET
,
2364 vmxnet3_device_serial_num(s
));
2367 register_savevm_live(dev
, "vmxnet3-msix", -1, 1, &savevm_vmxnet3_msix
, s
);
2370 static void vmxnet3_instance_init(Object
*obj
)
2372 VMXNET3State
*s
= VMXNET3(obj
);
2373 device_add_bootindex_property(obj
, &s
->conf
.bootindex
,
2374 "bootindex", "/ethernet-phy@0",
2378 static void vmxnet3_pci_uninit(PCIDevice
*pci_dev
)
2380 DeviceState
*dev
= DEVICE(pci_dev
);
2381 VMXNET3State
*s
= VMXNET3(pci_dev
);
2383 VMW_CBPRN("Starting uninit...");
2385 unregister_savevm(dev
, "vmxnet3-msix", s
);
2387 vmxnet3_net_uninit(s
);
2389 vmxnet3_cleanup_msix(s
);
2391 vmxnet3_cleanup_msi(s
);
2394 static void vmxnet3_qdev_reset(DeviceState
*dev
)
2396 PCIDevice
*d
= PCI_DEVICE(dev
);
2397 VMXNET3State
*s
= VMXNET3(d
);
2399 VMW_CBPRN("Starting QDEV reset...");
2403 static bool vmxnet3_mc_list_needed(void *opaque
)
2408 static int vmxnet3_mcast_list_pre_load(void *opaque
)
2410 VMXNET3State
*s
= opaque
;
2412 s
->mcast_list
= g_malloc(s
->mcast_list_buff_size
);
2418 static int vmxnet3_pre_save(void *opaque
)
2420 VMXNET3State
*s
= opaque
;
2422 s
->mcast_list_buff_size
= s
->mcast_list_len
* sizeof(MACAddr
);
2427 static const VMStateDescription vmxstate_vmxnet3_mcast_list
= {
2428 .name
= "vmxnet3/mcast_list",
2430 .minimum_version_id
= 1,
2431 .pre_load
= vmxnet3_mcast_list_pre_load
,
2432 .needed
= vmxnet3_mc_list_needed
,
2433 .fields
= (VMStateField
[]) {
2434 VMSTATE_VBUFFER_UINT32(mcast_list
, VMXNET3State
, 0, NULL
,
2435 mcast_list_buff_size
),
2436 VMSTATE_END_OF_LIST()
2440 static const VMStateDescription vmstate_vmxnet3_ring
= {
2441 .name
= "vmxnet3-ring",
2443 .fields
= (VMStateField
[]) {
2444 VMSTATE_UINT64(pa
, Vmxnet3Ring
),
2445 VMSTATE_UINT32(size
, Vmxnet3Ring
),
2446 VMSTATE_UINT32(cell_size
, Vmxnet3Ring
),
2447 VMSTATE_UINT32(next
, Vmxnet3Ring
),
2448 VMSTATE_UINT8(gen
, Vmxnet3Ring
),
2449 VMSTATE_END_OF_LIST()
2453 static const VMStateDescription vmstate_vmxnet3_tx_stats
= {
2454 .name
= "vmxnet3-tx-stats",
2456 .fields
= (VMStateField
[]) {
2457 VMSTATE_UINT64(TSOPktsTxOK
, struct UPT1_TxStats
),
2458 VMSTATE_UINT64(TSOBytesTxOK
, struct UPT1_TxStats
),
2459 VMSTATE_UINT64(ucastPktsTxOK
, struct UPT1_TxStats
),
2460 VMSTATE_UINT64(ucastBytesTxOK
, struct UPT1_TxStats
),
2461 VMSTATE_UINT64(mcastPktsTxOK
, struct UPT1_TxStats
),
2462 VMSTATE_UINT64(mcastBytesTxOK
, struct UPT1_TxStats
),
2463 VMSTATE_UINT64(bcastPktsTxOK
, struct UPT1_TxStats
),
2464 VMSTATE_UINT64(bcastBytesTxOK
, struct UPT1_TxStats
),
2465 VMSTATE_UINT64(pktsTxError
, struct UPT1_TxStats
),
2466 VMSTATE_UINT64(pktsTxDiscard
, struct UPT1_TxStats
),
2467 VMSTATE_END_OF_LIST()
2471 static const VMStateDescription vmstate_vmxnet3_txq_descr
= {
2472 .name
= "vmxnet3-txq-descr",
2474 .fields
= (VMStateField
[]) {
2475 VMSTATE_STRUCT(tx_ring
, Vmxnet3TxqDescr
, 0, vmstate_vmxnet3_ring
,
2477 VMSTATE_STRUCT(comp_ring
, Vmxnet3TxqDescr
, 0, vmstate_vmxnet3_ring
,
2479 VMSTATE_UINT8(intr_idx
, Vmxnet3TxqDescr
),
2480 VMSTATE_UINT64(tx_stats_pa
, Vmxnet3TxqDescr
),
2481 VMSTATE_STRUCT(txq_stats
, Vmxnet3TxqDescr
, 0, vmstate_vmxnet3_tx_stats
,
2482 struct UPT1_TxStats
),
2483 VMSTATE_END_OF_LIST()
2487 static const VMStateDescription vmstate_vmxnet3_rx_stats
= {
2488 .name
= "vmxnet3-rx-stats",
2490 .fields
= (VMStateField
[]) {
2491 VMSTATE_UINT64(LROPktsRxOK
, struct UPT1_RxStats
),
2492 VMSTATE_UINT64(LROBytesRxOK
, struct UPT1_RxStats
),
2493 VMSTATE_UINT64(ucastPktsRxOK
, struct UPT1_RxStats
),
2494 VMSTATE_UINT64(ucastBytesRxOK
, struct UPT1_RxStats
),
2495 VMSTATE_UINT64(mcastPktsRxOK
, struct UPT1_RxStats
),
2496 VMSTATE_UINT64(mcastBytesRxOK
, struct UPT1_RxStats
),
2497 VMSTATE_UINT64(bcastPktsRxOK
, struct UPT1_RxStats
),
2498 VMSTATE_UINT64(bcastBytesRxOK
, struct UPT1_RxStats
),
2499 VMSTATE_UINT64(pktsRxOutOfBuf
, struct UPT1_RxStats
),
2500 VMSTATE_UINT64(pktsRxError
, struct UPT1_RxStats
),
2501 VMSTATE_END_OF_LIST()
2505 static const VMStateDescription vmstate_vmxnet3_rxq_descr
= {
2506 .name
= "vmxnet3-rxq-descr",
2508 .fields
= (VMStateField
[]) {
2509 VMSTATE_STRUCT_ARRAY(rx_ring
, Vmxnet3RxqDescr
,
2510 VMXNET3_RX_RINGS_PER_QUEUE
, 0,
2511 vmstate_vmxnet3_ring
, Vmxnet3Ring
),
2512 VMSTATE_STRUCT(comp_ring
, Vmxnet3RxqDescr
, 0, vmstate_vmxnet3_ring
,
2514 VMSTATE_UINT8(intr_idx
, Vmxnet3RxqDescr
),
2515 VMSTATE_UINT64(rx_stats_pa
, Vmxnet3RxqDescr
),
2516 VMSTATE_STRUCT(rxq_stats
, Vmxnet3RxqDescr
, 0, vmstate_vmxnet3_rx_stats
,
2517 struct UPT1_RxStats
),
2518 VMSTATE_END_OF_LIST()
2522 static int vmxnet3_post_load(void *opaque
, int version_id
)
2524 VMXNET3State
*s
= opaque
;
2525 PCIDevice
*d
= PCI_DEVICE(s
);
2527 net_tx_pkt_init(&s
->tx_pkt
, PCI_DEVICE(s
),
2528 s
->max_tx_frags
, s
->peer_has_vhdr
);
2529 net_rx_pkt_init(&s
->rx_pkt
, s
->peer_has_vhdr
);
2532 if (!vmxnet3_use_msix_vectors(s
, VMXNET3_MAX_INTRS
)) {
2533 VMW_WRPRN("Failed to re-use MSI-X vectors");
2534 msix_uninit(d
, &s
->msix_bar
, &s
->msix_bar
);
2535 s
->msix_used
= false;
2540 vmxnet3_validate_queues(s
);
2541 vmxnet3_validate_interrupts(s
);
2546 static const VMStateDescription vmstate_vmxnet3_int_state
= {
2547 .name
= "vmxnet3-int-state",
2549 .fields
= (VMStateField
[]) {
2550 VMSTATE_BOOL(is_masked
, Vmxnet3IntState
),
2551 VMSTATE_BOOL(is_pending
, Vmxnet3IntState
),
2552 VMSTATE_BOOL(is_asserted
, Vmxnet3IntState
),
2553 VMSTATE_END_OF_LIST()
2557 static bool vmxnet3_vmstate_need_pcie_device(void *opaque
)
2559 VMXNET3State
*s
= VMXNET3(opaque
);
2561 return !(s
->compat_flags
& VMXNET3_COMPAT_FLAG_DISABLE_PCIE
);
2564 static bool vmxnet3_vmstate_test_pci_device(void *opaque
, int version_id
)
2566 return !vmxnet3_vmstate_need_pcie_device(opaque
);
2569 static const VMStateDescription vmstate_vmxnet3_pcie_device
= {
2570 .name
= "vmxnet3/pcie",
2572 .minimum_version_id
= 1,
2573 .needed
= vmxnet3_vmstate_need_pcie_device
,
2574 .fields
= (VMStateField
[]) {
2575 VMSTATE_PCI_DEVICE(parent_obj
, VMXNET3State
),
2576 VMSTATE_END_OF_LIST()
2580 static const VMStateDescription vmstate_vmxnet3
= {
2583 .minimum_version_id
= 1,
2584 .pre_save
= vmxnet3_pre_save
,
2585 .post_load
= vmxnet3_post_load
,
2586 .fields
= (VMStateField
[]) {
2587 VMSTATE_STRUCT_TEST(parent_obj
, VMXNET3State
,
2588 vmxnet3_vmstate_test_pci_device
, 0,
2589 vmstate_pci_device
, PCIDevice
),
2590 VMSTATE_BOOL(rx_packets_compound
, VMXNET3State
),
2591 VMSTATE_BOOL(rx_vlan_stripping
, VMXNET3State
),
2592 VMSTATE_BOOL(lro_supported
, VMXNET3State
),
2593 VMSTATE_UINT32(rx_mode
, VMXNET3State
),
2594 VMSTATE_UINT32(mcast_list_len
, VMXNET3State
),
2595 VMSTATE_UINT32(mcast_list_buff_size
, VMXNET3State
),
2596 VMSTATE_UINT32_ARRAY(vlan_table
, VMXNET3State
, VMXNET3_VFT_SIZE
),
2597 VMSTATE_UINT32(mtu
, VMXNET3State
),
2598 VMSTATE_UINT16(max_rx_frags
, VMXNET3State
),
2599 VMSTATE_UINT32(max_tx_frags
, VMXNET3State
),
2600 VMSTATE_UINT8(event_int_idx
, VMXNET3State
),
2601 VMSTATE_BOOL(auto_int_masking
, VMXNET3State
),
2602 VMSTATE_UINT8(txq_num
, VMXNET3State
),
2603 VMSTATE_UINT8(rxq_num
, VMXNET3State
),
2604 VMSTATE_UINT32(device_active
, VMXNET3State
),
2605 VMSTATE_UINT32(last_command
, VMXNET3State
),
2606 VMSTATE_UINT32(link_status_and_speed
, VMXNET3State
),
2607 VMSTATE_UINT32(temp_mac
, VMXNET3State
),
2608 VMSTATE_UINT64(drv_shmem
, VMXNET3State
),
2609 VMSTATE_UINT64(temp_shared_guest_driver_memory
, VMXNET3State
),
2611 VMSTATE_STRUCT_ARRAY(txq_descr
, VMXNET3State
,
2612 VMXNET3_DEVICE_MAX_TX_QUEUES
, 0, vmstate_vmxnet3_txq_descr
,
2614 VMSTATE_STRUCT_ARRAY(rxq_descr
, VMXNET3State
,
2615 VMXNET3_DEVICE_MAX_RX_QUEUES
, 0, vmstate_vmxnet3_rxq_descr
,
2617 VMSTATE_STRUCT_ARRAY(interrupt_states
, VMXNET3State
,
2618 VMXNET3_MAX_INTRS
, 0, vmstate_vmxnet3_int_state
,
2621 VMSTATE_END_OF_LIST()
2623 .subsections
= (const VMStateDescription
*[]) {
2624 &vmxstate_vmxnet3_mcast_list
,
2625 &vmstate_vmxnet3_pcie_device
,
2630 static Property vmxnet3_properties
[] = {
2631 DEFINE_NIC_PROPERTIES(VMXNET3State
, conf
),
2632 DEFINE_PROP_BIT("x-old-msi-offsets", VMXNET3State
, compat_flags
,
2633 VMXNET3_COMPAT_FLAG_OLD_MSI_OFFSETS_BIT
, false),
2634 DEFINE_PROP_BIT("x-disable-pcie", VMXNET3State
, compat_flags
,
2635 VMXNET3_COMPAT_FLAG_DISABLE_PCIE_BIT
, false),
2636 DEFINE_PROP_END_OF_LIST(),
2639 static void vmxnet3_realize(DeviceState
*qdev
, Error
**errp
)
2641 VMXNET3Class
*vc
= VMXNET3_DEVICE_GET_CLASS(qdev
);
2642 PCIDevice
*pci_dev
= PCI_DEVICE(qdev
);
2643 VMXNET3State
*s
= VMXNET3(qdev
);
2645 if (!(s
->compat_flags
& VMXNET3_COMPAT_FLAG_DISABLE_PCIE
)) {
2646 pci_dev
->cap_present
|= QEMU_PCI_CAP_EXPRESS
;
2649 vc
->parent_dc_realize(qdev
, errp
);
2652 static void vmxnet3_class_init(ObjectClass
*class, void *data
)
2654 DeviceClass
*dc
= DEVICE_CLASS(class);
2655 PCIDeviceClass
*c
= PCI_DEVICE_CLASS(class);
2656 VMXNET3Class
*vc
= VMXNET3_DEVICE_CLASS(class);
2658 c
->realize
= vmxnet3_pci_realize
;
2659 c
->exit
= vmxnet3_pci_uninit
;
2660 c
->vendor_id
= PCI_VENDOR_ID_VMWARE
;
2661 c
->device_id
= PCI_DEVICE_ID_VMWARE_VMXNET3
;
2662 c
->revision
= PCI_DEVICE_ID_VMWARE_VMXNET3_REVISION
;
2663 c
->romfile
= "efi-vmxnet3.rom";
2664 c
->class_id
= PCI_CLASS_NETWORK_ETHERNET
;
2665 c
->subsystem_vendor_id
= PCI_VENDOR_ID_VMWARE
;
2666 c
->subsystem_id
= PCI_DEVICE_ID_VMWARE_VMXNET3
;
2667 device_class_set_parent_realize(dc
, vmxnet3_realize
,
2668 &vc
->parent_dc_realize
);
2669 dc
->desc
= "VMWare Paravirtualized Ethernet v3";
2670 dc
->reset
= vmxnet3_qdev_reset
;
2671 dc
->vmsd
= &vmstate_vmxnet3
;
2672 dc
->props
= vmxnet3_properties
;
2673 set_bit(DEVICE_CATEGORY_NETWORK
, dc
->categories
);
2676 static const TypeInfo vmxnet3_info
= {
2677 .name
= TYPE_VMXNET3
,
2678 .parent
= TYPE_PCI_DEVICE
,
2679 .class_size
= sizeof(VMXNET3Class
),
2680 .instance_size
= sizeof(VMXNET3State
),
2681 .class_init
= vmxnet3_class_init
,
2682 .instance_init
= vmxnet3_instance_init
,
2683 .interfaces
= (InterfaceInfo
[]) {
2684 { INTERFACE_PCIE_DEVICE
},
2685 { INTERFACE_CONVENTIONAL_PCI_DEVICE
},
2690 static void vmxnet3_register_types(void)
2692 VMW_CBPRN("vmxnet3_register_types called...");
2693 type_register_static(&vmxnet3_info
);
2696 type_init(vmxnet3_register_types
)