Commit 9dbe3072 authored by Horia Geantă's avatar Horia Geantă Committed by Herbert Xu

crypto: caam/qi - ablkcipher -> skcipher conversion

Convert driver from deprecated ablkcipher API to skcipher.

Link: https://www.mail-archive.com/search?l=mid&q=20170728085622.GC19664@gondor.apana.org.auSigned-off-by: default avatarHoria Geantă <horia.geanta@nxp.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 5ca7badb
...@@ -693,14 +693,14 @@ static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, ...@@ -693,14 +693,14 @@ static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
/* skcipher_encrypt shared descriptor */ /* skcipher_encrypt shared descriptor */
desc = ctx->sh_desc_enc; desc = ctx->sh_desc_enc;
cnstr_shdsc_ablkcipher_encap(desc, &ctx->cdata, ivsize, is_rfc3686, cnstr_shdsc_skcipher_encap(desc, &ctx->cdata, ivsize, is_rfc3686,
ctx1_iv_off); ctx1_iv_off);
dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
desc_bytes(desc), ctx->dir); desc_bytes(desc), ctx->dir);
/* skcipher_decrypt shared descriptor */ /* skcipher_decrypt shared descriptor */
desc = ctx->sh_desc_dec; desc = ctx->sh_desc_dec;
cnstr_shdsc_ablkcipher_decap(desc, &ctx->cdata, ivsize, is_rfc3686, cnstr_shdsc_skcipher_decap(desc, &ctx->cdata, ivsize, is_rfc3686,
ctx1_iv_off); ctx1_iv_off);
dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
desc_bytes(desc), ctx->dir); desc_bytes(desc), ctx->dir);
...@@ -727,13 +727,13 @@ static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, ...@@ -727,13 +727,13 @@ static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
/* xts_skcipher_encrypt shared descriptor */ /* xts_skcipher_encrypt shared descriptor */
desc = ctx->sh_desc_enc; desc = ctx->sh_desc_enc;
cnstr_shdsc_xts_ablkcipher_encap(desc, &ctx->cdata); cnstr_shdsc_xts_skcipher_encap(desc, &ctx->cdata);
dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma, dma_sync_single_for_device(jrdev, ctx->sh_desc_enc_dma,
desc_bytes(desc), ctx->dir); desc_bytes(desc), ctx->dir);
/* xts_skcipher_decrypt shared descriptor */ /* xts_skcipher_decrypt shared descriptor */
desc = ctx->sh_desc_dec; desc = ctx->sh_desc_dec;
cnstr_shdsc_xts_ablkcipher_decap(desc, &ctx->cdata); cnstr_shdsc_xts_skcipher_decap(desc, &ctx->cdata);
dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma, dma_sync_single_for_device(jrdev, ctx->sh_desc_dec_dma,
desc_bytes(desc), ctx->dir); desc_bytes(desc), ctx->dir);
......
/* /*
* Shared descriptors for aead, ablkcipher algorithms * Shared descriptors for aead, skcipher algorithms
* *
* Copyright 2016 NXP * Copyright 2016-2018 NXP
*/ */
#include "compat.h" #include "compat.h"
...@@ -1212,11 +1212,8 @@ void cnstr_shdsc_rfc4543_decap(u32 * const desc, struct alginfo *cdata, ...@@ -1212,11 +1212,8 @@ void cnstr_shdsc_rfc4543_decap(u32 * const desc, struct alginfo *cdata,
} }
EXPORT_SYMBOL(cnstr_shdsc_rfc4543_decap); EXPORT_SYMBOL(cnstr_shdsc_rfc4543_decap);
/* /* For skcipher encrypt and decrypt, read from req->src and write to req->dst */
* For ablkcipher encrypt and decrypt, read from req->src and static inline void skcipher_append_src_dst(u32 *desc)
* write to req->dst
*/
static inline void ablkcipher_append_src_dst(u32 *desc)
{ {
append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ); append_math_add(desc, VARSEQOUTLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ); append_math_add(desc, VARSEQINLEN, SEQINLEN, REG0, CAAM_CMD_SZ);
...@@ -1226,7 +1223,7 @@ static inline void ablkcipher_append_src_dst(u32 *desc) ...@@ -1226,7 +1223,7 @@ static inline void ablkcipher_append_src_dst(u32 *desc)
} }
/** /**
* cnstr_shdsc_ablkcipher_encap - ablkcipher encapsulation shared descriptor * cnstr_shdsc_skcipher_encap - skcipher encapsulation shared descriptor
* @desc: pointer to buffer used for descriptor construction * @desc: pointer to buffer used for descriptor construction
* @cdata: pointer to block cipher transform definitions * @cdata: pointer to block cipher transform definitions
* Valid algorithm values - one of OP_ALG_ALGSEL_{AES, DES, 3DES} ANDed * Valid algorithm values - one of OP_ALG_ALGSEL_{AES, DES, 3DES} ANDed
...@@ -1235,7 +1232,7 @@ static inline void ablkcipher_append_src_dst(u32 *desc) ...@@ -1235,7 +1232,7 @@ static inline void ablkcipher_append_src_dst(u32 *desc)
* @is_rfc3686: true when ctr(aes) is wrapped by rfc3686 template * @is_rfc3686: true when ctr(aes) is wrapped by rfc3686 template
* @ctx1_iv_off: IV offset in CONTEXT1 register * @ctx1_iv_off: IV offset in CONTEXT1 register
*/ */
void cnstr_shdsc_ablkcipher_encap(u32 * const desc, struct alginfo *cdata, void cnstr_shdsc_skcipher_encap(u32 * const desc, struct alginfo *cdata,
unsigned int ivsize, const bool is_rfc3686, unsigned int ivsize, const bool is_rfc3686,
const u32 ctx1_iv_off) const u32 ctx1_iv_off)
{ {
...@@ -1280,18 +1277,18 @@ void cnstr_shdsc_ablkcipher_encap(u32 * const desc, struct alginfo *cdata, ...@@ -1280,18 +1277,18 @@ void cnstr_shdsc_ablkcipher_encap(u32 * const desc, struct alginfo *cdata,
OP_ALG_ENCRYPT); OP_ALG_ENCRYPT);
/* Perform operation */ /* Perform operation */
ablkcipher_append_src_dst(desc); skcipher_append_src_dst(desc);
#ifdef DEBUG #ifdef DEBUG
print_hex_dump(KERN_ERR, print_hex_dump(KERN_ERR,
"ablkcipher enc shdesc@" __stringify(__LINE__)": ", "skcipher enc shdesc@" __stringify(__LINE__)": ",
DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
#endif #endif
} }
EXPORT_SYMBOL(cnstr_shdsc_ablkcipher_encap); EXPORT_SYMBOL(cnstr_shdsc_skcipher_encap);
/** /**
* cnstr_shdsc_ablkcipher_decap - ablkcipher decapsulation shared descriptor * cnstr_shdsc_skcipher_decap - skcipher decapsulation shared descriptor
* @desc: pointer to buffer used for descriptor construction * @desc: pointer to buffer used for descriptor construction
* @cdata: pointer to block cipher transform definitions * @cdata: pointer to block cipher transform definitions
* Valid algorithm values - one of OP_ALG_ALGSEL_{AES, DES, 3DES} ANDed * Valid algorithm values - one of OP_ALG_ALGSEL_{AES, DES, 3DES} ANDed
...@@ -1300,7 +1297,7 @@ EXPORT_SYMBOL(cnstr_shdsc_ablkcipher_encap); ...@@ -1300,7 +1297,7 @@ EXPORT_SYMBOL(cnstr_shdsc_ablkcipher_encap);
* @is_rfc3686: true when ctr(aes) is wrapped by rfc3686 template * @is_rfc3686: true when ctr(aes) is wrapped by rfc3686 template
* @ctx1_iv_off: IV offset in CONTEXT1 register * @ctx1_iv_off: IV offset in CONTEXT1 register
*/ */
void cnstr_shdsc_ablkcipher_decap(u32 * const desc, struct alginfo *cdata, void cnstr_shdsc_skcipher_decap(u32 * const desc, struct alginfo *cdata,
unsigned int ivsize, const bool is_rfc3686, unsigned int ivsize, const bool is_rfc3686,
const u32 ctx1_iv_off) const u32 ctx1_iv_off)
{ {
...@@ -1348,24 +1345,23 @@ void cnstr_shdsc_ablkcipher_decap(u32 * const desc, struct alginfo *cdata, ...@@ -1348,24 +1345,23 @@ void cnstr_shdsc_ablkcipher_decap(u32 * const desc, struct alginfo *cdata,
append_dec_op1(desc, cdata->algtype); append_dec_op1(desc, cdata->algtype);
/* Perform operation */ /* Perform operation */
ablkcipher_append_src_dst(desc); skcipher_append_src_dst(desc);
#ifdef DEBUG #ifdef DEBUG
print_hex_dump(KERN_ERR, print_hex_dump(KERN_ERR,
"ablkcipher dec shdesc@" __stringify(__LINE__)": ", "skcipher dec shdesc@" __stringify(__LINE__)": ",
DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
#endif #endif
} }
EXPORT_SYMBOL(cnstr_shdsc_ablkcipher_decap); EXPORT_SYMBOL(cnstr_shdsc_skcipher_decap);
/** /**
* cnstr_shdsc_xts_ablkcipher_encap - xts ablkcipher encapsulation shared * cnstr_shdsc_xts_skcipher_encap - xts skcipher encapsulation shared descriptor
* descriptor
* @desc: pointer to buffer used for descriptor construction * @desc: pointer to buffer used for descriptor construction
* @cdata: pointer to block cipher transform definitions * @cdata: pointer to block cipher transform definitions
* Valid algorithm values - OP_ALG_ALGSEL_AES ANDed with OP_ALG_AAI_XTS. * Valid algorithm values - OP_ALG_ALGSEL_AES ANDed with OP_ALG_AAI_XTS.
*/ */
void cnstr_shdsc_xts_ablkcipher_encap(u32 * const desc, struct alginfo *cdata) void cnstr_shdsc_xts_skcipher_encap(u32 * const desc, struct alginfo *cdata)
{ {
__be64 sector_size = cpu_to_be64(512); __be64 sector_size = cpu_to_be64(512);
u32 *key_jump_cmd; u32 *key_jump_cmd;
...@@ -1400,24 +1396,23 @@ void cnstr_shdsc_xts_ablkcipher_encap(u32 * const desc, struct alginfo *cdata) ...@@ -1400,24 +1396,23 @@ void cnstr_shdsc_xts_ablkcipher_encap(u32 * const desc, struct alginfo *cdata)
OP_ALG_ENCRYPT); OP_ALG_ENCRYPT);
/* Perform operation */ /* Perform operation */
ablkcipher_append_src_dst(desc); skcipher_append_src_dst(desc);
#ifdef DEBUG #ifdef DEBUG
print_hex_dump(KERN_ERR, print_hex_dump(KERN_ERR,
"xts ablkcipher enc shdesc@" __stringify(__LINE__) ": ", "xts skcipher enc shdesc@" __stringify(__LINE__) ": ",
DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
#endif #endif
} }
EXPORT_SYMBOL(cnstr_shdsc_xts_ablkcipher_encap); EXPORT_SYMBOL(cnstr_shdsc_xts_skcipher_encap);
/** /**
* cnstr_shdsc_xts_ablkcipher_decap - xts ablkcipher decapsulation shared * cnstr_shdsc_xts_skcipher_decap - xts skcipher decapsulation shared descriptor
* descriptor
* @desc: pointer to buffer used for descriptor construction * @desc: pointer to buffer used for descriptor construction
* @cdata: pointer to block cipher transform definitions * @cdata: pointer to block cipher transform definitions
* Valid algorithm values - OP_ALG_ALGSEL_AES ANDed with OP_ALG_AAI_XTS. * Valid algorithm values - OP_ALG_ALGSEL_AES ANDed with OP_ALG_AAI_XTS.
*/ */
void cnstr_shdsc_xts_ablkcipher_decap(u32 * const desc, struct alginfo *cdata) void cnstr_shdsc_xts_skcipher_decap(u32 * const desc, struct alginfo *cdata)
{ {
__be64 sector_size = cpu_to_be64(512); __be64 sector_size = cpu_to_be64(512);
u32 *key_jump_cmd; u32 *key_jump_cmd;
...@@ -1451,15 +1446,15 @@ void cnstr_shdsc_xts_ablkcipher_decap(u32 * const desc, struct alginfo *cdata) ...@@ -1451,15 +1446,15 @@ void cnstr_shdsc_xts_ablkcipher_decap(u32 * const desc, struct alginfo *cdata)
append_dec_op1(desc, cdata->algtype); append_dec_op1(desc, cdata->algtype);
/* Perform operation */ /* Perform operation */
ablkcipher_append_src_dst(desc); skcipher_append_src_dst(desc);
#ifdef DEBUG #ifdef DEBUG
print_hex_dump(KERN_ERR, print_hex_dump(KERN_ERR,
"xts ablkcipher dec shdesc@" __stringify(__LINE__) ": ", "xts skcipher dec shdesc@" __stringify(__LINE__) ": ",
DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1); DUMP_PREFIX_ADDRESS, 16, 4, desc, desc_bytes(desc), 1);
#endif #endif
} }
EXPORT_SYMBOL(cnstr_shdsc_xts_ablkcipher_decap); EXPORT_SYMBOL(cnstr_shdsc_xts_skcipher_decap);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("FSL CAAM descriptor support"); MODULE_DESCRIPTION("FSL CAAM descriptor support");
......
/* SPDX-License-Identifier: GPL-2.0 */ /* SPDX-License-Identifier: GPL-2.0 */
/* /*
* Shared descriptors for aead, ablkcipher algorithms * Shared descriptors for aead, skcipher algorithms
* *
* Copyright 2016 NXP * Copyright 2016 NXP
*/ */
...@@ -42,10 +42,10 @@ ...@@ -42,10 +42,10 @@
#define DESC_QI_RFC4543_ENC_LEN (DESC_RFC4543_ENC_LEN + 4 * CAAM_CMD_SZ) #define DESC_QI_RFC4543_ENC_LEN (DESC_RFC4543_ENC_LEN + 4 * CAAM_CMD_SZ)
#define DESC_QI_RFC4543_DEC_LEN (DESC_RFC4543_DEC_LEN + 4 * CAAM_CMD_SZ) #define DESC_QI_RFC4543_DEC_LEN (DESC_RFC4543_DEC_LEN + 4 * CAAM_CMD_SZ)
#define DESC_ABLKCIPHER_BASE (3 * CAAM_CMD_SZ) #define DESC_SKCIPHER_BASE (3 * CAAM_CMD_SZ)
#define DESC_ABLKCIPHER_ENC_LEN (DESC_ABLKCIPHER_BASE + \ #define DESC_SKCIPHER_ENC_LEN (DESC_SKCIPHER_BASE + \
20 * CAAM_CMD_SZ) 20 * CAAM_CMD_SZ)
#define DESC_ABLKCIPHER_DEC_LEN (DESC_ABLKCIPHER_BASE + \ #define DESC_SKCIPHER_DEC_LEN (DESC_SKCIPHER_BASE + \
15 * CAAM_CMD_SZ) 15 * CAAM_CMD_SZ)
void cnstr_shdsc_aead_null_encap(u32 * const desc, struct alginfo *adata, void cnstr_shdsc_aead_null_encap(u32 * const desc, struct alginfo *adata,
...@@ -96,16 +96,16 @@ void cnstr_shdsc_rfc4543_decap(u32 * const desc, struct alginfo *cdata, ...@@ -96,16 +96,16 @@ void cnstr_shdsc_rfc4543_decap(u32 * const desc, struct alginfo *cdata,
unsigned int ivsize, unsigned int icvsize, unsigned int ivsize, unsigned int icvsize,
const bool is_qi); const bool is_qi);
void cnstr_shdsc_ablkcipher_encap(u32 * const desc, struct alginfo *cdata, void cnstr_shdsc_skcipher_encap(u32 * const desc, struct alginfo *cdata,
unsigned int ivsize, const bool is_rfc3686, unsigned int ivsize, const bool is_rfc3686,
const u32 ctx1_iv_off); const u32 ctx1_iv_off);
void cnstr_shdsc_ablkcipher_decap(u32 * const desc, struct alginfo *cdata, void cnstr_shdsc_skcipher_decap(u32 * const desc, struct alginfo *cdata,
unsigned int ivsize, const bool is_rfc3686, unsigned int ivsize, const bool is_rfc3686,
const u32 ctx1_iv_off); const u32 ctx1_iv_off);
void cnstr_shdsc_xts_ablkcipher_encap(u32 * const desc, struct alginfo *cdata); void cnstr_shdsc_xts_skcipher_encap(u32 * const desc, struct alginfo *cdata);
void cnstr_shdsc_xts_ablkcipher_decap(u32 * const desc, struct alginfo *cdata); void cnstr_shdsc_xts_skcipher_decap(u32 * const desc, struct alginfo *cdata);
#endif /* _CAAMALG_DESC_H_ */ #endif /* _CAAMALG_DESC_H_ */
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* Based on caamalg.c * Based on caamalg.c
* *
* Copyright 2013-2016 Freescale Semiconductor, Inc. * Copyright 2013-2016 Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP * Copyright 2016-2018 NXP
*/ */
#include "compat.h" #include "compat.h"
...@@ -43,6 +43,12 @@ struct caam_aead_alg { ...@@ -43,6 +43,12 @@ struct caam_aead_alg {
bool registered; bool registered;
}; };
struct caam_skcipher_alg {
struct skcipher_alg skcipher;
struct caam_alg_entry caam;
bool registered;
};
/* /*
* per-session context * per-session context
*/ */
...@@ -588,18 +594,19 @@ static int rfc4543_setkey(struct crypto_aead *aead, ...@@ -588,18 +594,19 @@ static int rfc4543_setkey(struct crypto_aead *aead,
return 0; return 0;
} }
static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher, static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
const u8 *key, unsigned int keylen) unsigned int keylen)
{ {
struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher); struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher);
struct crypto_tfm *tfm = crypto_ablkcipher_tfm(ablkcipher); struct caam_skcipher_alg *alg =
const char *alg_name = crypto_tfm_alg_name(tfm); container_of(crypto_skcipher_alg(skcipher), typeof(*alg),
skcipher);
struct device *jrdev = ctx->jrdev; struct device *jrdev = ctx->jrdev;
unsigned int ivsize = crypto_ablkcipher_ivsize(ablkcipher); unsigned int ivsize = crypto_skcipher_ivsize(skcipher);
u32 ctx1_iv_off = 0; u32 ctx1_iv_off = 0;
const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) == const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
OP_ALG_AAI_CTR_MOD128); OP_ALG_AAI_CTR_MOD128);
const bool is_rfc3686 = (ctr_mode && strstr(alg_name, "rfc3686")); const bool is_rfc3686 = alg->caam.rfc3686;
int ret = 0; int ret = 0;
#ifdef DEBUG #ifdef DEBUG
...@@ -628,10 +635,10 @@ static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher, ...@@ -628,10 +635,10 @@ static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
ctx->cdata.key_virt = key; ctx->cdata.key_virt = key;
ctx->cdata.key_inline = true; ctx->cdata.key_inline = true;
/* ablkcipher encrypt, decrypt shared descriptors */ /* skcipher encrypt, decrypt shared descriptors */
cnstr_shdsc_ablkcipher_encap(ctx->sh_desc_enc, &ctx->cdata, ivsize, cnstr_shdsc_skcipher_encap(ctx->sh_desc_enc, &ctx->cdata, ivsize,
is_rfc3686, ctx1_iv_off); is_rfc3686, ctx1_iv_off);
cnstr_shdsc_ablkcipher_decap(ctx->sh_desc_dec, &ctx->cdata, ivsize, cnstr_shdsc_skcipher_decap(ctx->sh_desc_dec, &ctx->cdata, ivsize,
is_rfc3686, ctx1_iv_off); is_rfc3686, ctx1_iv_off);
/* Now update the driver contexts with the new shared descriptor */ /* Now update the driver contexts with the new shared descriptor */
...@@ -655,14 +662,14 @@ static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher, ...@@ -655,14 +662,14 @@ static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
return ret; return ret;
badkey: badkey:
crypto_ablkcipher_set_flags(ablkcipher, CRYPTO_TFM_RES_BAD_KEY_LEN); crypto_skcipher_set_flags(skcipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
static int xts_ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher, static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
const u8 *key, unsigned int keylen) unsigned int keylen)
{ {
struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher); struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher);
struct device *jrdev = ctx->jrdev; struct device *jrdev = ctx->jrdev;
int ret = 0; int ret = 0;
...@@ -675,9 +682,9 @@ static int xts_ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher, ...@@ -675,9 +682,9 @@ static int xts_ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
ctx->cdata.key_virt = key; ctx->cdata.key_virt = key;
ctx->cdata.key_inline = true; ctx->cdata.key_inline = true;
/* xts ablkcipher encrypt, decrypt shared descriptors */ /* xts skcipher encrypt, decrypt shared descriptors */
cnstr_shdsc_xts_ablkcipher_encap(ctx->sh_desc_enc, &ctx->cdata); cnstr_shdsc_xts_skcipher_encap(ctx->sh_desc_enc, &ctx->cdata);
cnstr_shdsc_xts_ablkcipher_decap(ctx->sh_desc_dec, &ctx->cdata); cnstr_shdsc_xts_skcipher_decap(ctx->sh_desc_dec, &ctx->cdata);
/* Now update the driver contexts with the new shared descriptor */ /* Now update the driver contexts with the new shared descriptor */
if (ctx->drv_ctx[ENCRYPT]) { if (ctx->drv_ctx[ENCRYPT]) {
...@@ -700,7 +707,7 @@ static int xts_ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher, ...@@ -700,7 +707,7 @@ static int xts_ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
return ret; return ret;
badkey: badkey:
crypto_ablkcipher_set_flags(ablkcipher, CRYPTO_TFM_RES_BAD_KEY_LEN); crypto_skcipher_set_flags(skcipher, CRYPTO_TFM_RES_BAD_KEY_LEN);
return -EINVAL; return -EINVAL;
} }
...@@ -729,7 +736,7 @@ struct aead_edesc { ...@@ -729,7 +736,7 @@ struct aead_edesc {
}; };
/* /*
* ablkcipher_edesc - s/w-extended ablkcipher descriptor * skcipher_edesc - s/w-extended skcipher descriptor
* @src_nents: number of segments in input scatterlist * @src_nents: number of segments in input scatterlist
* @dst_nents: number of segments in output scatterlist * @dst_nents: number of segments in output scatterlist
* @iv_dma: dma address of iv for checking continuity and link table * @iv_dma: dma address of iv for checking continuity and link table
...@@ -738,7 +745,7 @@ struct aead_edesc { ...@@ -738,7 +745,7 @@ struct aead_edesc {
* @drv_req: driver-specific request structure * @drv_req: driver-specific request structure
* @sgt: the h/w link table, followed by IV * @sgt: the h/w link table, followed by IV
*/ */
struct ablkcipher_edesc { struct skcipher_edesc {
int src_nents; int src_nents;
int dst_nents; int dst_nents;
dma_addr_t iv_dma; dma_addr_t iv_dma;
...@@ -817,12 +824,11 @@ static void aead_unmap(struct device *dev, ...@@ -817,12 +824,11 @@ static void aead_unmap(struct device *dev,
dma_unmap_single(dev, edesc->assoclen_dma, 4, DMA_TO_DEVICE); dma_unmap_single(dev, edesc->assoclen_dma, 4, DMA_TO_DEVICE);
} }
static void ablkcipher_unmap(struct device *dev, static void skcipher_unmap(struct device *dev, struct skcipher_edesc *edesc,
struct ablkcipher_edesc *edesc, struct skcipher_request *req)
struct ablkcipher_request *req)
{ {
struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req); struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
int ivsize = crypto_ablkcipher_ivsize(ablkcipher); int ivsize = crypto_skcipher_ivsize(skcipher);
caam_unmap(dev, req->src, req->dst, edesc->src_nents, edesc->dst_nents, caam_unmap(dev, req->src, req->dst, edesc->src_nents, edesc->dst_nents,
edesc->iv_dma, ivsize, edesc->qm_sg_dma, edesc->qm_sg_bytes); edesc->iv_dma, ivsize, edesc->qm_sg_dma, edesc->qm_sg_bytes);
...@@ -1118,14 +1124,14 @@ static int ipsec_gcm_decrypt(struct aead_request *req) ...@@ -1118,14 +1124,14 @@ static int ipsec_gcm_decrypt(struct aead_request *req)
return aead_crypt(req, false); return aead_crypt(req, false);
} }
static void ablkcipher_done(struct caam_drv_req *drv_req, u32 status) static void skcipher_done(struct caam_drv_req *drv_req, u32 status)
{ {
struct ablkcipher_edesc *edesc; struct skcipher_edesc *edesc;
struct ablkcipher_request *req = drv_req->app_ctx; struct skcipher_request *req = drv_req->app_ctx;
struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req); struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
struct caam_ctx *caam_ctx = crypto_ablkcipher_ctx(ablkcipher); struct caam_ctx *caam_ctx = crypto_skcipher_ctx(skcipher);
struct device *qidev = caam_ctx->qidev; struct device *qidev = caam_ctx->qidev;
int ivsize = crypto_ablkcipher_ivsize(ablkcipher); int ivsize = crypto_skcipher_ivsize(skcipher);
#ifdef DEBUG #ifdef DEBUG
dev_err(qidev, "%s %d: status 0x%x\n", __func__, __LINE__, status); dev_err(qidev, "%s %d: status 0x%x\n", __func__, __LINE__, status);
...@@ -1138,60 +1144,60 @@ static void ablkcipher_done(struct caam_drv_req *drv_req, u32 status) ...@@ -1138,60 +1144,60 @@ static void ablkcipher_done(struct caam_drv_req *drv_req, u32 status)
#ifdef DEBUG #ifdef DEBUG
print_hex_dump(KERN_ERR, "dstiv @" __stringify(__LINE__)": ", print_hex_dump(KERN_ERR, "dstiv @" __stringify(__LINE__)": ",
DUMP_PREFIX_ADDRESS, 16, 4, req->info, DUMP_PREFIX_ADDRESS, 16, 4, req->iv,
edesc->src_nents > 1 ? 100 : ivsize, 1); edesc->src_nents > 1 ? 100 : ivsize, 1);
caam_dump_sg(KERN_ERR, "dst @" __stringify(__LINE__)": ", caam_dump_sg(KERN_ERR, "dst @" __stringify(__LINE__)": ",
DUMP_PREFIX_ADDRESS, 16, 4, req->dst, DUMP_PREFIX_ADDRESS, 16, 4, req->dst,
edesc->dst_nents > 1 ? 100 : req->nbytes, 1); edesc->dst_nents > 1 ? 100 : req->cryptlen, 1);
#endif #endif
ablkcipher_unmap(qidev, edesc, req); skcipher_unmap(qidev, edesc, req);
/* /*
* The crypto API expects us to set the IV (req->info) to the last * The crypto API expects us to set the IV (req->iv) to the last
* ciphertext block. This is used e.g. by the CTS mode. * ciphertext block. This is used e.g. by the CTS mode.
*/ */
if (edesc->drv_req.drv_ctx->op_type == ENCRYPT) if (edesc->drv_req.drv_ctx->op_type == ENCRYPT)
scatterwalk_map_and_copy(req->info, req->dst, req->nbytes - scatterwalk_map_and_copy(req->iv, req->dst, req->cryptlen -
ivsize, ivsize, 0); ivsize, ivsize, 0);
qi_cache_free(edesc); qi_cache_free(edesc);
ablkcipher_request_complete(req, status); skcipher_request_complete(req, status);
} }
static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request static struct skcipher_edesc *skcipher_edesc_alloc(struct skcipher_request *req,
*req, bool encrypt) bool encrypt)
{ {
struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req); struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher); struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher);
struct device *qidev = ctx->qidev; struct device *qidev = ctx->qidev;
gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
GFP_KERNEL : GFP_ATOMIC; GFP_KERNEL : GFP_ATOMIC;
int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0; int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0;
struct ablkcipher_edesc *edesc; struct skcipher_edesc *edesc;
dma_addr_t iv_dma; dma_addr_t iv_dma;
u8 *iv; u8 *iv;
int ivsize = crypto_ablkcipher_ivsize(ablkcipher); int ivsize = crypto_skcipher_ivsize(skcipher);
int dst_sg_idx, qm_sg_ents, qm_sg_bytes; int dst_sg_idx, qm_sg_ents, qm_sg_bytes;
struct qm_sg_entry *sg_table, *fd_sgt; struct qm_sg_entry *sg_table, *fd_sgt;
struct caam_drv_ctx *drv_ctx; struct caam_drv_ctx *drv_ctx;
drv_ctx = get_drv_ctx(ctx, encrypt ? ENCRYPT : DECRYPT); drv_ctx = get_drv_ctx(ctx, encrypt ? ENCRYPT : DECRYPT);
if (unlikely(IS_ERR_OR_NULL(drv_ctx))) if (unlikely(IS_ERR_OR_NULL(drv_ctx)))
return (struct ablkcipher_edesc *)drv_ctx; return (struct skcipher_edesc *)drv_ctx;
src_nents = sg_nents_for_len(req->src, req->nbytes); src_nents = sg_nents_for_len(req->src, req->cryptlen);
if (unlikely(src_nents < 0)) { if (unlikely(src_nents < 0)) {
dev_err(qidev, "Insufficient bytes (%d) in src S/G\n", dev_err(qidev, "Insufficient bytes (%d) in src S/G\n",
req->nbytes); req->cryptlen);
return ERR_PTR(src_nents); return ERR_PTR(src_nents);
} }
if (unlikely(req->src != req->dst)) { if (unlikely(req->src != req->dst)) {
dst_nents = sg_nents_for_len(req->dst, req->nbytes); dst_nents = sg_nents_for_len(req->dst, req->cryptlen);
if (unlikely(dst_nents < 0)) { if (unlikely(dst_nents < 0)) {
dev_err(qidev, "Insufficient bytes (%d) in dst S/G\n", dev_err(qidev, "Insufficient bytes (%d) in dst S/G\n",
req->nbytes); req->cryptlen);
return ERR_PTR(dst_nents); return ERR_PTR(dst_nents);
} }
...@@ -1223,7 +1229,7 @@ static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request ...@@ -1223,7 +1229,7 @@ static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request
qm_sg_ents += mapped_dst_nents > 1 ? mapped_dst_nents : 0; qm_sg_ents += mapped_dst_nents > 1 ? mapped_dst_nents : 0;
qm_sg_bytes = qm_sg_ents * sizeof(struct qm_sg_entry); qm_sg_bytes = qm_sg_ents * sizeof(struct qm_sg_entry);
if (unlikely(offsetof(struct ablkcipher_edesc, sgt) + qm_sg_bytes + if (unlikely(offsetof(struct skcipher_edesc, sgt) + qm_sg_bytes +
ivsize > CAAM_QI_MEMCACHE_SIZE)) { ivsize > CAAM_QI_MEMCACHE_SIZE)) {
dev_err(qidev, "No space for %d S/G entries and/or %dB IV\n", dev_err(qidev, "No space for %d S/G entries and/or %dB IV\n",
qm_sg_ents, ivsize); qm_sg_ents, ivsize);
...@@ -1244,7 +1250,7 @@ static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request ...@@ -1244,7 +1250,7 @@ static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request
/* Make sure IV is located in a DMAable area */ /* Make sure IV is located in a DMAable area */
sg_table = &edesc->sgt[0]; sg_table = &edesc->sgt[0];
iv = (u8 *)(sg_table + qm_sg_ents); iv = (u8 *)(sg_table + qm_sg_ents);
memcpy(iv, req->info, ivsize); memcpy(iv, req->iv, ivsize);
iv_dma = dma_map_single(qidev, iv, ivsize, DMA_TO_DEVICE); iv_dma = dma_map_single(qidev, iv, ivsize, DMA_TO_DEVICE);
if (dma_mapping_error(qidev, iv_dma)) { if (dma_mapping_error(qidev, iv_dma)) {
...@@ -1260,7 +1266,7 @@ static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request ...@@ -1260,7 +1266,7 @@ static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request
edesc->iv_dma = iv_dma; edesc->iv_dma = iv_dma;
edesc->qm_sg_bytes = qm_sg_bytes; edesc->qm_sg_bytes = qm_sg_bytes;
edesc->drv_req.app_ctx = req; edesc->drv_req.app_ctx = req;
edesc->drv_req.cbk = ablkcipher_done; edesc->drv_req.cbk = skcipher_done;
edesc->drv_req.drv_ctx = drv_ctx; edesc->drv_req.drv_ctx = drv_ctx;
dma_to_qm_sg_one(sg_table, iv_dma, ivsize, 0); dma_to_qm_sg_one(sg_table, iv_dma, ivsize, 0);
...@@ -1283,169 +1289,172 @@ static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request ...@@ -1283,169 +1289,172 @@ static struct ablkcipher_edesc *ablkcipher_edesc_alloc(struct ablkcipher_request
fd_sgt = &edesc->drv_req.fd_sgt[0]; fd_sgt = &edesc->drv_req.fd_sgt[0];
dma_to_qm_sg_one_last_ext(&fd_sgt[1], edesc->qm_sg_dma, dma_to_qm_sg_one_last_ext(&fd_sgt[1], edesc->qm_sg_dma,
ivsize + req->nbytes, 0); ivsize + req->cryptlen, 0);
if (req->src == req->dst) { if (req->src == req->dst) {
dma_to_qm_sg_one_ext(&fd_sgt[0], edesc->qm_sg_dma + dma_to_qm_sg_one_ext(&fd_sgt[0], edesc->qm_sg_dma +
sizeof(*sg_table), req->nbytes, 0); sizeof(*sg_table), req->cryptlen, 0);
} else if (mapped_dst_nents > 1) { } else if (mapped_dst_nents > 1) {
dma_to_qm_sg_one_ext(&fd_sgt[0], edesc->qm_sg_dma + dst_sg_idx * dma_to_qm_sg_one_ext(&fd_sgt[0], edesc->qm_sg_dma + dst_sg_idx *
sizeof(*sg_table), req->nbytes, 0); sizeof(*sg_table), req->cryptlen, 0);
} else { } else {
dma_to_qm_sg_one(&fd_sgt[0], sg_dma_address(req->dst), dma_to_qm_sg_one(&fd_sgt[0], sg_dma_address(req->dst),
req->nbytes, 0); req->cryptlen, 0);
} }
return edesc; return edesc;
} }
static inline int ablkcipher_crypt(struct ablkcipher_request *req, bool encrypt) static inline int skcipher_crypt(struct skcipher_request *req, bool encrypt)
{ {
struct ablkcipher_edesc *edesc; struct skcipher_edesc *edesc;
struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req); struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher); struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher);
int ivsize = crypto_ablkcipher_ivsize(ablkcipher); int ivsize = crypto_skcipher_ivsize(skcipher);
int ret; int ret;
if (unlikely(caam_congested)) if (unlikely(caam_congested))
return -EAGAIN; return -EAGAIN;
/* allocate extended descriptor */ /* allocate extended descriptor */
edesc = ablkcipher_edesc_alloc(req, encrypt); edesc = skcipher_edesc_alloc(req, encrypt);
if (IS_ERR(edesc)) if (IS_ERR(edesc))
return PTR_ERR(edesc); return PTR_ERR(edesc);
/* /*
* The crypto API expects us to set the IV (req->info) to the last * The crypto API expects us to set the IV (req->iv) to the last
* ciphertext block. * ciphertext block.
*/ */
if (!encrypt) if (!encrypt)
scatterwalk_map_and_copy(req->info, req->src, req->nbytes - scatterwalk_map_and_copy(req->iv, req->src, req->cryptlen -
ivsize, ivsize, 0); ivsize, ivsize, 0);
ret = caam_qi_enqueue(ctx->qidev, &edesc->drv_req); ret = caam_qi_enqueue(ctx->qidev, &edesc->drv_req);
if (!ret) { if (!ret) {
ret = -EINPROGRESS; ret = -EINPROGRESS;
} else { } else {
ablkcipher_unmap(ctx->qidev, edesc, req); skcipher_unmap(ctx->qidev, edesc, req);
qi_cache_free(edesc); qi_cache_free(edesc);
} }
return ret; return ret;
} }
static int ablkcipher_encrypt(struct ablkcipher_request *req) static int skcipher_encrypt(struct skcipher_request *req)
{ {
return ablkcipher_crypt(req, true); return skcipher_crypt(req, true);
} }
static int ablkcipher_decrypt(struct ablkcipher_request *req) static int skcipher_decrypt(struct skcipher_request *req)
{ {
return ablkcipher_crypt(req, false); return skcipher_crypt(req, false);
} }
#define template_ablkcipher template_u.ablkcipher static struct caam_skcipher_alg driver_algs[] = {
struct caam_alg_template {
char name[CRYPTO_MAX_ALG_NAME];
char driver_name[CRYPTO_MAX_ALG_NAME];
unsigned int blocksize;
u32 type;
union {
struct ablkcipher_alg ablkcipher;
} template_u;
u32 class1_alg_type;
u32 class2_alg_type;
};
static struct caam_alg_template driver_algs[] = {
/* ablkcipher descriptor */
{ {
.name = "cbc(aes)", .skcipher = {
.driver_name = "cbc-aes-caam-qi", .base = {
.blocksize = AES_BLOCK_SIZE, .cra_name = "cbc(aes)",
.template_ablkcipher = { .cra_driver_name = "cbc-aes-caam-qi",
.setkey = ablkcipher_setkey, .cra_blocksize = AES_BLOCK_SIZE,
.encrypt = ablkcipher_encrypt, },
.decrypt = ablkcipher_decrypt, .setkey = skcipher_setkey,
.encrypt = skcipher_encrypt,
.decrypt = skcipher_decrypt,
.min_keysize = AES_MIN_KEY_SIZE, .min_keysize = AES_MIN_KEY_SIZE,
.max_keysize = AES_MAX_KEY_SIZE, .max_keysize = AES_MAX_KEY_SIZE,
.ivsize = AES_BLOCK_SIZE, .ivsize = AES_BLOCK_SIZE,
}, },
.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC, .caam.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CBC,
}, },
{ {
.name = "cbc(des3_ede)", .skcipher = {
.driver_name = "cbc-3des-caam-qi", .base = {
.blocksize = DES3_EDE_BLOCK_SIZE, .cra_name = "cbc(des3_ede)",
.template_ablkcipher = { .cra_driver_name = "cbc-3des-caam-qi",
.setkey = ablkcipher_setkey, .cra_blocksize = DES3_EDE_BLOCK_SIZE,
.encrypt = ablkcipher_encrypt, },
.decrypt = ablkcipher_decrypt, .setkey = skcipher_setkey,
.encrypt = skcipher_encrypt,
.decrypt = skcipher_decrypt,
.min_keysize = DES3_EDE_KEY_SIZE, .min_keysize = DES3_EDE_KEY_SIZE,
.max_keysize = DES3_EDE_KEY_SIZE, .max_keysize = DES3_EDE_KEY_SIZE,
.ivsize = DES3_EDE_BLOCK_SIZE, .ivsize = DES3_EDE_BLOCK_SIZE,
}, },
.class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC, .caam.class1_alg_type = OP_ALG_ALGSEL_3DES | OP_ALG_AAI_CBC,
}, },
{ {
.name = "cbc(des)", .skcipher = {
.driver_name = "cbc-des-caam-qi", .base = {
.blocksize = DES_BLOCK_SIZE, .cra_name = "cbc(des)",
.template_ablkcipher = { .cra_driver_name = "cbc-des-caam-qi",
.setkey = ablkcipher_setkey, .cra_blocksize = DES_BLOCK_SIZE,
.encrypt = ablkcipher_encrypt, },
.decrypt = ablkcipher_decrypt, .setkey = skcipher_setkey,
.encrypt = skcipher_encrypt,
.decrypt = skcipher_decrypt,
.min_keysize = DES_KEY_SIZE, .min_keysize = DES_KEY_SIZE,
.max_keysize = DES_KEY_SIZE, .max_keysize = DES_KEY_SIZE,
.ivsize = DES_BLOCK_SIZE, .ivsize = DES_BLOCK_SIZE,
}, },
.class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, .caam.class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC,
}, },
{ {
.name = "ctr(aes)", .skcipher = {
.driver_name = "ctr-aes-caam-qi", .base = {
.blocksize = 1, .cra_name = "ctr(aes)",
.template_ablkcipher = { .cra_driver_name = "ctr-aes-caam-qi",
.setkey = ablkcipher_setkey, .cra_blocksize = 1,
.encrypt = ablkcipher_encrypt, },
.decrypt = ablkcipher_decrypt, .setkey = skcipher_setkey,
.geniv = "chainiv", .encrypt = skcipher_encrypt,
.decrypt = skcipher_decrypt,
.min_keysize = AES_MIN_KEY_SIZE, .min_keysize = AES_MIN_KEY_SIZE,
.max_keysize = AES_MAX_KEY_SIZE, .max_keysize = AES_MAX_KEY_SIZE,
.ivsize = AES_BLOCK_SIZE, .ivsize = AES_BLOCK_SIZE,
.chunksize = AES_BLOCK_SIZE,
}, },
.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CTR_MOD128, .caam.class1_alg_type = OP_ALG_ALGSEL_AES |
OP_ALG_AAI_CTR_MOD128,
}, },
{ {
.name = "rfc3686(ctr(aes))", .skcipher = {
.driver_name = "rfc3686-ctr-aes-caam-qi", .base = {
.blocksize = 1, .cra_name = "rfc3686(ctr(aes))",
.template_ablkcipher = { .cra_driver_name = "rfc3686-ctr-aes-caam-qi",
.setkey = ablkcipher_setkey, .cra_blocksize = 1,
.encrypt = ablkcipher_encrypt, },
.decrypt = ablkcipher_decrypt, .setkey = skcipher_setkey,
.encrypt = skcipher_encrypt,
.decrypt = skcipher_decrypt,
.min_keysize = AES_MIN_KEY_SIZE + .min_keysize = AES_MIN_KEY_SIZE +
CTR_RFC3686_NONCE_SIZE, CTR_RFC3686_NONCE_SIZE,
.max_keysize = AES_MAX_KEY_SIZE + .max_keysize = AES_MAX_KEY_SIZE +
CTR_RFC3686_NONCE_SIZE, CTR_RFC3686_NONCE_SIZE,
.ivsize = CTR_RFC3686_IV_SIZE, .ivsize = CTR_RFC3686_IV_SIZE,
.chunksize = AES_BLOCK_SIZE,
},
.caam = {
.class1_alg_type = OP_ALG_ALGSEL_AES |
OP_ALG_AAI_CTR_MOD128,
.rfc3686 = true,
}, },
.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CTR_MOD128,
}, },
{ {
.name = "xts(aes)", .skcipher = {
.driver_name = "xts-aes-caam-qi", .base = {
.blocksize = AES_BLOCK_SIZE, .cra_name = "xts(aes)",
.template_ablkcipher = { .cra_driver_name = "xts-aes-caam-qi",
.setkey = xts_ablkcipher_setkey, .cra_blocksize = AES_BLOCK_SIZE,
.encrypt = ablkcipher_encrypt, },
.decrypt = ablkcipher_decrypt, .setkey = xts_skcipher_setkey,
.geniv = "eseqiv", .encrypt = skcipher_encrypt,
.decrypt = skcipher_decrypt,
.min_keysize = 2 * AES_MIN_KEY_SIZE, .min_keysize = 2 * AES_MIN_KEY_SIZE,
.max_keysize = 2 * AES_MAX_KEY_SIZE, .max_keysize = 2 * AES_MAX_KEY_SIZE,
.ivsize = AES_BLOCK_SIZE, .ivsize = AES_BLOCK_SIZE,
}, },
.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_XTS, .caam.class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_XTS,
}, },
}; };
...@@ -2317,12 +2326,6 @@ static struct caam_aead_alg driver_aeads[] = { ...@@ -2317,12 +2326,6 @@ static struct caam_aead_alg driver_aeads[] = {
}, },
}; };
struct caam_crypto_alg {
struct list_head entry;
struct crypto_alg crypto_alg;
struct caam_alg_entry caam;
};
static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam, static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam,
bool uses_dkp) bool uses_dkp)
{ {
...@@ -2365,14 +2368,14 @@ static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam, ...@@ -2365,14 +2368,14 @@ static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam,
return 0; return 0;
} }
static int caam_cra_init(struct crypto_tfm *tfm) static int caam_cra_init(struct crypto_skcipher *tfm)
{ {
struct crypto_alg *alg = tfm->__crt_alg; struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
struct caam_crypto_alg *caam_alg = container_of(alg, typeof(*caam_alg), struct caam_skcipher_alg *caam_alg =
crypto_alg); container_of(alg, typeof(*caam_alg), skcipher);
struct caam_ctx *ctx = crypto_tfm_ctx(tfm);
return caam_init_common(ctx, &caam_alg->caam, false); return caam_init_common(crypto_skcipher_ctx(tfm), &caam_alg->caam,
false);
} }
static int caam_aead_init(struct crypto_aead *tfm) static int caam_aead_init(struct crypto_aead *tfm)
...@@ -2396,9 +2399,9 @@ static void caam_exit_common(struct caam_ctx *ctx) ...@@ -2396,9 +2399,9 @@ static void caam_exit_common(struct caam_ctx *ctx)
caam_jr_free(ctx->jrdev); caam_jr_free(ctx->jrdev);
} }
static void caam_cra_exit(struct crypto_tfm *tfm) static void caam_cra_exit(struct crypto_skcipher *tfm)
{ {
caam_exit_common(crypto_tfm_ctx(tfm)); caam_exit_common(crypto_skcipher_ctx(tfm));
} }
static void caam_aead_exit(struct crypto_aead *tfm) static void caam_aead_exit(struct crypto_aead *tfm)
...@@ -2406,10 +2409,8 @@ static void caam_aead_exit(struct crypto_aead *tfm) ...@@ -2406,10 +2409,8 @@ static void caam_aead_exit(struct crypto_aead *tfm)
caam_exit_common(crypto_aead_ctx(tfm)); caam_exit_common(crypto_aead_ctx(tfm));
} }
static struct list_head alg_list;
static void __exit caam_qi_algapi_exit(void) static void __exit caam_qi_algapi_exit(void)
{ {
struct caam_crypto_alg *t_alg, *n;
int i; int i;
for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) { for (i = 0; i < ARRAY_SIZE(driver_aeads); i++) {
...@@ -2419,47 +2420,25 @@ static void __exit caam_qi_algapi_exit(void) ...@@ -2419,47 +2420,25 @@ static void __exit caam_qi_algapi_exit(void)
crypto_unregister_aead(&t_alg->aead); crypto_unregister_aead(&t_alg->aead);
} }
if (!alg_list.next) for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
return; struct caam_skcipher_alg *t_alg = driver_algs + i;
list_for_each_entry_safe(t_alg, n, &alg_list, entry) { if (t_alg->registered)
crypto_unregister_alg(&t_alg->crypto_alg); crypto_unregister_skcipher(&t_alg->skcipher);
list_del(&t_alg->entry);
kfree(t_alg);
} }
} }
static struct caam_crypto_alg *caam_alg_alloc(struct caam_alg_template static void caam_skcipher_alg_init(struct caam_skcipher_alg *t_alg)
*template)
{ {
struct caam_crypto_alg *t_alg; struct skcipher_alg *alg = &t_alg->skcipher;
struct crypto_alg *alg;
t_alg = kzalloc(sizeof(*t_alg), GFP_KERNEL); alg->base.cra_module = THIS_MODULE;
if (!t_alg) alg->base.cra_priority = CAAM_CRA_PRIORITY;
return ERR_PTR(-ENOMEM); alg->base.cra_ctxsize = sizeof(struct caam_ctx);
alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY;
alg = &t_alg->crypto_alg; alg->init = caam_cra_init;
alg->exit = caam_cra_exit;
snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s", template->name);
snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
template->driver_name);
alg->cra_module = THIS_MODULE;
alg->cra_init = caam_cra_init;
alg->cra_exit = caam_cra_exit;
alg->cra_priority = CAAM_CRA_PRIORITY;
alg->cra_blocksize = template->blocksize;
alg->cra_alignmask = 0;
alg->cra_ctxsize = sizeof(struct caam_ctx);
alg->cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY |
CRYPTO_ALG_TYPE_ABLKCIPHER;
alg->cra_type = &crypto_ablkcipher_type;
alg->cra_ablkcipher = template->template_ablkcipher;
t_alg->caam.class1_alg_type = template->class1_alg_type;
t_alg->caam.class2_alg_type = template->class2_alg_type;
return t_alg;
} }
static void caam_aead_alg_init(struct caam_aead_alg *t_alg) static void caam_aead_alg_init(struct caam_aead_alg *t_alg)
...@@ -2513,8 +2492,6 @@ static int __init caam_qi_algapi_init(void) ...@@ -2513,8 +2492,6 @@ static int __init caam_qi_algapi_init(void)
return -ENODEV; return -ENODEV;
} }
INIT_LIST_HEAD(&alg_list);
/* /*
* Register crypto algorithms the device supports. * Register crypto algorithms the device supports.
* First, detect presence and attributes of DES, AES, and MD blocks. * First, detect presence and attributes of DES, AES, and MD blocks.
...@@ -2530,9 +2507,8 @@ static int __init caam_qi_algapi_init(void) ...@@ -2530,9 +2507,8 @@ static int __init caam_qi_algapi_init(void)
md_limit = SHA256_DIGEST_SIZE; md_limit = SHA256_DIGEST_SIZE;
for (i = 0; i < ARRAY_SIZE(driver_algs); i++) { for (i = 0; i < ARRAY_SIZE(driver_algs); i++) {
struct caam_crypto_alg *t_alg; struct caam_skcipher_alg *t_alg = driver_algs + i;
struct caam_alg_template *alg = driver_algs + i; u32 alg_sel = t_alg->caam.class1_alg_type & OP_ALG_ALGSEL_MASK;
u32 alg_sel = alg->class1_alg_type & OP_ALG_ALGSEL_MASK;
/* Skip DES algorithms if not supported by device */ /* Skip DES algorithms if not supported by device */
if (!des_inst && if (!des_inst &&
...@@ -2544,23 +2520,16 @@ static int __init caam_qi_algapi_init(void) ...@@ -2544,23 +2520,16 @@ static int __init caam_qi_algapi_init(void)
if (!aes_inst && (alg_sel == OP_ALG_ALGSEL_AES)) if (!aes_inst && (alg_sel == OP_ALG_ALGSEL_AES))
continue; continue;
t_alg = caam_alg_alloc(alg); caam_skcipher_alg_init(t_alg);
if (IS_ERR(t_alg)) {
err = PTR_ERR(t_alg);
dev_warn(priv->qidev, "%s alg allocation failed\n",
alg->driver_name);
continue;
}
err = crypto_register_alg(&t_alg->crypto_alg); err = crypto_register_skcipher(&t_alg->skcipher);
if (err) { if (err) {
dev_warn(priv->qidev, "%s alg registration failed\n", dev_warn(priv->qidev, "%s alg registration failed\n",
t_alg->crypto_alg.cra_driver_name); t_alg->skcipher.base.cra_driver_name);
kfree(t_alg);
continue; continue;
} }
list_add_tail(&t_alg->entry, &alg_list); t_alg->registered = true;
registered = true; registered = true;
} }
......
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