From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 35/54] xhci: iso xfer support
Date: Thu, 6 Sep 2012 09:12:36 +0200 [thread overview]
Message-ID: <1346915575-12369-36-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1346915575-12369-1-git-send-email-kraxel@redhat.com>
Add support for iso transfers.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/usb/hcd-xhci.c | 117 +++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 101 insertions(+), 16 deletions(-)
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 9077cb3..3c61bb8 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -325,9 +325,15 @@ typedef struct XHCITransfer {
unsigned int pkts;
unsigned int pktsize;
unsigned int cur_pkt;
+
+ uint64_t mfindex_kick;
} XHCITransfer;
typedef struct XHCIEPContext {
+ XHCIState *xhci;
+ unsigned int slotid;
+ unsigned int epid;
+
XHCIRing ring;
unsigned int next_xfer;
unsigned int comp_xfer;
@@ -337,6 +343,11 @@ typedef struct XHCIEPContext {
dma_addr_t pctx;
unsigned int max_psize;
uint32_t state;
+
+ /* iso xfer scheduling */
+ unsigned int interval;
+ int64_t mfindex_last;
+ QEMUTimer *kick_timer;
} XHCIEPContext;
typedef struct XHCISlot {
@@ -856,6 +867,12 @@ static void xhci_set_ep_state(XHCIState *xhci, XHCIEPContext *epctx,
epctx->state = state;
}
+static void xhci_ep_kick_timer(void *opaque)
+{
+ XHCIEPContext *epctx = opaque;
+ xhci_kick_ep(epctx->xhci, epctx->slotid, epctx->epid);
+}
+
static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned int slotid,
unsigned int epid, dma_addr_t pctx,
uint32_t *ctx)
@@ -877,6 +894,9 @@ static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned int slotid,
epctx = g_malloc(sizeof(XHCIEPContext));
memset(epctx, 0, sizeof(XHCIEPContext));
+ epctx->xhci = xhci;
+ epctx->slotid = slotid;
+ epctx->epid = epid;
slot->eps[epid-1] = epctx;
@@ -895,6 +915,10 @@ static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned int slotid,
usb_packet_init(&epctx->transfers[i].packet);
}
+ epctx->interval = 1 << (ctx[0] >> 16) & 0xff;
+ epctx->mfindex_last = 0;
+ epctx->kick_timer = qemu_new_timer_ns(vm_clock, xhci_ep_kick_timer, epctx);
+
epctx->state = EP_RUNNING;
ctx[0] &= ~EP_STATE_MASK;
ctx[0] |= EP_RUNNING;
@@ -934,6 +958,7 @@ static int xhci_ep_nuke_xfers(XHCIState *xhci, unsigned int slotid,
if (t->running_retry) {
t->running_retry = 0;
epctx->retry = NULL;
+ qemu_del_timer(epctx->kick_timer);
}
if (t->trbs) {
g_free(t->trbs);
@@ -969,6 +994,7 @@ static TRBCCode xhci_disable_ep(XHCIState *xhci, unsigned int slotid,
xhci_set_ep_state(xhci, epctx, EP_DISABLED);
+ qemu_free_timer(epctx->kick_timer);
g_free(epctx);
slot->eps[epid-1] = NULL;
@@ -1378,29 +1404,70 @@ static int xhci_fire_ctl_transfer(XHCIState *xhci, XHCITransfer *xfer)
return 0;
}
+static void xhci_calc_iso_kick(XHCIState *xhci, XHCITransfer *xfer,
+ XHCIEPContext *epctx, uint64_t mfindex)
+{
+ if (xfer->trbs[0].control & TRB_TR_SIA) {
+ uint64_t asap = ((mfindex + epctx->interval - 1) &
+ ~(epctx->interval-1));
+ if (asap >= epctx->mfindex_last &&
+ asap <= epctx->mfindex_last + epctx->interval * 4) {
+ xfer->mfindex_kick = epctx->mfindex_last + epctx->interval;
+ } else {
+ xfer->mfindex_kick = asap;
+ }
+ } else {
+ xfer->mfindex_kick = (xfer->trbs[0].control >> TRB_TR_FRAMEID_SHIFT)
+ & TRB_TR_FRAMEID_MASK;
+ xfer->mfindex_kick |= mfindex & ~0x3fff;
+ if (xfer->mfindex_kick < mfindex) {
+ xfer->mfindex_kick += 0x4000;
+ }
+ }
+}
+
+static void xhci_check_iso_kick(XHCIState *xhci, XHCITransfer *xfer,
+ XHCIEPContext *epctx, uint64_t mfindex)
+{
+ if (xfer->mfindex_kick > mfindex) {
+ qemu_mod_timer(epctx->kick_timer, qemu_get_clock_ns(vm_clock) +
+ (xfer->mfindex_kick - mfindex) * 125000);
+ xfer->running_retry = 1;
+ } else {
+ epctx->mfindex_last = xfer->mfindex_kick;
+ qemu_del_timer(epctx->kick_timer);
+ xfer->running_retry = 0;
+ }
+}
+
+
static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext *epctx)
{
+ uint64_t mfindex;
int ret;
DPRINTF("xhci_submit(slotid=%d,epid=%d)\n", xfer->slotid, xfer->epid);
xfer->in_xfer = epctx->type>>2;
- if (epctx->type == ET_ISO_IN || epctx->type == ET_ISO_OUT) {
- xfer->pkts = 1;
- } else {
- xfer->pkts = 0;
- }
-
switch(epctx->type) {
case ET_INTR_OUT:
case ET_INTR_IN:
case ET_BULK_OUT:
case ET_BULK_IN:
+ xfer->pkts = 0;
+ xfer->iso_xfer = false;
break;
case ET_ISO_OUT:
case ET_ISO_IN:
- FIXME();
+ xfer->pkts = 1;
+ xfer->iso_xfer = true;
+ mfindex = xhci_mfindex_get(xhci);
+ xhci_calc_iso_kick(xhci, xfer, epctx, mfindex);
+ xhci_check_iso_kick(xhci, xfer, epctx, mfindex);
+ if (xfer->running_retry) {
+ return -1;
+ }
break;
default:
fprintf(stderr, "xhci: unknown or unhandled EP "
@@ -1430,6 +1497,7 @@ static int xhci_fire_transfer(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext
static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid, unsigned int epid)
{
XHCIEPContext *epctx;
+ uint64_t mfindex;
int length;
int i;
@@ -1449,20 +1517,35 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid, unsigned int epid
}
if (epctx->retry) {
- /* retry nak'ed transfer */
XHCITransfer *xfer = epctx->retry;
int result;
trace_usb_xhci_xfer_retry(xfer);
assert(xfer->running_retry);
- if (xhci_setup_packet(xfer) < 0) {
- return;
- }
- result = usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
- if (result == USB_RET_NAK) {
- return;
+ if (xfer->iso_xfer) {
+ /* retry delayed iso transfer */
+ mfindex = xhci_mfindex_get(xhci);
+ xhci_check_iso_kick(xhci, xfer, epctx, mfindex);
+ if (xfer->running_retry) {
+ return;
+ }
+ if (xhci_setup_packet(xfer) < 0) {
+ return;
+ }
+ result = usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
+ assert(result != USB_RET_NAK);
+ xhci_complete_packet(xfer, result);
+ } else {
+ /* retry nak'ed transfer */
+ if (xhci_setup_packet(xfer) < 0) {
+ return;
+ }
+ result = usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
+ if (result == USB_RET_NAK) {
+ return;
+ }
+ xhci_complete_packet(xfer, result);
}
- xhci_complete_packet(xfer, result);
assert(!xfer->running_retry);
epctx->retry = NULL;
}
@@ -1514,7 +1597,9 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid, unsigned int epid
if (xhci_fire_transfer(xhci, xfer, epctx) >= 0) {
epctx->next_xfer = (epctx->next_xfer + 1) % TD_QUEUE;
} else {
- fprintf(stderr, "xhci: error firing data transfer\n");
+ if (!xfer->iso_xfer) {
+ fprintf(stderr, "xhci: error firing data transfer\n");
+ }
}
}
--
1.7.1
next prev parent reply other threads:[~2012-09-06 7:13 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-06 7:12 [Qemu-devel] [PULL 00/54] usb patch queue Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 01/54] usb: controllers do not need to check for babble themselves Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 02/54] usb-core: Don't set packet state to complete on a nak Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 03/54] usb-core: Add a usb_ep_find_packet_by_id() helper function Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 04/54] usb-core: Allow the first packet of a pipelined ep to complete immediately Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 05/54] Revert "ehci: don't flush cache on doorbell rings." Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 06/54] ehci: Validate qh is not changed unexpectedly by the guest Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 07/54] ehci: Update copyright headers to reflect recent work Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 08/54] ehci: Properly cleanup packets on cancel Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 09/54] ehci: Properly report completed but not yet processed packets to the guest Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 10/54] ehci: check for EHCI_ASYNC_FINISHED first in ehci_free_packet Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 11/54] ehci: trace guest bugs Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 12/54] ehci: add doorbell trace events Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 13/54] ehci: Add some additional ehci_trace_guest_bug() calls Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 14/54] ehci: Fix memory leak in handling of NAK-ed packets Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 15/54] ehci: Handle USB_RET_PROCERR in ehci_fill_queue Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 16/54] ehci: Correct a comment in fetchqtd packet processing Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 17/54] usb-redir: Never return USB_RET_NAK for async handled packets Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 18/54] usb-redir: Don't delay handling of open events to a bottom half Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 19/54] usb-redir: Get rid of async-struct get member Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 20/54] usb-redir: Get rid of local shadow copy of packet headers Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 21/54] usb-redir: Get rid of unused async-struct dev member Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 22/54] usb-redir: Move to core packet id and queue handling Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 23/54] usb-redir: Return babble when getting more bulk data then requested Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 24/54] usb-redir: Convert to new libusbredirparser 0.5 API Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 25/54] usb-redir: Set ep max_packet_size if available Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 26/54] usb-redir: Add a usbredir_reject_device helper function Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 27/54] usb-redir: Ensure our peer has the necessary caps when redirecting to XHCI Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 28/54] usb-redir: Enable pipelining for bulk endpoints Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 29/54] Better name usb braille device Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 30/54] usb-audio: fix usb version Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 31/54] xhci: rip out background transfer code Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 32/54] xhci: drop buffering Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 33/54] xhci: move device lookup into xhci_setup_packet Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 34/54] xhci: implement mfindex Gerd Hoffmann
2012-09-06 7:12 ` Gerd Hoffmann [this message]
2012-09-06 7:12 ` [Qemu-devel] [PATCH 36/54] xhci: trace cc codes in cleartext Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 37/54] xhci: add trace_usb_xhci_ep_set_dequeue Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 38/54] xhci: fix runtime write tracepoint Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 39/54] xhci: update register layout Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 40/54] xhci: update port handling Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 41/54] usb3: superspeed descriptors Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 42/54] usb3: superspeed endpoint companion Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 43/54] usb3: bos decriptor Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 44/54] usb-storage: usb3 support Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 45/54] xhci: fix & cleanup msi Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 46/54] xhci: rework interrupt handling Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 47/54] xhci: add msix support Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 48/54] xhci: move register update into xhci_intr_raise Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 49/54] xhci: add XHCIInterrupter Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 50/54] xhci: prepare xhci_runtime_{read, write} for multiple interrupters Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 51/54] xhci: pick target interrupter Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 52/54] xhci: support multiple interrupters Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 53/54] xhci: kill xhci_mem_{read, write} dispatcher functions Gerd Hoffmann
2012-09-06 7:12 ` [Qemu-devel] [PATCH 54/54] xhci: allow bytewise capability register reads Gerd Hoffmann
2012-09-10 13:23 ` [Qemu-devel] [PULL 00/54] usb patch queue Aurelien Jarno
2012-09-10 13:37 ` Gerd Hoffmann
2012-09-10 15:08 ` Andreas Färber
2012-09-10 17:49 ` Anthony Liguori
2012-09-11 5:46 ` Gerd Hoffmann
2012-09-11 17:22 ` Aurelien Jarno
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=1346915575-12369-36-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).