blob: a81025252c87989952cea07c1c546d55e25639f0 [file] [log] [blame]
Andreas Färber4a053e72013-11-07 18:37:34 +01001/*
2 * QTest testcase for vmxnet3 NIC
3 *
4 * Copyright (c) 2013-2014 SUSE LINUX Products GmbH
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
8 */
9
Andreas Färber4a053e72013-11-07 18:37:34 +010010#include "qemu/osdep.h"
Marc-André Lureau907b5102022-03-30 13:39:05 +040011#include "libqtest.h"
Markus Armbruster0b8fa322019-05-23 16:35:07 +020012#include "qemu/module.h"
Emanuele Giuseppe Esposito53bfb422018-08-17 15:52:52 +020013#include "libqos/qgraph.h"
14#include "libqos/pci.h"
Andreas Färber4a053e72013-11-07 18:37:34 +010015
Emanuele Giuseppe Esposito53bfb422018-08-17 15:52:52 +020016typedef struct QVmxnet3 QVmxnet3;
17
18struct QVmxnet3 {
19 QOSGraphObject obj;
20 QPCIDevice dev;
21};
22
23static void *vmxnet3_get_driver(void *obj, const char *interface)
Andreas Färber4a053e72013-11-07 18:37:34 +010024{
Emanuele Giuseppe Esposito53bfb422018-08-17 15:52:52 +020025 QVmxnet3 *vmxnet3 = obj;
26
27 if (!g_strcmp0(interface, "pci-device")) {
28 return &vmxnet3->dev;
29 }
30
31 fprintf(stderr, "%s not present in vmxnet3\n", interface);
32 g_assert_not_reached();
Andreas Färber4a053e72013-11-07 18:37:34 +010033}
34
Emanuele Giuseppe Esposito53bfb422018-08-17 15:52:52 +020035static void *vmxnet3_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
Andreas Färber4a053e72013-11-07 18:37:34 +010036{
Emanuele Giuseppe Esposito53bfb422018-08-17 15:52:52 +020037 QVmxnet3 *vmxnet3 = g_new0(QVmxnet3, 1);
38 QPCIBus *bus = pci_bus;
Andreas Färber4a053e72013-11-07 18:37:34 +010039
Emanuele Giuseppe Esposito53bfb422018-08-17 15:52:52 +020040 qpci_device_init(&vmxnet3->dev, bus, addr);
41 vmxnet3->obj.get_driver = vmxnet3_get_driver;
Andreas Färber4a053e72013-11-07 18:37:34 +010042
Emanuele Giuseppe Esposito53bfb422018-08-17 15:52:52 +020043 return &vmxnet3->obj;
Andreas Färber4a053e72013-11-07 18:37:34 +010044}
Emanuele Giuseppe Esposito53bfb422018-08-17 15:52:52 +020045
46static void vmxnet3_register_nodes(void)
47{
48 QOSGraphEdgeOptions opts = {
49 .extra_device_opts = "addr=04.0",
50 };
51 add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
52
53 qos_node_create_driver("vmxnet3", vmxnet3_create);
54 qos_node_consumes("vmxnet3", "pci-bus", &opts);
55 qos_node_produces("vmxnet3", "pci-device");
56}
57
58libqos_init(vmxnet3_register_nodes);