Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
0002 /*
0003  * Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
0004  */
0005 
0006 #ifndef MLX5_VFIO_CMD_H
0007 #define MLX5_VFIO_CMD_H
0008 
0009 #include <linux/kernel.h>
0010 #include <linux/vfio_pci_core.h>
0011 #include <linux/mlx5/driver.h>
0012 
0013 struct mlx5vf_async_data {
0014     struct mlx5_async_work cb_work;
0015     struct work_struct work;
0016     int status;
0017     u32 pdn;
0018     u32 mkey;
0019     void *out;
0020 };
0021 
0022 struct mlx5_vf_migration_file {
0023     struct file *filp;
0024     struct mutex lock;
0025     u8 disabled:1;
0026     u8 is_err:1;
0027 
0028     struct sg_append_table table;
0029     size_t total_length;
0030     size_t allocated_length;
0031 
0032     /* Optimize mlx5vf_get_migration_page() for sequential access */
0033     struct scatterlist *last_offset_sg;
0034     unsigned int sg_last_entry;
0035     unsigned long last_offset;
0036     struct mlx5vf_pci_core_device *mvdev;
0037     wait_queue_head_t poll_wait;
0038     struct mlx5_async_ctx async_ctx;
0039     struct mlx5vf_async_data async_data;
0040 };
0041 
0042 struct mlx5vf_pci_core_device {
0043     struct vfio_pci_core_device core_device;
0044     int vf_id;
0045     u16 vhca_id;
0046     u8 migrate_cap:1;
0047     u8 deferred_reset:1;
0048     u8 mdev_detach:1;
0049     /* protect migration state */
0050     struct mutex state_mutex;
0051     enum vfio_device_mig_state mig_state;
0052     /* protect the reset_done flow */
0053     spinlock_t reset_lock;
0054     struct mlx5_vf_migration_file *resuming_migf;
0055     struct mlx5_vf_migration_file *saving_migf;
0056     struct workqueue_struct *cb_wq;
0057     struct notifier_block nb;
0058     struct mlx5_core_dev *mdev;
0059 };
0060 
0061 int mlx5vf_cmd_suspend_vhca(struct mlx5vf_pci_core_device *mvdev, u16 op_mod);
0062 int mlx5vf_cmd_resume_vhca(struct mlx5vf_pci_core_device *mvdev, u16 op_mod);
0063 int mlx5vf_cmd_query_vhca_migration_state(struct mlx5vf_pci_core_device *mvdev,
0064                       size_t *state_size);
0065 void mlx5vf_cmd_set_migratable(struct mlx5vf_pci_core_device *mvdev,
0066                    const struct vfio_migration_ops *mig_ops);
0067 void mlx5vf_cmd_remove_migratable(struct mlx5vf_pci_core_device *mvdev);
0068 void mlx5vf_cmd_close_migratable(struct mlx5vf_pci_core_device *mvdev);
0069 int mlx5vf_cmd_save_vhca_state(struct mlx5vf_pci_core_device *mvdev,
0070                    struct mlx5_vf_migration_file *migf);
0071 int mlx5vf_cmd_load_vhca_state(struct mlx5vf_pci_core_device *mvdev,
0072                    struct mlx5_vf_migration_file *migf);
0073 void mlx5vf_state_mutex_unlock(struct mlx5vf_pci_core_device *mvdev);
0074 void mlx5vf_disable_fds(struct mlx5vf_pci_core_device *mvdev);
0075 void mlx5vf_mig_file_cleanup_cb(struct work_struct *_work);
0076 #endif /* MLX5_VFIO_CMD_H */