crypto: hisilicon/qm - misc fixes
Subsystems (5)
v5 cover crypto: hisilicon/qm - misc fixes
This patchset fix some qm bugs:
patch 1: store the string address before pass to 'strsep' patch 2: clear 'qp_status->used' when init the 'qp'
patch 3: use 'dev_info_ratelimited' to avoid printk flooding. patch 4: fix the judgement of queue is full
patch 7: save the vf configuration space to make sure it is available
after the 'PF' 'FLR'
patch 8: register callback to 'pci_driver.shutdown'
patch 9: wait for all working function finishs when remove the device patch 10: move the process of register alg to crypto in driver 'hisi_zip'
v5:
- add a error branch instead of return immediately in patch "fix wrong release after using strsep"
v4:
- exchange the patch 'fix the call trace when unbind device' and 'fix the process of register algorithms to crypto' to make sure the driver is stable.
v3:
- add the patch 10 which is aimed to fix the call trace when remove a working device
v2:
- fix the wrong email address on patch 1
Hui Tang (1):
crypto: hisilicon/qm - fix judgement of queue is full
Shukun Tan (3):
crypto: hisilicon/qm - clear used reference count when start qp
crypto: hisilicon/qm - fix event queue depth to 2048
crypto: hisilicon/qm - fix VF not available after PF FLR
Sihang Chen (1):
crypto: hisilicon/qm - fix wrong release after using strsep
Weili Qian (1):
crypto: hisilicon/qm - fix the call trace when unbind device
Yang Shen (4):
crypto: hisilicon/qm - fix print frequence in hisi_qp_send
crypto: hisilicon/qm - fix no stop reason when use 'hisi_qm_stop'
crypto: hisilicon/qm - register callback function to
'pci_driver.shutdown'
crypto: hisilicon/qm - fix the process of register algorithms to
crypto
drivers/crypto/hisilicon/hpre/hpre_crypto.c | 36 ++--- drivers/crypto/hisilicon/hpre/hpre_main.c | 28 ++-- drivers/crypto/hisilicon/qm.c | 224 ++++++++++++++++++++++++---- drivers/crypto/hisilicon/qm.h | 27 ++-- drivers/crypto/hisilicon/sec2/sec_crypto.c | 35 ++--- drivers/crypto/hisilicon/sec2/sec_main.c | 34 ++--- drivers/crypto/hisilicon/zip/zip_crypto.c | 2 +- drivers/crypto/hisilicon/zip/zip_main.c | 49 +++--- 8 files changed, 290 insertions(+), 145 deletions(-)
--
2.7.4
PATCH v5 1/10 crypto: hisilicon/qm - fix wrong release after using strsep
From: Sihang Chen <[email protected]>
Save the string address before pass to strsep, release it at end. Because strsep will update the string address to point after the token.
--- drivers/crypto/hisilicon/qm.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/crypto/hisilicon/qm.c +6 -4
@@ -1420,17 +1420,18 @@ static int qm_dbg_help(struct hisi_qm *qm, char *s)static int qm_cmd_write_dump (struct hisi_qm *qm,const char *cmd_buf) {struct device *dev = &qm->pdev->dev; -char *presult, *s; +char *presult, *s, *s_tmp;int ret; s =kstrdup (cmd_buf,GFP_KERNEL );if (!s)return -ENOMEM ; + s_tmp = s; presult =strsep (&s," " );if (!presult) { -kfree (s); -return -EINVAL ; + ret = -EINVAL ; + goto err_buffer_free; }if (!strcmp (presult,"sqc" ))
@@ -1459,7 +1460,8 @@ static int qm_cmd_write_dump(struct hisi_qm *qm, const char *cmd_buf)if (ret)dev_info (dev,"Please echo help\n" ); -kfree (s); +err_buffer_free: +kfree (s_tmp);return ret; }
Signature · 1 line
2.7.4
PATCH v5 2/10 crypto: hisilicon/qm - clear used reference count when start qp
In reply to Yang ShenFrom: Shukun Tan <[email protected]>
The used reference count is used for counting the number of 'sqe' which is under processing. This reference count should be cleared as starting 'qp', otherwise the 'used' will be messy when allocating this 'qp' again.
--- drivers/crypto/hisilicon/qm.c | 1 + 1 file changed, 1 insertion(+)
drivers/crypto/hisilicon/qm.c +1 -0
@@ -755,6 +755,7 @@ static void qm_init_qp_status(struct hisi_qp *qp) qp_status->cq_head =0 ; qp_status->cqc_phase = true;atomic_set (&qp_status->flags,0 ); +atomic_set (&qp_status->used,0 ); } static void qm_vft_data_cfg(struct hisi_qm *qm, enum vft_type type, u32 base,
Signature · 1 line
2.7.4
PATCH v5 3/10 crypto: hisilicon/qm - fix print frequence in hisi_qp_send
In reply to Yang ShenRequests will be sent continuously as resetting, which will cause 'printk' flooding. Using 'dev_info_ratelimited' can solve this problem well.
--- drivers/crypto/hisilicon/qm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/hisilicon/qm.c +1 -1
@@ -1984,7 +1984,7 @@ int hisi_qp_send(struct hisi_qp *qp, const void *msg)if (unlikely (atomic_read (&qp->qp_status.flags) ==QP_STOP ||atomic_read (&qp->qm->status.flags) ==QM_STOP || qp->is_resetting)) { -dev_info (&qp->qm->pdev->dev,"QP is stopped or resetting\n" ); +dev_info_ratelimited (&qp->qm->pdev->dev,"QP is stopped or resetting\n" );return -EAGAIN ; }
Signature · 1 line
2.7.4
PATCH v5 4/10 crypto: hisilicon/qm - fix judgement of queue is full
In reply to Yang ShenFrom: Hui Tang <[email protected]>
The queue depth is 1024, so the condition for judging the queue full should be 1023, otherwise the hardware cannot judge whether the queue is empty or full.
--- drivers/crypto/hisilicon/qm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/hisilicon/qm.c +1 -1
@@ -1647,7 +1647,7 @@ static void *qm_get_avail_sqe(struct hisi_qp *qp)struct hisi_qp_status *qp_status = &qp->qp_status;u16 sq_tail = qp_status->sq_tail; -if (unlikely (atomic_read (&qp->qp_status.used) ==QM_Q_DEPTH )) +if (unlikely (atomic_read (&qp->qp_status.used) ==QM_Q_DEPTH -1 ))return NULL ;return qp->sqe + sq_tail * qp->qm->sqe_size;
Signature · 1 line
2.7.4
PATCH v5 5/10 crypto: hisilicon/qm - fix event queue depth to 2048
In reply to Yang ShenFrom: Shukun Tan <[email protected]>
Increasing depth of 'event queue' from 1024 to 2048, which equals to twice depth of 'completion queue'. It will fix the easily happened 'event queue overflow' as using 1024 queue depth for 'event queue'.
--- drivers/crypto/hisilicon/qm.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/crypto/hisilicon/qm.c +13 -6
@@ -181,6 +181,7 @@#define QM_PCI_COMMAND_INVALID ~0#define QM_SQE_ADDR_MASK GENMASK(7, 0) +#define QM_EQ_DEPTH (1024 * 2)#define QM_MK_CQC_DW3_V1 (hop_num, pg_sz, buf_sz, cqe_sz) \ (((hop_num) << QM_CQ_HOP_NUM_SHIFT) | \
@@ -652,7 +653,7 @@ static void qm_work_process(struct work_struct *work) qp =qm_to_hisi_qp (qm, eqe);qm_poll_qp (qp, qm); -if (qm->status.eq_head ==QM_Q_DEPTH -1 ) { +if (qm->status.eq_head ==QM_EQ_DEPTH -1 ) { qm->status.eqc_phase = !qm->status.eqc_phase; eqe = qm->eqe; qm->status.eq_head =0 ;
@@ -661,7 +662,7 @@ static void qm_work_process(struct work_struct *work) qm->status.eq_head++; } -if (eqe_num ==QM_Q_DEPTH /2 -1 ) { +if (eqe_num ==QM_EQ_DEPTH /2 -1 ) { eqe_num =0 ;qm_db (qm,0 ,QM_DOORBELL_CMD_EQ , qm->status.eq_head,0 ); }
@@ -1371,7 +1372,13 @@ static int qm_eq_aeq_dump(struct hisi_qm *qm, const char *s,return -EINVAL ; ret =kstrtou32 (s,0 , &xeqe_id); -if (ret || xeqe_id >=QM_Q_DEPTH ) { +if (ret) +return -EINVAL ; + +if (!strcmp (name,"EQE" ) && xeqe_id >=QM_EQ_DEPTH ) { +dev_err (dev,"Please input eqe num (0-%d)" ,QM_EQ_DEPTH -1 ); +return -EINVAL ; + }else if (!strcmp (name,"AEQE" ) && xeqe_id >=QM_Q_DEPTH ) {dev_err (dev,"Please input aeqe num (0-%d)" ,QM_Q_DEPTH -1 );return -EINVAL ; }
@@ -2285,7 +2292,7 @@ static int hisi_qm_memory_init(struct hisi_qm *qm) }while (0 )idr_init (&qm->qp_idr); - qm->qdma.size =QMC_ALIGN (sizeof (struct qm_eqe ) *QM_Q_DEPTH ) + + qm->qdma.size =QMC_ALIGN (sizeof (struct qm_eqe ) *QM_EQ_DEPTH ) +QMC_ALIGN (sizeof (struct qm_aeqe ) *QM_Q_DEPTH ) +QMC_ALIGN (sizeof (struct qm_sqc ) * qm->qp_num) +QMC_ALIGN (sizeof (struct qm_cqc ) * qm->qp_num);
@@ -2295,7 +2302,7 @@ static int hisi_qm_memory_init(struct hisi_qm *qm)if (!qm->qdma.va)return -ENOMEM ; -QM_INIT_BUF (qm, eqe,QM_Q_DEPTH ); +QM_INIT_BUF (qm, eqe,QM_EQ_DEPTH );QM_INIT_BUF (qm, aeqe,QM_Q_DEPTH );QM_INIT_BUF (qm, sqc, qm->qp_num);QM_INIT_BUF (qm, cqc, qm->qp_num);
@@ -2465,7 +2472,7 @@ static int qm_eq_ctx_cfg(struct hisi_qm *qm) eqc->base_h =cpu_to_le32 (upper_32_bits (qm->eqe_dma));if (qm->ver ==QM_HW_V1 ) eqc->dw3 =cpu_to_le32 (QM_EQE_AEQE_SIZE ); - eqc->dw6 =cpu_to_le32 ((QM_Q_DEPTH -1 ) | (1 <<QM_EQC_PHASE_SHIFT )); + eqc->dw6 =cpu_to_le32 ((QM_EQ_DEPTH -1 ) | (1 <<QM_EQC_PHASE_SHIFT )); ret =qm_mb (qm,QM_MB_CMD_EQC , eqc_dma,0 ,0 );dma_unmap_single (dev, eqc_dma,sizeof (struct qm_eqc ),DMA_TO_DEVICE );kfree (eqc);
Signature · 1 line
2.7.4
PATCH v5 6/10 crypto: hisilicon/qm - fix no stop reason when use 'hisi_qm_stop'
In reply to Yang ShenNow, there are three reasons of stopping: 'NORMAL', 'SOFT_RESET' and 'FLR'. In order to keep this, explicitly pass the stop reason as an input parameter of 'hisi_qm_stop' function.
--- drivers/crypto/hisilicon/hpre/hpre_main.c | 4 ++-- drivers/crypto/hisilicon/qm.c | 20 ++++++++++---------- drivers/crypto/hisilicon/qm.h | 2 +- drivers/crypto/hisilicon/sec2/sec_main.c | 4 ++-- drivers/crypto/hisilicon/zip/zip_main.c | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-)
drivers/crypto/hisilicon/hpre/hpre_main.c +2 -2
@@ -886,7 +886,7 @@ static int hpre_probe(struct pci_dev *pdev, const struct pci_device_id *id) err_with_qm_start:hisi_qm_del_from_list (qm, &hpre_devices);hpre_debugfs_exit (qm); -hisi_qm_stop (qm); +hisi_qm_stop (qm,QM_NORMAL ); err_with_err_init:hisi_qm_dev_err_uninit (qm);
@@ -918,7 +918,7 @@ static void hpre_remove(struct pci_dev *pdev) }hpre_debugfs_exit (qm); -hisi_qm_stop (qm); +hisi_qm_stop (qm,QM_NORMAL );hisi_qm_dev_err_uninit (qm);hisi_qm_uninit (qm); }
drivers/crypto/hisilicon/qm.c +10 -10
@@ -2643,18 +2643,20 @@ static void qm_clear_queues(struct hisi_qm *qm)/** * hisi_qm_stop() - Stop a qm. * @qm: The qm which will be stopped. +* @r: The reason to stop qm. * * This function stops qm and its qps, then qm can not accept request. * Related resources are not released at this state, we can use hisi_qm_start * to let qm start again. */ -int hisi_qm_stop (struct hisi_qm *qm) +int hisi_qm_stop (struct hisi_qm *qm,enum qm_stop_reason r) {struct device *dev = &qm->pdev->dev;int ret =0 ;down_write (&qm->qps_lock); + qm->status.stop_reason = r;if (!qm_avail_state (qm,QM_STOP )) { ret = -EPERM ; goto err_unlock;
@@ -3300,10 +3302,10 @@ static int qm_set_msi(struct hisi_qm *qm, bool set)return 0 ; } -static int qm_vf_reset_prepare (struct hisi_qm *qm) +static int qm_vf_reset_prepare (struct hisi_qm *qm, +enum qm_stop_reason stop_reason) {struct hisi_qm_list *qm_list = qm->qm_list; -int stop_reason = qm->status.stop_reason;struct pci_dev *pdev = qm->pdev;struct pci_dev *virtfn;struct hisi_qm *vf_qm;
@@ -3316,8 +3318,7 @@ static int qm_vf_reset_prepare(struct hisi_qm *qm)continue ;if (pci_physfn (virtfn) == pdev) { - vf_qm->status.stop_reason = stop_reason; - ret =hisi_qm_stop (vf_qm); + ret =hisi_qm_stop (vf_qm, stop_reason);if (ret) goto stop_fail; }
@@ -3356,15 +3357,14 @@ static int qm_controller_reset_prepare(struct hisi_qm *qm) }if (qm->vfs_num) { - ret =qm_vf_reset_prepare (qm); + ret =qm_vf_reset_prepare (qm,QM_SOFT_RESET );if (ret) {pci_err (pdev,"Fails to stop VFs!\n" );return ret; } } - qm->status.stop_reason =QM_SOFT_RESET ; - ret =hisi_qm_stop (qm); + ret =hisi_qm_stop (qm,QM_SOFT_RESET );if (ret) {pci_err (pdev,"Fails to stop QM!\n" );return ret;
@@ -3705,7 +3705,7 @@ void hisi_qm_reset_prepare(struct pci_dev *pdev) }if (qm->vfs_num) { - ret =qm_vf_reset_prepare (qm); + ret =qm_vf_reset_prepare (qm,QM_FLR );if (ret) {pci_err (pdev,"Failed to prepare reset, ret = %d.\n" , ret);
@@ -3713,7 +3713,7 @@ void hisi_qm_reset_prepare(struct pci_dev *pdev) } } - ret =hisi_qm_stop (qm); + ret =hisi_qm_stop (qm,QM_FLR );if (ret) {pci_err (pdev,"Failed to stop QM, ret = %d.\n" , ret);return ;
drivers/crypto/hisilicon/qm.h +1 -1
@@ -355,7 +355,7 @@ static inline void hisi_qm_del_from_list(struct hisi_qm *qm,int hisi_qm_init (struct hisi_qm *qm);void hisi_qm_uninit (struct hisi_qm *qm);int hisi_qm_start (struct hisi_qm *qm); -int hisi_qm_stop (struct hisi_qm *qm); +int hisi_qm_stop (struct hisi_qm *qm,enum qm_stop_reason r);struct hisi_qp *hisi_qm_create_qp (struct hisi_qm *qm,u8 alg_type);int hisi_qm_start_qp (struct hisi_qp *qp,unsigned long arg);int hisi_qm_stop_qp (struct hisi_qp *qp);
drivers/crypto/hisilicon/sec2/sec_main.c +2 -2
@@ -901,7 +901,7 @@ static int sec_probe(struct pci_dev *pdev, const struct pci_device_id *id) err_remove_from_list:hisi_qm_del_from_list (qm, &sec_devices);sec_debugfs_exit (qm); -hisi_qm_stop (qm); +hisi_qm_stop (qm,QM_NORMAL ); err_probe_uninit:sec_probe_uninit (qm);
@@ -926,7 +926,7 @@ static void sec_remove(struct pci_dev *pdev)sec_debugfs_exit (qm); - (void )hisi_qm_stop (qm); + (void )hisi_qm_stop (qm,QM_NORMAL );if (qm->fun_type ==QM_HW_PF )sec_debug_regs_clear (qm);
drivers/crypto/hisilicon/zip/zip_main.c +2 -2
@@ -828,7 +828,7 @@ static int hisi_zip_probe(struct pci_dev *pdev, const struct pci_device_id *id) err_remove_from_list:hisi_qm_del_from_list (qm, &zip_devices);hisi_zip_debugfs_exit (hisi_zip); -hisi_qm_stop (qm); +hisi_qm_stop (qm,QM_NORMAL ); err_qm_uninit:hisi_qm_uninit (qm);
@@ -844,7 +844,7 @@ static void hisi_zip_remove(struct pci_dev *pdev)hisi_qm_sriov_disable (pdev);hisi_zip_debugfs_exit (hisi_zip); -hisi_qm_stop (qm); +hisi_qm_stop (qm,QM_NORMAL );hisi_qm_dev_err_uninit (qm);hisi_qm_uninit (qm);
Signature · 1 line
2.7.4
PATCH v5 7/10 crypto: hisilicon/qm - fix VF not available after PF FLR
In reply to Yang ShenFrom: Shukun Tan <[email protected]>
When PF FLR, the hardware will actively trigger the VF FLR. Configuration space of VF needs to be saved and restored to ensure that it is available after the PF FLR.
--- drivers/crypto/hisilicon/qm.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/crypto/hisilicon/qm.c +6 -0
@@ -3318,6 +3318,9 @@ static int qm_vf_reset_prepare(struct hisi_qm *qm,continue ;if (pci_physfn (virtfn) == pdev) { +/* save VFs PCIE BAR configuration */ +pci_save_state (virtfn); + ret =hisi_qm_stop (vf_qm, stop_reason);if (ret) goto stop_fail;
@@ -3481,6 +3484,9 @@ static int qm_vf_reset_done(struct hisi_qm *qm)continue ;if (pci_physfn (virtfn) == pdev) { +/* enable VFs PCIE BAR configuration */ +pci_restore_state (virtfn); + ret =qm_restart (vf_qm);if (ret) goto restart_fail;
Signature · 1 line
2.7.4
PATCH v5 8/10 crypto: hisilicon/qm - register callback function to 'pci_driver.shutdown'
In reply to Yang ShenSince the drivers such as HPRE/SEC/ZIP do not implement 'pci_driver.shutdow', a RAS will be triggered at OS rebooting or shutting down as the hardware device is processing request.
The log looks like this:
NOTICE: [NimbusSecNodeType1]:[2372L]This is sec, Base = 0x141800000 NOTICE: [NimbusSecHandle]:[2319L] SecIntSt = 0x3 NOTICE: [NimbusSecHandle]:[2320L] SecQmIntStatus = 0x2 NOTICE: [PrintSecurityType]:[344L] SecurityType is RECOVERABLE!
This patch offers a new API in qm to shutdown devices, and add shutdown callbacks in ACC driver based on this new API.
So the running devices will be stopped when the OS reboot or shutdown.
--- drivers/crypto/hisilicon/hpre/hpre_main.c | 1 + drivers/crypto/hisilicon/qm.c | 17 +++++++++++++++++ drivers/crypto/hisilicon/qm.h | 1 + drivers/crypto/hisilicon/sec2/sec_main.c | 1 + drivers/crypto/hisilicon/zip/zip_main.c | 1 + 5 files changed, 21 insertions(+)
drivers/crypto/hisilicon/hpre/hpre_main.c +1 -0
@@ -939,6 +939,7 @@ static struct pci_driver hpre_pci_driver = { .sriov_configure = IS_ENABLED(CONFIG_PCI_IOV) ? hisi_qm_sriov_configure : NULL, .err_handler = &hpre_err_handler, + .shutdown = hisi_qm_dev_shutdown, };static void hpre_register_debugfs (void )
drivers/crypto/hisilicon/qm.c +17 -0
@@ -3837,6 +3837,23 @@ static int qm_irq_register(struct hisi_qm *qm)return ret; } +/** +* hisi_qm_dev_shutdown() - Shutdown device. +* @pdev: The device will be shutdown. +* +* This function will stop qm when OS shutdown or rebooting. +*/ +void hisi_qm_dev_shutdown (struct pci_dev *pdev) +{ +struct hisi_qm *qm =pci_get_drvdata (pdev); +int ret; + + ret =hisi_qm_stop (qm,QM_NORMAL ); +if (ret) +dev_err (&pdev->dev,"Fail to stop qm in shutdown!\n" ); +} +EXPORT_SYMBOL_GPL (hisi_qm_dev_shutdown); +static void hisi_qm_controller_reset (struct work_struct *rst_work) { struct hisi_qm *qm = container_of(rst_work, struct hisi_qm, rst_work);
drivers/crypto/hisilicon/qm.h +1 -0
@@ -390,4 +390,5 @@ void hisi_acc_free_sgl_pool(struct device *dev,int hisi_qm_alloc_qps_node (struct hisi_qm_list *qm_list,int qp_num,u8 alg_type,int node,struct hisi_qp **qps);void hisi_qm_free_qps (struct hisi_qp **qps,int qp_num); +void hisi_qm_dev_shutdown (struct pci_dev *pdev);#endif
drivers/crypto/hisilicon/sec2/sec_main.c +1 -0
@@ -950,6 +950,7 @@ static struct pci_driver sec_pci_driver = { .remove = sec_remove, .err_handler = &sec_err_handler, .sriov_configure = hisi_qm_sriov_configure, + .shutdown = hisi_qm_dev_shutdown, };static void sec_register_debugfs (void )
drivers/crypto/hisilicon/zip/zip_main.c +1 -0
@@ -866,6 +866,7 @@ static struct pci_driver hisi_zip_pci_driver = { .sriov_configure = IS_ENABLED(CONFIG_PCI_IOV) ? hisi_qm_sriov_configure : NULL, .err_handler = &hisi_zip_err_handler, + .shutdown = hisi_qm_dev_shutdown, };static void hisi_zip_register_debugfs (void )
Signature · 1 line
2.7.4
PATCH v5 9/10 crypto: hisilicon/qm - fix the call trace when unbind device
In reply to Yang ShenFrom: Weili Qian <[email protected]>
Call trace will appear in the Hisilicon crypto driver unbinding or disabling SRIOV during task running with TFMs on the corresponding function.
The log looks like this:
[ 293.908078] Call trace: [ 293.908080] __queue_work+0x494/0x548 [ 293.908081] queue_work_on+0x84/0xd8 [ 293.908092] qm_irq+0x4c/0xd0 [hisi_qm] [ 293.908096] __handle_irq_event_percpu+0x74/0x2a0 [ 293.908098] handle_irq_event_percpu+0x40/0x98 [ 293.908099] handle_irq_event+0x4c/0x80 [ 293.908101] handle_fasteoi_irq+0xb0/0x170 [ 293.908102] generic_handle_irq+0x3c/0x58 [ 293.908103] __handle_domain_irq+0x68/0xc0 [ 293.908104] gic_handle_irq+0xb4/0x298 [ 293.908105] el1_irq+0xcc/0x180 [ 293.908107] arch_cpu_idle+0x38/0x228 [ 293.908110] default_idle_call+0x20/0x40 [ 293.908113] do_idle+0x1cc/0x2b8 [ 293.908114] cpu_startup_entry+0x2c/0x30 [ 293.908115] rest_init+0xdc/0xe8 [ 293.908117] arch_call_rest_init+0x14/0x1c [ 293.908117] start_kernel+0x490/0x4c4
This patch adds a waiting logic as user doing the above two operations to avoid panic. The two operations will hold on in the driver remove function until the tasks release all their relative TFMs.
--- drivers/crypto/hisilicon/hpre/hpre_main.c | 3 +- drivers/crypto/hisilicon/qm.c | 95 +++++++++++++++++++++++++++++-- drivers/crypto/hisilicon/qm.h | 4 +- drivers/crypto/hisilicon/sec2/sec_main.c | 3 +- drivers/crypto/hisilicon/zip/zip_main.c | 3 +- 5 files changed, 99 insertions(+), 9 deletions(-)
drivers/crypto/hisilicon/hpre/hpre_main.c +2 -1
@@ -903,10 +903,11 @@ static void hpre_remove(struct pci_dev *pdev)struct hisi_qm *qm = &hpre->qm;int ret; +hisi_qm_wait_task_finish (qm, &hpre_devices);hpre_algs_unregister ();hisi_qm_del_from_list (qm, &hpre_devices);if (qm->fun_type ==QM_HW_PF && qm->vfs_num) { - ret =hisi_qm_sriov_disable (pdev); + ret =hisi_qm_sriov_disable (pdev, qm->is_frozen);if (ret) {pci_err (pdev,"Disable SRIOV fail!\n" );return ;
drivers/crypto/hisilicon/qm.c +90 -5
133 lines not on this page · raw message
drivers/crypto/hisilicon/qm.h +3 -1
@@ -243,6 +243,7 @@ struct hisi_qm {const char *algs;bool use_sva; +bool is_frozen;resource_size_t phys_base;resource_size_t phys_size;struct uacce_device *uacce;
@@ -367,7 +368,7 @@ int hisi_qm_debug_init(struct hisi_qm *qm);enum qm_hw_ver hisi_qm_get_hw_version (struct pci_dev *pdev);void hisi_qm_debug_regs_clear (struct hisi_qm *qm);int hisi_qm_sriov_enable (struct pci_dev *pdev,int max_vfs); -int hisi_qm_sriov_disable (struct pci_dev *pdev); +int hisi_qm_sriov_disable (struct pci_dev *pdev,bool is_frozen);int hisi_qm_sriov_configure (struct pci_dev *pdev,int num_vfs);void hisi_qm_dev_err_init (struct hisi_qm *qm);void hisi_qm_dev_err_uninit (struct hisi_qm *qm);
@@ -391,4 +392,5 @@ int hisi_qm_alloc_qps_node(struct hisi_qm_list *qm_list, int qp_num, u8 alg_type, int node, struct hisi_qp **qps);void hisi_qm_free_qps (struct hisi_qp **qps,int qp_num);void hisi_qm_dev_shutdown (struct pci_dev *pdev); +void hisi_qm_wait_task_finish (struct hisi_qm *qm,struct hisi_qm_list *qm_list);#endif
drivers/crypto/hisilicon/sec2/sec_main.c +2 -1
@@ -917,12 +917,13 @@ static void sec_remove(struct pci_dev *pdev)struct sec_dev *sec =pci_get_drvdata (pdev);struct hisi_qm *qm = &sec->qm; +hisi_qm_wait_task_finish (qm, &sec_devices);sec_unregister_from_crypto ();hisi_qm_del_from_list (qm, &sec_devices);if (qm->fun_type ==QM_HW_PF && qm->vfs_num) -hisi_qm_sriov_disable (pdev); +hisi_qm_sriov_disable (pdev, qm->is_frozen);sec_debugfs_exit (qm);
drivers/crypto/hisilicon/zip/zip_main.c +2 -1
@@ -840,8 +840,9 @@ static void hisi_zip_remove(struct pci_dev *pdev)struct hisi_zip *hisi_zip =pci_get_drvdata (pdev);struct hisi_qm *qm = &hisi_zip->qm; +hisi_qm_wait_task_finish (qm, &zip_devices);if (qm->fun_type ==QM_HW_PF && qm->vfs_num) -hisi_qm_sriov_disable (pdev); +hisi_qm_sriov_disable (pdev, qm->is_frozen);hisi_zip_debugfs_exit (hisi_zip);hisi_qm_stop (qm,QM_NORMAL );
--
2.7.4
PATCH v5 10/10 crypto: hisilicon/qm - fix the process of register algorithms to crypto
In reply to Yang ShenWhen the devices are removed or not existing, the corresponding algorithms which are registered by 'hisi-zip' driver can't be used.
Move 'hisi_zip_register_to_crypto' from 'hisi_zip_init' to 'hisi_zip_probe'. The algorithms will be registered to crypto only when there is device bind on the driver. And when the devices are removed, the algorithms will be unregistered.
In the previous process, the function 'xxx_register_to_crypto' need a lock and a static variable to judge if the registration is the first time. Move this action into the function 'hisi_qm_alg_register'. Each device will call 'hisi_qm_alg_register' to add itself to qm list in probe process and registering algs when the qm list is empty.
--- drivers/crypto/hisilicon/hpre/hpre_crypto.c | 36 ++++++-------------- drivers/crypto/hisilicon/hpre/hpre_main.c | 20 +++++------ drivers/crypto/hisilicon/qm.c | 52 +++++++++++++++++++++++++++++ drivers/crypto/hisilicon/qm.h | 20 +++-------- drivers/crypto/hisilicon/sec2/sec_crypto.c | 35 +++++++------------ drivers/crypto/hisilicon/sec2/sec_main.c | 26 +++++++-------- drivers/crypto/hisilicon/zip/zip_crypto.c | 2 +- drivers/crypto/hisilicon/zip/zip_main.c | 41 +++++++++++++---------- 8 files changed, 125 insertions(+), 107 deletions(-)
drivers/crypto/hisilicon/hpre/hpre_crypto.c +11 -25
@@ -98,9 +98,6 @@ struct hpre_asym_request {struct timespec64 req_time; }; -static DEFINE_MUTEX (hpre_alg_lock); -static unsigned int hpre_active_devs; -static int hpre_alloc_req_id (struct hpre_ctx *ctx) {unsigned long flags;
@@ -1160,36 +1157,25 @@ static struct kpp_alg dh = {int hpre_algs_register (void ) { -int ret =0 ; - -mutex_lock (&hpre_alg_lock); -if (++hpre_active_devs ==1 ) { - rsa.base.cra_flags =0 ; - ret =crypto_register_akcipher (&rsa); -if (ret) - goto unlock; +int ret; + + rsa.base.cra_flags =0 ; + ret =crypto_register_akcipher (&rsa); +if (ret) +return ret;#ifdef CONFIG_CRYPTO_DH - ret =crypto_register_kpp (&dh); -if (ret) { -crypto_unregister_akcipher (&rsa); - goto unlock; - } + ret =crypto_register_kpp (&dh); +if (ret) +crypto_unregister_akcipher (&rsa);#endif - } -unlock: -mutex_unlock (&hpre_alg_lock);return ret; }void hpre_algs_unregister (void ) { -mutex_lock (&hpre_alg_lock); -if (--hpre_active_devs ==0 ) { -crypto_unregister_akcipher (&rsa); +crypto_unregister_akcipher (&rsa);#ifdef CONFIG_CRYPTO_DH -crypto_unregister_kpp (&dh); +crypto_unregister_kpp (&dh);#endif - } -mutex_unlock (&hpre_alg_lock); }
drivers/crypto/hisilicon/hpre/hpre_main.c +10 -10
@@ -90,7 +90,6 @@#define HPRE_SQE_MASK_OFFSET 8#define HPRE_SQE_MASK_LEN 24 -static struct hisi_qm_list hpre_devices;static const char hpre_name[] ="hisi_hpre" ;static struct dentry *hpre_debugfs_root;static const struct pci_device_id hpre_dev_ids[] = {
@@ -106,6 +105,11 @@ struct hpre_hw_error {const char *msg; }; +static struct hisi_qm_list hpre_devices = { + .register_to_crypto = hpre_algs_register, + .unregister_from_crypto = hpre_algs_unregister, +}; +static const char *const hpre_debug_file_name[] = { [HPRE_CURRENT_QM ] ="current_qm" , [HPRE_CLEAR_ENABLE ] ="rdclr_en" ,
@@ -864,9 +868,7 @@ static int hpre_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (ret)dev_warn (&pdev->dev,"init debugfs fail!\n" ); -hisi_qm_add_to_list (qm, &hpre_devices); - - ret =hpre_algs_register (); + ret =hisi_qm_alg_register (qm, &hpre_devices);if (ret <0 ) {pci_err (pdev,"fail to register algs to crypto!\n" ); goto err_with_qm_start;
@@ -875,16 +877,15 @@ static int hpre_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (qm->fun_type ==QM_HW_PF && vfs_num) { ret =hisi_qm_sriov_enable (pdev, vfs_num);if (ret <0 ) - goto err_with_crypto_register; + goto err_with_alg_register; }return 0 ; -err_with_crypto_register: -hpre_algs_unregister (); +err_with_alg_register: +hisi_qm_alg_unregister (qm, &hpre_devices); err_with_qm_start: -hisi_qm_del_from_list (qm, &hpre_devices);hpre_debugfs_exit (qm);hisi_qm_stop (qm,QM_NORMAL );
@@ -904,8 +905,7 @@ static void hpre_remove(struct pci_dev *pdev)int ret;hisi_qm_wait_task_finish (qm, &hpre_devices); -hpre_algs_unregister (); -hisi_qm_del_from_list (qm, &hpre_devices); +hisi_qm_alg_unregister (qm, &hpre_devices);if (qm->fun_type ==QM_HW_PF && qm->vfs_num) { ret =hisi_qm_sriov_disable (pdev, qm->is_frozen);if (ret) {
drivers/crypto/hisilicon/qm.c +52 -0
58 lines not on this page · raw message
drivers/crypto/hisilicon/qm.h +4 -16
@@ -193,6 +193,8 @@ struct hisi_qm_err_ini {struct hisi_qm_list {struct mutex lock;struct list_head list; +int (*register_to_crypto)(void ); +void (*unregister_from_crypto)(void ); };struct hisi_qm {
@@ -337,22 +339,6 @@ static inline void hisi_qm_init_list(struct hisi_qm_list *qm_list)mutex_init (&qm_list->lock); } -static inline void hisi_qm_add_to_list (struct hisi_qm *qm, -struct hisi_qm_list *qm_list) -{ -mutex_lock (&qm_list->lock); -list_add_tail (&qm->list, &qm_list->list); -mutex_unlock (&qm_list->lock); -} - -static inline void hisi_qm_del_from_list (struct hisi_qm *qm, -struct hisi_qm_list *qm_list) -{ -mutex_lock (&qm_list->lock); -list_del (&qm->list); -mutex_unlock (&qm_list->lock); -} -int hisi_qm_init (struct hisi_qm *qm);void hisi_qm_uninit (struct hisi_qm *qm);int hisi_qm_start (struct hisi_qm *qm);
@@ -393,4 +379,6 @@ int hisi_qm_alloc_qps_node(struct hisi_qm_list *qm_list, int qp_num,void hisi_qm_free_qps (struct hisi_qp **qps,int qp_num);void hisi_qm_dev_shutdown (struct pci_dev *pdev);void hisi_qm_wait_task_finish (struct hisi_qm *qm,struct hisi_qm_list *qm_list); +int hisi_qm_alg_register (struct hisi_qm *qm,struct hisi_qm_list *qm_list); +void hisi_qm_alg_unregister (struct hisi_qm *qm,struct hisi_qm_list *qm_list);#endif
drivers/crypto/hisilicon/sec2/sec_crypto.c +12 -23
@@ -66,8 +66,6 @@#define SEC_SQE_AEAD_FLAG 3#define SEC_SQE_DONE 0x1 -static atomic_t sec_active_devs; -/* Get an en/de-cipher queue cyclically to balance load over queues of TFM */ static inline int sec_alloc_queue_id (struct sec_ctx *ctx,struct sec_req *req) {
@@ -1633,33 +1631,24 @@ static struct aead_alg sec_aeads[] = {int sec_register_to_crypto (void ) { -int ret =0 ; +int ret;/* To avoid repeat register */ -if (atomic_add_return (1 , &sec_active_devs) ==1 ) { - ret =crypto_register_skciphers (sec_skciphers, -ARRAY_SIZE (sec_skciphers)); -if (ret) -return ret; - - ret =crypto_register_aeads (sec_aeads,ARRAY_SIZE (sec_aeads)); -if (ret) - goto reg_aead_fail; - } - -return ret; - -reg_aead_fail: -crypto_unregister_skciphers (sec_skciphers,ARRAY_SIZE (sec_skciphers)); + ret =crypto_register_skciphers (sec_skciphers, +ARRAY_SIZE (sec_skciphers)); +if (ret) +return ret; + ret =crypto_register_aeads (sec_aeads,ARRAY_SIZE (sec_aeads)); +if (ret) +crypto_unregister_skciphers (sec_skciphers, +ARRAY_SIZE (sec_skciphers));return ret; }void sec_unregister_from_crypto (void ) { -if (atomic_sub_return (1 , &sec_active_devs) ==0 ) { -crypto_unregister_skciphers (sec_skciphers, -ARRAY_SIZE (sec_skciphers)); -crypto_unregister_aeads (sec_aeads,ARRAY_SIZE (sec_aeads)); - } +crypto_unregister_skciphers (sec_skciphers, +ARRAY_SIZE (sec_skciphers)); +crypto_unregister_aeads (sec_aeads,ARRAY_SIZE (sec_aeads)); }
drivers/crypto/hisilicon/sec2/sec_main.c +12 -14
@@ -99,7 +99,11 @@ struct sec_dfx_item {static const char sec_name[] ="hisi_sec2" ;static struct dentry *sec_debugfs_root; -static struct hisi_qm_list sec_devices; + +static struct hisi_qm_list sec_devices = { + .register_to_crypto = sec_register_to_crypto, + .unregister_from_crypto = sec_unregister_from_crypto, +};static const struct sec_hw_error sec_hw_errors[] = { {.int_msk =BIT (0 ), .msg ="sec_axi_rresp_err_rint" },
@@ -879,27 +883,24 @@ static int sec_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (ret)pci_warn (pdev,"Failed to init debugfs!\n" ); -hisi_qm_add_to_list (qm, &sec_devices); - - ret =sec_register_to_crypto (); + ret =hisi_qm_alg_register (qm, &sec_devices);if (ret <0 ) {pr_err ("Failed to register driver to crypto.\n" ); - goto err_remove_from_list; + goto err_qm_stop; }if (qm->fun_type ==QM_HW_PF && vfs_num) { ret =hisi_qm_sriov_enable (pdev, vfs_num);if (ret <0 ) - goto err_crypto_unregister; + goto err_alg_unregister; }return 0 ; -err_crypto_unregister: -sec_unregister_from_crypto (); +err_alg_unregister: +hisi_qm_alg_unregister (qm, &sec_devices); -err_remove_from_list: -hisi_qm_del_from_list (qm, &sec_devices); +err_qm_stop:sec_debugfs_exit (qm);hisi_qm_stop (qm,QM_NORMAL );
@@ -918,10 +919,7 @@ static void sec_remove(struct pci_dev *pdev)struct hisi_qm *qm = &sec->qm;hisi_qm_wait_task_finish (qm, &sec_devices); -sec_unregister_from_crypto (); - -hisi_qm_del_from_list (qm, &sec_devices); - +hisi_qm_alg_unregister (qm, &sec_devices);if (qm->fun_type ==QM_HW_PF && qm->vfs_num)hisi_qm_sriov_disable (pdev, qm->is_frozen);
drivers/crypto/hisilicon/zip/zip_crypto.c +1 -1
@@ -611,7 +611,7 @@ static struct acomp_alg hisi_zip_acomp_gzip = {int hisi_zip_register_to_crypto (void ) { -int ret =0 ; +int ret; ret =crypto_register_acomp (&hisi_zip_acomp_zlib);if (ret) {
drivers/crypto/hisilicon/zip/zip_main.c +23 -18
106 lines not on this page · raw message
Signature · 1 line
2.7.4
Herbert Xu
maintainerQuoted 49 lines · Yang Shen
This patchset fix some qm bugs:
patch 1: store the string address before pass to 'strsep' patch 2: clear 'qp_status->used' when init the 'qp'
patch 3: use 'dev_info_ratelimited' to avoid printk flooding. patch 4: fix the judgement of queue is full
patch 7: save the vf configuration space to make sure it is available
after the 'PF' 'FLR'
patch 8: register callback to 'pci_driver.shutdown'
patch 9: wait for all working function finishs when remove the device patch 10: move the process of register alg to crypto in driver 'hisi_zip'v5:
- add a error branch instead of return immediately in patch "fix wrong release after using strsep"v4:
- exchange the patch 'fix the call trace when unbind device' and 'fix the process of register algorithms to crypto' to make sure the driver is stable.v3:
- add the patch 10 which is aimed to fix the call trace when remove a working devicev2:
- fix the wrong email address on patch 1Hui Tang (1):
crypto: hisilicon/qm - fix judgement of queue is fullShukun Tan (3):
crypto: hisilicon/qm - clear used reference count when start qp
crypto: hisilicon/qm - fix event queue depth to 2048
crypto: hisilicon/qm - fix VF not available after PF FLRSihang Chen (1):
crypto: hisilicon/qm - fix wrong release after using strsepWeili Qian (1):
crypto: hisilicon/qm - fix the call trace when unbind deviceYang Shen (4):
crypto: hisilicon/qm - fix print frequence inhisi_qp_send
crypto: hisilicon/qm - fix no stop reason when use 'hisi_qm_stop'
crypto: hisilicon/qm - register callback function to
'pci_driver.shutdown'
crypto: hisilicon/qm - fix the process of register algorithms to
crypto
Quoted 9 lines
drivers/crypto/hisilicon/hpre/hpre_crypto.c | 36 ++--- drivers/crypto/hisilicon/hpre/hpre_main.c | 28 ++-- drivers/crypto/hisilicon/qm.c | 224 ++++++++++++++++++++++++---- drivers/crypto/hisilicon/qm.h | 27 ++-- drivers/crypto/hisilicon/sec2/sec_crypto.c | 35 ++--- drivers/crypto/hisilicon/sec2/sec_main.c | 34 ++--- drivers/crypto/hisilicon/zip/zip_crypto.c | 2 +- drivers/crypto/hisilicon/zip/zip_main.c | 49 +++--- 8 files changed, 290 insertions(+), 145 deletions(-)
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt