1a21baf79SAndreas Färber /*
2a21baf79SAndreas Färber * QTest testcase for e1000 NIC
3a21baf79SAndreas Färber *
4a21baf79SAndreas Färber * Copyright (c) 2013-2014 SUSE LINUX Products GmbH
5a21baf79SAndreas Färber *
6a21baf79SAndreas Färber * This work is licensed under the terms of the GNU GPL, version 2 or later.
7a21baf79SAndreas Färber * See the COPYING file in the top-level directory.
8a21baf79SAndreas Färber */
9a21baf79SAndreas Färber
10a21baf79SAndreas Färber #include "qemu/osdep.h"
11907b5105SMarc-André Lureau #include "libqtest.h"
120b8fa32fSMarkus Armbruster #include "qemu/module.h"
13a138f266SEmanuele Giuseppe Esposito #include "libqos/qgraph.h"
14a138f266SEmanuele Giuseppe Esposito #include "libqos/pci.h"
15a21baf79SAndreas Färber
16a138f266SEmanuele Giuseppe Esposito typedef struct QE1000 QE1000;
17b167383fSGabriel L. Somlo
18a138f266SEmanuele Giuseppe Esposito struct QE1000 {
19a138f266SEmanuele Giuseppe Esposito QOSGraphObject obj;
20a138f266SEmanuele Giuseppe Esposito QPCIDevice dev;
21a138f266SEmanuele Giuseppe Esposito };
22b167383fSGabriel L. Somlo
23b167383fSGabriel L. Somlo static const char *models[] = {
24b167383fSGabriel L. Somlo "e1000",
25b167383fSGabriel L. Somlo "e1000-82540em",
26b167383fSGabriel L. Somlo "e1000-82544gc",
27b167383fSGabriel L. Somlo "e1000-82545em",
28b167383fSGabriel L. Somlo };
29a21baf79SAndreas Färber
e1000_get_driver(void * obj,const char * interface)30a138f266SEmanuele Giuseppe Esposito static void *e1000_get_driver(void *obj, const char *interface)
31a138f266SEmanuele Giuseppe Esposito {
32a138f266SEmanuele Giuseppe Esposito QE1000 *e1000 = obj;
33a138f266SEmanuele Giuseppe Esposito
34a138f266SEmanuele Giuseppe Esposito if (!g_strcmp0(interface, "pci-device")) {
35a138f266SEmanuele Giuseppe Esposito return &e1000->dev;
36a138f266SEmanuele Giuseppe Esposito }
37a138f266SEmanuele Giuseppe Esposito
38*a65c9527SJuan Quintela fprintf(stderr, "%s not present in e1000\n", interface);
39a138f266SEmanuele Giuseppe Esposito g_assert_not_reached();
40a138f266SEmanuele Giuseppe Esposito }
41a138f266SEmanuele Giuseppe Esposito
e1000_create(void * pci_bus,QGuestAllocator * alloc,void * addr)42a138f266SEmanuele Giuseppe Esposito static void *e1000_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
43a138f266SEmanuele Giuseppe Esposito {
44a138f266SEmanuele Giuseppe Esposito QE1000 *e1000 = g_new0(QE1000, 1);
45a138f266SEmanuele Giuseppe Esposito QPCIBus *bus = pci_bus;
46a138f266SEmanuele Giuseppe Esposito
47a138f266SEmanuele Giuseppe Esposito qpci_device_init(&e1000->dev, bus, addr);
48a138f266SEmanuele Giuseppe Esposito e1000->obj.get_driver = e1000_get_driver;
49a138f266SEmanuele Giuseppe Esposito
50a138f266SEmanuele Giuseppe Esposito return &e1000->obj;
51a138f266SEmanuele Giuseppe Esposito }
52a138f266SEmanuele Giuseppe Esposito
e1000_register_nodes(void)53a138f266SEmanuele Giuseppe Esposito static void e1000_register_nodes(void)
54a21baf79SAndreas Färber {
55b167383fSGabriel L. Somlo int i;
56a138f266SEmanuele Giuseppe Esposito QOSGraphEdgeOptions opts = {
57a138f266SEmanuele Giuseppe Esposito .extra_device_opts = "addr=04.0",
58a138f266SEmanuele Giuseppe Esposito };
59a138f266SEmanuele Giuseppe Esposito add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
60a21baf79SAndreas Färber
61b167383fSGabriel L. Somlo for (i = 0; i < ARRAY_SIZE(models); i++) {
62a138f266SEmanuele Giuseppe Esposito qos_node_create_driver(models[i], e1000_create);
63a138f266SEmanuele Giuseppe Esposito qos_node_consumes(models[i], "pci-bus", &opts);
64a138f266SEmanuele Giuseppe Esposito qos_node_produces(models[i], "pci-device");
65a138f266SEmanuele Giuseppe Esposito }
66b167383fSGabriel L. Somlo }
67a21baf79SAndreas Färber
68a138f266SEmanuele Giuseppe Esposito libqos_init(e1000_register_nodes);
69