Commit 20b291f5 authored by Shukun Tan's avatar Shukun Tan Committed by Herbert Xu

crypto: hisilicon - refactor module parameter pf_q_num related code

put q_num_set similar code into qm to reduce the redundancy.
Signed-off-by: default avatarShukun Tan <tanshukun1@huawei.com>
Reviewed-by: default avatarZhou Wang <wangzhou1@hisilicon.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent cfd66a66
...@@ -159,44 +159,19 @@ static const struct debugfs_reg32 hpre_com_dfx_regs[] = { ...@@ -159,44 +159,19 @@ static const struct debugfs_reg32 hpre_com_dfx_regs[] = {
{"INT_STATUS ", HPRE_INT_STATUS}, {"INT_STATUS ", HPRE_INT_STATUS},
}; };
static int hpre_pf_q_num_set(const char *val, const struct kernel_param *kp) static int pf_q_num_set(const char *val, const struct kernel_param *kp)
{ {
struct pci_dev *pdev; return q_num_set(val, kp, HPRE_PCI_DEVICE_ID);
u32 n, q_num;
u8 rev_id;
int ret;
if (!val)
return -EINVAL;
pdev = pci_get_device(PCI_VENDOR_ID_HUAWEI, HPRE_PCI_DEVICE_ID, NULL);
if (!pdev) {
q_num = HPRE_QUEUE_NUM_V2;
pr_info("No device found currently, suppose queue number is %d\n",
q_num);
} else {
rev_id = pdev->revision;
if (rev_id != QM_HW_V2)
return -EINVAL;
q_num = HPRE_QUEUE_NUM_V2;
}
ret = kstrtou32(val, 10, &n);
if (ret != 0 || n == 0 || n > q_num)
return -EINVAL;
return param_set_int(val, kp);
} }
static const struct kernel_param_ops hpre_pf_q_num_ops = { static const struct kernel_param_ops hpre_pf_q_num_ops = {
.set = hpre_pf_q_num_set, .set = pf_q_num_set,
.get = param_get_int, .get = param_get_int,
}; };
static u32 hpre_pf_q_num = HPRE_PF_DEF_Q_NUM; static u32 pf_q_num = HPRE_PF_DEF_Q_NUM;
module_param_cb(hpre_pf_q_num, &hpre_pf_q_num_ops, &hpre_pf_q_num, 0444); module_param_cb(pf_q_num, &hpre_pf_q_num_ops, &pf_q_num, 0444);
MODULE_PARM_DESC(hpre_pf_q_num, "Number of queues in PF of CS(1-1024)"); MODULE_PARM_DESC(pf_q_num, "Number of queues in PF of CS(1-1024)");
static const struct kernel_param_ops vfs_num_ops = { static const struct kernel_param_ops vfs_num_ops = {
.set = vfs_num_set, .set = vfs_num_set,
...@@ -688,7 +663,7 @@ static int hpre_qm_init(struct hisi_qm *qm, struct pci_dev *pdev) ...@@ -688,7 +663,7 @@ static int hpre_qm_init(struct hisi_qm *qm, struct pci_dev *pdev)
if (pdev->is_physfn) { if (pdev->is_physfn) {
qm->qp_base = HPRE_PF_DEF_Q_BASE; qm->qp_base = HPRE_PF_DEF_Q_BASE;
qm->qp_num = hpre_pf_q_num; qm->qp_num = pf_q_num;
} }
qm->use_dma_api = true; qm->use_dma_api = true;
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/pci.h> #include <linux/pci.h>
#define QM_QNUM_V1 4096
#define QM_QNUM_V2 1024
#define QM_MAX_VFS_NUM_V2 63 #define QM_MAX_VFS_NUM_V2 63
/* qm user domain */ /* qm user domain */
...@@ -252,6 +254,43 @@ struct hisi_qp { ...@@ -252,6 +254,43 @@ struct hisi_qp {
struct uacce_queue *uacce_q; struct uacce_queue *uacce_q;
}; };
static inline int q_num_set(const char *val, const struct kernel_param *kp,
unsigned int device)
{
struct pci_dev *pdev = pci_get_device(PCI_VENDOR_ID_HUAWEI,
device, NULL);
u32 n, q_num;
u8 rev_id;
int ret;
if (!val)
return -EINVAL;
if (!pdev) {
q_num = min_t(u32, QM_QNUM_V1, QM_QNUM_V2);
pr_info("No device found currently, suppose queue number is %d\n",
q_num);
} else {
rev_id = pdev->revision;
switch (rev_id) {
case QM_HW_V1:
q_num = QM_QNUM_V1;
break;
case QM_HW_V2:
q_num = QM_QNUM_V2;
break;
default:
return -EINVAL;
}
}
ret = kstrtou32(val, 10, &n);
if (ret || !n || n > q_num)
return -EINVAL;
return param_set_int(val, kp);
}
static inline int vfs_num_set(const char *val, const struct kernel_param *kp) static inline int vfs_num_set(const char *val, const struct kernel_param *kp)
{ {
u32 n; u32 n;
......
...@@ -136,45 +136,14 @@ static const struct debugfs_reg32 sec_dfx_regs[] = { ...@@ -136,45 +136,14 @@ static const struct debugfs_reg32 sec_dfx_regs[] = {
static int sec_pf_q_num_set(const char *val, const struct kernel_param *kp) static int sec_pf_q_num_set(const char *val, const struct kernel_param *kp)
{ {
struct pci_dev *pdev; return q_num_set(val, kp, SEC_PF_PCI_DEVICE_ID);
u32 n, q_num;
u8 rev_id;
int ret;
if (!val)
return -EINVAL;
pdev = pci_get_device(PCI_VENDOR_ID_HUAWEI,
SEC_PF_PCI_DEVICE_ID, NULL);
if (!pdev) {
q_num = min_t(u32, SEC_QUEUE_NUM_V1, SEC_QUEUE_NUM_V2);
pr_info("No device, suppose queue number is %d!\n", q_num);
} else {
rev_id = pdev->revision;
switch (rev_id) {
case QM_HW_V1:
q_num = SEC_QUEUE_NUM_V1;
break;
case QM_HW_V2:
q_num = SEC_QUEUE_NUM_V2;
break;
default:
return -EINVAL;
}
}
ret = kstrtou32(val, 10, &n);
if (ret || !n || n > q_num)
return -EINVAL;
return param_set_int(val, kp);
} }
static const struct kernel_param_ops sec_pf_q_num_ops = { static const struct kernel_param_ops sec_pf_q_num_ops = {
.set = sec_pf_q_num_set, .set = sec_pf_q_num_set,
.get = param_get_int, .get = param_get_int,
}; };
static u32 pf_q_num = SEC_PF_DEF_Q_NUM; static u32 pf_q_num = SEC_PF_DEF_Q_NUM;
module_param_cb(pf_q_num, &sec_pf_q_num_ops, &pf_q_num, 0444); module_param_cb(pf_q_num, &sec_pf_q_num_ops, &pf_q_num, 0444);
MODULE_PARM_DESC(pf_q_num, "Number of queues in PF(v1 0-4096, v2 0-1024)"); MODULE_PARM_DESC(pf_q_num, "Number of queues in PF(v1 0-4096, v2 0-1024)");
......
...@@ -192,38 +192,7 @@ static const struct debugfs_reg32 hzip_dfx_regs[] = { ...@@ -192,38 +192,7 @@ static const struct debugfs_reg32 hzip_dfx_regs[] = {
static int pf_q_num_set(const char *val, const struct kernel_param *kp) static int pf_q_num_set(const char *val, const struct kernel_param *kp)
{ {
struct pci_dev *pdev = pci_get_device(PCI_VENDOR_ID_HUAWEI, return q_num_set(val, kp, PCI_DEVICE_ID_ZIP_PF);
PCI_DEVICE_ID_ZIP_PF, NULL);
u32 n, q_num;
u8 rev_id;
int ret;
if (!val)
return -EINVAL;
if (!pdev) {
q_num = min_t(u32, HZIP_QUEUE_NUM_V1, HZIP_QUEUE_NUM_V2);
pr_info("No device found currently, suppose queue number is %d\n",
q_num);
} else {
rev_id = pdev->revision;
switch (rev_id) {
case QM_HW_V1:
q_num = HZIP_QUEUE_NUM_V1;
break;
case QM_HW_V2:
q_num = HZIP_QUEUE_NUM_V2;
break;
default:
return -EINVAL;
}
}
ret = kstrtou32(val, 10, &n);
if (ret != 0 || n > q_num || n == 0)
return -EINVAL;
return param_set_int(val, kp);
} }
static const struct kernel_param_ops pf_q_num_ops = { static const struct kernel_param_ops pf_q_num_ops = {
......
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