From 6d72c4188e001484e81fe27174cd57a89d266971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Wed, 18 Mar 2020 10:07:48 +0100 Subject: [PATCH] virtio_net: add VIRTIO_NET_F_MTU support Change-Id: Ie61fa0e0fe13a63d5b0ebde08303a1df836b1b52 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2384 Reviewed-by: Adrien Destugues Reviewed-by: waddlesplash --- .../drivers/network/virtio/virtio_net.cpp | 19 ++++++++++++++++++- .../drivers/network/virtio/virtio_net.h | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/add-ons/kernel/drivers/network/virtio/virtio_net.cpp b/src/add-ons/kernel/drivers/network/virtio/virtio_net.cpp index d6af769a6f..6bc10073fd 100644 --- a/src/add-ons/kernel/drivers/network/virtio/virtio_net.cpp +++ b/src/add-ons/kernel/drivers/network/virtio/virtio_net.cpp @@ -125,6 +125,8 @@ get_feature_name(uint32 feature) return "host checksum"; case VIRTIO_NET_F_GUEST_CSUM: return "guest checksum"; + case VIRTIO_NET_F_MTU: + return "mtu"; case VIRTIO_NET_F_MAC: return "macaddress"; case VIRTIO_NET_F_GSO: @@ -224,7 +226,7 @@ virtio_net_init_device(void* _info, void** _cookie) sDeviceManager->put_node(parent); info->virtio->negotiate_features(info->virtio_device, - VIRTIO_NET_F_STATUS | VIRTIO_NET_F_MAC + VIRTIO_NET_F_STATUS | VIRTIO_NET_F_MAC | VIRTIO_NET_F_MTU /* VIRTIO_NET_F_CTRL_VQ | VIRTIO_NET_F_MQ */, &info->features, &get_feature_name); @@ -474,6 +476,21 @@ virtio_net_open(void* _info, const char* path, int openMode, void** _cookie) &info->macaddr, sizeof(info->macaddr)); } + if ((info->features & VIRTIO_NET_F_MTU) != 0) { + dprintf("mtu feature\n"); + uint16 mtu; + info->virtio->read_device_config(info->virtio_device, + offsetof(struct virtio_net_config, mtu), + &mtu, sizeof(mtu)); + // check against minimum MTU + if (mtu > 68) + info->maxframesize = mtu; + else + info->virtio->clear_feature(info->virtio_device, VIRTIO_NET_F_MTU); + } else { + dprintf("no mtu feature\n"); + } + for (int i = 0; i < info->rxSizes[0]; i++) virtio_net_rx_enqueue_buf(info, info->rxBufInfos[i]); diff --git a/src/add-ons/kernel/drivers/network/virtio/virtio_net.h b/src/add-ons/kernel/drivers/network/virtio/virtio_net.h index 315b730006..a7f8f70abe 100644 --- a/src/add-ons/kernel/drivers/network/virtio/virtio_net.h +++ b/src/add-ons/kernel/drivers/network/virtio/virtio_net.h @@ -34,6 +34,7 @@ /* The feature bitmap for virtio net */ #define VIRTIO_NET_F_CSUM 0x00001 /* Host handles pkts w/ partial csum */ #define VIRTIO_NET_F_GUEST_CSUM 0x00002 /* Guest handles pkts w/ partial csum*/ +#define VIRTIO_NET_F_MTU 0x00008 /* Initial MTU advice. */ #define VIRTIO_NET_F_MAC 0x00020 /* Host has given MAC address. */ #define VIRTIO_NET_F_GSO 0x00040 /* Host handles pkts w/ any GSO type */ #define VIRTIO_NET_F_GUEST_TSO4 0x00080 /* Guest can handle TSOv4 in. */ @@ -66,6 +67,7 @@ struct virtio_net_config { * Legal values are between 1 and 0x8000. */ uint16_t max_virtqueue_pairs; + uint16_t mtu; } _PACKED; /*