virtio_net.c (0edbf9e55295585bbe9df61b646ca5bf80a8e1eb) virtio_net.c (4490001029012539937ff02778fe6180613fa949)
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.

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

1414 .get_ringparam = virtnet_get_ringparam,
1415 .set_channels = virtnet_set_channels,
1416 .get_channels = virtnet_get_channels,
1417 .get_ts_info = ethtool_op_get_ts_info,
1418 .get_settings = virtnet_get_settings,
1419 .set_settings = virtnet_set_settings,
1420};
1421
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.

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

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

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

1748 VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR,
1749 "VIRTIO_NET_F_CTRL_VQ"))) {
1750 return false;
1751 }
1752
1753 return true;
1754}
1755
1429 .ndo_get_stats64 = virtnet_stats,
1430 .ndo_vlan_rx_add_vid = virtnet_vlan_rx_add_vid,
1431 .ndo_vlan_rx_kill_vid = virtnet_vlan_rx_kill_vid,
1432#ifdef CONFIG_NET_POLL_CONTROLLER
1433 .ndo_poll_controller = virtnet_netpoll,
1434#endif
1435#ifdef CONFIG_NET_RX_BUSY_POLL
1436 .ndo_busy_poll = virtnet_busy_poll,

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

1736 VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR,
1737 "VIRTIO_NET_F_CTRL_VQ"))) {
1738 return false;
1739 }
1740
1741 return true;
1742}
1743
1744#define MIN_MTU ETH_MIN_MTU
1745#define MAX_MTU ETH_MAX_MTU
1746
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
1747static int virtnet_probe(struct virtio_device *vdev)
1748{
1749 int i, err;
1750 struct net_device *dev;
1751 struct virtnet_info *vi;
1752 u16 max_queue_pairs;
1753 int mtu;
1754

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

1812 dev->features |= dev->hw_features & (NETIF_F_ALL_TSO|NETIF_F_UFO);
1813 /* (!csum && gso) case will be fixed by register_netdev() */
1814 }
1815 if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM))
1816 dev->features |= NETIF_F_RXCSUM;
1817
1818 dev->vlan_features = dev->features;
1819
1820 /* MTU range: 68 - 65535 */
1821 dev->min_mtu = MIN_MTU;
1822 dev->max_mtu = MAX_MTU;
1823
1829 /* Configuration may specify what MAC to use. Otherwise random. */
1830 if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC))
1831 virtio_cread_bytes(vdev,
1832 offsetof(struct virtio_net_config, mac),
1833 dev->dev_addr, dev->addr_len);
1834 else
1835 eth_hw_addr_random(dev);
1836

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

1875
1876 if (virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ))
1877 vi->has_cvq = true;
1878
1879 if (virtio_has_feature(vdev, VIRTIO_NET_F_MTU)) {
1880 mtu = virtio_cread16(vdev,
1881 offsetof(struct virtio_net_config,
1882 mtu));
1824 /* Configuration may specify what MAC to use. Otherwise random. */
1825 if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC))
1826 virtio_cread_bytes(vdev,
1827 offsetof(struct virtio_net_config, mac),
1828 dev->dev_addr, dev->addr_len);
1829 else
1830 eth_hw_addr_random(dev);
1831

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

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

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

1914 virtio_device_ready(vdev);
1915
1916 err = virtnet_cpu_notif_add(vi);
1917 if (err) {
1918 pr_debug("virtio_net: registering cpu notifier failed\n");
1919 goto free_unregister_netdev;
1920 }
1921
1894 vi->max_queue_pairs = max_queue_pairs;
1895
1896 /* Allocate/initialize the rx/tx queues, and invoke find_vqs */
1897 err = init_vqs(vi);
1898 if (err)
1899 goto free_stats;
1900
1901#ifdef CONFIG_SYSFS

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

1916 virtio_device_ready(vdev);
1917
1918 err = virtnet_cpu_notif_add(vi);
1919 if (err) {
1920 pr_debug("virtio_net: registering cpu notifier failed\n");
1921 goto free_unregister_netdev;
1922 }
1923
1924 virtnet_set_affinity(vi);
1925
1922 /* Assume link up if device can't report link status,
1923 otherwise get link status from config. */
1924 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_STATUS)) {
1925 netif_carrier_off(dev);
1926 schedule_work(&vi->config_work);
1927 } else {
1928 vi->status = VIRTIO_NET_S_LINK_UP;
1929 netif_carrier_on(dev);

--- 194 unchanged lines hidden ---
1926 /* Assume link up if device can't report link status,
1927 otherwise get link status from config. */
1928 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_STATUS)) {
1929 netif_carrier_off(dev);
1930 schedule_work(&vi->config_work);
1931 } else {
1932 vi->status = VIRTIO_NET_S_LINK_UP;
1933 netif_carrier_on(dev);

--- 194 unchanged lines hidden ---