diff options
author | Amit Shah <amit.shah@redhat.com> | 2011-12-22 06:28:31 -0500 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2012-01-12 00:14:46 -0500 |
commit | 3f9c10b0d478a3b7c3dde555edae79fecef496e5 (patch) | |
tree | c83b10130dddce52bb8c71ea4b9e4acb82ee5bd0 /drivers/net/virtio_net.c | |
parent | f8fb5bc23a50a5398aa31a4e8c6dbbef53d2dec6 (diff) |
virtio: net: Move vq initialization into separate function
The probe and PM restore functions will share this code.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/net/virtio_net.c')
-rw-r--r-- | drivers/net/virtio_net.c | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 6345a52194f9..70a9c4b1252d 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c | |||
@@ -985,15 +985,38 @@ static void virtnet_config_changed(struct virtio_device *vdev) | |||
985 | virtnet_update_status(vi); | 985 | virtnet_update_status(vi); |
986 | } | 986 | } |
987 | 987 | ||
988 | static int init_vqs(struct virtnet_info *vi) | ||
989 | { | ||
990 | struct virtqueue *vqs[3]; | ||
991 | vq_callback_t *callbacks[] = { skb_recv_done, skb_xmit_done, NULL}; | ||
992 | const char *names[] = { "input", "output", "control" }; | ||
993 | int nvqs, err; | ||
994 | |||
995 | /* We expect two virtqueues, receive then send, | ||
996 | * and optionally control. */ | ||
997 | nvqs = virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ) ? 3 : 2; | ||
998 | |||
999 | err = vi->vdev->config->find_vqs(vi->vdev, nvqs, vqs, callbacks, names); | ||
1000 | if (err) | ||
1001 | return err; | ||
1002 | |||
1003 | vi->rvq = vqs[0]; | ||
1004 | vi->svq = vqs[1]; | ||
1005 | |||
1006 | if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)) { | ||
1007 | vi->cvq = vqs[2]; | ||
1008 | |||
1009 | if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VLAN)) | ||
1010 | vi->dev->features |= NETIF_F_HW_VLAN_FILTER; | ||
1011 | } | ||
1012 | return 0; | ||
1013 | } | ||
1014 | |||
988 | static int virtnet_probe(struct virtio_device *vdev) | 1015 | static int virtnet_probe(struct virtio_device *vdev) |
989 | { | 1016 | { |
990 | int err; | 1017 | int err; |
991 | struct net_device *dev; | 1018 | struct net_device *dev; |
992 | struct virtnet_info *vi; | 1019 | struct virtnet_info *vi; |
993 | struct virtqueue *vqs[3]; | ||
994 | vq_callback_t *callbacks[] = { skb_recv_done, skb_xmit_done, NULL}; | ||
995 | const char *names[] = { "input", "output", "control" }; | ||
996 | int nvqs; | ||
997 | 1020 | ||
998 | /* Allocate ourselves a network device with room for our info */ | 1021 | /* Allocate ourselves a network device with room for our info */ |
999 | dev = alloc_etherdev(sizeof(struct virtnet_info)); | 1022 | dev = alloc_etherdev(sizeof(struct virtnet_info)); |
@@ -1065,24 +1088,10 @@ static int virtnet_probe(struct virtio_device *vdev) | |||
1065 | if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF)) | 1088 | if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF)) |
1066 | vi->mergeable_rx_bufs = true; | 1089 | vi->mergeable_rx_bufs = true; |
1067 | 1090 | ||
1068 | /* We expect two virtqueues, receive then send, | 1091 | err = init_vqs(vi); |
1069 | * and optionally control. */ | ||
1070 | nvqs = virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ) ? 3 : 2; | ||
1071 | |||
1072 | err = vdev->config->find_vqs(vdev, nvqs, vqs, callbacks, names); | ||
1073 | if (err) | 1092 | if (err) |
1074 | goto free_stats; | 1093 | goto free_stats; |
1075 | 1094 | ||
1076 | vi->rvq = vqs[0]; | ||
1077 | vi->svq = vqs[1]; | ||
1078 | |||
1079 | if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)) { | ||
1080 | vi->cvq = vqs[2]; | ||
1081 | |||
1082 | if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VLAN)) | ||
1083 | dev->features |= NETIF_F_HW_VLAN_FILTER; | ||
1084 | } | ||
1085 | |||
1086 | err = register_netdev(dev); | 1095 | err = register_netdev(dev); |
1087 | if (err) { | 1096 | if (err) { |
1088 | pr_debug("virtio_net: registering device failed\n"); | 1097 | pr_debug("virtio_net: registering device failed\n"); |