Skip to content

Commit 1b46c90

Browse files
horiagherbertx
authored andcommitted
crypto: caam - convert top level drivers to libraries
Currently we allow top level code, i.e. that which sits between the low level (HW-specific) drivers and crypto API, to be built as several drivers: caamalg, caamhash, caam_pkc, caamrng, caamalg_qi. There is no advantage in this, more it interferes with adding support for deferred probing (there are no corresponding devices and thus no bus). Convert these drivers and call init() / exit() manually at the right time. Move algorithms initialization at JR probe / remove time: -the first probed JR registers the crypto algs -the last removed JR unregisters the crypto algs Note: caam_qi_init() is called before JR platform devices creation (of_populate_bus()), such that QI interface is initialized when the caam/qi algorithms are registered in the JR driver (by calling caam_qi_algapi_init(). While here, fix the Kconfig entries under CRYPTO_DEV_FSL_CAAM_JR to be aligned. Signed-off-by: Horia Geantă <horia.geanta@nxp.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent a5e5c13 commit 1b46c90

10 files changed

Lines changed: 208 additions & 277 deletions

File tree

‎drivers/crypto/caam/Kconfig‎

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
config CRYPTO_DEV_FSL_CAAM_COMMON
33
tristate
44

5+
config CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC
6+
tristate
7+
8+
config CRYPTO_DEV_FSL_CAAM_AHASH_API_DESC
9+
tristate
10+
511
config CRYPTO_DEV_FSL_CAAM
612
tristate "Freescale CAAM-Multicore platform driver backend"
713
depends on FSL_SOC || ARCH_MXC || ARCH_LAYERSCAPE
@@ -25,7 +31,7 @@ config CRYPTO_DEV_FSL_CAAM_DEBUG
2531
Selecting this will enable printing of various debug
2632
information in the CAAM driver.
2733

28-
config CRYPTO_DEV_FSL_CAAM_JR
34+
menuconfig CRYPTO_DEV_FSL_CAAM_JR
2935
tristate "Freescale CAAM Job Ring driver backend"
3036
default y
3137
help
@@ -86,8 +92,9 @@ config CRYPTO_DEV_FSL_CAAM_INTC_TIME_THLD
8692
threshold. Range is 1-65535.
8793

8894
config CRYPTO_DEV_FSL_CAAM_CRYPTO_API
89-
tristate "Register algorithm implementations with the Crypto API"
95+
bool "Register algorithm implementations with the Crypto API"
9096
default y
97+
select CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC
9198
select CRYPTO_AEAD
9299
select CRYPTO_AUTHENC
93100
select CRYPTO_BLKCIPHER
@@ -97,13 +104,11 @@ config CRYPTO_DEV_FSL_CAAM_CRYPTO_API
97104
scatterlist crypto API (such as the linux native IPSec
98105
stack) to the SEC4 via job ring.
99106

100-
To compile this as a module, choose M here: the module
101-
will be called caamalg.
102-
103107
config CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI
104-
tristate "Queue Interface as Crypto API backend"
108+
bool "Queue Interface as Crypto API backend"
105109
depends on FSL_DPAA && NET
106110
default y
111+
select CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC
107112
select CRYPTO_AUTHENC
108113
select CRYPTO_BLKCIPHER
109114
help
@@ -114,43 +119,33 @@ config CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI
114119
assigned to the kernel should also be more than the number of
115120
job rings.
116121

117-
To compile this as a module, choose M here: the module
118-
will be called caamalg_qi.
119-
120122
config CRYPTO_DEV_FSL_CAAM_AHASH_API
121-
tristate "Register hash algorithm implementations with Crypto API"
123+
bool "Register hash algorithm implementations with Crypto API"
122124
default y
125+
select CRYPTO_DEV_FSL_CAAM_AHASH_API_DESC
123126
select CRYPTO_HASH
124127
help
125128
Selecting this will offload ahash for users of the
126129
scatterlist crypto API to the SEC4 via job ring.
127130

128-
To compile this as a module, choose M here: the module
129-
will be called caamhash.
130-
131131
config CRYPTO_DEV_FSL_CAAM_PKC_API
132-
tristate "Register public key cryptography implementations with Crypto API"
132+
bool "Register public key cryptography implementations with Crypto API"
133133
default y
134134
select CRYPTO_RSA
135135
help
136136
Selecting this will allow SEC Public key support for RSA.
137137
Supported cryptographic primitives: encryption, decryption,
138138
signature and verification.
139-
To compile this as a module, choose M here: the module
140-
will be called caam_pkc.
141139

142140
config CRYPTO_DEV_FSL_CAAM_RNG_API
143-
tristate "Register caam device for hwrng API"
141+
bool "Register caam device for hwrng API"
144142
default y
145143
select CRYPTO_RNG
146144
select HW_RANDOM
147145
help
148146
Selecting this will register the SEC4 hardware rng to
149147
the hw_random API for suppying the kernel entropy pool.
150148

151-
To compile this as a module, choose M here: the module
152-
will be called caamrng.
153-
154149
endif # CRYPTO_DEV_FSL_CAAM_JR
155150

156151
endif # CRYPTO_DEV_FSL_CAAM
@@ -160,6 +155,8 @@ config CRYPTO_DEV_FSL_DPAA2_CAAM
160155
depends on FSL_MC_DPIO
161156
depends on NETDEVICES
162157
select CRYPTO_DEV_FSL_CAAM_COMMON
158+
select CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC
159+
select CRYPTO_DEV_FSL_CAAM_AHASH_API_DESC
163160
select CRYPTO_BLKCIPHER
164161
select CRYPTO_AUTHENC
165162
select CRYPTO_AEAD
@@ -171,12 +168,3 @@ config CRYPTO_DEV_FSL_DPAA2_CAAM
171168

172169
To compile this as a module, choose M here: the module
173170
will be called dpaa2_caam.
174-
175-
config CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC
176-
def_tristate (CRYPTO_DEV_FSL_CAAM_CRYPTO_API || \
177-
CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI || \
178-
CRYPTO_DEV_FSL_DPAA2_CAAM)
179-
180-
config CRYPTO_DEV_FSL_CAAM_AHASH_API_DESC
181-
def_tristate (CRYPTO_DEV_FSL_CAAM_AHASH_API || \
182-
CRYPTO_DEV_FSL_DPAA2_CAAM)

‎drivers/crypto/caam/Makefile‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ ccflags-y += -DVERSION=\"\"
1111
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_COMMON) += error.o
1212
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM) += caam.o
1313
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_JR) += caam_jr.o
14-
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API) += caamalg.o
15-
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI) += caamalg_qi.o
1614
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC) += caamalg_desc.o
17-
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API) += caamhash.o
1815
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API_DESC) += caamhash_desc.o
19-
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API) += caamrng.o
20-
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API) += caam_pkc.o
2116

22-
caam-objs := ctrl.o
23-
caam_jr-objs := jr.o key_gen.o
24-
caam_pkc-y := caampkc.o pkc_desc.o
17+
caam-y := ctrl.o
18+
caam_jr-y := jr.o key_gen.o
19+
caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API) += caamalg.o
20+
caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI) += caamalg_qi.o
21+
caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API) += caamhash.o
22+
caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API) += caamrng.o
23+
caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API) += caampkc.o pkc_desc.o
24+
25+
caam-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI) += qi.o
2526
ifneq ($(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI),)
2627
ccflags-y += -DCONFIG_CAAM_QI
27-
caam-objs += qi.o
2828
endif
2929

3030
obj-$(CONFIG_CRYPTO_DEV_FSL_DPAA2_CAAM) += dpaa2_caam.o

‎drivers/crypto/caam/caamalg.c‎

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3471,7 +3471,7 @@ static void caam_aead_exit(struct crypto_aead *tfm)
34713471
caam_exit_common(crypto_aead_ctx(tfm));
34723472
}
34733473

3474-
static void __exit caam_algapi_exit(void)
3474+
void caam_algapi_exit(void)
34753475
{
34763476
int i;
34773477

@@ -3516,43 +3516,15 @@ static void caam_aead_alg_init(struct caam_aead_alg *t_alg)
35163516
alg->exit = caam_aead_exit;
35173517
}
35183518

3519-
static int __init caam_algapi_init(void)
3519+
int caam_algapi_init(struct device *ctrldev)
35203520
{
3521-
struct device_node *dev_node;
3522-
struct platform_device *pdev;
3523-
struct caam_drv_private *priv;
3521+
struct caam_drv_private *priv = dev_get_drvdata(ctrldev);
35243522
int i = 0, err = 0;
35253523
u32 aes_vid, aes_inst, des_inst, md_vid, md_inst, ccha_inst, ptha_inst;
35263524
u32 arc4_inst;
35273525
unsigned int md_limit = SHA512_DIGEST_SIZE;
35283526
bool registered = false, gcm_support;
35293527

3530-
dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
3531-
if (!dev_node) {
3532-
dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
3533-
if (!dev_node)
3534-
return -ENODEV;
3535-
}
3536-
3537-
pdev = of_find_device_by_node(dev_node);
3538-
if (!pdev) {
3539-
of_node_put(dev_node);
3540-
return -ENODEV;
3541-
}
3542-
3543-
priv = dev_get_drvdata(&pdev->dev);
3544-
of_node_put(dev_node);
3545-
3546-
/*
3547-
* If priv is NULL, it's probably because the caam driver wasn't
3548-
* properly initialized (e.g. RNG4 init failed). Thus, bail out here.
3549-
*/
3550-
if (!priv) {
3551-
err = -ENODEV;
3552-
goto out_put_dev;
3553-
}
3554-
3555-
35563528
/*
35573529
* Register crypto algorithms the device supports.
35583530
* First, detect presence and attributes of DES, AES, and MD blocks.
@@ -3695,14 +3667,5 @@ static int __init caam_algapi_init(void)
36953667
if (registered)
36963668
pr_info("caam algorithms registered in /proc/crypto\n");
36973669

3698-
out_put_dev:
3699-
put_device(&pdev->dev);
37003670
return err;
37013671
}
3702-
3703-
module_init(caam_algapi_init);
3704-
module_exit(caam_algapi_exit);
3705-
3706-
MODULE_LICENSE("GPL");
3707-
MODULE_DESCRIPTION("FSL CAAM support for crypto API");
3708-
MODULE_AUTHOR("Freescale Semiconductor - NMG/STC");

‎drivers/crypto/caam/caamalg_qi.c‎

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,7 +2492,7 @@ static void caam_aead_exit(struct crypto_aead *tfm)
24922492
caam_exit_common(crypto_aead_ctx(tfm));
24932493
}
24942494

2495-
static void __exit caam_qi_algapi_exit(void)
2495+
void caam_qi_algapi_exit(void)
24962496
{
24972497
int i;
24982498

@@ -2537,45 +2537,17 @@ static void caam_aead_alg_init(struct caam_aead_alg *t_alg)
25372537
alg->exit = caam_aead_exit;
25382538
}
25392539

2540-
static int __init caam_qi_algapi_init(void)
2540+
int caam_qi_algapi_init(struct device *ctrldev)
25412541
{
2542-
struct device_node *dev_node;
2543-
struct platform_device *pdev;
2544-
struct device *ctrldev;
2545-
struct caam_drv_private *priv;
2542+
struct caam_drv_private *priv = dev_get_drvdata(ctrldev);
25462543
int i = 0, err = 0;
25472544
u32 aes_vid, aes_inst, des_inst, md_vid, md_inst;
25482545
unsigned int md_limit = SHA512_DIGEST_SIZE;
25492546
bool registered = false;
25502547

2551-
dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
2552-
if (!dev_node) {
2553-
dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
2554-
if (!dev_node)
2555-
return -ENODEV;
2556-
}
2557-
2558-
pdev = of_find_device_by_node(dev_node);
2559-
of_node_put(dev_node);
2560-
if (!pdev)
2561-
return -ENODEV;
2562-
2563-
ctrldev = &pdev->dev;
2564-
priv = dev_get_drvdata(ctrldev);
2565-
2566-
/*
2567-
* If priv is NULL, it's probably because the caam driver wasn't
2568-
* properly initialized (e.g. RNG4 init failed). Thus, bail out here.
2569-
*/
2570-
if (!priv || !priv->qi_present) {
2571-
err = -ENODEV;
2572-
goto out_put_dev;
2573-
}
2574-
25752548
if (caam_dpaa2) {
25762549
dev_info(ctrldev, "caam/qi frontend driver not suitable for DPAA 2.x, aborting...\n");
2577-
err = -ENODEV;
2578-
goto out_put_dev;
2550+
return -ENODEV;
25792551
}
25802552

25812553
/*
@@ -2688,14 +2660,5 @@ static int __init caam_qi_algapi_init(void)
26882660
if (registered)
26892661
dev_info(priv->qidev, "algorithms registered in /proc/crypto\n");
26902662

2691-
out_put_dev:
2692-
put_device(ctrldev);
26932663
return err;
26942664
}
2695-
2696-
module_init(caam_qi_algapi_init);
2697-
module_exit(caam_qi_algapi_exit);
2698-
2699-
MODULE_LICENSE("GPL");
2700-
MODULE_DESCRIPTION("Support for crypto API using CAAM-QI backend");
2701-
MODULE_AUTHOR("Freescale Semiconductor");

‎drivers/crypto/caam/caamhash.c‎

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,7 +1933,7 @@ static void caam_hash_cra_exit(struct crypto_tfm *tfm)
19331933
caam_jr_free(ctx->jrdev);
19341934
}
19351935

1936-
static void __exit caam_algapi_hash_exit(void)
1936+
void caam_algapi_hash_exit(void)
19371937
{
19381938
struct caam_hash_alg *t_alg, *n;
19391939

@@ -1991,40 +1991,13 @@ caam_hash_alloc(struct caam_hash_template *template,
19911991
return t_alg;
19921992
}
19931993

1994-
static int __init caam_algapi_hash_init(void)
1994+
int caam_algapi_hash_init(struct device *ctrldev)
19951995
{
1996-
struct device_node *dev_node;
1997-
struct platform_device *pdev;
19981996
int i = 0, err = 0;
1999-
struct caam_drv_private *priv;
1997+
struct caam_drv_private *priv = dev_get_drvdata(ctrldev);
20001998
unsigned int md_limit = SHA512_DIGEST_SIZE;
20011999
u32 md_inst, md_vid;
20022000

2003-
dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
2004-
if (!dev_node) {
2005-
dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
2006-
if (!dev_node)
2007-
return -ENODEV;
2008-
}
2009-
2010-
pdev = of_find_device_by_node(dev_node);
2011-
if (!pdev) {
2012-
of_node_put(dev_node);
2013-
return -ENODEV;
2014-
}
2015-
2016-
priv = dev_get_drvdata(&pdev->dev);
2017-
of_node_put(dev_node);
2018-
2019-
/*
2020-
* If priv is NULL, it's probably because the caam driver wasn't
2021-
* properly initialized (e.g. RNG4 init failed). Thus, bail out here.
2022-
*/
2023-
if (!priv) {
2024-
err = -ENODEV;
2025-
goto out_put_dev;
2026-
}
2027-
20282001
/*
20292002
* Register crypto algorithms the device supports. First, identify
20302003
* presence and attributes of MD block.
@@ -2045,10 +2018,8 @@ static int __init caam_algapi_hash_init(void)
20452018
* Skip registration of any hashing algorithms if MD block
20462019
* is not present.
20472020
*/
2048-
if (!md_inst) {
2049-
err = -ENODEV;
2050-
goto out_put_dev;
2051-
}
2021+
if (!md_inst)
2022+
return -ENODEV;
20522023

20532024
/* Limit digest size based on LP256 */
20542025
if (md_vid == CHA_VER_VID_MD_LP256)
@@ -2105,14 +2076,5 @@ static int __init caam_algapi_hash_init(void)
21052076
list_add_tail(&t_alg->entry, &hash_list);
21062077
}
21072078

2108-
out_put_dev:
2109-
put_device(&pdev->dev);
21102079
return err;
21112080
}
2112-
2113-
module_init(caam_algapi_hash_init);
2114-
module_exit(caam_algapi_hash_exit);
2115-
2116-
MODULE_LICENSE("GPL");
2117-
MODULE_DESCRIPTION("FSL CAAM support for ahash functions of crypto API");
2118-
MODULE_AUTHOR("Freescale Semiconductor - NMG");

0 commit comments

Comments
 (0)