From nobody Tue Nov 4 22:01:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1533567442731706.7380369688119; Mon, 6 Aug 2018 07:57:22 -0700 (PDT) Received: from localhost ([::1]:34472 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmgwj-000874-G2 for importer@patchew.org; Mon, 06 Aug 2018 10:57:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmgbN-0005O6-7I for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:35:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmgbL-00016v-3v for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:35:17 -0400 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]:39563) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmgbK-00015Q-P3 for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:35:15 -0400 Received: by mail-ed1-x541.google.com with SMTP id h4-v6so5253803edi.6 for ; Mon, 06 Aug 2018 07:35:14 -0700 (PDT) Received: from localhost.localdomain ([194.230.159.126]) by smtp.gmail.com with ESMTPSA id x13-v6sm14615157edx.17.2018.08.06.07.35.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Aug 2018 07:35:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LNJXZksoXrUYPMK1LDM6s1vOqQj2vMEX8yTGegCzpJ0=; b=N1Z5CWs8wbYLOIbwlVyTji+2/eGWFCU8poBPs4Aol3DKodi/Z7zOXwIz8L0Od1K7Z/ JERZblsPVpsSsagfN8jWlvjo6lkzRZtJcIWoVBnNvKCLLtMwbKp3j08vXa/dkgltjzEm PVZBXxAsnT+siwsSP13qgoCYwBKz+Nc1Ov0D41yiKsL0mFms9/7alKdmTtw5aL2A12Ig ekw04mXCBuX62SXcl0SU69lNCpcD+xpr0cU9aNMgtqyzrzCMwWRzOcGvvno89q3J4Hp/ GTAZHBfuuUstALVamvm0O2auo3TBD4/vA4v1l/7431V67QjJ6sytv2W8bAv/XjjlA4pz jWtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LNJXZksoXrUYPMK1LDM6s1vOqQj2vMEX8yTGegCzpJ0=; b=T2A3NLq6Jk7RjEFRQJgJBxVaVMAX6nUSKW3dY5Rn93btBownsBkYRLJp62d9L2/rIM CimiU0ZU83V1C//7Y5CaX1aEo/lryuwlxlNBPKaAuWI6Dg5HsoSY4NcvNf8oPrLoZeTY AFs1Nu3MXq4EmOmCj9oIcggE7hMKxTeadHFG9XT6yHFZ5Gx7TlzKOtLk0Rr0hsMePXen Aqw1exen/Yo9iYsKVeGgtTZ6PRq/Dcf0RJr0JyMdVF/i8q97+F1zakneBp5Cr1pYos/k ijCjqDCtdUIpb9+MGCLZ2TzQo+dkNBrSL4dnM0JsXaEy0naoqo9sHG7fCaUd4+nWlRAO A8rA== X-Gm-Message-State: AOUpUlFwK4CARXXEMqU6b2JGw9bvcfGvUC5iNYJYjNoeTcoYXQvauApK Fi5/HkQgd3VqwJdk1eO1U7M= X-Google-Smtp-Source: AAOMgpdimTcfFcUzfTPr3GQzqD0oIIJM15LVv1YKMejQD+Du9IkFcj8GUPm8su9s6+2kB2MxoDeXow== X-Received: by 2002:a50:c251:: with SMTP id t17-v6mr18490348edf.108.1533566113737; Mon, 06 Aug 2018 07:35:13 -0700 (PDT) From: Emanuele Giuseppe Esposito To: Paolo Bonzini Date: Mon, 6 Aug 2018 16:34:08 +0200 Message-Id: <20180806143412.27722-31-e.emanuelegiuseppe@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180806143412.27722-1-e.emanuelegiuseppe@gmail.com> References: <20180806143412.27722-1-e.emanuelegiuseppe@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::541 Subject: [Qemu-devel] [PATCH v2 30/34] test/qgraph: 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: Laurent Vivier , Stefan Hajnoczi , Emanuele Giuseppe Esposito , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- tests/Makefile.include | 1 + tests/libqos/virtio-net.c | 177 ++++++++++++++++++++++++++++++++++++++ tests/libqos/virtio-net.h | 41 +++++++++ 3 files changed, 219 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 b628d2b821..ecab26b7b2 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -768,6 +768,7 @@ libqgraph-virtio-obj-y +=3D tests/libqos/virtio-9p.o libqgraph-virtio-obj-y +=3D tests/libqos/virtio-balloon.o libqgraph-virtio-obj-y +=3D tests/libqos/virtio-rng.o libqgraph-virtio-obj-y +=3D tests/libqos/virtio-blk.o +libqgraph-virtio-obj-y +=3D tests/libqos/virtio-net.o =20 libqgraph-pci-obj-y =3D $(libqos-virtio-obj-y) libqgraph-pci-obj-y +=3D $(libqgraph-machines-obj-y) diff --git a/tests/libqos/virtio-net.c b/tests/libqos/virtio-net.c new file mode 100644 index 0000000000..12eb6e0530 --- /dev/null +++ b/tests/libqos/virtio-net.c @@ -0,0 +1,177 @@ +/* + * 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 driver_init(QVirtioDevice *dev) +{ + uint32_t features; + + features =3D qvirtio_get_features(dev); + features =3D features & ~(QVIRTIO_F_BAD_FEATURE | + (1u << VIRTIO_RING_F_INDIRECT_DESC) | + (1u << VIRTIO_RING_F_EVENT_IDX)); + qvirtio_set_features(dev, features); +} + +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) +{ + interface->rx =3D qvirtqueue_setup(interface->vdev, alloc, 0); + interface->tx =3D qvirtqueue_setup(interface->vdev, alloc, 1); + driver_init(interface->vdev); +} + +/* virtio-net-device */ +static void qvirtio_net_device_destroy(QOSGraphObject *obj) +{ + QVirtioNetDevice *v_net =3D (QVirtioNetDevice *) obj; + virtio_net_cleanup(&v_net->net); + g_free(v_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_device_get_driver(void *object, + const char *interface) +{ + QVirtioNetDevice *v_net =3D object; + if (!g_strcmp0(interface, "virtio-net")) { + return &v_net->net; + } + + printf("%s not present in virtio-net-device\n", interface); + abort(); +} + +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_destroy; + 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_destroy(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_destroy(pci_vobj); + g_free(v_net); +} + +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); + driver_init(interface->vdev); +} + +static void *qvirtio_net_pci_get_driver(void *object, + const char *interface) +{ + QVirtioNetPCI *v_net =3D object; + if (!g_strcmp0(interface, "virtio-net")) { + return &v_net->net; + } + + printf("%s not present in virtio-net-pci\n", interface); + abort(); +} + +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_destroy; + obj->start_hw =3D qvirtio_net_pci_start_hw; + obj->get_driver =3D qvirtio_net_pci_get_driver; + + return obj; +} + +static void virtio_net(void) +{ + /* FIXME: every test using these nodes needs to setup a + * -netdev socket,id=3Dhs0 otherwise QEMU is not going to start */ + 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", &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); diff --git a/tests/libqos/virtio-net.h b/tests/libqos/virtio-net.h new file mode 100644 index 0000000000..e6905cd82e --- /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; +}; --=20 2.17.1