aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Baron <jbaron@akamai.com>2018-01-05 17:44:54 -0500
committerDavid S. Miller <davem@davemloft.net>2018-01-09 11:37:56 -0500
commitfaa9b39f0e9ddfa8c83725b3f230784976dd3c7f (patch)
tree525e76db6fc11077f8a83cb981710f3be82d862f
parentccfdec9089229503d3a305e02accac01817d293e (diff)
virtio_net: propagate linkspeed/duplex settings from the hypervisor
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 <jbaron@akamai.com> Cc: "Michael S. Tsirkin" <mst@redhat.com> Cc: Jason Wang <jasowang@redhat.com> Cc: virtio-dev@lists.oasis-open.org Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/virtio_net.c23
-rw-r--r--include/uapi/linux/virtio_net.h13
2 files changed, 35 insertions, 1 deletions
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index ed8299343728..12dfc5fee58e 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1906,6 +1906,24 @@ static void virtnet_init_settings(struct net_device *dev)
1906 vi->duplex = DUPLEX_UNKNOWN; 1906 vi->duplex = DUPLEX_UNKNOWN;
1907} 1907}
1908 1908
1909static void virtnet_update_settings(struct virtnet_info *vi)
1910{
1911 u32 speed;
1912 u8 duplex;
1913
1914 if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_SPEED_DUPLEX))
1915 return;
1916
1917 speed = virtio_cread32(vi->vdev, offsetof(struct virtio_net_config,
1918 speed));
1919 if (ethtool_validate_speed(speed))
1920 vi->speed = speed;
1921 duplex = virtio_cread8(vi->vdev, offsetof(struct virtio_net_config,
1922 duplex));
1923 if (ethtool_validate_duplex(duplex))
1924 vi->duplex = duplex;
1925}
1926
1909static const struct ethtool_ops virtnet_ethtool_ops = { 1927static const struct ethtool_ops virtnet_ethtool_ops = {
1910 .get_drvinfo = virtnet_get_drvinfo, 1928 .get_drvinfo = virtnet_get_drvinfo,
1911 .get_link = ethtool_op_get_link, 1929 .get_link = ethtool_op_get_link,
@@ -2159,6 +2177,7 @@ static void virtnet_config_changed_work(struct work_struct *work)
2159 vi->status = v; 2177 vi->status = v;
2160 2178
2161 if (vi->status & VIRTIO_NET_S_LINK_UP) { 2179 if (vi->status & VIRTIO_NET_S_LINK_UP) {
2180 virtnet_update_settings(vi);
2162 netif_carrier_on(vi->dev); 2181 netif_carrier_on(vi->dev);
2163 netif_tx_wake_all_queues(vi->dev); 2182 netif_tx_wake_all_queues(vi->dev);
2164 } else { 2183 } else {
@@ -2707,6 +2726,7 @@ static int virtnet_probe(struct virtio_device *vdev)
2707 schedule_work(&vi->config_work); 2726 schedule_work(&vi->config_work);
2708 } else { 2727 } else {
2709 vi->status = VIRTIO_NET_S_LINK_UP; 2728 vi->status = VIRTIO_NET_S_LINK_UP;
2729 virtnet_update_settings(vi);
2710 netif_carrier_on(dev); 2730 netif_carrier_on(dev);
2711 } 2731 }
2712 2732
@@ -2808,7 +2828,8 @@ static struct virtio_device_id id_table[] = {
2808 VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN, \ 2828 VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN, \
2809 VIRTIO_NET_F_GUEST_ANNOUNCE, VIRTIO_NET_F_MQ, \ 2829 VIRTIO_NET_F_GUEST_ANNOUNCE, VIRTIO_NET_F_MQ, \
2810 VIRTIO_NET_F_CTRL_MAC_ADDR, \ 2830 VIRTIO_NET_F_CTRL_MAC_ADDR, \
2811 VIRTIO_NET_F_MTU, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 2831 VIRTIO_NET_F_MTU, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, \
2832 VIRTIO_NET_F_SPEED_DUPLEX
2812 2833
2813static unsigned int features[] = { 2834static unsigned int features[] = {
2814 VIRTNET_FEATURES, 2835 VIRTNET_FEATURES,
diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_net.h
index fc353b518288..5de6ed37695b 100644
--- a/include/uapi/linux/virtio_net.h
+++ b/include/uapi/linux/virtio_net.h
@@ -57,6 +57,8 @@
57 * Steering */ 57 * Steering */
58#define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ 58#define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */
59 59
60#define VIRTIO_NET_F_SPEED_DUPLEX 63 /* Device set linkspeed and duplex */
61
60#ifndef VIRTIO_NET_NO_LEGACY 62#ifndef VIRTIO_NET_NO_LEGACY
61#define VIRTIO_NET_F_GSO 6 /* Host handles pkts w/ any GSO type */ 63#define VIRTIO_NET_F_GSO 6 /* Host handles pkts w/ any GSO type */
62#endif /* VIRTIO_NET_NO_LEGACY */ 64#endif /* VIRTIO_NET_NO_LEGACY */
@@ -76,6 +78,17 @@ struct virtio_net_config {
76 __u16 max_virtqueue_pairs; 78 __u16 max_virtqueue_pairs;
77 /* Default maximum transmit unit advice */ 79 /* Default maximum transmit unit advice */
78 __u16 mtu; 80 __u16 mtu;
81 /*
82 * speed, in units of 1Mb. All values 0 to INT_MAX are legal.
83 * Any other value stands for unknown.
84 */
85 __u32 speed;
86 /*
87 * 0x00 - half duplex
88 * 0x01 - full duplex
89 * Any other value stands for unknown.
90 */
91 __u8 duplex;
79} __attribute__((packed)); 92} __attribute__((packed));
80 93
81/* 94/*