net/mlx4_core: Add PCI calls for suspend/resume
authorYishai Hadas <yishaih@mellanox.com>
Wed, 9 May 2018 15:29:03 +0000 (18:29 +0300)
committerDavid S. Miller <davem@davemloft.net>
Thu, 10 May 2018 20:08:25 +0000 (16:08 -0400)
Implement suspend/resume callbacks in struct pci_driver.

Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Tariq Toukan <tariqt@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlx4/main.c

index 211578ffc70d2ba12105e6f20d9ab7ecf7efd0ac..b6aaf34d6648b5cb9548c7601d31227abce6375b 100644 (file)
@@ -4125,12 +4125,58 @@ static const struct pci_error_handlers mlx4_err_handler = {
        .resume         = mlx4_pci_resume,
 };
 
+static int mlx4_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+       struct mlx4_dev_persistent *persist = pci_get_drvdata(pdev);
+       struct mlx4_dev *dev = persist->dev;
+
+       mlx4_err(dev, "suspend was called\n");
+       mutex_lock(&persist->interface_state_mutex);
+       if (persist->interface_state & MLX4_INTERFACE_STATE_UP)
+               mlx4_unload_one(pdev);
+       mutex_unlock(&persist->interface_state_mutex);
+
+       return 0;
+}
+
+static int mlx4_resume(struct pci_dev *pdev)
+{
+       struct mlx4_dev_persistent *persist = pci_get_drvdata(pdev);
+       struct mlx4_dev *dev = persist->dev;
+       struct mlx4_priv *priv = mlx4_priv(dev);
+       int nvfs[MLX4_MAX_PORTS + 1] = {0, 0, 0};
+       int total_vfs;
+       int ret = 0;
+
+       mlx4_err(dev, "resume was called\n");
+       total_vfs = dev->persist->num_vfs;
+       memcpy(nvfs, dev->persist->nvfs, sizeof(dev->persist->nvfs));
+
+       mutex_lock(&persist->interface_state_mutex);
+       if (!(persist->interface_state & MLX4_INTERFACE_STATE_UP)) {
+               ret = mlx4_load_one(pdev, priv->pci_dev_data, total_vfs,
+                                   nvfs, priv, 1);
+               if (!ret) {
+                       ret = restore_current_port_types(dev,
+                                       dev->persist->curr_port_type,
+                                       dev->persist->curr_port_poss_type);
+                       if (ret)
+                               mlx4_err(dev, "resume: could not restore original port types (%d)\n", ret);
+               }
+       }
+       mutex_unlock(&persist->interface_state_mutex);
+
+       return ret;
+}
+
 static struct pci_driver mlx4_driver = {
        .name           = DRV_NAME,
        .id_table       = mlx4_pci_table,
        .probe          = mlx4_init_one,
        .shutdown       = mlx4_shutdown,
        .remove         = mlx4_remove_one,
+       .suspend        = mlx4_suspend,
+       .resume         = mlx4_resume,
        .err_handler    = &mlx4_err_handler,
 };