Commit 4cb4f7c1 authored by Herbert Xu's avatar Herbert Xu

crypto: caam - Set DMA alignment explicitly

This driver has been implicitly relying on kmalloc alignment
to be sufficient for DMA.  This may no longer be the case with
upcoming arm64 changes.

This patch changes it to explicitly request DMA alignment from
the Crypto API.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent a5a49249
This diff is collapsed.
...@@ -81,7 +81,7 @@ static int aead_set_sh_desc(struct crypto_aead *aead) ...@@ -81,7 +81,7 @@ static int aead_set_sh_desc(struct crypto_aead *aead)
{ {
struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead), struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
typeof(*alg), aead); typeof(*alg), aead);
struct caam_ctx *ctx = crypto_aead_ctx(aead); struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
unsigned int ivsize = crypto_aead_ivsize(aead); unsigned int ivsize = crypto_aead_ivsize(aead);
u32 ctx1_iv_off = 0; u32 ctx1_iv_off = 0;
u32 *nonce = NULL; u32 *nonce = NULL;
...@@ -184,7 +184,7 @@ static int aead_set_sh_desc(struct crypto_aead *aead) ...@@ -184,7 +184,7 @@ static int aead_set_sh_desc(struct crypto_aead *aead)
static int aead_setauthsize(struct crypto_aead *authenc, unsigned int authsize) static int aead_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(authenc); struct caam_ctx *ctx = crypto_aead_ctx_dma(authenc);
ctx->authsize = authsize; ctx->authsize = authsize;
aead_set_sh_desc(authenc); aead_set_sh_desc(authenc);
...@@ -195,7 +195,7 @@ static int aead_setauthsize(struct crypto_aead *authenc, unsigned int authsize) ...@@ -195,7 +195,7 @@ static int aead_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
static int aead_setkey(struct crypto_aead *aead, const u8 *key, static int aead_setkey(struct crypto_aead *aead, const u8 *key,
unsigned int keylen) unsigned int keylen)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(aead); struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
struct device *jrdev = ctx->jrdev; struct device *jrdev = ctx->jrdev;
struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent); struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent);
struct crypto_authenc_keys keys; struct crypto_authenc_keys keys;
...@@ -299,7 +299,7 @@ static int des3_aead_setkey(struct crypto_aead *aead, const u8 *key, ...@@ -299,7 +299,7 @@ static int des3_aead_setkey(struct crypto_aead *aead, const u8 *key,
static int gcm_set_sh_desc(struct crypto_aead *aead) static int gcm_set_sh_desc(struct crypto_aead *aead)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(aead); struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
unsigned int ivsize = crypto_aead_ivsize(aead); unsigned int ivsize = crypto_aead_ivsize(aead);
int rem_bytes = CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN - int rem_bytes = CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN -
ctx->cdata.keylen; ctx->cdata.keylen;
...@@ -342,7 +342,7 @@ static int gcm_set_sh_desc(struct crypto_aead *aead) ...@@ -342,7 +342,7 @@ static int gcm_set_sh_desc(struct crypto_aead *aead)
static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize) static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(authenc); struct caam_ctx *ctx = crypto_aead_ctx_dma(authenc);
int err; int err;
err = crypto_gcm_check_authsize(authsize); err = crypto_gcm_check_authsize(authsize);
...@@ -358,7 +358,7 @@ static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize) ...@@ -358,7 +358,7 @@ static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
static int gcm_setkey(struct crypto_aead *aead, static int gcm_setkey(struct crypto_aead *aead,
const u8 *key, unsigned int keylen) const u8 *key, unsigned int keylen)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(aead); struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
struct device *jrdev = ctx->jrdev; struct device *jrdev = ctx->jrdev;
int ret; int ret;
...@@ -402,7 +402,7 @@ static int gcm_setkey(struct crypto_aead *aead, ...@@ -402,7 +402,7 @@ static int gcm_setkey(struct crypto_aead *aead,
static int rfc4106_set_sh_desc(struct crypto_aead *aead) static int rfc4106_set_sh_desc(struct crypto_aead *aead)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(aead); struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
unsigned int ivsize = crypto_aead_ivsize(aead); unsigned int ivsize = crypto_aead_ivsize(aead);
int rem_bytes = CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN - int rem_bytes = CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN -
ctx->cdata.keylen; ctx->cdata.keylen;
...@@ -446,7 +446,7 @@ static int rfc4106_set_sh_desc(struct crypto_aead *aead) ...@@ -446,7 +446,7 @@ static int rfc4106_set_sh_desc(struct crypto_aead *aead)
static int rfc4106_setauthsize(struct crypto_aead *authenc, static int rfc4106_setauthsize(struct crypto_aead *authenc,
unsigned int authsize) unsigned int authsize)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(authenc); struct caam_ctx *ctx = crypto_aead_ctx_dma(authenc);
int err; int err;
err = crypto_rfc4106_check_authsize(authsize); err = crypto_rfc4106_check_authsize(authsize);
...@@ -462,7 +462,7 @@ static int rfc4106_setauthsize(struct crypto_aead *authenc, ...@@ -462,7 +462,7 @@ static int rfc4106_setauthsize(struct crypto_aead *authenc,
static int rfc4106_setkey(struct crypto_aead *aead, static int rfc4106_setkey(struct crypto_aead *aead,
const u8 *key, unsigned int keylen) const u8 *key, unsigned int keylen)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(aead); struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
struct device *jrdev = ctx->jrdev; struct device *jrdev = ctx->jrdev;
int ret; int ret;
...@@ -510,7 +510,7 @@ static int rfc4106_setkey(struct crypto_aead *aead, ...@@ -510,7 +510,7 @@ static int rfc4106_setkey(struct crypto_aead *aead,
static int rfc4543_set_sh_desc(struct crypto_aead *aead) static int rfc4543_set_sh_desc(struct crypto_aead *aead)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(aead); struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
unsigned int ivsize = crypto_aead_ivsize(aead); unsigned int ivsize = crypto_aead_ivsize(aead);
int rem_bytes = CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN - int rem_bytes = CAAM_DESC_BYTES_MAX - DESC_JOB_IO_LEN -
ctx->cdata.keylen; ctx->cdata.keylen;
...@@ -554,7 +554,7 @@ static int rfc4543_set_sh_desc(struct crypto_aead *aead) ...@@ -554,7 +554,7 @@ static int rfc4543_set_sh_desc(struct crypto_aead *aead)
static int rfc4543_setauthsize(struct crypto_aead *authenc, static int rfc4543_setauthsize(struct crypto_aead *authenc,
unsigned int authsize) unsigned int authsize)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(authenc); struct caam_ctx *ctx = crypto_aead_ctx_dma(authenc);
if (authsize != 16) if (authsize != 16)
return -EINVAL; return -EINVAL;
...@@ -568,7 +568,7 @@ static int rfc4543_setauthsize(struct crypto_aead *authenc, ...@@ -568,7 +568,7 @@ static int rfc4543_setauthsize(struct crypto_aead *authenc,
static int rfc4543_setkey(struct crypto_aead *aead, static int rfc4543_setkey(struct crypto_aead *aead,
const u8 *key, unsigned int keylen) const u8 *key, unsigned int keylen)
{ {
struct caam_ctx *ctx = crypto_aead_ctx(aead); struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
struct device *jrdev = ctx->jrdev; struct device *jrdev = ctx->jrdev;
int ret; int ret;
...@@ -617,7 +617,7 @@ static int rfc4543_setkey(struct crypto_aead *aead, ...@@ -617,7 +617,7 @@ static int rfc4543_setkey(struct crypto_aead *aead,
static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
unsigned int keylen, const u32 ctx1_iv_off) unsigned int keylen, const u32 ctx1_iv_off)
{ {
struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher); struct caam_ctx *ctx = crypto_skcipher_ctx_dma(skcipher);
struct caam_skcipher_alg *alg = struct caam_skcipher_alg *alg =
container_of(crypto_skcipher_alg(skcipher), typeof(*alg), container_of(crypto_skcipher_alg(skcipher), typeof(*alg),
skcipher); skcipher);
...@@ -731,7 +731,7 @@ static int des_skcipher_setkey(struct crypto_skcipher *skcipher, ...@@ -731,7 +731,7 @@ static int des_skcipher_setkey(struct crypto_skcipher *skcipher,
static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key, static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
unsigned int keylen) unsigned int keylen)
{ {
struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher); struct caam_ctx *ctx = crypto_skcipher_ctx_dma(skcipher);
struct device *jrdev = ctx->jrdev; struct device *jrdev = ctx->jrdev;
struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent); struct caam_drv_private *ctrlpriv = dev_get_drvdata(jrdev->parent);
int ret = 0; int ret = 0;
...@@ -915,7 +915,7 @@ static void aead_done(struct caam_drv_req *drv_req, u32 status) ...@@ -915,7 +915,7 @@ static void aead_done(struct caam_drv_req *drv_req, u32 status)
struct aead_edesc *edesc; struct aead_edesc *edesc;
struct aead_request *aead_req = drv_req->app_ctx; struct aead_request *aead_req = drv_req->app_ctx;
struct crypto_aead *aead = crypto_aead_reqtfm(aead_req); struct crypto_aead *aead = crypto_aead_reqtfm(aead_req);
struct caam_ctx *caam_ctx = crypto_aead_ctx(aead); struct caam_ctx *caam_ctx = crypto_aead_ctx_dma(aead);
int ecode = 0; int ecode = 0;
qidev = caam_ctx->qidev; qidev = caam_ctx->qidev;
...@@ -937,7 +937,7 @@ static struct aead_edesc *aead_edesc_alloc(struct aead_request *req, ...@@ -937,7 +937,7 @@ static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
bool encrypt) bool encrypt)
{ {
struct crypto_aead *aead = crypto_aead_reqtfm(req); struct crypto_aead *aead = crypto_aead_reqtfm(req);
struct caam_ctx *ctx = crypto_aead_ctx(aead); struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead), struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
typeof(*alg), aead); typeof(*alg), aead);
struct device *qidev = ctx->qidev; struct device *qidev = ctx->qidev;
...@@ -1157,7 +1157,7 @@ static inline int aead_crypt(struct aead_request *req, bool encrypt) ...@@ -1157,7 +1157,7 @@ static inline int aead_crypt(struct aead_request *req, bool encrypt)
{ {
struct aead_edesc *edesc; struct aead_edesc *edesc;
struct crypto_aead *aead = crypto_aead_reqtfm(req); struct crypto_aead *aead = crypto_aead_reqtfm(req);
struct caam_ctx *ctx = crypto_aead_ctx(aead); struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
int ret; int ret;
if (unlikely(caam_congested)) if (unlikely(caam_congested))
...@@ -1207,7 +1207,7 @@ static void skcipher_done(struct caam_drv_req *drv_req, u32 status) ...@@ -1207,7 +1207,7 @@ static void skcipher_done(struct caam_drv_req *drv_req, u32 status)
struct skcipher_edesc *edesc; struct skcipher_edesc *edesc;
struct skcipher_request *req = drv_req->app_ctx; struct skcipher_request *req = drv_req->app_ctx;
struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
struct caam_ctx *caam_ctx = crypto_skcipher_ctx(skcipher); struct caam_ctx *caam_ctx = crypto_skcipher_ctx_dma(skcipher);
struct device *qidev = caam_ctx->qidev; struct device *qidev = caam_ctx->qidev;
int ivsize = crypto_skcipher_ivsize(skcipher); int ivsize = crypto_skcipher_ivsize(skcipher);
int ecode = 0; int ecode = 0;
...@@ -1245,7 +1245,7 @@ static struct skcipher_edesc *skcipher_edesc_alloc(struct skcipher_request *req, ...@@ -1245,7 +1245,7 @@ static struct skcipher_edesc *skcipher_edesc_alloc(struct skcipher_request *req,
bool encrypt) bool encrypt)
{ {
struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher); struct caam_ctx *ctx = crypto_skcipher_ctx_dma(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;
...@@ -1405,7 +1405,7 @@ static inline int skcipher_crypt(struct skcipher_request *req, bool encrypt) ...@@ -1405,7 +1405,7 @@ static inline int skcipher_crypt(struct skcipher_request *req, bool encrypt)
{ {
struct skcipher_edesc *edesc; struct skcipher_edesc *edesc;
struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req); struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
struct caam_ctx *ctx = crypto_skcipher_ctx(skcipher); struct caam_ctx *ctx = crypto_skcipher_ctx_dma(skcipher);
struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctx->jrdev->parent); struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctx->jrdev->parent);
int ret; int ret;
...@@ -2491,7 +2491,7 @@ static int caam_cra_init(struct crypto_skcipher *tfm) ...@@ -2491,7 +2491,7 @@ static int caam_cra_init(struct crypto_skcipher *tfm)
struct skcipher_alg *alg = crypto_skcipher_alg(tfm); struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
struct caam_skcipher_alg *caam_alg = struct caam_skcipher_alg *caam_alg =
container_of(alg, typeof(*caam_alg), skcipher); container_of(alg, typeof(*caam_alg), skcipher);
struct caam_ctx *ctx = crypto_skcipher_ctx(tfm); struct caam_ctx *ctx = crypto_skcipher_ctx_dma(tfm);
u32 alg_aai = caam_alg->caam.class1_alg_type & OP_ALG_AAI_MASK; u32 alg_aai = caam_alg->caam.class1_alg_type & OP_ALG_AAI_MASK;
int ret = 0; int ret = 0;
...@@ -2524,7 +2524,7 @@ static int caam_aead_init(struct crypto_aead *tfm) ...@@ -2524,7 +2524,7 @@ static int caam_aead_init(struct crypto_aead *tfm)
struct aead_alg *alg = crypto_aead_alg(tfm); struct aead_alg *alg = crypto_aead_alg(tfm);
struct caam_aead_alg *caam_alg = container_of(alg, typeof(*caam_alg), struct caam_aead_alg *caam_alg = container_of(alg, typeof(*caam_alg),
aead); aead);
struct caam_ctx *ctx = crypto_aead_ctx(tfm); struct caam_ctx *ctx = crypto_aead_ctx_dma(tfm);
return caam_init_common(ctx, &caam_alg->caam, !caam_alg->caam.nodkp); return caam_init_common(ctx, &caam_alg->caam, !caam_alg->caam.nodkp);
} }
...@@ -2542,7 +2542,7 @@ static void caam_exit_common(struct caam_ctx *ctx) ...@@ -2542,7 +2542,7 @@ static void caam_exit_common(struct caam_ctx *ctx)
static void caam_cra_exit(struct crypto_skcipher *tfm) static void caam_cra_exit(struct crypto_skcipher *tfm)
{ {
struct caam_ctx *ctx = crypto_skcipher_ctx(tfm); struct caam_ctx *ctx = crypto_skcipher_ctx_dma(tfm);
if (ctx->fallback) if (ctx->fallback)
crypto_free_skcipher(ctx->fallback); crypto_free_skcipher(ctx->fallback);
...@@ -2551,7 +2551,7 @@ static void caam_cra_exit(struct crypto_skcipher *tfm) ...@@ -2551,7 +2551,7 @@ static void caam_cra_exit(struct crypto_skcipher *tfm)
static void caam_aead_exit(struct crypto_aead *tfm) static void caam_aead_exit(struct crypto_aead *tfm)
{ {
caam_exit_common(crypto_aead_ctx(tfm)); caam_exit_common(crypto_aead_ctx_dma(tfm));
} }
void caam_qi_algapi_exit(void) void caam_qi_algapi_exit(void)
...@@ -2579,7 +2579,7 @@ static void caam_skcipher_alg_init(struct caam_skcipher_alg *t_alg) ...@@ -2579,7 +2579,7 @@ static void caam_skcipher_alg_init(struct caam_skcipher_alg *t_alg)
alg->base.cra_module = THIS_MODULE; alg->base.cra_module = THIS_MODULE;
alg->base.cra_priority = CAAM_CRA_PRIORITY; alg->base.cra_priority = CAAM_CRA_PRIORITY;
alg->base.cra_ctxsize = sizeof(struct caam_ctx); alg->base.cra_ctxsize = sizeof(struct caam_ctx) + crypto_dma_padding();
alg->base.cra_flags |= (CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | alg->base.cra_flags |= (CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY |
CRYPTO_ALG_KERN_DRIVER_ONLY); CRYPTO_ALG_KERN_DRIVER_ONLY);
...@@ -2593,7 +2593,7 @@ static void caam_aead_alg_init(struct caam_aead_alg *t_alg) ...@@ -2593,7 +2593,7 @@ static void caam_aead_alg_init(struct caam_aead_alg *t_alg)
alg->base.cra_module = THIS_MODULE; alg->base.cra_module = THIS_MODULE;
alg->base.cra_priority = CAAM_CRA_PRIORITY; alg->base.cra_priority = CAAM_CRA_PRIORITY;
alg->base.cra_ctxsize = sizeof(struct caam_ctx); alg->base.cra_ctxsize = sizeof(struct caam_ctx) + crypto_dma_padding();
alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY | alg->base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY |
CRYPTO_ALG_KERN_DRIVER_ONLY; CRYPTO_ALG_KERN_DRIVER_ONLY;
......
This diff is collapsed.
This diff is collapsed.
...@@ -57,7 +57,7 @@ static void rsa_pub_unmap(struct device *dev, struct rsa_edesc *edesc, ...@@ -57,7 +57,7 @@ static void rsa_pub_unmap(struct device *dev, struct rsa_edesc *edesc,
struct akcipher_request *req) struct akcipher_request *req)
{ {
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct caam_rsa_key *key = &ctx->key; struct caam_rsa_key *key = &ctx->key;
struct rsa_pub_pdb *pdb = &edesc->pdb.pub; struct rsa_pub_pdb *pdb = &edesc->pdb.pub;
...@@ -69,7 +69,7 @@ static void rsa_priv_f1_unmap(struct device *dev, struct rsa_edesc *edesc, ...@@ -69,7 +69,7 @@ static void rsa_priv_f1_unmap(struct device *dev, struct rsa_edesc *edesc,
struct akcipher_request *req) struct akcipher_request *req)
{ {
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct caam_rsa_key *key = &ctx->key; struct caam_rsa_key *key = &ctx->key;
struct rsa_priv_f1_pdb *pdb = &edesc->pdb.priv_f1; struct rsa_priv_f1_pdb *pdb = &edesc->pdb.priv_f1;
...@@ -81,7 +81,7 @@ static void rsa_priv_f2_unmap(struct device *dev, struct rsa_edesc *edesc, ...@@ -81,7 +81,7 @@ static void rsa_priv_f2_unmap(struct device *dev, struct rsa_edesc *edesc,
struct akcipher_request *req) struct akcipher_request *req)
{ {
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct caam_rsa_key *key = &ctx->key; struct caam_rsa_key *key = &ctx->key;
struct rsa_priv_f2_pdb *pdb = &edesc->pdb.priv_f2; struct rsa_priv_f2_pdb *pdb = &edesc->pdb.priv_f2;
size_t p_sz = key->p_sz; size_t p_sz = key->p_sz;
...@@ -98,7 +98,7 @@ static void rsa_priv_f3_unmap(struct device *dev, struct rsa_edesc *edesc, ...@@ -98,7 +98,7 @@ static void rsa_priv_f3_unmap(struct device *dev, struct rsa_edesc *edesc,
struct akcipher_request *req) struct akcipher_request *req)
{ {
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct caam_rsa_key *key = &ctx->key; struct caam_rsa_key *key = &ctx->key;
struct rsa_priv_f3_pdb *pdb = &edesc->pdb.priv_f3; struct rsa_priv_f3_pdb *pdb = &edesc->pdb.priv_f3;
size_t p_sz = key->p_sz; size_t p_sz = key->p_sz;
...@@ -149,7 +149,7 @@ static void rsa_priv_f_done(struct device *dev, u32 *desc, u32 err, ...@@ -149,7 +149,7 @@ static void rsa_priv_f_done(struct device *dev, u32 *desc, u32 err,
struct akcipher_request *req = context; struct akcipher_request *req = context;
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_drv_private_jr *jrp = dev_get_drvdata(dev); struct caam_drv_private_jr *jrp = dev_get_drvdata(dev);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct caam_rsa_key *key = &ctx->key; struct caam_rsa_key *key = &ctx->key;
struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req); struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
struct rsa_edesc *edesc; struct rsa_edesc *edesc;
...@@ -242,7 +242,7 @@ static struct rsa_edesc *rsa_edesc_alloc(struct akcipher_request *req, ...@@ -242,7 +242,7 @@ static struct rsa_edesc *rsa_edesc_alloc(struct akcipher_request *req,
size_t desclen) size_t desclen)
{ {
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct device *dev = ctx->dev; struct device *dev = ctx->dev;
struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req); struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
struct caam_rsa_key *key = &ctx->key; struct caam_rsa_key *key = &ctx->key;
...@@ -371,7 +371,7 @@ static int akcipher_do_one_req(struct crypto_engine *engine, void *areq) ...@@ -371,7 +371,7 @@ static int akcipher_do_one_req(struct crypto_engine *engine, void *areq)
base); base);
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req); struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct device *jrdev = ctx->dev; struct device *jrdev = ctx->dev;
u32 *desc = req_ctx->edesc->hw_desc; u32 *desc = req_ctx->edesc->hw_desc;
int ret; int ret;
...@@ -399,7 +399,7 @@ static int set_rsa_pub_pdb(struct akcipher_request *req, ...@@ -399,7 +399,7 @@ static int set_rsa_pub_pdb(struct akcipher_request *req,
{ {
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req); struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct caam_rsa_key *key = &ctx->key; struct caam_rsa_key *key = &ctx->key;
struct device *dev = ctx->dev; struct device *dev = ctx->dev;
struct rsa_pub_pdb *pdb = &edesc->pdb.pub; struct rsa_pub_pdb *pdb = &edesc->pdb.pub;
...@@ -444,7 +444,7 @@ static int set_rsa_priv_f1_pdb(struct akcipher_request *req, ...@@ -444,7 +444,7 @@ static int set_rsa_priv_f1_pdb(struct akcipher_request *req,
struct rsa_edesc *edesc) struct rsa_edesc *edesc)
{ {
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct caam_rsa_key *key = &ctx->key; struct caam_rsa_key *key = &ctx->key;
struct device *dev = ctx->dev; struct device *dev = ctx->dev;
struct rsa_priv_f1_pdb *pdb = &edesc->pdb.priv_f1; struct rsa_priv_f1_pdb *pdb = &edesc->pdb.priv_f1;
...@@ -491,7 +491,7 @@ static int set_rsa_priv_f2_pdb(struct akcipher_request *req, ...@@ -491,7 +491,7 @@ static int set_rsa_priv_f2_pdb(struct akcipher_request *req,
struct rsa_edesc *edesc) struct rsa_edesc *edesc)
{ {
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct caam_rsa_key *key = &ctx->key; struct caam_rsa_key *key = &ctx->key;
struct device *dev = ctx->dev; struct device *dev = ctx->dev;
struct rsa_priv_f2_pdb *pdb = &edesc->pdb.priv_f2; struct rsa_priv_f2_pdb *pdb = &edesc->pdb.priv_f2;
...@@ -568,7 +568,7 @@ static int set_rsa_priv_f3_pdb(struct akcipher_request *req, ...@@ -568,7 +568,7 @@ static int set_rsa_priv_f3_pdb(struct akcipher_request *req,
struct rsa_edesc *edesc) struct rsa_edesc *edesc)
{ {
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct caam_rsa_key *key = &ctx->key; struct caam_rsa_key *key = &ctx->key;
struct device *dev = ctx->dev; struct device *dev = ctx->dev;
struct rsa_priv_f3_pdb *pdb = &edesc->pdb.priv_f3; struct rsa_priv_f3_pdb *pdb = &edesc->pdb.priv_f3;
...@@ -664,7 +664,7 @@ static int akcipher_enqueue_req(struct device *jrdev, ...@@ -664,7 +664,7 @@ static int akcipher_enqueue_req(struct device *jrdev,
{ {
struct caam_drv_private_jr *jrpriv = dev_get_drvdata(jrdev); struct caam_drv_private_jr *jrpriv = dev_get_drvdata(jrdev);
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct caam_rsa_key *key = &ctx->key; struct caam_rsa_key *key = &ctx->key;
struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req); struct caam_rsa_req_ctx *req_ctx = akcipher_request_ctx(req);
struct rsa_edesc *edesc = req_ctx->edesc; struct rsa_edesc *edesc = req_ctx->edesc;
...@@ -707,7 +707,7 @@ static int akcipher_enqueue_req(struct device *jrdev, ...@@ -707,7 +707,7 @@ static int akcipher_enqueue_req(struct device *jrdev,
static int caam_rsa_enc(struct akcipher_request *req) static int caam_rsa_enc(struct akcipher_request *req)
{ {
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct caam_rsa_key *key = &ctx->key; struct caam_rsa_key *key = &ctx->key;
struct device *jrdev = ctx->dev; struct device *jrdev = ctx->dev;
struct rsa_edesc *edesc; struct rsa_edesc *edesc;
...@@ -746,7 +746,7 @@ static int caam_rsa_enc(struct akcipher_request *req) ...@@ -746,7 +746,7 @@ static int caam_rsa_enc(struct akcipher_request *req)
static int caam_rsa_dec_priv_f1(struct akcipher_request *req) static int caam_rsa_dec_priv_f1(struct akcipher_request *req)
{ {
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct device *jrdev = ctx->dev; struct device *jrdev = ctx->dev;
struct rsa_edesc *edesc; struct rsa_edesc *edesc;
int ret; int ret;
...@@ -775,7 +775,7 @@ static int caam_rsa_dec_priv_f1(struct akcipher_request *req) ...@@ -775,7 +775,7 @@ static int caam_rsa_dec_priv_f1(struct akcipher_request *req)
static int caam_rsa_dec_priv_f2(struct akcipher_request *req) static int caam_rsa_dec_priv_f2(struct akcipher_request *req)
{ {
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct device *jrdev = ctx->dev; struct device *jrdev = ctx->dev;
struct rsa_edesc *edesc; struct rsa_edesc *edesc;
int ret; int ret;
...@@ -804,7 +804,7 @@ static int caam_rsa_dec_priv_f2(struct akcipher_request *req) ...@@ -804,7 +804,7 @@ static int caam_rsa_dec_priv_f2(struct akcipher_request *req)
static int caam_rsa_dec_priv_f3(struct akcipher_request *req) static int caam_rsa_dec_priv_f3(struct akcipher_request *req)
{ {
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct device *jrdev = ctx->dev; struct device *jrdev = ctx->dev;
struct rsa_edesc *edesc; struct rsa_edesc *edesc;
int ret; int ret;
...@@ -833,7 +833,7 @@ static int caam_rsa_dec_priv_f3(struct akcipher_request *req) ...@@ -833,7 +833,7 @@ static int caam_rsa_dec_priv_f3(struct akcipher_request *req)
static int caam_rsa_dec(struct akcipher_request *req) static int caam_rsa_dec(struct akcipher_request *req)
{ {
struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct caam_rsa_key *key = &ctx->key; struct caam_rsa_key *key = &ctx->key;
int ret; int ret;
...@@ -936,7 +936,7 @@ static int caam_rsa_check_key_length(unsigned int len) ...@@ -936,7 +936,7 @@ static int caam_rsa_check_key_length(unsigned int len)
static int caam_rsa_set_pub_key(struct crypto_akcipher *tfm, const void *key, static int caam_rsa_set_pub_key(struct crypto_akcipher *tfm, const void *key,
unsigned int keylen) unsigned int keylen)
{ {
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct rsa_key raw_key = {NULL}; struct rsa_key raw_key = {NULL};
struct caam_rsa_key *rsa_key = &ctx->key; struct caam_rsa_key *rsa_key = &ctx->key;
int ret; int ret;
...@@ -1038,7 +1038,7 @@ static void caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx, ...@@ -1038,7 +1038,7 @@ static void caam_rsa_set_priv_key_form(struct caam_rsa_ctx *ctx,
static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key, static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key,
unsigned int keylen) unsigned int keylen)
{ {
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct rsa_key raw_key = {NULL}; struct rsa_key raw_key = {NULL};
struct caam_rsa_key *rsa_key = &ctx->key; struct caam_rsa_key *rsa_key = &ctx->key;
int ret; int ret;
...@@ -1089,7 +1089,7 @@ static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key, ...@@ -1089,7 +1089,7 @@ static int caam_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key,
static unsigned int caam_rsa_max_size(struct crypto_akcipher *tfm) static unsigned int caam_rsa_max_size(struct crypto_akcipher *tfm)
{ {
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
return ctx->key.n_sz; return ctx->key.n_sz;
} }
...@@ -1097,7 +1097,7 @@ static unsigned int caam_rsa_max_size(struct crypto_akcipher *tfm) ...@@ -1097,7 +1097,7 @@ static unsigned int caam_rsa_max_size(struct crypto_akcipher *tfm)
/* Per session pkc's driver context creation function */ /* Per session pkc's driver context creation function */
static int caam_rsa_init_tfm(struct crypto_akcipher *tfm) static int caam_rsa_init_tfm(struct crypto_akcipher *tfm)
{ {
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
akcipher_set_reqsize(tfm, sizeof(struct caam_rsa_req_ctx)); akcipher_set_reqsize(tfm, sizeof(struct caam_rsa_req_ctx));
...@@ -1125,7 +1125,7 @@ static int caam_rsa_init_tfm(struct crypto_akcipher *tfm) ...@@ -1125,7 +1125,7 @@ static int caam_rsa_init_tfm(struct crypto_akcipher *tfm)
/* Per session pkc's driver context cleanup function */ /* Per session pkc's driver context cleanup function */
static void caam_rsa_exit_tfm(struct crypto_akcipher *tfm) static void caam_rsa_exit_tfm(struct crypto_akcipher *tfm)
{ {
struct caam_rsa_ctx *ctx = akcipher_tfm_ctx(tfm); struct caam_rsa_ctx *ctx = akcipher_tfm_ctx_dma(tfm);
struct caam_rsa_key *key = &ctx->key; struct caam_rsa_key *key = &ctx->key;
dma_unmap_single(ctx->dev, ctx->padding_dma, CAAM_RSA_MAX_INPUT_SIZE - dma_unmap_single(ctx->dev, ctx->padding_dma, CAAM_RSA_MAX_INPUT_SIZE -
...@@ -1148,7 +1148,8 @@ static struct caam_akcipher_alg caam_rsa = { ...@@ -1148,7 +1148,8 @@ static struct caam_akcipher_alg caam_rsa = {
.cra_driver_name = "rsa-caam", .cra_driver_name = "rsa-caam",
.cra_priority = 3000, .cra_priority = 3000,
.cra_module = THIS_MODULE, .cra_module = THIS_MODULE,
.cra_ctxsize = sizeof(struct caam_rsa_ctx), .cra_ctxsize = sizeof(struct caam_rsa_ctx) +
CRYPTO_DMA_PADDING,
}, },
} }
}; };
......
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