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 <pulkomandy@gmail.com>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Jérôme Duval 2020-03-18 10:07:48 +01:00 committed by waddlesplash
parent d8e1fd6eda
commit 6d72c4188e
2 changed files with 20 additions and 1 deletions

View File

@ -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]);

View File

@ -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;
/*