From nobody Sun Nov 9 22:30:05 2025 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; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551982988857772.279437667381; Thu, 7 Mar 2019 10:23:08 -0800 (PST) Received: from localhost ([127.0.0.1]:56856 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xfc-0004bH-Ij for importer@patchew.org; Thu, 07 Mar 2019 13:23:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wr3-0003VP-Lm for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wr2-0008KS-1p for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:49 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:51168) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wr1-0008JB-NJ for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:47 -0500 Received: by mail-wm1-x341.google.com with SMTP id x7so10092567wmj.0 for ; Thu, 07 Mar 2019 09:30:47 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=EMKHLevsT8B5r1Tk5kCMLSWBiR0357EsQElAm0XzhQw=; b=ordSGTqyzzTKmqLBO9IA/Gu8loWp74E6xTPpkrCNUrE9NR542lqUGyO6YDVD07sF+2 em5uroVf0MmeFZwHmjpDAElXMTnH3LCGif2fg2wbRthprxIXzw5qNW1bYicDJTtvT7Yy OPHZMtgeMhTLFqvjbwBGDfd6dZFbL5kSRNbwfEuqLukjBPwF0T0Cpo3W4CCzZhcJxVV+ kcmEr79Ja5wVPhcNNIzy+Ce1XvQS0le8oaqcnszYIJ51wvTJG0oB17V+3BlI+YF4J18s eNHDxDzWCOKCBhRxGYXkkN5M5XhUNrl+tOjxI4+dnvQk8XwBl5nj5hi5Lo5XllKtvhZf IMJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=EMKHLevsT8B5r1Tk5kCMLSWBiR0357EsQElAm0XzhQw=; b=NHa+PS1Fp3+TxPABSDywU1cIBBTveBui6UecZQx+ioMpYKXbcRXYN0lbsZKIz0rmiM X8EPsMXWSzNFx0z0Ssdea+81a/ejmG5BnyAL57eiSq3v6d0bB8JQ29RmbDqmfK+Jyv/e I0G7isf3ehaX2PfJsaL/PaUGR4Cwy6wpFg+L3SXW9TFiIjT1AqdXD8oeiphuUuV8VmZi 6hJLhyYgflVWfiatsvqlbxolKbHjjSsfykID4EsjPB7gIc89HRI/5nRo4H+7y7zwfO5/ AjS2GGbPdG7ieWWe1PaPXKV6gBh+qJdAQWnSvRfy2306JGcjMwPc25gDTfK1tb3heKQK Le1w== X-Gm-Message-State: APjAAAV7zeEr8HS1CfJnWfKSq8seCcYA47FLLDbN6PRHPSsTsLIbGEyH 6qMeYllxx2q7Hi4YcL4VJpp1tqyD X-Google-Smtp-Source: APXvYqziPgvK8lijXumkjEKI9wc9C/SNzWpxS80uSddh3vw1pXGO7B0jr70mT7yVqD7lKJMjkQM9YQ== X-Received: by 2002:a1c:2543:: with SMTP id l64mr6678131wml.116.1551979846344; Thu, 07 Mar 2019 09:30:46 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:43 +0100 Message-Id: <1551979804-6060-37-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [PULL 36/57] tests/libqos: virtio-net driver and interface nodes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito Add qgraph nodes for virtio-net-pci and virtio-net-device. Both nodes produce virtio-net, but virtio-net-pci receives a pci-bus and overrides virtio-pci QOSGraphObject and its functions, while virtio-net-device receives a virtio and implements its own functions Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/virtio-net.c | 182 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/libqos/virtio-net.h | 41 +++++++++++ tests/libqos/virtio.c | 1 + tests/libqos/virtio.h | 1 + 5 files changed, 226 insertions(+) create mode 100644 tests/libqos/virtio-net.c create mode 100644 tests/libqos/virtio-net.h diff --git a/tests/Makefile.include b/tests/Makefile.include index 1d3133e..ec23364 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -743,6 +743,7 @@ qos-test-obj-y +=3D $(libqos-virtio-obj-y) qos-test-obj-$(CONFIG_VIRTFS) +=3D tests/libqos/virtio-9p.o qos-test-obj-y +=3D tests/libqos/virtio-balloon.o qos-test-obj-y +=3D tests/libqos/virtio-blk.o +qos-test-obj-y +=3D tests/libqos/virtio-net.o qos-test-obj-y +=3D tests/libqos/virtio-rng.o qos-test-obj-y +=3D tests/libqos/virtio-serial.o =20 diff --git a/tests/libqos/virtio-net.c b/tests/libqos/virtio-net.c new file mode 100644 index 0000000..3ddfbdc --- /dev/null +++ b/tests/libqos/virtio-net.c @@ -0,0 +1,182 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "libqos/qgraph.h" +#include "libqos/virtio-net.h" +#include "hw/virtio/virtio-net.h" + + +static QGuestAllocator *alloc; + +static void virtio_net_cleanup(QVirtioNet *interface) +{ + qvirtqueue_cleanup(interface->vdev->bus, interface->rx, alloc); + qvirtqueue_cleanup(interface->vdev->bus, interface->tx, alloc); +} + +static void virtio_net_setup(QVirtioNet *interface) +{ + QVirtioDevice *vdev =3D interface->vdev; + uint64_t features; + + features =3D qvirtio_get_features(vdev); + features &=3D ~(QVIRTIO_F_BAD_FEATURE | + (1u << VIRTIO_RING_F_INDIRECT_DESC) | + (1u << VIRTIO_RING_F_EVENT_IDX)); + qvirtio_set_features(vdev, features); + + interface->rx =3D qvirtqueue_setup(vdev, alloc, 0); + interface->tx =3D qvirtqueue_setup(vdev, alloc, 1); + qvirtio_set_driver_ok(vdev); +} + +/* virtio-net-device */ +static void qvirtio_net_device_destructor(QOSGraphObject *obj) +{ + QVirtioNetDevice *v_net =3D (QVirtioNetDevice *) obj; + virtio_net_cleanup(&v_net->net); +} + +static void qvirtio_net_device_start_hw(QOSGraphObject *obj) +{ + QVirtioNetDevice *v_net =3D (QVirtioNetDevice *) obj; + QVirtioNet *interface =3D &v_net->net; + + virtio_net_setup(interface); +} + +static void *qvirtio_net_get_driver(QVirtioNet *v_net, + const char *interface) +{ + if (!g_strcmp0(interface, "virtio-net")) { + return v_net; + } + if (!g_strcmp0(interface, "virtio")) { + return v_net->vdev; + } + + fprintf(stderr, "%s not present in virtio-net-device\n", interface); + g_assert_not_reached(); +} + +static void *qvirtio_net_device_get_driver(void *object, + const char *interface) +{ + QVirtioNetDevice *v_net =3D object; + return qvirtio_net_get_driver(&v_net->net, interface); +} + +static void *virtio_net_device_create(void *virtio_dev, + QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioNetDevice *virtio_ndevice =3D g_new0(QVirtioNetDevice, 1); + QVirtioNet *interface =3D &virtio_ndevice->net; + + interface->vdev =3D virtio_dev; + alloc =3D t_alloc; + + virtio_ndevice->obj.destructor =3D qvirtio_net_device_destructor; + virtio_ndevice->obj.get_driver =3D qvirtio_net_device_get_driver; + virtio_ndevice->obj.start_hw =3D qvirtio_net_device_start_hw; + + return &virtio_ndevice->obj; +} + +/* virtio-net-pci */ +static void qvirtio_net_pci_destructor(QOSGraphObject *obj) +{ + QVirtioNetPCI *v_net =3D (QVirtioNetPCI *) obj; + QVirtioNet *interface =3D &v_net->net; + QOSGraphObject *pci_vobj =3D &v_net->pci_vdev.obj; + + virtio_net_cleanup(interface); + qvirtio_pci_destructor(pci_vobj); +} + +static void qvirtio_net_pci_start_hw(QOSGraphObject *obj) +{ + QVirtioNetPCI *v_net =3D (QVirtioNetPCI *) obj; + QVirtioNet *interface =3D &v_net->net; + QOSGraphObject *pci_vobj =3D &v_net->pci_vdev.obj; + + qvirtio_pci_start_hw(pci_vobj); + virtio_net_setup(interface); +} + +static void *qvirtio_net_pci_get_driver(void *object, + const char *interface) +{ + QVirtioNetPCI *v_net =3D object; + if (!g_strcmp0(interface, "pci-device")) { + return v_net->pci_vdev.pdev; + } + return qvirtio_net_get_driver(&v_net->net, interface); +} + +static void *virtio_net_pci_create(void *pci_bus, QGuestAllocator *t_alloc, + void *addr) +{ + QVirtioNetPCI *virtio_bpci =3D g_new0(QVirtioNetPCI, 1); + QVirtioNet *interface =3D &virtio_bpci->net; + QOSGraphObject *obj =3D &virtio_bpci->pci_vdev.obj; + + virtio_pci_init(&virtio_bpci->pci_vdev, pci_bus, addr); + interface->vdev =3D &virtio_bpci->pci_vdev.vdev; + alloc =3D t_alloc; + + g_assert_cmphex(interface->vdev->device_type, =3D=3D, VIRTIO_ID_NET); + + obj->destructor =3D qvirtio_net_pci_destructor; + obj->start_hw =3D qvirtio_net_pci_start_hw; + obj->get_driver =3D qvirtio_net_pci_get_driver; + + return obj; +} + +static void virtio_net_register_nodes(void) +{ + /* FIXME: every test using these nodes needs to setup a + * -netdev socket,id=3Dhs0 otherwise QEMU is not going to start. + * Therefore, we do not include "produces" edge for virtio + * and pci-device yet. + */ + QPCIAddress addr =3D { + .devfn =3D QPCI_DEVFN(4, 0), + }; + + QOSGraphEdgeOptions opts =3D { }; + + /* virtio-net-device */ + opts.extra_device_opts =3D "netdev=3Dhs0"; + qos_node_create_driver("virtio-net-device", + virtio_net_device_create); + qos_node_consumes("virtio-net-device", "virtio-bus", &opts); + qos_node_produces("virtio-net-device", "virtio-net"); + + /* virtio-net-pci */ + opts.extra_device_opts =3D "netdev=3Dhs0,addr=3D04.0"; + add_qpci_address(&opts, &addr); + qos_node_create_driver("virtio-net-pci", virtio_net_pci_create); + qos_node_consumes("virtio-net-pci", "pci-bus", &opts); + qos_node_produces("virtio-net-pci", "virtio-net"); +} + +libqos_init(virtio_net_register_nodes); diff --git a/tests/libqos/virtio-net.h b/tests/libqos/virtio-net.h new file mode 100644 index 0000000..e6905cd --- /dev/null +++ b/tests/libqos/virtio-net.h @@ -0,0 +1,41 @@ +/* + * libqos driver framework + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "libqos/qgraph.h" +#include "libqos/virtio.h" +#include "libqos/virtio-pci.h" + +typedef struct QVirtioNet QVirtioNet; +typedef struct QVirtioNetPCI QVirtioNetPCI; +typedef struct QVirtioNetDevice QVirtioNetDevice; + +struct QVirtioNet { + QVirtioDevice *vdev; + QVirtQueue *rx; + QVirtQueue *tx; +}; + +struct QVirtioNetPCI { + QVirtioPCIDevice pci_vdev; + QVirtioNet net; +}; + +struct QVirtioNetDevice { + QOSGraphObject obj; + QVirtioNet net; +}; diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c index 9fc8c7e..e4925d1 100644 --- a/tests/libqos/virtio.c +++ b/tests/libqos/virtio.c @@ -40,6 +40,7 @@ uint32_t qvirtio_get_features(QVirtioDevice *d) =20 void qvirtio_set_features(QVirtioDevice *d, uint32_t features) { + d->features =3D features; d->bus->set_features(d, features); } =20 diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h index 7f0f9dd..3f97d79 100644 --- a/tests/libqos/virtio.h +++ b/tests/libqos/virtio.h @@ -21,6 +21,7 @@ typedef struct QVirtioDevice { const QVirtioBus *bus; /* Device type */ uint16_t device_type; + uint64_t features; bool big_endian; } QVirtioDevice; =20 --=20 1.8.3.1