From patchwork Wed Jan 4 03:00:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rusty Russell X-Patchwork-Id: 134188 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 397351007D8 for ; Wed, 4 Jan 2012 14:01:02 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755140Ab2ADDA4 (ORCPT ); Tue, 3 Jan 2012 22:00:56 -0500 Received: from ozlabs.org ([203.10.76.45]:37354 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754436Ab2ADDAy (ORCPT ); Tue, 3 Jan 2012 22:00:54 -0500 Received: by ozlabs.org (Postfix, from userid 1011) id 941521007D9; Wed, 4 Jan 2012 14:00:53 +1100 (EST) From: Rusty Russell To: netdev Cc: Virtualization List , "Michael S. Tsirkin" , Amit Shah Subject: [PATCH] (please ack, don't apply!) virtio: net: Add freeze, restore handlers to support S4 In-Reply-To: <87obukcgzi.fsf@rustcorp.com.au> References: <87obukcgzi.fsf@rustcorp.com.au> User-Agent: Notmuch/0.6.1-1 (http://notmuchmail.org) Emacs/23.3.1 (i686-pc-linux-gnu) Date: Wed, 04 Jan 2012 13:30:27 +1030 Message-ID: <87ipkscgtw.fsf@rustcorp.com.au> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org (This needs PM changes to virtio_pci which are in my tree, so best done via that rather than net-next. Thanks!) From: Amit Shah 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 Signed-off-by: Rusty Russell --- drivers/net/virtio_net.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -1159,6 +1159,48 @@ static void __devexit virtnet_remove(str free_netdev(vi->dev); } +#ifdef CONFIG_PM +static int virtnet_freeze(struct virtio_device *vdev) +{ + struct virtnet_info *vi = vdev->priv; + + virtqueue_disable_cb(vi->rvq); + virtqueue_disable_cb(vi->svq); + if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)) + virtqueue_disable_cb(vi->cvq); + + netif_device_detach(vi->dev); + cancel_delayed_work_sync(&vi->refill); + + if (netif_running(vi->dev)) + napi_disable(&vi->napi); + + remove_vq_common(vi); + + return 0; +} + +static int virtnet_restore(struct virtio_device *vdev) +{ + struct virtnet_info *vi = vdev->priv; + int err; + + err = init_vqs(vi); + if (err) + return err; + + if (netif_running(vi->dev)) + virtnet_napi_enable(vi); + + netif_device_attach(vi->dev); + + if (!try_fill_recv(vi, GFP_KERNEL)) + queue_delayed_work(system_nrt_wq, &vi->refill, 0); + + return 0; +} +#endif + static struct virtio_device_id id_table[] = { { VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID }, { 0 }, @@ -1183,6 +1225,10 @@ static struct virtio_driver virtio_net_d .probe = virtnet_probe, .remove = __devexit_p(virtnet_remove), .config_changed = virtnet_config_changed, +#ifdef CONFIG_PM + .freeze = virtnet_freeze, + .restore = virtnet_restore, +#endif }; static int __init init(void)