From patchwork Tue Dec 15 09:20:57 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 41172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3DF31B6F19 for ; Tue, 15 Dec 2009 20:21:44 +1100 (EST) Received: from localhost ([127.0.0.1]:55920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NKTbB-0001YL-A4 for incoming@patchwork.ozlabs.org; Tue, 15 Dec 2009 04:21:41 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NKTad-0001Xv-Ml for qemu-devel@nongnu.org; Tue, 15 Dec 2009 04:21:07 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NKTaZ-0001XF-2e for qemu-devel@nongnu.org; Tue, 15 Dec 2009 04:21:07 -0500 Received: from [199.232.76.173] (port=33193 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NKTaY-0001XC-Sg for qemu-devel@nongnu.org; Tue, 15 Dec 2009 04:21:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:61052) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NKTaY-0000Ev-BG for qemu-devel@nongnu.org; Tue, 15 Dec 2009 04:21:02 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBF9L1xj020878 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 15 Dec 2009 04:21:01 -0500 Received: from zweiblum.home.kraxel.org (vpn1-6-74.ams2.redhat.com [10.36.6.74]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBF9Kxgt027425; Tue, 15 Dec 2009 04:21:00 -0500 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id C3CD170FB8; Tue, 15 Dec 2009 10:20:58 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 15 Dec 2009 10:20:57 +0100 Message-Id: <1260868857-2869-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [FOR 0.12 PATCH RESENT] usb-net: use qdev for -usbdevice X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Rebased to master, adapted to device renaming by armbru, no other changes. Signed-off-by: Gerd Hoffmann --- hw/usb-net.c | 78 +++++++++++++++++++++++++++++++++++----------------------- hw/usb.h | 3 -- vl.c | 18 ------------- 3 files changed, 47 insertions(+), 52 deletions(-) diff --git a/hw/usb-net.c b/hw/usb-net.c index 122a0d8..9744dfa 100644 --- a/hw/usb-net.c +++ b/hw/usb-net.c @@ -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,43 +1455,45 @@ 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 */, "usb-net"); - 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 */, "usb-net"); + qdev_set_nic_properties(&dev->qdev, &nd_table[idx]); + qdev_init(&dev->qdev); + return dev; } static struct USBDeviceInfo net_info = { @@ -1496,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) diff --git a/hw/usb.h b/hw/usb.h index 0684588..106d174 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -258,9 +258,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); diff --git a/vl.c b/vl.c index c0d98f5..d0679cd 100644 --- a/vl.c +++ b/vl.c @@ -2654,24 +2654,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)));