Andreas Färber | 92838a1 | 2013-11-07 19:18:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * QTest testcase for eepro100 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ärber | 92838a1 | 2013-11-07 19:18:46 +0100 | [diff] [blame] | 10 | #include "qemu/osdep.h" |
Marc-André Lureau | 907b510 | 2022-03-30 13:39:05 +0400 | [diff] [blame] | 11 | #include "libqtest.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 12 | #include "qemu/module.h" |
Emanuele Giuseppe Esposito | 0b47730 | 2018-08-17 16:13:25 +0200 | [diff] [blame] | 13 | #include "libqos/qgraph.h" |
| 14 | #include "libqos/pci.h" |
Andreas Färber | 92838a1 | 2013-11-07 19:18:46 +0100 | [diff] [blame] | 15 | |
Emanuele Giuseppe Esposito | 0b47730 | 2018-08-17 16:13:25 +0200 | [diff] [blame] | 16 | typedef struct QEEPRO100 QEEPRO100; |
Andreas Färber | 92838a1 | 2013-11-07 19:18:46 +0100 | [diff] [blame] | 17 | |
Emanuele Giuseppe Esposito | 0b47730 | 2018-08-17 16:13:25 +0200 | [diff] [blame] | 18 | struct QEEPRO100 { |
| 19 | QOSGraphObject obj; |
| 20 | QPCIDevice dev; |
| 21 | }; |
Andreas Färber | 92838a1 | 2013-11-07 19:18:46 +0100 | [diff] [blame] | 22 | |
| 23 | static const char *models[] = { |
| 24 | "i82550", |
| 25 | "i82551", |
| 26 | "i82557a", |
| 27 | "i82557b", |
| 28 | "i82557c", |
| 29 | "i82558a", |
| 30 | "i82558b", |
| 31 | "i82559a", |
| 32 | "i82559b", |
| 33 | "i82559c", |
| 34 | "i82559er", |
| 35 | "i82562", |
| 36 | "i82801", |
| 37 | }; |
| 38 | |
Emanuele Giuseppe Esposito | 0b47730 | 2018-08-17 16:13:25 +0200 | [diff] [blame] | 39 | static void *eepro100_get_driver(void *obj, const char *interface) |
Andreas Färber | 92838a1 | 2013-11-07 19:18:46 +0100 | [diff] [blame] | 40 | { |
Emanuele Giuseppe Esposito | 0b47730 | 2018-08-17 16:13:25 +0200 | [diff] [blame] | 41 | QEEPRO100 *eepro100 = obj; |
Andreas Färber | 92838a1 | 2013-11-07 19:18:46 +0100 | [diff] [blame] | 42 | |
Emanuele Giuseppe Esposito | 0b47730 | 2018-08-17 16:13:25 +0200 | [diff] [blame] | 43 | if (!g_strcmp0(interface, "pci-device")) { |
| 44 | return &eepro100->dev; |
Andreas Färber | 92838a1 | 2013-11-07 19:18:46 +0100 | [diff] [blame] | 45 | } |
| 46 | |
Emanuele Giuseppe Esposito | 0b47730 | 2018-08-17 16:13:25 +0200 | [diff] [blame] | 47 | fprintf(stderr, "%s not present in eepro100\n", interface); |
| 48 | g_assert_not_reached(); |
Andreas Färber | 92838a1 | 2013-11-07 19:18:46 +0100 | [diff] [blame] | 49 | } |
Emanuele Giuseppe Esposito | 0b47730 | 2018-08-17 16:13:25 +0200 | [diff] [blame] | 50 | |
| 51 | static void *eepro100_create(void *pci_bus, QGuestAllocator *alloc, void *addr) |
| 52 | { |
| 53 | QEEPRO100 *eepro100 = g_new0(QEEPRO100, 1); |
| 54 | QPCIBus *bus = pci_bus; |
| 55 | |
| 56 | qpci_device_init(&eepro100->dev, bus, addr); |
| 57 | eepro100->obj.get_driver = eepro100_get_driver; |
| 58 | |
| 59 | return &eepro100->obj; |
| 60 | } |
| 61 | |
| 62 | static void eepro100_register_nodes(void) |
| 63 | { |
| 64 | int i; |
| 65 | QOSGraphEdgeOptions opts = { |
| 66 | .extra_device_opts = "addr=04.0", |
| 67 | }; |
| 68 | |
| 69 | add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) }); |
| 70 | for (i = 0; i < ARRAY_SIZE(models); i++) { |
| 71 | qos_node_create_driver(models[i], eepro100_create); |
| 72 | qos_node_consumes(models[i], "pci-bus", &opts); |
| 73 | qos_node_produces(models[i], "pci-device"); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | libqos_init(eepro100_register_nodes); |