From a4055d85863be76a5fb70ecd001e7db5bc6bd5cb Mon Sep 17 00:00:00 2001 From: Zhang Shuaiyi Date: Wed, 29 Jun 2016 23:50:40 -0400 Subject: [PATCH 1/3] nec-usb-xhci: set the device state to USB_STATE_DEFAULT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch is a rough fix to "hw/usb/core.c:401: usb_handle_packet: Assertion `dev->state == 3' failed.". Qemu will crash when a usb3 device redirect to Windows7 VM via nec-usb-xhci. In extensible-host-controler-interface-usb-xhci.pdf P94(4.6.5 Address Device): • If the Block Set Address Request (BSR) flag = ‘1’ • If the slot is in the Enabled state: ... • Set the Slot State in the Output Slot Context to Default. BSR = ‘1’: Enabled state to Default state; BSR = ‘0’: Default state to Addressed state. Try to call usb_device_reset to set device state to USB_STATE_DEFAULT in xhci_address_slot wether bsr is zero. Signed-off-by: Zhang Shuaiyi Message-id: 1467258640-11921-1-git-send-email-zhang_syi@massclouds.com Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-xhci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 1a3377f038..976bfb0659 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -2364,6 +2364,8 @@ static TRBCCode xhci_address_slot(XHCIState *xhci, unsigned int slotid, slot->uport = uport; slot->ctx = octx; + /* Make sure device is in USB_STATE_DEFAULT state */ + usb_device_reset(dev); if (bsr) { slot_ctx[3] = SLOT_DEFAULT << SLOT_STATE_SHIFT; } else { @@ -2371,7 +2373,6 @@ static TRBCCode xhci_address_slot(XHCIState *xhci, unsigned int slotid, uint8_t buf[1]; slot_ctx[3] = (SLOT_ADDRESSED << SLOT_STATE_SHIFT) | slotid; - usb_device_reset(dev); memset(&p, 0, sizeof(p)); usb_packet_addbuf(&p, buf, sizeof(buf)); usb_packet_setup(&p, USB_TOKEN_OUT, From b91e013982e8bd44833974128f1581e427082880 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 23 Jun 2016 09:45:01 +0200 Subject: [PATCH 2/3] usb: add storage hotplug documentation Suggested-by: Paolo Bonzini Signed-off-by: Gerd Hoffmann Message-id: 1466667901-1341-1-git-send-email-kraxel@redhat.com --- docs/usb-storage.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/usb-storage.txt b/docs/usb-storage.txt index c5a3866eeb..fbc1f2edd8 100644 --- a/docs/usb-storage.txt +++ b/docs/usb-storage.txt @@ -40,6 +40,18 @@ numbers must be continuous, i.e. for three devices you must use 0+1+2. The 0+1+5 numbering from the "usb-uas" example isn't going to work with "usb-bot". +Starting with qemu version 2.7 usb-bot and usb-uas devices can be +hotplugged. In the hotplug case they are added with "attached = +false" so the guest will not see the device until the "attached" +property is explicitly set to true. That allows to attach one or more +scsi devices before making the device visible to the guest, i.e. the +workflow looks like this: + + (1) device-add usb-bot,id=foo + (2) device-add scsi-{hd,cd},bus=foo.0,lun=0 + (2b) optionally add more devices (luns 1 ... 15). + (3) scripts/qmp/qom-set foo.attached = true + enjoy, Gerd From 042ec47e6825cbea67b9ad957780204dc1d346bc Mon Sep 17 00:00:00 2001 From: Anthony PERARD Date: Thu, 23 Jun 2016 12:08:29 +0100 Subject: [PATCH 3/3] xen-usb: Fix 32bit build Signed-off-by: Anthony PERARD Reviewed-by: Juergen Gross Message-id: 20160623110829.22671-1-anthony.perard@citrix.com Signed-off-by: Gerd Hoffmann --- hw/usb/xen-usb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c index 0fd34c62c4..7bed0cebe3 100644 --- a/hw/usb/xen-usb.c +++ b/hw/usb/xen-usb.c @@ -253,7 +253,8 @@ static int usbback_init_packet(struct usbback_req *usbback_req) case USBIF_PIPE_TYPE_CTRL: packet->parameter = *(uint64_t *)usbback_req->req.u.ctrl; - TR_REQ(xendev, "ctrl parameter: %lx, buflen: %x\n", packet->parameter, + TR_REQ(xendev, "ctrl parameter: %"PRIx64", buflen: %x\n", + packet->parameter, usbback_req->req.buffer_length); break;