virtio_net.c (152fce5a2371f64c57abf99dbb0600cc18d399d4) virtio_net.c (a220871be66f99d8957c693cf22ec67ecbd9c23a)
1/* A network driver using virtio.
2 *
3 * Copyright 2007 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.

--- 1414 unchanged lines hidden (view full) ---

1423 .get_ringparam = virtnet_get_ringparam,
1424 .set_channels = virtnet_set_channels,
1425 .get_channels = virtnet_get_channels,
1426 .get_ts_info = ethtool_op_get_ts_info,
1427 .get_settings = virtnet_get_settings,
1428 .set_settings = virtnet_set_settings,
1429};
1430
1/* A network driver using virtio.
2 *
3 * Copyright 2007 Rusty Russell <rusty@rustcorp.com.au> IBM Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.

--- 1414 unchanged lines hidden (view full) ---

1423 .get_ringparam = virtnet_get_ringparam,
1424 .set_channels = virtnet_set_channels,
1425 .get_channels = virtnet_get_channels,
1426 .get_ts_info = ethtool_op_get_ts_info,
1427 .get_settings = virtnet_get_settings,
1428 .set_settings = virtnet_set_settings,
1429};
1430
1431#define MIN_MTU 68
1432#define MAX_MTU 65535
1433
1434static int virtnet_change_mtu(struct net_device *dev, int new_mtu)
1435{
1436 if (new_mtu < MIN_MTU || new_mtu > MAX_MTU)
1437 return -EINVAL;
1438 dev->mtu = new_mtu;
1439 return 0;
1440}
1441
1442static const struct net_device_ops virtnet_netdev = {
1443 .ndo_open = virtnet_open,
1444 .ndo_stop = virtnet_close,
1445 .ndo_start_xmit = start_xmit,
1446 .ndo_validate_addr = eth_validate_addr,
1447 .ndo_set_mac_address = virtnet_set_mac_address,
1448 .ndo_set_rx_mode = virtnet_set_rx_mode,
1431static const struct net_device_ops virtnet_netdev = {
1432 .ndo_open = virtnet_open,
1433 .ndo_stop = virtnet_close,
1434 .ndo_start_xmit = start_xmit,
1435 .ndo_validate_addr = eth_validate_addr,
1436 .ndo_set_mac_address = virtnet_set_mac_address,
1437 .ndo_set_rx_mode = virtnet_set_rx_mode,
1449 .ndo_change_mtu = virtnet_change_mtu,
1450 .ndo_get_stats64 = virtnet_stats,
1451 .ndo_vlan_rx_add_vid = virtnet_vlan_rx_add_vid,
1452 .ndo_vlan_rx_kill_vid = virtnet_vlan_rx_kill_vid,
1453#ifdef CONFIG_NET_POLL_CONTROLLER
1454 .ndo_poll_controller = virtnet_netpoll,
1455#endif
1456#ifdef CONFIG_NET_RX_BUSY_POLL
1457 .ndo_busy_poll = virtnet_busy_poll,

--- 299 unchanged lines hidden (view full) ---

1757 VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR,
1758 "VIRTIO_NET_F_CTRL_VQ"))) {
1759 return false;
1760 }
1761
1762 return true;
1763}
1764
1438 .ndo_get_stats64 = virtnet_stats,
1439 .ndo_vlan_rx_add_vid = virtnet_vlan_rx_add_vid,
1440 .ndo_vlan_rx_kill_vid = virtnet_vlan_rx_kill_vid,
1441#ifdef CONFIG_NET_POLL_CONTROLLER
1442 .ndo_poll_controller = virtnet_netpoll,
1443#endif
1444#ifdef CONFIG_NET_RX_BUSY_POLL
1445 .ndo_busy_poll = virtnet_busy_poll,

--- 299 unchanged lines hidden (view full) ---

1745 VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR,
1746 "VIRTIO_NET_F_CTRL_VQ"))) {
1747 return false;
1748 }
1749
1750 return true;
1751}
1752
1753#define MIN_MTU ETH_MIN_MTU
1754#define MAX_MTU ETH_MAX_MTU
1755
1765static int virtnet_probe(struct virtio_device *vdev)
1766{
1767 int i, err;
1768 struct net_device *dev;
1769 struct virtnet_info *vi;
1770 u16 max_queue_pairs;
1771 int mtu;
1772

--- 57 unchanged lines hidden (view full) ---

1830 dev->features |= dev->hw_features & (NETIF_F_ALL_TSO|NETIF_F_UFO);
1831 /* (!csum && gso) case will be fixed by register_netdev() */
1832 }
1833 if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM))
1834 dev->features |= NETIF_F_RXCSUM;
1835
1836 dev->vlan_features = dev->features;
1837
1756static int virtnet_probe(struct virtio_device *vdev)
1757{
1758 int i, err;
1759 struct net_device *dev;
1760 struct virtnet_info *vi;
1761 u16 max_queue_pairs;
1762 int mtu;
1763

--- 57 unchanged lines hidden (view full) ---

1821 dev->features |= dev->hw_features & (NETIF_F_ALL_TSO|NETIF_F_UFO);
1822 /* (!csum && gso) case will be fixed by register_netdev() */
1823 }
1824 if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM))
1825 dev->features |= NETIF_F_RXCSUM;
1826
1827 dev->vlan_features = dev->features;
1828
1829 /* MTU range: 68 - 65535 */
1830 dev->min_mtu = MIN_MTU;
1831 dev->max_mtu = MAX_MTU;
1832
1838 /* Configuration may specify what MAC to use. Otherwise random. */
1839 if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC))
1840 virtio_cread_bytes(vdev,
1841 offsetof(struct virtio_net_config, mac),
1842 dev->dev_addr, dev->addr_len);
1843 else
1844 eth_hw_addr_random(dev);
1845

--- 38 unchanged lines hidden (view full) ---

1884
1885 if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ))
1886 vi->has_cvq = true;
1887
1888 if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
1889 mtu = virtio_cread16(vdev,
1890 offsetof(struct virtio_net_config,
1891 mtu));
1833 /* Configuration may specify what MAC to use. Otherwise random. */
1834 if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC))
1835 virtio_cread_bytes(vdev,
1836 offsetof(struct virtio_net_config, mac),
1837 dev->dev_addr, dev->addr_len);
1838 else
1839 eth_hw_addr_random(dev);
1840

--- 38 unchanged lines hidden (view full) ---

1879
1880 if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ))
1881 vi->has_cvq = true;
1882
1883 if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
1884 mtu = virtio_cread16(vdev,
1885 offsetof(struct virtio_net_config,
1886 mtu));
1892 if (virtnet_change_mtu(dev, mtu))
1887 if (mtu < dev->min_mtu) {
1893 __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);
1888 __virtio_clear_bit(vdev, VIRTIO_NET_F_MTU);
1889 } else {
1890 dev->mtu = mtu;
1891 dev->max_mtu = mtu;
1892 }
1894 }
1895
1896 if (vi->any_header_sg)
1897 dev->needed_headroom = vi->hdr_len;
1898
1893 }
1894
1895 if (vi->any_header_sg)
1896 dev->needed_headroom = vi->hdr_len;
1897
1899 /* Use single tx/rx queue pair as default */
1900 vi->curr_queue_pairs = 1;
1898 /* Enable multiqueue by default */
1899 if (num_online_cpus() >= max_queue_pairs)
1900 vi->curr_queue_pairs = max_queue_pairs;
1901 else
1902 vi->curr_queue_pairs = num_online_cpus();
1901 vi->max_queue_pairs = max_queue_pairs;
1902
1903 /* Allocate/initialize the rx/tx queues, and invoke find_vqs */
1904 err = init_vqs(vi);
1905 if (err)
1906 goto free_stats;
1907
1908#ifdef CONFIG_SYSFS

--- 14 unchanged lines hidden (view full) ---

1923 virtio_device_ready(vdev);
1924
1925 err = virtnet_cpu_notif_add(vi);
1926 if (err) {
1927 pr_debug("virtio_net: registering cpu notifier failed\n");
1928 goto free_unregister_netdev;
1929 }
1930
1903 vi->max_queue_pairs = max_queue_pairs;
1904
1905 /* Allocate/initialize the rx/tx queues, and invoke find_vqs */
1906 err = init_vqs(vi);
1907 if (err)
1908 goto free_stats;
1909
1910#ifdef CONFIG_SYSFS

--- 14 unchanged lines hidden (view full) ---

1925 virtio_device_ready(vdev);
1926
1927 err = virtnet_cpu_notif_add(vi);
1928 if (err) {
1929 pr_debug("virtio_net: registering cpu notifier failed\n");
1930 goto free_unregister_netdev;
1931 }
1932
1933 rtnl_lock();
1934 virtnet_set_queues(vi, vi->curr_queue_pairs);
1935 rtnl_unlock();
1936
1931 /* Assume link up if device can't report link status,
1932 otherwise get link status from config. */
1933 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_STATUS)) {
1934 netif_carrier_off(dev);
1935 schedule_work(&vi->config_work);
1936 } else {
1937 vi->status = VIRTIO_NET_S_LINK_UP;
1938 netif_carrier_on(dev);

--- 194 unchanged lines hidden ---
1937 /* Assume link up if device can't report link status,
1938 otherwise get link status from config. */
1939 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_STATUS)) {
1940 netif_carrier_off(dev);
1941 schedule_work(&vi->config_work);
1942 } else {
1943 vi->status = VIRTIO_NET_S_LINK_UP;
1944 netif_carrier_on(dev);

--- 194 unchanged lines hidden ---