virtio_net.c (288379f050284087578b77e04f040b57db3db3f8) | virtio_net.c (9f4d26d0f3016cf8813977d624751b94465fa317) |
---|---|
1/* A simple 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. --- 28 unchanged lines hidden (view full) --- 37#define GOOD_COPY_LEN 128 38 39struct virtnet_info 40{ 41 struct virtio_device *vdev; 42 struct virtqueue *rvq, *svq; 43 struct net_device *dev; 44 struct napi_struct napi; | 1/* A simple 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. --- 28 unchanged lines hidden (view full) --- 37#define GOOD_COPY_LEN 128 38 39struct virtnet_info 40{ 41 struct virtio_device *vdev; 42 struct virtqueue *rvq, *svq; 43 struct net_device *dev; 44 struct napi_struct napi; |
45 unsigned int status; |
|
45 46 /* The skb we couldn't send because buffers were full. */ 47 struct sk_buff *last_xmit_skb; 48 49 /* If we need to free in a timer, this is it. */ 50 struct timer_list xmit_free_timer; 51 52 /* Number of input buffers, and max we've ever had. */ --- 553 unchanged lines hidden (view full) --- 606 607 return ethtool_op_set_tx_hw_csum(dev, data); 608} 609 610static struct ethtool_ops virtnet_ethtool_ops = { 611 .set_tx_csum = virtnet_set_tx_csum, 612 .set_sg = ethtool_op_set_sg, 613 .set_tso = ethtool_op_set_tso, | 46 47 /* The skb we couldn't send because buffers were full. */ 48 struct sk_buff *last_xmit_skb; 49 50 /* If we need to free in a timer, this is it. */ 51 struct timer_list xmit_free_timer; 52 53 /* Number of input buffers, and max we've ever had. */ --- 553 unchanged lines hidden (view full) --- 607 608 return ethtool_op_set_tx_hw_csum(dev, data); 609} 610 611static struct ethtool_ops virtnet_ethtool_ops = { 612 .set_tx_csum = virtnet_set_tx_csum, 613 .set_sg = ethtool_op_set_sg, 614 .set_tso = ethtool_op_set_tso, |
615 .get_link = ethtool_op_get_link, |
|
614}; 615 616#define MIN_MTU 68 617#define MAX_MTU 65535 618 619static int virtnet_change_mtu(struct net_device *dev, int new_mtu) 620{ 621 if (new_mtu < MIN_MTU || new_mtu > MAX_MTU) --- 9 unchanged lines hidden (view full) --- 631 .ndo_validate_addr = eth_validate_addr, 632 .ndo_set_mac_address = eth_mac_addr, 633 .ndo_change_mtu = virtnet_change_mtu, 634#ifdef CONFIG_NET_POLL_CONTROLLER 635 .ndo_poll_controller = virtnet_netpoll, 636#endif 637}; 638 | 616}; 617 618#define MIN_MTU 68 619#define MAX_MTU 65535 620 621static int virtnet_change_mtu(struct net_device *dev, int new_mtu) 622{ 623 if (new_mtu < MIN_MTU || new_mtu > MAX_MTU) --- 9 unchanged lines hidden (view full) --- 633 .ndo_validate_addr = eth_validate_addr, 634 .ndo_set_mac_address = eth_mac_addr, 635 .ndo_change_mtu = virtnet_change_mtu, 636#ifdef CONFIG_NET_POLL_CONTROLLER 637 .ndo_poll_controller = virtnet_netpoll, 638#endif 639}; 640 |
641static void virtnet_update_status(struct virtnet_info *vi) 642{ 643 u16 v; 644 645 if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_STATUS)) 646 return; 647 648 vi->vdev->config->get(vi->vdev, 649 offsetof(struct virtio_net_config, status), 650 &v, sizeof(v)); 651 652 /* Ignore unknown (future) status bits */ 653 v &= VIRTIO_NET_S_LINK_UP; 654 655 if (vi->status == v) 656 return; 657 658 vi->status = v; 659 660 if (vi->status & VIRTIO_NET_S_LINK_UP) { 661 netif_carrier_on(vi->dev); 662 netif_wake_queue(vi->dev); 663 } else { 664 netif_carrier_off(vi->dev); 665 netif_stop_queue(vi->dev); 666 } 667} 668 669static void virtnet_config_changed(struct virtio_device *vdev) 670{ 671 struct virtnet_info *vi = vdev->priv; 672 673 virtnet_update_status(vi); 674} 675 |
|
639static int virtnet_probe(struct virtio_device *vdev) 640{ 641 int err; 642 struct net_device *dev; 643 struct virtnet_info *vi; 644 645 /* Allocate ourselves a network device with room for our info */ 646 dev = alloc_etherdev(sizeof(struct virtnet_info)); --- 86 unchanged lines hidden (view full) --- 733 try_fill_recv(vi); 734 735 /* If we didn't even get one input buffer, we're useless. */ 736 if (vi->num == 0) { 737 err = -ENOMEM; 738 goto unregister; 739 } 740 | 676static int virtnet_probe(struct virtio_device *vdev) 677{ 678 int err; 679 struct net_device *dev; 680 struct virtnet_info *vi; 681 682 /* Allocate ourselves a network device with room for our info */ 683 dev = alloc_etherdev(sizeof(struct virtnet_info)); --- 86 unchanged lines hidden (view full) --- 770 try_fill_recv(vi); 771 772 /* If we didn't even get one input buffer, we're useless. */ 773 if (vi->num == 0) { 774 err = -ENOMEM; 775 goto unregister; 776 } 777 |
778 vi->status = VIRTIO_NET_S_LINK_UP; 779 virtnet_update_status(vi); 780 |
|
741 pr_debug("virtnet: registered device %s\n", dev->name); 742 return 0; 743 744unregister: 745 unregister_netdev(dev); 746free_send: 747 vdev->config->del_vq(vi->svq); 748free_recv: --- 39 unchanged lines hidden (view full) --- 788}; 789 790static unsigned int features[] = { 791 VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GUEST_CSUM, 792 VIRTIO_NET_F_GSO, VIRTIO_NET_F_MAC, 793 VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6, 794 VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6, 795 VIRTIO_NET_F_GUEST_ECN, /* We don't yet handle UFO input. */ | 781 pr_debug("virtnet: registered device %s\n", dev->name); 782 return 0; 783 784unregister: 785 unregister_netdev(dev); 786free_send: 787 vdev->config->del_vq(vi->svq); 788free_recv: --- 39 unchanged lines hidden (view full) --- 828}; 829 830static unsigned int features[] = { 831 VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GUEST_CSUM, 832 VIRTIO_NET_F_GSO, VIRTIO_NET_F_MAC, 833 VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6, 834 VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6, 835 VIRTIO_NET_F_GUEST_ECN, /* We don't yet handle UFO input. */ |
796 VIRTIO_NET_F_MRG_RXBUF, | 836 VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, |
797 VIRTIO_F_NOTIFY_ON_EMPTY, 798}; 799 800static struct virtio_driver virtio_net = { 801 .feature_table = features, 802 .feature_table_size = ARRAY_SIZE(features), 803 .driver.name = KBUILD_MODNAME, 804 .driver.owner = THIS_MODULE, 805 .id_table = id_table, 806 .probe = virtnet_probe, 807 .remove = __devexit_p(virtnet_remove), | 837 VIRTIO_F_NOTIFY_ON_EMPTY, 838}; 839 840static struct virtio_driver virtio_net = { 841 .feature_table = features, 842 .feature_table_size = ARRAY_SIZE(features), 843 .driver.name = KBUILD_MODNAME, 844 .driver.owner = THIS_MODULE, 845 .id_table = id_table, 846 .probe = virtnet_probe, 847 .remove = __devexit_p(virtnet_remove), |
848 .config_changed = virtnet_config_changed, |
|
808}; 809 810static int __init init(void) 811{ 812 return register_virtio_driver(&virtio_net); 813} 814 815static void __exit fini(void) 816{ 817 unregister_virtio_driver(&virtio_net); 818} 819module_init(init); 820module_exit(fini); 821 822MODULE_DEVICE_TABLE(virtio, id_table); 823MODULE_DESCRIPTION("Virtio network driver"); 824MODULE_LICENSE("GPL"); | 849}; 850 851static int __init init(void) 852{ 853 return register_virtio_driver(&virtio_net); 854} 855 856static void __exit fini(void) 857{ 858 unregister_virtio_driver(&virtio_net); 859} 860module_init(init); 861module_exit(fini); 862 863MODULE_DEVICE_TABLE(virtio, id_table); 864MODULE_DESCRIPTION("Virtio network driver"); 865MODULE_LICENSE("GPL"); |