From nobody Mon Oct 20 07:25:09 2025 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520479672559559.2214311663433; Wed, 7 Mar 2018 19:27:52 -0800 (PST) Received: from localhost ([::1]:36647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etmDd-0000US-ND for importer@patchew.org; Wed, 07 Mar 2018 22:27:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etmBp-0007ws-4m for qemu-devel@nongnu.org; Wed, 07 Mar 2018 22:25:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etmBl-0002zv-OF for qemu-devel@nongnu.org; Wed, 07 Mar 2018 22:25:57 -0500 Received: from mx0b-00190b01.pphosted.com ([2620:100:9005:57f::1]:49876) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1etmBl-0002zf-CC for qemu-devel@nongnu.org; Wed, 07 Mar 2018 22:25:53 -0500 Received: from pps.filterd (m0122331.ppops.net [127.0.0.1]) by mx0b-00190b01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w283MsXd004428; Thu, 8 Mar 2018 03:25:51 GMT Received: from prod-mail-ppoint2 (prod-mail-ppoint2.akamai.com [184.51.33.19]) by mx0b-00190b01.pphosted.com with ESMTP id 2gjcyf2s5a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Mar 2018 03:25:51 +0000 Received: from pps.filterd (prod-mail-ppoint2.akamai.com [127.0.0.1]) by prod-mail-ppoint2.akamai.com (8.16.0.21/8.16.0.21) with SMTP id w283KfQ3026386; Wed, 7 Mar 2018 22:25:50 -0500 Received: from prod-mail-relay11.akamai.com ([172.27.118.250]) by prod-mail-ppoint2.akamai.com with ESMTP id 2gfqwy8aah-1; Wed, 07 Mar 2018 22:25:50 -0500 Received: from bos-lpjec.kendall.corp.akamai.com (bos-lpjec.kendall.corp.akamai.com [172.28.13.109]) by prod-mail-relay11.akamai.com (Postfix) with ESMTP id 8C04732D53; Thu, 8 Mar 2018 03:25:50 +0000 (GMT) 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 : in-reply-to : references; s=jan2016.eng; bh=Qi5H4+aqPG4Fvn0l5yK4zsaw4o+y8FGE2cjy1GrbDDc=; b=o4aFju8LWrQuyVOSx02zYs6a54RkWAnP9oQsNuTyJqRfKgp2A5RsZBcfSlIkgnNpG1jN KdxGA9wtETPUtQU0Elih3uMpVf5IvBGOxP86e8/Jmt62RVWTO8vunwT3cWA1y7f7WxmQ Cgwreiln+xv/L3qAGOsGHDR7U/7Hv0vL20pIjcKo4tLZK+qnGU28gAp7Pr+675+Zfezv Wfh7889i2a0mq50Fr/rv6ZLwTljY450SxotYHYCMdORC4+XiDk+7gLO2UIIAYSsioFLF VCAyXXhm1gC2uAhRpX35XCiKKQ84vx4PnkWXayf+ekcUpxKtDHnCqhwxHlEDj2jJBny6 kw== To: qemu-devel@nongnu.org Date: Wed, 7 Mar 2018 22:25:41 -0500 Message-Id: X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-08_02:, , signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 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-1803080039 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-08_02:, , signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 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-1803080040 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 2620:100:9005:57f::1 Subject: [Qemu-devel] [PATCH v2 3/3] virtio-net: 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: virtio-dev@lists.oasis-open.org, jasowang@redhat.com, mst@redhat.com 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 [0...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 | 26 ++++++++++++++++++++++++++ include/hw/virtio/virtio-net.h | 3 +++ 2 files changed, 29 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 4feaa49..c3ce7d2 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -26,6 +26,7 @@ #include "qapi-event.h" #include "hw/virtio/virtio-access.h" #include "migration/misc.h" +#include "standard-headers/linux/ethtool.h" =20 #define VIRTIO_NET_VM_VERSION 11 =20 @@ -61,6 +62,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 +92,8 @@ static void virtio_net_get_config(VirtIODevice *vdev, uin= t8_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 =3D n->net_conf.duplex; memcpy(config, &netcfg, n->config_size); } =20 @@ -1941,6 +1946,25 @@ static void virtio_net_device_realize(DeviceState *d= ev, Error **errp) n->host_features |=3D (1ULL << VIRTIO_NET_F_MTU); } =20 + 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'"); + } + n->host_features |=3D (1ULL << VIRTIO_NET_F_SPEED_DUPLEX); + } else { + n->net_conf.duplex =3D 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 >=3D 0) { + n->host_features |=3D (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); =20 @@ -2161,6 +2185,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 */ --=20 2.7.4