Пример #1
0
static int adf_ctl_ioctl_dev_config(struct file *fp, unsigned int cmd,
                                    unsigned long arg)
{
    int ret;
    struct adf_user_cfg_ctl_data *ctl_data;
    struct adf_accel_dev *accel_dev;

    ret = adf_ctl_alloc_resources(&ctl_data, arg);
    if (ret)
        return ret;

    accel_dev = adf_devmgr_get_dev_by_id(ctl_data->device_id);
    if (!accel_dev) {
        ret = -EFAULT;
        goto out;
    }

    if (adf_dev_started(accel_dev)) {
        ret = -EFAULT;
        goto out;
    }

    if (adf_copy_key_value_data(accel_dev, ctl_data)) {
        ret = -EFAULT;
        goto out;
    }
    set_bit(ADF_STATUS_CONFIGURED, &accel_dev->status);
out:
    kfree(ctl_data);
    return ret;
}
Пример #2
0
static int adf_ctl_ioctl_dev_start(struct file *fp, unsigned int cmd,
				   unsigned long arg)
{
	int ret;
	struct adf_user_cfg_ctl_data *ctl_data;
	struct adf_accel_dev *accel_dev;

	ret = adf_ctl_alloc_resources(&ctl_data, arg);
	if (ret)
		return ret;

	accel_dev = adf_devmgr_get_dev_by_id(ctl_data->device_id);
	if (!accel_dev) {
		pr_err("QAT: Device %d not found\n", ctl_data->device_id);
		ret = -ENODEV;
		goto out;
	}

	if (!adf_dev_started(accel_dev)) {
		pr_info("QAT: Starting acceleration device qat_dev%d.\n",
			ctl_data->device_id);
		ret = adf_dev_start(accel_dev);
	} else {
		pr_info("QAT: Acceleration device qat_dev%d already started.\n",
			ctl_data->device_id);
	}
	if (ret) {
		pr_err("QAT: Failed to start qat_dev%d\n", ctl_data->device_id);
		adf_dev_stop(accel_dev);
	}
out:
	kfree(ctl_data);
	return ret;
}
Пример #3
0
static int adf_dev_aer_schedule_reset(struct adf_accel_dev *accel_dev,
				      enum adf_dev_reset_mode mode)
{
	struct adf_reset_dev_data *reset_data;

	if (adf_dev_started(accel_dev) &&
	    !test_bit(ADF_STATUS_RESTARTING, &accel_dev->status))
		return 0;

	set_bit(ADF_STATUS_RESTARTING, &accel_dev->status);
	reset_data = kzalloc(sizeof(*reset_data), GFP_ATOMIC);
	if (!reset_data)
		return -ENOMEM;
	reset_data->accel_dev = accel_dev;
	init_completion(&reset_data->compl);
	reset_data->mode = mode;
	INIT_WORK(&reset_data->reset_work, adf_device_reset_worker);
	queue_work(device_reset_wq, &reset_data->reset_work);

	/* If in sync mode wait for the result */
	if (mode == ADF_DEV_RESET_SYNC) {
		int ret = 0;
		/* Maximum device reset time is 10 seconds */
		unsigned long wait_jiffies = msecs_to_jiffies(10000);
		unsigned long timeout = wait_for_completion_timeout(
				   &reset_data->compl, wait_jiffies);
		if (!timeout) {
			pr_err("QAT: Reset device timeout expired\n");
			ret = -EFAULT;
		}
		kfree(reset_data);
		return ret;
	}
	return 0;
}
Пример #4
0
static int adf_ctl_stop_devices(uint32_t id)
{
	struct list_head *itr, *head = adf_devmgr_get_head();
	int ret = 0;

	list_for_each(itr, head) {
		struct adf_accel_dev *accel_dev =
				list_entry(itr, struct adf_accel_dev, list);
		if (id == accel_dev->accel_id || id == ADF_CFG_ALL_DEVICES) {
			if (!adf_dev_started(accel_dev))
				continue;

			if (adf_dev_stop(accel_dev)) {
				pr_err("QAT: Failed to stop qat_dev%d\n", id);
				ret = -EFAULT;
			}
		}
	}
	return ret;
}
Пример #5
0
static int adf_ctl_ioctl_get_status(struct file *fp, unsigned int cmd,
                                    unsigned long arg)
{
    struct adf_hw_device_data *hw_data;
    struct adf_dev_status_info dev_info;
    struct adf_accel_dev *accel_dev;

    if (copy_from_user(&dev_info, (void __user *)arg,
                       sizeof(struct adf_dev_status_info))) {
        pr_err("QAT: failed to copy from user.\n");
        return -EFAULT;
    }

    accel_dev = adf_devmgr_get_dev_by_id(dev_info.accel_id);
    if (!accel_dev) {
        pr_err("QAT: Device %d not found\n", dev_info.accel_id);
        return -ENODEV;
    }
    hw_data = accel_dev->hw_device;
    dev_info.state = adf_dev_started(accel_dev) ? DEV_UP : DEV_DOWN;
    dev_info.num_ae = hw_data->get_num_aes(hw_data);
    dev_info.num_accel = hw_data->get_num_accels(hw_data);
    dev_info.num_logical_accel = hw_data->num_logical_accel;
    dev_info.banks_per_accel = hw_data->num_banks
                               / hw_data->num_logical_accel;
    strlcpy(dev_info.name, hw_data->dev_class->name, sizeof(dev_info.name));
    dev_info.instance_id = hw_data->instance_id;
    dev_info.type = hw_data->dev_class->type;
    dev_info.bus = accel_to_pci_dev(accel_dev)->bus->number;
    dev_info.dev = PCI_SLOT(accel_to_pci_dev(accel_dev)->devfn);
    dev_info.fun = PCI_FUNC(accel_to_pci_dev(accel_dev)->devfn);

    if (copy_to_user((void __user *)arg, &dev_info,
                     sizeof(struct adf_dev_status_info))) {
        dev_err(&GET_DEV(accel_dev), "failed to copy status.\n");
        return -EFAULT;
    }
    return 0;
}