xhci: Verify the device is still present in xhci_cmd_submit()
Make sure the USB device is still present before altering the xhci
"slot" for it. It appears some controllers will hang if a request is
sent to a port no longer connected.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
diff --git a/src/hw/usb-xhci.c b/src/hw/usb-xhci.c
index 0f717c6..08d1e32 100644
--- a/src/hw/usb-xhci.c
+++ b/src/hw/usb-xhci.c
@@ -780,6 +780,17 @@
static int xhci_cmd_submit(struct usb_xhci_s *xhci, struct xhci_inctx *inctx
, u32 flags)
{
+ if (inctx) {
+ struct xhci_slotctx *slot = (void*)&inctx[1 << xhci->context64];
+ u32 port = ((slot->ctx[1] >> 16) & 0xff) - 1;
+ u32 portsc = readl(&xhci->pr[port].portsc);
+ if (!(portsc & XHCI_PORTSC_CCS)) {
+ // Device no longer connected?!
+ xhci_print_port_state(1, __func__, port, portsc);
+ return -1;
+ }
+ }
+
mutex_lock(&xhci->cmds->lock);
xhci_trb_queue(xhci->cmds, inctx, 0, flags);
xhci_doorbell(xhci, 0, 0);