usb-net: use qdev for -usbdevice
PATCH 1/1 usb-net: use qdev for -usbdevice
Signed-off-by Gerd Hoffmann <[email protected]>
--- hw/usb-net.c | 78 +++++++++++++++++++++++++++++++++++---------------------- hw/usb.h | 3 -- vl.c | 18 ------------- 3 files changed, 48 insertions(+), 51 deletions(-)
hw/usb-net.c +48 -30
@@ -610,7 +610,6 @@ typedef struct USBNetState {uint32_t media_state;uint16_t filter;uint32_t vendorid; -uint8_t mac[6 ];unsigned int out_ptr;uint8_t out_buf[2048 ];
@@ -621,6 +620,7 @@ typedef struct USBNetState {char usbstring_mac[13 ];VLANClientState *vc; +NICConf conf; QTAILQ_HEAD(rndis_resp_head, rndis_response) rndis_resp; } USBNetState;
@@ -741,12 +741,12 @@ static int ndis_query(USBNetState *s, uint32_t oid,/* ieee802.3 OIDs (table 4-3) */ /* mandatory */ case OID_802_3_PERMANENT_ADDRESS : -memcpy (outbuf, s->mac,6 ); +memcpy (outbuf, s->conf.macaddr.a,6 );return 6 ;/* mandatory */ case OID_802_3_CURRENT_ADDRESS : -memcpy (outbuf, s->mac,6 ); +memcpy (outbuf, s->conf.macaddr.a,6 );return 6 ;/* mandatory */
@@ -1420,15 +1420,14 @@ static void usbnet_cleanup(VLANClientState *vc) {USBNetState *s = vc->opaque; -rndis_clear_responsequeue (s); -qemu_free (s); + s->vc =NULL ; }static void usb_net_handle_destroy (USBDevice *dev) {USBNetState *s = (USBNetState *) dev; -/* TODO: remove the nd_table[] entry */ +rndis_clear_responsequeue (s);qemu_del_vlan_client (s->vc); }
@@ -1447,42 +1446,55 @@ static int usb_net_initfn(USBDevice *dev) s->media_state =0 ;/* NDIS_MEDIA_STATE_CONNECTED */ ; s->filter =0 ; s->vendorid =0x1234 ; + +qemu_macaddr_default_if_unset (&s->conf.macaddr); + s->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , + s->conf.vlan, s->conf.peer, + dev->qdev.info->name, dev->qdev.id, + usbnet_can_receive, + usbnet_receive, +NULL ,NULL , + usbnet_cleanup, s); +qemu_format_nic_info_str (s->vc, s->conf.macaddr.a); +snprintf (s->usbstring_mac,sizeof (s->usbstring_mac), +"%02x%02x%02x%02x%02x%02x" , +0x40 , + s->conf.macaddr.a[1 ], + s->conf.macaddr.a[2 ], + s->conf.macaddr.a[3 ], + s->conf.macaddr.a[4 ], + s->conf.macaddr.a[5 ]); +return 0 ; } -USBDevice *usb_net_init (NICInfo *nd) +static USBDevice *usb_net_init (const char *cmdline) {USBDevice *dev; -USBNetState *s; - - dev =usb_create_simple (NULL /* FIXME */ ,"QEMU USB Network Interface" ); - s =DO_UPCAST (USBNetState, dev, dev); +QemuOpts *opts; +int idx; -memcpy (s->mac, nd->macaddr,6 ); - - s->vc = nd->vc =qemu_new_vlan_client (NET_CLIENT_TYPE_NIC , - nd->vlan, nd->netdev, - nd->model, nd->name, - usbnet_can_receive, - usbnet_receive, -NULL ,NULL , - usbnet_cleanup, s); + opts =qemu_opts_parse (&qemu_net_opts, cmdline,NULL ); +if (!opts) { +return NULL ; + } +qemu_opt_set (opts,"type" ,"nic" ); +qemu_opt_set (opts,"model" ,"usb" ); -qemu_format_nic_info_str (s->vc, s->mac); + idx =net_client_init (NULL , opts,0 ); +if (idx ==-1 ) { +return NULL ; + } -snprintf (s->usbstring_mac,sizeof (s->usbstring_mac), -"%02x%02x%02x%02x%02x%02x" , -0x40 , s->mac[1 ], s->mac[2 ], - s->mac[3 ], s->mac[4 ], s->mac[5 ]); -fprintf (stderr,"usbnet: initialized mac %02x:%02x:%02x:%02x:%02x:%02x\n" , - s->mac[0 ], s->mac[1 ], s->mac[2 ], - s->mac[3 ], s->mac[4 ], s->mac[5 ]); - -return (USBDevice *) s; + dev =usb_create (NULL /* FIXME */ ,"QEMU USB Network Interface" ); +qdev_set_nic_properties (&dev->qdev, &nd_table[idx]); +qdev_init (&dev->qdev); +return dev; }static struct USBDeviceInfo net_info = { .qdev.name ="QEMU USB Network Interface" , + .qdev.alias ="usb-net" , .qdev.size =sizeof (USBNetState), .init = usb_net_initfn, .handle_packet = usb_generic_handle_packet,
@@ -1490,6 +1502,12 @@ static struct USBDeviceInfo net_info = { .handle_control = usb_net_handle_control, .handle_data = usb_net_handle_data, .handle_destroy = usb_net_handle_destroy, + .usbdevice_name = "net", + .usbdevice_init = usb_net_init, + .qdev.props = (Property []) { +DEFINE_NIC_PROPERTIES (USBNetState, conf), +DEFINE_PROP_END_OF_LIST (), + } };static void usb_net_register_devices (void )
hw/usb.h +0 -3
@@ -256,9 +256,6 @@ void usb_host_info(Monitor *mon);/* usb-hid.c */ void usb_hid_datain_cb (USBDevice *dev,void *opaque,void (*datain)(void *)); -/* usb-net.c */ -USBDevice *usb_net_init (NICInfo *nd); -/* usb-bt.c */ USBDevice *usb_bt_init (HCIInfo *hci);
vl.c +0 -18
@@ -2543,24 +2543,6 @@ static int usb_device_add(const char *devname, int is_hotplug)/* the other ones */ if (strstart (devname,"host:" , &p)) { dev =usb_host_device_open (p); - }else if (strstart (devname,"net:" , &p)) { -QemuOpts *opts; -int idx; - - opts =qemu_opts_parse (&qemu_net_opts, p,NULL ); -if (!opts) { -return -1 ; - } - -qemu_opt_set (opts,"type" ,"nic" ); -qemu_opt_set (opts,"model" ,"usb" ); - - idx =net_client_init (NULL , opts,0 ); -if (idx ==-1 ) { -return -1 ; - } - - dev =usb_net_init (&nd_table[idx]); }else if (!strcmp (devname,"bt" ) ||strstart (devname,"bt:" , &p)) { dev =usb_bt_init (devname[2 ] ?hci_init (p) :bt_new_hci (qemu_find_bt_vlan (0 )));
Signature · 1 line
1.6.2.5
Can you update this against staging (or master if you want 24 hours) to take into account Mark's nic refactoring series? The changes looked non-trivial to me.
Regards,
Anthony Liguori
Quoted 3 lines · Anthony Liguori
Can you update this against staging (or master if you want 24 hours) to take into account Mark's nic refactoring series? The changes looked non-trivial to me.
Attached. Based on the commit just after marks nic series, because full staging tree doesn't build right now.
cheers,
Gerd
Quoted 1 line
From
fbca083ffcc1271bf41f35345dd8533930147ea0Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <[email protected]>
Date: Wed, 28 Oct 2009 11:21:27 +0100
Subject: [PATCH 1/2] usb-net: use qdev for -usbdevice
--- hw/usb-net.c | 79 +++++++++++++++++++++++++++++++++++---------------------- hw/usb.h | 3 -- vl.c | 18 ------------- 3 files changed, 48 insertions(+), 52 deletions(-)
hw/usb-net.c +48 -31
@@ -1420,8 +1420,7 @@ static void usbnet_cleanup(VLANClientState *nc) {USBNetState *s =DO_UPCAST (NICState, nc, nc)->opaque; -rndis_clear_responsequeue (s); -qemu_free (s); + s->nic =NULL ; }static void usb_net_handle_destroy (USBDevice *dev)
@@ -1429,9 +1428,18 @@ static void usb_net_handle_destroy(USBDevice *dev)USBNetState *s = (USBNetState *) dev;/* TODO: remove the nd_table[] entry */ +rndis_clear_responsequeue (s);qemu_del_vlan_client (&s->nic->nc); } +static NetClientInfo net_usbnet_info = { + .type =NET_CLIENT_TYPE_NIC , + .size =sizeof (NICState), + .can_receive = usbnet_can_receive, + .receive = usbnet_receive, + .cleanup = usbnet_cleanup, +}; +static int usb_net_initfn (USBDevice *dev) {USBNetState *s =DO_UPCAST (USBNetState, dev, dev);
@@ -1447,47 +1455,50 @@ static int usb_net_initfn(USBDevice *dev) s->media_state =0 ;/* NDIS_MEDIA_STATE_CONNECTED */ ; s->filter =0 ; s->vendorid =0x1234 ; + +qemu_macaddr_default_if_unset (&s->conf.macaddr); + s->nic =qemu_new_nic (&net_usbnet_info, &s->conf, + s->dev.qdev.info->name, s->dev.qdev.id, s); +qemu_format_nic_info_str (&s->nic->nc, s->conf.macaddr.a); +snprintf (s->usbstring_mac,sizeof (s->usbstring_mac), +"%02x%02x%02x%02x%02x%02x" , +0x40 , + s->conf.macaddr.a[1 ], + s->conf.macaddr.a[2 ], + s->conf.macaddr.a[3 ], + s->conf.macaddr.a[4 ], + s->conf.macaddr.a[5 ]); +return 0 ; } -static NetClientInfo net_usbnet_info = { - .type =NET_CLIENT_TYPE_NIC , - .size =sizeof (NICState), - .can_receive = usbnet_can_receive, - .receive = usbnet_receive, - .cleanup = usbnet_cleanup, -}; - -USBDevice *usb_net_init (NICInfo *nd) +static USBDevice *usb_net_init (const char *cmdline) {USBDevice *dev; -USBNetState *s; - - dev =usb_create_simple (NULL /* FIXME */ ,"QEMU USB Network Interface" ); - s =DO_UPCAST (USBNetState, dev, dev); +QemuOpts *opts; +int idx; -memcpy (s->conf.macaddr.a, nd->macaddr,sizeof (nd->macaddr)); - s->conf.vlan = nd->vlan; - s->conf.peer = nd->netdev; - - s->nic =qemu_new_nic (&net_usbnet_info, &s->conf, - nd->model, nd->name, s); + opts =qemu_opts_parse (&qemu_net_opts, cmdline,NULL ); +if (!opts) { +return NULL ; + } +qemu_opt_set (opts,"type" ,"nic" ); +qemu_opt_set (opts,"model" ,"usb" ); -qemu_format_nic_info_str (&s->nic->nc, s->conf.macaddr.a); + idx =net_client_init (NULL , opts,0 ); +if (idx ==-1 ) { +return NULL ; + } -snprintf (s->usbstring_mac,sizeof (s->usbstring_mac), -"%02x%02x%02x%02x%02x%02x" , -0x40 , s->conf.macaddr.a[1 ], s->conf.macaddr.a[2 ], - s->conf.macaddr.a[3 ], s->conf.macaddr.a[4 ], s->conf.macaddr.a[5 ]); -fprintf (stderr,"usbnet: initialized mac %02x:%02x:%02x:%02x:%02x:%02x\n" , - s->conf.macaddr.a[0 ], s->conf.macaddr.a[1 ], s->conf.macaddr.a[2 ], - s->conf.macaddr.a[3 ], s->conf.macaddr.a[4 ], s->conf.macaddr.a[5 ]); - -return (USBDevice *) s; + dev =usb_create (NULL /* FIXME */ ,"QEMU USB Network Interface" ); +qdev_set_nic_properties (&dev->qdev, &nd_table[idx]); +qdev_init (&dev->qdev); +return dev; }static struct USBDeviceInfo net_info = { .qdev.name ="QEMU USB Network Interface" , + .qdev.alias ="usb-net" , .qdev.size =sizeof (USBNetState), .init = usb_net_initfn, .handle_packet = usb_generic_handle_packet,
@@ -1495,6 +1506,12 @@ static struct USBDeviceInfo net_info = { .handle_control = usb_net_handle_control, .handle_data = usb_net_handle_data, .handle_destroy = usb_net_handle_destroy, + .usbdevice_name = "net", + .usbdevice_init = usb_net_init, + .qdev.props = (Property []) { +DEFINE_NIC_PROPERTIES (USBNetState, conf), +DEFINE_PROP_END_OF_LIST (), + } };static void usb_net_register_devices (void )
hw/usb.h +0 -3
@@ -264,9 +264,6 @@ void usb_host_info(Monitor *mon);/* usb-hid.c */ void usb_hid_datain_cb (USBDevice *dev,void *opaque,void (*datain)(void *)); -/* usb-net.c */ -USBDevice *usb_net_init (NICInfo *nd); -/* usb-bt.c */ USBDevice *usb_bt_init (HCIInfo *hci);
vl.c +0 -18
@@ -2544,24 +2544,6 @@ static int usb_device_add(const char *devname, int is_hotplug)/* the other ones */ if (strstart (devname,"host:" , &p)) { dev =usb_host_device_open (p); - }else if (strstart (devname,"net:" , &p)) { -QemuOpts *opts; -int idx; - - opts =qemu_opts_parse (&qemu_net_opts, p,NULL ); -if (!opts) { -return -1 ; - } - -qemu_opt_set (opts,"type" ,"nic" ); -qemu_opt_set (opts,"model" ,"usb" ); - - idx =net_client_init (NULL , opts,0 ); -if (idx ==-1 ) { -return -1 ; - } - - dev =usb_net_init (&nd_table[idx]); }else if (!strcmp (devname,"bt" ) ||strstart (devname,"bt:" , &p)) { dev =usb_bt_init (devname[2 ] ?hci_init (p) :bt_new_hci (qemu_find_bt_vlan (0 )));
Signature · 1 line
1.6.5.2