Lines Matching refs:migf
37 static void mlx5vf_disable_fd(struct mlx5_vf_migration_file *migf) in mlx5vf_disable_fd() argument
39 mutex_lock(&migf->lock); in mlx5vf_disable_fd()
40 migf->state = MLX5_MIGF_STATE_ERROR; in mlx5vf_disable_fd()
41 migf->filp->f_pos = 0; in mlx5vf_disable_fd()
42 mutex_unlock(&migf->lock); in mlx5vf_disable_fd()
47 struct mlx5_vf_migration_file *migf = filp->private_data; in mlx5vf_release_file() local
49 mlx5vf_disable_fd(migf); in mlx5vf_release_file()
50 mutex_destroy(&migf->lock); in mlx5vf_release_file()
51 kfree(migf); in mlx5vf_release_file()
56 mlx5vf_get_data_buff_from_pos(struct mlx5_vf_migration_file *migf, loff_t pos, in mlx5vf_get_data_buff_from_pos() argument
63 spin_lock_irq(&migf->list_lock); in mlx5vf_get_data_buff_from_pos()
64 if (list_empty(&migf->buf_list)) { in mlx5vf_get_data_buff_from_pos()
69 buf = list_first_entry(&migf->buf_list, struct mlx5_vhca_data_buffer, in mlx5vf_get_data_buff_from_pos()
81 migf->state = MLX5_MIGF_STATE_ERROR; in mlx5vf_get_data_buff_from_pos()
84 spin_unlock_irq(&migf->list_lock); in mlx5vf_get_data_buff_from_pos()
90 struct mlx5_vf_migration_file *migf = vhca_buf->migf; in mlx5vf_buf_read_done() local
98 migf->buf_header[chunk_num - 1] = vhca_buf; in mlx5vf_buf_read_done()
100 migf->buf[chunk_num - 1] = vhca_buf; in mlx5vf_buf_read_done()
102 spin_lock_irq(&migf->list_lock); in mlx5vf_buf_read_done()
106 migf->next_required_umem_size; in mlx5vf_buf_read_done()
107 migf->next_required_umem_size = 0; in mlx5vf_buf_read_done()
108 migf->num_ready_chunks--; in mlx5vf_buf_read_done()
110 spin_unlock_irq(&migf->list_lock); in mlx5vf_buf_read_done()
112 mlx5vf_mig_file_set_save_work(migf, chunk_num, in mlx5vf_buf_read_done()
117 spin_lock_irq(&migf->list_lock); in mlx5vf_buf_read_done()
119 list_add_tail(&vhca_buf->buf_elm, &vhca_buf->migf->avail_list); in mlx5vf_buf_read_done()
120 spin_unlock_irq(&migf->list_lock); in mlx5vf_buf_read_done()
167 struct mlx5_vf_migration_file *migf = filp->private_data; in mlx5vf_save_read() local
178 if (wait_event_interruptible(migf->poll_wait, in mlx5vf_save_read()
179 !list_empty(&migf->buf_list) || in mlx5vf_save_read()
180 migf->state == MLX5_MIGF_STATE_ERROR || in mlx5vf_save_read()
181 migf->state == MLX5_MIGF_STATE_PRE_COPY_ERROR || in mlx5vf_save_read()
182 migf->state == MLX5_MIGF_STATE_PRE_COPY || in mlx5vf_save_read()
183 migf->state == MLX5_MIGF_STATE_COMPLETE)) in mlx5vf_save_read()
187 mutex_lock(&migf->lock); in mlx5vf_save_read()
188 if (migf->state == MLX5_MIGF_STATE_ERROR) { in mlx5vf_save_read()
196 vhca_buf = mlx5vf_get_data_buff_from_pos(migf, *pos, in mlx5vf_save_read()
201 if (end_of_data && (migf->state == MLX5_MIGF_STATE_PRE_COPY || in mlx5vf_save_read()
202 migf->state == MLX5_MIGF_STATE_PRE_COPY_ERROR)) { in mlx5vf_save_read()
207 if (end_of_data && migf->state != MLX5_MIGF_STATE_COMPLETE) { in mlx5vf_save_read()
232 mutex_unlock(&migf->lock); in mlx5vf_save_read()
239 struct mlx5_vf_migration_file *migf = filp->private_data; in mlx5vf_save_poll() local
242 poll_wait(filp, &migf->poll_wait, wait); in mlx5vf_save_poll()
244 mutex_lock(&migf->lock); in mlx5vf_save_poll()
245 if (migf->state == MLX5_MIGF_STATE_ERROR) in mlx5vf_save_poll()
247 else if (!list_empty(&migf->buf_list) || in mlx5vf_save_poll()
248 migf->state == MLX5_MIGF_STATE_COMPLETE) in mlx5vf_save_poll()
250 mutex_unlock(&migf->lock); in mlx5vf_save_poll()
259 static void mlx5vf_mark_err(struct mlx5_vf_migration_file *migf) in mlx5vf_mark_err() argument
261 migf->state = MLX5_MIGF_STATE_ERROR; in mlx5vf_mark_err()
262 wake_up_interruptible(&migf->poll_wait); in mlx5vf_mark_err()
265 void mlx5vf_mig_file_set_save_work(struct mlx5_vf_migration_file *migf, in mlx5vf_mig_file_set_save_work() argument
268 migf->save_data[chunk_num - 1].next_required_umem_size = in mlx5vf_mig_file_set_save_work()
270 migf->save_data[chunk_num - 1].migf = migf; in mlx5vf_mig_file_set_save_work()
271 get_file(migf->filp); in mlx5vf_mig_file_set_save_work()
272 queue_work(migf->mvdev->cb_wq, in mlx5vf_mig_file_set_save_work()
273 &migf->save_data[chunk_num - 1].work); in mlx5vf_mig_file_set_save_work()
277 mlx5vf_mig_file_get_stop_copy_buf(struct mlx5_vf_migration_file *migf, in mlx5vf_mig_file_get_stop_copy_buf() argument
281 struct mlx5_vhca_data_buffer *buf = migf->buf[index]; in mlx5vf_mig_file_get_stop_copy_buf()
286 buf->migf->buf[index] = NULL; in mlx5vf_mig_file_get_stop_copy_buf()
292 buf = mlx5vf_get_data_buffer(buf->migf, npages, DMA_FROM_DEVICE); in mlx5vf_mig_file_get_stop_copy_buf()
304 struct mlx5_vf_migration_file *migf = save_data->migf; in mlx5vf_mig_file_save_work() local
305 struct mlx5vf_pci_core_device *mvdev = migf->mvdev; in mlx5vf_mig_file_save_work()
309 if (migf->state == MLX5_MIGF_STATE_ERROR) in mlx5vf_mig_file_save_work()
312 buf = mlx5vf_mig_file_get_stop_copy_buf(migf, in mlx5vf_mig_file_save_work()
318 if (mlx5vf_cmd_save_vhca_state(mvdev, migf, buf, true, false)) in mlx5vf_mig_file_save_work()
326 mlx5vf_mark_err(migf); in mlx5vf_mig_file_save_work()
329 fput(migf->filp); in mlx5vf_mig_file_save_work()
332 static int mlx5vf_add_stop_copy_header(struct mlx5_vf_migration_file *migf, in mlx5vf_add_stop_copy_header() argument
345 header_buf = mlx5vf_get_data_buffer(migf, DIV_ROUND_UP(size, PAGE_SIZE), in mlx5vf_add_stop_copy_header()
361 data.stop_copy_size = cpu_to_le64(migf->buf[0]->npages * PAGE_SIZE); in mlx5vf_add_stop_copy_header()
365 header_buf->start_pos = header_buf->migf->max_pos; in mlx5vf_add_stop_copy_header()
366 migf->max_pos += header_buf->length; in mlx5vf_add_stop_copy_header()
367 spin_lock_irqsave(&migf->list_lock, flags); in mlx5vf_add_stop_copy_header()
368 list_add_tail(&header_buf->buf_elm, &migf->buf_list); in mlx5vf_add_stop_copy_header()
369 spin_unlock_irqrestore(&migf->list_lock, flags); in mlx5vf_add_stop_copy_header()
371 migf->pre_copy_initial_bytes = size; in mlx5vf_add_stop_copy_header()
379 struct mlx5_vf_migration_file *migf, in mlx5vf_prep_stop_copy() argument
411 migf, DIV_ROUND_UP(inc_state_size, PAGE_SIZE), in mlx5vf_prep_stop_copy()
418 migf->buf[i] = buf; in mlx5vf_prep_stop_copy()
420 migf, in mlx5vf_prep_stop_copy()
428 migf->buf_header[i] = buf; in mlx5vf_prep_stop_copy()
430 migf->buf[i]->stop_copy_chunk_num = i + 1; in mlx5vf_prep_stop_copy()
431 migf->buf_header[i]->stop_copy_chunk_num = i + 1; in mlx5vf_prep_stop_copy()
432 INIT_WORK(&migf->save_data[i].work, in mlx5vf_prep_stop_copy()
434 migf->save_data[i].chunk_num = i + 1; in mlx5vf_prep_stop_copy()
438 ret = mlx5vf_add_stop_copy_header(migf, track); in mlx5vf_prep_stop_copy()
445 if (migf->buf[i]) { in mlx5vf_prep_stop_copy()
446 mlx5vf_put_data_buffer(migf->buf[i]); in mlx5vf_prep_stop_copy()
447 migf->buf[i] = NULL; in mlx5vf_prep_stop_copy()
449 if (migf->buf_header[i]) { in mlx5vf_prep_stop_copy()
450 mlx5vf_put_data_buffer(migf->buf_header[i]); in mlx5vf_prep_stop_copy()
451 migf->buf_header[i] = NULL; in mlx5vf_prep_stop_copy()
461 struct mlx5_vf_migration_file *migf = filp->private_data; in mlx5vf_precopy_ioctl() local
462 struct mlx5vf_pci_core_device *mvdev = migf->mvdev; in mlx5vf_precopy_ioctl()
506 mutex_lock(&migf->lock); in mlx5vf_precopy_ioctl()
507 if (migf->state == MLX5_MIGF_STATE_ERROR) { in mlx5vf_precopy_ioctl()
512 if (migf->pre_copy_initial_bytes > *pos) { in mlx5vf_precopy_ioctl()
513 info.initial_bytes = migf->pre_copy_initial_bytes - *pos; in mlx5vf_precopy_ioctl()
515 info.dirty_bytes = migf->max_pos - *pos; in mlx5vf_precopy_ioctl()
522 mutex_unlock(&migf->lock); in mlx5vf_precopy_ioctl()
526 mutex_unlock(&migf->lock); in mlx5vf_precopy_ioctl()
531 buf = mlx5vf_get_data_buffer(migf, DIV_ROUND_UP(inc_length, PAGE_SIZE), in mlx5vf_precopy_ioctl()
535 mlx5vf_mark_err(migf); in mlx5vf_precopy_ioctl()
539 ret = mlx5vf_cmd_save_vhca_state(mvdev, migf, buf, true, true); in mlx5vf_precopy_ioctl()
541 mlx5vf_mark_err(migf); in mlx5vf_precopy_ioctl()
553 mutex_unlock(&migf->lock); in mlx5vf_precopy_ioctl()
570 struct mlx5_vf_migration_file *migf = mvdev->saving_migf; in mlx5vf_pci_save_device_inc_data() local
575 if (migf->state == MLX5_MIGF_STATE_ERROR) in mlx5vf_pci_save_device_inc_data()
583 buf = mlx5vf_mig_file_get_stop_copy_buf(migf, 0, length); in mlx5vf_pci_save_device_inc_data()
589 ret = mlx5vf_cmd_save_vhca_state(mvdev, migf, buf, true, false); in mlx5vf_pci_save_device_inc_data()
598 mlx5vf_mark_err(migf); in mlx5vf_pci_save_device_inc_data()
605 struct mlx5_vf_migration_file *migf; in mlx5vf_pci_save_device_data() local
611 migf = kzalloc(sizeof(*migf), GFP_KERNEL_ACCOUNT); in mlx5vf_pci_save_device_data()
612 if (!migf) in mlx5vf_pci_save_device_data()
615 migf->filp = anon_inode_getfile("mlx5vf_mig", &mlx5vf_save_fops, migf, in mlx5vf_pci_save_device_data()
617 if (IS_ERR(migf->filp)) { in mlx5vf_pci_save_device_data()
618 ret = PTR_ERR(migf->filp); in mlx5vf_pci_save_device_data()
619 kfree(migf); in mlx5vf_pci_save_device_data()
623 migf->mvdev = mvdev; in mlx5vf_pci_save_device_data()
624 stream_open(migf->filp->f_inode, migf->filp); in mlx5vf_pci_save_device_data()
625 mutex_init(&migf->lock); in mlx5vf_pci_save_device_data()
626 init_waitqueue_head(&migf->poll_wait); in mlx5vf_pci_save_device_data()
627 init_completion(&migf->save_comp); in mlx5vf_pci_save_device_data()
633 complete(&migf->save_comp); in mlx5vf_pci_save_device_data()
634 mlx5_cmd_init_async_ctx(mvdev->mdev, &migf->async_ctx); in mlx5vf_pci_save_device_data()
635 INIT_WORK(&migf->async_data.work, mlx5vf_mig_file_cleanup_cb); in mlx5vf_pci_save_device_data()
636 INIT_LIST_HEAD(&migf->buf_list); in mlx5vf_pci_save_device_data()
637 INIT_LIST_HEAD(&migf->avail_list); in mlx5vf_pci_save_device_data()
638 spin_lock_init(&migf->list_lock); in mlx5vf_pci_save_device_data()
640 ret = mlx5vf_cmd_alloc_pd(migf); in mlx5vf_pci_save_device_data()
648 ret = mlx5vf_prep_stop_copy(mvdev, migf, length, full_size, track); in mlx5vf_pci_save_device_data()
654 buf = mlx5vf_alloc_data_buffer(migf, migf->buf[0]->npages, in mlx5vf_pci_save_device_data()
661 buf = migf->buf[0]; in mlx5vf_pci_save_device_data()
662 migf->buf[0] = NULL; in mlx5vf_pci_save_device_data()
665 ret = mlx5vf_cmd_save_vhca_state(mvdev, migf, buf, false, track); in mlx5vf_pci_save_device_data()
668 return migf; in mlx5vf_pci_save_device_data()
672 mlx5fv_cmd_clean_migf_resources(migf); in mlx5vf_pci_save_device_data()
674 fput(migf->filp); in mlx5vf_pci_save_device_data()
712 mlx5vf_resume_read_image(struct mlx5_vf_migration_file *migf, in mlx5vf_resume_read_image() argument
732 migf->load_state = MLX5_VF_LOAD_STATE_LOAD_IMAGE; in mlx5vf_resume_read_image()
733 migf->max_pos += image_size; in mlx5vf_resume_read_image()
741 mlx5vf_resume_read_header_data(struct mlx5_vf_migration_file *migf, in mlx5vf_resume_read_header_data() argument
751 required_data = migf->record_size - vhca_buf->length; in mlx5vf_resume_read_header_data()
762 if (vhca_buf->length == migf->record_size) { in mlx5vf_resume_read_header_data()
763 switch (migf->record_tag) { in mlx5vf_resume_read_header_data()
772 migf->stop_copy_prep_size = min_t(u64, in mlx5vf_resume_read_header_data()
782 migf->load_state = MLX5_VF_LOAD_STATE_READ_HEADER; in mlx5vf_resume_read_header_data()
783 migf->max_pos += migf->record_size; in mlx5vf_resume_read_header_data()
791 mlx5vf_resume_read_header(struct mlx5_vf_migration_file *migf, in mlx5vf_resume_read_header() argument
829 migf->record_size = record_size; in mlx5vf_resume_read_header()
832 migf->record_tag = le32_to_cpup((__le32 *)(to_buff + in mlx5vf_resume_read_header()
834 switch (migf->record_tag) { in mlx5vf_resume_read_header()
836 migf->load_state = MLX5_VF_LOAD_STATE_PREP_IMAGE; in mlx5vf_resume_read_header()
839 migf->load_state = MLX5_VF_LOAD_STATE_PREP_HEADER_DATA; in mlx5vf_resume_read_header()
847 migf->load_state = MLX5_VF_LOAD_STATE_PREP_HEADER_DATA; in mlx5vf_resume_read_header()
850 migf->max_pos += vhca_buf->length; in mlx5vf_resume_read_header()
862 struct mlx5_vf_migration_file *migf = filp->private_data; in mlx5vf_resume_write() local
863 struct mlx5_vhca_data_buffer *vhca_buf = migf->buf[0]; in mlx5vf_resume_write()
864 struct mlx5_vhca_data_buffer *vhca_buf_header = migf->buf_header[0]; in mlx5vf_resume_write()
878 mutex_lock(&migf->mvdev->state_mutex); in mlx5vf_resume_write()
879 mutex_lock(&migf->lock); in mlx5vf_resume_write()
880 if (migf->state == MLX5_MIGF_STATE_ERROR) { in mlx5vf_resume_write()
887 switch (migf->load_state) { in mlx5vf_resume_write()
889 ret = mlx5vf_resume_read_header(migf, vhca_buf_header, in mlx5vf_resume_write()
897 u32 npages = DIV_ROUND_UP(migf->record_size, PAGE_SIZE); in mlx5vf_resume_write()
902 migf->buf_header[0] = mlx5vf_alloc_data_buffer( in mlx5vf_resume_write()
903 migf, npages, DMA_NONE); in mlx5vf_resume_write()
904 if (IS_ERR(migf->buf_header[0])) { in mlx5vf_resume_write()
905 ret = PTR_ERR(migf->buf_header[0]); in mlx5vf_resume_write()
906 migf->buf_header[0] = NULL; in mlx5vf_resume_write()
910 vhca_buf_header = migf->buf_header[0]; in mlx5vf_resume_write()
913 vhca_buf_header->start_pos = migf->max_pos; in mlx5vf_resume_write()
914 migf->load_state = MLX5_VF_LOAD_STATE_READ_HEADER_DATA; in mlx5vf_resume_write()
918 ret = mlx5vf_resume_read_header_data(migf, vhca_buf_header, in mlx5vf_resume_write()
925 u64 size = max(migf->record_size, in mlx5vf_resume_write()
926 migf->stop_copy_prep_size); in mlx5vf_resume_write()
932 migf->buf[0] = mlx5vf_alloc_data_buffer( in mlx5vf_resume_write()
933 migf, npages, DMA_TO_DEVICE); in mlx5vf_resume_write()
934 if (IS_ERR(migf->buf[0])) { in mlx5vf_resume_write()
935 ret = PTR_ERR(migf->buf[0]); in mlx5vf_resume_write()
936 migf->buf[0] = NULL; in mlx5vf_resume_write()
940 vhca_buf = migf->buf[0]; in mlx5vf_resume_write()
943 vhca_buf->start_pos = migf->max_pos; in mlx5vf_resume_write()
944 migf->load_state = MLX5_VF_LOAD_STATE_READ_IMAGE; in mlx5vf_resume_write()
948 ret = mlx5vf_resume_read_image(migf, vhca_buf, in mlx5vf_resume_write()
949 migf->record_size, in mlx5vf_resume_write()
955 ret = mlx5vf_cmd_load_vhca_state(migf->mvdev, migf, vhca_buf); in mlx5vf_resume_write()
958 migf->load_state = MLX5_VF_LOAD_STATE_READ_HEADER; in mlx5vf_resume_write()
973 migf->state = MLX5_MIGF_STATE_ERROR; in mlx5vf_resume_write()
974 mutex_unlock(&migf->lock); in mlx5vf_resume_write()
975 mlx5vf_state_mutex_unlock(migf->mvdev); in mlx5vf_resume_write()
988 struct mlx5_vf_migration_file *migf; in mlx5vf_pci_resume_device_data() local
992 migf = kzalloc(sizeof(*migf), GFP_KERNEL_ACCOUNT); in mlx5vf_pci_resume_device_data()
993 if (!migf) in mlx5vf_pci_resume_device_data()
996 migf->filp = anon_inode_getfile("mlx5vf_mig", &mlx5vf_resume_fops, migf, in mlx5vf_pci_resume_device_data()
998 if (IS_ERR(migf->filp)) { in mlx5vf_pci_resume_device_data()
999 ret = PTR_ERR(migf->filp); in mlx5vf_pci_resume_device_data()
1000 kfree(migf); in mlx5vf_pci_resume_device_data()
1004 stream_open(migf->filp->f_inode, migf->filp); in mlx5vf_pci_resume_device_data()
1005 mutex_init(&migf->lock); in mlx5vf_pci_resume_device_data()
1006 INIT_LIST_HEAD(&migf->buf_list); in mlx5vf_pci_resume_device_data()
1007 INIT_LIST_HEAD(&migf->avail_list); in mlx5vf_pci_resume_device_data()
1008 spin_lock_init(&migf->list_lock); in mlx5vf_pci_resume_device_data()
1009 migf->mvdev = mvdev; in mlx5vf_pci_resume_device_data()
1010 ret = mlx5vf_cmd_alloc_pd(migf); in mlx5vf_pci_resume_device_data()
1014 buf = mlx5vf_alloc_data_buffer(migf, 0, DMA_TO_DEVICE); in mlx5vf_pci_resume_device_data()
1020 migf->buf[0] = buf; in mlx5vf_pci_resume_device_data()
1022 migf, in mlx5vf_pci_resume_device_data()
1031 migf->buf_header[0] = buf; in mlx5vf_pci_resume_device_data()
1032 migf->load_state = MLX5_VF_LOAD_STATE_READ_HEADER; in mlx5vf_pci_resume_device_data()
1034 return migf; in mlx5vf_pci_resume_device_data()
1036 mlx5vf_free_data_buffer(migf->buf[0]); in mlx5vf_pci_resume_device_data()
1038 mlx5vf_cmd_dealloc_pd(migf); in mlx5vf_pci_resume_device_data()
1040 fput(migf->filp); in mlx5vf_pci_resume_device_data()
1108 struct mlx5_vf_migration_file *migf; in mlx5vf_pci_step_device_state_locked() local
1110 migf = mlx5vf_pci_save_device_data(mvdev, false); in mlx5vf_pci_step_device_state_locked()
1111 if (IS_ERR(migf)) in mlx5vf_pci_step_device_state_locked()
1112 return ERR_CAST(migf); in mlx5vf_pci_step_device_state_locked()
1113 get_file(migf->filp); in mlx5vf_pci_step_device_state_locked()
1114 mvdev->saving_migf = migf; in mlx5vf_pci_step_device_state_locked()
1115 return migf->filp; in mlx5vf_pci_step_device_state_locked()
1126 struct mlx5_vf_migration_file *migf = mvdev->saving_migf; in mlx5vf_pci_step_device_state_locked() local
1135 buf = mlx5vf_get_data_buffer(migf, in mlx5vf_pci_step_device_state_locked()
1140 ret = mlx5vf_cmd_save_vhca_state(mvdev, migf, buf, false, false); in mlx5vf_pci_step_device_state_locked()
1150 struct mlx5_vf_migration_file *migf; in mlx5vf_pci_step_device_state_locked() local
1152 migf = mlx5vf_pci_resume_device_data(mvdev); in mlx5vf_pci_step_device_state_locked()
1153 if (IS_ERR(migf)) in mlx5vf_pci_step_device_state_locked()
1154 return ERR_CAST(migf); in mlx5vf_pci_step_device_state_locked()
1155 get_file(migf->filp); in mlx5vf_pci_step_device_state_locked()
1156 mvdev->resuming_migf = migf; in mlx5vf_pci_step_device_state_locked()
1157 return migf->filp; in mlx5vf_pci_step_device_state_locked()
1168 struct mlx5_vf_migration_file *migf; in mlx5vf_pci_step_device_state_locked() local
1170 migf = mlx5vf_pci_save_device_data(mvdev, true); in mlx5vf_pci_step_device_state_locked()
1171 if (IS_ERR(migf)) in mlx5vf_pci_step_device_state_locked()
1172 return ERR_CAST(migf); in mlx5vf_pci_step_device_state_locked()
1173 get_file(migf->filp); in mlx5vf_pci_step_device_state_locked()
1174 mvdev->saving_migf = migf; in mlx5vf_pci_step_device_state_locked()
1175 return migf->filp; in mlx5vf_pci_step_device_state_locked()