2023-01-14 06:59:18 +03:00
|
|
|
/*
|
2016-06-01 11:23:46 +03:00
|
|
|
* QTest testcase for e1000e NIC
|
|
|
|
*
|
|
|
|
* Copyright (c) 2015 Ravello Systems LTD (http://ravellosystems.com)
|
|
|
|
* Developed by Daynix Computing LTD (http://www.daynix.com)
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Dmitry Fleytman <dmitry@daynix.com>
|
|
|
|
* Leonid Bloch <leonid@daynix.com>
|
|
|
|
* Yan Vugenfirer <yan@daynix.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2020-06-05 13:02:42 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2016-06-01 11:23:46 +03:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
2019-09-03 08:50:26 +03:00
|
|
|
#include "libqtest-single.h"
|
2016-06-01 11:23:46 +03:00
|
|
|
#include "libqos/pci-pc.h"
|
|
|
|
#include "qemu/sockets.h"
|
|
|
|
#include "qemu/iov.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2016-06-01 11:23:46 +03:00
|
|
|
#include "qemu/bitops.h"
|
2022-08-24 12:40:03 +03:00
|
|
|
#include "libqos/libqos-malloc.h"
|
2018-07-20 16:35:56 +03:00
|
|
|
#include "libqos/e1000e.h"
|
2022-11-03 12:54:16 +03:00
|
|
|
#include "hw/net/e1000_regs.h"
|
2016-06-01 11:23:46 +03:00
|
|
|
|
2018-07-20 16:35:56 +03:00
|
|
|
static void e1000e_send_verify(QE1000E *d, int *test_sockets, QGuestAllocator *alloc)
|
2016-06-01 11:23:46 +03:00
|
|
|
{
|
2022-11-10 14:44:26 +03:00
|
|
|
static const char test[] = "TEST";
|
2022-11-03 12:54:16 +03:00
|
|
|
struct e1000_tx_desc descr;
|
2016-06-01 11:23:46 +03:00
|
|
|
char buffer[64];
|
|
|
|
int ret;
|
|
|
|
uint32_t recv_len;
|
|
|
|
|
|
|
|
/* Prepare test data buffer */
|
2022-11-10 14:44:26 +03:00
|
|
|
uint64_t data = guest_alloc(alloc, sizeof(buffer));
|
|
|
|
memwrite(data, test, sizeof(test));
|
2016-06-01 11:23:46 +03:00
|
|
|
|
|
|
|
/* Prepare TX descriptor */
|
|
|
|
memset(&descr, 0, sizeof(descr));
|
|
|
|
descr.buffer_addr = cpu_to_le64(data);
|
2022-11-03 12:54:16 +03:00
|
|
|
descr.lower.data = cpu_to_le32(E1000_TXD_CMD_RS |
|
|
|
|
E1000_TXD_CMD_EOP |
|
|
|
|
E1000_TXD_CMD_DEXT |
|
|
|
|
E1000_TXD_DTYP_D |
|
2022-11-10 14:44:26 +03:00
|
|
|
sizeof(buffer));
|
2016-06-01 11:23:46 +03:00
|
|
|
|
|
|
|
/* Put descriptor to the ring */
|
|
|
|
e1000e_tx_ring_push(d, &descr);
|
|
|
|
|
|
|
|
/* Wait for TX WB interrupt */
|
|
|
|
e1000e_wait_isr(d, E1000E_TX0_MSG_ID);
|
|
|
|
|
|
|
|
/* Check DD bit */
|
2022-11-03 12:54:16 +03:00
|
|
|
g_assert_cmphex(le32_to_cpu(descr.upper.data) & E1000_TXD_STAT_DD, ==,
|
|
|
|
E1000_TXD_STAT_DD);
|
2016-06-01 11:23:46 +03:00
|
|
|
|
|
|
|
/* Check data sent to the backend */
|
2022-02-19 00:34:50 +03:00
|
|
|
ret = recv(test_sockets[0], &recv_len, sizeof(recv_len), 0);
|
2016-06-01 11:23:46 +03:00
|
|
|
g_assert_cmpint(ret, == , sizeof(recv_len));
|
2022-11-10 14:44:26 +03:00
|
|
|
ret = recv(test_sockets[0], buffer, sizeof(buffer), 0);
|
|
|
|
g_assert_cmpint(ret, ==, sizeof(buffer));
|
|
|
|
g_assert_cmpstr(buffer, == , test);
|
2016-06-01 11:23:46 +03:00
|
|
|
|
|
|
|
/* Free test data buffer */
|
2018-07-20 16:35:56 +03:00
|
|
|
guest_free(alloc, data);
|
2016-06-01 11:23:46 +03:00
|
|
|
}
|
|
|
|
|
2018-07-20 16:35:56 +03:00
|
|
|
static void e1000e_receive_verify(QE1000E *d, int *test_sockets, QGuestAllocator *alloc)
|
2016-06-01 11:23:46 +03:00
|
|
|
{
|
2022-11-03 12:54:16 +03:00
|
|
|
union e1000_rx_desc_extended descr;
|
2016-06-01 11:23:46 +03:00
|
|
|
|
|
|
|
char test[] = "TEST";
|
|
|
|
int len = htonl(sizeof(test));
|
|
|
|
struct iovec iov[] = {
|
|
|
|
{
|
|
|
|
.iov_base = &len,
|
|
|
|
.iov_len = sizeof(len),
|
|
|
|
},{
|
|
|
|
.iov_base = test,
|
|
|
|
.iov_len = sizeof(test),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
char buffer[64];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Send a dummy packet to device's socket*/
|
|
|
|
ret = iov_send(test_sockets[0], iov, 2, 0, sizeof(len) + sizeof(test));
|
|
|
|
g_assert_cmpint(ret, == , sizeof(test) + sizeof(len));
|
|
|
|
|
|
|
|
/* Prepare test data buffer */
|
2022-11-10 14:44:26 +03:00
|
|
|
uint64_t data = guest_alloc(alloc, sizeof(buffer));
|
2016-06-01 11:23:46 +03:00
|
|
|
|
|
|
|
/* Prepare RX descriptor */
|
|
|
|
memset(&descr, 0, sizeof(descr));
|
|
|
|
descr.read.buffer_addr = cpu_to_le64(data);
|
|
|
|
|
|
|
|
/* Put descriptor to the ring */
|
|
|
|
e1000e_rx_ring_push(d, &descr);
|
|
|
|
|
|
|
|
/* Wait for TX WB interrupt */
|
|
|
|
e1000e_wait_isr(d, E1000E_RX0_MSG_ID);
|
|
|
|
|
|
|
|
/* Check DD bit */
|
|
|
|
g_assert_cmphex(le32_to_cpu(descr.wb.upper.status_error) &
|
2022-11-03 12:54:16 +03:00
|
|
|
E1000_RXD_STAT_DD, ==, E1000_RXD_STAT_DD);
|
2016-06-01 11:23:46 +03:00
|
|
|
|
|
|
|
/* Check data sent to the backend */
|
|
|
|
memread(data, buffer, sizeof(buffer));
|
2022-11-10 14:44:26 +03:00
|
|
|
g_assert_cmpstr(buffer, == , test);
|
2016-06-01 11:23:46 +03:00
|
|
|
|
|
|
|
/* Free test data buffer */
|
2018-07-20 16:35:56 +03:00
|
|
|
guest_free(alloc, data);
|
2016-06-01 11:23:46 +03:00
|
|
|
}
|
|
|
|
|
2018-07-20 16:35:56 +03:00
|
|
|
static void test_e1000e_init(void *obj, void *data, QGuestAllocator * alloc)
|
2016-06-01 11:23:46 +03:00
|
|
|
{
|
2018-07-20 16:35:56 +03:00
|
|
|
/* init does nothing */
|
2016-06-01 11:23:46 +03:00
|
|
|
}
|
|
|
|
|
2018-07-20 16:35:56 +03:00
|
|
|
static void test_e1000e_tx(void *obj, void *data, QGuestAllocator * alloc)
|
2016-06-01 11:23:46 +03:00
|
|
|
{
|
2018-07-20 16:35:56 +03:00
|
|
|
QE1000E_PCI *e1000e = obj;
|
|
|
|
QE1000E *d = &e1000e->e1000e;
|
|
|
|
QOSGraphObject *e_object = obj;
|
|
|
|
QPCIDevice *dev = e_object->get_driver(e_object, "pci-device");
|
|
|
|
|
|
|
|
/* FIXME: add spapr support */
|
|
|
|
if (qpci_check_buggy_msi(dev)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-01 11:23:46 +03:00
|
|
|
|
2018-07-20 16:35:56 +03:00
|
|
|
e1000e_send_verify(d, data, alloc);
|
2016-06-01 11:23:46 +03:00
|
|
|
}
|
|
|
|
|
2018-07-20 16:35:56 +03:00
|
|
|
static void test_e1000e_rx(void *obj, void *data, QGuestAllocator * alloc)
|
2016-06-01 11:23:46 +03:00
|
|
|
{
|
2018-07-20 16:35:56 +03:00
|
|
|
QE1000E_PCI *e1000e = obj;
|
|
|
|
QE1000E *d = &e1000e->e1000e;
|
|
|
|
QOSGraphObject *e_object = obj;
|
|
|
|
QPCIDevice *dev = e_object->get_driver(e_object, "pci-device");
|
|
|
|
|
|
|
|
/* FIXME: add spapr support */
|
|
|
|
if (qpci_check_buggy_msi(dev)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-01 11:23:46 +03:00
|
|
|
|
2018-07-20 16:35:56 +03:00
|
|
|
e1000e_receive_verify(d, data, alloc);
|
2016-06-01 11:23:46 +03:00
|
|
|
}
|
|
|
|
|
2018-07-20 16:35:56 +03:00
|
|
|
static void test_e1000e_multiple_transfers(void *obj, void *data,
|
|
|
|
QGuestAllocator *alloc)
|
2016-06-01 11:23:46 +03:00
|
|
|
{
|
|
|
|
static const long iterations = 4 * 1024;
|
|
|
|
long i;
|
|
|
|
|
2018-07-20 16:35:56 +03:00
|
|
|
QE1000E_PCI *e1000e = obj;
|
|
|
|
QE1000E *d = &e1000e->e1000e;
|
|
|
|
QOSGraphObject *e_object = obj;
|
|
|
|
QPCIDevice *dev = e_object->get_driver(e_object, "pci-device");
|
2016-06-01 11:23:46 +03:00
|
|
|
|
2018-07-20 16:35:56 +03:00
|
|
|
/* FIXME: add spapr support */
|
|
|
|
if (qpci_check_buggy_msi(dev)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-01 11:23:46 +03:00
|
|
|
|
|
|
|
for (i = 0; i < iterations; i++) {
|
2018-07-20 16:35:56 +03:00
|
|
|
e1000e_send_verify(d, data, alloc);
|
|
|
|
e1000e_receive_verify(d, data, alloc);
|
2016-06-01 11:23:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-07-20 16:35:56 +03:00
|
|
|
static void test_e1000e_hotplug(void *obj, void *data, QGuestAllocator * alloc)
|
2016-06-01 11:23:46 +03:00
|
|
|
{
|
2019-04-09 15:25:57 +03:00
|
|
|
QTestState *qts = global_qtest; /* TODO: get rid of global_qtest here */
|
2022-05-04 18:20:24 +03:00
|
|
|
QE1000E_PCI *dev = obj;
|
|
|
|
|
|
|
|
if (dev->pci_dev.bus->not_hotpluggable) {
|
|
|
|
g_test_skip("pci bus does not support hotplug");
|
|
|
|
return;
|
|
|
|
}
|
2019-04-09 15:25:57 +03:00
|
|
|
|
2019-07-22 18:10:55 +03:00
|
|
|
qtest_qmp_device_add(qts, "e1000e", "e1000e_net", "{'addr': '0x06'}");
|
2019-04-09 15:25:57 +03:00
|
|
|
qpci_unplug_acpi_device_test(qts, "e1000e_net", 0x06);
|
2018-07-20 16:35:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void data_test_clear(void *sockets)
|
|
|
|
{
|
|
|
|
int *test_sockets = sockets;
|
2016-06-01 11:23:46 +03:00
|
|
|
|
2018-07-20 16:35:56 +03:00
|
|
|
close(test_sockets[0]);
|
|
|
|
qos_invalidate_command_line();
|
|
|
|
close(test_sockets[1]);
|
|
|
|
g_free(test_sockets);
|
2016-06-01 11:23:46 +03:00
|
|
|
}
|
|
|
|
|
2018-07-20 16:35:56 +03:00
|
|
|
static void *data_test_init(GString *cmd_line, void *arg)
|
2016-06-01 11:23:46 +03:00
|
|
|
{
|
2018-07-20 16:35:56 +03:00
|
|
|
int *test_sockets = g_new(int, 2);
|
|
|
|
int ret = socketpair(PF_UNIX, SOCK_STREAM, 0, test_sockets);
|
|
|
|
g_assert_cmpint(ret, != , -1);
|
2016-06-01 11:23:46 +03:00
|
|
|
|
2018-07-20 16:35:56 +03:00
|
|
|
g_string_append_printf(cmd_line, " -netdev socket,fd=%d,id=hs0 ",
|
|
|
|
test_sockets[1]);
|
2016-06-01 11:23:46 +03:00
|
|
|
|
2018-07-20 16:35:56 +03:00
|
|
|
g_test_queue_destroy(data_test_clear, test_sockets);
|
|
|
|
return test_sockets;
|
2016-06-01 11:23:46 +03:00
|
|
|
}
|
2018-07-20 16:35:56 +03:00
|
|
|
|
|
|
|
static void register_e1000e_test(void)
|
|
|
|
{
|
|
|
|
QOSGraphTestOptions opts = {
|
|
|
|
.before = data_test_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
qos_add_test("init", "e1000e", test_e1000e_init, &opts);
|
|
|
|
qos_add_test("tx", "e1000e", test_e1000e_tx, &opts);
|
|
|
|
qos_add_test("rx", "e1000e", test_e1000e_rx, &opts);
|
|
|
|
qos_add_test("multiple_transfers", "e1000e",
|
|
|
|
test_e1000e_multiple_transfers, &opts);
|
|
|
|
qos_add_test("hotplug", "e1000e", test_e1000e_hotplug, &opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
libqos_init(register_e1000e_test);
|