Skip to contentSkip to conversation

Fix XHCI errors with isochronous transfer

PATCH In review Yuri Benditovich 3 participants 6 messages Jan 28, 2019 – Jan 31, 2019

lore
Share & tools
lore
#0 lore raw

cover Fix XHCI errors with isochronous transfer

These patches fix errors causing isochronous transfer to stop when XHCI works with redirected devices:
* avoid halt of isochronous endpoints
* implement underrun/overrun events

Note that checkpatch emits errors for patch 2 on usage by 'slotid-1' statement. I still leave it for readability as this construction is used in this file everywhere.

Yuri Benditovich (2):
usb: XHCI shall not halt isochronous endpoints
usb: implement XHCI underrun/overrun events

 hw/usb/hcd-xhci.c | 22 ++++++++++++++++++++--
 hw/usb/hcd-xhci.h |  1 +
 2 files changed, 21 insertions(+), 2 deletions(-)
Signature · 1 line
2.9.5
#1 lore raw

PATCH 1/2 usb: XHCI shall not halt isochronous endpoints

According to the XHCI spec (4.10.2) the controller never halts isochronous endpoints. This commit prevent stop of isochronous streaming when sporadic errors status received from backends.

---
 hw/usb/hcd-xhci.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/usb/hcd-xhci.c +5 -0
index 8f1a01a..1a8fd96 100644
@@ -1571,6 +1571,11 @@ static void xhci_stall_ep(XHCITransfer *xfer)
     uint32_t err;
     XHCIStreamContext *sctx;
 
+    if (epctx->type == ET_ISO_IN || epctx->type == ET_ISO_OUT) {
+        /* never halt isoch endpoints, 4.10.2 */
+        return;
+    }
+
     if (epctx->nr_pstreams) {
         sctx = xhci_find_stream(epctx, xfer->streamid, &err);
         if (sctx == NULL) {
Signature · 1 line
2.9.5
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] usb: XHCI shall not halt isochronous endpoints

Quoted 9 lines · Yuri Benditovich

According to the XHCI spec (4.10.2) the controller never halts isochronous endpoints. This commit prevent stop of isochronous streaming when sporadic errors status received from backends.

Quoted 23 lines

---
hw/usb/hcd-xhci.c | 5 +++++

1 file changed, 5 insertions(+)
hw/usb/hcd-xhci.c +5 -0
index 8f1a01a..1a8fd96 100644
@@ -1571,6 +1571,11 @@ static void xhci_stall_ep(XHCITransfer *xfer)
    uint32_t err;
    XHCIStreamContext *sctx;
 
+    if (epctx->type == ET_ISO_IN || epctx->type == ET_ISO_OUT) {
+        /* never halt isoch endpoints, 4.10.2 */
+        return;
+    }
+
    if (epctx->nr_pstreams) {
        sctx = xhci_find_stream(epctx, xfer->streamid, &err);
        if (sctx == NULL) {
Signature · 1 line
2.9.5
#3 lore raw

PATCH 2/2 usb: implement XHCI underrun/overrun events

In reply to Yuri Benditovich

Implement underrun/overrun events of isochronous endpoints according to XHCI spec (4.10.3.1)
Guest software restarts data streaming when receives these events. The XHCI reports these events using interrupter assigned to the slot (as these events do not have TRB), so current commit adds the field of assigned interrupter to the XHCISlot structure. Guest software assigns interrupter to the slot on 'Address Device' and 'Evaluate Context' commands.

---
 hw/usb/hcd-xhci.c | 17 +++++++++++++++--
 hw/usb/hcd-xhci.h |  1 +
 2 files changed, 16 insertions(+), 2 deletions(-)
hw/usb/hcd-xhci.c +15 -2
index 1a8fd96..19c64f7 100644
@@ -1949,6 +1949,16 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
     while (1) {
         length = xhci_ring_chain_length(xhci, ring);
         if (length <= 0) {
+            if (epctx->type == ET_ISO_OUT || epctx->type == ET_ISO_IN) {
+                /* 4.10.3.1 */
+                XHCIEvent ev = { ER_TRANSFER };
+                ev.ccode  = epctx->type == ET_ISO_IN ?
+                    CC_RING_OVERRUN : CC_RING_UNDERRUN;
+                ev.slotid = epctx->slotid;
+                ev.epid   = epctx->epid;
+                ev.ptr    = epctx->ring.dequeue;
+                xhci_event(xhci, &ev, xhci->slots[epctx->slotid-1].intr);
+            }
             break;
         }
         xfer = xhci_ep_alloc_xfer(epctx, length);
@@ -2028,6 +2038,7 @@ static TRBCCode xhci_disable_slot(XHCIState *xhci, unsigned int slotid)
     xhci->slots[slotid-1].enabled = 0;
     xhci->slots[slotid-1].addressed = 0;
     xhci->slots[slotid-1].uport = NULL;
+    xhci->slots[slotid-1].intr = 0;
     return CC_SUCCESS;
 }
 
@@ -2127,6 +2138,7 @@ static TRBCCode xhci_address_slot(XHCIState *xhci, unsigned int slotid,
     slot = &xhci->slots[slotid-1];
     slot->uport = uport;
     slot->ctx = octx;
+    slot->intr = get_field(slot_ctx[2], TRB_INTR);
 
     /* Make sure device is in USB_STATE_DEFAULT state */
     usb_device_reset(dev);
@@ -2300,8 +2312,9 @@ static TRBCCode xhci_evaluate_slot(XHCIState *xhci, unsigned int slotid,
 
         slot_ctx[1] &= ~0xFFFF; /* max exit latency */
         slot_ctx[1] |= islot_ctx[1] & 0xFFFF;
-        slot_ctx[2] &= ~0xFF00000; /* interrupter target */
-        slot_ctx[2] |= islot_ctx[2] & 0xFF000000;
+        /* update interrupter target field */
+        xhci->slots[slotid-1].intr = get_field(islot_ctx[2], TRB_INTR);
+        set_field(&slot_ctx[2], xhci->slots[slotid-1].intr, TRB_INTR);
 
         DPRINTF("xhci: output slot context: %08x %08x %08x %08x\n",
                 slot_ctx[0], slot_ctx[1], slot_ctx[2], slot_ctx[3]);
hw/usb/hcd-xhci.h +1 -0
index fc36a4c..240caa4 100644
@@ -140,6 +140,7 @@ typedef struct XHCIPort {
 typedef struct XHCISlot {
     bool enabled;
     bool addressed;
+    uint16_t intr;
     dma_addr_t ctx;
     USBPort *uport;
     XHCIEPContext *eps[31];
Signature · 1 line
2.9.5
Reviewed-by on v1 2/2
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] usb: implement XHCI underrun/overrun events

Quoted 13 lines · Yuri Benditovich

Implement underrun/overrun events of isochronous endpoints according to XHCI spec (4.10.3.1)
Guest software restarts data streaming when receives these events. The XHCI reports these events using interrupter assigned to the slot (as these events do not have TRB), so current commit adds the field of assigned interrupter to the XHCISlot structure. Guest software assigns interrupter to the slot on 'Address Device' and 'Evaluate Context' commands.

Quoted 1 line
Quoted 69 lines

---
hw/usb/hcd-xhci.c | 17 +++++++++++++++--
hw/usb/hcd-xhci.h | 1 +

2 files changed, 16 insertions(+), 2 deletions(-)
hw/usb/hcd-xhci.c +15 -2
index 1a8fd96..19c64f7 100644
@@ -1949,6 +1949,16 @@ static void xhci_kick_epctx(XHCIEPContext *epctx, unsigned int streamid)
    while (1) {
        length = xhci_ring_chain_length(xhci, ring);
        if (length <= 0) {
+            if (epctx->type == ET_ISO_OUT || epctx->type == ET_ISO_IN) {
+                /* 4.10.3.1 */
+                XHCIEvent ev = { ER_TRANSFER };
+                ev.ccode  = epctx->type == ET_ISO_IN ?
+                    CC_RING_OVERRUN : CC_RING_UNDERRUN;
+                ev.slotid = epctx->slotid;
+                ev.epid   = epctx->epid;
+                ev.ptr    = epctx->ring.dequeue;
+                xhci_event(xhci, &ev, xhci->slots[epctx->slotid-1].intr);
+            }
            break;
        }
        xfer = xhci_ep_alloc_xfer(epctx, length);
@@ -2028,6 +2038,7 @@ static TRBCCode xhci_disable_slot(XHCIState *xhci, unsigned int slotid)
    xhci->slots[slotid-1].enabled = 0;
    xhci->slots[slotid-1].addressed = 0;
    xhci->slots[slotid-1].uport = NULL;
+    xhci->slots[slotid-1].intr = 0;
    return CC_SUCCESS;
 }
 
@@ -2127,6 +2138,7 @@ static TRBCCode xhci_address_slot(XHCIState *xhci, unsigned int slotid,
    slot = &xhci->slots[slotid-1];
    slot->uport = uport;
    slot->ctx = octx;
+    slot->intr = get_field(slot_ctx[2], TRB_INTR);
 
    /* Make sure device is in USB_STATE_DEFAULT state */
    usb_device_reset(dev);
@@ -2300,8 +2312,9 @@ static TRBCCode xhci_evaluate_slot(XHCIState *xhci, unsigned int slotid,
 
        slot_ctx[1] &= ~0xFFFF; /* max exit latency */
        slot_ctx[1] |= islot_ctx[1] & 0xFFFF;
-        slot_ctx[2] &= ~0xFF00000; /* interrupter target */
-        slot_ctx[2] |= islot_ctx[2] & 0xFF000000;
+        /* update interrupter target field */
+        xhci->slots[slotid-1].intr = get_field(islot_ctx[2], TRB_INTR);
+        set_field(&slot_ctx[2], xhci->slots[slotid-1].intr, TRB_INTR);
 
        DPRINTF("xhci: output slot context: %08x %08x %08x %08x\n",
                slot_ctx[0], slot_ctx[1], slot_ctx[2], slot_ctx[3]);
hw/usb/hcd-xhci.h +1 -0
index fc36a4c..240caa4 100644
@@ -140,6 +140,7 @@ typedef struct XHCIPort {
 typedef struct XHCISlot {
    bool enabled;
    bool addressed;
+    uint16_t intr;
    dma_addr_t ctx;
    USBPort *uport;
    XHCIEPContext *eps[31];
Signature · 1 line
2.9.5
#5 lore raw
In reply to Yuri Benditovich
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Subject: [Qemu-devel] [PATCH 0/2] Fix XHCI errors with isochronous transfer
Type: series
Message-id: [email protected]

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 Switched to a new branch 'test'
e2d10359a8 usb: implement XHCI underrun/overrun events 2e60bc48ea usb: XHCI shall not halt isochronous endpoints

=== OUTPUT BEGIN ===
1/2 Checking commit 2e60bc48ea8c (usb: XHCI shall not halt isochronous endpoints) 2/2 Checking commit e2d10359a81c (usb: implement XHCI underrun/overrun events)
ERROR: spaces required around that '-' (ctx:VxV)
#36: FILE: hw/usb/hcd-xhci.c:1960:

+                xhci_event(xhci, &ev, xhci->slots[epctx->slotid-1].intr);
                                                                ^

ERROR: spaces required around that '-' (ctx:VxV)
#45: FILE: hw/usb/hcd-xhci.c:2041:

+    xhci->slots[slotid-1].intr = 0;
                       ^

ERROR: spaces required around that '-' (ctx:VxV)
#64: FILE: hw/usb/hcd-xhci.c:2316:

+        xhci->slots[slotid-1].intr = get_field(islot_ctx[2], TRB_INTR);
                           ^

ERROR: spaces required around that '-' (ctx:VxV)
#65: FILE: hw/usb/hcd-xhci.c:2317:

+        set_field(&slot_ctx[2], xhci->slots[slotid-1].intr, TRB_INTR);
                                                   ^

total: 4 errors, 0 warnings, 48 lines checked

Patch 2/2 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]