xref: /qemu/tests/qtest/e1000-test.c (revision a138f26623e15ec721489f3164fbd7eb03a6dc98)
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"
11681c28a3SPeter Maydell #include "libqtest.h"
12*a138f266SEmanuele Giuseppe Esposito #include "libqos/qgraph.h"
13*a138f266SEmanuele Giuseppe Esposito #include "libqos/pci.h"
14a21baf79SAndreas Färber 
15*a138f266SEmanuele Giuseppe Esposito typedef struct QE1000 QE1000;
16b167383fSGabriel L. Somlo 
17*a138f266SEmanuele Giuseppe Esposito struct QE1000 {
18*a138f266SEmanuele Giuseppe Esposito     QOSGraphObject obj;
19*a138f266SEmanuele Giuseppe Esposito     QPCIDevice dev;
20*a138f266SEmanuele Giuseppe Esposito };
21b167383fSGabriel L. Somlo 
22b167383fSGabriel L. Somlo static const char *models[] = {
23b167383fSGabriel L. Somlo     "e1000",
24b167383fSGabriel L. Somlo     "e1000-82540em",
25b167383fSGabriel L. Somlo     "e1000-82544gc",
26b167383fSGabriel L. Somlo     "e1000-82545em",
27b167383fSGabriel L. Somlo };
28a21baf79SAndreas Färber 
29*a138f266SEmanuele Giuseppe Esposito static void *e1000_get_driver(void *obj, const char *interface)
30*a138f266SEmanuele Giuseppe Esposito {
31*a138f266SEmanuele Giuseppe Esposito     QE1000 *e1000 = obj;
32*a138f266SEmanuele Giuseppe Esposito 
33*a138f266SEmanuele Giuseppe Esposito     if (!g_strcmp0(interface, "pci-device")) {
34*a138f266SEmanuele Giuseppe Esposito         return &e1000->dev;
35*a138f266SEmanuele Giuseppe Esposito     }
36*a138f266SEmanuele Giuseppe Esposito 
37*a138f266SEmanuele Giuseppe Esposito     fprintf(stderr, "%s not present in e1000e\n", interface);
38*a138f266SEmanuele Giuseppe Esposito     g_assert_not_reached();
39*a138f266SEmanuele Giuseppe Esposito }
40*a138f266SEmanuele Giuseppe Esposito 
41*a138f266SEmanuele Giuseppe Esposito static void *e1000_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
42*a138f266SEmanuele Giuseppe Esposito {
43*a138f266SEmanuele Giuseppe Esposito     QE1000 *e1000 = g_new0(QE1000, 1);
44*a138f266SEmanuele Giuseppe Esposito     QPCIBus *bus = pci_bus;
45*a138f266SEmanuele Giuseppe Esposito 
46*a138f266SEmanuele Giuseppe Esposito     qpci_device_init(&e1000->dev, bus, addr);
47*a138f266SEmanuele Giuseppe Esposito     e1000->obj.get_driver = e1000_get_driver;
48*a138f266SEmanuele Giuseppe Esposito 
49*a138f266SEmanuele Giuseppe Esposito     return &e1000->obj;
50*a138f266SEmanuele Giuseppe Esposito }
51*a138f266SEmanuele Giuseppe Esposito 
52*a138f266SEmanuele Giuseppe Esposito static void e1000_register_nodes(void)
53a21baf79SAndreas Färber {
54b167383fSGabriel L. Somlo     int i;
55*a138f266SEmanuele Giuseppe Esposito     QOSGraphEdgeOptions opts = {
56*a138f266SEmanuele Giuseppe Esposito         .extra_device_opts = "addr=04.0",
57*a138f266SEmanuele Giuseppe Esposito     };
58*a138f266SEmanuele Giuseppe Esposito     add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
59a21baf79SAndreas Färber 
60b167383fSGabriel L. Somlo     for (i = 0; i < ARRAY_SIZE(models); i++) {
61*a138f266SEmanuele Giuseppe Esposito         qos_node_create_driver(models[i], e1000_create);
62*a138f266SEmanuele Giuseppe Esposito         qos_node_consumes(models[i], "pci-bus", &opts);
63*a138f266SEmanuele Giuseppe Esposito         qos_node_produces(models[i], "pci-device");
64*a138f266SEmanuele Giuseppe Esposito     }
65b167383fSGabriel L. Somlo }
66a21baf79SAndreas Färber 
67*a138f266SEmanuele Giuseppe Esposito libqos_init(e1000_register_nodes);
68