From nobody Sat Feb 7 06:55:46 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1572127086; cv=none; d=zoho.com; s=zohoarc; b=GytLOVHyn25LhcyCfquttaaK7CVKAdPDyCpKxSKiv/XVE+78k6ckiQ+M/WxaeP/2dSQfg5KPUrhun2UQZENqs8KaqXbkaEjADlRkUFp82XrWDBjijtvgUIoEx9ZcyXfHf1WlNqQrp+/owULv+IHaFraEcbHYoczfeTyQVWwVcCk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572127086; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/MkpAHK2Hskh7ImAHNPKaD4E2/muC8lHemAshCkwGhQ=; b=mYN2KxSFLKb7HAMpzcYxzmd5ByqgHv3Vjy6EPscM3Y+xpBJv5eApJUTppUfKvwCPJI1yO0ldnWck3YzS6iTgnyynbKuwU9B7N1YIwhA4lm2zoELo24ForIV0KuOD9J2z3cpKGKxPpf2ErLG8icYRNNzduRmHrTOELs/bCv4KRl4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157212708663471.09947132456114; Sat, 26 Oct 2019 14:58:06 -0700 (PDT) Received: from localhost ([::1]:42820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOU4T-0001Jb-9J for importer@patchew.org; Sat, 26 Oct 2019 17:58:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34281) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOTzd-0007Pl-9Q for qemu-devel@nongnu.org; Sat, 26 Oct 2019 17:53:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iOTzb-0003f0-A9 for qemu-devel@nongnu.org; Sat, 26 Oct 2019 17:53:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49360) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iOTzZ-0003eR-AG for qemu-devel@nongnu.org; Sat, 26 Oct 2019 17:53:03 -0400 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 15535C049E10 for ; Sat, 26 Oct 2019 21:53:00 +0000 (UTC) Received: by mail-qk1-f199.google.com with SMTP id k67so6388468qkc.3 for ; Sat, 26 Oct 2019 14:53:00 -0700 (PDT) Received: from redhat.com (bzq-79-176-10-77.red.bezeqint.net. [79.176.10.77]) by smtp.gmail.com with ESMTPSA id t1sm3553913qkt.87.2019.10.26.14.52.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Oct 2019 14:52:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=/MkpAHK2Hskh7ImAHNPKaD4E2/muC8lHemAshCkwGhQ=; b=RUdTDxpiX6jvUM/70M9Cb0Ut0IP1F08IUQhc293m5YcLSuaLj+wXPbPE2KvSuDCHmJ 5CIFXMHiO38mhvicP9puZ62Kya7oflO6fjnkSsRWurPsn68cu/vPvQa7JaTw2qmmWFX0 O2gvu0ybrQPHnXGLwgWDai5YyngIMJ/UxwlgEHl0gX6l7PEylcqJUSR0VJlgCIWMr48H yZKQvWjCTgLbP93EW5FkXzcdPk63PfU50KoDaCOSG8yvRVCfcY9qzBO2Uu1eO+18wr27 XDKl58FGZKjhBxhAFqOtsJd7gdPhKIW6P63nq+yqWM+KBuG2NrAfltq0oup7HyNe444I o0aw== X-Gm-Message-State: APjAAAVQ9a5VOd49Zmo3UYNBj9gMh3Eq5F/1LTwfr8qUVatWIYeJtRCj oZC5AZsMKxJUyJVUA0oXyP84buygH83ogdL6pmhLOhmn9tcxpN2eh6PKEdhAQcn18DkMhonmnav bjO5bMUizqyyRtRw= X-Received: by 2002:a37:7904:: with SMTP id u4mr9306702qkc.267.1572126778798; Sat, 26 Oct 2019 14:52:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqwAzx1qIgCzYr9e4d27a90G5Z+OB39mlgo9BglGyG1wWfhsHVigqqNuYwhaJcZlhSYS7khCgA== X-Received: by 2002:a37:7904:: with SMTP id u4mr9306683qkc.267.1572126778473; Sat, 26 Oct 2019 14:52:58 -0700 (PDT) Date: Sat, 26 Oct 2019 17:52:53 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 20/25] libqos: add MSI-X callbacks to QVirtioPCIDevice Message-ID: <20191026193824.11926-21-mst@redhat.com> References: <20191026193824.11926-1-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20191026193824.11926-1-mst@redhat.com> X-Mailer: git-send-email 2.22.0.678.g13338e74b8 X-Mutt-Fcc: =sent X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Peter Maydell , Thomas Huth , Sergio Lopez , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi The MSI-X vectors are programmed differently in the VIRTIO 1.0 and Legacy interfaces. Introduce callbacks so different implementations can be used depending on the interface version. Signed-off-by: Stefan Hajnoczi Reviewed-by: Sergio Lopez Reviewed-by: Thomas Huth Message-Id: <20191023100425.12168-13-stefanha@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/libqos/virtio-pci.c | 37 ++++++++++++++++++++++++++++--------- tests/libqos/virtio-pci.h | 12 ++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c index e4fa318dcc..0725777a8d 100644 --- a/tests/libqos/virtio-pci.c +++ b/tests/libqos/virtio-pci.c @@ -281,6 +281,31 @@ const QVirtioBus qvirtio_pci =3D { .virtqueue_kick =3D qvirtio_pci_virtqueue_kick, }; =20 +static void qvirtio_pci_set_config_vector(QVirtioPCIDevice *d, uint16_t en= try) +{ + uint16_t vector; + + qpci_io_writew(d->pdev, d->bar, VIRTIO_MSI_CONFIG_VECTOR, entry); + vector =3D qpci_io_readw(d->pdev, d->bar, VIRTIO_MSI_CONFIG_VECTOR); + g_assert_cmphex(vector, !=3D, VIRTIO_MSI_NO_VECTOR); +} + +static void qvirtio_pci_set_queue_vector(QVirtioPCIDevice *d, uint16_t vq_= idx, + uint16_t entry) +{ + uint16_t vector; + + qvirtio_pci_queue_select(&d->vdev, vq_idx); + qpci_io_writew(d->pdev, d->bar, VIRTIO_MSI_QUEUE_VECTOR, entry); + vector =3D qpci_io_readw(d->pdev, d->bar, VIRTIO_MSI_QUEUE_VECTOR); + g_assert_cmphex(vector, !=3D, VIRTIO_MSI_NO_VECTOR); +} + +static const QVirtioPCIMSIXOps qvirtio_pci_msix_ops_legacy =3D { + .set_config_vector =3D qvirtio_pci_set_config_vector, + .set_queue_vector =3D qvirtio_pci_set_queue_vector, +}; + void qvirtio_pci_device_enable(QVirtioPCIDevice *d) { qpci_device_enable(d->pdev); @@ -295,7 +320,6 @@ void qvirtio_pci_device_disable(QVirtioPCIDevice *d) void qvirtqueue_pci_msix_setup(QVirtioPCIDevice *d, QVirtQueuePCI *vqpci, QGuestAllocator *alloc, uint16_t e= ntry) { - uint16_t vector; uint32_t control; uint64_t off; =20 @@ -321,16 +345,12 @@ void qvirtqueue_pci_msix_setup(QVirtioPCIDevice *d, Q= VirtQueuePCI *vqpci, off + PCI_MSIX_ENTRY_VECTOR_CTRL, control & ~PCI_MSIX_ENTRY_CTRL_MASKBIT); =20 - qvirtio_pci_queue_select(&d->vdev, vqpci->vq.index); - qpci_io_writew(d->pdev, d->bar, VIRTIO_MSI_QUEUE_VECTOR, entry); - vector =3D qpci_io_readw(d->pdev, d->bar, VIRTIO_MSI_QUEUE_VECTOR); - g_assert_cmphex(vector, !=3D, VIRTIO_MSI_NO_VECTOR); + d->msix_ops->set_queue_vector(d, vqpci->vq.index, entry); } =20 void qvirtio_pci_set_msix_configuration_vector(QVirtioPCIDevice *d, QGuestAllocator *alloc, uint16_t e= ntry) { - uint16_t vector; uint32_t control; uint64_t off; =20 @@ -358,9 +378,7 @@ void qvirtio_pci_set_msix_configuration_vector(QVirtioP= CIDevice *d, off + PCI_MSIX_ENTRY_VECTOR_CTRL, control & ~PCI_MSIX_ENTRY_CTRL_MASKBIT); =20 - qpci_io_writew(d->pdev, d->bar, VIRTIO_MSI_CONFIG_VECTOR, entry); - vector =3D qpci_io_readw(d->pdev, d->bar, VIRTIO_MSI_CONFIG_VECTOR); - g_assert_cmphex(vector, !=3D, VIRTIO_MSI_NO_VECTOR); + d->msix_ops->set_config_vector(d, entry); } =20 void qvirtio_pci_destructor(QOSGraphObject *obj) @@ -383,6 +401,7 @@ static void qvirtio_pci_init_from_pcidev(QVirtioPCIDevi= ce *dev, QPCIDevice *pci_ dev->vdev.device_type =3D qpci_config_readw(pci_dev, PCI_SUBSYSTEM_ID); =20 dev->config_msix_entry =3D -1; + dev->msix_ops =3D &qvirtio_pci_msix_ops_legacy; =20 dev->vdev.bus =3D &qvirtio_pci; dev->vdev.big_endian =3D qvirtio_pci_is_big_endian(dev); diff --git a/tests/libqos/virtio-pci.h b/tests/libqos/virtio-pci.h index 728b4715f1..4299efc023 100644 --- a/tests/libqos/virtio-pci.h +++ b/tests/libqos/virtio-pci.h @@ -14,16 +14,28 @@ #include "libqos/pci.h" #include "libqos/qgraph.h" =20 +typedef struct QVirtioPCIMSIXOps QVirtioPCIMSIXOps; + typedef struct QVirtioPCIDevice { QOSGraphObject obj; QVirtioDevice vdev; QPCIDevice *pdev; QPCIBar bar; + const QVirtioPCIMSIXOps *msix_ops; uint16_t config_msix_entry; uint64_t config_msix_addr; uint32_t config_msix_data; } QVirtioPCIDevice; =20 +struct QVirtioPCIMSIXOps { + /* Set the Configuration Vector for MSI-X */ + void (*set_config_vector)(QVirtioPCIDevice *d, uint16_t entry); + + /* Set the Queue Vector for MSI-X */ + void (*set_queue_vector)(QVirtioPCIDevice *d, uint16_t vq_idx, + uint16_t entry); +}; + typedef struct QVirtQueuePCI { QVirtQueue vq; uint16_t msix_entry; --=20 MST