From nobody Mon Apr 29 18:18:18 2024 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 151504315792616.38490090501932; Wed, 3 Jan 2018 21:19:17 -0800 (PST) Received: from localhost ([::1]:47340 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWxvm-0000zD-Nw for importer@patchew.org; Thu, 04 Jan 2018 00:19:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50692) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWxu7-00081P-Fo for qemu-devel@nongnu.org; Thu, 04 Jan 2018 00:17:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWxu4-0008Sf-AP for qemu-devel@nongnu.org; Thu, 04 Jan 2018 00:17:23 -0500 Received: from mx0a-00190b01.pphosted.com ([2620:100:9001:583::1]:58596) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eWxu4-0008Ql-1S for qemu-devel@nongnu.org; Thu, 04 Jan 2018 00:17:20 -0500 Received: from pps.filterd (m0122332.ppops.net [127.0.0.1]) by mx0a-00190b01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w045H6Bj010449; Thu, 4 Jan 2018 05:17:17 GMT Received: from prod-mail-ppoint3 ([96.6.114.86]) by mx0a-00190b01.pphosted.com with ESMTP id 2f63qmc7mc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 Jan 2018 05:17:17 +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 w045ESsB013085; Thu, 4 Jan 2018 00:17:16 -0500 Received: from prod-mail-relay14.akamai.com ([172.27.17.39]) by prod-mail-ppoint3.akamai.com with ESMTP id 2f95des5my-1; Thu, 04 Jan 2018 00:17:16 -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 585B6821F3; Wed, 3 Jan 2018 22:17:16 -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 : in-reply-to : references; s=jan2016.eng; bh=ymvdqxTs5ejScdI7jLv5WYuEgmJxKx2l0Hhj0VYmucI=; b=IedJ6WLV+9Gxp473uFHrWkiE8oYw+2J/w5hKOxg+1E2EPiUYsJQbo5I8A+bhF7W+vF90 mSRDEFAbfGMKimcvZWpmLMugAdeMjWhhilv2149iGeAggTguqfi3l3KlqcsSxfbOBblA NpLiyKFu9gmgfT64IyK1dVp6j/RJB+u/zXl/LShgCdoKkSRBhs7CrbRZZyzykimZVaIL o0x757Diy88VXN8m3mIL2LhXLajVzOWmCG/MJ+SLgcYwK1t1fnUdEJaYvw0Bnw0OcP1t vFh7v3dKz0SGl+wCOsXhN/qnLN8jBHBu9iH1xYWxb25OF/3V0FSsOjEpe4onvKcyuLfF oA== To: mst@redhat.com, davem@davemloft.net Date: Thu, 4 Jan 2018 00:16:44 -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-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 net-next v3 1/3] virtio_net: propagate linkspeed/duplex settings from the hypervisor 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" The ability to set speed and duplex for virtio_net is useful in various scenarios as described here: 16032be virtio_net: add ethtool support for set and get of settings However, it would be nice to be able to set this from the hypervisor, such that virtio_net doesn't require custom guest ethtool commands. 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'. Note that VIRTIO_NET_F_SPEED_DUPLEX is defined as bit 63, the intention is that device feature bits are to grow down from bit 63, since the transports are starting from bit 24 and growing up. Signed-off-by: Jason Baron Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: virtio-dev@lists.oasis-open.org --- drivers/net/virtio_net.c | 19 ++++++++++++++++++- include/uapi/linux/virtio_net.h | 13 +++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 6fb7b65..0b2d314 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2146,6 +2146,22 @@ static void virtnet_config_changed_work(struct work_= struct *work) =20 vi->status =3D v; =20 + if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_SPEED_DUPLEX)) { + u32 speed; + u8 duplex; + + speed =3D virtio_cread32(vi->vdev, + offsetof(struct virtio_net_config, + speed)); + if (ethtool_validate_speed(speed)) + vi->speed =3D speed; + duplex =3D virtio_cread8(vi->vdev, + offsetof(struct virtio_net_config, + duplex)); + if (ethtool_validate_duplex(duplex)) + vi->duplex =3D duplex; + } + if (vi->status & VIRTIO_NET_S_LINK_UP) { netif_carrier_on(vi->dev); netif_tx_wake_all_queues(vi->dev); @@ -2796,7 +2812,8 @@ static struct virtio_device_id id_table[] =3D { VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN, \ VIRTIO_NET_F_GUEST_ANNOUNCE, VIRTIO_NET_F_MQ, \ VIRTIO_NET_F_CTRL_MAC_ADDR, \ - VIRTIO_NET_F_MTU, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS + VIRTIO_NET_F_MTU, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, \ + VIRTIO_NET_F_SPEED_DUPLEX =20 static unsigned int features[] =3D { VIRTNET_FEATURES, diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_ne= t.h index fc353b5..5de6ed3 100644 --- a/include/uapi/linux/virtio_net.h +++ b/include/uapi/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 { __u16 max_virtqueue_pairs; /* Default maximum transmit unit advice */ __u16 mtu; + /* + * speed, in units of 1Mb. All values 0 to INT_MAX are legal. + * Any other value stands for unknown. + */ + __u32 speed; + /* + * 0x00 - half duplex + * 0x01 - full duplex + * Any other value stands for unknown. + */ + __u8 duplex; } __attribute__((packed)); =20 /* --=20 2.6.1 From nobody Mon Apr 29 18:18:18 2024 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 1515043242957113.22599536854352; Wed, 3 Jan 2018 21:20:42 -0800 (PST) Received: from localhost ([::1]:47352 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWxxI-0002HV-7H for importer@patchew.org; Thu, 04 Jan 2018 00:20:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50674) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWxu5-000804-0U for qemu-devel@nongnu.org; Thu, 04 Jan 2018 00:17:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWxu3-0008Rh-R9 for qemu-devel@nongnu.org; Thu, 04 Jan 2018 00:17:20 -0500 Received: from mx0b-00190b01.pphosted.com ([2620:100:9005:57f::1]:44444) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eWxu3-0008Qq-MB for qemu-devel@nongnu.org; Thu, 04 Jan 2018 00:17:19 -0500 Received: from pps.filterd (m0122331.ppops.net [127.0.0.1]) by mx0b-00190b01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w045GU3U000722; Thu, 4 Jan 2018 05:17:12 GMT Received: from prod-mail-ppoint3 ([96.6.114.86]) by mx0b-00190b01.pphosted.com with ESMTP id 2f60huknnh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 Jan 2018 05:17:12 +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 w045EXiX013098; Thu, 4 Jan 2018 00:17:11 -0500 Received: from prod-mail-relay14.akamai.com ([172.27.17.39]) by prod-mail-ppoint3.akamai.com with ESMTP id 2f95des5mn-1; Thu, 04 Jan 2018 00:17:11 -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 AEEFD821FC; Wed, 3 Jan 2018 22:17:10 -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=/bs2LkOMVaK16pqvwNvN72nNx41s5fS4tc0W51sOAT0=; b=oLDluB88pa0d5I9U+In8CbgHNkdJOKsaLgx0V6taCwDitkhJXFARQxtM+ABViOxFwvO0 Ux24t4ledZEx5t8sfs45q3FWjVwzXPSbNa2W4NNmuq/8datZpEKv3PhXC6c/sPRjVGFn zJd1/T+C8U9DsyJlovqZjI6QsCd6A2WTotpS7AUQck/25jbJnhp3c13FdhRu00xWxeql PoBtWz4qcmWNoiD8Ii8tZy98ZgIwIQGirJhI9lCXCBuKk5fmeCJQ6gZ5sD9PYmvf6UWz BKURPx0k5X7RaiHZqOPYRPIdhtsqhd7A5LFKC8tl5wDOhfDqy4q3wWIwAWw2D5EhHR0G aQ== To: mst@redhat.com, davem@davemloft.net Date: Thu, 4 Jan 2018 00:16:43 -0500 Message-Id: <2289a84dfdbf6e9cf9c9123ab33e6b1c8c38e578.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:9005:57f::1 Subject: [Qemu-devel] [PATCH v3 2/3] qemu: virtio-net: use 64-bit values for feature flags 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" In prepartion for using some of the high order feature bits, make sure that virtio-net uses 64-bit values everywhere. Signed-off-by: Jason Baron Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: virtio-dev@lists.oasis-open.org --- hw/net/virtio-net.c | 54 +++++++++++++++++++++-----------------= ---- include/hw/virtio/virtio-net.h | 2 +- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 38674b0..adc20df 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -48,18 +48,18 @@ (offsetof(container, field) + sizeof(((container *)0)->field)) =20 typedef struct VirtIOFeature { - uint32_t flags; + uint64_t flags; size_t end; } VirtIOFeature; =20 static VirtIOFeature feature_sizes[] =3D { - {.flags =3D 1 << VIRTIO_NET_F_MAC, + {.flags =3D 1ULL << VIRTIO_NET_F_MAC, .end =3D endof(struct virtio_net_config, mac)}, - {.flags =3D 1 << VIRTIO_NET_F_STATUS, + {.flags =3D 1ULL << VIRTIO_NET_F_STATUS, .end =3D endof(struct virtio_net_config, status)}, - {.flags =3D 1 << VIRTIO_NET_F_MQ, + {.flags =3D 1ULL << VIRTIO_NET_F_MQ, .end =3D endof(struct virtio_net_config, max_virtqueue_pairs)}, - {.flags =3D 1 << VIRTIO_NET_F_MTU, + {.flags =3D 1ULL << VIRTIO_NET_F_MTU, .end =3D endof(struct virtio_net_config, mtu)}, {} }; @@ -1938,7 +1938,7 @@ static void virtio_net_device_realize(DeviceState *de= v, Error **errp) int i; =20 if (n->net_conf.mtu) { - n->host_features |=3D (0x1 << VIRTIO_NET_F_MTU); + n->host_features |=3D (1ULL << VIRTIO_NET_F_MTU); } =20 virtio_net_set_config_size(n, n->host_features); @@ -2109,45 +2109,45 @@ static const VMStateDescription vmstate_virtio_net = =3D { }; =20 static Property virtio_net_properties[] =3D { - DEFINE_PROP_BIT("csum", VirtIONet, host_features, VIRTIO_NET_F_CSUM, t= rue), - DEFINE_PROP_BIT("guest_csum", VirtIONet, host_features, + DEFINE_PROP_BIT64("csum", VirtIONet, host_features, VIRTIO_NET_F_CSUM,= true), + DEFINE_PROP_BIT64("guest_csum", VirtIONet, host_features, VIRTIO_NET_F_GUEST_CSUM, true), - DEFINE_PROP_BIT("gso", VirtIONet, host_features, VIRTIO_NET_F_GSO, tru= e), - DEFINE_PROP_BIT("guest_tso4", VirtIONet, host_features, + DEFINE_PROP_BIT64("gso", VirtIONet, host_features, VIRTIO_NET_F_GSO, t= rue), + DEFINE_PROP_BIT64("guest_tso4", VirtIONet, host_features, VIRTIO_NET_F_GUEST_TSO4, true), - DEFINE_PROP_BIT("guest_tso6", VirtIONet, host_features, + DEFINE_PROP_BIT64("guest_tso6", VirtIONet, host_features, VIRTIO_NET_F_GUEST_TSO6, true), - DEFINE_PROP_BIT("guest_ecn", VirtIONet, host_features, + DEFINE_PROP_BIT64("guest_ecn", VirtIONet, host_features, VIRTIO_NET_F_GUEST_ECN, true), - DEFINE_PROP_BIT("guest_ufo", VirtIONet, host_features, + DEFINE_PROP_BIT64("guest_ufo", VirtIONet, host_features, VIRTIO_NET_F_GUEST_UFO, true), - DEFINE_PROP_BIT("guest_announce", VirtIONet, host_features, + DEFINE_PROP_BIT64("guest_announce", VirtIONet, host_features, VIRTIO_NET_F_GUEST_ANNOUNCE, true), - DEFINE_PROP_BIT("host_tso4", VirtIONet, host_features, + DEFINE_PROP_BIT64("host_tso4", VirtIONet, host_features, VIRTIO_NET_F_HOST_TSO4, true), - DEFINE_PROP_BIT("host_tso6", VirtIONet, host_features, + DEFINE_PROP_BIT64("host_tso6", VirtIONet, host_features, VIRTIO_NET_F_HOST_TSO6, true), - DEFINE_PROP_BIT("host_ecn", VirtIONet, host_features, + DEFINE_PROP_BIT64("host_ecn", VirtIONet, host_features, VIRTIO_NET_F_HOST_ECN, true), - DEFINE_PROP_BIT("host_ufo", VirtIONet, host_features, + DEFINE_PROP_BIT64("host_ufo", VirtIONet, host_features, VIRTIO_NET_F_HOST_UFO, true), - DEFINE_PROP_BIT("mrg_rxbuf", VirtIONet, host_features, + DEFINE_PROP_BIT64("mrg_rxbuf", VirtIONet, host_features, VIRTIO_NET_F_MRG_RXBUF, true), - DEFINE_PROP_BIT("status", VirtIONet, host_features, + DEFINE_PROP_BIT64("status", VirtIONet, host_features, VIRTIO_NET_F_STATUS, true), - DEFINE_PROP_BIT("ctrl_vq", VirtIONet, host_features, + DEFINE_PROP_BIT64("ctrl_vq", VirtIONet, host_features, VIRTIO_NET_F_CTRL_VQ, true), - DEFINE_PROP_BIT("ctrl_rx", VirtIONet, host_features, + DEFINE_PROP_BIT64("ctrl_rx", VirtIONet, host_features, VIRTIO_NET_F_CTRL_RX, true), - DEFINE_PROP_BIT("ctrl_vlan", VirtIONet, host_features, + DEFINE_PROP_BIT64("ctrl_vlan", VirtIONet, host_features, VIRTIO_NET_F_CTRL_VLAN, true), - DEFINE_PROP_BIT("ctrl_rx_extra", VirtIONet, host_features, + DEFINE_PROP_BIT64("ctrl_rx_extra", VirtIONet, host_features, VIRTIO_NET_F_CTRL_RX_EXTRA, true), - DEFINE_PROP_BIT("ctrl_mac_addr", VirtIONet, host_features, + DEFINE_PROP_BIT64("ctrl_mac_addr", VirtIONet, host_features, VIRTIO_NET_F_CTRL_MAC_ADDR, true), - DEFINE_PROP_BIT("ctrl_guest_offloads", VirtIONet, host_features, + DEFINE_PROP_BIT64("ctrl_guest_offloads", VirtIONet, host_features, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, true), - DEFINE_PROP_BIT("mq", VirtIONet, host_features, VIRTIO_NET_F_MQ, false= ), + DEFINE_PROP_BIT64("mq", VirtIONet, host_features, VIRTIO_NET_F_MQ, fal= se), DEFINE_NIC_PROPERTIES(VirtIONet, nic_conf), DEFINE_PROP_UINT32("x-txtimer", VirtIONet, net_conf.txtimer, TX_TIMER_INTERVAL), diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index b81b6a4..e7634c9 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -67,7 +67,7 @@ typedef struct VirtIONet { uint32_t has_vnet_hdr; size_t host_hdr_len; size_t guest_hdr_len; - uint32_t host_features; + uint64_t host_features; uint8_t has_ufo; uint32_t mergeable_rx_bufs; uint8_t promisc; --=20 2.6.1 From nobody Mon Apr 29 18:18:18 2024 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 /*