Skip to contentSkip to conversation

qdev-ify network cards

PATCH New Gerd Hoffmann 2 participants 24 messages Oct 21, 2009 – Oct 28, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/22 qdev-ify network cards

Hi,

Now the first non-RfC version of this series. Changes compared to last RfC patch:

* Added some common helper code so we have less code duplication and the actual driver changes are smaller.
* All network drivers are converted now.
* Some final cleanups which zap dead code.

With the patches applied network cards can now be created using ...

-device ne2k_isa,mac=00:11:22:33:44:55,vlan=1,irq=3,id=foo

'info qtree' shows ...

	[ ... ]
        bus: isa.0
          type ISA
          dev: ne2k_isa, id "foo"
            dev-prop: iobase = 0x300
            dev-prop: irq = 3
            dev-prop: mac = 00:11:22:33:44:55
            dev-prop: vlan = 1
            dev-prop: netdev = <null>
	[ ... ]

'info network' shows:

	[ ... ]
	VLAN 1 devices:
	  foo: model=ne2k_isa,macaddr=00:11:22:33:44:55

The nic initialization code calls qemu_new_vlan_client() with the vlan/netdev specified using the properties. Likewise the device cleanup code should call qemu_del_vlan_client (which only makes sense for hot-pluggable devices).

struct NICInfo is only involved when creating nics using the legacy path (via -net nic,...).

This patch series is also available here:
http://repo.or.cz/w/qemu/kraxel.git?a=shortlog;h=refs/heads/nic.v4

cheers,
Gerd

#1 lore raw

PATCH 1/22 net: add macaddr type.

Add new type for mac addresses.

Add function which sets the qemu default mac address if it finds the mac address uninitialized (i.e. all zeros).

---
 net.c         |   15 +++++++++++++++
 net.h         |    5 +++++
 qemu-common.h |    1 +
 3 files changed, 21 insertions(+), 0 deletions(-)
net.c +15 -0
index 4708080..3b69d3b 100644
@@ -280,6 +280,21 @@ void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6])
              macaddr[3], macaddr[4], macaddr[5]);
 }
 
+void qemu_macaddr_default_if_unset(MACAddr *macaddr)
+{
+    static int index = 0;
+    static const MACAddr zero = { .a = { 0,0,0,0,0,0 } };
+
+    if (memcmp(macaddr, &zero, sizeof(zero)) != 0)
+        return;
+    macaddr->a[0] = 0x52;
+    macaddr->a[1] = 0x54;
+    macaddr->a[2] = 0x00;
+    macaddr->a[3] = 0x12;
+    macaddr->a[4] = 0x34;
+    macaddr->a[5] = 0x56 + index++;
+}
+
 static char *assign_name(VLANClientState *vc1, const char *model)
 {
     VLANState *vlan;
net.h +5 -0
index 439de2a..605092a 100644
@@ -7,6 +7,10 @@
 #include "qemu-option.h"
 #include "net-queue.h"
 
+struct MACAddr {
+    uint8_t a[6];
+};
+
 /* VLANs support */
 
 typedef int (NetCanReceive)(VLANClientState *);
@@ -65,6 +69,7 @@ ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
 void qemu_purge_queued_packets(VLANClientState *vc);
 void qemu_flush_queued_packets(VLANClientState *vc);
 void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
+void qemu_macaddr_default_if_unset(MACAddr *macaddr);
 int qemu_show_nic_models(const char *arg, const char *const *models);
 void qemu_check_nic_model(NICInfo *nd, const char *model);
 int qemu_find_nic_model(NICInfo *nd, const char * const *models,
qemu-common.h +1 -0
index 8551862..980f362 100644
@@ -180,6 +180,7 @@ typedef struct PixelFormat PixelFormat;
 typedef struct TextConsole TextConsole;
 typedef TextConsole QEMUConsole;
 typedef struct CharDriverState CharDriverState;
+typedef struct MACAddr MACAddr;
 typedef struct VLANState VLANState;
 typedef struct VLANClientState VLANClientState;
 typedef struct QEMUFile QEMUFile;
Signature · 1 line
1.6.2.5
#2 lore raw

PATCH 2/22 qdev: mac addr property fixups

In reply to Gerd Hoffmann

Make the mac property use the newly added type for the mac address.

---
 hw/qdev-properties.c |   31 +++++++++++++++++++++----------
 hw/qdev.h            |    3 ++-
 2 files changed, 23 insertions(+), 11 deletions(-)
hw/qdev-properties.c +21 -10
index 5c627fa..1d68125 100644
@@ -1,4 +1,5 @@
 #include "sysemu.h"
+#include "net.h"
 #include "qdev.h"
 
 void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
@@ -274,7 +275,7 @@ PropertyInfo qdev_prop_ptr = {
  */
 static int parse_mac(DeviceState *dev, Property *prop, const char *str)
 {
-    uint8_t *mac = qdev_get_prop_ptr(dev, prop);
+    MACAddr *mac = qdev_get_prop_ptr(dev, prop);
     int i, pos;
     char *p;
 
@@ -283,26 +284,31 @@ static int parse_mac(DeviceState *dev, Property *prop, const char *str)
             return -1;
         if (!qemu_isxdigit(str[pos+1]))
             return -1;
-        if (i == 5 && str[pos+2] != '\0')
-            return -1;
-        if (str[pos+2] != ':' && str[pos+2] != '-')
-            return -1;
-        mac[i] = strtol(str+pos, &p, 16);
+        if (i == 5) {
+            if (str[pos+2] != '\0')
+                return -1;
+        } else {
+            if (str[pos+2] != ':' && str[pos+2] != '-')
+                return -1;
+        }
+        mac->a[i] = strtol(str+pos, &p, 16);
     }
     return 0;
 }
 
 static int print_mac(DeviceState *dev, Property *prop, char *dest, size_t len)
 {
-    uint8_t *mac = qdev_get_prop_ptr(dev, prop);
+    MACAddr *mac = qdev_get_prop_ptr(dev, prop);
+
     return snprintf(dest, len, "%02x:%02x:%02x:%02x:%02x:%02x",
-                    mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+                    mac->a[0], mac->a[1], mac->a[2],
+                    mac->a[3], mac->a[4], mac->a[5]);
 }
 
 PropertyInfo qdev_prop_macaddr = {
-    .name  = "mac-addr",
+    .name  = "macaddr",
     .type  = PROP_TYPE_MACADDR,
-    .size  = 6,
+    .size  = sizeof(MACAddr),
     .parse = parse_mac,
     .print = print_mac,
 };
@@ -454,6 +460,11 @@ void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *valu
     qdev_prop_set(dev, name, &value, PROP_TYPE_CHR);
 }
 
+void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
+{
+    qdev_prop_set(dev, name, value, PROP_TYPE_MACADDR);
+}
+
 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
 {
     qdev_prop_set(dev, name, &value, PROP_TYPE_PTR);
hw/qdev.h +2 -1
index 8cd843e..118e886 100644
@@ -230,7 +230,7 @@ extern PropertyInfo qdev_prop_pci_devfn;
 #define DEFINE_PROP_DRIVE(_n, _s, _f)             \
     DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*)
 #define DEFINE_PROP_MACADDR(_n, _s, _f)         \
-    DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, uint8_t[6])
+    DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
 
 #define DEFINE_PROP_END_OF_LIST()               \
     {}
@@ -246,6 +246,7 @@ void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
 void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
 void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
 void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value);
+void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
 /* FIXME: Remove opaque pointer properties.  */
 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
 void qdev_prop_set_defaults(DeviceState *dev, Property *props);
Signature · 1 line
1.6.2.5
#3 lore raw

PATCH 3/22 qdev: add netdev property

In reply to Gerd Hoffmann
---
 hw/qdev-properties.c |   36 ++++++++++++++++++++++++++++++++++++
 hw/qdev.h            |    4 ++++
 net.c                |    2 +-
 net.h                |    1 +
 4 files changed, 42 insertions(+), 1 deletions(-)
hw/qdev-properties.c +36 -0
index 1d68125..76925c8 100644
@@ -251,6 +251,37 @@ PropertyInfo qdev_prop_chr = {
     .print = print_chr,
 };
 
+/* --- netdev device --- */
+
+static int parse_netdev(DeviceState *dev, Property *prop, const char *str)
+{
+    VLANClientState **ptr = qdev_get_prop_ptr(dev, prop);
+
+    *ptr = qemu_find_netdev(str);
+    if (*ptr == NULL)
+        return -1;
+    return 0;
+}
+
+static int print_netdev(DeviceState *dev, Property *prop, char *dest, size_t len)
+{
+    VLANClientState **ptr = qdev_get_prop_ptr(dev, prop);
+
+    if (*ptr && (*ptr)->name) {
+        return snprintf(dest, len, "%s", (*ptr)->name);
+    } else {
+        return snprintf(dest, len, "<null>");
+    }
+}
+
+PropertyInfo qdev_prop_netdev = {
+    .name  = "netdev",
+    .type  = PROP_TYPE_NETDEV,
+    .size  = sizeof(VLANClientState*),
+    .parse = parse_netdev,
+    .print = print_netdev,
+};
+
 /* --- pointer --- */
 
 static int print_ptr(DeviceState *dev, Property *prop, char *dest, size_t len)
@@ -460,6 +491,11 @@ void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *valu
     qdev_prop_set(dev, name, &value, PROP_TYPE_CHR);
 }
 
+void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value)
+{
+    qdev_prop_set(dev, name, &value, PROP_TYPE_NETDEV);
+}
+
 void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
 {
     qdev_prop_set(dev, name, value, PROP_TYPE_MACADDR);
hw/qdev.h +4 -0
index 118e886..c0d59bc 100644
@@ -79,6 +79,7 @@ enum PropertyType {
     PROP_TYPE_MACADDR,
     PROP_TYPE_DRIVE,
     PROP_TYPE_CHR,
+    PROP_TYPE_NETDEV,
     PROP_TYPE_PTR,
 };
 
@@ -227,6 +228,8 @@ extern PropertyInfo qdev_prop_pci_devfn;
     DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
 #define DEFINE_PROP_CHR(_n, _s, _f)             \
     DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
+#define DEFINE_PROP_NETDEV(_n, _s, _f)             \
+    DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*)
 #define DEFINE_PROP_DRIVE(_n, _s, _f)             \
     DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*)
 #define DEFINE_PROP_MACADDR(_n, _s, _f)         \
@@ -245,6 +248,7 @@ void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
 void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
 void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
 void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
+void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value);
 void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value);
 void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
 /* FIXME: Remove opaque pointer properties.  */
net.c +1 -1
index 3b69d3b..75a01d2 100644
@@ -2363,7 +2363,7 @@ VLANState *qemu_find_vlan(int id, int allocate)
     return vlan;
 }
 
-static VLANClientState *qemu_find_netdev(const char *id)
+VLANClientState *qemu_find_netdev(const char *id)
 {
     VLANClientState *vc;
 
net.h +1 -0
index 605092a..6a24f55 100644
@@ -47,6 +47,7 @@ struct VLANState {
 };
 
 VLANState *qemu_find_vlan(int id, int allocate);
+VLANClientState *qemu_find_netdev(const char *id);
 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
                                       VLANClientState *peer,
                                       const char *model,
Signature · 1 line
1.6.2.5
#4 lore raw

PATCH 4/22 qdev: add vlan property

In reply to Gerd Hoffmann
---
 hw/qdev-properties.c |   39 +++++++++++++++++++++++++++++++++++++++
 hw/qdev.h            |    6 ++++++
 2 files changed, 45 insertions(+), 0 deletions(-)
hw/qdev-properties.c +39 -0
index 76925c8..c9843a2 100644
@@ -282,6 +282,40 @@ PropertyInfo qdev_prop_netdev = {
     .print = print_netdev,
 };
 
+/* --- vlan --- */
+
+static int parse_vlan(DeviceState *dev, Property *prop, const char *str)
+{
+    VLANState **ptr = qdev_get_prop_ptr(dev, prop);
+    int id;
+
+    if (sscanf(str, "%d", &id) != 1)
+        return -1;
+    *ptr = qemu_find_vlan(id, 1);
+    if (*ptr == NULL)
+        return -1;
+    return 0;
+}
+
+static int print_vlan(DeviceState *dev, Property *prop, char *dest, size_t len)
+{
+    VLANState **ptr = qdev_get_prop_ptr(dev, prop);
+
+    if (*ptr) {
+        return snprintf(dest, len, "%d", (*ptr)->id);
+    } else {
+        return snprintf(dest, len, "<null>");
+    }
+}
+
+PropertyInfo qdev_prop_vlan = {
+    .name  = "vlan",
+    .type  = PROP_TYPE_VLAN,
+    .size  = sizeof(VLANClientState*),
+    .parse = parse_vlan,
+    .print = print_vlan,
+};
+
 /* --- pointer --- */
 
 static int print_ptr(DeviceState *dev, Property *prop, char *dest, size_t len)
@@ -496,6 +530,11 @@ void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *v
     qdev_prop_set(dev, name, &value, PROP_TYPE_NETDEV);
 }
 
+void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value)
+{
+    qdev_prop_set(dev, name, &value, PROP_TYPE_VLAN);
+}
+
 void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
 {
     qdev_prop_set(dev, name, value, PROP_TYPE_MACADDR);
hw/qdev.h +6 -0
index c0d59bc..c678ab2 100644
@@ -80,6 +80,7 @@ enum PropertyType {
     PROP_TYPE_DRIVE,
     PROP_TYPE_CHR,
     PROP_TYPE_NETDEV,
+    PROP_TYPE_VLAN,
     PROP_TYPE_PTR,
 };
 
@@ -191,6 +192,8 @@ extern PropertyInfo qdev_prop_chr;
 extern PropertyInfo qdev_prop_ptr;
 extern PropertyInfo qdev_prop_macaddr;
 extern PropertyInfo qdev_prop_drive;
+extern PropertyInfo qdev_prop_netdev;
+extern PropertyInfo qdev_prop_vlan;
 extern PropertyInfo qdev_prop_pci_devfn;
 
 #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
@@ -230,6 +233,8 @@ extern PropertyInfo qdev_prop_pci_devfn;
     DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
 #define DEFINE_PROP_NETDEV(_n, _s, _f)             \
     DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*)
+#define DEFINE_PROP_VLAN(_n, _s, _f)             \
+    DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANState*)
 #define DEFINE_PROP_DRIVE(_n, _s, _f)             \
     DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*)
 #define DEFINE_PROP_MACADDR(_n, _s, _f)         \
@@ -249,6 +254,7 @@ void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
 void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
 void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
 void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value);
+void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value);
 void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value);
 void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
 /* FIXME: Remove opaque pointer properties.  */
Signature · 1 line
1.6.2.5
#5 lore raw

PATCH 5/22 qdev/net: common nic property bits

In reply to Gerd Hoffmann

Add a new type for properties common to all nics.
Add helper functions and macros to deal with it.

---
 hw/qdev.c |    9 +++++++++
 net.h     |   14 ++++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)
hw/qdev.c +9 -0
index 20f931c..b32dbfc 100644
@@ -383,6 +383,15 @@ void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr)
     memcpy(macaddr, dev->nd->macaddr, 6);
 }
 
+void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
+{
+    qdev_prop_set_macaddr(dev, "mac", nd->macaddr);
+    if (nd->vlan)
+        qdev_prop_set_vlan(dev, "vlan", nd->vlan);
+    if (nd->netdev)
+        qdev_prop_set_netdev(dev, "netdev", nd->netdev);
+}
+
 static int next_block_unit[IF_COUNT];
 
 /* Get a block device.  This should only be used for single-drive devices
net.h +14 -0
index 6a24f55..f2d10f0 100644
@@ -11,6 +11,19 @@ struct MACAddr {
     uint8_t a[6];
 };
 
+/* qdev nic properties */
+
+typedef struct NICConf {
+    MACAddr macaddr;
+    VLANState *vlan;
+    VLANClientState *peer;
+} NICConf;
+
+#define DEFINE_NIC_PROPERTIES(_state, _conf)                            \
+    DEFINE_PROP_MACADDR("mac",   _state, _conf.macaddr),                \
+    DEFINE_PROP_VLAN("vlan",     _state, _conf.vlan),                   \
+    DEFINE_PROP_NETDEV("netdev", _state, _conf.peer)
+
 /* VLANs support */
 
 typedef int (NetCanReceive)(VLANClientState *);
@@ -158,5 +171,6 @@ VLANClientState *qdev_get_vlan_client(DeviceState *dev,
                                       NetReceiveIOV *receive_iov,
                                       NetCleanup *cleanup,
                                       void *opaque);
+void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd);
 
 #endif
Signature · 1 line
1.6.2.5
#6 lore raw

PATCH 6/22 ne2k_isa: use qdev properties for configuration.

In reply to Gerd Hoffmann
---
 hw/ne2000-isa.c |   17 +++++++----------
 hw/ne2000.c     |    6 +++---
 hw/ne2000.h     |    2 +-
 3 files changed, 11 insertions(+), 14 deletions(-)
hw/ne2000-isa.c +7 -10
index e346731..1da0d54 100644
@@ -38,13 +38,8 @@ typedef struct ISANE2000State {
 static void isa_ne2000_cleanup(VLANClientState *vc)
 {
     NE2000State *s = vc->opaque;
-    ISANE2000State *isa = container_of(s, ISANE2000State, ne2000);
 
-    unregister_savevm("ne2000", s);
-
-    isa_unassign_ioport(isa->iobase, 16);
-    isa_unassign_ioport(isa->iobase + 0x10, 2);
-    isa_unassign_ioport(isa->iobase + 0x1f, 1);
+    s->vc = NULL;
 }
 
 static int isa_ne2000_initfn(ISADevice *dev)
@@ -65,13 +60,14 @@ static int isa_ne2000_initfn(ISADevice *dev)
 
     isa_init_irq(dev, &s->irq, isa->isairq);
 
-    qdev_get_macaddr(&dev->qdev, s->macaddr);
+    qemu_macaddr_default_if_unset(&s->c.macaddr);
     ne2000_reset(s);
 
-    s->vc = qdev_get_vlan_client(&dev->qdev,
+    s->vc = qemu_new_vlan_client(s->c.vlan, s->c.peer,
+                                 dev->qdev.info->name, dev->qdev.id,
                                  ne2000_can_receive, ne2000_receive, NULL,
                                  isa_ne2000_cleanup, s);
-    qemu_format_nic_info_str(s->vc, s->macaddr);
+    qemu_format_nic_info_str(s->vc, s->c.macaddr.a);
 
     register_savevm("ne2000", -1, 2, ne2000_save, ne2000_load, s);
     return 0;
@@ -84,9 +80,9 @@ void isa_ne2000_init(int base, int irq, NICInfo *nd)
     qemu_check_nic_model(nd, "ne2k_isa");
 
     dev = isa_create("ne2k_isa");
-    dev->qdev.nd = nd; /* hack alert */
     qdev_prop_set_uint32(&dev->qdev, "iobase", base);
     qdev_prop_set_uint32(&dev->qdev, "irq",    irq);
+    qdev_set_nic_properties(&dev->qdev, nd);
     qdev_init_nofail(&dev->qdev);
 }
 
@@ -97,6 +93,7 @@ static ISADeviceInfo ne2000_isa_info = {
     .qdev.props = (Property[]) {
         DEFINE_PROP_HEX32("iobase", ISANE2000State, iobase, 0x300),
         DEFINE_PROP_UINT32("irq",   ISANE2000State, isairq, 9),
+        DEFINE_NIC_PROPERTIES(ISANE2000State, ne2000.c),
         DEFINE_PROP_END_OF_LIST(),
     },
 };
hw/ne2000.c +3 -3
index 87f1e59..7ce56ff 100644
@@ -126,7 +126,7 @@ void ne2000_reset(NE2000State *s)
     int i;
 
     s->isr = ENISR_RESET;
-    memcpy(s->mem, s->macaddr, 6);
+    memcpy(s->mem, &s->c.macaddr, 6);
     s->mem[14] = 0x57;
     s->mem[15] = 0x57;
 
@@ -758,13 +758,13 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
                            PCI_ADDRESS_SPACE_IO, ne2000_map);
     s = &d->ne2000;
     s->irq = d->dev.irq[0];
-    qdev_get_macaddr(&d->dev.qdev, s->macaddr);
+    qdev_get_macaddr(&d->dev.qdev, s->c.macaddr.a);
     ne2000_reset(s);
     s->vc = qdev_get_vlan_client(&d->dev.qdev,
                                  ne2000_can_receive, ne2000_receive, NULL,
                                  ne2000_cleanup, s);
 
-    qemu_format_nic_info_str(s->vc, s->macaddr);
+    qemu_format_nic_info_str(s->vc, s->c.macaddr.a);
 
     register_savevm("ne2000", -1, 3, pci_ne2000_save, pci_ne2000_load, d);
     return 0;
hw/ne2000.h +1 -1
index 92a2ddb..7842246 100644
@@ -23,7 +23,7 @@ typedef struct NE2000State {
     uint8_t mult[8]; /* multicast mask array */
     qemu_irq irq;
     VLANClientState *vc;
-    uint8_t macaddr[6];
+    NICConf c;
     uint8_t mem[NE2000_MEM_SIZE];
 } NE2000State;
 
Signature · 1 line
1.6.2.5
#7 lore raw

PATCH 7/22 qdev: add qdev_prop_exists()

In reply to Gerd Hoffmann

Function test whenever a driver has a specific property.

---
 hw/qdev-properties.c |    5 +++++
 hw/qdev.h            |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)
hw/qdev-properties.c +5 -0
index c9843a2..370f356 100644
@@ -452,6 +452,11 @@ static Property *qdev_prop_find(DeviceState *dev, const char *name)
     return NULL;
 }
 
+int qdev_prop_exists(DeviceState *dev, const char *name)
+{
+    return qdev_prop_find(dev, name) ? true : false;
+}
+
 int qdev_prop_parse(DeviceState *dev, const char *name, const char *value)
 {
     Property *prop;
hw/qdev.h +1 -0
index c678ab2..5271a3c 100644
@@ -245,6 +245,7 @@ extern PropertyInfo qdev_prop_pci_devfn;
 
 /* Set properties between creation and init.  */
 void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
+int qdev_prop_exists(DeviceState *dev, const char *name);
 int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
 void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type);
 void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
Signature · 1 line
1.6.2.5
#8 lore raw

PATCH 8/22 prepare pci nic init path for qdev property configuration.

In reply to Gerd Hoffmann

Initialization path will work with both converted and not-converted drivers, so we can convert drivers one by one.

---
 hw/pci.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
hw/pci.c +8 -2
index abf07ca..fe2c4bd 100644
@@ -859,10 +859,16 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
     dev = &pci_dev->qdev;
     if (nd->name)
         dev->id = qemu_strdup(nd->name);
-    dev->nd = nd;
+    if (qdev_prop_exists(dev, "mac")) {
+        /* qdev-ified */
+        qdev_set_nic_properties(dev, nd);
+    } else {
+        /* legacy */
+        dev->nd = nd;
+        nd->private = dev;
+    }
     if (qdev_init(dev) < 0)
         return NULL;
-    nd->private = dev;
     return pci_dev;
 }
 
Signature · 1 line
1.6.2.5
#9 lore raw

PATCH 9/22 ne2k_pci: use qdev properties for configuration.

In reply to Gerd Hoffmann
---
 hw/ne2000.c |   39 ++++++++++++++++++++++++++++++++-------
 1 files changed, 32 insertions(+), 7 deletions(-)
hw/ne2000.c +32 -7
index 7ce56ff..41893b3 100644
@@ -25,6 +25,7 @@
 #include "pci.h"
 #include "net.h"
 #include "ne2000.h"
+#include "loader.h"
 
 /* debug NE2000 card */
 //#define DEBUG_NE2000
@@ -738,7 +739,7 @@ static void ne2000_cleanup(VLANClientState *vc)
 {
     NE2000State *s = vc->opaque;
 
-    unregister_savevm("ne2000", s);
+    s->vc = NULL;
 }
 
 static int pci_ne2000_init(PCIDevice *pci_dev)
@@ -758,22 +759,46 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
                            PCI_ADDRESS_SPACE_IO, ne2000_map);
     s = &d->ne2000;
     s->irq = d->dev.irq[0];
-    qdev_get_macaddr(&d->dev.qdev, s->c.macaddr.a);
+
+    qemu_macaddr_default_if_unset(&s->c.macaddr);
     ne2000_reset(s);
-    s->vc = qdev_get_vlan_client(&d->dev.qdev,
+    s->vc = qemu_new_vlan_client(s->c.vlan, s->c.peer,
+                                 pci_dev->qdev.info->name, pci_dev->qdev.id,
                                  ne2000_can_receive, ne2000_receive, NULL,
                                  ne2000_cleanup, s);
-
     qemu_format_nic_info_str(s->vc, s->c.macaddr.a);
 
+    if (!pci_dev->qdev.hotplugged) {
+        static int loaded = 0;
+        if (!loaded) {
+            rom_add_option("pxe-ne2k_pci.bin");
+            loaded = 1;
+        }
+    }
+
     register_savevm("ne2000", -1, 3, pci_ne2000_save, pci_ne2000_load, d);
     return 0;
 }
 
+static int pci_ne2000_exit(PCIDevice *pci_dev)
+{
+    PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
+    NE2000State *s = &d->ne2000;
+
+    unregister_savevm("ne2000", s);
+    qemu_del_vlan_client(s->vc);
+    return 0;
+}
+
 static PCIDeviceInfo ne2000_info = {
-    .qdev.name = "ne2k_pci",
-    .qdev.size = sizeof(PCINE2000State),
-    .init      = pci_ne2000_init,
+    .qdev.name  = "ne2k_pci",
+    .qdev.size  = sizeof(PCINE2000State),
+    .init       = pci_ne2000_init,
+    .exit       = pci_ne2000_exit,
+    .qdev.props = (Property[]) {
+        DEFINE_NIC_PROPERTIES(PCINE2000State, ne2000.c),
+        DEFINE_PROP_END_OF_LIST(),
+    }
 };
 
 static void ne2000_register_devices(void)
Signature · 1 line
1.6.2.5
#10 lore raw

PATCH 10/22 e1000: use qdev properties for configuration.

In reply to Gerd Hoffmann
---
 hw/e1000.c |   46 ++++++++++++++++++++++++++++++++++++----------
 1 files changed, 36 insertions(+), 10 deletions(-)
hw/e1000.c +36 -10
index f123bda..301997b 100644
@@ -25,6 +25,7 @@
 #include "hw.h"
 #include "pci.h"
 #include "net.h"
+#include "loader.h"
 
 #include "e1000_hw.h"
 
@@ -74,6 +75,7 @@ enum {
 typedef struct E1000State_st {
     PCIDevice dev;
     VLANClientState *vc;
+    NICConf conf;
     int mmio_index;
 
     uint32_t mac_reg[0x8000];
@@ -1056,7 +1058,7 @@ e1000_cleanup(VLANClientState *vc)
 {
     E1000State *d = vc->opaque;
 
-    unregister_savevm("e1000", d);
+    d->vc = NULL;
 }
 
 static int
@@ -1065,7 +1067,8 @@ pci_e1000_uninit(PCIDevice *dev)
     E1000State *d = DO_UPCAST(E1000State, dev, dev);
 
     cpu_unregister_io_memory(d->mmio_index);
-
+    qemu_del_vlan_client(d->vc);
+    unregister_savevm("e1000", d);
     return 0;
 }
 
@@ -1088,7 +1091,7 @@ static int pci_e1000_init(PCIDevice *pci_dev)
     uint16_t checksum = 0;
     static const char info_str[] = "e1000";
     int i;
-    uint8_t macaddr[6];
+    uint8_t *macaddr;
 
     pci_conf = d->dev.config;
 
@@ -1113,7 +1116,8 @@ static int pci_e1000_init(PCIDevice *pci_dev)
 
     memmove(d->eeprom_data, e1000_eeprom_template,
         sizeof e1000_eeprom_template);
-    qdev_get_macaddr(&d->dev.qdev, macaddr);
+    qemu_macaddr_default_if_unset(&d->conf.macaddr);
+    macaddr = d->conf.macaddr.a;
     for (i = 0; i < 3; i++)
         d->eeprom_data[i] = (macaddr[2*i+1]<<8) | macaddr[2*i];
     for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
@@ -1121,7 +1125,8 @@ static int pci_e1000_init(PCIDevice *pci_dev)
     checksum = (uint16_t) EEPROM_SUM - checksum;
     d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum;
 
-    d->vc = qdev_get_vlan_client(&d->dev.qdev,
+    d->vc = qemu_new_vlan_client(d->conf.vlan, d->conf.peer,
+                                 d->dev.qdev.info->name, d->dev.qdev.id,
                                  e1000_can_receive, e1000_receive,
                                  NULL, e1000_cleanup, d);
     d->vc->link_status_changed = e1000_set_link_status;
@@ -1129,16 +1134,37 @@ static int pci_e1000_init(PCIDevice *pci_dev)
     qemu_format_nic_info_str(d->vc, macaddr);
 
     register_savevm(info_str, -1, 2, nic_save, nic_load, d);
-    qemu_register_reset(e1000_reset, d);
     e1000_reset(d);
+
+#if 0 /* rom bev support is broken -> can't load unconditionally */
+    if (!pci_dev->qdev.hotplugged) {
+        static int loaded = 0;
+        if (!loaded) {
+            rom_add_option("pxe-e1000.bin");
+            loaded = 1;
+        }
+    }
+#endif
     return 0;
 }
 
+static void qdev_e1000_reset(DeviceState *dev)
+{
+    E1000State *d = DO_UPCAST(E1000State, dev.qdev, dev);
+    e1000_reset(d);
+}
+
 static PCIDeviceInfo e1000_info = {
-    .qdev.name = "e1000",
-    .qdev.size = sizeof(E1000State),
-    .init      = pci_e1000_init,
-    .exit      = pci_e1000_uninit,
+    .qdev.name  = "e1000",
+    .qdev.desc  = "Intel Gigabit Ethernet",
+    .qdev.size  = sizeof(E1000State),
+    .qdev.reset = qdev_e1000_reset,
+    .init       = pci_e1000_init,
+    .exit       = pci_e1000_uninit,
+    .qdev.props = (Property[]) {
+        DEFINE_NIC_PROPERTIES(E1000State, conf),
+        DEFINE_PROP_END_OF_LIST(),
+    }
 };
 
 static void e1000_register_devices(void)
Signature · 1 line
1.6.2.5
#11 lore raw

PATCH 11/22 pcnet: use qdev properties for configuration.

In reply to Gerd Hoffmann
---
 hw/pcnet.c |   64 +++++++++++++++++++++++++++++++++++++++++++++---------------
 hw/sun4m.c |    2 +-
 2 files changed, 49 insertions(+), 17 deletions(-)
hw/pcnet.c +48 -16
index fecbff7..45ca6f3 100644
@@ -38,6 +38,7 @@
 #include "sysbus.h"
 #include "pci.h"
 #include "net.h"
+#include "loader.h"
 #include "qemu-timer.h"
 #include "qemu_socket.h"
 
@@ -61,7 +62,7 @@ typedef struct PCNetState_st PCNetState;
 
 struct PCNetState_st {
     VLANClientState *vc;
-    uint8_t macaddr[6];
+    NICConf conf;
     QEMUTimer *poll_timer;
     int rap, isr, lnkst;
     uint32_t rdra, tdra;
@@ -1601,7 +1602,7 @@ static void pcnet_h_reset(void *opaque)
 
     /* Initialize the PROM */
 
-    memcpy(s->prom, s->macaddr, 6);
+    memcpy(s->prom, s->conf.macaddr.a, 6);
     s->prom[12] = s->prom[13] = 0x00;
     s->prom[14] = s->prom[15] = 0x57;
 
@@ -1953,22 +1954,20 @@ static int pci_pcnet_load(QEMUFile *f, void *opaque, int version_id)
 
 static void pcnet_common_cleanup(PCNetState *d)
 {
-    unregister_savevm("pcnet", d);
-
-    qemu_del_timer(d->poll_timer);
-    qemu_free_timer(d->poll_timer);
+    d->vc = NULL;
 }
 
 static int pcnet_common_init(DeviceState *dev, PCNetState *s,
-                              NetCleanup *cleanup)
+                             NetCleanup *cleanup)
 {
     s->poll_timer = qemu_new_timer(vm_clock, pcnet_poll_timer, s);
 
-    qdev_get_macaddr(dev, s->macaddr);
-    s->vc = qdev_get_vlan_client(dev,
+    qemu_macaddr_default_if_unset(&s->conf.macaddr);
+    s->vc = qemu_new_vlan_client(s->conf.vlan, s->conf.peer,
+                                 dev->info->name, dev->id,
                                  pcnet_can_receive, pcnet_receive, NULL,
                                  cleanup, s);
-    qemu_register_reset(pcnet_h_reset, s);
+    qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
     pcnet_h_reset(s);
     return 0;
 }
@@ -2023,7 +2022,10 @@ static int pci_pcnet_uninit(PCIDevice *dev)
     PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, dev);
 
     cpu_unregister_io_memory(d->state.mmio_index);
-
+    unregister_savevm("pcnet", d);
+    qemu_del_timer(d->state.poll_timer);
+    qemu_free_timer(d->state.poll_timer);
+    qemu_del_vlan_client(d->state.vc);
     return 0;
 }
 
@@ -2071,9 +2073,25 @@ static int pci_pcnet_init(PCIDevice *pci_dev)
     s->phys_mem_write = pci_physical_memory_write;
 
     register_savevm("pcnet", -1, 3, pci_pcnet_save, pci_pcnet_load, d);
+
+    if (!pci_dev->qdev.hotplugged) {
+        static int loaded = 0;
+        if (!loaded) {
+            rom_add_option("pxe-pcnet.bin");
+            loaded = 1;
+        }
+    }
+
     return pcnet_common_init(&pci_dev->qdev, s, pci_pcnet_cleanup);
 }
 
+static void pci_reset(DeviceState *dev)
+{
+    PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev.qdev, dev);
+
+    pcnet_h_reset(&d->state);
+}
+
 /* SPARC32 interface */
 
 #if defined (TARGET_SPARC) && !defined(TARGET_SPARC64) // Avoid compile failure
@@ -2151,12 +2169,21 @@ static int lance_init(SysBusDevice *dev)
     return pcnet_common_init(&dev->qdev, s, lance_cleanup);
 }
 
+static void lance_reset(DeviceState *dev)
+{
+    SysBusPCNetState *d = DO_UPCAST(SysBusPCNetState, busdev.qdev, dev);
+
+    pcnet_h_reset(&d->state);
+}
+
 static SysBusDeviceInfo lance_info = {
-    .init = lance_init,
+    .init       = lance_init,
     .qdev.name  = "lance",
     .qdev.size  = sizeof(SysBusPCNetState),
+    .qdev.reset = lance_reset,
     .qdev.props = (Property[]) {
         DEFINE_PROP_PTR("dma", SysBusPCNetState, state.dma_opaque),
+        DEFINE_NIC_PROPERTIES(SysBusPCNetState, state.conf),
         DEFINE_PROP_END_OF_LIST(),
     }
 };
@@ -2164,10 +2191,15 @@ static SysBusDeviceInfo lance_info = {
 #endif /* TARGET_SPARC */
 
 static PCIDeviceInfo pcnet_info = {
-    .qdev.name = "pcnet",
-    .qdev.size = sizeof(PCIPCNetState),
-    .init      = pci_pcnet_init,
-    .exit      = pci_pcnet_uninit,
+    .qdev.name  = "pcnet",
+    .qdev.size  = sizeof(PCIPCNetState),
+    .qdev.reset = pci_reset,
+    .init       = pci_pcnet_init,
+    .exit       = pci_pcnet_uninit,
+    .qdev.props = (Property[]) {
+        DEFINE_NIC_PROPERTIES(PCIPCNetState, state.conf),
+        DEFINE_PROP_END_OF_LIST(),
+    }
 };
 
 static void pcnet_register_devices(void)
hw/sun4m.c +1 -1
index 21f609c..424cf6d 100644
@@ -396,7 +396,7 @@ static void lance_init(NICInfo *nd, target_phys_addr_t leaddr,
     qemu_check_nic_model(&nd_table[0], "lance");
 
     dev = qdev_create(NULL, "lance");
-    dev->nd = nd;
+    qdev_set_nic_properties(dev, nd);
     qdev_prop_set_ptr(dev, "dma", dma_opaque);
     qdev_init_nofail(dev);
     s = sysbus_from_qdev(dev);
Signature · 1 line
1.6.2.5
#12 lore raw

PATCH 12/22 pcnet: split away lance.c (sparc32 code).

In reply to Gerd Hoffmann
---
 Makefile.target |    2 +-
 hw/lance.c      |  146 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/pcnet.c      |  154 +++---------------------------------------------------
 hw/pcnet.h      |   39 ++++++++++++++
 4 files changed, 195 insertions(+), 146 deletions(-)
 create mode 100644 hw/lance.c
 create mode 100644 hw/pcnet.h
Makefile.target +1 -1
index 8d146c5..1d6bad8 100644
@@ -260,7 +260,7 @@ obj-sparc-y += vga.o vga-pci.o
 obj-sparc-y += fdc.o mc146818rtc.o serial.o
 obj-sparc-y += cirrus_vga.o parallel.o
 else
-obj-sparc-y = sun4m.o tcx.o iommu.o slavio_intctl.o
+obj-sparc-y = sun4m.o lance.o tcx.o iommu.o slavio_intctl.o
 obj-sparc-y += slavio_timer.o slavio_misc.o fdc.o sparc32_dma.o
 obj-sparc-y += cs4231.o eccmemctl.o sbi.o sun4c_intctl.o
 endif
hw/lance.c new file +146 -0

146 lines not on this page · raw message

hw/pcnet.c +9 -145

229 lines not on this page · raw message

hw/pcnet.h new file +39 -0
new file mode 100644
index 0000000..a94b605
@@ -0,0 +1,39 @@
+#define PCNET_IOPORT_SIZE       0x20
+#define PCNET_PNPMMIO_SIZE      0x20
+
+#define PCNET_LOOPTEST_CRC	1
+#define PCNET_LOOPTEST_NOCRC	2
+
+
+typedef struct PCNetState_st PCNetState;
+
+struct PCNetState_st {
+    VLANClientState *vc;
+    NICConf conf;
+    QEMUTimer *poll_timer;
+    int rap, isr, lnkst;
+    uint32_t rdra, tdra;
+    uint8_t prom[16];
+    uint16_t csr[128];
+    uint16_t bcr[32];
+    uint64_t timer;
+    int mmio_index, xmit_pos;
+    uint8_t buffer[4096];
+    int tx_busy;
+    qemu_irq irq;
+    void (*phys_mem_read)(void *dma_opaque, target_phys_addr_t addr,
+                         uint8_t *buf, int len, int do_bswap);
+    void (*phys_mem_write)(void *dma_opaque, target_phys_addr_t addr,
+                          uint8_t *buf, int len, int do_bswap);
+    void *dma_opaque;
+    int looptest;
+};
+
+void pcnet_h_reset(void *opaque);
+void pcnet_ioport_writew(void *opaque, uint32_t addr, uint32_t val);
+uint32_t pcnet_ioport_readw(void *opaque, uint32_t addr);
+void pcnet_common_cleanup(PCNetState *d);
+int pcnet_common_init(DeviceState *dev, PCNetState *s,
+                      NetCleanup *cleanup);
+void pcnet_save(QEMUFile *f, void *opaque);
+int pcnet_load(QEMUFile *f, void *opaque, int version_id);
Signature · 1 line
1.6.2.5
#13 lore raw

PATCH 13/22 rtl8139: use qdev properties for configuration.

In reply to Gerd Hoffmann
---
 hw/rtl8139.c |   54 +++++++++++++++++++++++++++++++++---------------------
 1 files changed, 33 insertions(+), 21 deletions(-)
hw/rtl8139.c +33 -21
index 10daeb2..de60246 100644
@@ -47,6 +47,7 @@
 #include "pci.h"
 #include "qemu-timer.h"
 #include "net.h"
+#include "loader.h"
 
 /* debug RTL8139 card */
 //#define DEBUG_RTL8139 1
@@ -465,7 +466,7 @@ typedef struct RTL8139State {
     uint8_t  TxThresh;
 
     VLANClientState *vc;
-    uint8_t macaddr[6];
+    NICConf conf;
     int rtl8139_mmio_io_addr;
 
     /* C ring mode */
@@ -1179,7 +1180,7 @@ static void rtl8139_reset(DeviceState *d)
     int i;
 
     /* restore MAC address */
-    memcpy(s->phys, s->macaddr, 6);
+    memcpy(s->phys, s->conf.macaddr.a, 6);
 
     /* reset interrupt mask */
     s->IntrStatus = 0;
@@ -1195,9 +1196,9 @@ static void rtl8139_reset(DeviceState *d)
     s->eeprom.contents[2] = PCI_DEVICE_ID_REALTEK_8139;
 #endif
 
-    s->eeprom.contents[7] = s->macaddr[0] | s->macaddr[1] << 8;
-    s->eeprom.contents[8] = s->macaddr[2] | s->macaddr[3] << 8;
-    s->eeprom.contents[9] = s->macaddr[4] | s->macaddr[5] << 8;
+    s->eeprom.contents[7] = s->conf.macaddr.a[0] | s->conf.macaddr.a[1] << 8;
+    s->eeprom.contents[8] = s->conf.macaddr.a[2] | s->conf.macaddr.a[3] << 8;
+    s->eeprom.contents[9] = s->conf.macaddr.a[4] | s->conf.macaddr.a[5] << 8;
 
     /* mark all status registers as owned by host */
     for (i = 0; i < 4; ++i)
@@ -3171,7 +3172,7 @@ static void rtl8139_save(QEMUFile* f,void* opaque)
 
     i = 0;
     qemu_put_be32s(f, &i); /* unused.  */
-    qemu_put_buffer(f, s->macaddr, 6);
+    qemu_put_buffer(f, s->conf.macaddr.a, 6);
     qemu_put_be32(f, s->rtl8139_mmio_io_addr);
 
     qemu_put_be32s(f, &s->currTxDesc);
@@ -3268,7 +3269,7 @@ static int rtl8139_load(QEMUFile* f,void* opaque,int version_id)
     qemu_get_8s(f, &s->TxThresh);
 
     qemu_get_be32s(f, &i); /* unused.  */
-    qemu_get_buffer(f, s->macaddr, 6);
+    qemu_get_buffer(f, s->conf.macaddr.a, 6);
     s->rtl8139_mmio_io_addr=qemu_get_be32(f);
 
     qemu_get_be32s(f, &s->currTxDesc);
@@ -3416,25 +3417,24 @@ static void rtl8139_cleanup(VLANClientState *vc)
 {
     RTL8139State *s = vc->opaque;
 
+    s->vc = NULL;
+}
+
+static int pci_rtl8139_uninit(PCIDevice *dev)
+{
+    RTL8139State *s = DO_UPCAST(RTL8139State, dev, dev);
+
+    cpu_unregister_io_memory(s->rtl8139_mmio_io_addr);
     if (s->cplus_txbuffer) {
         qemu_free(s->cplus_txbuffer);
         s->cplus_txbuffer = NULL;
     }
-
 #ifdef RTL8139_ONBOARD_TIMER
     qemu_del_timer(s->timer);
     qemu_free_timer(s->timer);
 #endif
-
     unregister_savevm("rtl8139", s);
-}
-
-static int pci_rtl8139_uninit(PCIDevice *dev)
-{
-    RTL8139State *s = DO_UPCAST(RTL8139State, dev, dev);
-
-    cpu_unregister_io_memory(s->rtl8139_mmio_io_addr);
-
+    qemu_del_vlan_client(s->vc);
     return 0;
 }
 
@@ -3463,13 +3463,13 @@ static int pci_rtl8139_init(PCIDevice *dev)
     pci_register_bar(&s->dev, 1, 0x100,
                            PCI_ADDRESS_SPACE_MEM, rtl8139_mmio_map);
 
-    qdev_get_macaddr(&dev->qdev, s->macaddr);
+    qemu_macaddr_default_if_unset(&s->conf.macaddr);
     rtl8139_reset(&s->dev.qdev);
-    s->vc = qdev_get_vlan_client(&dev->qdev,
+    s->vc = qemu_new_vlan_client(s->conf.vlan, s->conf.peer,
+                                 dev->qdev.info->name, dev->qdev.id,
                                  rtl8139_can_receive, rtl8139_receive, NULL,
                                  rtl8139_cleanup, s);
-
-    qemu_format_nic_info_str(s->vc, s->macaddr);
+    qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
 
     s->cplus_txbuffer = NULL;
     s->cplus_txbuffer_len = 0;
@@ -3483,6 +3483,14 @@ static int pci_rtl8139_init(PCIDevice *dev)
     qemu_mod_timer(s->timer,
         rtl8139_get_next_tctr_time(s,qemu_get_clock(vm_clock)));
 #endif /* RTL8139_ONBOARD_TIMER */
+
+    if (!dev->qdev.hotplugged) {
+        static int loaded = 0;
+        if (!loaded) {
+            rom_add_option("pxe-rtl8139.bin");
+            loaded = 1;
+        }
+    }
     return 0;
 }
 
@@ -3492,6 +3500,10 @@ static PCIDeviceInfo rtl8139_info = {
     .qdev.reset = rtl8139_reset,
     .init       = pci_rtl8139_init,
     .exit       = pci_rtl8139_uninit,
+    .qdev.props = (Property[]) {
+        DEFINE_NIC_PROPERTIES(RTL8139State, conf),
+        DEFINE_PROP_END_OF_LIST(),
+    }
 };
 
 static void rtl8139_register_devices(void)
Signature · 1 line
1.6.2.5
#14 lore raw

PATCH 14/22 virtio: use qdev properties for configuration.

In reply to Gerd Hoffmann
---
 hw/qdev.c          |    4 ++++
 hw/syborg.c        |    4 ++--
 hw/syborg_virtio.c |   16 +++++++++++++---
 hw/virtio-net.c    |   43 ++++++++++++++++++++++++-------------------
 hw/virtio-pci.c    |   33 +++++++++++++++++++++++----------
 hw/virtio.h        |    5 ++++-
 6 files changed, 70 insertions(+), 35 deletions(-)
hw/qdev.c +4 -0
index b32dbfc..e81d662 100644
@@ -390,6 +390,10 @@ void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
         qdev_prop_set_vlan(dev, "vlan", nd->vlan);
     if (nd->netdev)
         qdev_prop_set_netdev(dev, "netdev", nd->netdev);
+    if (nd->nvectors != NIC_NVECTORS_UNSPECIFIED &&
+        qdev_prop_exists(dev, "vectors")) {
+        qdev_prop_set_uint32(dev, "vectors", nd->nvectors);
+    }
 }
 
 static int next_block_unit[IF_COUNT];
hw/syborg.c +2 -2
index 2aec769..2d08cb2 100644
@@ -77,13 +77,13 @@ static void syborg_init(ram_addr_t ram_size,
     sysbus_create_simple("syborg,serial", 0xC0008000, pic[7]);
     sysbus_create_simple("syborg,serial", 0xC0009000, pic[8]);
 
-    if (nd_table[0].vlan) {
+    if (nd_table[0].vlan || nd_table[0].netdev) {
         DeviceState *dev;
         SysBusDevice *s;
 
         qemu_check_nic_model(&nd_table[0], "virtio");
         dev = qdev_create(NULL, "syborg,virtio-net");
-        dev->nd = &nd_table[0];
+        qdev_set_nic_properties(dev, &nd_table[0]);
         qdev_init_nofail(dev);
         s = sysbus_from_qdev(dev);
         sysbus_mmio_map(s, 0, 0xc000c000);
hw/syborg_virtio.c +13 -3
index c1faf3d..6cf5a15 100644
@@ -65,6 +65,7 @@ typedef struct {
     qemu_irq irq;
     uint32_t int_enable;
     uint32_t id;
+    NICConf nic;
 } SyborgVirtIOProxy;
 
 static uint32_t syborg_virtio_readl(void *opaque, target_phys_addr_t offset)
@@ -273,14 +274,23 @@ static int syborg_virtio_net_init(SysBusDevice *dev)
     VirtIODevice *vdev;
     SyborgVirtIOProxy *proxy = FROM_SYSBUS(SyborgVirtIOProxy, dev);
 
-    vdev = virtio_net_init(&dev->qdev);
+    vdev = virtio_net_init(&dev->qdev, &proxy->nic);
     return syborg_virtio_init(proxy, vdev);
 }
 
+static SysBusDeviceInfo syborg_virtio_net_info = {
+    .init = syborg_virtio_net_init,
+    .qdev.name  = "syborg,virtio-net",
+    .qdev.size  = sizeof(SyborgVirtIOProxy),
+    .qdev.props = (Property[]) {
+        DEFINE_NIC_PROPERTIES(SyborgVirtIOProxy, nic),
+        DEFINE_PROP_END_OF_LIST(),
+    }
+};
+
 static void syborg_virtio_register_devices(void)
 {
-    sysbus_register_dev("syborg,virtio-net", sizeof(SyborgVirtIOProxy),
-                        syborg_virtio_net_init);
+    sysbus_register_withprop(&syborg_virtio_net_info);
 }
 
 device_init(syborg_virtio_register_devices)
hw/virtio-net.c +24 -19

72 lines not on this page · raw message

hw/virtio-pci.c +23 -10
index e07a2a7..1665b59 100644
@@ -20,6 +20,7 @@
 #include "sysemu.h"
 #include "msix.h"
 #include "net.h"
+#include "loader.h"
 
 /* from Linux's linux/virtio_pci.h */
 
@@ -90,6 +91,7 @@ typedef struct {
     uint32_t class_code;
     uint32_t nvectors;
     DriveInfo *dinfo;
+    NICConf nic;
 } VirtIOPCIProxy;
 
 /* virtio device */
@@ -493,14 +495,9 @@ static int virtio_net_init_pci(PCIDevice *pci_dev)
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
     VirtIODevice *vdev;
 
-    vdev = virtio_net_init(&pci_dev->qdev);
-
-    /* set nvectors from property, unless the user specified something
-     * via -net nic,model=virtio,vectors=n command line option */
-    if (pci_dev->qdev.nd->nvectors == NIC_NVECTORS_UNSPECIFIED)
-        if (proxy->nvectors != NIC_NVECTORS_UNSPECIFIED)
-            vdev->nvectors = proxy->nvectors;
+    vdev = virtio_net_init(&pci_dev->qdev, &proxy->nic);
 
+    vdev->nvectors = proxy->nvectors;
     virtio_init_pci(proxy, vdev,
                     PCI_VENDOR_ID_REDHAT_QUMRANET,
                     PCI_DEVICE_ID_VIRTIO_NET,
@@ -509,9 +506,25 @@ static int virtio_net_init_pci(PCIDevice *pci_dev)
 
     /* make the actual value visible */
     proxy->nvectors = vdev->nvectors;
+
+    if (!pci_dev->qdev.hotplugged) {
+        static int loaded = 0;
+        if (!loaded) {
+            rom_add_option("pxe-virtio.bin");
+            loaded = 1;
+        }
+    }
     return 0;
 }
 
+static int virtio_net_exit_pci(PCIDevice *pci_dev)
+{
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+
+    virtio_net_exit(proxy->vdev);
+    return virtio_exit_pci(pci_dev);
+}
+
 static int virtio_balloon_init_pci(PCIDevice *pci_dev)
 {
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
@@ -543,10 +556,10 @@ static PCIDeviceInfo virtio_info[] = {
         .qdev.name  = "virtio-net-pci",
         .qdev.size  = sizeof(VirtIOPCIProxy),
         .init       = virtio_net_init_pci,
-        .exit       = virtio_exit_pci,
+        .exit       = virtio_net_exit_pci,
         .qdev.props = (Property[]) {
-            DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
-                               NIC_NVECTORS_UNSPECIFIED),
+            DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
+            DEFINE_NIC_PROPERTIES(VirtIOPCIProxy, nic),
             DEFINE_PROP_END_OF_LIST(),
         },
         .qdev.reset = virtio_pci_reset,
hw/virtio.h +4 -1
index 0f9be7d..15ad910 100644
@@ -15,6 +15,7 @@
 #define _QEMU_VIRTIO_H
 
 #include "hw.h"
+#include "net.h"
 #include "qdev.h"
 #include "sysemu.h"
 
@@ -163,8 +164,10 @@ void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,
 
 /* Base devices.  */
 VirtIODevice *virtio_blk_init(DeviceState *dev, DriveInfo *dinfo);
-VirtIODevice *virtio_net_init(DeviceState *dev);
+VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf);
 VirtIODevice *virtio_console_init(DeviceState *dev);
 VirtIODevice *virtio_balloon_init(DeviceState *dev);
 
+void virtio_net_exit(VirtIODevice *vdev);
+
 #endif
Signature · 1 line
1.6.2.5
#15 lore raw

PATCH 1/1 virtio-net: fix macaddr config regression

This commit:

commit 97b15621
virtio: use qdev properties for configuration.

makes a guest using virtio-net see an empty macaddr because we never copy the macaddr into the location that virtio_net_get_config() uses.

---
 hw/virtio-net.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/virtio-net.c +1 -0
index 93294af..4b09a93 100644
@@ -837,6 +837,7 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf)
     n->tx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_tx);
     n->ctrl_vq = virtio_add_queue(&n->vdev, 64, virtio_net_handle_ctrl);
     qemu_macaddr_default_if_unset(&conf->macaddr);
+    memcpy(&n->mac[0], &conf->macaddr, sizeof(n->mac));
     n->status = VIRTIO_NET_S_LINK_UP;
     n->vc = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, conf->vlan, conf->peer,
                                  dev->info->name, dev->id,
Signature · 1 line
1.6.2.5
#16 lore raw

PATCH 15/22 eepro100: use qdev properties for configuration.

In reply to Gerd Hoffmann
---
 hw/eepro100.c |   75 +++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 62 insertions(+), 13 deletions(-)
hw/eepro100.c +62 -13
index 62207da..277759f 100644
@@ -194,11 +194,11 @@ typedef struct {
     uint8_t mult[8];            /* multicast mask array */
     int mmio_index;
     VLANClientState *vc;
+    NICConf conf;
     uint8_t scb_stat;           /* SCB stat/ack byte */
     uint8_t int_stat;           /* PCI interrupt status */
     /* region must not be saved by nic_save. */
     uint32_t region[3];         /* PCI region addresses */
-    uint8_t macaddr[6];
     uint16_t mdimem[32];
     eeprom_t *eeprom;
     uint32_t device;            /* device variant */
@@ -482,7 +482,7 @@ static void nic_selective_reset(EEPRO100State * s)
     size_t i;
     uint16_t *eeprom_contents = eeprom93xx_data(s->eeprom);
     //~ eeprom93xx_reset(s->eeprom);
-    memcpy(eeprom_contents, s->macaddr, 6);
+    memcpy(eeprom_contents, s->conf.macaddr.a, 6);
     eeprom_contents[0xa] = 0x4000;
     if (s->device == i82557B || s->device == i82557C)
         eeprom_contents[5] = 0x0100;
@@ -665,7 +665,7 @@ static void eepro100_cu_command(EEPRO100State * s, uint8_t val)
             /* Do nothing. */
             break;
         case CmdIASetup:
-            cpu_physical_memory_read(cb_address + 8, &s->macaddr[0], 6);
+            cpu_physical_memory_read(cb_address + 8, &s->conf.macaddr.a[0], 6);
             TRACE(OTHER, logout("macaddr: %s\n", nic_dump(&s->macaddr[0], 6)));
             break;
         case CmdConfigure:
@@ -1507,7 +1507,7 @@ static ssize_t nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size
          * Long frames are discarded. */
         logout("%p received long frame (%zu byte), ignored\n", s, size);
         return -1;
-    } else if (memcmp(buf, s->macaddr, 6) == 0) {       // !!!
+    } else if (memcmp(buf, s->conf.macaddr.a, 6) == 0) {       // !!!
         /* Frame matches individual address. */
         /* TODO: check configuration byte 15/4 (ignore U/L). */
         TRACE(RXTX, logout("%p received frame for me, len=%zu\n", s, size));
@@ -1616,7 +1616,7 @@ static int nic_load(QEMUFile * f, void *opaque, int version_id)
     qemu_get_8s(f, &s->int_stat);
     /* Skip unused entries. */
     qemu_fseek(f, 3 * 4, SEEK_CUR);
-    qemu_get_buffer(f, s->macaddr, 6);
+    qemu_get_buffer(f, s->conf.macaddr.a, 6);
     /* Skip unused entries. */
     qemu_fseek(f, 19 * 4, SEEK_CUR);
     for (i = 0; i < 32; i++) {
@@ -1682,7 +1682,7 @@ static void nic_save(QEMUFile * f, void *opaque)
     qemu_put_8s(f, &s->int_stat);
     /* Skip unused entries. */
     qemu_fseek(f, 3 * 4, SEEK_CUR);
-    qemu_put_buffer(f, s->macaddr, 6);
+    qemu_put_buffer(f, s->conf.macaddr.a, 6);
     /* Skip unused entries. */
     qemu_fseek(f, 19 * 4, SEEK_CUR);
     for (i = 0; i < 32; i++) {
@@ -1731,9 +1731,7 @@ static void nic_cleanup(VLANClientState *vc)
 {
     EEPRO100State *s = vc->opaque;
 
-    unregister_savevm(vc->model, s);
-
-    eeprom93xx_free(s->eeprom);
+    s->vc = NULL;
 }
 
 static int pci_nic_uninit(PCIDevice *pci_dev)
@@ -1741,7 +1739,9 @@ static int pci_nic_uninit(PCIDevice *pci_dev)
     EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev);
 
     cpu_unregister_io_memory(s->mmio_index);
-
+    unregister_savevm(s->vc->model, s);
+    eeprom93xx_free(s->eeprom);
+    qemu_del_vlan_client(s->vc);
     return 0;
 }
 
@@ -1771,17 +1771,18 @@ static int nic_init(PCIDevice *pci_dev, uint32_t device)
     pci_register_bar(&s->dev, 2, PCI_FLASH_SIZE, PCI_ADDRESS_SPACE_MEM,
                            pci_mmio_map);
 
-    qdev_get_macaddr(&s->dev.qdev, s->macaddr);
+    qemu_macaddr_default_if_unset(&s->conf.macaddr);
     logout("macaddr: %s\n", nic_dump(&s->macaddr[0], 6));
     assert(s->region[1] == 0);
 
     nic_reset(s);
 
-    s->vc = qdev_get_vlan_client(&s->dev.qdev,
+    s->vc = qemu_new_vlan_client(s->conf.vlan, s->conf.peer,
+                                 pci_dev->qdev.info->name, pci_dev->qdev.id,
                                  nic_can_receive, nic_receive, NULL,
                                  nic_cleanup, s);
 
-    qemu_format_nic_info_str(s->vc, s->macaddr);
+    qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
     TRACE(OTHER, logout("%s\n", s->vc->info_str));
 
     qemu_register_reset(nic_reset, s);
@@ -1855,53 +1856,101 @@ static PCIDeviceInfo eepro100_info[] = {
         .qdev.name = "i82550",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82550_init,
+        .qdev.props = (Property[]) {
+            DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
+            DEFINE_PROP_END_OF_LIST(),
+        },
     },{
         .qdev.name = "i82551",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82551_init,
         .exit      = pci_nic_uninit,
+        .qdev.props = (Property[]) {
+            DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
+            DEFINE_PROP_END_OF_LIST(),
+        },
     },{
         .qdev.name = "i82557a",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557a_init,
+        .qdev.props = (Property[]) {
+            DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
+            DEFINE_PROP_END_OF_LIST(),
+        },
     },{
         .qdev.name = "i82557b",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557b_init,
         .exit      = pci_nic_uninit,
+        .qdev.props = (Property[]) {
+            DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
+            DEFINE_PROP_END_OF_LIST(),
+        },
     },{
         .qdev.name = "i82557c",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82557c_init,
+        .qdev.props = (Property[]) {
+            DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
+            DEFINE_PROP_END_OF_LIST(),
+        },
     },{
         .qdev.name = "i82558a",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82558a_init,
+        .qdev.props = (Property[]) {
+            DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
+            DEFINE_PROP_END_OF_LIST(),
+        },
     },{
         .qdev.name = "i82558b",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82558b_init,
+        .qdev.props = (Property[]) {
+            DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
+            DEFINE_PROP_END_OF_LIST(),
+        },
     },{
         .qdev.name = "i82559a",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559a_init,
+        .qdev.props = (Property[]) {
+            DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
+            DEFINE_PROP_END_OF_LIST(),
+        },
     },{
         .qdev.name = "i82559b",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559b_init,
+        .qdev.props = (Property[]) {
+            DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
+            DEFINE_PROP_END_OF_LIST(),
+        },
     },{
         .qdev.name = "i82559c",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559c_init,
+        .qdev.props = (Property[]) {
+            DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
+            DEFINE_PROP_END_OF_LIST(),
+        },
     },{
         .qdev.name = "i82559er",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82559er_init,
         .exit      = pci_nic_uninit,
+        .qdev.props = (Property[]) {
+            DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
+            DEFINE_PROP_END_OF_LIST(),
+        },
     },{
         .qdev.name = "i82562",
         .qdev.size = sizeof(EEPRO100State),
         .init      = pci_i82562_init,
+        .qdev.props = (Property[]) {
+            DEFINE_NIC_PROPERTIES(EEPRO100State, conf),
+            DEFINE_PROP_END_OF_LIST(),
+        },
     },{
         /* end of list */
     }
Signature · 1 line
1.6.2.5
#17 lore raw

PATCH 16/22 smc91c111: use qdev properties for configuration.

In reply to Gerd Hoffmann
---
 hw/smc91c111.c |   28 +++++++++++++++++++---------
 1 files changed, 19 insertions(+), 9 deletions(-)
hw/smc91c111.c +19 -9
index d58821a..4006035 100644
@@ -19,6 +19,7 @@
 typedef struct {
     SysBusDevice busdev;
     VLANClientState *vc;
+    NICConf conf;
     uint16_t tcr;
     uint16_t rcr;
     uint16_t cr;
@@ -42,7 +43,6 @@ typedef struct {
     uint8_t data[NUM_PACKETS][2048];
     uint8_t int_level;
     uint8_t int_mask;
-    uint8_t macaddr[6];
     int mmio_index;
 } smc91c111_state;
 
@@ -474,7 +474,7 @@ static uint32_t smc91c111_readb(void *opaque, target_phys_addr_t offset)
             /* Not implemented.  */
             return 0;
         case 4: case 5: case 6: case 7: case 8: case 9: /* IA */
-            return s->macaddr[offset - 4];
+            return s->conf.macaddr.a[offset - 4];
         case 10: /* General Purpose */
             return s->gpr & 0xff;
         case 11:
@@ -696,8 +696,7 @@ static void smc91c111_cleanup(VLANClientState *vc)
 {
     smc91c111_state *s = vc->opaque;
 
-    cpu_unregister_io_memory(s->mmio_index);
-    qemu_free(s);
+    s->vc = NULL;
 }
 
 static int smc91c111_init1(SysBusDevice *dev)
@@ -708,21 +707,32 @@ static int smc91c111_init1(SysBusDevice *dev)
                                            smc91c111_writefn, s);
     sysbus_init_mmio(dev, 16, s->mmio_index);
     sysbus_init_irq(dev, &s->irq);
-    qdev_get_macaddr(&dev->qdev, s->macaddr);
+    qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
     smc91c111_reset(s);
 
-    s->vc = qdev_get_vlan_client(&dev->qdev,
+    s->vc = qemu_new_vlan_client(s->conf.vlan, s->conf.peer,
+                                 dev->qdev.info->name, dev->qdev.id,
                                  smc91c111_can_receive, smc91c111_receive, NULL,
                                  smc91c111_cleanup, s);
-    qemu_format_nic_info_str(s->vc, s->macaddr);
+    qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
     /* ??? Save/restore.  */
     return 0;
 }
 
+static SysBusDeviceInfo smc91c111_info = {
+    .init = smc91c111_init1,
+    .qdev.name  = "smc91c111",
+    .qdev.size  = sizeof(smc91c111_state),
+    .qdev.props = (Property[]) {
+        DEFINE_NIC_PROPERTIES(smc91c111_state, conf),
+        DEFINE_PROP_END_OF_LIST(),
+    }
+};
+
 static void smc91c111_register_devices(void)
 {
-    sysbus_register_dev("smc91c111", sizeof(smc91c111_state), smc91c111_init1);
+    sysbus_register_withprop(&smc91c111_info);
 }
 
 /* Legacy helper function.  Should go away when machine config files are
@@ -734,7 +744,7 @@ void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)
 
     qemu_check_nic_model(nd, "smc91c111");
     dev = qdev_create(NULL, "smc91c111");
-    dev->nd = nd;
+    qdev_set_nic_properties(dev, nd);
     qdev_init_nofail(dev);
     s = sysbus_from_qdev(dev);
     sysbus_mmio_map(s, 0, base);
Signature · 1 line
1.6.2.5
#18 lore raw

PATCH 17/22 xilinx_ethlite: use qdev properties for configuration.

In reply to Gerd Hoffmann
---
 hw/xilinx.h         |    2 +-
 hw/xilinx_ethlite.c |   16 ++++++++++------
 2 files changed, 11 insertions(+), 7 deletions(-)
hw/xilinx.h +1 -1
index 5e6aeea..705ff5b 100644
@@ -40,7 +40,7 @@ xilinx_ethlite_create(NICInfo *nd, target_phys_addr_t base, qemu_irq irq,
     qemu_check_nic_model(nd, "xilinx-ethlite");
 
     dev = qdev_create(NULL, "xilinx,ethlite");
-    dev->nd = nd;
+    qdev_set_nic_properties(dev, nd);
     qdev_prop_set_uint32(dev, "txpingpong", txpingpong);
     qdev_prop_set_uint32(dev, "rxpingpong", rxpingpong);
     qdev_init_nofail(dev);
hw/xilinx_ethlite.c +10 -6
index 9b0074c..994e0e2 100644
@@ -52,13 +52,13 @@ struct xlx_ethlite
     SysBusDevice busdev;
     qemu_irq irq;
     VLANClientState *vc;
+    NICConf conf;
 
     uint32_t c_tx_pingpong;
     uint32_t c_rx_pingpong;
     unsigned int txbuf;
     unsigned int rxbuf;
 
-    uint8_t macaddr[6];
     uint32_t regs[R_MAX];
 };
 
@@ -125,7 +125,7 @@ eth_writel (void *opaque, target_phys_addr_t addr, uint32_t value)
                 if (s->regs[base + R_TX_CTRL0] & CTRL_I)
                     eth_pulse_irq(s);
             } else if ((value & (CTRL_P | CTRL_S)) == (CTRL_P | CTRL_S)) {
-                memcpy(&s->macaddr[0], &s->regs[base], 6);
+                memcpy(&s->conf.macaddr.a[0], &s->regs[base], 6);
                 if (s->regs[base + R_TX_CTRL0] & CTRL_I)
                     eth_pulse_irq(s);
             }
@@ -175,7 +175,7 @@ static ssize_t eth_rx(VLANClientState *vc, const uint8_t *buf, size_t size)
     int i;
 
     /* DA filter.  */
-    if (!(buf[0] & 0x80) && memcmp(&s->macaddr[0], buf, 6))
+    if (!(buf[0] & 0x80) && memcmp(&s->conf.macaddr.a[0], buf, 6))
         return size;
 
     if (s->regs[rxbase + R_RX_CTRL0] & CTRL_S) {
@@ -204,7 +204,8 @@ static ssize_t eth_rx(VLANClientState *vc, const uint8_t *buf, size_t size)
 static void eth_cleanup(VLANClientState *vc)
 {
     struct xlx_ethlite *s = vc->opaque;
-    qemu_free(s);
+
+    s->vc = NULL;
 }
 
 static int xilinx_ethlite_init(SysBusDevice *dev)
@@ -218,9 +219,11 @@ static int xilinx_ethlite_init(SysBusDevice *dev)
     regs = cpu_register_io_memory(eth_read, eth_write, s);
     sysbus_init_mmio(dev, R_MAX * 4, regs);
 
-    qdev_get_macaddr(&dev->qdev, s->macaddr);
-    s->vc = qdev_get_vlan_client(&dev->qdev,
+    qemu_macaddr_default_if_unset(&s->conf.macaddr);
+    s->vc = qemu_new_vlan_client(s->conf.vlan, s->conf.peer,
+                                 dev->qdev.info->name, dev->qdev.id,
                                  eth_can_rx, eth_rx, NULL, eth_cleanup, s);
+    qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
     return 0;
 }
 
@@ -231,6 +234,7 @@ static SysBusDeviceInfo xilinx_ethlite_info = {
     .qdev.props = (Property[]) {
         DEFINE_PROP_UINT32("txpingpong", struct xlx_ethlite, c_tx_pingpong, 1),
         DEFINE_PROP_UINT32("rxpingpong", struct xlx_ethlite, c_rx_pingpong, 1),
+        DEFINE_NIC_PROPERTIES(struct xlx_ethlite, conf),
         DEFINE_PROP_END_OF_LIST(),
     }
 };
Signature · 1 line
1.6.2.5
#19 lore raw

PATCH 18/22 stellaris_enet: use qdev properties for configuration.

In reply to Gerd Hoffmann
---
 hw/stellaris.c      |    2 +-
 hw/stellaris_enet.c |   40 +++++++++++++++++++++++++---------------
 2 files changed, 26 insertions(+), 16 deletions(-)
hw/stellaris.c +1 -1
index 1628914..44c9eee 100644
@@ -1383,7 +1383,7 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,
         qemu_check_nic_model(&nd_table[0], "stellaris");
 
         enet = qdev_create(NULL, "stellaris_enet");
-        enet->nd = &nd_table[0];
+        qdev_set_nic_properties(enet, &nd_table[0]);
         qdev_init_nofail(enet);
         sysbus_mmio_map(sysbus_from_qdev(enet), 0, 0x40048000);
         sysbus_connect_irq(sysbus_from_qdev(enet), 0, pic[42]);
hw/stellaris_enet.c +25 -15
index 4596a69..fe2cffe 100644
@@ -67,8 +67,8 @@ typedef struct {
     int rx_fifo_len;
     int next_packet;
     VLANClientState *vc;
+    NICConf conf;
     qemu_irq irq;
-    uint8_t macaddr[6];
     int mmio_index;
 } stellaris_enet_state;
 
@@ -169,10 +169,10 @@ static uint32_t stellaris_enet_read(void *opaque, target_phys_addr_t offset)
         }
         return val;
     case 0x14: /* IA0 */
-        return s->macaddr[0] | (s->macaddr[1] << 8)
-               | (s->macaddr[2] << 16) | (s->macaddr[3] << 24);
+        return s->conf.macaddr.a[0] | (s->conf.macaddr.a[1] << 8)
+               | (s->conf.macaddr.a[2] << 16) | (s->conf.macaddr.a[3] << 24);
     case 0x18: /* IA1 */
-        return s->macaddr[4] | (s->macaddr[5] << 8);
+        return s->conf.macaddr.a[4] | (s->conf.macaddr.a[5] << 8);
     case 0x1c: /* THR */
         return s->thr;
     case 0x20: /* MCTL */
@@ -267,14 +267,14 @@ static void stellaris_enet_write(void *opaque, target_phys_addr_t offset,
         }
         break;
     case 0x14: /* IA0 */
-        s->macaddr[0] = value;
-        s->macaddr[1] = value >> 8;
-        s->macaddr[2] = value >> 16;
-        s->macaddr[3] = value >> 24;
+        s->conf.macaddr.a[0] = value;
+        s->conf.macaddr.a[1] = value >> 8;
+        s->conf.macaddr.a[2] = value >> 16;
+        s->conf.macaddr.a[3] = value >> 24;
         break;
     case 0x18: /* IA1 */
-        s->macaddr[4] = value;
-        s->macaddr[5] = value >> 8;
+        s->conf.macaddr.a[4] = value;
+        s->conf.macaddr.a[5] = value >> 8;
         break;
     case 0x1c: /* THR */
         s->thr = value;
@@ -404,13 +404,14 @@ static int stellaris_enet_init(SysBusDevice *dev)
                                            stellaris_enet_writefn, s);
     sysbus_init_mmio(dev, 0x1000, s->mmio_index);
     sysbus_init_irq(dev, &s->irq);
-    qdev_get_macaddr(&dev->qdev, s->macaddr);
+    qemu_macaddr_default_if_unset(&s->conf.macaddr);
 
-    s->vc = qdev_get_vlan_client(&dev->qdev,
+    s->vc = qemu_new_vlan_client(s->conf.vlan, s->conf.peer,
+                                 dev->qdev.info->name, dev->qdev.id,
                                  stellaris_enet_can_receive,
                                  stellaris_enet_receive, NULL,
                                  stellaris_enet_cleanup, s);
-    qemu_format_nic_info_str(s->vc, s->macaddr);
+    qemu_format_nic_info_str(s->vc, s->conf.macaddr.a);
 
     stellaris_enet_reset(s);
     register_savevm("stellaris_enet", -1, 1,
@@ -418,10 +419,19 @@ static int stellaris_enet_init(SysBusDevice *dev)
     return 0;
 }
 
+static SysBusDeviceInfo stellaris_enet_info = {
+    .init = stellaris_enet_init,
+    .qdev.name  = "stellaris_enet",
+    .qdev.size  = sizeof(stellaris_enet_state),
+    .qdev.props = (Property[]) {
+        DEFINE_NIC_PROPERTIES(stellaris_enet_state, conf),
+        DEFINE_PROP_END_OF_LIST(),
+    }
+};
+
 static void stellaris_enet_register_devices(void)
 {
-    sysbus_register_dev("stellaris_enet", sizeof(stellaris_enet_state),
-                        stellaris_enet_init);
+    sysbus_register_withprop(&stellaris_enet_info);
 }
 
 device_init(stellaris_enet_register_devices)
Signature · 1 line
1.6.2.5
#20 lore raw

PATCH 19/22 musicpal: use qdev properties for configuration.

In reply to Gerd Hoffmann
---
 hw/musicpal.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)
hw/musicpal.c +9 -5
index 02d4c70..cb1ac6d 100644
@@ -152,6 +152,7 @@ typedef struct mv88w8618_eth_state {
     uint32_t frx_queue[4];
     uint32_t cur_rx[4];
     VLANClientState *vc;
+    NICConf conf;
 } mv88w8618_eth_state;
 
 static void eth_rx_desc_put(uint32_t addr, mv88w8618_rx_desc *desc)
@@ -368,9 +369,7 @@ static void eth_cleanup(VLANClientState *vc)
 {
     mv88w8618_eth_state *s = vc->opaque;
 
-    cpu_unregister_io_memory(s->mmio_index);
-
-    qemu_free(s);
+    s->vc = NULL;
 }
 
 static int mv88w8618_eth_init(SysBusDevice *dev)
@@ -378,7 +377,8 @@ static int mv88w8618_eth_init(SysBusDevice *dev)
     mv88w8618_eth_state *s = FROM_SYSBUS(mv88w8618_eth_state, dev);
 
     sysbus_init_irq(dev, &s->irq);
-    s->vc = qdev_get_vlan_client(&dev->qdev,
+    s->vc = qemu_new_vlan_client(s->conf.vlan, s->conf.peer,
+                                 dev->qdev.info->name, dev->qdev.id,
                                  eth_can_receive, eth_receive, NULL,
                                  eth_cleanup, s);
     s->mmio_index = cpu_register_io_memory(mv88w8618_eth_readfn,
@@ -410,6 +410,10 @@ static SysBusDeviceInfo mv88w8618_eth_info = {
     .qdev.name = "mv88w8618_eth",
     .qdev.size = sizeof(mv88w8618_eth_state),
     .qdev.vmsd = &mv88w8618_eth_vmsd,
+    .qdev.props = (Property[]) {
+        DEFINE_NIC_PROPERTIES(mv88w8618_eth_state, conf),
+        DEFINE_PROP_END_OF_LIST(),
+    },
 };
 
 /* LCD register offsets */
@@ -1550,7 +1554,7 @@ static void musicpal_init(ram_addr_t ram_size,
 
     qemu_check_nic_model(&nd_table[0], "mv88w8618");
     dev = qdev_create(NULL, "mv88w8618_eth");
-    dev->nd = &nd_table[0];
+    qdev_set_nic_properties(dev, &nd_table[0]);
     qdev_init_nofail(dev);
     sysbus_mmio_map(sysbus_from_qdev(dev), 0, MP_ETH_BASE);
     sysbus_connect_irq(sysbus_from_qdev(dev), 0, pic[MP_ETH_IRQ]);
Signature · 1 line
1.6.2.5
#21 lore raw

PATCH 20/22 zap DeviceState->nd

In reply to Gerd Hoffmann

No users left.
Also cleanup obsolete helper functions.

---
 hw/pci.c  |    9 +--------
 hw/qdev.c |   22 ----------------------
 hw/qdev.h |    1 -
 net.h     |    7 -------
 4 files changed, 1 insertions(+), 38 deletions(-)
hw/pci.c +1 -8
index fe2c4bd..553febb 100644
@@ -859,14 +859,7 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
     dev = &pci_dev->qdev;
     if (nd->name)
         dev->id = qemu_strdup(nd->name);
-    if (qdev_prop_exists(dev, "mac")) {
-        /* qdev-ified */
-        qdev_set_nic_properties(dev, nd);
-    } else {
-        /* legacy */
-        dev->nd = nd;
-        nd->private = dev;
-    }
+    qdev_set_nic_properties(dev, nd);
     if (qdev_init(dev) < 0)
         return NULL;
     return pci_dev;
hw/qdev.c +0 -22
index e81d662..373ddfc 100644
@@ -361,28 +361,6 @@ void qdev_connect_gpio_out(DeviceState * dev, int n, qemu_irq pin)
     dev->gpio_out[n] = pin;
 }
 
-VLANClientState *qdev_get_vlan_client(DeviceState *dev,
-                                      NetCanReceive *can_receive,
-                                      NetReceive *receive,
-                                      NetReceiveIOV *receive_iov,
-                                      NetCleanup *cleanup,
-                                      void *opaque)
-{
-    NICInfo *nd = dev->nd;
-    assert(nd);
-    nd->vc = qemu_new_vlan_client(nd->vlan, nd->netdev,
-                                  nd->model, nd->name,
-                                  can_receive, receive, receive_iov,
-                                  cleanup, opaque);
-    return nd->vc;
-}
-
-
-void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr)
-{
-    memcpy(macaddr, dev->nd->macaddr, 6);
-}
-
 void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd)
 {
     qdev_prop_set_macaddr(dev, "mac", nd->macaddr);
hw/qdev.h +0 -1
index 5271a3c..d28978f 100644
@@ -39,7 +39,6 @@ struct DeviceState {
     qemu_irq *gpio_in;
     QLIST_HEAD(, BusState) child_bus;
     int num_child_bus;
-    NICInfo *nd;
     QLIST_ENTRY(DeviceState) sibling;
 };
 
net.h +0 -7
index f2d10f0..c96f291 100644
@@ -164,13 +164,6 @@ void net_host_device_remove(Monitor *mon, const QDict *qdict);
 #define SMBD_COMMAND "/usr/sbin/smbd"
 #endif
 
-void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr);
-VLANClientState *qdev_get_vlan_client(DeviceState *dev,
-                                      NetCanReceive *can_receive,
-                                      NetReceive *receive,
-                                      NetReceiveIOV *receive_iov,
-                                      NetCleanup *cleanup,
-                                      void *opaque);
 void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd);
 
 #endif
Signature · 1 line
1.6.2.5
#22 lore raw

PATCH 21/22 kill dead nic unplug code.

In reply to Gerd Hoffmann

Cleanup on unplug happens via qdev->exit() callback now.

---
 hw/acpi.c           |    3 ---
 hw/device-hotplug.c |   16 ----------------
 hw/pci-hotplug.c    |   25 -------------------------
 sysemu.h            |    4 ----
 4 files changed, 0 insertions(+), 48 deletions(-)
hw/acpi.c +0 -3
index d73aee9..dcc2c86 100644
@@ -702,9 +702,6 @@ static void pciej_write(void *opaque, uint32_t addr, uint32_t val)
     QLIST_FOREACH_SAFE(qdev, &bus->children, sibling, next) {
         dev = DO_UPCAST(PCIDevice, qdev, qdev);
         if (PCI_SLOT(dev->devfn) == slot) {
-#if defined (TARGET_I386)
-            pci_device_hot_remove_success(dev);
-#endif
             qdev_free(qdev);
         }
     }
hw/device-hotplug.c +0 -16
index c0cfd31..9cc8376 100644
@@ -46,19 +46,3 @@ DriveInfo *add_init_drive(const char *optstr)
 
     return dinfo;
 }
-
-void destroy_nic(dev_match_fn *match_fn, void *arg)
-{
-    int i;
-    NICInfo *nic;
-
-    for (i = 0; i < MAX_NICS; i++) {
-        nic = &nd_table[i];
-        if (nic->used) {
-            if (nic->private && match_fn(nic->private, arg)) {
-                qemu_del_vlan_client(nic->vc);
-                net_client_uninit(nic);
-            }
-        }
-    }
-}
hw/pci-hotplug.c +0 -25
index 35fa290..4673b89 100644
@@ -234,28 +234,3 @@ void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict)
 {
     pci_device_hot_remove(mon, qdict_get_str(qdict, "pci_addr"));
 }
-
-static int pci_match_fn(void *dev_private, void *arg)
-{
-    PCIDevice *dev = dev_private;
-    PCIDevice *match = arg;
-
-    return (dev == match);
-}
-
-/*
- * OS has executed _EJ0 method, we now can remove the device
- */
-void pci_device_hot_remove_success(PCIDevice *d)
-{
-    int class_code;
-
-    class_code = d->config_read(d, PCI_CLASS_DEVICE+1, 1);
-
-    switch(class_code) {
-    case PCI_BASE_CLASS_NETWORK:
-        destroy_nic(pci_match_fn, d);
-        break;
-    }
-}
-
sysemu.h +0 -4
index 763861d..cda5848 100644
@@ -202,17 +202,13 @@ extern DriveInfo *drive_init(QemuOpts *arg, void *machine, int *fatal_error);
 
 /* device-hotplug */
 
-typedef int (dev_match_fn)(void *dev_private, void *arg);
-
 DriveInfo *add_init_drive(const char *opts);
-void destroy_nic(dev_match_fn *match_fn, void *arg);
 
 /* pci-hotplug */
 void pci_device_hot_add(Monitor *mon, const QDict *qdict);
 void drive_hot_add(Monitor *mon, const QDict *qdict);
 void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
 void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict);
-void pci_device_hot_remove_success(PCIDevice *dev);
 
 /* serial ports */
 
Signature · 1 line
1.6.2.5
#23 lore raw

PATCH 22/22 pc.c: only load e1000 rom.

In reply to Gerd Hoffmann

The other pxe roms are loaded by the drivers individual drivers now.

---
 hw/pc.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
hw/pc.c +8 -1
index 408d6d6..4cd8ec6 100644
@@ -1163,6 +1163,11 @@ static void pc_init1(ram_addr_t ram_size,
         rom_add_option(option_rom[i]);
     }
 
+#if 1
+    /*
+     * Needed for the e1000 rom only.  The rom doesn't do proper BEV
+     * and thus we can't load it unconditionally.
+     */
     for (i = 0; i < nb_nics; i++) {
         char nic_oprom[1024];
         const char *model = nd_table[i].model;
@@ -1172,10 +1177,12 @@ static void pc_init1(ram_addr_t ram_size,
 
         if (model == NULL)
             model = "e1000";
+        if (strcmp(model,"e1000") != 0)
+            continue;
         snprintf(nic_oprom, sizeof(nic_oprom), "pxe-%s.bin", model);
-
         rom_add_option(nic_oprom);
     }
+#endif
 
     cpu_irq = qemu_allocate_irqs(pic_irq_request, NULL, 1);
     i8259 = i8259_init(cpu_irq[0]);
Signature · 1 line
1.6.2.5