Blame 0331-xhci-rip-out-background-transfer-code.patch

c8dfc6
From f019cdb4b17a0615e897ddac37f2ffa8866a4979 Mon Sep 17 00:00:00 2001
c8dfc6
From: Gerd Hoffmann <kraxel@redhat.com>
c8dfc6
Date: Fri, 17 Aug 2012 14:05:21 +0200
c8dfc6
Subject: [PATCH 331/366] xhci: rip out background transfer code
c8dfc6
c8dfc6
original xhci code (the one which used libusb directly) used to use
c8dfc6
'background transfers' for iso streams.  In upstream qemu the iso
c8dfc6
stream buffering is handled by usb-host & usb-redir, so we will
c8dfc6
never ever need this.  It has been left in as reference, but is dead
c8dfc6
code anyway.  Rip it out.
c8dfc6
c8dfc6
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
c8dfc6
---
c8dfc6
 hw/usb/hcd-xhci.c | 223 +-----------------------------------------------------
c8dfc6
 1 file changed, 4 insertions(+), 219 deletions(-)
c8dfc6
c8dfc6
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
c8dfc6
index 3eb27fa..c0a2476 100644
c8dfc6
--- a/hw/usb/hcd-xhci.c
c8dfc6
+++ b/hw/usb/hcd-xhci.c
c8dfc6
@@ -45,8 +45,6 @@
c8dfc6
 #define MAXPORTS (USB2_PORTS+USB3_PORTS)
c8dfc6
 
c8dfc6
 #define TD_QUEUE 24
c8dfc6
-#define BG_XFERS 8
c8dfc6
-#define BG_PKTS 8
c8dfc6
 
c8dfc6
 /* Very pessimistic, let's hope it's enough for all cases */
c8dfc6
 #define EV_QUEUE (((3*TD_QUEUE)+16)*MAXSLOTS)
c8dfc6
@@ -311,13 +309,11 @@ typedef struct XHCITransfer {
c8dfc6
     bool running_retry;
c8dfc6
     bool cancelled;
c8dfc6
     bool complete;
c8dfc6
-    bool backgrounded;
c8dfc6
     unsigned int iso_pkts;
c8dfc6
     unsigned int slotid;
c8dfc6
     unsigned int epid;
c8dfc6
     bool in_xfer;
c8dfc6
     bool iso_xfer;
c8dfc6
-    bool bg_xfer;
c8dfc6
 
c8dfc6
     unsigned int trb_count;
c8dfc6
     unsigned int trb_alloced;
c8dfc6
@@ -340,14 +336,9 @@ typedef struct XHCIEPContext {
c8dfc6
     unsigned int comp_xfer;
c8dfc6
     XHCITransfer transfers[TD_QUEUE];
c8dfc6
     XHCITransfer *retry;
c8dfc6
-    bool bg_running;
c8dfc6
-    bool bg_updating;
c8dfc6
-    unsigned int next_bg;
c8dfc6
-    XHCITransfer bg_transfers[BG_XFERS];
c8dfc6
     EPType type;
c8dfc6
     dma_addr_t pctx;
c8dfc6
     unsigned int max_psize;
c8dfc6
-    bool has_bg;
c8dfc6
     uint32_t state;
c8dfc6
 } XHCIEPContext;
c8dfc6
 
c8dfc6
@@ -866,10 +857,6 @@ static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned int slotid,
c8dfc6
     epctx->pctx = pctx;
c8dfc6
     epctx->max_psize = ctx[1]>>16;
c8dfc6
     epctx->max_psize *= 1+((ctx[1]>>8)&0xff);
c8dfc6
-    epctx->has_bg = false;
c8dfc6
-    if (epctx->type == ET_ISO_IN) {
c8dfc6
-        epctx->has_bg = true;
c8dfc6
-    }
c8dfc6
     DPRINTF("xhci: endpoint %d.%d max transaction (burst) size is %d\n",
c8dfc6
             epid/2, epid%2, epctx->max_psize);
c8dfc6
     for (i = 0; i < ARRAY_SIZE(epctx->transfers); i++) {
c8dfc6
@@ -916,9 +903,6 @@ static int xhci_ep_nuke_xfers(XHCIState *xhci, unsigned int slotid,
c8dfc6
             t->running_retry = 0;
c8dfc6
             epctx->retry = NULL;
c8dfc6
         }
c8dfc6
-        if (t->backgrounded) {
c8dfc6
-            t->backgrounded = 0;
c8dfc6
-        }
c8dfc6
         if (t->trbs) {
c8dfc6
             g_free(t->trbs);
c8dfc6
         }
c8dfc6
@@ -932,25 +916,6 @@ static int xhci_ep_nuke_xfers(XHCIState *xhci, unsigned int slotid,
c8dfc6
         t->data_length = t->data_alloced = 0;
c8dfc6
         xferi = (xferi + 1) % TD_QUEUE;
c8dfc6
     }
c8dfc6
-    if (epctx->has_bg) {
c8dfc6
-        xferi = epctx->next_bg;
c8dfc6
-        for (i = 0; i < BG_XFERS; i++) {
c8dfc6
-            XHCITransfer *t = &epctx->bg_transfers[xferi];
c8dfc6
-            if (t->running_async) {
c8dfc6
-                usb_cancel_packet(&t->packet);
c8dfc6
-                t->running_async = 0;
c8dfc6
-                t->cancelled = 1;
c8dfc6
-                DPRINTF("xhci: cancelling bg transfer %d, waiting for it to complete...\n", i);
c8dfc6
-                killed++;
c8dfc6
-            }
c8dfc6
-            if (t->data) {
c8dfc6
-                g_free(t->data);
c8dfc6
-            }
c8dfc6
-
c8dfc6
-            t->data = NULL;
c8dfc6
-            xferi = (xferi + 1) % BG_XFERS;
c8dfc6
-        }
c8dfc6
-    }
c8dfc6
     return killed;
c8dfc6
 }
c8dfc6
 
c8dfc6
@@ -1231,160 +1196,6 @@ static void xhci_stall_ep(XHCITransfer *xfer)
c8dfc6
 static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer,
c8dfc6
                        XHCIEPContext *epctx);
c8dfc6
 
c8dfc6
-static void xhci_bg_update(XHCIState *xhci, XHCIEPContext *epctx)
c8dfc6
-{
c8dfc6
-    if (epctx->bg_updating) {
c8dfc6
-        return;
c8dfc6
-    }
c8dfc6
-    DPRINTF("xhci_bg_update(%p, %p)\n", xhci, epctx);
c8dfc6
-    assert(epctx->has_bg);
c8dfc6
-    DPRINTF("xhci: fg=%d bg=%d\n", epctx->comp_xfer, epctx->next_bg);
c8dfc6
-    epctx->bg_updating = 1;
c8dfc6
-    while (epctx->transfers[epctx->comp_xfer].backgrounded &&
c8dfc6
-           epctx->bg_transfers[epctx->next_bg].complete) {
c8dfc6
-        XHCITransfer *fg = &epctx->transfers[epctx->comp_xfer];
c8dfc6
-        XHCITransfer *bg = &epctx->bg_transfers[epctx->next_bg];
c8dfc6
-#if 0
c8dfc6
-        DPRINTF("xhci: completing fg %d from bg %d.%d (stat: %d)\n",
c8dfc6
-                epctx->comp_xfer, epctx->next_bg, bg->cur_pkt,
c8dfc6
-                bg->usbxfer->iso_packet_desc[bg->cur_pkt].status
c8dfc6
-               );
c8dfc6
-#endif
c8dfc6
-        assert(epctx->type == ET_ISO_IN);
c8dfc6
-        assert(bg->iso_xfer);
c8dfc6
-        assert(bg->in_xfer);
c8dfc6
-        uint8_t *p = bg->data + bg->cur_pkt * bg->pktsize;
c8dfc6
-#if 0
c8dfc6
-        int len = bg->usbxfer->iso_packet_desc[bg->cur_pkt].actual_length;
c8dfc6
-        fg->status = libusb_to_ccode(bg->usbxfer->iso_packet_desc[bg->cur_pkt].status);
c8dfc6
-#else
c8dfc6
-        int len = 0;
c8dfc6
-        FIXME();
c8dfc6
-#endif
c8dfc6
-        fg->complete = 1;
c8dfc6
-        fg->backgrounded = 0;
c8dfc6
-
c8dfc6
-        if (fg->status == CC_STALL_ERROR) {
c8dfc6
-            xhci_stall_ep(fg);
c8dfc6
-        }
c8dfc6
-
c8dfc6
-        xhci_xfer_data(fg, p, len, 1, 0, 1);
c8dfc6
-
c8dfc6
-        epctx->comp_xfer++;
c8dfc6
-        if (epctx->comp_xfer == TD_QUEUE) {
c8dfc6
-            epctx->comp_xfer = 0;
c8dfc6
-        }
c8dfc6
-        DPRINTF("next fg xfer: %d\n", epctx->comp_xfer);
c8dfc6
-        bg->cur_pkt++;
c8dfc6
-        if (bg->cur_pkt == bg->pkts) {
c8dfc6
-            bg->complete = 0;
c8dfc6
-            if (xhci_submit(xhci, bg, epctx) < 0) {
c8dfc6
-                fprintf(stderr, "xhci: bg resubmit failed\n");
c8dfc6
-            }
c8dfc6
-            epctx->next_bg++;
c8dfc6
-            if (epctx->next_bg == BG_XFERS) {
c8dfc6
-                epctx->next_bg = 0;
c8dfc6
-            }
c8dfc6
-            DPRINTF("next bg xfer: %d\n", epctx->next_bg);
c8dfc6
-
c8dfc6
-        xhci_kick_ep(xhci, fg->slotid, fg->epid);
c8dfc6
-        }
c8dfc6
-    }
c8dfc6
-    epctx->bg_updating = 0;
c8dfc6
-}
c8dfc6
-
c8dfc6
-#if 0
c8dfc6
-static void xhci_xfer_cb(struct libusb_transfer *transfer)
c8dfc6
-{
c8dfc6
-    XHCIState *xhci;
c8dfc6
-    XHCITransfer *xfer;
c8dfc6
-
c8dfc6
-    xfer = (XHCITransfer *)transfer->user_data;
c8dfc6
-    xhci = xfer->xhci;
c8dfc6
-
c8dfc6
-    DPRINTF("xhci_xfer_cb(slot=%d, ep=%d, status=%d)\n", xfer->slotid,
c8dfc6
-            xfer->epid, transfer->status);
c8dfc6
-
c8dfc6
-    assert(xfer->slotid >= 1 && xfer->slotid <= MAXSLOTS);
c8dfc6
-    assert(xfer->epid >= 1 && xfer->epid <= 31);
c8dfc6
-
c8dfc6
-    if (xfer->cancelled) {
c8dfc6
-        DPRINTF("xhci: transfer cancelled, not reporting anything\n");
c8dfc6
-        xfer->running = 0;
c8dfc6
-        return;
c8dfc6
-    }
c8dfc6
-
c8dfc6
-    XHCIEPContext *epctx;
c8dfc6
-    XHCISlot *slot;
c8dfc6
-    slot = &xhci->slots[xfer->slotid-1];
c8dfc6
-    assert(slot->eps[xfer->epid-1]);
c8dfc6
-    epctx = slot->eps[xfer->epid-1];
c8dfc6
-
c8dfc6
-    if (xfer->bg_xfer) {
c8dfc6
-        DPRINTF("xhci: background transfer, updating\n");
c8dfc6
-        xfer->complete = 1;
c8dfc6
-        xfer->running = 0;
c8dfc6
-        xhci_bg_update(xhci, epctx);
c8dfc6
-        return;
c8dfc6
-    }
c8dfc6
-
c8dfc6
-    if (xfer->iso_xfer) {
c8dfc6
-        transfer->status = transfer->iso_packet_desc[0].status;
c8dfc6
-        transfer->actual_length = transfer->iso_packet_desc[0].actual_length;
c8dfc6
-    }
c8dfc6
-
c8dfc6
-    xfer->status = libusb_to_ccode(transfer->status);
c8dfc6
-
c8dfc6
-    xfer->complete = 1;
c8dfc6
-    xfer->running = 0;
c8dfc6
-
c8dfc6
-    if (transfer->status == LIBUSB_TRANSFER_STALL)
c8dfc6
-        xhci_stall_ep(xhci, epctx, xfer);
c8dfc6
-
c8dfc6
-    DPRINTF("xhci: transfer actual length = %d\n", transfer->actual_length);
c8dfc6
-
c8dfc6
-    if (xfer->in_xfer) {
c8dfc6
-        if (xfer->epid == 1) {
c8dfc6
-            xhci_xfer_data(xhci, xfer, xfer->data + 8,
c8dfc6
-                           transfer->actual_length, 1, 0, 1);
c8dfc6
-        } else {
c8dfc6
-            xhci_xfer_data(xhci, xfer, xfer->data,
c8dfc6
-                           transfer->actual_length, 1, 0, 1);
c8dfc6
-        }
c8dfc6
-    } else {
c8dfc6
-        xhci_xfer_data(xhci, xfer, NULL, transfer->actual_length, 0, 0, 1);
c8dfc6
-    }
c8dfc6
-
c8dfc6
-    xhci_kick_ep(xhci, xfer->slotid, xfer->epid);
c8dfc6
-}
c8dfc6
-
c8dfc6
-static int xhci_hle_control(XHCIState *xhci, XHCITransfer *xfer,
c8dfc6
-                            uint8_t bmRequestType, uint8_t bRequest,
c8dfc6
-                            uint16_t wValue, uint16_t wIndex, uint16_t wLength)
c8dfc6
-{
c8dfc6
-    uint16_t type_req = (bmRequestType << 8) | bRequest;
c8dfc6
-
c8dfc6
-    switch (type_req) {
c8dfc6
-        case 0x0000 | USB_REQ_SET_CONFIGURATION:
c8dfc6
-            DPRINTF("xhci: HLE switch configuration\n");
c8dfc6
-            return xhci_switch_config(xhci, xfer->slotid, wValue) == 0;
c8dfc6
-        case 0x0100 | USB_REQ_SET_INTERFACE:
c8dfc6
-            DPRINTF("xhci: HLE set interface altsetting\n");
c8dfc6
-            return xhci_set_iface_alt(xhci, xfer->slotid, wIndex, wValue) == 0;
c8dfc6
-        case 0x0200 | USB_REQ_CLEAR_FEATURE:
c8dfc6
-            if (wValue == 0) { // endpoint halt
c8dfc6
-                DPRINTF("xhci: HLE clear halt\n");
c8dfc6
-                return xhci_clear_halt(xhci, xfer->slotid, wIndex);
c8dfc6
-            }
c8dfc6
-        case 0x0000 | USB_REQ_SET_ADDRESS:
c8dfc6
-            fprintf(stderr, "xhci: warn: illegal SET_ADDRESS request\n");
c8dfc6
-            return 0;
c8dfc6
-        default:
c8dfc6
-            return 0;
c8dfc6
-    }
c8dfc6
-}
c8dfc6
-#endif
c8dfc6
-
c8dfc6
 static int xhci_setup_packet(XHCITransfer *xfer, USBDevice *dev)
c8dfc6
 {
c8dfc6
     USBEndpoint *ep;
c8dfc6
@@ -1559,9 +1370,7 @@ static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext *epctx
c8dfc6
         xfer->data_alloced = xfer->data_length;
c8dfc6
     }
c8dfc6
     if (epctx->type == ET_ISO_IN || epctx->type == ET_ISO_OUT) {
c8dfc6
-        if (!xfer->bg_xfer) {
c8dfc6
-            xfer->pkts = 1;
c8dfc6
-        }
c8dfc6
+        xfer->pkts = 1;
c8dfc6
     } else {
c8dfc6
         xfer->pkts = 0;
c8dfc6
     }
c8dfc6
@@ -1620,32 +1429,8 @@ static int xhci_fire_transfer(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext
c8dfc6
 
c8dfc6
     trace_usb_xhci_xfer_start(xfer, xfer->slotid, xfer->epid, length);
c8dfc6
 
c8dfc6
-    if (!epctx->has_bg) {
c8dfc6
-        xfer->data_length = length;
c8dfc6
-        xfer->backgrounded = 0;
c8dfc6
-        return xhci_submit(xhci, xfer, epctx);
c8dfc6
-    } else {
c8dfc6
-        if (!epctx->bg_running) {
c8dfc6
-            for (i = 0; i < BG_XFERS; i++) {
c8dfc6
-                XHCITransfer *t = &epctx->bg_transfers[i];
c8dfc6
-                t->xhci = xhci;
c8dfc6
-                t->epid = xfer->epid;
c8dfc6
-                t->slotid = xfer->slotid;
c8dfc6
-                t->pkts = BG_PKTS;
c8dfc6
-                t->pktsize = epctx->max_psize;
c8dfc6
-                t->data_length = t->pkts * t->pktsize;
c8dfc6
-                t->bg_xfer = 1;
c8dfc6
-                if (xhci_submit(xhci, t, epctx) < 0) {
c8dfc6
-                    fprintf(stderr, "xhci: bg submit failed\n");
c8dfc6
-                    return -1;
c8dfc6
-                }
c8dfc6
-            }
c8dfc6
-            epctx->bg_running = 1;
c8dfc6
-        }
c8dfc6
-        xfer->backgrounded = 1;
c8dfc6
-        xhci_bg_update(xhci, epctx);
c8dfc6
-        return 0;
c8dfc6
-    }
c8dfc6
+    xfer->data_length = length;
c8dfc6
+    return xhci_submit(xhci, xfer, epctx);
c8dfc6
 }
c8dfc6
 
c8dfc6
 static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid, unsigned int epid)
c8dfc6
@@ -1695,7 +1480,7 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid, unsigned int epid
c8dfc6
 
c8dfc6
     while (1) {
c8dfc6
         XHCITransfer *xfer = &epctx->transfers[epctx->next_xfer];
c8dfc6
-        if (xfer->running_async || xfer->running_retry || xfer->backgrounded) {
c8dfc6
+        if (xfer->running_async || xfer->running_retry) {
c8dfc6
             break;
c8dfc6
         }
c8dfc6
         length = xhci_ring_chain_length(xhci, &epctx->ring);
c8dfc6
-- 
c8dfc6
1.7.12
c8dfc6