diff options
author | Amit Shah <amit.shah@redhat.com> | 2011-12-22 06:28:33 -0500 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2012-01-12 00:14:46 -0500 |
commit | 0741bcb5584f9e2390ae6261573c4de8314999f2 (patch) | |
tree | d52abfa39e08dbdda0bee35d85a72a8060391a16 /drivers/net/virtio_net.c | |
parent | 04486ed019d249249c00546704af12498a432c15 (diff) |
virtio: net: Add freeze, restore handlers to support S4
Remove all the vqs, disable napi and detach from the netdev on
hibernation.
Re-create vqs after restoring from a hibernated image, re-enable napi
and re-attach the netdev. This keeps networking working across
hibernation.
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 | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 59109c1b6b87..4880aa8b4c28 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c | |||
@@ -1178,6 +1178,48 @@ static void __devexit virtnet_remove(struct virtio_device *vdev) | |||
1178 | free_netdev(vi->dev); | 1178 | free_netdev(vi->dev); |
1179 | } | 1179 | } |
1180 | 1180 | ||
1181 | #ifdef CONFIG_PM | ||
1182 | static int virtnet_freeze(struct virtio_device *vdev) | ||
1183 | { | ||
1184 | struct virtnet_info *vi = vdev->priv; | ||
1185 | |||
1186 | virtqueue_disable_cb(vi->rvq); | ||
1187 | virtqueue_disable_cb(vi->svq); | ||
1188 | if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)) | ||
1189 | virtqueue_disable_cb(vi->cvq); | ||
1190 | |||
1191 | netif_device_detach(vi->dev); | ||
1192 | cancel_delayed_work_sync(&vi->refill); | ||
1193 | |||
1194 | if (netif_running(vi->dev)) | ||
1195 | napi_disable(&vi->napi); | ||
1196 | |||
1197 | remove_vq_common(vi); | ||
1198 | |||
1199 | return 0; | ||
1200 | } | ||
1201 | |||
1202 | static int virtnet_restore(struct virtio_device *vdev) | ||
1203 | { | ||
1204 | struct virtnet_info *vi = vdev->priv; | ||
1205 | int err; | ||
1206 | |||
1207 | err = init_vqs(vi); | ||
1208 | if (err) | ||
1209 | return err; | ||
1210 | |||
1211 | if (netif_running(vi->dev)) | ||
1212 | virtnet_napi_enable(vi); | ||
1213 | |||
1214 | netif_device_attach(vi->dev); | ||
1215 | |||
1216 | if (!try_fill_recv(vi, GFP_KERNEL)) | ||
1217 | queue_delayed_work(system_nrt_wq, &vi->refill, 0); | ||
1218 | |||
1219 | return 0; | ||
1220 | } | ||
1221 | #endif | ||
1222 | |||
1181 | static struct virtio_device_id id_table[] = { | 1223 | static struct virtio_device_id id_table[] = { |
1182 | { VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID }, | 1224 | { VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID }, |
1183 | { 0 }, | 1225 | { 0 }, |
@@ -1202,6 +1244,10 @@ static struct virtio_driver virtio_net_driver = { | |||
1202 | .probe = virtnet_probe, | 1244 | .probe = virtnet_probe, |
1203 | .remove = __devexit_p(virtnet_remove), | 1245 | .remove = __devexit_p(virtnet_remove), |
1204 | .config_changed = virtnet_config_changed, | 1246 | .config_changed = virtnet_config_changed, |
1247 | #ifdef CONFIG_PM | ||
1248 | .freeze = virtnet_freeze, | ||
1249 | .restore = virtnet_restore, | ||
1250 | #endif | ||
1205 | }; | 1251 | }; |
1206 | 1252 | ||
1207 | static int __init init(void) | 1253 | static int __init init(void) |