Commit d9701f8d authored by Weili Qian's avatar Weili Qian Committed by Herbert Xu

crypto: hisilicon - unify initial value assignment into QM

Some initial value assignment of struct hisi_qm could put into QM.
Signed-off-by: default avatarWeili Qian <qianweili@huawei.com>
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 b977e030
...@@ -672,12 +672,13 @@ static int hpre_qm_init(struct hisi_qm *qm, struct pci_dev *pdev) ...@@ -672,12 +672,13 @@ static int hpre_qm_init(struct hisi_qm *qm, struct pci_dev *pdev)
qm->ver = rev_id; qm->ver = rev_id;
qm->sqe_size = HPRE_SQE_SIZE; qm->sqe_size = HPRE_SQE_SIZE;
qm->dev_name = hpre_name; qm->dev_name = hpre_name;
qm->fun_type = (pdev->device == HPRE_PCI_DEVICE_ID) ?
QM_HW_PF : QM_HW_VF;
if (pdev->is_physfn) { qm->fun_type = (pdev->device == HPRE_PCI_DEVICE_ID) ?
QM_HW_PF : QM_HW_VF;
if (qm->fun_type == QM_HW_PF) {
qm->qp_base = HPRE_PF_DEF_Q_BASE; qm->qp_base = HPRE_PF_DEF_Q_BASE;
qm->qp_num = pf_q_num; qm->qp_num = pf_q_num;
qm->qm_list = &hpre_devices;
} }
return hisi_qm_init(qm); return hisi_qm_init(qm);
...@@ -748,7 +749,6 @@ static int hpre_pf_probe_init(struct hpre *hpre) ...@@ -748,7 +749,6 @@ static int hpre_pf_probe_init(struct hpre *hpre)
if (ret) if (ret)
return ret; return ret;
qm->qm_list = &hpre_devices;
qm->err_ini = &hpre_err_ini; qm->err_ini = &hpre_err_ini;
hisi_qm_dev_err_init(qm); hisi_qm_dev_err_init(qm);
...@@ -758,15 +758,15 @@ static int hpre_pf_probe_init(struct hpre *hpre) ...@@ -758,15 +758,15 @@ static int hpre_pf_probe_init(struct hpre *hpre)
static int hpre_probe_init(struct hpre *hpre) static int hpre_probe_init(struct hpre *hpre)
{ {
struct hisi_qm *qm = &hpre->qm; struct hisi_qm *qm = &hpre->qm;
int ret = -ENODEV; int ret;
if (qm->fun_type == QM_HW_PF) if (qm->fun_type == QM_HW_PF) {
ret = hpre_pf_probe_init(hpre); ret = hpre_pf_probe_init(hpre);
else if (qm->fun_type == QM_HW_VF && qm->ver == QM_HW_V2) if (ret)
/* v2 starts to support get vft by mailbox */ return ret;
ret = hisi_qm_get_vft(qm, &qm->qp_base, &qm->qp_num); }
return ret; return 0;
} }
static int hpre_probe(struct pci_dev *pdev, const struct pci_device_id *id) static int hpre_probe(struct pci_dev *pdev, const struct pci_device_id *id)
...@@ -779,8 +779,6 @@ static int hpre_probe(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -779,8 +779,6 @@ static int hpre_probe(struct pci_dev *pdev, const struct pci_device_id *id)
if (!hpre) if (!hpre)
return -ENOMEM; return -ENOMEM;
pci_set_drvdata(pdev, hpre);
qm = &hpre->qm; qm = &hpre->qm;
ret = hpre_qm_init(qm, pdev); ret = hpre_qm_init(qm, pdev);
if (ret) { if (ret) {
......
...@@ -1916,6 +1916,27 @@ int hisi_qm_get_free_qp_num(struct hisi_qm *qm) ...@@ -1916,6 +1916,27 @@ int hisi_qm_get_free_qp_num(struct hisi_qm *qm)
} }
EXPORT_SYMBOL_GPL(hisi_qm_get_free_qp_num); EXPORT_SYMBOL_GPL(hisi_qm_get_free_qp_num);
static void hisi_qm_pre_init(struct hisi_qm *qm)
{
struct pci_dev *pdev = qm->pdev;
switch (qm->ver) {
case QM_HW_V1:
qm->ops = &qm_hw_ops_v1;
break;
case QM_HW_V2:
qm->ops = &qm_hw_ops_v2;
break;
default:
return;
}
pci_set_drvdata(pdev, qm);
mutex_init(&qm->mailbox_lock);
init_rwsem(&qm->qps_lock);
qm->qp_in_used = 0;
}
/** /**
* hisi_qm_init() - Initialize configures about qm. * hisi_qm_init() - Initialize configures about qm.
* @qm: The qm needing init. * @qm: The qm needing init.
...@@ -1929,16 +1950,7 @@ int hisi_qm_init(struct hisi_qm *qm) ...@@ -1929,16 +1950,7 @@ int hisi_qm_init(struct hisi_qm *qm)
unsigned int num_vec; unsigned int num_vec;
int ret; int ret;
switch (qm->ver) { hisi_qm_pre_init(qm);
case QM_HW_V1:
qm->ops = &qm_hw_ops_v1;
break;
case QM_HW_V2:
qm->ops = &qm_hw_ops_v2;
break;
default:
return -EINVAL;
}
ret = qm_alloc_uacce(qm); ret = qm_alloc_uacce(qm);
if (ret < 0) if (ret < 0)
...@@ -1984,15 +1996,21 @@ int hisi_qm_init(struct hisi_qm *qm) ...@@ -1984,15 +1996,21 @@ int hisi_qm_init(struct hisi_qm *qm)
if (ret) if (ret)
goto err_free_irq_vectors; goto err_free_irq_vectors;
qm->qp_in_used = 0; if (qm->fun_type == QM_HW_VF && qm->ver == QM_HW_V2) {
mutex_init(&qm->mailbox_lock); /* v2 starts to support get vft by mailbox */
init_rwsem(&qm->qps_lock); ret = hisi_qm_get_vft(qm, &qm->qp_base, &qm->qp_num);
if (ret)
goto err_irq_unregister;
}
INIT_WORK(&qm->work, qm_work_process); INIT_WORK(&qm->work, qm_work_process);
atomic_set(&qm->status.flags, QM_INIT); atomic_set(&qm->status.flags, QM_INIT);
return 0; return 0;
err_irq_unregister:
qm_irq_unregister(qm);
err_free_irq_vectors: err_free_irq_vectors:
pci_free_irq_vectors(pdev); pci_free_irq_vectors(pdev);
err_iounmap: err_iounmap:
......
...@@ -722,6 +722,7 @@ static int sec_pf_probe_init(struct sec_dev *sec) ...@@ -722,6 +722,7 @@ static int sec_pf_probe_init(struct sec_dev *sec)
static int sec_qm_init(struct hisi_qm *qm, struct pci_dev *pdev) static int sec_qm_init(struct hisi_qm *qm, struct pci_dev *pdev)
{ {
enum qm_hw_ver rev_id; enum qm_hw_ver rev_id;
int ret;
rev_id = hisi_qm_get_hw_version(pdev); rev_id = hisi_qm_get_hw_version(pdev);
if (rev_id == QM_HW_UNKNOWN) if (rev_id == QM_HW_UNKNOWN)
...@@ -729,9 +730,9 @@ static int sec_qm_init(struct hisi_qm *qm, struct pci_dev *pdev) ...@@ -729,9 +730,9 @@ static int sec_qm_init(struct hisi_qm *qm, struct pci_dev *pdev)
qm->pdev = pdev; qm->pdev = pdev;
qm->ver = rev_id; qm->ver = rev_id;
qm->sqe_size = SEC_SQE_SIZE; qm->sqe_size = SEC_SQE_SIZE;
qm->dev_name = sec_name; qm->dev_name = sec_name;
qm->fun_type = (pdev->device == SEC_PF_PCI_DEVICE_ID) ? qm->fun_type = (pdev->device == SEC_PF_PCI_DEVICE_ID) ?
QM_HW_PF : QM_HW_VF; QM_HW_PF : QM_HW_VF;
if (qm->fun_type == QM_HW_PF) { if (qm->fun_type == QM_HW_PF) {
...@@ -750,7 +751,25 @@ static int sec_qm_init(struct hisi_qm *qm, struct pci_dev *pdev) ...@@ -750,7 +751,25 @@ static int sec_qm_init(struct hisi_qm *qm, struct pci_dev *pdev)
qm->qp_num = SEC_QUEUE_NUM_V1 - SEC_PF_DEF_Q_NUM; qm->qp_num = SEC_QUEUE_NUM_V1 - SEC_PF_DEF_Q_NUM;
} }
return hisi_qm_init(qm); /*
* WQ_HIGHPRI: SEC request must be low delayed,
* so need a high priority workqueue.
* WQ_UNBOUND: SEC task is likely with long
* running CPU intensive workloads.
*/
qm->wq = alloc_workqueue("%s", WQ_HIGHPRI | WQ_MEM_RECLAIM |
WQ_UNBOUND, num_online_cpus(),
pci_name(qm->pdev));
if (!qm->wq) {
pci_err(qm->pdev, "fail to alloc workqueue\n");
return -ENOMEM;
}
ret = hisi_qm_init(qm);
if (ret)
destroy_workqueue(qm->wq);
return ret;
} }
static void sec_qm_uninit(struct hisi_qm *qm) static void sec_qm_uninit(struct hisi_qm *qm)
...@@ -763,29 +782,10 @@ static int sec_probe_init(struct sec_dev *sec) ...@@ -763,29 +782,10 @@ static int sec_probe_init(struct sec_dev *sec)
struct hisi_qm *qm = &sec->qm; struct hisi_qm *qm = &sec->qm;
int ret; int ret;
/* if (qm->fun_type == QM_HW_PF) {
* WQ_HIGHPRI: SEC request must be low delayed,
* so need a high priority workqueue.
* WQ_UNBOUND: SEC task is likely with long
* running CPU intensive workloads.
*/
qm->wq = alloc_workqueue("%s", WQ_HIGHPRI |
WQ_MEM_RECLAIM | WQ_UNBOUND, num_online_cpus(),
pci_name(qm->pdev));
if (!qm->wq) {
pci_err(qm->pdev, "fail to alloc workqueue\n");
return -ENOMEM;
}
if (qm->fun_type == QM_HW_PF)
ret = sec_pf_probe_init(sec); ret = sec_pf_probe_init(sec);
else if (qm->fun_type == QM_HW_VF && qm->ver == QM_HW_V2) if (ret)
/* v2 starts to support get vft by mailbox */ return ret;
ret = hisi_qm_get_vft(qm, &qm->qp_base, &qm->qp_num);
if (ret) {
destroy_workqueue(qm->wq);
return ret;
} }
return 0; return 0;
...@@ -825,8 +825,6 @@ static int sec_probe(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -825,8 +825,6 @@ static int sec_probe(struct pci_dev *pdev, const struct pci_device_id *id)
if (!sec) if (!sec)
return -ENOMEM; return -ENOMEM;
pci_set_drvdata(pdev, sec);
qm = &sec->qm; qm = &sec->qm;
ret = sec_qm_init(qm, pdev); ret = sec_qm_init(qm, pdev);
if (ret) { if (ret) {
......
...@@ -694,12 +694,27 @@ static int hisi_zip_qm_init(struct hisi_qm *qm, struct pci_dev *pdev) ...@@ -694,12 +694,27 @@ static int hisi_zip_qm_init(struct hisi_qm *qm, struct pci_dev *pdev)
qm->pdev = pdev; qm->pdev = pdev;
qm->ver = rev_id; qm->ver = rev_id;
qm->algs = "zlib\ngzip"; qm->algs = "zlib\ngzip";
qm->sqe_size = HZIP_SQE_SIZE; qm->sqe_size = HZIP_SQE_SIZE;
qm->dev_name = hisi_zip_name; qm->dev_name = hisi_zip_name;
qm->fun_type = (pdev->device == PCI_DEVICE_ID_ZIP_PF) ? qm->fun_type = (pdev->device == PCI_DEVICE_ID_ZIP_PF) ?
QM_HW_PF : QM_HW_VF; QM_HW_PF : QM_HW_VF;
if (qm->fun_type == QM_HW_PF) {
qm->qp_base = HZIP_PF_DEF_Q_BASE;
qm->qp_num = pf_q_num;
qm->qm_list = &zip_devices;
} else if (qm->fun_type == QM_HW_VF && qm->ver == QM_HW_V1) {
/*
* have no way to get qm configure in VM in v1 hardware,
* so currently force PF to uses HZIP_PF_DEF_Q_NUM, and force
* to trigger only one VF in v1 hardware.
*
* v2 hardware has no such problem.
*/
qm->qp_base = HZIP_PF_DEF_Q_NUM;
qm->qp_num = HZIP_QUEUE_NUM_V1 - HZIP_PF_DEF_Q_NUM;
}
return hisi_qm_init(qm); return hisi_qm_init(qm);
} }
...@@ -713,24 +728,6 @@ static int hisi_zip_probe_init(struct hisi_zip *hisi_zip) ...@@ -713,24 +728,6 @@ static int hisi_zip_probe_init(struct hisi_zip *hisi_zip)
ret = hisi_zip_pf_probe_init(hisi_zip); ret = hisi_zip_pf_probe_init(hisi_zip);
if (ret) if (ret)
return ret; return ret;
qm->qp_base = HZIP_PF_DEF_Q_BASE;
qm->qp_num = pf_q_num;
qm->qm_list = &zip_devices;
} else if (qm->fun_type == QM_HW_VF) {
/*
* have no way to get qm configure in VM in v1 hardware,
* so currently force PF to uses HZIP_PF_DEF_Q_NUM, and force
* to trigger only one VF in v1 hardware.
*
* v2 hardware has no such problem.
*/
if (qm->ver == QM_HW_V1) {
qm->qp_base = HZIP_PF_DEF_Q_NUM;
qm->qp_num = HZIP_QUEUE_NUM_V1 - HZIP_PF_DEF_Q_NUM;
} else if (qm->ver == QM_HW_V2)
/* v2 starts to support get vft by mailbox */
return hisi_qm_get_vft(qm, &qm->qp_base, &qm->qp_num);
} }
return 0; return 0;
...@@ -746,8 +743,6 @@ static int hisi_zip_probe(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -746,8 +743,6 @@ static int hisi_zip_probe(struct pci_dev *pdev, const struct pci_device_id *id)
if (!hisi_zip) if (!hisi_zip)
return -ENOMEM; return -ENOMEM;
pci_set_drvdata(pdev, hisi_zip);
qm = &hisi_zip->qm; qm = &hisi_zip->qm;
ret = hisi_zip_qm_init(qm, pdev); ret = hisi_zip_qm_init(qm, pdev);
......
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