11e8a1faeSThomas Huth /*
21e8a1faeSThomas Huth * QTest testcase for e1000 NIC
31e8a1faeSThomas Huth *
41e8a1faeSThomas Huth * Copyright (c) 2013-2014 SUSE LINUX Products GmbH
51e8a1faeSThomas Huth *
61e8a1faeSThomas Huth * This work is licensed under the terms of the GNU GPL, version 2 or later.
71e8a1faeSThomas Huth * See the COPYING file in the top-level directory.
81e8a1faeSThomas Huth */
91e8a1faeSThomas Huth
101e8a1faeSThomas Huth #include "qemu/osdep.h"
11907b5105SMarc-André Lureau #include "libqtest.h"
121e8a1faeSThomas Huth #include "qemu/module.h"
131e8a1faeSThomas Huth #include "libqos/qgraph.h"
141e8a1faeSThomas Huth #include "libqos/pci.h"
151e8a1faeSThomas Huth
161e8a1faeSThomas Huth typedef struct QE1000 QE1000;
171e8a1faeSThomas Huth
181e8a1faeSThomas Huth struct QE1000 {
191e8a1faeSThomas Huth QOSGraphObject obj;
201e8a1faeSThomas Huth QPCIDevice dev;
211e8a1faeSThomas Huth };
221e8a1faeSThomas Huth
231e8a1faeSThomas Huth static const char *models[] = {
241e8a1faeSThomas Huth "e1000",
251e8a1faeSThomas Huth "e1000-82540em",
261e8a1faeSThomas Huth "e1000-82544gc",
271e8a1faeSThomas Huth "e1000-82545em",
281e8a1faeSThomas Huth };
291e8a1faeSThomas Huth
e1000_get_driver(void * obj,const char * interface)301e8a1faeSThomas Huth static void *e1000_get_driver(void *obj, const char *interface)
311e8a1faeSThomas Huth {
321e8a1faeSThomas Huth QE1000 *e1000 = obj;
331e8a1faeSThomas Huth
341e8a1faeSThomas Huth if (!g_strcmp0(interface, "pci-device")) {
351e8a1faeSThomas Huth return &e1000->dev;
361e8a1faeSThomas Huth }
371e8a1faeSThomas Huth
38*a65c9527SJuan Quintela fprintf(stderr, "%s not present in e1000\n", interface);
391e8a1faeSThomas Huth g_assert_not_reached();
401e8a1faeSThomas Huth }
411e8a1faeSThomas Huth
e1000_create(void * pci_bus,QGuestAllocator * alloc,void * addr)421e8a1faeSThomas Huth static void *e1000_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
431e8a1faeSThomas Huth {
441e8a1faeSThomas Huth QE1000 *e1000 = g_new0(QE1000, 1);
451e8a1faeSThomas Huth QPCIBus *bus = pci_bus;
461e8a1faeSThomas Huth
471e8a1faeSThomas Huth qpci_device_init(&e1000->dev, bus, addr);
481e8a1faeSThomas Huth e1000->obj.get_driver = e1000_get_driver;
491e8a1faeSThomas Huth
501e8a1faeSThomas Huth return &e1000->obj;
511e8a1faeSThomas Huth }
521e8a1faeSThomas Huth
e1000_register_nodes(void)531e8a1faeSThomas Huth static void e1000_register_nodes(void)
541e8a1faeSThomas Huth {
551e8a1faeSThomas Huth int i;
561e8a1faeSThomas Huth QOSGraphEdgeOptions opts = {
571e8a1faeSThomas Huth .extra_device_opts = "addr=04.0",
581e8a1faeSThomas Huth };
591e8a1faeSThomas Huth add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
601e8a1faeSThomas Huth
611e8a1faeSThomas Huth for (i = 0; i < ARRAY_SIZE(models); i++) {
621e8a1faeSThomas Huth qos_node_create_driver(models[i], e1000_create);
631e8a1faeSThomas Huth qos_node_consumes(models[i], "pci-bus", &opts);
641e8a1faeSThomas Huth qos_node_produces(models[i], "pci-device");
651e8a1faeSThomas Huth }
661e8a1faeSThomas Huth }
671e8a1faeSThomas Huth
681e8a1faeSThomas Huth libqos_init(e1000_register_nodes);
69