Merge tag 'hyperv-next-signed' of git://git.kernel.org/pub/scm/linux/kernel/git/hyper...
[linux-2.6-microblaze.git] / drivers / net / hyperv / netvsc_drv.c
index 868e22e..eff8fef 100644 (file)
@@ -2424,6 +2424,61 @@ static int netvsc_remove(struct hv_device *dev)
        return 0;
 }
 
+static int netvsc_suspend(struct hv_device *dev)
+{
+       struct net_device_context *ndev_ctx;
+       struct net_device *vf_netdev, *net;
+       struct netvsc_device *nvdev;
+       int ret;
+
+       net = hv_get_drvdata(dev);
+
+       ndev_ctx = netdev_priv(net);
+       cancel_delayed_work_sync(&ndev_ctx->dwork);
+
+       rtnl_lock();
+
+       nvdev = rtnl_dereference(ndev_ctx->nvdev);
+       if (nvdev == NULL) {
+               ret = -ENODEV;
+               goto out;
+       }
+
+       vf_netdev = rtnl_dereference(ndev_ctx->vf_netdev);
+       if (vf_netdev)
+               netvsc_unregister_vf(vf_netdev);
+
+       /* Save the current config info */
+       ndev_ctx->saved_netvsc_dev_info = netvsc_devinfo_get(nvdev);
+
+       ret = netvsc_detach(net, nvdev);
+out:
+       rtnl_unlock();
+
+       return ret;
+}
+
+static int netvsc_resume(struct hv_device *dev)
+{
+       struct net_device *net = hv_get_drvdata(dev);
+       struct net_device_context *net_device_ctx;
+       struct netvsc_device_info *device_info;
+       int ret;
+
+       rtnl_lock();
+
+       net_device_ctx = netdev_priv(net);
+       device_info = net_device_ctx->saved_netvsc_dev_info;
+
+       ret = netvsc_attach(net, device_info);
+
+       rtnl_unlock();
+
+       kfree(device_info);
+       net_device_ctx->saved_netvsc_dev_info = NULL;
+
+       return ret;
+}
 static const struct hv_vmbus_device_id id_table[] = {
        /* Network guid */
        { HV_NIC_GUID, },
@@ -2438,6 +2493,8 @@ static struct  hv_driver netvsc_drv = {
        .id_table = id_table,
        .probe = netvsc_probe,
        .remove = netvsc_remove,
+       .suspend = netvsc_suspend,
+       .resume = netvsc_resume,
        .driver = {
                .probe_type = PROBE_FORCE_SYNCHRONOUS,
        },