drivers/vfio/pci/qat/main.c

Source file repositories/reference/linux-study-clean/drivers/vfio/pci/qat/main.c

File Facts

System
Linux kernel
Corpus path
drivers/vfio/pci/qat/main.c
Extension
.c
Size
18868 bytes
Lines
706
Domain
Driver Families
Bucket
drivers/vfio
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct file_operations qat_vf_save_fops = {
	.owner = THIS_MODULE,
	.read = qat_vf_save_read,
	.unlocked_ioctl = qat_vf_precopy_ioctl,
	.compat_ioctl = compat_ptr_ioctl,
	.release = qat_vf_release_file,
};

static int qat_vf_save_state(struct qat_vf_core_device *qat_vdev,
			     struct qat_vf_migration_file *migf)
{
	int ret;

	ret = qat_vfmig_save_state(qat_vdev->mdev);
	if (ret)
		return ret;
	migf->filled_size = qat_vdev->mdev->state_size;

	return 0;
}

static int qat_vf_save_setup(struct qat_vf_core_device *qat_vdev,
			     struct qat_vf_migration_file *migf)
{
	int ret;

	ret = qat_vfmig_save_setup(qat_vdev->mdev);
	if (ret)
		return ret;
	migf->filled_size = qat_vdev->mdev->setup_size;

	return 0;
}

/*
 * Allocate a file handler for user space and then save the migration data for
 * the device being migrated. If this is called in the pre-copy stage, save the
 * pre-configured device data. Otherwise, if this is called in the stop-copy
 * stage, save the device state. In both cases, update the data size which can
 * then be read from user space.
 */
static struct qat_vf_migration_file *
qat_vf_save_device_data(struct qat_vf_core_device *qat_vdev, bool pre_copy)
{
	struct qat_vf_migration_file *migf;
	int ret;

	migf = kzalloc_obj(*migf);
	if (!migf)
		return ERR_PTR(-ENOMEM);

	migf->filp = anon_inode_getfile("qat_vf_mig", &qat_vf_save_fops,
					migf, O_RDONLY);
	ret = PTR_ERR_OR_ZERO(migf->filp);
	if (ret) {
		kfree(migf);
		return ERR_PTR(ret);
	}

	stream_open(migf->filp->f_inode, migf->filp);
	mutex_init(&migf->lock);

	if (pre_copy)
		ret = qat_vf_save_setup(qat_vdev, migf);
	else
		ret = qat_vf_save_state(qat_vdev, migf);
	if (ret) {
		fput(migf->filp);
		return ERR_PTR(ret);
	}

	migf->qat_vdev = qat_vdev;

	return migf;
}

static ssize_t qat_vf_resume_write(struct file *filp, const char __user *buf,
				   size_t len, loff_t *pos)
{
	struct qat_vf_migration_file *migf = filp->private_data;
	struct qat_mig_dev *mig_dev = migf->qat_vdev->mdev;
	loff_t end, *offs;
	ssize_t done = 0;
	int ret;

	if (pos)
		return -ESPIPE;
	offs = &filp->f_pos;

	mutex_lock(&migf->lock);

Annotation

Implementation Notes