Skip to contentSkip to conversation

VMXNET3 paravirtual NIC device implementation

PATCH Superseded Dmitry Fleytman 2 participants 8 messages Mar 6, 2013 – Mar 7, 2013 Networking

v13 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

v13 cover VMXNET3 paravirtual NIC device implementation

This set of patches implements VMWare VMXNET3 paravirtual NIC device. The device supports of all the device features including offload capabilties, VLANs and etc.
The device is tested on different OSes:

    Fedora 15
    Ubuntu 10.4
    Centos 6.2
    Windows 2008R2
    Windows 2008 64bit
    Windows 2008 32bit
    Windows 2003 64bit
    Windows 2003 32bit

Changes in V13:
Licensing of vmxnet3.h changed to match original VMWare's header file license

Changes in V12:

QOM-related fixes

Changes in V11:
Rebased to master HEAD to fix multiqueue compilation issues

Changes in V10:

Issues reported by Stefan Hajnoczi fixed.

Changes in V9:

Issues reported by Stefan Hajnoczi fixed.

Changes in V8:

Issues reported by Stefan Hajnoczi reviewed and mostly fixed:

Review

Quoted 5 lines
(quoted diff) +5 -0
+        }
+        curr_src_off += src[i].iov_len;
+    }
+    return j;
+}

The existing iov_copy() function provides equivalent functionality. I don't think iov_rebuild() is needed.

[DF] Done. Thanks, missed it.

Review

Quoted 6 lines
(quoted diff) +6 -0
+            size -= len;
+        }
+        iovec_off += iov[i].iov_len;
+    }
+    return res;
+}

Rename this net_checksum_add_iov() and place it in net/checksum.c, then the new dependency on net from block can be dropped.

[DF] Done.

Quoted 5 lines

+vmw_shmem_read(hwaddr addr, void *buf, int len)

 {
     VMW_SHPRN("SHMEM r: %" PRIx64 ", len: %d to %p", addr, len, buf);
     cpu_physical_memory_read(addr, buf, len);

}

All changes to this file should be squashed with the previous patch.

[DF] Done

Review

Quoted 13 lines
(quoted diff) +9 -0
+#ifdef VMXNET_DEBUG_SHMEM_ACCESS
+#define VMW_SHPRN(fmt, ...)                                                  
 \
+    do {                                                                     
 \
+        printf("[%s][SH][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,      
 \
+            ## __VA_ARGS__);                                                 
 \
+    } while (0)
+#else
+#define VMW_SHPRN(fmt, ...) do {} while (0)
+#endif

Please use QEMU tracing. It eliminates all this boilerplate and conditional compilation. Tracing can be enabled/disabled at runtime and works with SystemTap/DTrace. See docs/tracing.txt.

[DF] We'd like to stick with compile time logic in this case becase of 2 reasons:
[DF] 1. These printouts are intended for reverse engineering/development only and there is
[DF] no need to enable them at run time
[DF] 2. There is a big number of printouts, all driver-device communication is traced,
[DF] they hit performance even on strongest x86 in case of run-time logic

Review

Quoted 5 lines
(quoted diff) +5 -0
+struct eth_header {
+    uint8_t  h_dest[ETH_ALEN];   /* destination eth addr */
+    uint8_t  h_source[ETH_ALEN]; /* source ether addr    */
+    uint16_t h_proto;            /* packet type ID field */
+};

Looks like it's copy-pasted stuff from /usr/include/linux/if_*.h, /usr/include/netinet/*.h, and friends. If the system-wide headers are included names will collide for some of the macros at least.

Did you check if the slirp/ definitions can be reused?

[DF] Yes, you are right. This is copy-pasted from different places. [DF] Slips definishing do not fully cover our needs.

I'd rather we import network header definitions once in a generic place into the source tree. That way vmxnet and other components don't need to redefine these structs.

[DF] Exaclty! Our intention is to create generic header with network definitions and make everyone use it. [DF] We can move our header to some shared place if you want, however I'd do it in parallel with cleanup [DF] of similar definitions in existing code and this is a big change that os out of scope of these patches.

Quoted 2 lines

+ *===========================================================================*/

Is this huge comment box a sign that the code should be split into a foo_tx.c and an foo_rx.c file?

[DF] As for me this file is not that big to be splitted (<800 lines), however I'll do this if you insist :)

Quoted 1 line

+size_t vmxnet_tx_pkt_send(VmxnetTxPktH pkt, NetClientState *vc)

'vc' is an old name that was used for VLANClientState. The struct has since been renamed to NetClientState and the rest of QEMU uses 'nc' instead of 'vc'.

[DF] Fixed. Thanks.

Review

Quoted 2 lines
(quoted diff) +2 -0
+/* tx module context handle */
+typedef void *VmxnetTxPktH;

Forward-declaring the struct is nicer:

typedef struct VmxnetTxPkt VmxnetTxPkt;

The definition of VmxnetTxPkt is still hidden from the caller but you avoid the void* and casting. In vmxnet_pkt.c define using:

struct VmxnetTxPkt {
    ...
};

[DF] Agree, fixed. Thanks.

hw/vmxnet_utils.h

Quoted 4 lines
hw/vmxnet_utils.h +0 -0
index 7fd9a01..fac3b7b 100644

Please squash these fixes into the previous patch.

[DF] Oops, my bad. Fixed.

hw/vmxnet_utils.h

Quoted 3 lines
hw/vmxnet_utils.h +3 -0
+        uint8_t msix_used;
+        /* Whether MSI support was installed successfully */
+        uint8_t msi_used;

These two fields should be bool.

hw/vmxnet_utils.h

Quoted 2 lines
hw/vmxnet_utils.h +2 -0
+        /* Whether automatic interrupts masking enabled */
+        uint8_t auto_int_masking;

bool

[DF] Done.

hw/vmxnet_utils.h

Quoted 9 lines
hw/vmxnet_utils.h +9 -0
+static inline void vmxnet3_flush_shmem_changes(void)
+{
+    /*
+     * Flush shared memory changes
+     * Needed before sending interrupt to guest to ensure
+     * it gets consistent memory state
+     */
+    smp_wmb();
+}

It's useful to document why a memory barrier is being used in each instance. Therefore hiding smp_wmb() inside a wrapper function isn't great.

[DF] Fixed.

Also, it's suspicious that smb_wmb() is used but no other barriers are used. What about a read memory barrier when accessing shared memory written by the guest?

[DF] VMWARE interface build a in safe way - you always read out data buffer (packet descriptor) with memcopy, [DF] and then check its last byte to see whether it was fully filled by driver.
[DF] In this case device doesn't need read barriers. Drivers need write barriers of course to secure [DF] proper order of writes.

Changes in V7:

Issues reported by Michael S. Tsirkin reviewed and mostly fixed:

File vmware_utils.h:

...

hw/vmxnet_utils.h

Quoted 7 lines
hw/vmxnet_utils.h +7 -0
+static inline void
+vmw_shmem_st64(target_phys_addr_t addr, uint64_t value)
+{
+    VMW_SHPRN("SHMEM store64: %" PRIx64 " (value %" PRIx64 ")", addr, value);
+    stq_le_phys(addr, value);
+}
+

Pls remove these wrappers. These are just memory stores. Our codebase is too large as it is without every driver wrapping all standard calls.

[DF] Idea behind this macros is to have printout in each of them [DF] Printouts are really needed when reverse-engineering windows guest drivers [DF] Since there is no windows drivers code this is the only way to understand [DF] sequences they use

Quoted 1 line

+/* MACROS for simplification of operations on array-style registers */

UPPERCASE ABUSE

[DF] Fixed

hw/vmxnet_utils.h

Quoted 2 lines
hw/vmxnet_utils.h +2 -0
+#define IS_MULTIREG_ADDR(addr, base, cnt, regsize)                 \
+    (((addr + 1) > (base)) && ((addr) < (base) + (cnt) * (regsize)))

Same as range_covers_byte(base, cnt * regsize, addr)?

[DF] Fixed, thanks

hw/vmxnet_utils.h

Quoted 4 lines
hw/vmxnet_utils.h +4 -0
+
+#define MULTIREG_IDX_BY_ADDR(addr, base, regsize)                  \
+    (((addr) - (base)) / (regsize))
+

Above two macros is all that's left. No objection but it does not say what they do - want to add minimal documentation?
And please prefix with VMWARE_ or something.

[DF] Prefix added, macros documented

File vmxnet_utils.h (and related with the same problems):

...

hw/vmxnet_utils.h

Quoted 6 lines

+ * See the COPYING file in the top-level directory.
+ *
+ */

hw/vmxnet_utils.h +3 -0
+
+#ifndef _VMXNET_UTILS_H_
+#define _VMXNET_UTILS_H_

Please do not start identifiers with _ followed by an uppercase lattters.

[DF] Fixed

...

hw/vmxnet_utils.h

Quoted 7 lines
hw/vmxnet_utils.h +7 -0
+
+struct eth_header {
+    uint8_t  h_dest[ETH_ALEN];   /* destination eth addr */
+    uint8_t  h_source[ETH_ALEN]; /* source ether addr    */
+    uint16_t h_proto;            /* packet type ID field */
+};
+

And fix struct definitions to
1. follow qemu coding style
[DF] It's not clear what's wrong with the coding style. Please, elaborate.
2. start with vmxnet
[DF] Since this is generic network definitions with no device specifics
[DF] I'm not sure it makes sense to add vmxnet prefix.
[DF] I'd say it makes sense to put them into some generic header files under "net" directory instead [DF] and clean up other devices that have their local definitions of the same structures. [DF] Please, advise.

I also don't really understand why are these functions split out - vmxnet is the only user, no?

[DF] Currently vmxnet3 is the only user, hovewer we have vmxnet2 implementation as well (not submitted yet) [DF] and it uses the same header

File vmxnet_pkt.h:

...

hw/vmxnet_utils.h

Quoted 3 lines
hw/vmxnet_utils.h +3 -0
+
+/* tx module context handle */
+typedef void *VmxnetTxPktH;

This gets you zero type safety and makes debugging impossible. Just use pointers like everyone does.

[DF] Handle type is added to hide VmxnetTxPkt structure into .c header [DF] for better encapsulation.
[DF] Should we drop it anyway?

Files vmxnet3.*:

...

hw/vmxnet_utils.h

Quoted 3 lines
hw/vmxnet_utils.h +3 -0
+
+    if (zero_region) {
+        vmw_shmem_set(pa, 0, size*cell_size);

spaces around *

[DF] Fixed

...

Quoted 7 lines

+#define vmxnet3_ring_dump(macro, ring_name, ridx, r) \
+ macro("%s#%d: base %" PRIx64 " size %lu cell_size %lu gen %d next %lu",
\
+ (ring_name), (ridx),
\
+ (r)->pa, (r)->size, (r)->cell_size, (r)->gen, (r)->next)

make macros upper case

[DF] Fixed

...

hw/vmxnet_utils.h

Quoted 5 lines
hw/vmxnet_utils.h +5 -0
+static inline void vmxnet3_flush_shmem_changes(void)
+{
+    /*
+     * Flush shared memory changes
+     * Needed before transferring control to guest

what does 'transferring control to guest' mean?
[DF] Changed to
[DF] /*

[DF]     * Flush shared memory changes
[DF]     * Needed before sending interrupt to guest to ensure
[DF]     * it gets consistent memory state
[DF]     */

...

hw/vmxnet_utils.h

Quoted 3 lines
hw/vmxnet_utils.h +3 -0
+     */
+    smp_wmb();
+}

Don't use wrappers like this. They just hide bugs. For example it's not helpful before an interrupt in the function below.

[DF] I guess you are talking about vmxnet3_complete_packet() [DF] Strictly speaking barrier is a must because we change shared memory in [DF] vmxnet3_complete_packet()

[DF] And the wrapper is a good thing because its name explains its effect [DF] in a formal way as opposed to comments

...

hw/vmxnet_utils.h

Quoted 2 lines
hw/vmxnet_utils.h +2 -0
+    switch (status) {
+    case VMXNET3_PKT_STATUS_OK: {

don't put {} around cases: they align incorrectly
if it's too big move to a function.

[DF] Fixed

...

hw/vmxnet_utils.h

Quoted 5 lines
hw/vmxnet_utils.h +5 -0
+static bool
+vmxnet3_send_packet(VMXNET3State *s, uint32_t qidx)
+{
+    size_t bytes_sent = 0;
+    bool res = true;

why = true? don't initialize just because.

[DF] Fixed

...

Quoted 6 lines

+/*
+ * VMWARE headers we got from Linux kernel do not fully comply QEMU coding
+ * standards in sense of types and defines used.
+ * Since we didn't want to change VMWARE code, following set of typedefs
+ * and defines needed to compile these headers with QEMU introduced.
+ */

No need for this now.
You can export headers and put them under linux-headers.

[DF] Not sure it is possible because the header as-is is not stand-alone and won't compile [DF] without changes. We extracted definitions we use from their header and dropped unused [DF] and kernel-specific stuff.
[DF} Please, advise.

...

Quoted 1 line

+ if (VMXNET3_OM_TSO == s->offload_mode) {

Don't do Yoda style like this

[DF] "Yoda" style removed everywhere

Changes in V6:
Fixed most of problems pointed out by Michael S. Tsirkin
The only issue still open is creation of shared place
with generic network structures and functions. Currently
all generic network code introduced by VMXNET3 resides in vmxnet_utils.c/h files. It could be moved to some shared location however we believe it is a matter of separate refactoring as there are a lot of copy-pasted definitions in almost every device and code cleanup efforts requred in order to create truly shared codebase.

Implemented suggestions by Anthony Liguori

Fixed incorrect checksum caclulation for some packets in SW offloads mode

Changes in V5:
MSI-X save/load implemented in the device instead of pci bus as suggested by Michael S. Tsirkin

Patches regrouped as suggested by Paolo Bonzini

Changes in V4:
Fixed a few problems uncovered by NETIO test suit Assertion on failure to initialize MSI/MSI-X replaced with warning message and fallback to Legacy/MSI respectively

Various coding style adjustments and patch split-up as suggested by Anthony
Liguori

Live migration support added

Changes in V3:
Fixed crash when net device that is used as network fronted has no virtio HDR support.
Task offloads emulation for cases when net device that is used as network fronted has no virtio HDR support.

Changes in V2:
License text changed accoring to community suggestions Standard license header from GPLv2+ - licensed QEMU files used

Dmitry Fleytman (5):
Checksum-related utility functions
net: iovec checksum calculator
Common definitions for VMWARE devices
Packet abstraction for VMWARE network devices
VMXNET3 device implementation

 default-configs/pci.mak |    1 +
 hw/Makefile.objs        |    2 +
 hw/pci/pci.h            |    1 +
 hw/vmware_utils.h       |  143 +++
 hw/vmxnet3.c            | 2460 +++++++++++++++++++++++++++++++++++++++++++++++
 hw/vmxnet3.h            |  760 +++++++++++++++
 hw/vmxnet_debug.h       |  115 +++
 hw/vmxnet_rx_pkt.c      |  187 ++++
 hw/vmxnet_rx_pkt.h      |  174 ++++
 hw/vmxnet_tx_pkt.c      |  567 +++++++++++
 hw/vmxnet_tx_pkt.h      |  148 +++
 include/net/checksum.h  |   26 +-
 include/net/eth.h       |  347 +++++++
 net/Makefile.objs       |    1 +
 net/checksum.c          |   42 +-
 net/eth.c               |  217 +++++
 16 files changed, 5184 insertions(+), 7 deletions(-)
 create mode 100644 hw/vmware_utils.h
 create mode 100644 hw/vmxnet3.c
 create mode 100644 hw/vmxnet3.h
 create mode 100644 hw/vmxnet_debug.h
 create mode 100644 hw/vmxnet_rx_pkt.c
 create mode 100644 hw/vmxnet_rx_pkt.h
 create mode 100644 hw/vmxnet_tx_pkt.c
 create mode 100644 hw/vmxnet_tx_pkt.h
 create mode 100644 include/net/eth.h
 create mode 100644 net/eth.c
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH v13 1/5 Checksum-related utility functions

net_checksum_add_cont()
checksum calculation for scattered data with odd chunk sizes

net_raw_checksum()
checksum calculation for a buffer

---
 include/net/checksum.h | 14 +++++++++++++-
 net/checksum.c         | 13 +++++++------
 2 files changed, 20 insertions(+), 7 deletions(-)
include/net/checksum.h +13 -1
index 1f05298..3e7b93d 100644
@@ -20,10 +20,22 @@
 
 #include <stdint.h>
 
-uint32_t net_checksum_add(int len, uint8_t *buf);
+uint32_t net_checksum_add_cont(int len, uint8_t *buf, int seq);
 uint16_t net_checksum_finish(uint32_t sum);
 uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
                              uint8_t *addrs, uint8_t *buf);
 void net_checksum_calculate(uint8_t *data, int length);
 
+static inline uint32_t
+net_checksum_add(int len, uint8_t *buf)
+{
+    return net_checksum_add_cont(len, buf, 0);
+}
+
+static inline uint16_t
+net_raw_checksum(uint8_t *data, int length)
+{
+    return net_checksum_finish(net_checksum_add(length, data));
+}
+
 #endif /* QEMU_NET_CHECKSUM_H */
net/checksum.c +7 -6
index 9919b2e..4fa5563 100644
@@ -20,16 +20,17 @@
 #define PROTO_TCP  6
 #define PROTO_UDP 17
 
-uint32_t net_checksum_add(int len, uint8_t *buf)
+uint32_t net_checksum_add_cont(int len, uint8_t *buf, int seq)
 {
     uint32_t sum = 0;
     int i;
 
-    for (i = 0; i < len; i++) {
-	if (i & 1)
-	    sum += (uint32_t)buf[i];
-	else
-	    sum += (uint32_t)buf[i] << 8;
+    for (i = seq; i < seq + len; i++) {
+        if (i & 1) {
+            sum += (uint32_t)buf[i - seq];
+        } else {
+            sum += (uint32_t)buf[i - seq] << 8;
+        }
     }
     return sum;
 }
Signature · 1 line
1.8.1.2
#2 lore raw

PATCH v13 2/5 net: iovec checksum calculator

In reply to Dmitry Fleytman
---
 include/net/checksum.h | 12 ++++++++++++
 net/checksum.c         | 29 +++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
include/net/checksum.h +12 -0
index 3e7b93d..80203fb 100644
@@ -38,4 +38,16 @@ net_raw_checksum(uint8_t *data, int length)
     return net_checksum_finish(net_checksum_add(length, data));
 }
 
+/**
+ * net_checksum_add_iov: scatter-gather vector checksumming
+ *
+ * @iov: input scatter-gather array
+ * @iov_cnt: number of array elements
+ * @iov_off: starting iov offset for checksumming
+ * @size: length of data to be checksummed
+ */
+uint32_t net_checksum_add_iov(const struct iovec *iov,
+                              const unsigned int iov_cnt,
+                              uint32_t iov_off, uint32_t size);
+
 #endif /* QEMU_NET_CHECKSUM_H */
net/checksum.c +29 -0
index 4fa5563..14c0855 100644
@@ -15,6 +15,7 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "qemu-common.h"
 #include "net/checksum.h"
 
 #define PROTO_TCP  6
@@ -84,3 +85,31 @@ void net_checksum_calculate(uint8_t *data, int length)
     data[14+hlen+csum_offset]   = csum >> 8;
     data[14+hlen+csum_offset+1] = csum & 0xff;
 }
+
+uint32_t
+net_checksum_add_iov(const struct iovec *iov, const unsigned int iov_cnt,
+                     uint32_t iov_off, uint32_t size)
+{
+    size_t iovec_off, buf_off;
+    unsigned int i;
+    uint32_t res = 0;
+    uint32_t seq = 0;
+
+    iovec_off = 0;
+    buf_off = 0;
+    for (i = 0; i < iov_cnt && size; i++) {
+        if (iov_off < (iovec_off + iov[i].iov_len)) {
+            size_t len = MIN((iovec_off + iov[i].iov_len) - iov_off , size);
+            void *chunk_buf = iov[i].iov_base + (iov_off - iovec_off);
+
+            res += net_checksum_add_cont(len, chunk_buf, seq);
+            seq += len;
+
+            buf_off += len;
+            iov_off += len;
+            size -= len;
+        }
+        iovec_off += iov[i].iov_len;
+    }
+    return res;
+}
Signature · 1 line
1.8.1.2
#3 lore raw

PATCH v13 3/5 Common definitions for VMWARE devices

In reply to Dmitry Fleytman
---
 hw/vmware_utils.h | 143 ++++++++++++++++++++++
 hw/vmxnet_debug.h | 115 ++++++++++++++++++
 include/net/eth.h | 347 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/Makefile.objs |   1 +
 net/eth.c         | 217 ++++++++++++++++++++++++++++++++++
 5 files changed, 823 insertions(+)
 create mode 100644 hw/vmware_utils.h
 create mode 100644 hw/vmxnet_debug.h
 create mode 100644 include/net/eth.h
 create mode 100644 net/eth.c
hw/vmware_utils.h new file +143 -0
new file mode 100644
index 0000000..5307e2c
@@ -0,0 +1,143 @@
+/*
+ * QEMU VMWARE paravirtual devices - auxiliary code
+ *
+ * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
+ *
+ * Developed by Daynix Computing LTD (http://www.daynix.com)
+ *
+ * Authors:
+ * Dmitry Fleytman <[email protected]>
+ * Yan Vugenfirer <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef VMWARE_UTILS_H
+#define VMWARE_UTILS_H
+
+#include "qemu/range.h"
+
+#ifndef VMW_SHPRN
+#define VMW_SHPRN(fmt, ...) do {} while (0)
+#endif
+
+/*
+ * Shared memory access functions with byte swap support
+ * Each function contains printout for reverse-engineering needs
+ *
+ */
+static inline void
+vmw_shmem_read(hwaddr addr, void *buf, int len)
+{
+    VMW_SHPRN("SHMEM r: %" PRIx64 ", len: %d to %p", addr, len, buf);
+    cpu_physical_memory_read(addr, buf, len);
+}
+
+static inline void
+vmw_shmem_write(hwaddr addr, void *buf, int len)
+{
+    VMW_SHPRN("SHMEM w: %" PRIx64 ", len: %d to %p", addr, len, buf);
+    cpu_physical_memory_write(addr, buf, len);
+}
+
+static inline void
+vmw_shmem_rw(hwaddr addr, void *buf, int len, int is_write)
+{
+    VMW_SHPRN("SHMEM r/w: %" PRIx64 ", len: %d (to %p), is write: %d",
+              addr, len, buf, is_write);
+
+    cpu_physical_memory_rw(addr, buf, len, is_write);
+}
+
+static inline void
+vmw_shmem_set(hwaddr addr, uint8 val, int len)
+{
+    int i;
+    VMW_SHPRN("SHMEM set: %" PRIx64 ", len: %d (value 0x%X)", addr, len, val);
+
+    for (i = 0; i < len; i++) {
+        cpu_physical_memory_write(addr + i, &val, 1);
+    }
+}
+
+static inline uint32_t
+vmw_shmem_ld8(hwaddr addr)
+{
+    uint8_t res = ldub_phys(addr);
+    VMW_SHPRN("SHMEM load8: %" PRIx64 " (value 0x%X)", addr, res);
+    return res;
+}
+
+static inline void
+vmw_shmem_st8(hwaddr addr, uint8_t value)
+{
+    VMW_SHPRN("SHMEM store8: %" PRIx64 " (value 0x%X)", addr, value);
+    stb_phys(addr, value);
+}
+
+static inline uint32_t
+vmw_shmem_ld16(hwaddr addr)
+{
+    uint16_t res = lduw_le_phys(addr);
+    VMW_SHPRN("SHMEM load16: %" PRIx64 " (value 0x%X)", addr, res);
+    return res;
+}
+
+static inline void
+vmw_shmem_st16(hwaddr addr, uint16_t value)
+{
+    VMW_SHPRN("SHMEM store16: %" PRIx64 " (value 0x%X)", addr, value);
+    stw_le_phys(addr, value);
+}
+
+static inline uint32_t
+vmw_shmem_ld32(hwaddr addr)
+{
+    uint32_t res = ldl_le_phys(addr);
+    VMW_SHPRN("SHMEM load32: %" PRIx64 " (value 0x%X)", addr, res);
+    return res;
+}
+
+static inline void
+vmw_shmem_st32(hwaddr addr, uint32_t value)
+{
+    VMW_SHPRN("SHMEM store32: %" PRIx64 " (value 0x%X)", addr, value);
+    stl_le_phys(addr, value);
+}
+
+static inline uint64_t
+vmw_shmem_ld64(hwaddr addr)
+{
+    uint64_t res = ldq_le_phys(addr);
+    VMW_SHPRN("SHMEM load64: %" PRIx64 " (value %" PRIx64 ")", addr, res);
+    return res;
+}
+
+static inline void
+vmw_shmem_st64(hwaddr addr, uint64_t value)
+{
+    VMW_SHPRN("SHMEM store64: %" PRIx64 " (value %" PRIx64 ")", addr, value);
+    stq_le_phys(addr, value);
+}
+
+/* Macros for simplification of operations on array-style registers */
+
+/*
+ * Whether <addr> lies inside of array-style register defined by <base>,
+ * number of elements (<cnt>) and element size (<regsize>)
+ *
+*/
+#define VMW_IS_MULTIREG_ADDR(addr, base, cnt, regsize)                 \
+    range_covers_byte(base, cnt * regsize, addr)
+
+/*
+ * Returns index of given register (<addr>) in array-style register defined by
+ * <base> and element size (<regsize>)
+ *
+*/
+#define VMW_MULTIREG_IDX_BY_ADDR(addr, base, regsize)                  \
+    (((addr) - (base)) / (regsize))
+
+#endif
hw/vmxnet_debug.h new file +115 -0

115 lines not on this page · raw message

include/net/eth.h new file +347 -0

347 lines not on this page · raw message

net/Makefile.objs +1 -0
index a08cd14..4854a14 100644
@@ -1,6 +1,7 @@
 common-obj-y = net.o queue.o checksum.o util.o hub.o
 common-obj-y += socket.o
 common-obj-y += dump.o
+common-obj-y += eth.o
 common-obj-$(CONFIG_POSIX) += tap.o
 common-obj-$(CONFIG_LINUX) += tap-linux.o
 common-obj-$(CONFIG_WIN32) += tap-win32.o
net/eth.c new file +217 -0

217 lines not on this page · raw message

Signature · 1 line
1.8.1.2
#4 lore raw

PATCH v13 4/5 Packet abstraction for VMWARE network devices

In reply to Dmitry Fleytman
---
 hw/Makefile.objs   |   1 +
 hw/vmxnet_rx_pkt.c | 187 ++++++++++++++++++
 hw/vmxnet_rx_pkt.h | 174 ++++++++++++++++
 hw/vmxnet_tx_pkt.c | 567 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/vmxnet_tx_pkt.h | 148 ++++++++++++++
 5 files changed, 1077 insertions(+)
 create mode 100644 hw/vmxnet_rx_pkt.c
 create mode 100644 hw/vmxnet_rx_pkt.h
 create mode 100644 hw/vmxnet_tx_pkt.c
 create mode 100644 hw/vmxnet_tx_pkt.h
hw/Makefile.objs +1 -0
index 40ebe46..14922cb 100644
@@ -119,6 +119,7 @@ common-obj-$(CONFIG_PCNET_PCI) += pcnet-pci.o
 common-obj-$(CONFIG_PCNET_COMMON) += pcnet.o
 common-obj-$(CONFIG_E1000_PCI) += e1000.o
 common-obj-$(CONFIG_RTL8139_PCI) += rtl8139.o
+common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet_tx_pkt.o vmxnet_rx_pkt.o
 
 common-obj-$(CONFIG_SMC91C111) += smc91c111.o
 common-obj-$(CONFIG_LAN9118) += lan9118.o
hw/vmxnet_rx_pkt.c new file +187 -0

187 lines not on this page · raw message

hw/vmxnet_rx_pkt.h new file +174 -0

174 lines not on this page · raw message

hw/vmxnet_tx_pkt.c new file +567 -0

567 lines not on this page · raw message

hw/vmxnet_tx_pkt.h new file +148 -0

148 lines not on this page · raw message

Signature · 1 line
1.8.1.2
#5 lore raw

PATCH v13 5/5 VMXNET3 device implementation

In reply to Dmitry Fleytman
---
 default-configs/pci.mak |    1 +
 hw/Makefile.objs        |    1 +
 hw/pci/pci.h            |    1 +
 hw/vmxnet3.c            | 2460 +++++++++++++++++++++++++++++++++++++++++++++++
 hw/vmxnet3.h            |  760 +++++++++++++++
 5 files changed, 3223 insertions(+)
 create mode 100644 hw/vmxnet3.c
 create mode 100644 hw/vmxnet3.h
default-configs/pci.mak +1 -0
index ee2d18d..ce56d58 100644
@@ -13,6 +13,7 @@ CONFIG_LSI_SCSI_PCI=y
 CONFIG_MEGASAS_SCSI_PCI=y
 CONFIG_RTL8139_PCI=y
 CONFIG_E1000_PCI=y
+CONFIG_VMXNET3_PCI=y
 CONFIG_IDE_CORE=y
 CONFIG_IDE_QDEV=y
 CONFIG_IDE_PCI=y
hw/Makefile.objs +1 -0
index 14922cb..026aff6 100644
@@ -120,6 +120,7 @@ common-obj-$(CONFIG_PCNET_COMMON) += pcnet.o
 common-obj-$(CONFIG_E1000_PCI) += e1000.o
 common-obj-$(CONFIG_RTL8139_PCI) += rtl8139.o
 common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet_tx_pkt.o vmxnet_rx_pkt.o
+common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet3.o
 
 common-obj-$(CONFIG_SMC91C111) += smc91c111.o
 common-obj-$(CONFIG_LAN9118) += lan9118.o
hw/pci/pci.h +1 -0
index f340fe5..3beb70b 100644
@@ -60,6 +60,7 @@
 #define PCI_DEVICE_ID_VMWARE_NET         0x0720
 #define PCI_DEVICE_ID_VMWARE_SCSI        0x0730
 #define PCI_DEVICE_ID_VMWARE_IDE         0x1729
+#define PCI_DEVICE_ID_VMWARE_VMXNET3     0x07B0
 
 /* Intel (0x8086) */
 #define PCI_DEVICE_ID_INTEL_82551IT      0x1209
hw/vmxnet3.c new file +2460 -0

2,460 lines not on this page · raw message

hw/vmxnet3.h new file +760 -0

519 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.8.1.2

Part of the diff is not shown here. View the raw message.

#6 lore raw

Re: [Qemu-devel] [PATCH v13 5/5] VMXNET3 device implementation

Am 06.03.2013 08:21, schrieb Dmitry Fleytman:

Quoted 152 lines
---
 default-configs/pci.mak |    1 +
 hw/Makefile.objs        |    1 +
 hw/pci/pci.h            |    1 +
 hw/vmxnet3.c            | 2460 +++++++++++++++++++++++++++++++++++++++++++++++
 hw/vmxnet3.h            |  760 +++++++++++++++
 5 files changed, 3223 insertions(+)
 create mode 100644 hw/vmxnet3.c
 create mode 100644 hw/vmxnet3.h
default-configs/pci.mak +1 -0
index ee2d18d..ce56d58 100644
@@ -13,6 +13,7 @@ CONFIG_LSI_SCSI_PCI=y
 CONFIG_MEGASAS_SCSI_PCI=y
 CONFIG_RTL8139_PCI=y
 CONFIG_E1000_PCI=y
+CONFIG_VMXNET3_PCI=y
 CONFIG_IDE_CORE=y
 CONFIG_IDE_QDEV=y
 CONFIG_IDE_PCI=y
hw/Makefile.objs +1 -0
index 14922cb..026aff6 100644
@@ -120,6 +120,7 @@ common-obj-$(CONFIG_PCNET_COMMON) += pcnet.o
 common-obj-$(CONFIG_E1000_PCI) += e1000.o
 common-obj-$(CONFIG_RTL8139_PCI) += rtl8139.o
 common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet_tx_pkt.o vmxnet_rx_pkt.o
+common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet3.o
 
 common-obj-$(CONFIG_SMC91C111) += smc91c111.o
 common-obj-$(CONFIG_LAN9118) += lan9118.o
hw/pci/pci.h +1 -0
index f340fe5..3beb70b 100644
@@ -60,6 +60,7 @@
 #define PCI_DEVICE_ID_VMWARE_NET         0x0720
 #define PCI_DEVICE_ID_VMWARE_SCSI        0x0730
 #define PCI_DEVICE_ID_VMWARE_IDE         0x1729
+#define PCI_DEVICE_ID_VMWARE_VMXNET3     0x07B0
 
 /* Intel (0x8086) */
 #define PCI_DEVICE_ID_INTEL_82551IT      0x1209
hw/vmxnet3.c new file +98 -0
new file mode 100644
index 0000000..75b7181
@@ -0,0 +1,2460 @@
+/*
+ * QEMU VMWARE VMXNET3 paravirtual NIC
+ *
+ * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
+ *
+ * Developed by Daynix Computing LTD (http://www.daynix.com)
+ *
+ * Authors:
+ * Dmitry Fleytman <[email protected]>
+ * Tamir Shomer <[email protected]>
+ * Yan Vugenfirer <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "hw.h"
+#include "pci/pci.h"
+#include "net/net.h"
+#include "virtio-net.h"
+#include "net/tap.h"
+#include "net/checksum.h"
+#include "sysemu/sysemu.h"
+#include "qemu-common.h"
+#include "qemu/bswap.h"
+#include "pci/msix.h"
+#include "pci/msi.h"
+
+#include "vmxnet3.h"
+#include "vmxnet_debug.h"
+#include "vmware_utils.h"
+#include "vmxnet_tx_pkt.h"
+#include "vmxnet_rx_pkt.h"
+
+#define PCI_DEVICE_ID_VMWARE_VMXNET3_REVISION 0x1
+#define VMXNET3_MSIX_BAR_SIZE 0x2000
+
+#define VMXNET3_BAR0_IDX      (0)
+#define VMXNET3_BAR1_IDX      (1)
+#define VMXNET3_MSIX_BAR_IDX  (2)
+
+#define VMXNET3_OFF_MSIX_TABLE (0x000)
+#define VMXNET3_OFF_MSIX_PBA   (0x800)
+
+/* Link speed in Mbps should be shifted by 16 */
+#define VMXNET3_LINK_SPEED      (1000 << 16)
+
+/* Link status: 1 - up, 0 - down. */
+#define VMXNET3_LINK_STATUS_UP  0x1
+
+/* Least significant bit should be set for revision and version */
+#define VMXNET3_DEVICE_VERSION    0x1
+#define VMXNET3_DEVICE_REVISION   0x1
+
+/* Macros for rings descriptors access */
+#define VMXNET3_READ_TX_QUEUE_DESCR8(dpa, field) \
+    (vmw_shmem_ld8(dpa + offsetof(struct Vmxnet3_TxQueueDesc, field)))
+
+#define VMXNET3_WRITE_TX_QUEUE_DESCR8(dpa, field, value) \
+    (vmw_shmem_st8(dpa + offsetof(struct Vmxnet3_TxQueueDesc, field, value)))
+
+#define VMXNET3_READ_TX_QUEUE_DESCR32(dpa, field) \
+    (vmw_shmem_ld32(dpa + offsetof(struct Vmxnet3_TxQueueDesc, field)))
+
+#define VMXNET3_WRITE_TX_QUEUE_DESCR32(dpa, field, value) \
+    (vmw_shmem_st32(dpa + offsetof(struct Vmxnet3_TxQueueDesc, field), value))
+
+#define VMXNET3_READ_TX_QUEUE_DESCR64(dpa, field) \
+    (vmw_shmem_ld64(dpa + offsetof(struct Vmxnet3_TxQueueDesc, field)))
+
+#define VMXNET3_WRITE_TX_QUEUE_DESCR64(dpa, field, value) \
+    (vmw_shmem_st64(dpa + offsetof(struct Vmxnet3_TxQueueDesc, field), value))
+
+#define VMXNET3_READ_RX_QUEUE_DESCR64(dpa, field) \
+    (vmw_shmem_ld64(dpa + offsetof(struct Vmxnet3_RxQueueDesc, field)))
+
+#define VMXNET3_READ_RX_QUEUE_DESCR32(dpa, field) \
+    (vmw_shmem_ld32(dpa + offsetof(struct Vmxnet3_RxQueueDesc, field)))
+
+#define VMXNET3_WRITE_RX_QUEUE_DESCR64(dpa, field, value) \
+    (vmw_shmem_st64(dpa + offsetof(struct Vmxnet3_RxQueueDesc, field), value))
+
+#define VMXNET3_WRITE_RX_QUEUE_DESCR8(dpa, field, value) \
+    (vmw_shmem_st8(dpa + offsetof(struct Vmxnet3_RxQueueDesc, field), value))
+
+/* Macros for guest driver shared area access */
+#define VMXNET3_READ_DRV_SHARED64(shpa, field) \
+    (vmw_shmem_ld64(shpa + offsetof(struct Vmxnet3_DriverShared, field)))
+
+#define VMXNET3_READ_DRV_SHARED32(shpa, field) \
+    (vmw_shmem_ld32(shpa + offsetof(struct Vmxnet3_DriverShared, field)))
+
+#define VMXNET3_WRITE_DRV_SHARED32(shpa, field, val) \
+    (vmw_shmem_st32(shpa + offsetof(struct Vmxnet3_DriverShared, field), val))
+
+#define VMXNET3_READ_DRV_SHARED16(shpa, field) \
+    (vmw_shmem_ld16(shpa + offsetof(struct Vmxnet3_DriverShared, field)))

hw/vmxnet3.c line 108

Quoted 10 lines
hw/vmxnet3.c new file +10 -0
+
+#define VMXNET3_READ_DRV_SHARED8(shpa, field) \
+    (vmw_shmem_ld8(shpa + offsetof(struct Vmxnet3_DriverShared, field)))
+
+#define VMXNET3_READ_DRV_SHARED(shpa, field, b, l) \
+    (vmw_shmem_read(shpa + offsetof(struct Vmxnet3_DriverShared, field), b, l))
+
+#define VMXNET_FLAG_IS_SET(field, flag) (((field) & (flag)) == (flag))
+
+#define VMXNET3(pci_dev) container_of((pci_dev), VMXNET3State, parent_obj)

This still accessing parent_obj field and wrongly makes type assumptions about the argument. It should be:

#define TYPE_VMXNET3 "vmxnet3"
#define VMXNET3(obj) OBJECT_CHECK(VMXNET3State, (obj), TYPE_VMXNET3)

[...]

hw/vmxnet3.c line 2448

Quoted 2 lines
hw/vmxnet3.c new file +2 -0
+static const TypeInfo vmxnet3_info = {
+    .name          = "vmxnet3",

.name = TYPE_VMXNET3,

hw/vmxnet3.c line 2452

Quoted 4 lines
hw/vmxnet3.c new file +4 -0
+    .parent        = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(VMXNET3State),
+    .class_init    = vmxnet3_class_init,
+};

[snip]

Cf. include/qom/object.h

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#7 lore raw

Re: [Qemu-devel] [PATCH v13 5/5] VMXNET3 device implementation

Thanks, Andreas

Now I see.
We'll resubmit our patches soon.

Dmitry.

Quoted 203 lines · Andreas Färber

Am 06.03.2013 08:21, schrieb Dmitry Fleytman:

Quoted 7 lines
---
 default-configs/pci.mak |    1 +
 hw/Makefile.objs        |    1 +
 hw/pci/pci.h            |    1 +
 hw/vmxnet3.c            | 2460

+++++++++++++++++++++++++++++++++++++++++++++++

Quoted 50 lines
 hw/vmxnet3.h            |  760 +++++++++++++++
 5 files changed, 3223 insertions(+)
 create mode 100644 hw/vmxnet3.c
 create mode 100644 hw/vmxnet3.h
default-configs/pci.mak +1 -0
index ee2d18d..ce56d58 100644
@@ -13,6 +13,7 @@ CONFIG_LSI_SCSI_PCI=y
 CONFIG_MEGASAS_SCSI_PCI=y
 CONFIG_RTL8139_PCI=y
 CONFIG_E1000_PCI=y
+CONFIG_VMXNET3_PCI=y
 CONFIG_IDE_CORE=y
 CONFIG_IDE_QDEV=y
 CONFIG_IDE_PCI=y
hw/Makefile.objs +1 -0
index 14922cb..026aff6 100644
@@ -120,6 +120,7 @@ common-obj-$(CONFIG_PCNET_COMMON) += pcnet.o
 common-obj-$(CONFIG_E1000_PCI) += e1000.o
 common-obj-$(CONFIG_RTL8139_PCI) += rtl8139.o
 common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet_tx_pkt.o vmxnet_rx_pkt.o
+common-obj-$(CONFIG_VMXNET3_PCI) += vmxnet3.o
 
 common-obj-$(CONFIG_SMC91C111) += smc91c111.o
 common-obj-$(CONFIG_LAN9118) += lan9118.o
hw/pci/pci.h +1 -0
index f340fe5..3beb70b 100644
@@ -60,6 +60,7 @@
 #define PCI_DEVICE_ID_VMWARE_NET         0x0720
 #define PCI_DEVICE_ID_VMWARE_SCSI        0x0730
 #define PCI_DEVICE_ID_VMWARE_IDE         0x1729
+#define PCI_DEVICE_ID_VMWARE_VMXNET3     0x07B0
 
 /* Intel (0x8086) */
 #define PCI_DEVICE_ID_INTEL_82551IT      0x1209
hw/vmxnet3.c new file +3 -0
new file mode 100644
index 0000000..75b7181
@@ -0,0 +1,2460 @@
+/*
+ * QEMU VMWARE VMXNET3 paravirtual NIC
+ *

hw/vmxnet3.c line 13

Quoted 10 lines
hw/vmxnet3.c new file +10 -0
+ * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
+ *
+ * Developed by Daynix Computing LTD (http://www.daynix.com)
+ *
+ * Authors:
+ * Dmitry Fleytman <[email protected]>
+ * Tamir Shomer <[email protected]>
+ * Yan Vugenfirer <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or

later.

Quoted 38 lines
hw/vmxnet3.c new file +38 -0
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "hw.h"
+#include "pci/pci.h"
+#include "net/net.h"
+#include "virtio-net.h"
+#include "net/tap.h"
+#include "net/checksum.h"
+#include "sysemu/sysemu.h"
+#include "qemu-common.h"
+#include "qemu/bswap.h"
+#include "pci/msix.h"
+#include "pci/msi.h"
+
+#include "vmxnet3.h"
+#include "vmxnet_debug.h"
+#include "vmware_utils.h"
+#include "vmxnet_tx_pkt.h"
+#include "vmxnet_rx_pkt.h"
+
+#define PCI_DEVICE_ID_VMWARE_VMXNET3_REVISION 0x1
+#define VMXNET3_MSIX_BAR_SIZE 0x2000
+
+#define VMXNET3_BAR0_IDX      (0)
+#define VMXNET3_BAR1_IDX      (1)
+#define VMXNET3_MSIX_BAR_IDX  (2)
+
+#define VMXNET3_OFF_MSIX_TABLE (0x000)
+#define VMXNET3_OFF_MSIX_PBA   (0x800)
+
+/* Link speed in Mbps should be shifted by 16 */
+#define VMXNET3_LINK_SPEED      (1000 << 16)
+
+/* Link status: 1 - up, 0 - down. */
+#define VMXNET3_LINK_STATUS_UP  0x1
+

hw/vmxnet3.c

Quoted 10 lines
hw/vmxnet3.c new file +10 -0
+/* Least significant bit should be set for revision and version */
+#define VMXNET3_DEVICE_VERSION    0x1
+#define VMXNET3_DEVICE_REVISION   0x1
+
+/* Macros for rings descriptors access */
+#define VMXNET3_READ_TX_QUEUE_DESCR8(dpa, field) \
+    (vmw_shmem_ld8(dpa + offsetof(struct Vmxnet3_TxQueueDesc, field)))
+
+#define VMXNET3_WRITE_TX_QUEUE_DESCR8(dpa, field, value) \
+    (vmw_shmem_st8(dpa + offsetof(struct Vmxnet3_TxQueueDesc, field,

value)))

hw/vmxnet3.c

Quoted 6 lines
hw/vmxnet3.c new file +6 -0
+
+#define VMXNET3_READ_TX_QUEUE_DESCR32(dpa, field) \
+    (vmw_shmem_ld32(dpa + offsetof(struct Vmxnet3_TxQueueDesc, field)))
+
+#define VMXNET3_WRITE_TX_QUEUE_DESCR32(dpa, field, value) \
+    (vmw_shmem_st32(dpa + offsetof(struct Vmxnet3_TxQueueDesc, field),

value))

hw/vmxnet3.c

Quoted 6 lines
hw/vmxnet3.c new file +6 -0
+
+#define VMXNET3_READ_TX_QUEUE_DESCR64(dpa, field) \
+    (vmw_shmem_ld64(dpa + offsetof(struct Vmxnet3_TxQueueDesc, field)))
+
+#define VMXNET3_WRITE_TX_QUEUE_DESCR64(dpa, field, value) \
+    (vmw_shmem_st64(dpa + offsetof(struct Vmxnet3_TxQueueDesc, field),

value))

hw/vmxnet3.c

Quoted 9 lines
hw/vmxnet3.c new file +9 -0
+
+#define VMXNET3_READ_RX_QUEUE_DESCR64(dpa, field) \
+    (vmw_shmem_ld64(dpa + offsetof(struct Vmxnet3_RxQueueDesc, field)))
+
+#define VMXNET3_READ_RX_QUEUE_DESCR32(dpa, field) \
+    (vmw_shmem_ld32(dpa + offsetof(struct Vmxnet3_RxQueueDesc, field)))
+
+#define VMXNET3_WRITE_RX_QUEUE_DESCR64(dpa, field, value) \
+    (vmw_shmem_st64(dpa + offsetof(struct Vmxnet3_RxQueueDesc, field),

value))

hw/vmxnet3.c

Quoted 3 lines
hw/vmxnet3.c new file +3 -0
+
+#define VMXNET3_WRITE_RX_QUEUE_DESCR8(dpa, field, value) \
+    (vmw_shmem_st8(dpa + offsetof(struct Vmxnet3_RxQueueDesc, field),

value))

hw/vmxnet3.c

Quoted 4 lines
hw/vmxnet3.c new file +4 -0
+
+/* Macros for guest driver shared area access */
+#define VMXNET3_READ_DRV_SHARED64(shpa, field) \
+    (vmw_shmem_ld64(shpa + offsetof(struct Vmxnet3_DriverShared,

field)))

hw/vmxnet3.c

Quoted 3 lines
hw/vmxnet3.c new file +3 -0
+
+#define VMXNET3_READ_DRV_SHARED32(shpa, field) \
+    (vmw_shmem_ld32(shpa + offsetof(struct Vmxnet3_DriverShared,

field)))

hw/vmxnet3.c

Quoted 3 lines
hw/vmxnet3.c new file +3 -0
+
+#define VMXNET3_WRITE_DRV_SHARED32(shpa, field, val) \
+    (vmw_shmem_st32(shpa + offsetof(struct Vmxnet3_DriverShared,

field), val))

hw/vmxnet3.c

Quoted 3 lines
hw/vmxnet3.c new file +3 -0
+
+#define VMXNET3_READ_DRV_SHARED16(shpa, field) \
+    (vmw_shmem_ld16(shpa + offsetof(struct Vmxnet3_DriverShared,

field)))

hw/vmxnet3.c

Quoted 6 lines
hw/vmxnet3.c new file +6 -0
+
+#define VMXNET3_READ_DRV_SHARED8(shpa, field) \
+    (vmw_shmem_ld8(shpa + offsetof(struct Vmxnet3_DriverShared, field)))
+
+#define VMXNET3_READ_DRV_SHARED(shpa, field, b, l) \
+    (vmw_shmem_read(shpa + offsetof(struct Vmxnet3_DriverShared,

field), b, l))

hw/vmxnet3.c

Quoted 4 lines
hw/vmxnet3.c new file +4 -0
+
+#define VMXNET_FLAG_IS_SET(field, flag) (((field) & (flag)) == (flag))
+
+#define VMXNET3(pci_dev) container_of((pci_dev), VMXNET3State,

parent_obj)

This still accessing parent_obj field and wrongly makes type assumptions about the argument. It should be:

#define TYPE_VMXNET3 "vmxnet3"
#define VMXNET3(obj) OBJECT_CHECK(VMXNET3State, (obj), TYPE_VMXNET3)

[...]

hw/vmxnet3.c line 2448

Quoted 2 lines
hw/vmxnet3.c new file +2 -0
+static const TypeInfo vmxnet3_info = {
+    .name          = "vmxnet3",

.name = TYPE_VMXNET3,

hw/vmxnet3.c line 2452

Quoted 4 lines
hw/vmxnet3.c new file +4 -0
+    .parent        = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(VMXNET3State),
+    .class_init    = vmxnet3_class_init,
+};

[snip]

Cf. include/qom/object.h

Andreas

--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg