Merge remote-tracking branch 'kraxel/usb.91' into staging

* kraxel/usb.91:
  usb-hcd-xhci: Update endpoint context dequeue pointer for streams too
  usb-hcd-xhci: Report completion of active transfer with CC_STOPPED on ep stop
  usb-hcd-xhci: Remove unused cancelled member from XHCITransfer
  usb-hcd-xhci: Remove unused sstreamsm member from XHCIStreamContext
  usb-host-libusb: Detach kernel drivers earlier
  usb-host-libusb: Configuration 0 may be a valid configuration
  usb-host-libusb: Fix reset handling

Message-id: 1382620267-18065-1-git-send-email-kraxel@redhat.com
Signed-off-by: Anthony Liguori <anthony@codemonkey.ws>
This commit is contained in:
Anthony Liguori 2013-10-31 17:00:25 +01:00
commit cb95ec1b83
2 changed files with 39 additions and 37 deletions

View File

@ -346,7 +346,6 @@ typedef struct XHCITransfer {
QEMUSGList sgl; QEMUSGList sgl;
bool running_async; bool running_async;
bool running_retry; bool running_retry;
bool cancelled;
bool complete; bool complete;
bool int_req; bool int_req;
unsigned int iso_pkts; unsigned int iso_pkts;
@ -374,7 +373,6 @@ struct XHCIStreamContext {
dma_addr_t pctx; dma_addr_t pctx;
unsigned int sct; unsigned int sct;
XHCIRing ring; XHCIRing ring;
XHCIStreamContext *sstreams;
}; };
struct XHCIEPContext { struct XHCIEPContext {
@ -506,6 +504,7 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
unsigned int epid, unsigned int streamid); unsigned int epid, unsigned int streamid);
static TRBCCode xhci_disable_ep(XHCIState *xhci, unsigned int slotid, static TRBCCode xhci_disable_ep(XHCIState *xhci, unsigned int slotid,
unsigned int epid); unsigned int epid);
static void xhci_xfer_report(XHCITransfer *xfer);
static void xhci_event(XHCIState *xhci, XHCIEvent *event, int v); static void xhci_event(XHCIState *xhci, XHCIEvent *event, int v);
static void xhci_write_event(XHCIState *xhci, XHCIEvent *event, int v); static void xhci_write_event(XHCIState *xhci, XHCIEvent *event, int v);
static USBEndpoint *xhci_epid_to_usbep(XHCIState *xhci, static USBEndpoint *xhci_epid_to_usbep(XHCIState *xhci,
@ -1132,7 +1131,6 @@ static void xhci_reset_streams(XHCIEPContext *epctx)
for (i = 0; i < epctx->nr_pstreams; i++) { for (i = 0; i < epctx->nr_pstreams; i++) {
epctx->pstreams[i].sct = -1; epctx->pstreams[i].sct = -1;
g_free(epctx->pstreams[i].sstreams);
} }
} }
@ -1145,15 +1143,8 @@ static void xhci_alloc_streams(XHCIEPContext *epctx, dma_addr_t base)
static void xhci_free_streams(XHCIEPContext *epctx) static void xhci_free_streams(XHCIEPContext *epctx)
{ {
int i;
assert(epctx->pstreams != NULL); assert(epctx->pstreams != NULL);
if (!epctx->lsa) {
for (i = 0; i < epctx->nr_pstreams; i++) {
g_free(epctx->pstreams[i].sstreams);
}
}
g_free(epctx->pstreams); g_free(epctx->pstreams);
epctx->pstreams = NULL; epctx->pstreams = NULL;
epctx->nr_pstreams = 0; epctx->nr_pstreams = 0;
@ -1195,6 +1186,7 @@ static XHCIStreamContext *xhci_find_stream(XHCIEPContext *epctx,
static void xhci_set_ep_state(XHCIState *xhci, XHCIEPContext *epctx, static void xhci_set_ep_state(XHCIState *xhci, XHCIEPContext *epctx,
XHCIStreamContext *sctx, uint32_t state) XHCIStreamContext *sctx, uint32_t state)
{ {
XHCIRing *ring = NULL;
uint32_t ctx[5]; uint32_t ctx[5];
uint32_t ctx2[2]; uint32_t ctx2[2];
@ -1205,6 +1197,7 @@ static void xhci_set_ep_state(XHCIState *xhci, XHCIEPContext *epctx,
/* update ring dequeue ptr */ /* update ring dequeue ptr */
if (epctx->nr_pstreams) { if (epctx->nr_pstreams) {
if (sctx != NULL) { if (sctx != NULL) {
ring = &sctx->ring;
xhci_dma_read_u32s(xhci, sctx->pctx, ctx2, sizeof(ctx2)); xhci_dma_read_u32s(xhci, sctx->pctx, ctx2, sizeof(ctx2));
ctx2[0] &= 0xe; ctx2[0] &= 0xe;
ctx2[0] |= sctx->ring.dequeue | sctx->ring.ccs; ctx2[0] |= sctx->ring.dequeue | sctx->ring.ccs;
@ -1212,8 +1205,12 @@ static void xhci_set_ep_state(XHCIState *xhci, XHCIEPContext *epctx,
xhci_dma_write_u32s(xhci, sctx->pctx, ctx2, sizeof(ctx2)); xhci_dma_write_u32s(xhci, sctx->pctx, ctx2, sizeof(ctx2));
} }
} else { } else {
ctx[2] = epctx->ring.dequeue | epctx->ring.ccs; ring = &epctx->ring;
ctx[3] = (epctx->ring.dequeue >> 16) >> 16; }
if (ring) {
ctx[2] = ring->dequeue | ring->ccs;
ctx[3] = (ring->dequeue >> 16) >> 16;
DPRINTF("xhci: set epctx: " DMA_ADDR_FMT " state=%d dequeue=%08x%08x\n", DPRINTF("xhci: set epctx: " DMA_ADDR_FMT " state=%d dequeue=%08x%08x\n",
epctx->pctx, state, ctx[3], ctx[2]); epctx->pctx, state, ctx[3], ctx[2]);
} }
@ -1311,15 +1308,18 @@ static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned int slotid,
return CC_SUCCESS; return CC_SUCCESS;
} }
static int xhci_ep_nuke_one_xfer(XHCITransfer *t) static int xhci_ep_nuke_one_xfer(XHCITransfer *t, TRBCCode report)
{ {
int killed = 0; int killed = 0;
if (report && (t->running_async || t->running_retry)) {
t->status = report;
xhci_xfer_report(t);
}
if (t->running_async) { if (t->running_async) {
usb_cancel_packet(&t->packet); usb_cancel_packet(&t->packet);
t->running_async = 0; t->running_async = 0;
t->cancelled = 1;
DPRINTF("xhci: cancelling transfer, waiting for it to complete\n");
killed = 1; killed = 1;
} }
if (t->running_retry) { if (t->running_retry) {
@ -1329,6 +1329,7 @@ static int xhci_ep_nuke_one_xfer(XHCITransfer *t)
timer_del(epctx->kick_timer); timer_del(epctx->kick_timer);
} }
t->running_retry = 0; t->running_retry = 0;
killed = 1;
} }
if (t->trbs) { if (t->trbs) {
g_free(t->trbs); g_free(t->trbs);
@ -1341,7 +1342,7 @@ static int xhci_ep_nuke_one_xfer(XHCITransfer *t)
} }
static int xhci_ep_nuke_xfers(XHCIState *xhci, unsigned int slotid, static int xhci_ep_nuke_xfers(XHCIState *xhci, unsigned int slotid,
unsigned int epid) unsigned int epid, TRBCCode report)
{ {
XHCISlot *slot; XHCISlot *slot;
XHCIEPContext *epctx; XHCIEPContext *epctx;
@ -1362,7 +1363,10 @@ static int xhci_ep_nuke_xfers(XHCIState *xhci, unsigned int slotid,
xferi = epctx->next_xfer; xferi = epctx->next_xfer;
for (i = 0; i < TD_QUEUE; i++) { for (i = 0; i < TD_QUEUE; i++) {
killed += xhci_ep_nuke_one_xfer(&epctx->transfers[xferi]); killed += xhci_ep_nuke_one_xfer(&epctx->transfers[xferi], report);
if (killed) {
report = 0; /* Only report once */
}
epctx->transfers[xferi].packet.ep = NULL; epctx->transfers[xferi].packet.ep = NULL;
xferi = (xferi + 1) % TD_QUEUE; xferi = (xferi + 1) % TD_QUEUE;
} }
@ -1392,7 +1396,7 @@ static TRBCCode xhci_disable_ep(XHCIState *xhci, unsigned int slotid,
return CC_SUCCESS; return CC_SUCCESS;
} }
xhci_ep_nuke_xfers(xhci, slotid, epid); xhci_ep_nuke_xfers(xhci, slotid, epid, 0);
epctx = slot->eps[epid-1]; epctx = slot->eps[epid-1];
@ -1434,7 +1438,7 @@ static TRBCCode xhci_stop_ep(XHCIState *xhci, unsigned int slotid,
return CC_EP_NOT_ENABLED_ERROR; return CC_EP_NOT_ENABLED_ERROR;
} }
if (xhci_ep_nuke_xfers(xhci, slotid, epid) > 0) { if (xhci_ep_nuke_xfers(xhci, slotid, epid, CC_STOPPED) > 0) {
fprintf(stderr, "xhci: FIXME: endpoint stopped w/ xfers running, " fprintf(stderr, "xhci: FIXME: endpoint stopped w/ xfers running, "
"data might be lost\n"); "data might be lost\n");
} }
@ -1479,7 +1483,7 @@ static TRBCCode xhci_reset_ep(XHCIState *xhci, unsigned int slotid,
return CC_CONTEXT_STATE_ERROR; return CC_CONTEXT_STATE_ERROR;
} }
if (xhci_ep_nuke_xfers(xhci, slotid, epid) > 0) { if (xhci_ep_nuke_xfers(xhci, slotid, epid, 0) > 0) {
fprintf(stderr, "xhci: FIXME: endpoint reset w/ xfers running, " fprintf(stderr, "xhci: FIXME: endpoint reset w/ xfers running, "
"data might be lost\n"); "data might be lost\n");
} }
@ -1736,14 +1740,12 @@ static int xhci_complete_packet(XHCITransfer *xfer)
xfer->running_async = 1; xfer->running_async = 1;
xfer->running_retry = 0; xfer->running_retry = 0;
xfer->complete = 0; xfer->complete = 0;
xfer->cancelled = 0;
return 0; return 0;
} else if (xfer->packet.status == USB_RET_NAK) { } else if (xfer->packet.status == USB_RET_NAK) {
trace_usb_xhci_xfer_nak(xfer); trace_usb_xhci_xfer_nak(xfer);
xfer->running_async = 0; xfer->running_async = 0;
xfer->running_retry = 1; xfer->running_retry = 1;
xfer->complete = 0; xfer->complete = 0;
xfer->cancelled = 0;
return 0; return 0;
} else { } else {
xfer->running_async = 0; xfer->running_async = 0;
@ -2474,7 +2476,7 @@ static void xhci_detach_slot(XHCIState *xhci, USBPort *uport)
for (ep = 0; ep < 31; ep++) { for (ep = 0; ep < 31; ep++) {
if (xhci->slots[slot].eps[ep]) { if (xhci->slots[slot].eps[ep]) {
xhci_ep_nuke_xfers(xhci, slot+1, ep+1); xhci_ep_nuke_xfers(xhci, slot + 1, ep + 1, 0);
} }
} }
xhci->slots[slot].uport = NULL; xhci->slots[slot].uport = NULL;
@ -3289,7 +3291,7 @@ static void xhci_complete(USBPort *port, USBPacket *packet)
XHCITransfer *xfer = container_of(packet, XHCITransfer, packet); XHCITransfer *xfer = container_of(packet, XHCITransfer, packet);
if (packet->status == USB_RET_REMOVE_FROM_QUEUE) { if (packet->status == USB_RET_REMOVE_FROM_QUEUE) {
xhci_ep_nuke_one_xfer(xfer); xhci_ep_nuke_one_xfer(xfer, 0);
return; return;
} }
xhci_complete_packet(xfer); xhci_complete_packet(xfer);

View File

@ -137,6 +137,7 @@ static QTAILQ_HEAD(, USBHostDevice) hostdevs =
static void usb_host_auto_check(void *unused); static void usb_host_auto_check(void *unused);
static void usb_host_release_interfaces(USBHostDevice *s); static void usb_host_release_interfaces(USBHostDevice *s);
static void usb_host_nodev(USBHostDevice *s); static void usb_host_nodev(USBHostDevice *s);
static void usb_host_detach_kernel(USBHostDevice *s);
static void usb_host_attach_kernel(USBHostDevice *s); static void usb_host_attach_kernel(USBHostDevice *s);
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
@ -787,10 +788,13 @@ static int usb_host_open(USBHostDevice *s, libusb_device *dev)
goto fail; goto fail;
} }
libusb_get_device_descriptor(dev, &s->ddesc);
s->dev = dev; s->dev = dev;
s->bus_num = bus_num; s->bus_num = bus_num;
s->addr = addr; s->addr = addr;
usb_host_detach_kernel(s);
libusb_get_device_descriptor(dev, &s->ddesc);
usb_host_get_port(s->dev, s->port, sizeof(s->port)); usb_host_get_port(s->dev, s->port, sizeof(s->port));
usb_ep_init(udev); usb_ep_init(udev);
@ -992,15 +996,14 @@ static int usb_host_claim_interfaces(USBHostDevice *s, int configuration)
udev->ninterfaces = 0; udev->ninterfaces = 0;
udev->configuration = 0; udev->configuration = 0;
if (configuration == 0) {
/* address state - ignore */
return USB_RET_SUCCESS;
}
usb_host_detach_kernel(s); usb_host_detach_kernel(s);
rc = libusb_get_active_config_descriptor(s->dev, &conf); rc = libusb_get_active_config_descriptor(s->dev, &conf);
if (rc != 0) { if (rc != 0) {
if (rc == LIBUSB_ERROR_NOT_FOUND) {
/* address state - ignore */
return USB_RET_SUCCESS;
}
return USB_RET_STALL; return USB_RET_STALL;
} }
@ -1052,7 +1055,6 @@ static void usb_host_set_config(USBHostDevice *s, int config, USBPacket *p)
trace_usb_host_set_config(s->bus_num, s->addr, config); trace_usb_host_set_config(s->bus_num, s->addr, config);
usb_host_release_interfaces(s); usb_host_release_interfaces(s);
usb_host_detach_kernel(s);
rc = libusb_set_configuration(s->dh, config); rc = libusb_set_configuration(s->dh, config);
if (rc != 0) { if (rc != 0) {
usb_host_libusb_error("libusb_set_configuration", rc); usb_host_libusb_error("libusb_set_configuration", rc);
@ -1256,16 +1258,14 @@ static void usb_host_flush_ep_queue(USBDevice *dev, USBEndpoint *ep)
static void usb_host_handle_reset(USBDevice *udev) static void usb_host_handle_reset(USBDevice *udev)
{ {
USBHostDevice *s = USB_HOST_DEVICE(udev); USBHostDevice *s = USB_HOST_DEVICE(udev);
int rc;
trace_usb_host_reset(s->bus_num, s->addr); trace_usb_host_reset(s->bus_num, s->addr);
if (udev->configuration == 0) { rc = libusb_reset_device(s->dh);
return; if (rc != 0) {
usb_host_nodev(s);
} }
usb_host_release_interfaces(s);
libusb_reset_device(s->dh);
usb_host_claim_interfaces(s, 0);
usb_host_ep_update(s);
} }
/* /*