Commit 03906fba authored by Herbert Xu's avatar Herbert Xu

crypto: omap - Use new crypto_engine_op interface

Use the new crypto_engine_op interface where the callback is stored
in the algorithm object.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 530d7b00
......@@ -7,18 +7,21 @@
* Copyright (c) 2016 Texas Instruments Incorporated
*/
#include <crypto/aes.h>
#include <crypto/engine.h>
#include <crypto/gcm.h>
#include <crypto/internal/aead.h>
#include <crypto/scatterwalk.h>
#include <crypto/skcipher.h>
#include <linux/errno.h>
#include <linux/scatterlist.h>
#include <linux/dma-mapping.h>
#include <linux/dmaengine.h>
#include <linux/omap-dma.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/omap-dma.h>
#include <linux/pm_runtime.h>
#include <crypto/aes.h>
#include <crypto/gcm.h>
#include <crypto/scatterwalk.h>
#include <crypto/skcipher.h>
#include <crypto/internal/aead.h>
#include <linux/scatterlist.h>
#include <linux/string.h>
#include "omap-crypto.h"
#include "omap-aes.h"
......@@ -354,7 +357,7 @@ int omap_aes_4106gcm_setauthsize(struct crypto_aead *parent,
return crypto_rfc4106_check_authsize(authsize);
}
static int omap_aes_gcm_crypt_req(struct crypto_engine *engine, void *areq)
int omap_aes_gcm_crypt_req(struct crypto_engine *engine, void *areq)
{
struct aead_request *req = container_of(areq, struct aead_request,
base);
......@@ -379,10 +382,6 @@ static int omap_aes_gcm_crypt_req(struct crypto_engine *engine, void *areq)
int omap_aes_gcm_cra_init(struct crypto_aead *tfm)
{
struct omap_aes_ctx *ctx = crypto_aead_ctx(tfm);
ctx->enginectx.op.do_one_request = omap_aes_gcm_crypt_req;
crypto_aead_set_reqsize(tfm, sizeof(struct omap_aes_reqctx));
return 0;
......
......@@ -33,6 +33,7 @@
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/scatterlist.h>
#include <linux/string.h>
#include "omap-crypto.h"
#include "omap-aes.h"
......@@ -638,8 +639,6 @@ static int omap_aes_init_tfm(struct crypto_skcipher *tfm)
crypto_skcipher_set_reqsize(tfm, sizeof(struct omap_aes_reqctx) +
crypto_skcipher_reqsize(blk));
ctx->enginectx.op.do_one_request = omap_aes_crypt_req;
return 0;
}
......@@ -655,8 +654,9 @@ static void omap_aes_exit_tfm(struct crypto_skcipher *tfm)
/* ********************** ALGS ************************************ */
static struct skcipher_alg algs_ecb_cbc[] = {
static struct skcipher_engine_alg algs_ecb_cbc[] = {
{
.base = {
.base.cra_name = "ecb(aes)",
.base.cra_driver_name = "ecb-aes-omap",
.base.cra_priority = 300,
......@@ -674,8 +674,11 @@ static struct skcipher_alg algs_ecb_cbc[] = {
.decrypt = omap_aes_ecb_decrypt,
.init = omap_aes_init_tfm,
.exit = omap_aes_exit_tfm,
},
.op.do_one_request = omap_aes_crypt_req,
},
{
.base = {
.base.cra_name = "cbc(aes)",
.base.cra_driver_name = "cbc-aes-omap",
.base.cra_priority = 300,
......@@ -694,11 +697,14 @@ static struct skcipher_alg algs_ecb_cbc[] = {
.decrypt = omap_aes_cbc_decrypt,
.init = omap_aes_init_tfm,
.exit = omap_aes_exit_tfm,
},
.op.do_one_request = omap_aes_crypt_req,
}
};
static struct skcipher_alg algs_ctr[] = {
static struct skcipher_engine_alg algs_ctr[] = {
{
.base = {
.base.cra_name = "ctr(aes)",
.base.cra_driver_name = "ctr-aes-omap",
.base.cra_priority = 300,
......@@ -717,6 +723,8 @@ static struct skcipher_alg algs_ctr[] = {
.decrypt = omap_aes_ctr_decrypt,
.init = omap_aes_init_tfm,
.exit = omap_aes_exit_tfm,
},
.op.do_one_request = omap_aes_crypt_req,
}
};
......@@ -727,8 +735,9 @@ static struct omap_aes_algs_info omap_aes_algs_info_ecb_cbc[] = {
},
};
static struct aead_alg algs_aead_gcm[] = {
static struct aead_engine_alg algs_aead_gcm[] = {
{
.base = {
.base = {
.cra_name = "gcm(aes)",
.cra_driver_name = "gcm-aes-omap",
......@@ -747,8 +756,11 @@ static struct aead_alg algs_aead_gcm[] = {
.setauthsize = omap_aes_gcm_setauthsize,
.encrypt = omap_aes_gcm_encrypt,
.decrypt = omap_aes_gcm_decrypt,
},
.op.do_one_request = omap_aes_gcm_crypt_req,
},
{
.base = {
.base = {
.cra_name = "rfc4106(gcm(aes))",
.cra_driver_name = "rfc4106-gcm-aes-omap",
......@@ -767,6 +779,8 @@ static struct aead_alg algs_aead_gcm[] = {
.setauthsize = omap_aes_4106gcm_setauthsize,
.encrypt = omap_aes_4106gcm_encrypt,
.decrypt = omap_aes_4106gcm_decrypt,
},
.op.do_one_request = omap_aes_gcm_crypt_req,
},
};
......@@ -1088,8 +1102,8 @@ static int omap_aes_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct omap_aes_dev *dd;
struct skcipher_alg *algp;
struct aead_alg *aalg;
struct skcipher_engine_alg *algp;
struct aead_engine_alg *aalg;
struct resource res;
int err = -ENOMEM, i, j, irq = -1;
u32 reg;
......@@ -1182,9 +1196,9 @@ static int omap_aes_probe(struct platform_device *pdev)
for (j = 0; j < dd->pdata->algs_info[i].size; j++) {
algp = &dd->pdata->algs_info[i].algs_list[j];
pr_debug("reg alg: %s\n", algp->base.cra_name);
pr_debug("reg alg: %s\n", algp->base.base.cra_name);
err = crypto_register_skcipher(algp);
err = crypto_engine_register_skcipher(algp);
if (err)
goto err_algs;
......@@ -1198,9 +1212,9 @@ static int omap_aes_probe(struct platform_device *pdev)
for (i = 0; i < dd->pdata->aead_algs_info->size; i++) {
aalg = &dd->pdata->aead_algs_info->algs_list[i];
pr_debug("reg alg: %s\n", aalg->base.cra_name);
pr_debug("reg alg: %s\n", aalg->base.base.cra_name);
err = crypto_register_aead(aalg);
err = crypto_engine_register_aead(aalg);
if (err)
goto err_aead_algs;
......@@ -1218,12 +1232,12 @@ static int omap_aes_probe(struct platform_device *pdev)
err_aead_algs:
for (i = dd->pdata->aead_algs_info->registered - 1; i >= 0; i--) {
aalg = &dd->pdata->aead_algs_info->algs_list[i];
crypto_unregister_aead(aalg);
crypto_engine_unregister_aead(aalg);
}
err_algs:
for (i = dd->pdata->algs_info_size - 1; i >= 0; i--)
for (j = dd->pdata->algs_info[i].registered - 1; j >= 0; j--)
crypto_unregister_skcipher(
crypto_engine_unregister_skcipher(
&dd->pdata->algs_info[i].algs_list[j]);
err_engine:
......@@ -1245,7 +1259,7 @@ static int omap_aes_probe(struct platform_device *pdev)
static int omap_aes_remove(struct platform_device *pdev)
{
struct omap_aes_dev *dd = platform_get_drvdata(pdev);
struct aead_alg *aalg;
struct aead_engine_alg *aalg;
int i, j;
spin_lock_bh(&list_lock);
......@@ -1254,14 +1268,14 @@ static int omap_aes_remove(struct platform_device *pdev)
for (i = dd->pdata->algs_info_size - 1; i >= 0; i--)
for (j = dd->pdata->algs_info[i].registered - 1; j >= 0; j--) {
crypto_unregister_skcipher(
crypto_engine_unregister_skcipher(
&dd->pdata->algs_info[i].algs_list[j]);
dd->pdata->algs_info[i].registered--;
}
for (i = dd->pdata->aead_algs_info->registered - 1; i >= 0; i--) {
aalg = &dd->pdata->aead_algs_info->algs_list[i];
crypto_unregister_aead(aalg);
crypto_engine_unregister_aead(aalg);
dd->pdata->aead_algs_info->registered--;
}
......
......@@ -10,7 +10,6 @@
#define __OMAP_AES_H__
#include <crypto/aes.h>
#include <crypto/engine.h>
#define DST_MAXBURST 4
#define DMA_MIN (DST_MAXBURST * sizeof(u32))
......@@ -93,7 +92,6 @@ struct omap_aes_gcm_result {
};
struct omap_aes_ctx {
struct crypto_engine_ctx enginectx;
int keylen;
u32 key[AES_KEYSIZE_256 / sizeof(u32)];
u8 nonce[4];
......@@ -117,13 +115,13 @@ struct omap_aes_reqctx {
#define OMAP_AES_CACHE_SIZE 0
struct omap_aes_algs_info {
struct skcipher_alg *algs_list;
struct skcipher_engine_alg *algs_list;
unsigned int size;
unsigned int registered;
};
struct omap_aes_aead_algs {
struct aead_alg *algs_list;
struct aead_engine_alg *algs_list;
unsigned int size;
unsigned int registered;
};
......@@ -218,5 +216,6 @@ int omap_aes_crypt_dma_start(struct omap_aes_dev *dd);
int omap_aes_crypt_dma_stop(struct omap_aes_dev *dd);
void omap_aes_gcm_dma_out_callback(void *data);
void omap_aes_clear_copy_flags(struct omap_aes_dev *dd);
int omap_aes_gcm_crypt_req(struct crypto_engine *engine, void *areq);
#endif
......@@ -16,27 +16,25 @@
#define prx(num) do { } while (0)
#endif
#include <crypto/engine.h>
#include <crypto/internal/des.h>
#include <crypto/internal/skcipher.h>
#include <crypto/scatterwalk.h>
#include <linux/dma-mapping.h>
#include <linux/dmaengine.h>
#include <linux/err.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/scatterlist.h>
#include <linux/dma-mapping.h>
#include <linux/dmaengine.h>
#include <linux/pm_runtime.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/of_address.h>
#include <linux/io.h>
#include <linux/crypto.h>
#include <linux/interrupt.h>
#include <crypto/scatterwalk.h>
#include <crypto/internal/des.h>
#include <crypto/internal/skcipher.h>
#include <crypto/algapi.h>
#include <crypto/engine.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/scatterlist.h>
#include <linux/string.h>
#include "omap-crypto.h"
......@@ -83,7 +81,6 @@
#define FLAGS_OUT_DATA_ST_SHIFT 10
struct omap_des_ctx {
struct crypto_engine_ctx enginectx;
struct omap_des_dev *dd;
int keylen;
......@@ -99,7 +96,7 @@ struct omap_des_reqctx {
#define OMAP_DES_CACHE_SIZE 0
struct omap_des_algs_info {
struct skcipher_alg *algs_list;
struct skcipher_engine_alg *algs_list;
unsigned int size;
unsigned int registered;
};
......@@ -707,21 +704,18 @@ static int omap_des_cbc_decrypt(struct skcipher_request *req)
static int omap_des_init_tfm(struct crypto_skcipher *tfm)
{
struct omap_des_ctx *ctx = crypto_skcipher_ctx(tfm);
pr_debug("enter\n");
crypto_skcipher_set_reqsize(tfm, sizeof(struct omap_des_reqctx));
ctx->enginectx.op.do_one_request = omap_des_crypt_req;
return 0;
}
/* ********************** ALGS ************************************ */
static struct skcipher_alg algs_ecb_cbc[] = {
static struct skcipher_engine_alg algs_ecb_cbc[] = {
{
.base = {
.base.cra_name = "ecb(des)",
.base.cra_driver_name = "ecb-des-omap",
.base.cra_priority = 300,
......@@ -737,8 +731,11 @@ static struct skcipher_alg algs_ecb_cbc[] = {
.encrypt = omap_des_ecb_encrypt,
.decrypt = omap_des_ecb_decrypt,
.init = omap_des_init_tfm,
},
.op.do_one_request = omap_des_crypt_req,
},
{
.base = {
.base.cra_name = "cbc(des)",
.base.cra_driver_name = "cbc-des-omap",
.base.cra_priority = 300,
......@@ -755,8 +752,11 @@ static struct skcipher_alg algs_ecb_cbc[] = {
.encrypt = omap_des_cbc_encrypt,
.decrypt = omap_des_cbc_decrypt,
.init = omap_des_init_tfm,
},
.op.do_one_request = omap_des_crypt_req,
},
{
.base = {
.base.cra_name = "ecb(des3_ede)",
.base.cra_driver_name = "ecb-des3-omap",
.base.cra_priority = 300,
......@@ -772,8 +772,11 @@ static struct skcipher_alg algs_ecb_cbc[] = {
.encrypt = omap_des_ecb_encrypt,
.decrypt = omap_des_ecb_decrypt,
.init = omap_des_init_tfm,
},
.op.do_one_request = omap_des_crypt_req,
},
{
.base = {
.base.cra_name = "cbc(des3_ede)",
.base.cra_driver_name = "cbc-des3-omap",
.base.cra_priority = 300,
......@@ -790,6 +793,8 @@ static struct skcipher_alg algs_ecb_cbc[] = {
.encrypt = omap_des_cbc_encrypt,
.decrypt = omap_des_cbc_decrypt,
.init = omap_des_init_tfm,
},
.op.do_one_request = omap_des_crypt_req,
}
};
......@@ -947,7 +952,7 @@ static int omap_des_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct omap_des_dev *dd;
struct skcipher_alg *algp;
struct skcipher_engine_alg *algp;
struct resource *res;
int err = -ENOMEM, i, j, irq = -1;
u32 reg;
......@@ -1035,9 +1040,9 @@ static int omap_des_probe(struct platform_device *pdev)
for (j = 0; j < dd->pdata->algs_info[i].size; j++) {
algp = &dd->pdata->algs_info[i].algs_list[j];
pr_debug("reg alg: %s\n", algp->base.cra_name);
pr_debug("reg alg: %s\n", algp->base.base.cra_name);
err = crypto_register_skcipher(algp);
err = crypto_engine_register_skcipher(algp);
if (err)
goto err_algs;
......@@ -1050,7 +1055,7 @@ static int omap_des_probe(struct platform_device *pdev)
err_algs:
for (i = dd->pdata->algs_info_size - 1; i >= 0; i--)
for (j = dd->pdata->algs_info[i].registered - 1; j >= 0; j--)
crypto_unregister_skcipher(
crypto_engine_unregister_skcipher(
&dd->pdata->algs_info[i].algs_list[j]);
err_engine:
......@@ -1080,7 +1085,7 @@ static int omap_des_remove(struct platform_device *pdev)
for (i = dd->pdata->algs_info_size - 1; i >= 0; i--)
for (j = dd->pdata->algs_info[i].registered - 1; j >= 0; j--)
crypto_unregister_skcipher(
crypto_engine_unregister_skcipher(
&dd->pdata->algs_info[i].algs_list[j]);
tasklet_kill(&dd->done_task);
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment