Skip to content

Commit 14de9d1

Browse files
apconoledavem330
authored andcommitted
virtio-net: Add initial MTU advice feature
This commit adds the feature bit and associated mtu device entry for the virtio network device. When a virtio device comes up, it checks the feature bit for the VIRTIO_NET_F_MTU feature. If such feature bit is enabled, the driver will read the advised MTU and use it as the initial value. Signed-off-by: Aaron Conole <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3d9dc40 commit 14de9d1

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

drivers/net/virtio_net.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,7 @@ static int virtnet_probe(struct virtio_device *vdev)
17801780
struct net_device *dev;
17811781
struct virtnet_info *vi;
17821782
u16 max_queue_pairs;
1783+
int mtu;
17831784

17841785
if (!vdev->config->get) {
17851786
dev_err(&vdev->dev, "%s failure: config access disabled\n",
@@ -1896,6 +1897,14 @@ static int virtnet_probe(struct virtio_device *vdev)
18961897
if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ))
18971898
vi->has_cvq = true;
18981899

1900+
if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
1901+
mtu = virtio_cread16(vdev,
1902+
offsetof(struct virtio_net_config,
1903+
mtu));
1904+
if (virtnet_change_mtu(dev, mtu))
1905+
__virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);
1906+
}
1907+
18991908
if (vi->any_header_sg)
19001909
dev->needed_headroom = vi->hdr_len;
19011910

@@ -2067,6 +2076,7 @@ static unsigned int features[] = {
20672076
VIRTIO_NET_F_GUEST_ANNOUNCE, VIRTIO_NET_F_MQ,
20682077
VIRTIO_NET_F_CTRL_MAC_ADDR,
20692078
VIRTIO_F_ANY_LAYOUT,
2079+
VIRTIO_NET_F_MTU,
20702080
};
20712081

20722082
static struct virtio_driver virtio_net_driver = {

include/uapi/linux/virtio_net.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow
5656
* Steering */
5757
#define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */
58+
#define VIRTIO_NET_F_MTU 25 /* Initial MTU advice */
5859

5960
#ifndef VIRTIO_NET_NO_LEGACY
6061
#define VIRTIO_NET_F_GSO 6 /* Host handles pkts w/ any GSO type */
@@ -73,6 +74,8 @@ struct virtio_net_config {
7374
* Legal values are between 1 and 0x8000
7475
*/
7576
__u16 max_virtqueue_pairs;
77+
/* Default maximum transmit unit advice */
78+
__u16 mtu;
7679
} __attribute__((packed));
7780

7881
/*

0 commit comments

Comments
 (0)