Skip to content

Commit 313ea29

Browse files
Ruchika Guptaherbertx
authored andcommitted
crypto: caam - Add Platform driver for Job Ring
The SEC Job Rings are now available as individual devices. This would enable sharing of job rings between kernel and user space. Job Rings can now be dynamically bound/unbound from kernel. Changes are made in the following layers of CAAM Driver 1. Controller driver - Does basic initialization of CAAM Block. - Creates platform devices for Job Rings. (Earlier the initialization of Job ring was done by the controller driver) 2. JobRing Platform driver - Manages the platform Job Ring devices created by the controller driver Signed-off-by: Ruchika Gupta <ruchika.gupta@freescale.com> Reviewed-by: Garg Vakul-B16394 <vakul@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 0d28978 commit 313ea29

9 files changed

Lines changed: 232 additions & 136 deletions

File tree

‎drivers/crypto/caam/Kconfig‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,29 @@ config CRYPTO_DEV_FSL_CAAM
44
help
55
Enables the driver module for Freescale's Cryptographic Accelerator
66
and Assurance Module (CAAM), also known as the SEC version 4 (SEC4).
7-
This module adds a job ring operation interface, and configures h/w
7+
This module creates job ring devices, and configures h/w
88
to operate as a DPAA component automatically, depending
99
on h/w feature availability.
1010

1111
To compile this driver as a module, choose M here: the module
1212
will be called caam.
1313

14+
config CRYPTO_DEV_FSL_CAAM_JR
15+
tristate "Freescale CAAM Job Ring driver backend"
16+
depends on CRYPTO_DEV_FSL_CAAM
17+
default y
18+
help
19+
Enables the driver module for Job Rings which are part of
20+
Freescale's Cryptographic Accelerator
21+
and Assurance Module (CAAM). This module adds a job ring operation
22+
interface.
23+
24+
To compile this driver as a module, choose M here: the module
25+
will be called caam_jr.
26+
1427
config CRYPTO_DEV_FSL_CAAM_RINGSIZE
1528
int "Job Ring size"
16-
depends on CRYPTO_DEV_FSL_CAAM
29+
depends on CRYPTO_DEV_FSL_CAAM_JR
1730
range 2 9
1831
default "9"
1932
help
@@ -31,7 +44,7 @@ config CRYPTO_DEV_FSL_CAAM_RINGSIZE
3144

3245
config CRYPTO_DEV_FSL_CAAM_INTC
3346
bool "Job Ring interrupt coalescing"
34-
depends on CRYPTO_DEV_FSL_CAAM
47+
depends on CRYPTO_DEV_FSL_CAAM_JR
3548
default n
3649
help
3750
Enable the Job Ring's interrupt coalescing feature.
@@ -62,7 +75,7 @@ config CRYPTO_DEV_FSL_CAAM_INTC_TIME_THLD
6275

6376
config CRYPTO_DEV_FSL_CAAM_CRYPTO_API
6477
tristate "Register algorithm implementations with the Crypto API"
65-
depends on CRYPTO_DEV_FSL_CAAM
78+
depends on CRYPTO_DEV_FSL_CAAM && CRYPTO_DEV_FSL_CAAM_JR
6679
default y
6780
select CRYPTO_ALGAPI
6881
select CRYPTO_AUTHENC
@@ -76,7 +89,7 @@ config CRYPTO_DEV_FSL_CAAM_CRYPTO_API
7689

7790
config CRYPTO_DEV_FSL_CAAM_AHASH_API
7891
tristate "Register hash algorithm implementations with Crypto API"
79-
depends on CRYPTO_DEV_FSL_CAAM
92+
depends on CRYPTO_DEV_FSL_CAAM && CRYPTO_DEV_FSL_CAAM_JR
8093
default y
8194
select CRYPTO_HASH
8295
help
@@ -88,7 +101,7 @@ config CRYPTO_DEV_FSL_CAAM_AHASH_API
88101

89102
config CRYPTO_DEV_FSL_CAAM_RNG_API
90103
tristate "Register caam device for hwrng API"
91-
depends on CRYPTO_DEV_FSL_CAAM
104+
depends on CRYPTO_DEV_FSL_CAAM && CRYPTO_DEV_FSL_CAAM_JR
92105
default y
93106
select CRYPTO_RNG
94107
select HW_RANDOM

‎drivers/crypto/caam/Makefile‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ ifeq ($(CONFIG_CRYPTO_DEV_FSL_CAAM_DEBUG), y)
66
endif
77

88
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM) += caam.o
9+
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_JR) += caam_jr.o
910
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API) += caamalg.o
1011
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API) += caamhash.o
1112
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API) += caamrng.o
1213

13-
caam-objs := ctrl.o jr.o error.o key_gen.o
14+
caam-objs := ctrl.o
15+
caam_jr-objs := jr.o key_gen.o error.o

‎drivers/crypto/caam/caamalg.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2071,13 +2071,15 @@ static int caam_cra_init(struct crypto_tfm *tfm)
20712071
container_of(alg, struct caam_crypto_alg, crypto_alg);
20722072
struct caam_ctx *ctx = crypto_tfm_ctx(tfm);
20732073
struct caam_drv_private *priv = dev_get_drvdata(caam_alg->ctrldev);
2074+
struct platform_device *pdev;
20742075
int tgt_jr = atomic_inc_return(&priv->tfm_count);
20752076

20762077
/*
20772078
* distribute tfms across job rings to ensure in-order
20782079
* crypto request processing per tfm
20792080
*/
2080-
ctx->jrdev = priv->jrdev[(tgt_jr / 2) % priv->total_jobrs];
2081+
pdev = priv->jrpdev[(tgt_jr / 2) % priv->total_jobrs];
2082+
ctx->jrdev = &pdev->dev;
20812083

20822084
/* copy descriptor header template value */
20832085
ctx->class1_alg_type = OP_TYPE_CLASS1_ALG | caam_alg->class1_alg_type;

‎drivers/crypto/caam/caamhash.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1680,12 +1680,14 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm)
16801680
HASH_MSG_LEN + SHA512_DIGEST_SIZE };
16811681
int tgt_jr = atomic_inc_return(&priv->tfm_count);
16821682
int ret = 0;
1683+
struct platform_device *pdev;
16831684

16841685
/*
16851686
* distribute tfms across job rings to ensure in-order
16861687
* crypto request processing per tfm
16871688
*/
1688-
ctx->jrdev = priv->jrdev[tgt_jr % priv->total_jobrs];
1689+
pdev = priv->jrpdev[tgt_jr % priv->total_jobrs];
1690+
ctx->jrdev = &pdev->dev;
16891691

16901692
/* copy descriptor header template value */
16911693
ctx->alg_type = OP_TYPE_CLASS2_ALG | caam_hash->alg_type;

‎drivers/crypto/caam/caamrng.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static void __exit caam_rng_exit(void)
279279
static int __init caam_rng_init(void)
280280
{
281281
struct device_node *dev_node;
282-
struct platform_device *pdev;
282+
struct platform_device *pdev, *jrpdev;
283283
struct device *ctrldev;
284284
struct caam_drv_private *priv;
285285

@@ -305,9 +305,10 @@ static int __init caam_rng_init(void)
305305
if (!priv)
306306
return -ENODEV;
307307

308-
caam_init_rng(&rng_ctx, priv->jrdev[0]);
308+
jrpdev = priv->jrpdev[0];
309+
caam_init_rng(&rng_ctx, &jrpdev->dev);
309310

310-
dev_info(priv->jrdev[0], "registering rng-caam\n");
311+
dev_info(&jrpdev->dev, "registering rng-caam\n");
311312
return hwrng_register(&caam_rng);
312313
}
313314

‎drivers/crypto/caam/ctrl.c‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -268,19 +268,17 @@ static int caam_remove(struct platform_device *pdev)
268268
{
269269
struct device *ctrldev;
270270
struct caam_drv_private *ctrlpriv;
271-
struct caam_drv_private_jr *jrpriv;
272271
struct caam_full __iomem *topregs;
273272
int ring, ret = 0;
274273

275274
ctrldev = &pdev->dev;
276275
ctrlpriv = dev_get_drvdata(ctrldev);
277276
topregs = (struct caam_full __iomem *)ctrlpriv->ctrl;
278277

279-
/* shut down JobRs */
278+
/* Remove platform devices for JobRs */
280279
for (ring = 0; ring < ctrlpriv->total_jobrs; ring++) {
281-
ret |= caam_jr_shutdown(ctrlpriv->jrdev[ring]);
282-
jrpriv = dev_get_drvdata(ctrlpriv->jrdev[ring]);
283-
irq_dispose_mapping(jrpriv->irq);
280+
if (ctrlpriv->jrpdev[ring])
281+
of_device_unregister(ctrlpriv->jrpdev[ring]);
284282
}
285283

286284
/* De-initialize RNG state handles initialized by this driver. */
@@ -295,7 +293,7 @@ static int caam_remove(struct platform_device *pdev)
295293
/* Unmap controller region */
296294
iounmap(&topregs->ctrl);
297295

298-
kfree(ctrlpriv->jrdev);
296+
kfree(ctrlpriv->jrpdev);
299297
kfree(ctrlpriv);
300298

301299
return ret;
@@ -450,22 +448,34 @@ static int caam_probe(struct platform_device *pdev)
450448
rspec++;
451449
}
452450

453-
ctrlpriv->jrdev = kzalloc(sizeof(struct device *) * rspec, GFP_KERNEL);
454-
if (ctrlpriv->jrdev == NULL) {
451+
ctrlpriv->jrpdev = kzalloc(sizeof(struct platform_device *) * rspec,
452+
GFP_KERNEL);
453+
if (ctrlpriv->jrpdev == NULL) {
455454
iounmap(&topregs->ctrl);
456455
return -ENOMEM;
457456
}
458457

459458
ring = 0;
460459
ctrlpriv->total_jobrs = 0;
461460
for_each_compatible_node(np, NULL, "fsl,sec-v4.0-job-ring") {
462-
caam_jr_probe(pdev, np, ring);
461+
ctrlpriv->jrpdev[ring] =
462+
of_platform_device_create(np, NULL, dev);
463+
if (!ctrlpriv->jrpdev[ring]) {
464+
pr_warn("JR%d Platform device creation error\n", ring);
465+
continue;
466+
}
463467
ctrlpriv->total_jobrs++;
464468
ring++;
465469
}
466470
if (!ring) {
467471
for_each_compatible_node(np, NULL, "fsl,sec4.0-job-ring") {
468-
caam_jr_probe(pdev, np, ring);
472+
ctrlpriv->jrpdev[ring] =
473+
of_platform_device_create(np, NULL, dev);
474+
if (!ctrlpriv->jrpdev[ring]) {
475+
pr_warn("JR%d Platform device creation error\n",
476+
ring);
477+
continue;
478+
}
469479
ctrlpriv->total_jobrs++;
470480
ring++;
471481
}

‎drivers/crypto/caam/intern.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ struct caam_jrentry_info {
3737

3838
/* Private sub-storage for a single JobR */
3939
struct caam_drv_private_jr {
40-
struct device *parentdev; /* points back to controller dev */
41-
struct platform_device *jr_pdev;/* points to platform device for JR */
40+
struct list_head list_node; /* Job Ring device list */
41+
struct device *dev;
4242
int ridx;
4343
struct caam_job_ring __iomem *rregs; /* JobR's register space */
4444
struct tasklet_struct irqtask;
@@ -63,7 +63,7 @@ struct caam_drv_private_jr {
6363
struct caam_drv_private {
6464

6565
struct device *dev;
66-
struct device **jrdev; /* Alloc'ed array per sub-device */
66+
struct platform_device **jrpdev; /* Alloc'ed array per sub-device */
6767
struct platform_device *pdev;
6868

6969
/* Physical-presence section */

0 commit comments

Comments
 (0)