* [Qemu-devel] [RfC PATCH v3 01/10] net: macaddr tweaks.
2009-10-16 13:41 [Qemu-devel] [RfC PATCH v3 00/10] qdev-ify network cards Gerd Hoffmann
@ 2009-10-16 13:41 ` Gerd Hoffmann
2009-10-16 13:41 ` [Qemu-devel] [RfC PATCH v3 02/10] qdev: mac addr property fixups Gerd Hoffmann
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2009-10-16 13:41 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
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).
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
net.c | 15 +++++++++++++++
net.h | 5 +++++
qemu-common.h | 1 +
3 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/net.c b/net.c
index 4708080..3b69d3b 100644
--- a/net.c
+++ b/net.c
@@ -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;
diff --git a/net.h b/net.h
index 439de2a..605092a 100644
--- a/net.h
+++ b/net.h
@@ -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,
diff --git a/qemu-common.h b/qemu-common.h
index 8551862..980f362 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -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;
--
1.6.2.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [RfC PATCH v3 02/10] qdev: mac addr property fixups
2009-10-16 13:41 [Qemu-devel] [RfC PATCH v3 00/10] qdev-ify network cards Gerd Hoffmann
2009-10-16 13:41 ` [Qemu-devel] [RfC PATCH v3 01/10] net: macaddr tweaks Gerd Hoffmann
@ 2009-10-16 13:41 ` Gerd Hoffmann
2009-10-16 13:41 ` [Qemu-devel] [RfC PATCH v3 03/10] qdev: add netdev property Gerd Hoffmann
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2009-10-16 13:41 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/qdev-properties.c | 31 +++++++++++++++++++++----------
hw/qdev.h | 3 ++-
2 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 5c627fa..1d68125 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -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);
diff --git a/hw/qdev.h b/hw/qdev.h
index 8cd843e..118e886 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -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);
--
1.6.2.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [RfC PATCH v3 03/10] qdev: add netdev property
2009-10-16 13:41 [Qemu-devel] [RfC PATCH v3 00/10] qdev-ify network cards Gerd Hoffmann
2009-10-16 13:41 ` [Qemu-devel] [RfC PATCH v3 01/10] net: macaddr tweaks Gerd Hoffmann
2009-10-16 13:41 ` [Qemu-devel] [RfC PATCH v3 02/10] qdev: mac addr property fixups Gerd Hoffmann
@ 2009-10-16 13:41 ` Gerd Hoffmann
2009-10-16 13:41 ` [Qemu-devel] [RfC PATCH v3 04/10] qdev: add vlan property Gerd Hoffmann
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2009-10-16 13:41 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/qdev-properties.c | 36 ++++++++++++++++++++++++++++++++++++
hw/qdev.h | 4 ++++
net.c | 2 +-
net.h | 1 +
4 files changed, 42 insertions(+), 1 deletions(-)
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 1d68125..76925c8 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -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);
diff --git a/hw/qdev.h b/hw/qdev.h
index 118e886..c0d59bc 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -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. */
diff --git a/net.c b/net.c
index 3b69d3b..75a01d2 100644
--- a/net.c
+++ b/net.c
@@ -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;
diff --git a/net.h b/net.h
index 605092a..6a24f55 100644
--- a/net.h
+++ b/net.h
@@ -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,
--
1.6.2.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [RfC PATCH v3 04/10] qdev: add vlan property
2009-10-16 13:41 [Qemu-devel] [RfC PATCH v3 00/10] qdev-ify network cards Gerd Hoffmann
` (2 preceding siblings ...)
2009-10-16 13:41 ` [Qemu-devel] [RfC PATCH v3 03/10] qdev: add netdev property Gerd Hoffmann
@ 2009-10-16 13:41 ` Gerd Hoffmann
2009-10-16 13:41 ` [Qemu-devel] [RfC PATCH v3 05/10] qdev/net: common nic property bits Gerd Hoffmann
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2009-10-16 13:41 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/qdev-properties.c | 39 +++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 6 ++++++
2 files changed, 45 insertions(+), 0 deletions(-)
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 76925c8..c9843a2 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -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);
diff --git a/hw/qdev.h b/hw/qdev.h
index c0d59bc..c678ab2 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -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. */
--
1.6.2.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [RfC PATCH v3 05/10] qdev/net: common nic property bits
2009-10-16 13:41 [Qemu-devel] [RfC PATCH v3 00/10] qdev-ify network cards Gerd Hoffmann
` (3 preceding siblings ...)
2009-10-16 13:41 ` [Qemu-devel] [RfC PATCH v3 04/10] qdev: add vlan property Gerd Hoffmann
@ 2009-10-16 13:41 ` Gerd Hoffmann
2009-10-16 13:41 ` [Qemu-devel] [RfC PATCH v3 06/10] ne2k_isa: qdev-ify Gerd Hoffmann
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2009-10-16 13:41 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
net.h | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/net.h b/net.h
index 6a24f55..77720af 100644
--- a/net.h
+++ b/net.h
@@ -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 *);
--
1.6.2.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [RfC PATCH v3 06/10] ne2k_isa: qdev-ify.
2009-10-16 13:41 [Qemu-devel] [RfC PATCH v3 00/10] qdev-ify network cards Gerd Hoffmann
` (4 preceding siblings ...)
2009-10-16 13:41 ` [Qemu-devel] [RfC PATCH v3 05/10] qdev/net: common nic property bits Gerd Hoffmann
@ 2009-10-16 13:41 ` Gerd Hoffmann
2009-10-16 13:42 ` [Qemu-devel] [RfC PATCH v3 07/10] qdev: add qdev_prop_exists() Gerd Hoffmann
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2009-10-16 13:41 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/ne2000-isa.c | 12 ++++++++----
hw/ne2000.c | 6 +++---
hw/ne2000.h | 2 +-
3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c
index e346731..1bed5d4 100644
--- a/hw/ne2000-isa.c
+++ b/hw/ne2000-isa.c
@@ -65,13 +65,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 +85,11 @@ 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_prop_set_macaddr(&dev->qdev, "mac", nd->macaddr);
+ if (nd->vlan)
+ qdev_prop_set_int32(&dev->qdev, "vlan", nd->vlan->id);
qdev_init_nofail(&dev->qdev);
}
@@ -97,6 +100,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(),
},
};
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 87f1e59..7ce56ff 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -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;
diff --git a/hw/ne2000.h b/hw/ne2000.h
index 92a2ddb..7842246 100644
--- a/hw/ne2000.h
+++ b/hw/ne2000.h
@@ -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;
--
1.6.2.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [RfC PATCH v3 07/10] qdev: add qdev_prop_exists()
2009-10-16 13:41 [Qemu-devel] [RfC PATCH v3 00/10] qdev-ify network cards Gerd Hoffmann
` (5 preceding siblings ...)
2009-10-16 13:41 ` [Qemu-devel] [RfC PATCH v3 06/10] ne2k_isa: qdev-ify Gerd Hoffmann
@ 2009-10-16 13:42 ` Gerd Hoffmann
2009-10-16 13:42 ` [Qemu-devel] [RfC PATCH v3 08/10] prepare pci nic init path for qdev conversion Gerd Hoffmann
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2009-10-16 13:42 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/qdev-properties.c | 5 +++++
hw/qdev.h | 1 +
2 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index c9843a2..370f356 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -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;
diff --git a/hw/qdev.h b/hw/qdev.h
index c678ab2..5271a3c 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -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);
--
1.6.2.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [RfC PATCH v3 08/10] prepare pci nic init path for qdev conversion
2009-10-16 13:41 [Qemu-devel] [RfC PATCH v3 00/10] qdev-ify network cards Gerd Hoffmann
` (6 preceding siblings ...)
2009-10-16 13:42 ` [Qemu-devel] [RfC PATCH v3 07/10] qdev: add qdev_prop_exists() Gerd Hoffmann
@ 2009-10-16 13:42 ` Gerd Hoffmann
2009-10-16 13:42 ` [Qemu-devel] [RfC PATCH v3 09/10] ne2k_pci: qdev-ify Gerd Hoffmann
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2009-10-16 13:42 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/pci.c | 14 ++++++++++++--
1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/hw/pci.c b/hw/pci.c
index abf07ca..fe8e939 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -859,10 +859,20 @@ 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_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);
+ } else {
+ /* legacy */
+ dev->nd = nd;
+ nd->private = dev;
+ }
if (qdev_init(dev) < 0)
return NULL;
- nd->private = dev;
return pci_dev;
}
--
1.6.2.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [RfC PATCH v3 09/10] ne2k_pci: qdev-ify.
2009-10-16 13:41 [Qemu-devel] [RfC PATCH v3 00/10] qdev-ify network cards Gerd Hoffmann
` (7 preceding siblings ...)
2009-10-16 13:42 ` [Qemu-devel] [RfC PATCH v3 08/10] prepare pci nic init path for qdev conversion Gerd Hoffmann
@ 2009-10-16 13:42 ` Gerd Hoffmann
2009-10-16 13:42 ` [Qemu-devel] [RfC PATCH v3 10/10] ne2k_pci: load rom Gerd Hoffmann
2009-10-19 8:59 ` [Qemu-devel] [RfC PATCH v3 00/10] qdev-ify network cards Mark McLoughlin
10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2009-10-16 13:42 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/ne2000.c | 27 +++++++++++++++++++++------
1 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 7ce56ff..f296b10 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -758,22 +758,37 @@ 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);
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;
+
+ 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)
--
1.6.2.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [RfC PATCH v3 10/10] ne2k_pci: load rom.
2009-10-16 13:41 [Qemu-devel] [RfC PATCH v3 00/10] qdev-ify network cards Gerd Hoffmann
` (8 preceding siblings ...)
2009-10-16 13:42 ` [Qemu-devel] [RfC PATCH v3 09/10] ne2k_pci: qdev-ify Gerd Hoffmann
@ 2009-10-16 13:42 ` Gerd Hoffmann
2009-10-19 8:59 ` [Qemu-devel] [RfC PATCH v3 00/10] qdev-ify network cards Mark McLoughlin
10 siblings, 0 replies; 12+ messages in thread
From: Gerd Hoffmann @ 2009-10-16 13:42 UTC (permalink / raw)
To: qemu-devel; +Cc: Gerd Hoffmann
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/ne2000.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/hw/ne2000.c b/hw/ne2000.c
index f296b10..6cb5f58 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -25,6 +25,7 @@
#include "pci.h"
#include "net.h"
#include "ne2000.h"
+#include "loader.h"
/* debug NE2000 card */
//#define DEBUG_NE2000
@@ -767,6 +768,14 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
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;
}
--
1.6.2.5
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [RfC PATCH v3 00/10] qdev-ify network cards
2009-10-16 13:41 [Qemu-devel] [RfC PATCH v3 00/10] qdev-ify network cards Gerd Hoffmann
` (9 preceding siblings ...)
2009-10-16 13:42 ` [Qemu-devel] [RfC PATCH v3 10/10] ne2k_pci: load rom Gerd Hoffmann
@ 2009-10-19 8:59 ` Mark McLoughlin
10 siblings, 0 replies; 12+ messages in thread
From: Mark McLoughlin @ 2009-10-19 8:59 UTC (permalink / raw)
To: Gerd Hoffmann; +Cc: qemu-devel
On Fri, 2009-10-16 at 15:41 +0200, Gerd Hoffmann wrote:
> Hi,
>
> Short RfC patch series to get the discussion rolling. We really need to
> get the nic drivers qdev-ified properly, so qemu stops segfaulting on
> '-device $any_nic_here'.
>
> New in v3:
> * renamed macaddr_t to MACAddr and made it a struct.
> * Adapted to netdev changes merged recently.
> * Also convert ne2k_pci.
> * Some new qdev properties and common bits for nics to ease
> conversion.
> * load pxe rom unconditionally (ne2k_pci only).
Very nice, I like it.
Acked-by: Mark McLoughlin <markmc@redhat.com>
Cheers,
Mark.
^ permalink raw reply [flat|nested] 12+ messages in thread