Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b46c90c authored by Horia Geantă's avatar Horia Geantă Committed by Herbert Xu
Browse files

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: default avatarHoria Geantă <horia.geanta@nxp.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent a5e5c133
Loading
Loading
Loading
Loading
+17 −29
Original line number Diff line number Diff line
@@ -2,6 +2,12 @@
config CRYPTO_DEV_FSL_CAAM_COMMON
	tristate

config CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC
	tristate

config CRYPTO_DEV_FSL_CAAM_AHASH_API_DESC
	tristate

config CRYPTO_DEV_FSL_CAAM
	tristate "Freescale CAAM-Multicore platform driver backend"
	depends on FSL_SOC || ARCH_MXC || ARCH_LAYERSCAPE
@@ -25,7 +31,7 @@ config CRYPTO_DEV_FSL_CAAM_DEBUG
	  Selecting this will enable printing of various debug
	  information in the CAAM driver.

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

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

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

config CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI
	tristate "Queue Interface as Crypto API backend"
	bool "Queue Interface as Crypto API backend"
	depends on FSL_DPAA && NET
	default y
	select CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC
	select CRYPTO_AUTHENC
	select CRYPTO_BLKCIPHER
	help
@@ -114,33 +119,26 @@ config CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI
	  assigned to the kernel should also be more than the number of
	  job rings.

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

config CRYPTO_DEV_FSL_CAAM_AHASH_API
	tristate "Register hash algorithm implementations with Crypto API"
	bool "Register hash algorithm implementations with Crypto API"
	default y
	select CRYPTO_DEV_FSL_CAAM_AHASH_API_DESC
	select CRYPTO_HASH
	help
	  Selecting this will offload ahash for users of the
	  scatterlist crypto API to the SEC4 via job ring.

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

config CRYPTO_DEV_FSL_CAAM_PKC_API
        tristate "Register public key cryptography implementations with Crypto API"
        bool "Register public key cryptography implementations with Crypto API"
        default y
        select CRYPTO_RSA
        help
          Selecting this will allow SEC Public key support for RSA.
          Supported cryptographic primitives: encryption, decryption,
          signature and verification.
          To compile this as a module, choose M here: the module
          will be called caam_pkc.

config CRYPTO_DEV_FSL_CAAM_RNG_API
	tristate "Register caam device for hwrng API"
	bool "Register caam device for hwrng API"
	default y
	select CRYPTO_RNG
	select HW_RANDOM
@@ -148,9 +146,6 @@ config CRYPTO_DEV_FSL_CAAM_RNG_API
	  Selecting this will register the SEC4 hardware rng to
	  the hw_random API for suppying the kernel entropy pool.

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

endif # CRYPTO_DEV_FSL_CAAM_JR

endif # CRYPTO_DEV_FSL_CAAM
@@ -160,6 +155,8 @@ config CRYPTO_DEV_FSL_DPAA2_CAAM
	depends on FSL_MC_DPIO
	depends on NETDEVICES
	select CRYPTO_DEV_FSL_CAAM_COMMON
	select CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC
	select CRYPTO_DEV_FSL_CAAM_AHASH_API_DESC
	select CRYPTO_BLKCIPHER
	select CRYPTO_AUTHENC
	select CRYPTO_AEAD
@@ -171,12 +168,3 @@ config CRYPTO_DEV_FSL_DPAA2_CAAM

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

config CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC
	def_tristate (CRYPTO_DEV_FSL_CAAM_CRYPTO_API || \
		      CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI || \
		      CRYPTO_DEV_FSL_DPAA2_CAAM)

config CRYPTO_DEV_FSL_CAAM_AHASH_API_DESC
	def_tristate (CRYPTO_DEV_FSL_CAAM_AHASH_API || \
		      CRYPTO_DEV_FSL_DPAA2_CAAM)
+9 −9
Original line number Diff line number Diff line
@@ -11,20 +11,20 @@ ccflags-y += -DVERSION=\"\"
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_COMMON) += error.o
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_CRYPTO_API_QI) += caamalg_qi.o
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_DESC) += caamalg_desc.o
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API) += caamhash.o
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API_DESC) += caamhash_desc.o
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API) += caamrng.o
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API) += caam_pkc.o

caam-objs := ctrl.o
caam_jr-objs := jr.o key_gen.o
caam_pkc-y := caampkc.o pkc_desc.o
caam-y := ctrl.o
caam_jr-y := jr.o key_gen.o
caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API) += caamalg.o
caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI) += caamalg_qi.o
caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API) += caamhash.o
caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API) += caamrng.o
caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API) += caampkc.o pkc_desc.o

caam-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI) += qi.o
ifneq ($(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI),)
	ccflags-y += -DCONFIG_CAAM_QI
	caam-objs += qi.o
endif

obj-$(CONFIG_CRYPTO_DEV_FSL_DPAA2_CAAM) += dpaa2_caam.o
+3 −40
Original line number Diff line number Diff line
@@ -3471,7 +3471,7 @@ static void caam_aead_exit(struct crypto_aead *tfm)
	caam_exit_common(crypto_aead_ctx(tfm));
}

static void __exit caam_algapi_exit(void)
void caam_algapi_exit(void)
{
	int i;

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

static int __init caam_algapi_init(void)
int caam_algapi_init(struct device *ctrldev)
{
	struct device_node *dev_node;
	struct platform_device *pdev;
	struct caam_drv_private *priv;
	struct caam_drv_private *priv = dev_get_drvdata(ctrldev);
	int i = 0, err = 0;
	u32 aes_vid, aes_inst, des_inst, md_vid, md_inst, ccha_inst, ptha_inst;
	u32 arc4_inst;
	unsigned int md_limit = SHA512_DIGEST_SIZE;
	bool registered = false, gcm_support;

	dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
	if (!dev_node) {
		dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
		if (!dev_node)
			return -ENODEV;
	}

	pdev = of_find_device_by_node(dev_node);
	if (!pdev) {
		of_node_put(dev_node);
		return -ENODEV;
	}

	priv = dev_get_drvdata(&pdev->dev);
	of_node_put(dev_node);

	/*
	 * If priv is NULL, it's probably because the caam driver wasn't
	 * properly initialized (e.g. RNG4 init failed). Thus, bail out here.
	 */
	if (!priv) {
		err = -ENODEV;
		goto out_put_dev;
	}


	/*
	 * Register crypto algorithms the device supports.
	 * First, detect presence and attributes of DES, AES, and MD blocks.
@@ -3695,14 +3667,5 @@ static int __init caam_algapi_init(void)
	if (registered)
		pr_info("caam algorithms registered in /proc/crypto\n");

out_put_dev:
	put_device(&pdev->dev);
	return err;
}

module_init(caam_algapi_init);
module_exit(caam_algapi_exit);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("FSL CAAM support for crypto API");
MODULE_AUTHOR("Freescale Semiconductor - NMG/STC");
+4 −41
Original line number Diff line number Diff line
@@ -2492,7 +2492,7 @@ static void caam_aead_exit(struct crypto_aead *tfm)
	caam_exit_common(crypto_aead_ctx(tfm));
}

static void __exit caam_qi_algapi_exit(void)
void caam_qi_algapi_exit(void)
{
	int i;

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

static int __init caam_qi_algapi_init(void)
int caam_qi_algapi_init(struct device *ctrldev)
{
	struct device_node *dev_node;
	struct platform_device *pdev;
	struct device *ctrldev;
	struct caam_drv_private *priv;
	struct caam_drv_private *priv = dev_get_drvdata(ctrldev);
	int i = 0, err = 0;
	u32 aes_vid, aes_inst, des_inst, md_vid, md_inst;
	unsigned int md_limit = SHA512_DIGEST_SIZE;
	bool registered = false;

	dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
	if (!dev_node) {
		dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
		if (!dev_node)
			return -ENODEV;
	}

	pdev = of_find_device_by_node(dev_node);
	of_node_put(dev_node);
	if (!pdev)
		return -ENODEV;

	ctrldev = &pdev->dev;
	priv = dev_get_drvdata(ctrldev);

	/*
	 * If priv is NULL, it's probably because the caam driver wasn't
	 * properly initialized (e.g. RNG4 init failed). Thus, bail out here.
	 */
	if (!priv || !priv->qi_present) {
		err = -ENODEV;
		goto out_put_dev;
	}

	if (caam_dpaa2) {
		dev_info(ctrldev, "caam/qi frontend driver not suitable for DPAA 2.x, aborting...\n");
		err = -ENODEV;
		goto out_put_dev;
		return -ENODEV;
	}

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

out_put_dev:
	put_device(ctrldev);
	return err;
}

module_init(caam_qi_algapi_init);
module_exit(caam_qi_algapi_exit);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Support for crypto API using CAAM-QI backend");
MODULE_AUTHOR("Freescale Semiconductor");
+5 −43
Original line number Diff line number Diff line
@@ -1933,7 +1933,7 @@ static void caam_hash_cra_exit(struct crypto_tfm *tfm)
	caam_jr_free(ctx->jrdev);
}

static void __exit caam_algapi_hash_exit(void)
void caam_algapi_hash_exit(void)
{
	struct caam_hash_alg *t_alg, *n;

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

static int __init caam_algapi_hash_init(void)
int caam_algapi_hash_init(struct device *ctrldev)
{
	struct device_node *dev_node;
	struct platform_device *pdev;
	int i = 0, err = 0;
	struct caam_drv_private *priv;
	struct caam_drv_private *priv = dev_get_drvdata(ctrldev);
	unsigned int md_limit = SHA512_DIGEST_SIZE;
	u32 md_inst, md_vid;

	dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
	if (!dev_node) {
		dev_node = of_find_compatible_node(NULL, NULL, "fsl,sec4.0");
		if (!dev_node)
			return -ENODEV;
	}

	pdev = of_find_device_by_node(dev_node);
	if (!pdev) {
		of_node_put(dev_node);
		return -ENODEV;
	}

	priv = dev_get_drvdata(&pdev->dev);
	of_node_put(dev_node);

	/*
	 * If priv is NULL, it's probably because the caam driver wasn't
	 * properly initialized (e.g. RNG4 init failed). Thus, bail out here.
	 */
	if (!priv) {
		err = -ENODEV;
		goto out_put_dev;
	}

	/*
	 * Register crypto algorithms the device supports.  First, identify
	 * presence and attributes of MD block.
@@ -2045,10 +2018,8 @@ static int __init caam_algapi_hash_init(void)
	 * Skip registration of any hashing algorithms if MD block
	 * is not present.
	 */
	if (!md_inst) {
		err = -ENODEV;
		goto out_put_dev;
	}
	if (!md_inst)
		return -ENODEV;

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

out_put_dev:
	put_device(&pdev->dev);
	return err;
}

module_init(caam_algapi_hash_init);
module_exit(caam_algapi_hash_exit);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("FSL CAAM support for ahash functions of crypto API");
MODULE_AUTHOR("Freescale Semiconductor - NMG");
Loading