Skip to content

Commit

Permalink
crypto: caam - Add Platform driver for Job Ring
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ruchika Gupta authored and herbertx committed Oct 30, 2013
1 parent 0d28978 commit 313ea29
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 136 deletions.
25 changes: 19 additions & 6 deletions drivers/crypto/caam/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,29 @@ config CRYPTO_DEV_FSL_CAAM
help
Enables the driver module for Freescale's Cryptographic Accelerator
and Assurance Module (CAAM), also known as the SEC version 4 (SEC4).
This module adds a job ring operation interface, and configures h/w
This module creates job ring devices, and configures h/w
to operate as a DPAA component automatically, depending
on h/w feature availability.

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

config CRYPTO_DEV_FSL_CAAM_JR
tristate "Freescale CAAM Job Ring driver backend"
depends on CRYPTO_DEV_FSL_CAAM
default y
help
Enables the driver module for Job Rings which are part of
Freescale's Cryptographic Accelerator
and Assurance Module (CAAM). This module adds a job ring operation
interface.

To compile this driver as a module, choose M here: the module
will be called caam_jr.

config CRYPTO_DEV_FSL_CAAM_RINGSIZE
int "Job Ring size"
depends on CRYPTO_DEV_FSL_CAAM
depends on CRYPTO_DEV_FSL_CAAM_JR
range 2 9
default "9"
help
Expand All @@ -31,7 +44,7 @@ config CRYPTO_DEV_FSL_CAAM_RINGSIZE

config CRYPTO_DEV_FSL_CAAM_INTC
bool "Job Ring interrupt coalescing"
depends on CRYPTO_DEV_FSL_CAAM
depends on CRYPTO_DEV_FSL_CAAM_JR
default n
help
Enable the Job Ring's interrupt coalescing feature.
Expand Down Expand Up @@ -62,7 +75,7 @@ config CRYPTO_DEV_FSL_CAAM_INTC_TIME_THLD

config CRYPTO_DEV_FSL_CAAM_CRYPTO_API
tristate "Register algorithm implementations with the Crypto API"
depends on CRYPTO_DEV_FSL_CAAM
depends on CRYPTO_DEV_FSL_CAAM && CRYPTO_DEV_FSL_CAAM_JR
default y
select CRYPTO_ALGAPI
select CRYPTO_AUTHENC
Expand All @@ -76,7 +89,7 @@ config CRYPTO_DEV_FSL_CAAM_CRYPTO_API

config CRYPTO_DEV_FSL_CAAM_AHASH_API
tristate "Register hash algorithm implementations with Crypto API"
depends on CRYPTO_DEV_FSL_CAAM
depends on CRYPTO_DEV_FSL_CAAM && CRYPTO_DEV_FSL_CAAM_JR
default y
select CRYPTO_HASH
help
Expand All @@ -88,7 +101,7 @@ config CRYPTO_DEV_FSL_CAAM_AHASH_API

config CRYPTO_DEV_FSL_CAAM_RNG_API
tristate "Register caam device for hwrng API"
depends on CRYPTO_DEV_FSL_CAAM
depends on CRYPTO_DEV_FSL_CAAM && CRYPTO_DEV_FSL_CAAM_JR
default y
select CRYPTO_RNG
select HW_RANDOM
Expand Down
4 changes: 3 additions & 1 deletion drivers/crypto/caam/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ ifeq ($(CONFIG_CRYPTO_DEV_FSL_CAAM_DEBUG), y)
endif

obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM) += caam.o
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_JR) += caam_jr.o
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API) += caamalg.o
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API) += caamhash.o
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API) += caamrng.o

caam-objs := ctrl.o jr.o error.o key_gen.o
caam-objs := ctrl.o
caam_jr-objs := jr.o key_gen.o error.o
4 changes: 3 additions & 1 deletion drivers/crypto/caam/caamalg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2071,13 +2071,15 @@ static int caam_cra_init(struct crypto_tfm *tfm)
container_of(alg, struct caam_crypto_alg, crypto_alg);
struct caam_ctx *ctx = crypto_tfm_ctx(tfm);
struct caam_drv_private *priv = dev_get_drvdata(caam_alg->ctrldev);
struct platform_device *pdev;
int tgt_jr = atomic_inc_return(&priv->tfm_count);

/*
* distribute tfms across job rings to ensure in-order
* crypto request processing per tfm
*/
ctx->jrdev = priv->jrdev[(tgt_jr / 2) % priv->total_jobrs];
pdev = priv->jrpdev[(tgt_jr / 2) % priv->total_jobrs];
ctx->jrdev = &pdev->dev;

/* copy descriptor header template value */
ctx->class1_alg_type = OP_TYPE_CLASS1_ALG | caam_alg->class1_alg_type;
Expand Down
4 changes: 3 additions & 1 deletion drivers/crypto/caam/caamhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -1680,12 +1680,14 @@ static int caam_hash_cra_init(struct crypto_tfm *tfm)
HASH_MSG_LEN + SHA512_DIGEST_SIZE };
int tgt_jr = atomic_inc_return(&priv->tfm_count);
int ret = 0;
struct platform_device *pdev;

/*
* distribute tfms across job rings to ensure in-order
* crypto request processing per tfm
*/
ctx->jrdev = priv->jrdev[tgt_jr % priv->total_jobrs];
pdev = priv->jrpdev[tgt_jr % priv->total_jobrs];
ctx->jrdev = &pdev->dev;

/* copy descriptor header template value */
ctx->alg_type = OP_TYPE_CLASS2_ALG | caam_hash->alg_type;
Expand Down
7 changes: 4 additions & 3 deletions drivers/crypto/caam/caamrng.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static void __exit caam_rng_exit(void)
static int __init caam_rng_init(void)
{
struct device_node *dev_node;
struct platform_device *pdev;
struct platform_device *pdev, *jrpdev;
struct device *ctrldev;
struct caam_drv_private *priv;

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

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

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

Expand Down
30 changes: 20 additions & 10 deletions drivers/crypto/caam/ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,17 @@ static int caam_remove(struct platform_device *pdev)
{
struct device *ctrldev;
struct caam_drv_private *ctrlpriv;
struct caam_drv_private_jr *jrpriv;
struct caam_full __iomem *topregs;
int ring, ret = 0;

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

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

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

kfree(ctrlpriv->jrdev);
kfree(ctrlpriv->jrpdev);
kfree(ctrlpriv);

return ret;
Expand Down Expand Up @@ -450,22 +448,34 @@ static int caam_probe(struct platform_device *pdev)
rspec++;
}

ctrlpriv->jrdev = kzalloc(sizeof(struct device *) * rspec, GFP_KERNEL);
if (ctrlpriv->jrdev == NULL) {
ctrlpriv->jrpdev = kzalloc(sizeof(struct platform_device *) * rspec,
GFP_KERNEL);
if (ctrlpriv->jrpdev == NULL) {
iounmap(&topregs->ctrl);
return -ENOMEM;
}

ring = 0;
ctrlpriv->total_jobrs = 0;
for_each_compatible_node(np, NULL, "fsl,sec-v4.0-job-ring") {
caam_jr_probe(pdev, np, ring);
ctrlpriv->jrpdev[ring] =
of_platform_device_create(np, NULL, dev);
if (!ctrlpriv->jrpdev[ring]) {
pr_warn("JR%d Platform device creation error\n", ring);
continue;
}
ctrlpriv->total_jobrs++;
ring++;
}
if (!ring) {
for_each_compatible_node(np, NULL, "fsl,sec4.0-job-ring") {
caam_jr_probe(pdev, np, ring);
ctrlpriv->jrpdev[ring] =
of_platform_device_create(np, NULL, dev);
if (!ctrlpriv->jrpdev[ring]) {
pr_warn("JR%d Platform device creation error\n",
ring);
continue;
}
ctrlpriv->total_jobrs++;
ring++;
}
Expand Down
6 changes: 3 additions & 3 deletions drivers/crypto/caam/intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ struct caam_jrentry_info {

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

struct device *dev;
struct device **jrdev; /* Alloc'ed array per sub-device */
struct platform_device **jrpdev; /* Alloc'ed array per sub-device */
struct platform_device *pdev;

/* Physical-presence section */
Expand Down
Loading

0 comments on commit 313ea29

Please sign in to comment.