CAAM bugfixes, small improvements
v2 cover CAAM bugfixes, small improvements
Everyone:
This series contains bugfixes and small improvement I made while doing more testing of CAAM code.
Changes since [v1]:
- Rebased on latest cryptodev/master, series limited to just devres changes
- Minor code style changes as per feedback
[v1] lore.kernel.org/lkml/[email protected]
Andrey Smirnov (6):
crypto: caam - use devres to unmap memory
crypto: caam - use devres to remove debugfs
crypto: caam - use devres to de-initialize the RNG
crypto: caam - use devres to de-initialize QI
crypto: caam - use devres to populate platform devices
crypto: caam - populate platform devices last
drivers/crypto/caam/ctrl.c | 222 ++++++++++++++++------------------- drivers/crypto/caam/intern.h | 4 - drivers/crypto/caam/qi.c | 8 +- drivers/crypto/caam/qi.h | 1 - 4 files changed, 104 insertions(+), 131 deletions(-)
Signature · 1 line
2.21.0
PATCH v2 1/6 crypto: caam - use devres to unmap memory
Use devres to unmap memory and drop corresponding iounmap() call.
--- drivers/crypto/caam/ctrl.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-)
drivers/crypto/caam/ctrl.c +9 -19
@@ -308,11 +308,9 @@ static int caam_remove(struct platform_device *pdev) {struct device *ctrldev;struct caam_drv_private *ctrlpriv; -struct caam_ctrl __iomem *ctrl; ctrldev = &pdev->dev; ctrlpriv =dev_get_drvdata (ctrldev); - ctrl = (struct caam_ctrl __iomem *)ctrlpriv->ctrl;/* Remove platform devices under the crypto node */ of_platform_depopulate (ctrldev);
@@ -334,9 +332,6 @@ static int caam_remove(struct platform_device *pdev)debugfs_remove_recursive (ctrlpriv->dfs_root);#endif -/* Unmap controller region */ -iounmap (ctrl); -return 0 ; }
@@ -611,10 +606,11 @@ static int caam_probe(struct platform_device *pdev)/* Get configuration properties from device tree */ /* First, get register page */ - ctrl =of_iomap (nprop,0 ); -if (!ctrl) { + ctrl =devm_of_iomap (dev, nprop,0 ,NULL ); + ret =PTR_ERR_OR_ZERO (ctrl); +if (ret) {dev_err (dev,"caam: of_iomap() failed\n" ); -return -ENOMEM ; +return ret; } caam_little_end = !(bool)(rd_reg32(&ctrl->perfmon.status) &
@@ -632,22 +628,18 @@ static int caam_probe(struct platform_device *pdev)if (ctrlpriv->qi_present && !caam_dpaa2) { ret =qman_is_probed ();if (!ret) { - ret = -EPROBE_DEFER ; - goto iounmap_ctrl; +return -EPROBE_DEFER ; }else if (ret <0 ) {dev_err (dev,"failing probe due to qman probe error\n" ); - ret = -ENODEV ; - goto iounmap_ctrl; +return -ENODEV ; } ret =qman_portals_probed ();if (!ret) { - ret = -EPROBE_DEFER ; - goto iounmap_ctrl; +return -EPROBE_DEFER ; }else if (ret <0 ) {dev_err (dev,"failing probe due to qman portals probe error\n" ); - ret = -ENODEV ; - goto iounmap_ctrl; +return -ENODEV ; } }#endif
@@ -722,7 +714,7 @@ static int caam_probe(struct platform_device *pdev) ret =dma_set_mask_and_coherent (dev,caam_get_dma_mask (dev));if (ret) {dev_err (dev,"dma_set_mask_and_coherent failed (%d)\n" , ret); - goto iounmap_ctrl; +return ret; } ctrlpriv->era =caam_get_era (ctrl);
@@ -927,8 +919,6 @@ static int caam_probe(struct platform_device *pdev)if (ctrlpriv->qi_init)caam_qi_shutdown (dev);#endif -iounmap_ctrl: -iounmap (ctrl);return ret; }
Signature · 1 line
2.21.0
PATCH v2 2/6 crypto: caam - use devres to remove debugfs
In reply to Andrey SmirnovUse devres to remove debugfs and drop corresponding debugfs_remove_recursive() call.
--- drivers/crypto/caam/ctrl.c | 21 ++++++++++++++------- drivers/crypto/caam/intern.h | 1 - 2 files changed, 14 insertions(+), 8 deletions(-)
drivers/crypto/caam/ctrl.c +14 -7
@@ -327,11 +327,6 @@ static int caam_remove(struct platform_device *pdev)if (!ctrlpriv->mc_en && ctrlpriv->rng4_sh_init)deinstantiate_rng (ctrldev, ctrlpriv->rng4_sh_init); -/* Shut down debug views */ -#ifdef CONFIG_DEBUG_FS -debugfs_remove_recursive (ctrlpriv->dfs_root); -#endif -return 0 ; }
@@ -563,6 +558,13 @@ static int init_clocks(struct device *dev, const struct caam_imx_data *data)return devm_add_action_or_reset (dev, disable_clocks, ctrlpriv); } +#ifdef CONFIG_DEBUG_FS +static void caam_remove_debugfs (void *root) +{ +debugfs_remove_recursive (root); +} +#endif +/* Probe routine for CAAM top (controller) level */ static int caam_probe (struct platform_device *pdev) {
@@ -575,6 +577,7 @@ static int caam_probe(struct platform_device *pdev)struct caam_drv_private *ctrlpriv;#ifdef CONFIG_DEBUG_FS struct caam_perfmon *perfmon; +struct dentry *dfs_root;#endif u32 scfgr, comp_params;u8 rng_vid;
@@ -728,8 +731,12 @@ static int caam_probe(struct platform_device *pdev)*/ perfmon = (struct caam_perfmon __force *)&ctrl->perfmon; - ctrlpriv->dfs_root =debugfs_create_dir (dev_name (dev),NULL ); - ctrlpriv->ctl =debugfs_create_dir ("ctl" , ctrlpriv->dfs_root); + dfs_root =debugfs_create_dir (dev_name (dev),NULL ); + ret =devm_add_action_or_reset (dev, caam_remove_debugfs, dfs_root); +if (ret) +return ret; + + ctrlpriv->ctl =debugfs_create_dir ("ctl" , dfs_root);#endif /* Check to see if (DPAA 1.x) QI present. If so, enable */
drivers/crypto/caam/intern.h +0 -1
@@ -102,7 +102,6 @@ struct caam_drv_private {* variables at runtime. */ #ifdef CONFIG_DEBUG_FS -struct dentry *dfs_root;struct dentry *ctl;/* controller dir */ struct debugfs_blob_wrapper ctl_kek_wrap, ctl_tkek_wrap, ctl_tdsk_wrap;#endif
Signature · 1 line
2.21.0
PATCH v2 3/6 crypto: caam - use devres to de-initialize the RNG
In reply to Andrey SmirnovUse devres to de-initialize the RNG and drop explicit de-initialization code in caam_remove().
--- drivers/crypto/caam/ctrl.c | 130 ++++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 60 deletions(-)
drivers/crypto/caam/ctrl.c +70 -60
@@ -175,6 +175,73 @@ static inline int run_descriptor_deco0(struct device *ctrldev, u32 *desc,return 0 ; } +/* +* deinstantiate_rng - builds and executes a descriptor on DECO0, +* which deinitializes the RNG block. +* @ctrldev - pointer to device +* @state_handle_mask - bitmask containing the instantiation status +* for the RNG4 state handles which exist in +* the RNG4 block: 1 if it's been instantiated +* +* Return: - 0 if no error occurred +* - -ENOMEM if there isn't enough memory to allocate the descriptor +* - -ENODEV if DECO0 couldn't be acquired +* - -EAGAIN if an error occurred when executing the descriptor +*/ +static int deinstantiate_rng (struct device *ctrldev,int state_handle_mask) +{ +u32 *desc, status; +int sh_idx, ret =0 ; + + desc =kmalloc (CAAM_CMD_SZ *3 ,GFP_KERNEL ); +if (!desc) +return -ENOMEM ; + +for (sh_idx =0 ; sh_idx <RNG4_MAX_HANDLES ; sh_idx++) { +/* +* If the corresponding bit is set, then it means the state +* handle was initialized by us, and thus it needs to be +* deinitialized as well +*/ +if ((1 << sh_idx) & state_handle_mask) { +/* +* Create the descriptor for deinstantating this state +* handle +*/ +build_deinstantiation_desc (desc, sh_idx); + +/* Try to run it through DECO0 */ + ret =run_descriptor_deco0 (ctrldev, desc, &status); + +if (ret || + (status && status !=JRSTA_SSRC_JUMP_HALT_CC )) { +dev_err (ctrldev, +"Failed to deinstantiate RNG4 SH%d\n" , + sh_idx); +break ; + } +dev_info (ctrldev,"Deinstantiated RNG4 SH%d\n" , sh_idx); + } + } + +kfree (desc); + +return ret; +} + +static void devm_deinstantiate_rng (void *data) +{ +struct device *ctrldev = data; +struct caam_drv_private *ctrlpriv =dev_get_drvdata (ctrldev); + +/* +* De-initialize RNG state handles initialized by this driver. +* In case of SoCs with Management Complex, RNG is managed by MC f/w. +*/ +if (ctrlpriv->rng4_sh_init) +deinstantiate_rng (ctrldev, ctrlpriv->rng4_sh_init); +} +/* * instantiate_rng - builds and executes a descriptor on DECO0, * which initializes the RNG block.
@@ -247,59 +314,9 @@ static int instantiate_rng(struct device *ctrldev, int state_handle_mask,kfree (desc); -return ret; -} - -/* -* deinstantiate_rng - builds and executes a descriptor on DECO0, -* which deinitializes the RNG block. -* @ctrldev - pointer to device -* @state_handle_mask - bitmask containing the instantiation status -* for the RNG4 state handles which exist in -* the RNG4 block: 1 if it's been instantiated -* -* Return: - 0 if no error occurred -* - -ENOMEM if there isn't enough memory to allocate the descriptor -* - -ENODEV if DECO0 couldn't be acquired -* - -EAGAIN if an error occurred when executing the descriptor -*/ -static int deinstantiate_rng (struct device *ctrldev,int state_handle_mask) -{ -u32 *desc, status; -int sh_idx, ret =0 ; - - desc =kmalloc (CAAM_CMD_SZ *3 ,GFP_KERNEL ); -if (!desc) -return -ENOMEM ; - -for (sh_idx =0 ; sh_idx <RNG4_MAX_HANDLES ; sh_idx++) { -/* -* If the corresponding bit is set, then it means the state -* handle was initialized by us, and thus it needs to be -* deinitialized as well -*/ -if ((1 << sh_idx) & state_handle_mask) { -/* -* Create the descriptor for deinstantating this state -* handle -*/ -build_deinstantiation_desc (desc, sh_idx); - -/* Try to run it through DECO0 */ - ret =run_descriptor_deco0 (ctrldev, desc, &status); - -if (ret || - (status && status !=JRSTA_SSRC_JUMP_HALT_CC )) { -dev_err (ctrldev, -"Failed to deinstantiate RNG4 SH%d\n" , - sh_idx); -break ; - } -dev_info (ctrldev,"Deinstantiated RNG4 SH%d\n" , sh_idx); - } - } - -kfree (desc); +if (!ret) + ret =devm_add_action_or_reset (ctrldev, devm_deinstantiate_rng, + ctrldev);return ret; }
@@ -320,13 +337,6 @@ static int caam_remove(struct platform_device *pdev)caam_qi_shutdown (ctrldev);#endif -/* -* De-initialize RNG state handles initialized by this driver. -* In case of SoCs with Management Complex, RNG is managed by MC f/w. -*/ -if (!ctrlpriv->mc_en && ctrlpriv->rng4_sh_init) -deinstantiate_rng (ctrldev, ctrlpriv->rng4_sh_init); -return 0 ; }
Signature · 1 line
2.21.0
Re: [PATCH v2 3/6] crypto: caam - use devres to de-initialize the RNG
Quoted 11 lines · Andrey Smirnov
Use devres to de-initialize the RNG and drop explicit de-initialization code in
caam_remove().Signed-off-by Andrey Smirnov <[email protected]>Cc Chris Healy <[email protected]>Cc Lucas Stach <[email protected]>Cc Horia Geantă <[email protected]>Cc Herbert Xu <[email protected]>Cc Iuliana Prodan <[email protected]>
Thanks,
Horia
PATCH v2 4/6 crypto: caam - use devres to de-initialize QI
In reply to Andrey SmirnovUse devres to de-initialize the QI and drop explicit de-initialization code in caam_remove().
--- drivers/crypto/caam/ctrl.c | 14 +------------- drivers/crypto/caam/intern.h | 3 --- drivers/crypto/caam/qi.c | 8 ++++++-- drivers/crypto/caam/qi.h | 1 - 4 files changed, 7 insertions(+), 19 deletions(-)
drivers/crypto/caam/ctrl.c +1 -13
@@ -332,11 +332,6 @@ static int caam_remove(struct platform_device *pdev)/* Remove platform devices under the crypto node */ of_platform_depopulate (ctrldev); -#ifdef CONFIG_CAAM_QI -if (ctrlpriv->qi_init) -caam_qi_shutdown (ctrldev); -#endif -return 0 ; }
@@ -769,7 +764,7 @@ static int caam_probe(struct platform_device *pdev) ret =of_platform_populate (nprop, caam_match,NULL , dev);if (ret) {dev_err (dev,"JR platform devices creation error\n" ); - goto shutdown_qi; +return ret; } ring =0 ;
@@ -930,13 +925,6 @@ static int caam_probe(struct platform_device *pdev) caam_remove:caam_remove (pdev);return ret; - -shutdown_qi: -#ifdef CONFIG_CAAM_QI -if (ctrlpriv->qi_init) -caam_qi_shutdown (dev); -#endif -return ret; }static struct platform_driver caam_driver = {
drivers/crypto/caam/intern.h +0 -3
@@ -81,9 +81,6 @@ struct caam_drv_private {*/ u8 total_jobrs;/* Total Job Rings in device */ u8 qi_present;/* Nonzero if QI present in device */ -#ifdef CONFIG_CAAM_QI -u8 qi_init;/* Nonzero if QI has been initialized */ -#endif u8 mc_en;/* Nonzero if MC f/w is active */ int secvio_irq;/* Security violation interrupt number */ int virt_en;/* Virtualization enabled in CAAM */
drivers/crypto/caam/qi.c +6 -2
@@ -500,9 +500,10 @@ void caam_drv_ctx_rel(struct caam_drv_ctx *drv_ctx) }EXPORT_SYMBOL (caam_drv_ctx_rel); -void caam_qi_shutdown (struct device *qidev) +static void caam_qi_shutdown (void *data) {int i; +struct device *qidev = data;struct caam_qi_priv *priv = &qipriv;const cpumask_t *cpus =qman_affine_cpus ();
@@ -761,7 +762,10 @@ int caam_qi_init(struct platform_device *caam_pdev) ×_congested, &caam_fops_u64_ro);#endif - ctrlpriv->qi_init =1 ; + err =devm_add_action_or_reset (qidev, caam_qi_shutdown, ctrlpriv); +if (err) +return err; +dev_info (qidev,"Linux CAAM Queue I/F driver initialised\n" );return 0 ; }
drivers/crypto/caam/qi.h +0 -1
@@ -147,7 +147,6 @@ int caam_drv_ctx_update(struct caam_drv_ctx *drv_ctx, u32 *sh_desc);void caam_drv_ctx_rel (struct caam_drv_ctx *drv_ctx);int caam_qi_init (struct platform_device *pdev); -void caam_qi_shutdown (struct device *dev);/** * qi_cache_alloc - Allocate buffers from CAAM-QI cache
Signature · 1 line
2.21.0
PATCH v2 5/6 crypto: caam - use devres to populate platform devices
In reply to Andrey SmirnovUse devres to de-initialize the RNG and drop explicit de-initialization code in caam_remove().
--- drivers/crypto/caam/ctrl.c | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-)
drivers/crypto/caam/ctrl.c +3 -23
@@ -321,20 +321,6 @@ static int instantiate_rng(struct device *ctrldev, int state_handle_mask,return ret; } -static int caam_remove (struct platform_device *pdev) -{ -struct device *ctrldev; -struct caam_drv_private *ctrlpriv; - - ctrldev = &pdev->dev; - ctrlpriv =dev_get_drvdata (ctrldev); - -/* Remove platform devices under the crypto node */ -of_platform_depopulate (ctrldev); - -return 0 ; -} -/* * kick_trng - sets the various parameters for enabling the initialization * of the RNG4 block in CAAM
@@ -761,7 +747,7 @@ static int caam_probe(struct platform_device *pdev)#endif } - ret =of_platform_populate (nprop, caam_match,NULL , dev); + ret =devm_of_platform_populate (dev);if (ret) {dev_err (dev,"JR platform devices creation error\n" );return ret;
@@ -783,8 +769,7 @@ static int caam_probe(struct platform_device *pdev)/* If no QI and no rings specified, quit and go home */ if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) {dev_err (dev,"no queues configured, terminating\n" ); - ret = -ENOMEM ; - goto caam_remove; +return -ENOMEM ; }if (ctrlpriv->era <10 )
@@ -847,7 +832,7 @@ static int caam_probe(struct platform_device *pdev) }while ((ret == -EAGAIN ) && (ent_delay <RTSDCTL_ENT_DLY_MAX ));if (ret) {dev_err (dev,"failed to instantiate RNG" ); - goto caam_remove; +return ret; }/* * Set handles init'ed by this module as the complement of the
@@ -921,10 +906,6 @@ static int caam_probe(struct platform_device *pdev) &ctrlpriv->ctl_tdsk_wrap);#endif return 0 ; - -caam_remove: -caam_remove (pdev); -return ret; }static struct platform_driver caam_driver = {
@@ -933,7 +914,6 @@ static struct platform_driver caam_driver = { .of_match_table = caam_match, }, .probe = caam_probe, - .remove = caam_remove, };module_platform_driver (caam_driver);
Signature · 1 line
2.21.0
PATCH v2 6/6 crypto: caam - populate platform devices last
In reply to Andrey SmirnovMove the call to devm_of_platform_populate() at the end of caam_probe(), so we won't try to add any child devices until all of the initialization is finished successfully.
--- drivers/crypto/caam/ctrl.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/crypto/caam/ctrl.c +6 -7
@@ -747,12 +747,6 @@ static int caam_probe(struct platform_device *pdev)#endif } - ret =devm_of_platform_populate (dev); -if (ret) { -dev_err (dev,"JR platform devices creation error\n" ); -return ret; - } - ring =0 ;for_each_available_child_of_node (nprop, np) if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") ||
@@ -905,7 +899,12 @@ static int caam_probe(struct platform_device *pdev)debugfs_create_blob ("tdsk" ,S_IRUSR |S_IRGRP |S_IROTH , ctrlpriv->ctl, &ctrlpriv->ctl_tdsk_wrap);#endif -return 0 ; + + ret =devm_of_platform_populate (dev); +if (ret) +dev_err (dev,"JR platform devices creation error\n" ); + +return ret; }static struct platform_driver caam_driver = {
Signature · 1 line
2.21.0
Re: [PATCH v2 6/6] crypto: caam - populate platform devices last
Quoted 4 lines · Andrey Smirnov
Move the call to
devm_of_platform_populate()at the end ofcaam_probe(), so we won't try to add any child devices until all of the initialization is finished successfully.
Quoted 8 lines
Signed-off-by Andrey Smirnov <[email protected]>Cc Chris Healy <[email protected]>Cc Lucas Stach <[email protected]>Cc Horia Geantă <[email protected]>Cc Herbert Xu <[email protected]>Cc Iuliana Prodan <[email protected]>
Thanks,
Horia
Herbert Xu
maintainerQuoted 22 lines · Andrey Smirnov
Everyone:
This series contains bugfixes and small improvement I made while doing more testing of CAAM code.
Changes since [v1]:
- Rebased on latest cryptodev/master, series limited to just devres changes
- Minor code style changes as per feedback
[v1] lore.kernel.org/lkml/[email protected]
Andrey Smirnov (6):
crypto: caam - use devres to unmap memory
crypto: caam - use devres to remove debugfs
crypto: caam - use devres to de-initialize the RNG
crypto: caam - use devres to de-initialize QI
crypto: caam - use devres to populate platform devices
crypto: caam - populate platform devices last
Quoted 5 lines
drivers/crypto/caam/ctrl.c | 222 ++++++++++++++++------------------- drivers/crypto/caam/intern.h | 4 - drivers/crypto/caam/qi.c | 8 +- drivers/crypto/caam/qi.h | 1 - 4 files changed, 104 insertions(+), 131 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