xref: /openbmc/linux/drivers/vfio/pci/mlx5/cmd.h (revision dff03381)
1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /*
3  * Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4  */
5 
6 #ifndef MLX5_VFIO_CMD_H
7 #define MLX5_VFIO_CMD_H
8 
9 #include <linux/kernel.h>
10 #include <linux/vfio_pci_core.h>
11 #include <linux/mlx5/driver.h>
12 
13 struct mlx5vf_async_data {
14 	struct mlx5_async_work cb_work;
15 	struct work_struct work;
16 	int status;
17 	u32 pdn;
18 	u32 mkey;
19 	void *out;
20 };
21 
22 struct mlx5_vf_migration_file {
23 	struct file *filp;
24 	struct mutex lock;
25 	u8 disabled:1;
26 	u8 is_err:1;
27 
28 	struct sg_append_table table;
29 	size_t total_length;
30 	size_t allocated_length;
31 
32 	/* Optimize mlx5vf_get_migration_page() for sequential access */
33 	struct scatterlist *last_offset_sg;
34 	unsigned int sg_last_entry;
35 	unsigned long last_offset;
36 	struct mlx5vf_pci_core_device *mvdev;
37 	wait_queue_head_t poll_wait;
38 	struct mlx5_async_ctx async_ctx;
39 	struct mlx5vf_async_data async_data;
40 };
41 
42 struct mlx5vf_pci_core_device {
43 	struct vfio_pci_core_device core_device;
44 	int vf_id;
45 	u16 vhca_id;
46 	u8 migrate_cap:1;
47 	u8 deferred_reset:1;
48 	u8 mdev_detach:1;
49 	/* protect migration state */
50 	struct mutex state_mutex;
51 	enum vfio_device_mig_state mig_state;
52 	/* protect the reset_done flow */
53 	spinlock_t reset_lock;
54 	struct mlx5_vf_migration_file *resuming_migf;
55 	struct mlx5_vf_migration_file *saving_migf;
56 	struct workqueue_struct *cb_wq;
57 	struct notifier_block nb;
58 	struct mlx5_core_dev *mdev;
59 };
60 
61 int mlx5vf_cmd_suspend_vhca(struct mlx5vf_pci_core_device *mvdev, u16 op_mod);
62 int mlx5vf_cmd_resume_vhca(struct mlx5vf_pci_core_device *mvdev, u16 op_mod);
63 int mlx5vf_cmd_query_vhca_migration_state(struct mlx5vf_pci_core_device *mvdev,
64 					  size_t *state_size);
65 void mlx5vf_cmd_set_migratable(struct mlx5vf_pci_core_device *mvdev,
66 			       const struct vfio_migration_ops *mig_ops);
67 void mlx5vf_cmd_remove_migratable(struct mlx5vf_pci_core_device *mvdev);
68 void mlx5vf_cmd_close_migratable(struct mlx5vf_pci_core_device *mvdev);
69 int mlx5vf_cmd_save_vhca_state(struct mlx5vf_pci_core_device *mvdev,
70 			       struct mlx5_vf_migration_file *migf);
71 int mlx5vf_cmd_load_vhca_state(struct mlx5vf_pci_core_device *mvdev,
72 			       struct mlx5_vf_migration_file *migf);
73 void mlx5vf_state_mutex_unlock(struct mlx5vf_pci_core_device *mvdev);
74 void mlx5vf_disable_fds(struct mlx5vf_pci_core_device *mvdev);
75 void mlx5vf_mig_file_cleanup_cb(struct work_struct *_work);
76 #endif /* MLX5_VFIO_CMD_H */
77