diff options
author | Amos Kong <akong@redhat.com> | 2013-01-20 20:17:21 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-01-21 14:07:43 -0500 |
commit | 40cbfc37075a2ae2ed6c769cb0e9193819511f0a (patch) | |
tree | 1bd8b4c42357c67b7d12d7bbedccaa4aeddd7664 /drivers/net/virtio_net.c | |
parent | 3fcd550a4b37b1c60b4afce2e4b200919ec8bd20 (diff) |
move virtnet_send_command() above virtnet_set_mac_address()
We want to send vq command to set mac address in
virtnet_set_mac_address(), so do this function moving.
Fixed a little issue of coding style.
Signed-off-by: Amos Kong <akong@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/virtio_net.c')
-rw-r--r-- | drivers/net/virtio_net.c | 89 |
1 files changed, 44 insertions, 45 deletions
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index a6fcf15adc4f..395ab4ff3e64 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c | |||
@@ -753,6 +753,50 @@ static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev) | |||
753 | return NETDEV_TX_OK; | 753 | return NETDEV_TX_OK; |
754 | } | 754 | } |
755 | 755 | ||
756 | /* | ||
757 | * Send command via the control virtqueue and check status. Commands | ||
758 | * supported by the hypervisor, as indicated by feature bits, should | ||
759 | * never fail unless improperly formated. | ||
760 | */ | ||
761 | static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd, | ||
762 | struct scatterlist *data, int out, int in) | ||
763 | { | ||
764 | struct scatterlist *s, sg[VIRTNET_SEND_COMMAND_SG_MAX + 2]; | ||
765 | struct virtio_net_ctrl_hdr ctrl; | ||
766 | virtio_net_ctrl_ack status = ~0; | ||
767 | unsigned int tmp; | ||
768 | int i; | ||
769 | |||
770 | /* Caller should know better */ | ||
771 | BUG_ON(!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ) || | ||
772 | (out + in > VIRTNET_SEND_COMMAND_SG_MAX)); | ||
773 | |||
774 | out++; /* Add header */ | ||
775 | in++; /* Add return status */ | ||
776 | |||
777 | ctrl.class = class; | ||
778 | ctrl.cmd = cmd; | ||
779 | |||
780 | sg_init_table(sg, out + in); | ||
781 | |||
782 | sg_set_buf(&sg[0], &ctrl, sizeof(ctrl)); | ||
783 | for_each_sg(data, s, out + in - 2, i) | ||
784 | sg_set_buf(&sg[i + 1], sg_virt(s), s->length); | ||
785 | sg_set_buf(&sg[out + in - 1], &status, sizeof(status)); | ||
786 | |||
787 | BUG_ON(virtqueue_add_buf(vi->cvq, sg, out, in, vi, GFP_ATOMIC) < 0); | ||
788 | |||
789 | virtqueue_kick(vi->cvq); | ||
790 | |||
791 | /* Spin for a response, the kick causes an ioport write, trapping | ||
792 | * into the hypervisor, so the request should be handled immediately. | ||
793 | */ | ||
794 | while (!virtqueue_get_buf(vi->cvq, &tmp)) | ||
795 | cpu_relax(); | ||
796 | |||
797 | return status == VIRTIO_NET_OK; | ||
798 | } | ||
799 | |||
756 | static int virtnet_set_mac_address(struct net_device *dev, void *p) | 800 | static int virtnet_set_mac_address(struct net_device *dev, void *p) |
757 | { | 801 | { |
758 | struct virtnet_info *vi = netdev_priv(dev); | 802 | struct virtnet_info *vi = netdev_priv(dev); |
@@ -819,51 +863,6 @@ static void virtnet_netpoll(struct net_device *dev) | |||
819 | } | 863 | } |
820 | #endif | 864 | #endif |
821 | 865 | ||
822 | /* | ||
823 | * Send command via the control virtqueue and check status. Commands | ||
824 | * supported by the hypervisor, as indicated by feature bits, should | ||
825 | * never fail unless improperly formated. | ||
826 | */ | ||
827 | static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd, | ||
828 | struct scatterlist *data, int out, int in) | ||
829 | { | ||
830 | struct scatterlist *s, sg[VIRTNET_SEND_COMMAND_SG_MAX + 2]; | ||
831 | struct virtio_net_ctrl_hdr ctrl; | ||
832 | virtio_net_ctrl_ack status = ~0; | ||
833 | unsigned int tmp; | ||
834 | int i; | ||
835 | |||
836 | /* Caller should know better */ | ||
837 | BUG_ON(!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ) || | ||
838 | (out + in > VIRTNET_SEND_COMMAND_SG_MAX)); | ||
839 | |||
840 | out++; /* Add header */ | ||
841 | in++; /* Add return status */ | ||
842 | |||
843 | ctrl.class = class; | ||
844 | ctrl.cmd = cmd; | ||
845 | |||
846 | sg_init_table(sg, out + in); | ||
847 | |||
848 | sg_set_buf(&sg[0], &ctrl, sizeof(ctrl)); | ||
849 | for_each_sg(data, s, out + in - 2, i) | ||
850 | sg_set_buf(&sg[i + 1], sg_virt(s), s->length); | ||
851 | sg_set_buf(&sg[out + in - 1], &status, sizeof(status)); | ||
852 | |||
853 | BUG_ON(virtqueue_add_buf(vi->cvq, sg, out, in, vi, GFP_ATOMIC) < 0); | ||
854 | |||
855 | virtqueue_kick(vi->cvq); | ||
856 | |||
857 | /* | ||
858 | * Spin for a response, the kick causes an ioport write, trapping | ||
859 | * into the hypervisor, so the request should be handled immediately. | ||
860 | */ | ||
861 | while (!virtqueue_get_buf(vi->cvq, &tmp)) | ||
862 | cpu_relax(); | ||
863 | |||
864 | return status == VIRTIO_NET_OK; | ||
865 | } | ||
866 | |||
867 | static void virtnet_ack_link_announce(struct virtnet_info *vi) | 866 | static void virtnet_ack_link_announce(struct virtnet_info *vi) |
868 | { | 867 | { |
869 | rtnl_lock(); | 868 | rtnl_lock(); |