From: Junjie Cao <[email protected]>

An isochronous OUT transaction sent to EP0 must leave a pending
control read intact. Extend the IN mismatch test to cover this
direction as well.

Without the endpoint type check, the unexpected OUT packet changes
the control state and the following valid IN qTD halts.

Signed-off-by: Junjie Cao <[email protected]>
---
 tests/qtest/usb-hcd-ehci-test.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/tests/qtest/usb-hcd-ehci-test.c b/tests/qtest/usb-hcd-ehci-test.c
index 66070ee5c1..6097d470fb 100644
--- a/tests/qtest/usb-hcd-ehci-test.c
+++ b/tests/qtest/usb-hcd-ehci-test.c
@@ -38,6 +38,7 @@ static struct qhc ehci1;
 enum EHCIControlScenario {
     EHCI_CONTROL_ONLY,
     EHCI_ISO_IN_TO_CONTROL,
+    EHCI_ISO_OUT_TO_CONTROL,
 };
 
 typedef struct EHCITransferTest {
@@ -147,7 +148,7 @@ static void ehci_control_packet(EHCITransferTest *t, 
unsigned int pid,
     ehci_stop_schedules(t);
 }
 
-static void ehci_iso_to_control(EHCITransferTest *t)
+static void ehci_iso_to_control(EHCITransferTest *t, bool in)
 {
     QTestState *qts = t->qs->qts;
     uint8_t buffer[18];
@@ -159,7 +160,7 @@ static void ehci_iso_to_control(EHCITransferTest *t)
     qtest_writel(qts, t->itd + 4, EHCI_ITD_ACTIVE | EHCI_ITD_IOC |
                                   (sizeof(buffer) << 16));
     qtest_writel(qts, t->itd + 36, t->isodata); /* Address 0, endpoint 0. */
-    qtest_writel(qts, t->itd + 40, 64 | EHCI_ITD_IN);
+    qtest_writel(qts, t->itd + 40, 64 | (in ? EHCI_ITD_IN : 0));
     qtest_writel(qts, t->itd + 44, 1); /* One transaction per microframe. */
     for (i = 0; i < 1024; i++) {
         qtest_writel(qts, t->mem + 4 * i, t->itd);
@@ -176,7 +177,8 @@ static void ehci_iso_to_control(EHCITransferTest *t)
     }
     g_assert_cmpuint(i, <, 10);
     /* A non-iso endpoint must not transfer data or receive the packet. */
-    g_assert_cmphex(transaction, ==, EHCI_ITD_IOC);
+    g_assert_cmphex(transaction, ==, EHCI_ITD_IOC |
+                    (in ? 0 : sizeof(buffer) << 16));
     qtest_memread(qts, t->isodata, buffer, sizeof(buffer));
     for (i = 0; i < sizeof(buffer); i++) {
         g_assert_cmphex(buffer[i], ==, 0xa5);
@@ -197,7 +199,7 @@ static void test_ehci_control(gconstpointer opaque)
     qtest_memwrite(t.qs->qts, t.data, setup, sizeof(setup));
     ehci_control_packet(&t, EHCI_QTD_PID_SETUP, sizeof(setup));
     if (scenario != EHCI_CONTROL_ONLY) {
-        ehci_iso_to_control(&t);
+        ehci_iso_to_control(&t, scenario == EHCI_ISO_IN_TO_CONTROL);
     }
     /* The invalid iTD must leave the pending control transfer intact. */
     qtest_memset(t.qs->qts, t.data, 0xa5, sizeof(descriptor));
@@ -362,6 +364,9 @@ int main(int argc, char **argv)
         qtest_add_data_func("/ehci/pci/iso-in-to-control",
                             GUINT_TO_POINTER(EHCI_ISO_IN_TO_CONTROL),
                             test_ehci_control);
+        qtest_add_data_func("/ehci/pci/iso-out-to-control",
+                            GUINT_TO_POINTER(EHCI_ISO_OUT_TO_CONTROL),
+                            test_ehci_control);
     }
 
     qtest_start("-machine q35 -device ich9-usb-ehci1,bus=pcie.0,addr=1d.7,"
-- 
2.43.0


Reply via email to