Merge tag 'net-next-5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev...
[linux-2.6-microblaze.git] / drivers / net / ethernet / mellanox / mlx5 / core / main.c
index bba72b2..2589e39 100644 (file)
@@ -736,10 +736,9 @@ static int mlx5_core_set_issi(struct mlx5_core_dev *dev)
        MLX5_SET(query_issi_in, query_in, opcode, MLX5_CMD_OP_QUERY_ISSI);
        err = mlx5_cmd_exec_inout(dev, query_issi, query_in, query_out);
        if (err) {
-               u32 syndrome;
-               u8 status;
+               u32 syndrome = MLX5_GET(query_issi_out, query_out, syndrome);
+               u8 status = MLX5_GET(query_issi_out, query_out, status);
 
-               mlx5_cmd_mbox_status(query_out, &status, &syndrome);
                if (!status || syndrome == MLX5_DRIVER_SYND) {
                        mlx5_core_err(dev, "Failed to query ISSI err(%d) status(%d) synd(%d)\n",
                                      err, status, syndrome);
@@ -1488,8 +1487,8 @@ int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx)
        INIT_LIST_HEAD(&priv->pgdir_list);
 
        priv->numa_node = dev_to_node(mlx5_core_dma_dev(dev));
-       priv->dbg_root = debugfs_create_dir(dev_name(dev->device),
-                                           mlx5_debugfs_root);
+       priv->dbg.dbg_root = debugfs_create_dir(dev_name(dev->device),
+                                               mlx5_debugfs_root);
        INIT_LIST_HEAD(&priv->traps);
 
        err = mlx5_tout_init(dev);
@@ -1525,7 +1524,7 @@ err_pagealloc_init:
 err_health_init:
        mlx5_tout_cleanup(dev);
 err_timeout_init:
-       debugfs_remove(dev->priv.dbg_root);
+       debugfs_remove(dev->priv.dbg.dbg_root);
        mutex_destroy(&priv->pgdir_mutex);
        mutex_destroy(&priv->alloc_mutex);
        mutex_destroy(&priv->bfregs.wc_head.lock);
@@ -1543,7 +1542,7 @@ void mlx5_mdev_uninit(struct mlx5_core_dev *dev)
        mlx5_pagealloc_cleanup(dev);
        mlx5_health_cleanup(dev);
        mlx5_tout_cleanup(dev);
-       debugfs_remove_recursive(dev->priv.dbg_root);
+       debugfs_remove_recursive(dev->priv.dbg.dbg_root);
        mutex_destroy(&priv->pgdir_mutex);
        mutex_destroy(&priv->alloc_mutex);
        mutex_destroy(&priv->bfregs.wc_head.lock);
@@ -1620,6 +1619,7 @@ static void remove_one(struct pci_dev *pdev)
        struct devlink *devlink = priv_to_devlink(dev);
 
        devlink_unregister(devlink);
+       mlx5_sriov_disable(pdev);
        mlx5_crdump_disable(dev);
        mlx5_drain_health_wq(dev);
        mlx5_uninit_one(dev);
@@ -1882,6 +1882,50 @@ static struct pci_driver mlx5_core_driver = {
        .sriov_set_msix_vec_count = mlx5_core_sriov_set_msix_vec_count,
 };
 
+/**
+ * mlx5_vf_get_core_dev - Get the mlx5 core device from a given VF PCI device if
+ *                     mlx5_core is its driver.
+ * @pdev: The associated PCI device.
+ *
+ * Upon return the interface state lock stay held to let caller uses it safely.
+ * Caller must ensure to use the returned mlx5 device for a narrow window
+ * and put it back with mlx5_vf_put_core_dev() immediately once usage was over.
+ *
+ * Return: Pointer to the associated mlx5_core_dev or NULL.
+ */
+struct mlx5_core_dev *mlx5_vf_get_core_dev(struct pci_dev *pdev)
+                       __acquires(&mdev->intf_state_mutex)
+{
+       struct mlx5_core_dev *mdev;
+
+       mdev = pci_iov_get_pf_drvdata(pdev, &mlx5_core_driver);
+       if (IS_ERR(mdev))
+               return NULL;
+
+       mutex_lock(&mdev->intf_state_mutex);
+       if (!test_bit(MLX5_INTERFACE_STATE_UP, &mdev->intf_state)) {
+               mutex_unlock(&mdev->intf_state_mutex);
+               return NULL;
+       }
+
+       return mdev;
+}
+EXPORT_SYMBOL(mlx5_vf_get_core_dev);
+
+/**
+ * mlx5_vf_put_core_dev - Put the mlx5 core device back.
+ * @mdev: The mlx5 core device.
+ *
+ * Upon return the interface state lock is unlocked and caller should not
+ * access the mdev any more.
+ */
+void mlx5_vf_put_core_dev(struct mlx5_core_dev *mdev)
+                       __releases(&mdev->intf_state_mutex)
+{
+       mutex_unlock(&mdev->intf_state_mutex);
+}
+EXPORT_SYMBOL(mlx5_vf_put_core_dev);
+
 static void mlx5_core_verify_params(void)
 {
        if (prof_sel >= ARRAY_SIZE(profile)) {