|
Hans de Goede |
c8dfc6 |
From 9f7a9361a816479ca109e1747e45d40135fad3b0 Mon Sep 17 00:00:00 2001
|
|
Hans de Goede |
c8dfc6 |
From: Gerd Hoffmann <kraxel@redhat.com>
|
|
Hans de Goede |
c8dfc6 |
Date: Fri, 24 Aug 2012 14:13:08 +0200
|
|
Hans de Goede |
c8dfc6 |
Subject: [PATCH 335/366] xhci: iso xfer support
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
Add support for iso transfers.
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
|
|
Hans de Goede |
c8dfc6 |
---
|
|
Hans de Goede |
c8dfc6 |
hw/usb/hcd-xhci.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++--------
|
|
Hans de Goede |
c8dfc6 |
1 file changed, 101 insertions(+), 16 deletions(-)
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
|
|
Hans de Goede |
c8dfc6 |
index 9077cb3..3c61bb8 100644
|
|
Hans de Goede |
c8dfc6 |
--- a/hw/usb/hcd-xhci.c
|
|
Hans de Goede |
c8dfc6 |
+++ b/hw/usb/hcd-xhci.c
|
|
Hans de Goede |
c8dfc6 |
@@ -325,9 +325,15 @@ typedef struct XHCITransfer {
|
|
Hans de Goede |
c8dfc6 |
unsigned int pkts;
|
|
Hans de Goede |
c8dfc6 |
unsigned int pktsize;
|
|
Hans de Goede |
c8dfc6 |
unsigned int cur_pkt;
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
+ uint64_t mfindex_kick;
|
|
Hans de Goede |
c8dfc6 |
} XHCITransfer;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
typedef struct XHCIEPContext {
|
|
Hans de Goede |
c8dfc6 |
+ XHCIState *xhci;
|
|
Hans de Goede |
c8dfc6 |
+ unsigned int slotid;
|
|
Hans de Goede |
c8dfc6 |
+ unsigned int epid;
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
XHCIRing ring;
|
|
Hans de Goede |
c8dfc6 |
unsigned int next_xfer;
|
|
Hans de Goede |
c8dfc6 |
unsigned int comp_xfer;
|
|
Hans de Goede |
c8dfc6 |
@@ -337,6 +343,11 @@ typedef struct XHCIEPContext {
|
|
Hans de Goede |
c8dfc6 |
dma_addr_t pctx;
|
|
Hans de Goede |
c8dfc6 |
unsigned int max_psize;
|
|
Hans de Goede |
c8dfc6 |
uint32_t state;
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
+ /* iso xfer scheduling */
|
|
Hans de Goede |
c8dfc6 |
+ unsigned int interval;
|
|
Hans de Goede |
c8dfc6 |
+ int64_t mfindex_last;
|
|
Hans de Goede |
c8dfc6 |
+ QEMUTimer *kick_timer;
|
|
Hans de Goede |
c8dfc6 |
} XHCIEPContext;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
typedef struct XHCISlot {
|
|
Hans de Goede |
c8dfc6 |
@@ -856,6 +867,12 @@ static void xhci_set_ep_state(XHCIState *xhci, XHCIEPContext *epctx,
|
|
Hans de Goede |
c8dfc6 |
epctx->state = state;
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
+static void xhci_ep_kick_timer(void *opaque)
|
|
Hans de Goede |
c8dfc6 |
+{
|
|
Hans de Goede |
c8dfc6 |
+ XHCIEPContext *epctx = opaque;
|
|
Hans de Goede |
c8dfc6 |
+ xhci_kick_ep(epctx->xhci, epctx->slotid, epctx->epid);
|
|
Hans de Goede |
c8dfc6 |
+}
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned int slotid,
|
|
Hans de Goede |
c8dfc6 |
unsigned int epid, dma_addr_t pctx,
|
|
Hans de Goede |
c8dfc6 |
uint32_t *ctx)
|
|
Hans de Goede |
c8dfc6 |
@@ -877,6 +894,9 @@ static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned int slotid,
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
epctx = g_malloc(sizeof(XHCIEPContext));
|
|
Hans de Goede |
c8dfc6 |
memset(epctx, 0, sizeof(XHCIEPContext));
|
|
Hans de Goede |
c8dfc6 |
+ epctx->xhci = xhci;
|
|
Hans de Goede |
c8dfc6 |
+ epctx->slotid = slotid;
|
|
Hans de Goede |
c8dfc6 |
+ epctx->epid = epid;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
slot->eps[epid-1] = epctx;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
@@ -895,6 +915,10 @@ static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned int slotid,
|
|
Hans de Goede |
c8dfc6 |
usb_packet_init(&epctx->transfers[i].packet);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
+ epctx->interval = 1 << (ctx[0] >> 16) & 0xff;
|
|
Hans de Goede |
c8dfc6 |
+ epctx->mfindex_last = 0;
|
|
Hans de Goede |
c8dfc6 |
+ epctx->kick_timer = qemu_new_timer_ns(vm_clock, xhci_ep_kick_timer, epctx);
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
epctx->state = EP_RUNNING;
|
|
Hans de Goede |
c8dfc6 |
ctx[0] &= ~EP_STATE_MASK;
|
|
Hans de Goede |
c8dfc6 |
ctx[0] |= EP_RUNNING;
|
|
Hans de Goede |
c8dfc6 |
@@ -934,6 +958,7 @@ static int xhci_ep_nuke_xfers(XHCIState *xhci, unsigned int slotid,
|
|
Hans de Goede |
c8dfc6 |
if (t->running_retry) {
|
|
Hans de Goede |
c8dfc6 |
t->running_retry = 0;
|
|
Hans de Goede |
c8dfc6 |
epctx->retry = NULL;
|
|
Hans de Goede |
c8dfc6 |
+ qemu_del_timer(epctx->kick_timer);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
if (t->trbs) {
|
|
Hans de Goede |
c8dfc6 |
g_free(t->trbs);
|
|
Hans de Goede |
c8dfc6 |
@@ -969,6 +994,7 @@ static TRBCCode xhci_disable_ep(XHCIState *xhci, unsigned int slotid,
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
xhci_set_ep_state(xhci, epctx, EP_DISABLED);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
+ qemu_free_timer(epctx->kick_timer);
|
|
Hans de Goede |
c8dfc6 |
g_free(epctx);
|
|
Hans de Goede |
c8dfc6 |
slot->eps[epid-1] = NULL;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
@@ -1378,29 +1404,70 @@ static int xhci_fire_ctl_transfer(XHCIState *xhci, XHCITransfer *xfer)
|
|
Hans de Goede |
c8dfc6 |
return 0;
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
+static void xhci_calc_iso_kick(XHCIState *xhci, XHCITransfer *xfer,
|
|
Hans de Goede |
c8dfc6 |
+ XHCIEPContext *epctx, uint64_t mfindex)
|
|
Hans de Goede |
c8dfc6 |
+{
|
|
Hans de Goede |
c8dfc6 |
+ if (xfer->trbs[0].control & TRB_TR_SIA) {
|
|
Hans de Goede |
c8dfc6 |
+ uint64_t asap = ((mfindex + epctx->interval - 1) &
|
|
Hans de Goede |
c8dfc6 |
+ ~(epctx->interval-1));
|
|
Hans de Goede |
c8dfc6 |
+ if (asap >= epctx->mfindex_last &&
|
|
Hans de Goede |
c8dfc6 |
+ asap <= epctx->mfindex_last + epctx->interval * 4) {
|
|
Hans de Goede |
c8dfc6 |
+ xfer->mfindex_kick = epctx->mfindex_last + epctx->interval;
|
|
Hans de Goede |
c8dfc6 |
+ } else {
|
|
Hans de Goede |
c8dfc6 |
+ xfer->mfindex_kick = asap;
|
|
Hans de Goede |
c8dfc6 |
+ }
|
|
Hans de Goede |
c8dfc6 |
+ } else {
|
|
Hans de Goede |
c8dfc6 |
+ xfer->mfindex_kick = (xfer->trbs[0].control >> TRB_TR_FRAMEID_SHIFT)
|
|
Hans de Goede |
c8dfc6 |
+ & TRB_TR_FRAMEID_MASK;
|
|
Hans de Goede |
c8dfc6 |
+ xfer->mfindex_kick |= mfindex & ~0x3fff;
|
|
Hans de Goede |
c8dfc6 |
+ if (xfer->mfindex_kick < mfindex) {
|
|
Hans de Goede |
c8dfc6 |
+ xfer->mfindex_kick += 0x4000;
|
|
Hans de Goede |
c8dfc6 |
+ }
|
|
Hans de Goede |
c8dfc6 |
+ }
|
|
Hans de Goede |
c8dfc6 |
+}
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
+static void xhci_check_iso_kick(XHCIState *xhci, XHCITransfer *xfer,
|
|
Hans de Goede |
c8dfc6 |
+ XHCIEPContext *epctx, uint64_t mfindex)
|
|
Hans de Goede |
c8dfc6 |
+{
|
|
Hans de Goede |
c8dfc6 |
+ if (xfer->mfindex_kick > mfindex) {
|
|
Hans de Goede |
c8dfc6 |
+ qemu_mod_timer(epctx->kick_timer, qemu_get_clock_ns(vm_clock) +
|
|
Hans de Goede |
c8dfc6 |
+ (xfer->mfindex_kick - mfindex) * 125000);
|
|
Hans de Goede |
c8dfc6 |
+ xfer->running_retry = 1;
|
|
Hans de Goede |
c8dfc6 |
+ } else {
|
|
Hans de Goede |
c8dfc6 |
+ epctx->mfindex_last = xfer->mfindex_kick;
|
|
Hans de Goede |
c8dfc6 |
+ qemu_del_timer(epctx->kick_timer);
|
|
Hans de Goede |
c8dfc6 |
+ xfer->running_retry = 0;
|
|
Hans de Goede |
c8dfc6 |
+ }
|
|
Hans de Goede |
c8dfc6 |
+}
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext *epctx)
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
+ uint64_t mfindex;
|
|
Hans de Goede |
c8dfc6 |
int ret;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
DPRINTF("xhci_submit(slotid=%d,epid=%d)\n", xfer->slotid, xfer->epid);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
xfer->in_xfer = epctx->type>>2;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- if (epctx->type == ET_ISO_IN || epctx->type == ET_ISO_OUT) {
|
|
Hans de Goede |
c8dfc6 |
- xfer->pkts = 1;
|
|
Hans de Goede |
c8dfc6 |
- } else {
|
|
Hans de Goede |
c8dfc6 |
- xfer->pkts = 0;
|
|
Hans de Goede |
c8dfc6 |
- }
|
|
Hans de Goede |
c8dfc6 |
-
|
|
Hans de Goede |
c8dfc6 |
switch(epctx->type) {
|
|
Hans de Goede |
c8dfc6 |
case ET_INTR_OUT:
|
|
Hans de Goede |
c8dfc6 |
case ET_INTR_IN:
|
|
Hans de Goede |
c8dfc6 |
case ET_BULK_OUT:
|
|
Hans de Goede |
c8dfc6 |
case ET_BULK_IN:
|
|
Hans de Goede |
c8dfc6 |
+ xfer->pkts = 0;
|
|
Hans de Goede |
c8dfc6 |
+ xfer->iso_xfer = false;
|
|
Hans de Goede |
c8dfc6 |
break;
|
|
Hans de Goede |
c8dfc6 |
case ET_ISO_OUT:
|
|
Hans de Goede |
c8dfc6 |
case ET_ISO_IN:
|
|
Hans de Goede |
c8dfc6 |
- FIXME();
|
|
Hans de Goede |
c8dfc6 |
+ xfer->pkts = 1;
|
|
Hans de Goede |
c8dfc6 |
+ xfer->iso_xfer = true;
|
|
Hans de Goede |
c8dfc6 |
+ mfindex = xhci_mfindex_get(xhci);
|
|
Hans de Goede |
c8dfc6 |
+ xhci_calc_iso_kick(xhci, xfer, epctx, mfindex);
|
|
Hans de Goede |
c8dfc6 |
+ xhci_check_iso_kick(xhci, xfer, epctx, mfindex);
|
|
Hans de Goede |
c8dfc6 |
+ if (xfer->running_retry) {
|
|
Hans de Goede |
c8dfc6 |
+ return -1;
|
|
Hans de Goede |
c8dfc6 |
+ }
|
|
Hans de Goede |
c8dfc6 |
break;
|
|
Hans de Goede |
c8dfc6 |
default:
|
|
Hans de Goede |
c8dfc6 |
fprintf(stderr, "xhci: unknown or unhandled EP "
|
|
Hans de Goede |
c8dfc6 |
@@ -1430,6 +1497,7 @@ static int xhci_fire_transfer(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext
|
|
Hans de Goede |
c8dfc6 |
static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid, unsigned int epid)
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
XHCIEPContext *epctx;
|
|
Hans de Goede |
c8dfc6 |
+ uint64_t mfindex;
|
|
Hans de Goede |
c8dfc6 |
int length;
|
|
Hans de Goede |
c8dfc6 |
int i;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
@@ -1449,20 +1517,35 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid, unsigned int epid
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
if (epctx->retry) {
|
|
Hans de Goede |
c8dfc6 |
- /* retry nak'ed transfer */
|
|
Hans de Goede |
c8dfc6 |
XHCITransfer *xfer = epctx->retry;
|
|
Hans de Goede |
c8dfc6 |
int result;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
trace_usb_xhci_xfer_retry(xfer);
|
|
Hans de Goede |
c8dfc6 |
assert(xfer->running_retry);
|
|
Hans de Goede |
c8dfc6 |
- if (xhci_setup_packet(xfer) < 0) {
|
|
Hans de Goede |
c8dfc6 |
- return;
|
|
Hans de Goede |
c8dfc6 |
- }
|
|
Hans de Goede |
c8dfc6 |
- result = usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
|
|
Hans de Goede |
c8dfc6 |
- if (result == USB_RET_NAK) {
|
|
Hans de Goede |
c8dfc6 |
- return;
|
|
Hans de Goede |
c8dfc6 |
+ if (xfer->iso_xfer) {
|
|
Hans de Goede |
c8dfc6 |
+ /* retry delayed iso transfer */
|
|
Hans de Goede |
c8dfc6 |
+ mfindex = xhci_mfindex_get(xhci);
|
|
Hans de Goede |
c8dfc6 |
+ xhci_check_iso_kick(xhci, xfer, epctx, mfindex);
|
|
Hans de Goede |
c8dfc6 |
+ if (xfer->running_retry) {
|
|
Hans de Goede |
c8dfc6 |
+ return;
|
|
Hans de Goede |
c8dfc6 |
+ }
|
|
Hans de Goede |
c8dfc6 |
+ if (xhci_setup_packet(xfer) < 0) {
|
|
Hans de Goede |
c8dfc6 |
+ return;
|
|
Hans de Goede |
c8dfc6 |
+ }
|
|
Hans de Goede |
c8dfc6 |
+ result = usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
|
|
Hans de Goede |
c8dfc6 |
+ assert(result != USB_RET_NAK);
|
|
Hans de Goede |
c8dfc6 |
+ xhci_complete_packet(xfer, result);
|
|
Hans de Goede |
c8dfc6 |
+ } else {
|
|
Hans de Goede |
c8dfc6 |
+ /* retry nak'ed transfer */
|
|
Hans de Goede |
c8dfc6 |
+ if (xhci_setup_packet(xfer) < 0) {
|
|
Hans de Goede |
c8dfc6 |
+ return;
|
|
Hans de Goede |
c8dfc6 |
+ }
|
|
Hans de Goede |
c8dfc6 |
+ result = usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
|
|
Hans de Goede |
c8dfc6 |
+ if (result == USB_RET_NAK) {
|
|
Hans de Goede |
c8dfc6 |
+ return;
|
|
Hans de Goede |
c8dfc6 |
+ }
|
|
Hans de Goede |
c8dfc6 |
+ xhci_complete_packet(xfer, result);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
- xhci_complete_packet(xfer, result);
|
|
Hans de Goede |
c8dfc6 |
assert(!xfer->running_retry);
|
|
Hans de Goede |
c8dfc6 |
epctx->retry = NULL;
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
@@ -1514,7 +1597,9 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid, unsigned int epid
|
|
Hans de Goede |
c8dfc6 |
if (xhci_fire_transfer(xhci, xfer, epctx) >= 0) {
|
|
Hans de Goede |
c8dfc6 |
epctx->next_xfer = (epctx->next_xfer + 1) % TD_QUEUE;
|
|
Hans de Goede |
c8dfc6 |
} else {
|
|
Hans de Goede |
c8dfc6 |
- fprintf(stderr, "xhci: error firing data transfer\n");
|
|
Hans de Goede |
c8dfc6 |
+ if (!xfer->iso_xfer) {
|
|
Hans de Goede |
c8dfc6 |
+ fprintf(stderr, "xhci: error firing data transfer\n");
|
|
Hans de Goede |
c8dfc6 |
+ }
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
--
|
|
Hans de Goede |
c8dfc6 |
1.7.12
|
|
Hans de Goede |
c8dfc6 |
|