From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Jason Baron <jbaron@akamai.com>, Jason Wang <jasowang@redhat.com>,
virtio-dev@lists.oasis-open.org
Subject: [Qemu-devel] [PULL 03/22] virtio-net: add linkspeed and duplex settings to virtio-net
Date: Tue, 13 Mar 2018 23:45:13 +0200 [thread overview]
Message-ID: <1520977432-187679-4-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1520977432-187679-1-git-send-email-mst@redhat.com>
From: Jason Baron <jbaron@akamai.com>
Although linkspeed and duplex can be set in a linux guest via 'ethtool -s',
this requires custom ethtool commands for virtio-net by default.
Introduce a new feature flag, VIRTIO_NET_F_SPEED_DUPLEX, which allows
the hypervisor to export a linkspeed and duplex setting. The user can
subsequently overwrite it later if desired via: 'ethtool -s'.
Linkspeed and duplex settings can be set as:
'-device virtio-net,speed=10000,duplex=full'
where speed is [0...INT_MAX], and duplex is ["half"|"full"].
Signed-off-by: Jason Baron <jbaron@akamai.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: virtio-dev@lists.oasis-open.org
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/virtio/virtio-net.h | 3 +++
hw/net/virtio-net.c | 26 ++++++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index e7634c9..02484dc 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -38,6 +38,9 @@ typedef struct virtio_net_conf
uint16_t rx_queue_size;
uint16_t tx_queue_size;
uint16_t mtu;
+ int32_t speed;
+ char *duplex_str;
+ uint8_t duplex;
} virtio_net_conf;
/* Maximum packet size we can receive from tap device: header + 64k */
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index ab06f93..67ad38c 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -26,6 +26,7 @@
#include "qapi/qapi-events-net.h"
#include "hw/virtio/virtio-access.h"
#include "migration/misc.h"
+#include "standard-headers/linux/ethtool.h"
#define VIRTIO_NET_VM_VERSION 11
@@ -61,6 +62,8 @@ static VirtIOFeature feature_sizes[] = {
.end = endof(struct virtio_net_config, max_virtqueue_pairs)},
{.flags = 1ULL << VIRTIO_NET_F_MTU,
.end = endof(struct virtio_net_config, mtu)},
+ {.flags = 1ULL << VIRTIO_NET_F_SPEED_DUPLEX,
+ .end = endof(struct virtio_net_config, duplex)},
{}
};
@@ -89,6 +92,8 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
virtio_stw_p(vdev, &netcfg.max_virtqueue_pairs, n->max_queues);
virtio_stw_p(vdev, &netcfg.mtu, n->net_conf.mtu);
memcpy(netcfg.mac, n->mac, ETH_ALEN);
+ virtio_stl_p(vdev, &netcfg.speed, n->net_conf.speed);
+ netcfg.duplex = n->net_conf.duplex;
memcpy(config, &netcfg, n->config_size);
}
@@ -1941,6 +1946,25 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
n->host_features |= (1ULL << VIRTIO_NET_F_MTU);
}
+ if (n->net_conf.duplex_str) {
+ if (strncmp(n->net_conf.duplex_str, "half", 5) == 0) {
+ n->net_conf.duplex = DUPLEX_HALF;
+ } else if (strncmp(n->net_conf.duplex_str, "full", 5) == 0) {
+ n->net_conf.duplex = DUPLEX_FULL;
+ } else {
+ error_setg(errp, "'duplex' must be 'half' or 'full'");
+ }
+ n->host_features |= (1ULL << VIRTIO_NET_F_SPEED_DUPLEX);
+ } else {
+ n->net_conf.duplex = DUPLEX_UNKNOWN;
+ }
+
+ if (n->net_conf.speed < SPEED_UNKNOWN) {
+ error_setg(errp, "'speed' must be between 0 and INT_MAX");
+ } else if (n->net_conf.speed >= 0) {
+ n->host_features |= (1ULL << VIRTIO_NET_F_SPEED_DUPLEX);
+ }
+
virtio_net_set_config_size(n, n->host_features);
virtio_init(vdev, "virtio-net", VIRTIO_ID_NET, n->config_size);
@@ -2161,6 +2185,8 @@ static Property virtio_net_properties[] = {
DEFINE_PROP_UINT16("host_mtu", VirtIONet, net_conf.mtu, 0),
DEFINE_PROP_BOOL("x-mtu-bypass-backend", VirtIONet, mtu_bypass_backend,
true),
+ DEFINE_PROP_INT32("speed", VirtIONet, net_conf.speed, SPEED_UNKNOWN),
+ DEFINE_PROP_STRING("duplex", VirtIONet, net_conf.duplex_str),
DEFINE_PROP_END_OF_LIST(),
};
--
MST
next prev parent reply other threads:[~2018-03-13 21:45 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-13 21:45 [Qemu-devel] [PULL 00/22] virtio,vhost,pci,pc: features, cleanups Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 01/22] scripts/update-linux-headers: add ethtool.h and update to 4.16.0-rc4 Michael S. Tsirkin
2018-03-13 21:45 ` Michael S. Tsirkin [this message]
2018-03-13 21:45 ` [Qemu-devel] [PULL 02/22] virtio-net: use 64-bit values for feature flags Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 04/22] acpi: remove unused acpi-dsdt.aml Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 05/22] pc: replace pm object initialization with one-liner in acpi_get_pm_info() Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 06/22] acpi: reuse AcpiGenericAddress instead of Acpi20GenericAddress Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 07/22] acpi: add build_append_gas() helper for Generic Address Structure Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 08/22] acpi: move ACPI_PORT_SMI_CMD define to header it belongs to Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 09/22] pc: acpi: isolate FADT specific data into AcpiFadtData structure Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 11/22] acpi: move build_fadt() from i386 specific to generic ACPI source Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 10/22] pc: acpi: use build_append_foo() API to construct FADT Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 12/22] virt_arm: acpi: reuse common build_fadt() Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 13/22] tests: acpi: don't read all fields in test_acpi_fadt_table() Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 15/22] qemu-options-wrapper.h: fix include patch Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 14/22] vhost: used_memslots refactoring Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 16/22] standard-headers: update virtio_net.h Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 17/22] hw/pci: remove obsolete PCIDevice->init() Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 18/22] pc-dimm: make qmp_pc_dimm_device_list() sort devices by address Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 20/22] hw/acpi-build: build SRAT memory affinity structures for DIMM devices Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 19/22] qmp: distinguish PC-DIMM and NVDIMM in MemoryDeviceInfoList Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 21/22] tests/bios-tables-test: add test cases for DIMM proximity Michael S. Tsirkin
2018-03-13 21:45 ` [Qemu-devel] [PULL 22/22] test/acpi-test-data: add ACPI tables for dimmpxm test Michael S. Tsirkin
2018-03-16 16:31 ` [Qemu-devel] [PULL 00/22] virtio, vhost, pci, pc: features, cleanups Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1520977432-187679-4-git-send-email-mst@redhat.com \
--to=mst@redhat.com \
--cc=jasowang@redhat.com \
--cc=jbaron@akamai.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=virtio-dev@lists.oasis-open.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).