From nobody Mon Feb 9 15:29:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515043159391339.4294374278004; Wed, 3 Jan 2018 21:19:19 -0800 (PST) Received: from localhost ([::1]:47341 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWxvp-00012I-Ta for importer@patchew.org; Thu, 04 Jan 2018 00:19:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWxuB-00083t-SJ for qemu-devel@nongnu.org; Thu, 04 Jan 2018 00:17:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWxuA-0000C0-Om for qemu-devel@nongnu.org; Thu, 04 Jan 2018 00:17:27 -0500 Received: from mx0a-00190b01.pphosted.com ([2620:100:9001:583::1]:50340) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eWxuA-0000AX-Ej for qemu-devel@nongnu.org; Thu, 04 Jan 2018 00:17:26 -0500 Received: from pps.filterd (m0050095.ppops.net [127.0.0.1]) by mx0a-00190b01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w045H35K028580; Thu, 4 Jan 2018 05:17:22 GMT Received: from prod-mail-ppoint3 ([96.6.114.86]) by m0050095.ppops.net-00190b01. with ESMTP id 2f6377d2pu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 Jan 2018 05:17:22 +0000 Received: from pps.filterd (prod-mail-ppoint3.akamai.com [127.0.0.1]) by prod-mail-ppoint3.akamai.com (8.16.0.21/8.16.0.21) with SMTP id w045ESsC013085; Thu, 4 Jan 2018 00:17:21 -0500 Received: from prod-mail-relay14.akamai.com ([172.27.17.39]) by prod-mail-ppoint3.akamai.com with ESMTP id 2f95des5n2-1; Thu, 04 Jan 2018 00:17:21 -0500 Received: from bos-lpjec.kendall.corp.akamai.com (bos-lpjec.kendall.corp.akamai.com [172.28.12.191]) by prod-mail-relay14.akamai.com (Postfix) with ESMTP id B48A1821FC; Wed, 3 Jan 2018 22:17:20 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akamai.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : references; s=jan2016.eng; bh=79xq30ThcD1SV1t9prbPvbawjuMwdRTVkRgF7eAsyrY=; b=ncb32IRHLpnLhMSqQF6/MlzB3kzNTrZUDISwXflr845JHhlkv50/RpcEu7NlhjDsncBC +Zu0sDm2zeHq7zrfH8P1PpKt6DNCfqypi4CD1z/pL8NxFe6EmagaHfLUMrT2CNNowdro k6C88vQsoKv+oIAY1EZyGxTJaNpAIuJWUfrUBZiZz2TjJPiNCQuS1FBwmsPvVSv1xldQ lLQpB4YhO8Fkq5L+LvktBOkoQ2w1pTU3mFOjrwLaUDeqFIYnM4TNvhT/Imc0IIb0q+iv 80CKgyHOXYz40M76gAjDHKjNb3diYriZ2nlfIP1ayguqir5nS6e48hWsDjNnwpJzeojz fQ== To: mst@redhat.com, davem@davemloft.net Date: Thu, 4 Jan 2018 00:16:45 -0500 Message-Id: <045deae35c270264b14550fd41bd14f5b75e76e9.1515042044.git.jbaron@akamai.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: References: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-04_02:, , signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801040070 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-04_02:, , signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801040072 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 2620:100:9001:583::1 Subject: [Qemu-devel] [PATCH v3 3/3] qemu: add linkspeed and duplex settings to virtio-net X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Jason Baron via Qemu-devel Reply-To: Jason Baron Cc: netdev@vger.kernel.org, jasowang@redhat.com, virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org, virtualization@lists.linux-foundation.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=3D10000,duplex=3Dfull' where speed is [-1...INT_MAX], and duplex is ["half"|"full"]. Signed-off-by: Jason Baron Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: virtio-dev@lists.oasis-open.org --- hw/net/virtio-net.c | 35 +++++++++++++++++++++++++= ++++ include/hw/virtio/virtio-net.h | 3 +++ include/standard-headers/linux/virtio_net.h | 13 +++++++++++ 3 files changed, 51 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index adc20df..eec8422 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -40,6 +40,12 @@ #define VIRTIO_NET_RX_QUEUE_MIN_SIZE VIRTIO_NET_RX_QUEUE_DEFAULT_SIZE #define VIRTIO_NET_TX_QUEUE_MIN_SIZE VIRTIO_NET_TX_QUEUE_DEFAULT_SIZE =20 +/* duplex and speed */ +#define DUPLEX_UNKNOWN 0xff +#define DUPLEX_HALF 0x00 +#define DUPLEX_FULL 0x01 +#define SPEED_UNKNOWN -1 + /* * Calculate the number of bytes up to and including the given 'field' of * 'container'. @@ -61,6 +67,8 @@ static VirtIOFeature feature_sizes[] =3D { .end =3D endof(struct virtio_net_config, max_virtqueue_pairs)}, {.flags =3D 1ULL << VIRTIO_NET_F_MTU, .end =3D endof(struct virtio_net_config, mtu)}, + {.flags =3D 1ULL << VIRTIO_NET_F_SPEED_DUPLEX, + .end =3D endof(struct virtio_net_config, duplex)}, {} }; =20 @@ -89,6 +97,14 @@ static void virtio_net_get_config(VirtIODevice *vdev, ui= nt8_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); + if (n->status & VIRTIO_NET_S_LINK_UP) { + virtio_stl_p(vdev, &netcfg.speed, n->net_conf.speed); + netcfg.duplex =3D n->net_conf.duplex; + } else { + virtio_stl_p(vdev, &netcfg.speed, SPEED_UNKNOWN); + netcfg.duplex =3D DUPLEX_UNKNOWN; + } + memcpy(config, &netcfg, n->config_size); } =20 @@ -1941,6 +1957,23 @@ static void virtio_net_device_realize(DeviceState *d= ev, Error **errp) n->host_features |=3D (1ULL << VIRTIO_NET_F_MTU); } =20 + n->host_features |=3D (1ULL << VIRTIO_NET_F_SPEED_DUPLEX); + if (n->net_conf.duplex_str) { + if (strncmp(n->net_conf.duplex_str, "half", 5) =3D=3D 0) { + n->net_conf.duplex =3D DUPLEX_HALF; + } else if (strncmp(n->net_conf.duplex_str, "full", 5) =3D=3D 0) { + n->net_conf.duplex =3D DUPLEX_FULL; + } else { + error_setg(errp, "'duplex' must be 'half' or 'full'"); + } + } else { + n->net_conf.duplex =3D DUPLEX_UNKNOWN; + } + if (n->net_conf.speed < SPEED_UNKNOWN) { + error_setg(errp, "'speed' must be between -1 (SPEED_UNKOWN) an= d " + "INT_MAX"); + } + virtio_net_set_config_size(n, n->host_features); virtio_init(vdev, "virtio-net", VIRTIO_ID_NET, n->config_size); =20 @@ -2160,6 +2193,8 @@ static Property virtio_net_properties[] =3D { 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(), }; =20 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; =20 /* Maximum packet size we can receive from tap device: header + 64k */ diff --git a/include/standard-headers/linux/virtio_net.h b/include/standard= -headers/linux/virtio_net.h index 30ff249..17c8531 100644 --- a/include/standard-headers/linux/virtio_net.h +++ b/include/standard-headers/linux/virtio_net.h @@ -57,6 +57,8 @@ * Steering */ #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ =20 +#define VIRTIO_NET_F_SPEED_DUPLEX 63 /* Device set linkspeed and duplex = */ + #ifndef VIRTIO_NET_NO_LEGACY #define VIRTIO_NET_F_GSO 6 /* Host handles pkts w/ any GSO type */ #endif /* VIRTIO_NET_NO_LEGACY */ @@ -76,6 +78,17 @@ struct virtio_net_config { uint16_t max_virtqueue_pairs; /* Default maximum transmit unit advice */ uint16_t mtu; + /* + * speed, in units of 1Mb. All values 0 to INT_MAX are legal. + * Any other value stands for unknown. + */ + uint32_t speed; + /* + * 0x00 - half duplex + * 0x01 - full duplex + * Any other value stands for unknown. + */ + uint8_t duplex; } QEMU_PACKED; =20 /*