@@ -613,6 +613,29 @@ static struct ethtool_ops virtnet_ethtool_ops = {
.set_tso = ethtool_op_set_tso,
};
+#define MIN_MTU 68
+#define MAX_MTU 65535
+
+static int virtnet_change_mtu(struct net_device *dev, int new_mtu)
+{
+ struct virtnet_info *vi = netdev_priv(dev);
+ int max_mtu;
+
+ /* Only allow a large MTU if we know we have a chance
+ * of also supporting that MTU on the receive side. */
+ if (vi->mergeable_rx_bufs || vi->big_packets)
+ max_mtu = MAX_MTU;
+ else
+ max_mtu = ETH_DATA_LEN;
+
+ if (new_mtu < MIN_MTU || new_mtu > max_mtu)
+ return -EINVAL;
+
+ dev->mtu = new_mtu;
+
+ return 0;
+}
+
static int virtnet_probe(struct virtio_device *vdev)
{
int err;
@@ -628,6 +651,7 @@ static int virtnet_probe(struct virtio_device *vdev)
dev->open = virtnet_open;
dev->stop = virtnet_close;
dev->hard_start_xmit = start_xmit;
+ dev->change_mtu = virtnet_change_mtu;
dev->features = NETIF_F_HIGHDMA;
#ifdef CONFIG_NET_POLL_CONTROLLER
dev->poll_controller = virtnet_netpoll;