[PATCH v4 08/22] tests/qtest/usb-hcd-xhci: Deliver msix interrupts

Nicholas Piggin posted 22 patches 6 months, 2 weeks ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>
[PATCH v4 08/22] tests/qtest/usb-hcd-xhci: Deliver msix interrupts
Posted by Nicholas Piggin 6 months, 2 weeks ago
msix
---
 tests/qtest/usb-hcd-xhci-test.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tests/qtest/usb-hcd-xhci-test.c b/tests/qtest/usb-hcd-xhci-test.c
index 7f801f8f1a0..2eecc8d9f26 100644
--- a/tests/qtest/usb-hcd-xhci-test.c
+++ b/tests/qtest/usb-hcd-xhci-test.c
@@ -48,6 +48,8 @@ typedef struct XHCIQState {
     QPCIBar bar;
     uint64_t barsize;
     uint32_t fingerprint;
+    uint64_t guest_msix_addr;
+    uint32_t msix_data;
 
     /* In-memory arrays */
     uint64_t dc_base_array;
@@ -279,7 +281,8 @@ static void xhci_db_writel(XHCIQState *s, uint32_t db, uint32_t value)
 
 static bool xhci_test_isr(XHCIQState *s)
 {
-    return xhci_op_readl(s, XHCI_OPER_REG_USBSTS) & XHCI_USBSTS_EINT;
+    return qpci_msix_test_interrupt(s->dev, 0,
+                                    s->guest_msix_addr, s->msix_data);
 }
 
 static void wait_event_trb(XHCIQState *s, XHCITRB *trb)
@@ -298,6 +301,9 @@ static void wait_event_trb(XHCIQState *s, XHCITRB *trb)
         qtest_clock_step(s->parent->qts, 10000);
     }
 
+    value = xhci_op_readl(s, XHCI_OPER_REG_USBSTS);
+    g_assert(value & XHCI_USBSTS_EINT);
+
     /* With MSI-X enabled, IMAN IP is cleared after raising the interrupt */
     value = xhci_intr_readl(s, 0, XHCI_INTR_REG_IMAN);
     g_assert(!(value & XHCI_IMAN_IP));
@@ -395,7 +401,12 @@ static void xhci_enable_device(XHCIQState *s)
     uint32_t value;
     int i;
 
+    s->guest_msix_addr = xhci_guest_zalloc(s, 4);
+    s->msix_data = 0x1234abcd;
+
     qpci_msix_enable(s->dev);
+    qpci_msix_set_entry(s->dev, 0, s->guest_msix_addr, s->msix_data);
+    qpci_msix_set_masked(s->dev, 0, false);
 
     hcsparams1 = xhci_cap_readl(s, XHCI_HCCAP_REG_HCSPARAMS1);
     s->maxports = (hcsparams1 >> 24) & 0xff;
@@ -640,6 +651,7 @@ static void xhci_disable_device(XHCIQState *s)
     guest_free(&s->parent->alloc, s->command_ring.addr);
     guest_free(&s->parent->alloc, s->event_ring_seg);
     guest_free(&s->parent->alloc, s->dc_base_array);
+    guest_free(&s->parent->alloc, s->guest_msix_addr);
 }
 
 struct QEMU_PACKED usb_msd_cbw {
-- 
2.47.1
Re: [PATCH v4 08/22] tests/qtest/usb-hcd-xhci: Deliver msix interrupts
Posted by Philippe Mathieu-Daudé 6 months, 2 weeks ago
On 2/5/25 05:30, Nicholas Piggin wrote:
> msix

Hmm? :)

> ---
>   tests/qtest/usb-hcd-xhci-test.c | 14 +++++++++++++-
>   1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/qtest/usb-hcd-xhci-test.c b/tests/qtest/usb-hcd-xhci-test.c
> index 7f801f8f1a0..2eecc8d9f26 100644
> --- a/tests/qtest/usb-hcd-xhci-test.c
> +++ b/tests/qtest/usb-hcd-xhci-test.c
> @@ -48,6 +48,8 @@ typedef struct XHCIQState {
>       QPCIBar bar;
>       uint64_t barsize;
>       uint32_t fingerprint;
> +    uint64_t guest_msix_addr;
> +    uint32_t msix_data;
>   
>       /* In-memory arrays */
>       uint64_t dc_base_array;
> @@ -279,7 +281,8 @@ static void xhci_db_writel(XHCIQState *s, uint32_t db, uint32_t value)
>   
>   static bool xhci_test_isr(XHCIQState *s)
>   {
> -    return xhci_op_readl(s, XHCI_OPER_REG_USBSTS) & XHCI_USBSTS_EINT;
> +    return qpci_msix_test_interrupt(s->dev, 0,
> +                                    s->guest_msix_addr, s->msix_data);
>   }
>   
>   static void wait_event_trb(XHCIQState *s, XHCITRB *trb)
> @@ -298,6 +301,9 @@ static void wait_event_trb(XHCIQState *s, XHCITRB *trb)
>           qtest_clock_step(s->parent->qts, 10000);
>       }
>   
> +    value = xhci_op_readl(s, XHCI_OPER_REG_USBSTS);
> +    g_assert(value & XHCI_USBSTS_EINT);
> +
>       /* With MSI-X enabled, IMAN IP is cleared after raising the interrupt */
>       value = xhci_intr_readl(s, 0, XHCI_INTR_REG_IMAN);
>       g_assert(!(value & XHCI_IMAN_IP));
> @@ -395,7 +401,12 @@ static void xhci_enable_device(XHCIQState *s)
>       uint32_t value;
>       int i;
>   
> +    s->guest_msix_addr = xhci_guest_zalloc(s, 4);
> +    s->msix_data = 0x1234abcd;
> +
>       qpci_msix_enable(s->dev);
> +    qpci_msix_set_entry(s->dev, 0, s->guest_msix_addr, s->msix_data);
> +    qpci_msix_set_masked(s->dev, 0, false);
>   
>       hcsparams1 = xhci_cap_readl(s, XHCI_HCCAP_REG_HCSPARAMS1);
>       s->maxports = (hcsparams1 >> 24) & 0xff;
> @@ -640,6 +651,7 @@ static void xhci_disable_device(XHCIQState *s)
>       guest_free(&s->parent->alloc, s->command_ring.addr);
>       guest_free(&s->parent->alloc, s->event_ring_seg);
>       guest_free(&s->parent->alloc, s->dc_base_array);
> +    guest_free(&s->parent->alloc, s->guest_msix_addr);
>   }
>   
>   struct QEMU_PACKED usb_msd_cbw {
Re: [PATCH v4 08/22] tests/qtest/usb-hcd-xhci: Deliver msix interrupts
Posted by Nicholas Piggin 6 months, 2 weeks ago
On Fri May 2, 2025 at 6:24 PM AEST, Philippe Mathieu-Daudé wrote:
> On 2/5/25 05:30, Nicholas Piggin wrote:
>> msix
>
> Hmm? :)

Oops, thanks. Too much juggling around of the different patch series.
This depends on some of the libqos pci changes so I split it out (and
it's probably nicer to be separate anyway).

Thanks,
Nick