Commit 488f30d4 authored by Kai Ye's avatar Kai Ye Committed by Herbert Xu

crypto: hisilicon/qm - some optimizations of ths qos write process

1. Optimize overly long functions.
2. Fix the format symbol does not match the actual type.
3. Use the PCI_DEVFN to get the function id.
Signed-off-by: default avatarKai Ye <yekai13@huawei.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent ecc7169d
...@@ -4231,66 +4231,69 @@ static ssize_t qm_qos_value_init(const char *buf, unsigned long *val) ...@@ -4231,66 +4231,69 @@ static ssize_t qm_qos_value_init(const char *buf, unsigned long *val)
return 0; return 0;
} }
static ssize_t qm_get_qos_value(struct hisi_qm *qm, const char *buf,
unsigned long *val,
unsigned int *fun_index)
{
char tbuf_bdf[QM_DBG_READ_LEN] = {0};
char val_buf[QM_QOS_VAL_MAX_LEN] = {0};
u32 tmp1, device, function;
int ret, bus;
ret = sscanf(buf, "%s %s", tbuf_bdf, val_buf);
if (ret != QM_QOS_PARAM_NUM)
return -EINVAL;
ret = qm_qos_value_init(val_buf, val);
if (*val == 0 || *val > QM_QOS_MAX_VAL || ret) {
pci_err(qm->pdev, "input qos value is error, please set 1~1000!\n");
return -EINVAL;
}
ret = sscanf(tbuf_bdf, "%u:%x:%u.%u", &tmp1, &bus, &device, &function);
if (ret != QM_QOS_BDF_PARAM_NUM) {
pci_err(qm->pdev, "input pci bdf value is error!\n");
return -EINVAL;
}
*fun_index = PCI_DEVFN(device, function);
return 0;
}
static ssize_t qm_algqos_write(struct file *filp, const char __user *buf, static ssize_t qm_algqos_write(struct file *filp, const char __user *buf,
size_t count, loff_t *pos) size_t count, loff_t *pos)
{ {
struct hisi_qm *qm = filp->private_data; struct hisi_qm *qm = filp->private_data;
char tbuf[QM_DBG_READ_LEN]; char tbuf[QM_DBG_READ_LEN];
int tmp1, bus, device, function;
char tbuf_bdf[QM_DBG_READ_LEN] = {0};
char val_buf[QM_QOS_VAL_MAX_LEN] = {0};
unsigned int fun_index; unsigned int fun_index;
unsigned long val = 0; unsigned long val;
int len, ret; int len, ret;
if (qm->fun_type == QM_HW_VF) if (qm->fun_type == QM_HW_VF)
return -EINVAL; return -EINVAL;
/* Mailbox and reset cannot be operated at the same time */ if (*pos != 0)
if (test_and_set_bit(QM_RESETTING, &qm->misc_ctl)) { return 0;
pci_err(qm->pdev, "dev resetting, write alg qos failed!\n");
return -EAGAIN;
}
if (*pos != 0) {
ret = 0;
goto err_get_status;
}
if (count >= QM_DBG_READ_LEN) { if (count >= QM_DBG_READ_LEN)
ret = -ENOSPC; return -ENOSPC;
goto err_get_status;
}
len = simple_write_to_buffer(tbuf, QM_DBG_READ_LEN - 1, pos, buf, count); len = simple_write_to_buffer(tbuf, QM_DBG_READ_LEN - 1, pos, buf, count);
if (len < 0) { if (len < 0)
ret = len; return len;
goto err_get_status;
}
tbuf[len] = '\0'; tbuf[len] = '\0';
ret = sscanf(tbuf, "%s %s", tbuf_bdf, val_buf); ret = qm_get_qos_value(qm, tbuf, &val, &fun_index);
if (ret != QM_QOS_PARAM_NUM) { if (ret)
ret = -EINVAL; return ret;
goto err_get_status;
}
ret = qm_qos_value_init(val_buf, &val);
if (val == 0 || val > QM_QOS_MAX_VAL || ret) {
pci_err(qm->pdev, "input qos value is error, please set 1~1000!\n");
ret = -EINVAL;
goto err_get_status;
}
ret = sscanf(tbuf_bdf, "%d:%x:%d.%d", &tmp1, &bus, &device, &function); /* Mailbox and reset cannot be operated at the same time */
if (ret != QM_QOS_BDF_PARAM_NUM) { if (test_and_set_bit(QM_RESETTING, &qm->misc_ctl)) {
pci_err(qm->pdev, "input pci bdf value is error!\n"); pci_err(qm->pdev, "dev resetting, write alg qos failed!\n");
ret = -EINVAL; return -EAGAIN;
goto err_get_status;
} }
fun_index = device * 8 + function;
ret = qm_pm_get_sync(qm); ret = qm_pm_get_sync(qm);
if (ret) { if (ret) {
ret = -EINVAL; ret = -EINVAL;
...@@ -4304,6 +4307,8 @@ static ssize_t qm_algqos_write(struct file *filp, const char __user *buf, ...@@ -4304,6 +4307,8 @@ static ssize_t qm_algqos_write(struct file *filp, const char __user *buf,
goto err_put_sync; goto err_put_sync;
} }
pci_info(qm->pdev, "the qos value of function%u is set to %lu.\n",
fun_index, val);
ret = count; ret = count;
err_put_sync: err_put_sync:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment