From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 5/8] usb core: add migration support
Date: Mon, 24 Jan 2011 17:30:52 +0100 [thread overview]
Message-ID: <1295886655-32312-6-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1295886655-32312-1-git-send-email-kraxel@redhat.com>
Yes, seriously. There is no migration support at all for usb devices.
They loose state, especially the device address, and stop responding
because of that. Oops.
Luckily there is so much broken usb hardware out there that the guest
usually just kicks the device hard (via port reset and
reinitialization), then continues without a hitch. So we got away with
that in a surprising high number of cases.
The arrival of remote wakeup (which enables autosuspend support) changes
that picture though. The usb devices also forget that it they are
supposed to wakeup, so they don't do that. The host also doesn't notice
the device stopped working in case it suspended the device and thus
expects it waking up instead of polling it. Result is that your mouse
is dead.
Lets start fixing that. Add a vmstate struct for USBDevice.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/hw.h | 10 ++++++++++
hw/usb-bus.c | 16 ++++++++++++++++
hw/usb.h | 10 +++++-----
3 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/hw/hw.h b/hw/hw.h
index dd993de..5e24329 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -587,6 +587,16 @@ extern const VMStateDescription vmstate_i2c_slave;
.offset = vmstate_offset_value(_state, _field, i2c_slave), \
}
+extern const VMStateDescription vmstate_usb_device;
+
+#define VMSTATE_USB_DEVICE(_field, _state) { \
+ .name = (stringify(_field)), \
+ .size = sizeof(USBDevice), \
+ .vmsd = &vmstate_usb_device, \
+ .flags = VMS_STRUCT, \
+ .offset = vmstate_offset_value(_state, _field, USBDevice), \
+}
+
#define vmstate_offset_macaddr(_state, _field) \
vmstate_offset_array(_state, _field.a, uint8_t, \
sizeof(typeof_field(_state, _field)))
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 6e2e5fd..ac56fbc 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -23,6 +23,22 @@ static struct BusInfo usb_bus_info = {
static int next_usb_bus = 0;
static QTAILQ_HEAD(, USBBus) busses = QTAILQ_HEAD_INITIALIZER(busses);
+const VMStateDescription vmstate_usb_device = {
+ .name = "USBDevice",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .fields = (VMStateField []) {
+ VMSTATE_UINT8(addr, USBDevice),
+ VMSTATE_INT32(state, USBDevice),
+ VMSTATE_INT32(remote_wakeup, USBDevice),
+ VMSTATE_INT32(setup_state, USBDevice),
+ VMSTATE_INT32(setup_len, USBDevice),
+ VMSTATE_INT32(setup_index, USBDevice),
+ VMSTATE_UINT8_ARRAY(setup_buf, USBDevice, 8),
+ VMSTATE_END_OF_LIST(),
+ }
+};
+
void usb_bus_new(USBBus *bus, DeviceState *host)
{
qbus_create_inplace(&bus->qbus, &usb_bus_info, host, NULL);
diff --git a/hw/usb.h b/hw/usb.h
index 5c1da3e..d3d755d 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -165,13 +165,13 @@ struct USBDevice {
int auto_attach;
int attached;
- int state;
+ int32_t state;
uint8_t setup_buf[8];
uint8_t data_buf[1024];
- int remote_wakeup;
- int setup_state;
- int setup_len;
- int setup_index;
+ int32_t remote_wakeup;
+ int32_t setup_state;
+ int32_t setup_len;
+ int32_t setup_index;
QLIST_HEAD(, USBDescString) strings;
const USBDescDevice *device;
--
1.7.1
next prev parent reply other threads:[~2011-01-24 16:31 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-24 16:30 [Qemu-devel] [PULL 0/8] usb patch queue Gerd Hoffmann
2011-01-24 16:30 ` [Qemu-devel] [PATCH 1/8] add event queueing to USB HID Gerd Hoffmann
2011-01-24 16:30 ` [Qemu-devel] [PATCH 2/8] usb keyboard: add event event queue Gerd Hoffmann
2011-01-24 16:30 ` [Qemu-devel] [PATCH 3/8] usb hid: move head+n to common struct Gerd Hoffmann
2011-01-24 16:30 ` [Qemu-devel] [PATCH 4/8] vnc: fix numlock+capslock tracking Gerd Hoffmann
2011-01-28 13:36 ` [Qemu-devel] " Paolo Bonzini
2011-01-28 19:58 ` Gerd Hoffmann
2011-01-28 20:11 ` Anthony Liguori
2011-01-24 16:30 ` Gerd Hoffmann [this message]
2011-01-24 16:30 ` [Qemu-devel] [PATCH 6/8] usb hub: add migration support Gerd Hoffmann
2011-01-24 16:30 ` [Qemu-devel] [PATCH 7/8] usb hid: " Gerd Hoffmann
2011-01-24 16:30 ` [Qemu-devel] [PATCH 8/8] usb-bus: use snprintf Gerd Hoffmann
2011-02-17 20:00 ` [Qemu-devel] [PULL 0/8] usb patch queue Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1295886655-32312-6-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).