2 * QTest testcase for e1000e NIC
4 * Copyright (c) 2015 Ravello Systems LTD (http://ravellosystems.com)
5 * Developed by Daynix Computing LTD (http://www.daynix.com)
8 * Dmitry Fleytman <dmitry@daynix.com>
9 * Leonid Bloch <leonid@daynix.com>
10 * Yan Vugenfirer <yan@daynix.com>
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
27 #include "qemu/osdep.h"
29 #include "qemu-common.h"
30 #include "libqos/pci-pc.h"
31 #include "qemu/sockets.h"
33 #include "qemu/bitops.h"
34 #include "libqos/malloc.h"
35 #include "libqos/e1000e.h"
37 static void e1000e_send_verify(QE1000E
*d
, int *test_sockets
, QGuestAllocator
*alloc
)
59 static const uint32_t dtyp_data
= BIT(20);
60 static const uint32_t dtyp_ext
= BIT(29);
61 static const uint32_t dcmd_rs
= BIT(27);
62 static const uint32_t dcmd_eop
= BIT(24);
63 static const uint32_t dsta_dd
= BIT(0);
64 static const int data_len
= 64;
69 /* Prepare test data buffer */
70 uint64_t data
= guest_alloc(alloc
, data_len
);
71 memwrite(data
, "TEST", 5);
73 /* Prepare TX descriptor */
74 memset(&descr
, 0, sizeof(descr
));
75 descr
.buffer_addr
= cpu_to_le64(data
);
76 descr
.lower
.data
= cpu_to_le32(dcmd_rs
|
82 /* Put descriptor to the ring */
83 e1000e_tx_ring_push(d
, &descr
);
85 /* Wait for TX WB interrupt */
86 e1000e_wait_isr(d
, E1000E_TX0_MSG_ID
);
89 g_assert_cmphex(le32_to_cpu(descr
.upper
.data
) & dsta_dd
, ==, dsta_dd
);
91 /* Check data sent to the backend */
92 ret
= qemu_recv(test_sockets
[0], &recv_len
, sizeof(recv_len
), 0);
93 g_assert_cmpint(ret
, == , sizeof(recv_len
));
94 qemu_recv(test_sockets
[0], buffer
, 64, 0);
95 g_assert_cmpstr(buffer
, == , "TEST");
97 /* Free test data buffer */
98 guest_free(alloc
, data
);
101 static void e1000e_receive_verify(QE1000E
*d
, int *test_sockets
, QGuestAllocator
*alloc
)
105 uint64_t buffer_addr
;
120 uint32_t status_error
;
127 static const uint32_t esta_dd
= BIT(0);
129 char test
[] = "TEST";
130 int len
= htonl(sizeof(test
));
131 struct iovec iov
[] = {
134 .iov_len
= sizeof(len
),
137 .iov_len
= sizeof(test
),
141 static const int data_len
= 64;
145 /* Send a dummy packet to device's socket*/
146 ret
= iov_send(test_sockets
[0], iov
, 2, 0, sizeof(len
) + sizeof(test
));
147 g_assert_cmpint(ret
, == , sizeof(test
) + sizeof(len
));
149 /* Prepare test data buffer */
150 uint64_t data
= guest_alloc(alloc
, data_len
);
152 /* Prepare RX descriptor */
153 memset(&descr
, 0, sizeof(descr
));
154 descr
.read
.buffer_addr
= cpu_to_le64(data
);
156 /* Put descriptor to the ring */
157 e1000e_rx_ring_push(d
, &descr
);
159 /* Wait for TX WB interrupt */
160 e1000e_wait_isr(d
, E1000E_RX0_MSG_ID
);
163 g_assert_cmphex(le32_to_cpu(descr
.wb
.upper
.status_error
) &
164 esta_dd
, ==, esta_dd
);
166 /* Check data sent to the backend */
167 memread(data
, buffer
, sizeof(buffer
));
168 g_assert_cmpstr(buffer
, == , "TEST");
170 /* Free test data buffer */
171 guest_free(alloc
, data
);
174 static void test_e1000e_init(void *obj
, void *data
, QGuestAllocator
* alloc
)
176 /* init does nothing */
179 static void test_e1000e_tx(void *obj
, void *data
, QGuestAllocator
* alloc
)
181 QE1000E_PCI
*e1000e
= obj
;
182 QE1000E
*d
= &e1000e
->e1000e
;
183 QOSGraphObject
*e_object
= obj
;
184 QPCIDevice
*dev
= e_object
->get_driver(e_object
, "pci-device");
186 /* FIXME: add spapr support */
187 if (qpci_check_buggy_msi(dev
)) {
191 e1000e_send_verify(d
, data
, alloc
);
194 static void test_e1000e_rx(void *obj
, void *data
, QGuestAllocator
* alloc
)
196 QE1000E_PCI
*e1000e
= obj
;
197 QE1000E
*d
= &e1000e
->e1000e
;
198 QOSGraphObject
*e_object
= obj
;
199 QPCIDevice
*dev
= e_object
->get_driver(e_object
, "pci-device");
201 /* FIXME: add spapr support */
202 if (qpci_check_buggy_msi(dev
)) {
206 e1000e_receive_verify(d
, data
, alloc
);
209 static void test_e1000e_multiple_transfers(void *obj
, void *data
,
210 QGuestAllocator
*alloc
)
212 static const long iterations
= 4 * 1024;
215 QE1000E_PCI
*e1000e
= obj
;
216 QE1000E
*d
= &e1000e
->e1000e
;
217 QOSGraphObject
*e_object
= obj
;
218 QPCIDevice
*dev
= e_object
->get_driver(e_object
, "pci-device");
220 /* FIXME: add spapr support */
221 if (qpci_check_buggy_msi(dev
)) {
225 for (i
= 0; i
< iterations
; i
++) {
226 e1000e_send_verify(d
, data
, alloc
);
227 e1000e_receive_verify(d
, data
, alloc
);
232 static void test_e1000e_hotplug(void *obj
, void *data
, QGuestAllocator
* alloc
)
234 QTestState
*qts
= global_qtest
; /* TODO: get rid of global_qtest here */
236 qtest_qmp_device_add("e1000e", "e1000e_net", "{'addr': '0x06'}");
237 qpci_unplug_acpi_device_test(qts
, "e1000e_net", 0x06);
240 static void data_test_clear(void *sockets
)
242 int *test_sockets
= sockets
;
244 close(test_sockets
[0]);
245 qos_invalidate_command_line();
246 close(test_sockets
[1]);
247 g_free(test_sockets
);
250 static void *data_test_init(GString
*cmd_line
, void *arg
)
252 int *test_sockets
= g_new(int, 2);
253 int ret
= socketpair(PF_UNIX
, SOCK_STREAM
, 0, test_sockets
);
254 g_assert_cmpint(ret
, != , -1);
256 g_string_append_printf(cmd_line
, " -netdev socket,fd=%d,id=hs0 ",
259 g_test_queue_destroy(data_test_clear
, test_sockets
);
263 static void register_e1000e_test(void)
265 QOSGraphTestOptions opts
= {
266 .before
= data_test_init
,
269 qos_add_test("init", "e1000e", test_e1000e_init
, &opts
);
270 qos_add_test("tx", "e1000e", test_e1000e_tx
, &opts
);
271 qos_add_test("rx", "e1000e", test_e1000e_rx
, &opts
);
272 qos_add_test("multiple_transfers", "e1000e",
273 test_e1000e_multiple_transfers
, &opts
);
274 qos_add_test("hotplug", "e1000e", test_e1000e_hotplug
, &opts
);
277 libqos_init(register_e1000e_test
);