From nobody Wed Nov 5 10:45:06 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 1534156330188904.3811485557925; Mon, 13 Aug 2018 03:32:10 -0700 (PDT) Received: from localhost ([::1]:38620 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fpA8v-0006Bn-0t for importer@patchew.org; Mon, 13 Aug 2018 06:32:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp9tb-0007vR-Hd for qemu-devel@nongnu.org; Mon, 13 Aug 2018 06:16:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fp9tZ-00032M-Q2 for qemu-devel@nongnu.org; Mon, 13 Aug 2018 06:16:19 -0400 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]:35278) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fp9tZ-00030S-FS; Mon, 13 Aug 2018 06:16:17 -0400 Received: by mail-ed1-x544.google.com with SMTP id e6-v6so7969644edr.2; Mon, 13 Aug 2018 03:16:17 -0700 (PDT) Received: from localhost.localdomain ([194.230.159.125]) by smtp.gmail.com with ESMTPSA id s27-v6sm11670006edb.73.2018.08.13.03.16.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Aug 2018 03:16:15 -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=0eApTlE7XVfDyVlqnjVs74NH77OpwAvFdeosYQ3PWS4=; b=i5aV3wPkhde9wbLtas+NLmUbSlOQW8dDX0IP2X+xeJaDcyy6JL1Av7WVXsp45GbV/l dUWyanLnRq04RCacUD2mIeDqduetRHDCHqqd94B3fdsG5EBXRbyVA7UKVW9e4N7T22v8 RSla60vN0B8c308odgVAV6AfhM37G4T28YjQYP4BjrHIJCEkQ7zGXKniKbMtTG+qHRER VkO6YK6WeFjgtfjLaLm+5xKsTMT2kFKJ/urfXrNJydHKak0C5BVeaTrYh4NQjfHXXw3G VqQfIrD13hLeOAaRX9pm+ld/sCKD7DRog1zD4XZiU/n7YidHkdN6hoZeILR9yPqPaV5S Ovwg== 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=0eApTlE7XVfDyVlqnjVs74NH77OpwAvFdeosYQ3PWS4=; b=UCRRRUWUp5N4qNs1UuYKNq9O9pT7vXshvH98i9C0efVwRwceA668WYcol5QedUddz4 9xiXyQaB7GC2iRrN97Vh91Lpl/ubAQuqLEToPc+fTM3oaPHHX2xidXrCI3GTXMZS59Rh 9nZy4Si3PN62UMWmCGbmwDi+jZkzylknJaQKjaMUCc/wQ16E48hDODlZkeAuanYGRVlJ YSbomderI3HAnJDzgoXSC41JB87ioq7rA6oyQ+BvyrIvpM6DZYtxSWbeCHbi4URG48C8 aBRMP2nlJEbSuYtO/YxTP/dcSH5qgOgfQA+wFvoSxeVOiO1R6/QG9jXG00nZwkruxjIT Nj3Q== X-Gm-Message-State: AOUpUlF6APgy8/ApV1g1hilQomIAwaHORu1NzY3TXkdXf+z8oJm9avnx VzcSDxqV7/lcMA2VEL/nYVaqHWDS8zw= X-Google-Smtp-Source: AA+uWPwIr2cZIndCyQPYiSs101c4YTL7iSdIyV/VXJgXIqV8+1iP681b464iW8SDg+ebhQb32NhhHg== X-Received: by 2002:a50:b4b0:: with SMTP id w45-v6mr21628978edd.254.1534155376095; Mon, 13 Aug 2018 03:16:16 -0700 (PDT) From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Date: Mon, 13 Aug 2018 12:14:49 +0200 Message-Id: <20180813101453.10200-30-e.emanuelegiuseppe@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180813101453.10200-1-e.emanuelegiuseppe@gmail.com> References: <20180813101453.10200-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::544 Subject: [Qemu-devel] [PATCH 29/33] tests/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 , Fam Zheng , qemu-block@nongnu.org, "Michael S. Tsirkin" , Jason Wang , Amit Shah , Emanuele Giuseppe Esposito , Alexander Graf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Greg Kurz , qemu-ppc@nongnu.org, Gerd Hoffmann , Stefan Hajnoczi , Paolo Bonzini , John Snow , David Gibson 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 | 179 ++++++++++++++++++++++++++++++++++++++ tests/libqos/virtio-net.h | 41 +++++++++ 3 files changed, 221 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 814cef85c7..c105c0902c 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..332d121486 --- /dev/null +++ b/tests/libqos/virtio-net.c @@ -0,0 +1,179 @@ +/* + * 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); + + qvirtio_set_driver_ok(dev); +} + +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_destructor(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; + } + + fprintf(stderr, "%s not present in virtio-net-device\n", interface); + g_assert_not_reached(); +} + +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); + 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; + } + + fprintf(stderr, "%s not present in virtio-net-pci\n", interface); + g_assert_not_reached(); +} + +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 */ + 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_register_nodes); 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